SNMP 添加MIB 节点 (九) --- SNMP.CONF PASS添加节点

首先在/home下建个shell脚本passtest

---------------------------------------------------------------------------------------------------------------------------------

#!/bin/sh
echo $2 #因为snmpd是用EXEC -g MIBOID来调脚本的,所以MIBOID是第二个参数
echo string
echo "hello world"

---------------------------------------------------------------------------------------------------------------------------------

随后在snmod.conf中添加

---------------------------------------------------------------------------------------------------------------------------------

pass .1.3.6.1.4.1.8072.2.255  /bin/sh       /home/passtest

---------------------------------------------------------------------------------------------------------------------------------

之后,执行ubuntu@ubuntu:/usr/local/net-snmp/sbin$ sudo ./snmpd -f -Le
 

管理端执行如下:

ubuntu@ubuntu:/usr/local/net-snmp/bin$ snmpget -v 2c -c public localhost 1.3.6.1.4.1.8072.2.255
NET-SNMP-PASS-MIB::netSnmpPassExamples = STRING: "hello world"
ubuntu@ubuntu:/usr/local/net-snmp/bin$ 
 

添加get,get-next,set

修改脚本内容如下

---------------------------------------------------------------------------------------------------------------------------------

bin/sh

opt=$1
oid=$2

if [ "$opt" = "-g" ]; then
    #do_the_snmpget
    #...
    echo $oid
    echo string
    echo "get operator"
elif [ "$opt" = "-n" ]; then
    #do_the_snmpgetnext
    #...
    echo $oid
    echo string
    echo "get next operator"
elif [ "$opt" = "-s" ]; then
    #do_the_snmpset
    #...
    if_success, exit_directly
    if_fail, echo not-writable or wrong-type
fi

exit 0

---------------------------------------------------------------------------------------------------------------------------------

执行ubuntu@ubuntu:/usr/local/net-snmp/sbin$ sudo ./snmpd -f -Le
 

管理端执行如下:

ubuntu@ubuntu:/usr/local/net-snmp/bin$ snmpget -v 2c -c public localhost 1.3.6.1.4.1.8072.2.255
NET-SNMP-PASS-MIB::netSnmpPassExamples = STRING: "get operator"
ubuntu@ubuntu:/usr/local/net-snmp/bin$ snmpgetnext -v 2c -c public localhost 1.3.6.1.4.1.8072.2.255
NET-SNMP-PASS-MIB::netSnmpPassExamples = STRING: "get next operator"
ubuntu@ubuntu:/usr/local/net-snmp/bin$ snmpset -v 2c -c public localhost 1.3.6.1.4.1.8072.2.255 s "hello world"
NET-SNMP-PASS-MIB::netSnmpPassExamples = STRING: "hello world"
ubuntu@ubuntu:/usr/local/net-snmp/bin$ snmpget -v 2c -c public localhost 1.3.6.1.4.1.8072.2.255
NET-SNMP-PASS-MIB::netSnmpPassExamples = STRING: "get operator"
ubuntu@ubuntu:/usr/local/net-snmp/bin$ 
 

模板来自网上,如下

#!bin/bash

opt=$1
oid=$2

if [ "$opt" = "-g" ]; then
    do_the_snmpget
    ...
    echo $oid
    echo TYPE
    echo VALUE
elif [ "$opt" = "-n" ]; then
    do_the_snmpgetnext
    ...
    echo $oid
    echo TYPE
    echo VALUE
elif [ "$opt" = "-s" ]; then
    do_the_snmpset
    ...
    if_success, exit_directly
    if_fail, echo not-writable or wrong-type
fi

exit 0
上一篇:snmp协议


下一篇:TCP/IP详解 卷1:协议 学习笔记 第二十五章 SNMP:简单网络管理协议