Update raspberrypi sensor discovery to check for sensor existance #5114

Merged
merged 1 commit into from Dec 7, 2016

Projects

None yet

4 participants

@jquagga
Contributor
jquagga commented Dec 5, 2016

Please note

Please read this information carefully. You can run ./scripts/pre-commit.php to check your code before submitting.

I recently added a RaspberryPi to my network to convert a USB UPS into a Network UPS. As part of that I added snmp to the Pi and added it to my librenms install. What I found is that the existing discovery code for the Pi just assumes that the snmp extend for raspberry.sh is enabled. It discovers sensors which on my install, had no data and it made for a messy page. So I offer this patch for consideration.

It looks like 2 of the 4 sensors have code to validate the data before discovering the sensor, but only one of those works (temperature). So these patches add if code to confirm we get something good back before discover_senors(). It's using is_numeric for all of the numeric sensors and for the codecs, I'm using stripos for "abled" since the options are enabled / disabled.

My main use for this is that is allows me to run my own raspberry.sh snmp extend which only provides temperature data and doesn't require root/sudo. I didn't want to give those permissions to the script/ run vcgencmd on the pi and this patch works nicely to enable that. Also this is a headless box where I'm never going to change the voltage or enable codecs so didn't want to bother polling that.

The attached screenshot shows the existing behavior with a snmp extend only providing temperature data, then the same situation after this patch (the unused sensors disappear). Finally the bottom screenshot is after this patch is applied with a "stock" snmp extend showing the sensors still polled and working.

out-fs8

This code should only run on raspberry pi discovery since it's already in an if block identifying the device as a RPI.

@jquagga jquagga Update raspberrypi sensor discover to check for sensor data
Presently the discovery code enables the raspberry pi snmp extend
sensors without checking to see if the snmp extend has actually
happened.  This adds appropriate checks to make sure that's happened
before enabling the sensor in librenms.
7762874
@scrutinizer-notifier

The inspection completed: 1 new issues

@@ -31,7 +31,7 @@
}
$value = snmp_get($device, $oid.$codec, '-Oqv');
- if (!empty($value)) {
+ if (stripos($value, 'abled') !== false) {
@laf
laf Dec 5, 2016 Member

What output is this trying to match out of interest?

@jquagga
jquagga Dec 6, 2016 Contributor

@laf The options are "enabled" or "disabled" for the codec:

ra:~% dash raspberry.sh 
47.2
1.2000
1.2000
1.2000
1.2250
600062000
250000000
enabled
disabled
disabled
enabled
enabled
disabled

That's the full output of a "normal" raspberry.sh snmp extension. That's the "stock" output on a RPI which hasn't had any of the extra codec's purchased. It's a headless system so they aren't needed.

@jquagga
jquagga Dec 6, 2016 Contributor

I can also modify the stipos() if statement to if ($value = 'enabled' || $value = 'disabled') if the goal was to have some tighter checking on the line.

@laf
laf Dec 7, 2016 Member

No I'm fine with it as is :)

@laf laf merged commit 28e35ef into librenms:master Dec 7, 2016

2 checks passed

Auto-Deploy Build finished.
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@laf laf added the Bug label Dec 7, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment