[Python] snmp-get value from pass is missing

Discussão em 'Python' iniciado por Stack, Março 5, 2025.

  1. Stack

    Stack Membro Participativo

    I want to read a GPIO-pin of a RaspberryPi via snmp. I wrote a script in python to read the pin. For testing purposes I delivered the value 17 and 99.

    /usr/local/bin/snmp-gpio17.py:

    #!/usr/bin/python3 -u
    import RPi.GPIO as GPIO
    from time import sleep
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_UP)
    if not GPIO.input(17):
    var=17
    else:
    var=99
    print ( var )


    This script is called by /usr/local/bin/snmp-gpio17.sh:

    #!/bin/bash
    if [ "$1" = "-g" ]
    then
    echo .1.3.6.1.4.1.18565.1.12.101.1.17
    echo gauge
    python /usr/local/bin/snmp-gpio17.py
    fi
    exit 0


    In /etc/snmp/snmpd.conf, I added the line

    pass .1.3.6.1.4.1.18565.1.12.101.1.17 /bin/sh /usr/local/bin/snmp-gpio17.sh


    When I run the script on the RasPi it works:

    root@raspberrypi:~# /usr/local/bin/snmp-gpio17.sh -g
    .1.3.6.1.4.1.18565.1.12.101.1.17
    gauge
    17


    but when I try to read the OID (locally or over the network) I get:

    karls@mintbox ~ $ snmpget -v1 -c public 192.168.129.4 .1.3.6.1.4.1.18565.1.12.101.1.17
    iso.3.6.1.4.1.18565.1.12.101.1.17 = Gauge32: 0


    I also set up measurement of the cpu-temperature via snmp with another pass-line and it works fine. I use nearly the same script:

    #!/bin/bash
    if [ "$1" = "-g" ]
    then
    echo .1.3.6.1.4.1.18565.1.12.101.1.101
    echo gauge
    cat /sys/class/thermal/thermal_zone0/temp
    fi
    exit 0


    So the snmp-communication seems to be OK (I compared answers with wireshark), but snmpd on the RasPi gets wrong information from the bash-script.

    Anyone have an idea?

    Regards, Karl

    Continue reading...

Compartilhe esta Página