Poller.php returns same values for custom sensors

Hi everyone,

I’ve created several sensors for certain device, but when using ./poller.php I’ve discovered that all the sensors have the same value.

./discovery.php seems to return the proper value for each OID, but not ./poller.php.

On the Web UI, all the sensors have the same value.

I pasted here part of the ./discovery.php and ./poller.php to better understand.

← ./discovery.php →

SNMP[‘/usr/bin/snmpget’ ‘-v2c’ ‘-c’ ‘COMMUNITY’ ‘-Oqv’ ‘-M’ ‘/opt/librenms/mibs:/opt/librenms/mibs/calix’ ‘udp:HOSTNAME:161’ ‘.1.3.6.1.4.1.6321.1.2.2.2.1.6.2.1.5.1.1.1’]
32

Discover sensor: .1.3.6.1.4.1.6321.1.2.2.2.1.6.2.1.5.1.1.1, 1.1.1, exa, Gpon 1/1/1, snmp, 1, 1, , 32, (limits: LL: , LW: , W: , H: ), rrd_type = GAUGE
SQL[SELECT COUNT(sensor_id) FROM sensors WHERE poller_type= ? AND sensor_class = ? AND device_id = ? AND sensor_type = ? AND sensor_index = ? [“snmp”,“temperature”,702,“exa”,“1.1.1”] 0.93ms]

SQL[SELECT * FROM sensors WHERE sensor_class = ? AND device_id = ? AND sensor_type = ? AND sensor_index = ? [“temperature”,702,“exa”,“1.1.1”] 0.67ms]

.SNMP[‘/usr/bin/snmpget’ ‘-v2c’ ‘-c’ ‘COMMUNITY’ ‘-Oqv’ ‘-M’ ‘/opt/librenms/mibs:/opt/librenms/mibs/calix’ ‘udp:HOSTNAME:161’ ‘.1.3.6.1.4.1.6321.1.2.2.2.1.6.2.1.5.1.1.2’]
0

Discover sensor: .1.3.6.1.4.1.6321.1.2.2.2.1.6.2.1.5.1.1.2, 1.1.2, exa, Gpon 1/1/2, snmp, 1, 1, , 0, (limits: LL: , LW: , W: , H: ), rrd_type = GAUGE
SQL[SELECT COUNT(sensor_id) FROM sensors WHERE poller_type= ? AND sensor_class = ? AND device_id = ? AND sensor_type = ? AND sensor_index = ? [“snmp”,“temperature”,702,“exa”,“1.1.2”] 0.94ms]

SQL[SELECT * FROM sensors WHERE sensor_class = ? AND device_id = ? AND sensor_type = ? AND sensor_index = ? [“temperature”,702,“exa”,“1.1.2”] 0.6ms]

.SNMP[‘/usr/bin/snmpget’ ‘-v2c’ ‘-c’ ‘COMMUNITY’ ‘-Oqv’ ‘-M’ ‘/opt/librenms/mibs:/opt/librenms/mibs/calix’ ‘udp:HOSTNAME:161’ ‘.1.3.6.1.4.1.6321.1.2.2.2.1.6.2.1.5.1.1.3’]
0

Discover sensor: .1.3.6.1.4.1.6321.1.2.2.2.1.6.2.1.5.1.1.3, 1.1.3, exa, Gpon 1/1/3, snmp, 1, 1, , 0, (limits: LL: , LW: , W: , H: ), rrd_type = GAUGE
SQL[SELECT COUNT(sensor_id) FROM sensors WHERE poller_type= ? AND sensor_class = ? AND device_id = ? AND sensor_type = ? AND sensor_index = ? [“snmp”,“temperature”,702,“exa”,“1.1.3”] 0.6ms]

SQL[SELECT * FROM sensors WHERE sensor_class = ? AND device_id = ? AND sensor_type = ? AND sensor_index = ? [“temperature”,702,“exa”,“1.1.3”] 0.59ms]

