我们如何在Linux中动态更新MIB变量值?
我创建了一个MIB文件,其中添加了五个变量。另外,通过使用以下命令,
snmptranslate -m +GET-LATEST-SIGNALS-MIB -IR -On oversightInteger
我可以看到所有Varialbes的OID。
之后,通过使用“通过协议”,我尝试借助关注脚本文件从一个变量中获取数据
#!/bin/sh -f
PLACE=".1.3.6.1.4.1.53864.1.1"
REQ="$2" # Requested OID
#
# Process SET requests by simply logging the assigned value
# Note that such "assignments" are not persistent,
# nor is the syntax or requested value validated
#
if [ "$1" = "-s" ]; then
echo $* >> /tmp/passtest.log
exit 0
fi
#
# GETNEXT requests - determine next valid instance
#
if [ "$1" = "-n" ]; then
case "$REQ" in
$PLACE| \
$PLACE.0| \
$PLACE.0.*| \
$PLACE.1) RET=$PLACE.1.0 ;; # netSnmpPassString.0
$PLACE.1.*| \
$PLACE.2| \
$PLACE.2.0| \
$PLACE.2.0.*| \
$PLACE.2.1| \
$PLACE.2.1.0| \
$PLACE.2.1.0.*| \
$PLACE.2.1.1| \
$PLACE.2.1.1.*| \
$PLACE.2.1.2| \
$PLACE.2.1.2.0) RET=$PLACE.2.1.2.1 ;; # netSnmpPassInteger.1
$PLACE.2.1.2.*| \
$PLACE.2.1.3| \
$PLACE.2.1.3.0) RET=$PLACE.2.1.3.1 ;; # netSnmpPassOID.1
$PLACE.2.*| \
$PLACE.3) RET=$PLACE.3.0 ;; # netSnmpPassTimeTicks.0
$PLACE.3.*| \
$PLACE.4) RET=$PLACE.4.0 ;; # netSnmpPassIpAddress.0
$PLACE.4.*| \
$PLACE.5) RET=$PLACE.5.0 ;; # netSnmpPassCounter.0
$PLACE.5.*| \
$PLACE.6) RET=$PLACE.6.0 ;; # netSnmpPassGauge.0
*) exit 0 ;;
esac
else
#
# GET requests - check for valid instance
#
case "$REQ" in
$PLACE.1.0| \
$PLACE.2.1.2.1| \
$PLACE.2.1.3.1| \
$PLACE.3.0| \
$PLACE.4.0| \
$PLACE.5.0| \
$PLACE.6.0) RET=$REQ ;;
*) exit 0 ;;
esac
fi
#
# "Process" GET* requests - return hard-coded value
#
echo "$RET"
case "$RET" in
$PLACE.1.0) echo "string"; echo "Life, the Universe, and Everything"; exit 0 ;;
$PLACE.2.1.2.1) echo "integer"; echo "42"; exit 0 ;;
$PLACE.2.1.3.1) echo "objectid"; echo "$PLACE.99"; exit 0 ;;
$PLACE.3.0) echo "timeticks"; echo "363136200"; exit 0 ;;
$PLACE.4.0) echo "ipaddress"; echo "127.0.0.1"; exit 0 ;;
$PLACE.5.0) echo "counter"; echo "42"; exit 0 ;;
$PLACE.6.0) echo "gauge"; echo "42"; exit 0 ;;
*) echo "string"; echo "ack... $RET $REQ"; exit 0 ;; # Should not happen
esac
运行上面的脚本文件后,我使用以下命令
snmpwalk -v2c localhost -c public .1.3.6.1.4.1.53864
和输出,
GET-LATEST-SIGNALS-MIB::oversightInteger.1.0 = STRING: "Life, the
Universe, and Everything"
GET-LATEST-SIGNALS-MIB::oversightInteger.2.1.2.1 = Wrong Type
(should be OCTET STRING): INTEGER: 42
GET-LATEST-SIGNALS-MIB::oversightInteger.2.1.3.1 = Wrong Type
(should be OCTET STRING): OID: GET-LATEST-SIGNALS-
MIB::oversightInteger.99
GET-LATEST-SIGNALS-MIB::oversightInteger.3.0 = Wrong Type (should
be OCTET STRING): Timeticks: (363136200) 42 days, 0:42:42.00
GET-LATEST-SIGNALS-MIB::oversightInteger.4.0 = Wrong Type (should
be OCTET STRING): IpAddress: 127.0.0.1
GET-LATEST-SIGNALS-MIB::oversightInteger.5.0 = Wrong Type (should
e OCTET STRING): Counter32: 42
GET-LATEST-SIGNALS-MIB::oversightInteger.6.0 = Wrong Type (should
be OCTET STRING): Gauge32: 42
因此现在我想动态地更改“生命,宇宙和所有内容”的值,以便我们如何动态地更改OID值?
我现在呆了将近2周,所以任何帮助都将不胜感激!!
I have created one mib file where five variables are added. Also by using the following command
snmptranslate -m +GET-LATEST-SIGNALS-MIB -IR -On oversightInteger
I'm able to see the OID's of the all varialbes.
After this by using "PASS protocol" I tried to get the data from the one variable with the help of following script file
#!/bin/sh -f
PLACE=".1.3.6.1.4.1.53864.1.1"
REQ="$2" # Requested OID
#
# Process SET requests by simply logging the assigned value
# Note that such "assignments" are not persistent,
# nor is the syntax or requested value validated
#
if [ "$1" = "-s" ]; then
echo $* >> /tmp/passtest.log
exit 0
fi
#
# GETNEXT requests - determine next valid instance
#
if [ "$1" = "-n" ]; then
case "$REQ" in
$PLACE| \
$PLACE.0| \
$PLACE.0.*| \
$PLACE.1) RET=$PLACE.1.0 ;; # netSnmpPassString.0
$PLACE.1.*| \
$PLACE.2| \
$PLACE.2.0| \
$PLACE.2.0.*| \
$PLACE.2.1| \
$PLACE.2.1.0| \
$PLACE.2.1.0.*| \
$PLACE.2.1.1| \
$PLACE.2.1.1.*| \
$PLACE.2.1.2| \
$PLACE.2.1.2.0) RET=$PLACE.2.1.2.1 ;; # netSnmpPassInteger.1
$PLACE.2.1.2.*| \
$PLACE.2.1.3| \
$PLACE.2.1.3.0) RET=$PLACE.2.1.3.1 ;; # netSnmpPassOID.1
$PLACE.2.*| \
$PLACE.3) RET=$PLACE.3.0 ;; # netSnmpPassTimeTicks.0
$PLACE.3.*| \
$PLACE.4) RET=$PLACE.4.0 ;; # netSnmpPassIpAddress.0
$PLACE.4.*| \
$PLACE.5) RET=$PLACE.5.0 ;; # netSnmpPassCounter.0
$PLACE.5.*| \
$PLACE.6) RET=$PLACE.6.0 ;; # netSnmpPassGauge.0
*) exit 0 ;;
esac
else
#
# GET requests - check for valid instance
#
case "$REQ" in
$PLACE.1.0| \
$PLACE.2.1.2.1| \
$PLACE.2.1.3.1| \
$PLACE.3.0| \
$PLACE.4.0| \
$PLACE.5.0| \
$PLACE.6.0) RET=$REQ ;;
*) exit 0 ;;
esac
fi
#
# "Process" GET* requests - return hard-coded value
#
echo "$RET"
case "$RET" in
$PLACE.1.0) echo "string"; echo "Life, the Universe, and Everything"; exit 0 ;;
$PLACE.2.1.2.1) echo "integer"; echo "42"; exit 0 ;;
$PLACE.2.1.3.1) echo "objectid"; echo "$PLACE.99"; exit 0 ;;
$PLACE.3.0) echo "timeticks"; echo "363136200"; exit 0 ;;
$PLACE.4.0) echo "ipaddress"; echo "127.0.0.1"; exit 0 ;;
$PLACE.5.0) echo "counter"; echo "42"; exit 0 ;;
$PLACE.6.0) echo "gauge"; echo "42"; exit 0 ;;
*) echo "string"; echo "ack... $RET $REQ"; exit 0 ;; # Should not happen
esac
After running the above script file I used the following command
snmpwalk -v2c localhost -c public .1.3.6.1.4.1.53864
and the output i got as follows
GET-LATEST-SIGNALS-MIB::oversightInteger.1.0 = STRING: "Life, the
Universe, and Everything"
GET-LATEST-SIGNALS-MIB::oversightInteger.2.1.2.1 = Wrong Type
(should be OCTET STRING): INTEGER: 42
GET-LATEST-SIGNALS-MIB::oversightInteger.2.1.3.1 = Wrong Type
(should be OCTET STRING): OID: GET-LATEST-SIGNALS-
MIB::oversightInteger.99
GET-LATEST-SIGNALS-MIB::oversightInteger.3.0 = Wrong Type (should
be OCTET STRING): Timeticks: (363136200) 42 days, 0:42:42.00
GET-LATEST-SIGNALS-MIB::oversightInteger.4.0 = Wrong Type (should
be OCTET STRING): IpAddress: 127.0.0.1
GET-LATEST-SIGNALS-MIB::oversightInteger.5.0 = Wrong Type (should
e OCTET STRING): Counter32: 42
GET-LATEST-SIGNALS-MIB::oversightInteger.6.0 = Wrong Type (should
be OCTET STRING): Gauge32: 42
So now I wanted to change the value"Life, the Universe, and Everything" dynamically so how we can change the oid values dynamically?.
I'm stuck at this point for almost 2 weeks now so any help will be really appreciated!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因此,要解决此问题,我包括
sqlite3数据库
。现在,每当我们在
嵌入式C应用程序
(将始终在后面运行)中获取最新值时,我们在数据库中更新该值,因此IF之间接收任何请求,例如设置,获取等,然后脚本将读取数据库以获取MIB Varialbes的最新值,并将发送到MIB浏览器。我们在脚本中使用以下命令来从数据库中获取数据
So to solve this issue I have included a
sqlite3 database
.Now, whenever we will get the latest values in our
embedded c application
(which will be always running behind) we are updating the same in the database so in between ifSNMPD daemon
receives any request for example set, get etc then the script will go and read the database to get the latest values of the mib varialbes and will be sent to the mib browser.We are using the following command in the script to get the data from the database