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