简体   繁体   English

通过传递从snmp-get值丢失

[英]snmp-get value from pass is missing

I want to read a GPIO-pin of a RaspberryPi via snmp. 我想通过snmp读取RaspberryPi的GPIO引脚。 I wrote a script in python to read the pin. 我用python编写了一个脚本来读取图钉。 For testing purposes I delivered the value 17 and 99. 为了进行测试,我提供了值17和99。

/usr/local/bin/snmp-gpio17.py : /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 : 该脚本由/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 /etc/snmp/snmpd.conf ,我添加了这一行

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: 当我在RasPi上运行脚本时,它可以工作:

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: 但是当我尝试读取OID(本地或通过网络)时,我得到了:

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. 我还通过另一条通过线通过snmp设置了CPU温度的测量,并且工作正常。 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. 因此snmp通讯似乎还可以(我将答案与wireshark进行了比较),但是RasPi上的snmpd从bash脚本中获取了错误的信息。

Anyone have an idea? 有人有主意吗?

Regards, Karl 问候,卡尔

[solved] It works now, even if I remove user snmp from group gpio. [解决]现在就可以使用,即使我从组gpio中删除了用户snmp。 My problem in testing was, that I did not wait between two tests. 我在测试中遇到的问题是,我没有在两次测试之间等待。 I found out, that snmpd on the RasPi caches the result of a get for 30 seconds. 我发现,RasPi上的snmpd将获取结果缓存30秒。 Only if you wait that long, you get the new result! 只有等待了这么长时间,您才能获得新的结果! Thanks to all 谢谢大家

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM