Blame SOURCES/net-snmp-5.7.2-dskTable-dynamic.patch

9a6c41
commit e3fc76e0ae502fb8ef0aac87eee237db9d9690f5
9a6c41
Author: Jan Safranek <jsafranek@users.sourceforge.net>
9a6c41
Date:   Tue Jul 9 14:26:59 2013 +0200
9a6c41
9a6c41
    CHANGES: snmpd: Make UCD-SNMP::dskTable dynamic if includeAllDisks is set.
9a6c41
9a6c41
diff --git a/agent/mibgroup/ucd-snmp/disk_hw.c b/agent/mibgroup/ucd-snmp/disk_hw.c
9a6c41
index ea37610..f7911d9 100644
9a6c41
--- a/agent/mibgroup/ucd-snmp/disk_hw.c
9a6c41
+++ b/agent/mibgroup/ucd-snmp/disk_hw.c
9a6c41
@@ -55,6 +55,7 @@ static netsnmp_fsys_info ** _expand_disk_array( char *cptr );
9a6c41
 
9a6c41
 int             numdisks;
9a6c41
 int             allDisksIncluded = 0;
9a6c41
+int             allDisksMinPercent = 0;
9a6c41
 int             maxdisks = 0;
9a6c41
 netsnmp_fsys_info **disks = NULL;
9a6c41
 
9a6c41
@@ -119,6 +120,7 @@ init_disk_hw(void)
9a6c41
 				disk_free_config,
9a6c41
 				"minpercent%");
9a6c41
   allDisksIncluded = 0;
9a6c41
+  allDisksMinPercent = 0;
9a6c41
 }
9a6c41
 
9a6c41
 static void
9a6c41
@@ -140,6 +142,7 @@ disk_free_config(void)
9a6c41
      maxdisks = numdisks = 0;
9a6c41
   }
9a6c41
   allDisksIncluded = 0;
9a6c41
+  allDisksMinPercent = 0;
9a6c41
 }
9a6c41
 
9a6c41
 static void 
9a6c41
@@ -199,8 +202,7 @@ static void
9a6c41
 disk_parse_config_all(const char *token, char *cptr)
9a6c41
 {
9a6c41
   int             minpercent = DISKMINPERCENT;
9a6c41
-  netsnmp_fsys_info *entry;
9a6c41
-    
9a6c41
+
9a6c41
   /*
9a6c41
    * read the minimum disk usage percent
9a6c41
    */
9a6c41
@@ -220,30 +222,36 @@ disk_parse_config_all(const char *token, char *cptr)
9a6c41
       netsnmp_config_error("\tignoring: includeAllDisks %s", cptr);
9a6c41
   }
9a6c41
   else {
9a6c41
-
9a6c41
-      netsnmp_fsys_load( NULL, NULL );  /* Prime the fsys H/W module */
9a6c41
-      for ( entry  = netsnmp_fsys_get_first();
9a6c41
-            entry != NULL;
9a6c41
-            entry  = netsnmp_fsys_get_next( entry )) {
9a6c41
-
9a6c41
-          if ( !(entry->flags & NETSNMP_FS_FLAG_ACTIVE ))
9a6c41
-              continue;
9a6c41
-          entry->minspace   = -1;
9a6c41
-          entry->minpercent = minpercent;
9a6c41
-          entry->flags     |= NETSNMP_FS_FLAG_UCD;
9a6c41
-          /*
9a6c41
-           * Ensure there is space for the new entry
9a6c41
-           */
9a6c41
-          if (numdisks == maxdisks) {
9a6c41
-              if (!_expand_disk_array( entry->device )) 
9a6c41
-                  return;
9a6c41
-          }
9a6c41
-          disks[numdisks++] = entry;
9a6c41
-      }
9a6c41
       allDisksIncluded = 1;
9a6c41
+      allDisksMinPercent = minpercent;
9a6c41
   }
9a6c41
 }
9a6c41
 
9a6c41
+/* add new entries to dskTable dynamically */
9a6c41
+static void _refresh_disks(int minpercent)
9a6c41
+{
9a6c41
+    netsnmp_fsys_info *entry;
9a6c41
+
9a6c41
+    for ( entry  = netsnmp_fsys_get_first();
9a6c41
+        entry != NULL;
9a6c41
+        entry  = netsnmp_fsys_get_next( entry )) {
9a6c41
+
9a6c41
+        if (!(entry->flags & NETSNMP_FS_FLAG_UCD)) {
9a6c41
+            /* this is new disk, add it to the table */
9a6c41
+            entry->minspace   = -1;
9a6c41
+            entry->minpercent = minpercent;
9a6c41
+            entry->flags     |= NETSNMP_FS_FLAG_UCD;
9a6c41
+            /*
9a6c41
+             * Ensure there is space for the new entry
9a6c41
+             */
9a6c41
+            if (numdisks == maxdisks) {
9a6c41
+                if (!_expand_disk_array( entry->device ))
9a6c41
+                    return;
9a6c41
+            }
9a6c41
+            disks[numdisks++] = entry;
9a6c41
+        }
9a6c41
+    }
9a6c41
+}
9a6c41
 
