Blame SOURCES/net-snmp-5.5-sensors-duplicate.patch

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