如何在linux下动态更新MIB变量值?



我创建了一个mib文件,其中添加了五个变量。还可以使用以下命令

snmptranslate -m +GET-LATEST-SIGNALS-MIB -IR -On oversightInteger

我可以看到所有变量的OID。

之后使用"PASS协议"我试图在以下脚本文件

的帮助下从一个变量中获取数据

#!/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周了,所以任何帮助都会非常感激!!

所以为了解决这个问题,我包含了一个sqlite3 database

现在,每当我们在embedded c application中获得最新值(它将始终运行在后面)时,我们都会在数据库中更新相同的值,因此在SNMPD daemon接收到任何请求(例如set, get等)之间,脚本将去读取数据库以获取mib变量的最新值,并将被发送到mib浏览器。

我们在脚本中使用以下命令从数据库

获取数据
echo "$(sqlite3 /home/root/database/pdu.db <<'END_SQL'
.timeout 2000
SELECT Variable_Value FROM Data Where Sr_No='2';
END_SQL)

相关内容

  • 没有找到相关文章

最新更新