9a6c41
Bug 967871 - net-snmp does not display correct lm_sensors sensor data / missing CPU cores
9a6c41
9a6c41
commit e886f5eb9701851ad6948583156bfd59fcb6110f
9a6c41
Author: Jan Safranek <jsafranek@users.sourceforge.net>
9a6c41
Date:   Wed Feb 25 09:30:24 2015 +0100
9a6c41
9a6c41
    CHANGES: snmpd: fixed lm_sensors not reporting sensors with duplicate names.
9a6c41
    
9a6c41
    Some systems report two or more sensors with the same name.
9a6c41
    This patch adds support for reporting of all these duplicate
9a6c41
    sensor names.
9a6c41
    
9a6c41
    Before the patch, these sensors were reported:
9a6c41
    > lmTempSensorsDevice.2 = STRING: Core 0
9a6c41
    
9a6c41
    After the patch, new sensors appear with a prefix:
9a6c41
    > lmTempSensorsDevice.2 = STRING: Core 0
9a6c41
    > lmTempSensorsDevice.6 = STRING: coretemp-isa-0004:Core 0
9a6c41
    
9a6c41
    This approach keeps backward compatibility (applications used to 'Core 0'
9a6c41
    will keep workig, while it adds new sensorscto the table (with a prefix).
9a6c41
9a6c41
diff --git a/agent/mibgroup/hardware/sensors/lmsensors_v3.c b/agent/mibgroup/hardware/sensors/lmsensors_v3.c
9a6c41
index 60af9e6..1de7c68 100644
9a6c41
--- a/agent/mibgroup/hardware/sensors/lmsensors_v3.c
9a6c41
+++ b/agent/mibgroup/hardware/sensors/lmsensors_v3.c
9a6c41
@@ -86,7 +86,28 @@ netsnmp_sensor_arch_load(netsnmp_cache *cache, void *vp) {
9a6c41
                  *  (inserting it in the appropriate sub-containers)
9a6c41
                  */
9a6c41
                 sp = sensor_by_name( label, type );
9a6c41
-                if ( sp ) {
9a6c41
+                if ( sp && sp->flags & NETSNMP_SENSOR_FLAG_ACTIVE) {
9a6c41
+                    /*
9a6c41
+                     * Some HW does not have unique sensors labels.
9a6c41
+                     * We already have a sensor with this label, thus
9a6c41
+                     * try to create unique label by adding chip-name prefix
9a6c41
+                     * and try again.
9a6c41
+                     */
9a6c41
+                    char chip_name[64];
9a6c41
+                    char new_label[128];
9a6c41
+                    int ret;
9a6c41
+                    DEBUGMSGTL(("sensors:arch:detail", "Already know label %s, adding prefix\n", label));
9a6c41
+                    ret = sensors_snprintf_chip_name(chip_name, sizeof(chip_name), chip);
9a6c41
+                    if (ret < 0) {
9a6c41
+                        DEBUGMSGTL(("sensors:arch:detail", "Can't get chip name for label %s\n", label));
9a6c41
+                        free(label);
9a6c41
+                        continue;
9a6c41
+                    }
9a6c41
+                    snprintf(new_label, sizeof(new_label), "%s:%s", chip_name, label);
9a6c41
+                    DEBUGMSGTL(("sensors:arch:detail", "New label: %s\n", new_label));
9a6c41
+                    sp = sensor_by_name( new_label, type );
9a6c41
+                }
9a6c41
+                if (sp) {
9a6c41
                     sp->value = val;
9a6c41
                     sp->flags|= NETSNMP_SENSOR_FLAG_ACTIVE;
9a6c41
                 }