Blob Blame History Raw
diff -ruNp a/agent/mibgroup/ucd-snmp/disk.c b/agent/mibgroup/ucd-snmp/disk.c
--- a/agent/mibgroup/ucd-snmp/disk.c	2020-06-10 09:29:35.867328760 +0200
+++ b/agent/mibgroup/ucd-snmp/disk.c	2020-06-10 09:44:13.053535421 +0200
@@ -153,9 +153,10 @@ static void       disk_free_config(void)
 static void       disk_parse_config(const char *, char *);
 static void       disk_parse_config_all(const char *, char *);
 #if HAVE_FSTAB_H || HAVE_GETMNTENT || HAVE_STATFS
-static void       find_and_add_allDisks(int minpercent);
+static void       refresh_disk_table(int addNewDisks, int minpercent);
 static void       add_device(char *path, char *device,
-	                     int minspace, int minpercent, int override);
+	                     int minspace, int minpercent, int addNewDisks,
+	                     int override);
 static void       modify_disk_parameters(int index, int minspace,
 	                                 int minpercent);
 static int        disk_exists(char *path);
@@ -167,6 +168,7 @@ struct diskpart {
     char            path[STRMAX];
     int             minimumspace;
     int             minpercent;
+    int             alive;
 };
 
 #define MAX_INT_32 0x7fffffff
@@ -174,6 +176,7 @@ struct diskpart {
 
 unsigned int    numdisks;
 int             allDisksIncluded = 0;
+int             allDisksMinPercent = 0;
 unsigned int    maxdisks = 0;
 struct diskpart *disks;
 
@@ -238,6 +241,7 @@ init_disk(void)
 				disk_free_config,
 				"minpercent%");
   allDisksIncluded = 0;
+  allDisksMinPercent = 0;
 }
 
 static void
@@ -253,6 +257,7 @@ disk_free_config(void)
     disks[i].minpercent = -1;
   }
   allDisksIncluded = 0;
+  allDisksMinPercent = 0;
 }
 
 static void 
@@ -313,7 +318,7 @@ disk_parse_config(const char *token, cha
    * check if the disk already exists, if so then modify its
    * parameters. if it does not exist then add it
    */
-  add_device(path, find_device(path), minspace, minpercent, 1);
+  add_device(path, find_device(path), minspace, minpercent, 1, 1);
 #endif /* HAVE_FSTAB_H || HAVE_GETMNTENT || HAVE_STATFS */
 }
 