9a6c41
 static int _percent( unsigned long long value, unsigned long long total ) {
9a6c41
     float v=value, t=total, pct;
9a6c41
@@ -301,7 +309,7 @@ var_extensible_disk(struct variable *vp,
9a6c41
                     size_t * var_len, WriteMethod ** write_method)
9a6c41
 {
9a6c41
     int             disknum = 0;
9a6c41
-  netsnmp_fsys_info *entry;
9a6c41
+    netsnmp_fsys_info *entry;
9a6c41
     unsigned long long val;
9a6c41
     static long     long_ret;
9a6c41
     static char     errmsg[300];
9a6c41
@@ -310,6 +318,8 @@ var_extensible_disk(struct variable *vp,
9a6c41
     /* Update the fsys H/W module */
9a6c41
     cache = netsnmp_fsys_get_cache();
9a6c41
     netsnmp_cache_check_and_reload(cache);
9a6c41
+    if (allDisksIncluded)
9a6c41
+        _refresh_disks(allDisksMinPercent);
9a6c41
 
9a6c41
 tryAgain:
9a6c41
     if (header_simple_table
9a6c41
@@ -318,9 +328,14 @@ tryAgain:
9a6c41
     disknum = name[*length - 1] - 1;
9a6c41
     entry = disks[disknum];
9a6c41
     if ( !entry ) {
9a6c41
-        if (!exact || !(entry->flags & NETSNMP_FS_FLAG_UCD))
9a6c41
-            goto tryAgain;
9a6c41
-        return NULL;
9a6c41
+        if (exact)
9a6c41
+            return NULL;
9a6c41
+        goto tryAgain;
9a6c41
+    }
9a6c41
+    if (!(entry->flags & NETSNMP_FS_FLAG_ACTIVE) || !(entry->flags & NETSNMP_FS_FLAG_UCD)) {
9a6c41
+        if (exact)
9a6c41
+            return NULL;
9a6c41
+        goto tryAgain;
9a6c41
     }
9a6c41
 
9a6c41
     switch (vp->magic) {
9a6c41
diff --git a/man/snmpd.conf.5.def b/man/snmpd.conf.5.def
9a6c41
index 5f85f72..d2caf9c 100644
9a6c41
--- a/man/snmpd.conf.5.def
9a6c41
+++ b/man/snmpd.conf.5.def
9a6c41
@@ -652,6 +652,8 @@ This requires that the agent was built with support for the
9a6c41
 default build configuration).
9a6c41
 .IP "disk PATH [ MINSPACE | MINPERCENT% ]"
9a6c41
 monitors the disk mounted at PATH for available disk space.
9a6c41
+Disks mounted after the agent has started will not be monitored,
9a6c41
+unless \fIincludeAllDisks\fR option is specified.
9a6c41
 .IP
9a6c41
 The minimum threshold can either be specified in kB (MINSPACE) or
9a6c41
 as a percentage of the total disk (MINPERCENT% with a '%' character),
9a6c41
@@ -668,6 +670,9 @@ the problem - see the DisMan Event MIB section later.
9a6c41
 .IP "includeAllDisks MINPERCENT%"
9a6c41
 configures monitoring of all disks found on the system,
9a6c41
 using the specified (percentage) threshold.
9a6c41
+The \fCdskTable\fR is dynamically updated, unmounted disks
9a6c41
+disappear from the table and newly mounted disks are
9a6c41
+added to the table.
9a6c41
 The threshold for individual disks can be adjusted using suitable
9a6c41
 \fIdisk\fR directives (which can come either before or after the
9a6c41
 \fIincludeAllDisks\fR directive).
9a6c41
@@ -680,12 +685,8 @@ may affect the indexing of the \fCdskTable\fR.
9a6c41
 Only one \fIincludeAllDisks\fR directive should be specified - any
9a6c41
 subsequent copies will be ignored.
9a6c41
 .IP
9a6c41
-The list of mounted disks will be determined when the agent starts using the
9a6c41
-setmntent(3) and getmntent(3), or fopen(3) and getmntent(3),  or
9a6c41
-setfsent(3)  and  getfsent(3) system calls. If none of the above
9a6c41
-system calls are available then the root partition  "/"
9a6c41
-(which  is  assumed to exist on any UNIX based system) will be monitored.
9a6c41
-Disks mounted after the agent has started will not be monitored.
9a6c41
+The list of mounted disks will be determined from
9a6c41
+HOST-RESOURCES-MIB::hrFSTable.
9a6c41
 .\"
9a6c41
 .\" XXX - unless the config is re-read ??
9a6c41
 .\"