eliteacs
Posts: 7
Joined: Thu Oct 27, 2016 10:18 am

SNMP Script

Fri Dec 02, 2016 12:33 pm

I need help with using SNMP with RaspberryPi.
I'm trying to read the status of an incoming GPIO.
Following your instructions, I created two files and changed the snmpd.conf file
When I do the tests the python script works correctly.
The bash script also works correctly and returns the state of the digital input, but when I put the pass in the snmd.conf file, it only returns 0, even though I change the status physically the read is 0, in the other scripts it returns 0 and 1 more In snmpget only 0.
Following are scripts below.

/home/pi > gpio_23.py

import RPi.GPIO as gpio
import time

gpio.setmode(gpio.BCM)

# Com pull-up interno
gpio.setup(23, gpio.IN, pull_up_down = gpio.PUD_UP)

print (gpio.input(23))

time.sleep(1)
gpio.cleanup()


/usr/local/bin > input23

#!/bin/bash
if [ "$1" = "-g" ]
then
echo .1.3.6.1.2.1.25.1.222
echo gauge
python /home/pi/gpio_23.py
fi
exit 0


/etc/snmp/snmpd.conf
...
# "Pass-through" MIB extension command
#
#pass .1.3.6.1.4.1.8072.2.255 /bin/sh PREFIX/local/passtest
#pass .1.3.6.1.4.1.8072.2.255 /usr/bin/perl PREFIX/local/passtest.pl

pass .1.3.6.1.2.1.25.1.8 /bin/sh /usr/local/bin/snmp-cpu-temp
pass .1.3.6.1.2.1.25.1.222 /bin/sh /usr/local/bin/input23

# Note that this requires one of the two 'passtest' scripts to be installed fir$
# before the appropriate line is uncommented.
# These scripts can be found in the 'local' directory of the source distributio$
# and are not installed automatically.




Results:

root@raspberrypi:/home/pi# snmpget -v 2c localhost -c public .1.3.6.1.2.1.25.1.222
iso.3.6.1.2.1.25.1.222 = Gauge32: 0

root@raspberrypi:/home/pi# python gpio_23.py
1

root@raspberrypi:/usr/local/bin# ./input23 -g
.1.3.6.1.2.1.25.1.222
gauge
1


Thank you in advance

José Luiz Vieira.


Return to “Advanced users”