@@ -372,7 +377,7 @@ disk_parse_config_all(const char *token,
 
 #if HAVE_FSTAB_H || HAVE_GETMNTENT || HAVE_STATFS
 static void
-add_device(char *path, char *device, int minspace, int minpercent, int override) 
+add_device(char *path, char *device, int minspace, int minpercent, int addNewDisks, int override) 
 {
   int index;
 
@@ -402,10 +407,16 @@ add_device(char *path, char *device, int
   }
 
   index = disk_exists(path);
-  if((index != -1) && (index < maxdisks) && (override==1)) {
-    modify_disk_parameters(index, minspace, minpercent);
+  if((index != -1) && (index < maxdisks)) {
+    /* the path is already in the table */
+    disks[index].alive = 1;
+    /* -> update its device */
+    strlcpy(disks[index].device, device, sizeof(disks[index].device));
+    if (override == 1) {
+        modify_disk_parameters(index, minspace, minpercent);
+    }
   }
-  else if(index == -1){
+  else if(index == -1 && addNewDisks){
     /* add if and only if the device was found */
     if(device[0] != 0) {
       /* The following buffers are cleared above, no need to add '\0' */
@@ -413,6 +424,7 @@ add_device(char *path, char *device, int
       strlcpy(disks[numdisks].device, device, sizeof(disks[numdisks].device));
       disks[numdisks].minimumspace = minspace;
       disks[numdisks].minpercent   = minpercent;
+      disks[numdisks].alive        = 1;
       numdisks++;  
     }
     else {
@@ -420,6 +432,7 @@ add_device(char *path, char *device, int
       disks[numdisks].minpercent = -1;
       disks[numdisks].path[0] = 0;
       disks[numdisks].device[0] = 0;
+      disks[numdisks].alive = 0;
     }
   }
 }
@@ -444,7 +457,7 @@ int disk_exists(char *path)
 }
 
 static void 
-find_and_add_allDisks(int minpercent)
+refresh_disk_table(int addNewDisks, int minpercent)
 {
 #if HAVE_GETMNTENT
 #if HAVE_SYS_MNTTAB_H
@@ -480,7 +493,7 @@ find_and_add_allDisks(int minpercent)
       return;
   }
   while (mntfp && NULL != (mntent = getmntent(mntfp))) {
-    add_device(mntent->mnt_dir, mntent->mnt_fsname, -1, minpercent, 0);
+    add_device(mntent->mnt_dir, mntent->mnt_fsname, -1, minpercent, addNewDisks, 0);
     dummy = 1;
   }
   if (mntfp)
@@ -497,7 +510,7 @@ find_and_add_allDisks(int minpercent)
       return;
   }
   while ((i = getmntent(mntfp, &mnttab)) == 0) {
-    add_device(mnttab.mnt_mountp, mnttab.mnt_special, -1, minpercent, 0);
+    add_device(mnttab.mnt_mountp, mnttab.mnt_special, -1, minpercent, addNewDisks, 0);
     dummy = 1;
   }
   fclose(mntfp);
@@ -510,7 +523,7 @@ find_and_add_allDisks(int minpercent)
 #elif HAVE_FSTAB_H
   setfsent();			/* open /etc/fstab */
   while((fstab1 = getfsent()) != NULL) {
-    add_device(fstab1->fs_file, fstab1->fs_spec, -1, minpercent, 0);
+    add_device(fstab1->fs_file, fstab1->fs_spec, -1, minpercent, addNewDisks, 0);
     dummy = 1;
   }
   endfsent();			/* close /etc/fstab */
@@ -521,7 +534,7 @@ find_and_add_allDisks(int minpercent)
     mntsize = getmntinfo(&mntbuf, MNT_NOWAIT);
     for (i = 0; i < mntsize; i++) {
       if (strncmp(mntbuf[i].f_fstypename, "zfs", 3) == 0) {
-	add_device(mntbuf[i].f_mntonname, mntbuf[i].f_mntfromname, -1, minpercent, 0);
+    	add_device(mntbuf[i].f_mntonname, mntbuf[i].f_mntfromname, -1, minpercent, addNewDisks, 0);
       }
     }
   }
@@ -537,7 +550,7 @@ find_and_add_allDisks(int minpercent)
    * statfs we default to the root partition "/"
    */
   if (statfs("/", &statf) == 0) {
-    add_device("/", statf.f_mntfromname, -1, minpercent, 0);
+    add_device("/", statf.f_mntfromname, -1, minpercent, addNewDisks, 0);
   }
 #endif
   else {
@@ -696,6 +709,10 @@ fill_dsk_entry(int disknum, struct dsk_e
 #endif
 #endif
 
+    if (disks[disknum].alive == 0){
+        return -1;
+    }
+
     entry->dskPercentInode = -1;
 
 #if defined(HAVE_STATVFS) || defined(HAVE_STATFS)
@@ -826,6 +843,13 @@ var_extensible_disk(struct variable *vp,
     static long     long_ret;
     static char    *errmsg;
 
+    int i;
+    for (i = 0; i < numdisks; i++){
+        disks[i].alive = 0;
+    }
+    /* dynamically add new disks + update alive flag */
+    refresh_disk_table(allDisksIncluded, allDisksMinPercent);
+
 tryAgain:
     if (header_simple_table
         (vp, name, length, exact, var_len, write_method, numdisks))