.SNMP[‘/usr/bin/snmpget’ ‘-v2c’ ‘-c’ ‘COMMUNITY’ ‘-Oqv’ ‘-M’ ‘/opt/librenms/mibs:/opt/librenms/mibs/calix’ ‘udp:HOSTNAME:161’ ‘.1.3.6.1.4.1.6321.1.2.2.2.1.6.2.1.5.1.1.4’]
0

Discover sensor: .1.3.6.1.4.1.6321.1.2.2.2.1.6.2.1.5.1.1.4, 1.1.4, exa, Gpon 1/1/4, snmp, 1, 1, , 0, (limits: LL: , LW: , W: , H: ), rrd_type = GAUGE
SQL[SELECT COUNT(sensor_id) FROM sensors WHERE poller_type= ? AND sensor_class = ? AND device_id = ? AND sensor_type = ? AND sensor_index = ? [“snmp”,“temperature”,702,“exa”,“1.1.4”] 0.72ms]

← END →

← ./poller.php →

SNMP[‘/usr/bin/snmpget’ ‘-v2c’ ‘-c’ ‘COMMUNITY’ ‘-OUQntea’ ‘-M’ ‘/opt/librenms/mibs:/opt/librenms/mibs/calix’ ‘udp:HOSTNAME:161’ ‘.1.3.6.1.4.1.6321.1.2.2.2.1.6.2.1.5.1.1.1’ ‘.1.3.6.1.4.1.6321.1.2.2.2.1.6.2.1.5.1.1.2’ ‘.1.3.6.1.4.1.6321.1.2.2.2.1.6.2.1.5.1.1.3’ ‘.1.3.6.1.4.1.6321.1.2.2.2.1.6.2.1.5.1.1.4’]
..4.1.63...1 = 32
..4.1.63...2 = 32
..4.1.63...3 = 32
..4.1.63...4 = 32

← END →

Thank you !

You likely set the num_oid field incorrectly. This oid is used for polling.

Maybe is better to have the code here to better understand:

if (strstr($device['sysObjectID'], '.1.3.6.1.4.1.6321.1.2.2')) { // E7 Series
        echo "Calix E7: ";

        if (strpos($device['sysObjectID'], '.1.3.6.1.4.1.6321.1.2.2.5') !== false) { // E7-2
        $oids = snmp_walk($device, '.1.3.6.1.4.1.6321.1.2.2.2.1.6.2.1.5', '-Osqn', 'E7-CALIX-MIB', 'exa');
        $oids = trim($oids);
        $oids = str_replace('.1.3.6.1.4.1.6321.1.2.2.2.1.6.2.1.5.', '', $oids);
        foreach (explode("\n", $oids) as $data) {
            $data = trim($data);
            if ($data != '') {
                [$oid] = explode(' ', $data);
                $temperature_oid = ".1.3.6.1.4.1.6321.1.2.2.2.1.6.2.1.5.$oid";
                $temperature = snmp_get($device, $temperature_oid, '-Oqv', '');
                $descr = 'Gpon ' . str_replace('.', '/', $oid);
                $current = $temperature;

                discover_sensor($valid['sensor'], 'temperature', $device, $temperature_oid, $oid, 'exa', $descr, '1', '1', null, null, null, null, $current);
            }
        }
    }
}

The snmp_walk returns:

SNMPv2-SMI::enterprises.6321.1.2.2.2.1.6.2.1.5.1.1.1 = INTEGER: 33
SNMPv2-SMI::enterprises.6321.1.2.2.2.1.6.2.1.5.1.1.2 = INTEGER: 0
SNMPv2-SMI::enterprises.6321.1.2.2.2.1.6.2.1.5.1.1.3 = INTEGER: 0
SNMPv2-SMI::enterprises.6321.1.2.2.2.1.6.2.1.5.1.1.4 = INTEGER: 0

Thank you !

FYI, this is the problem with your code $oid will contain the full oid, but you prepended the base oid assuming $oid contains the index.

It doesn’t help that you are copying some very old code. Almost all our snmpwalk functions parse the output for you.