我在snmpd.conf文件中添加了以下两行:
view all included .1.3.6.1.4.1.8072.9999.9999
pass_persist .1.3.6.1.4.1.8072.9999.9999 /root/kshtest
我创建了一个shell脚本(/ root / kshtest),它接受一个文件OIDDEFS,其中包含每个OID,它的类型及其值(用空格分隔)的行:
.1.3.6.1.4.1.8072.9999.9999.1.1 integer 35
.1.3.6.1.4.1.8072.9999.9999.1.2 integer 21
.1.3.6.1.4.1.8072.9999.9999.1.3 integer 56
.1.3.6.1.4.1.8072.9999.9999.2.1 integer 3592
.1.3.6.1.4.1.8072.9999.9999.2.2 integer 2234
.1.3.6.1.4.1.8072.9999.9999.2.3 integer 4499
.1.3.6.1.4.1.8072.9999.9999.2.4 integer 2233
.1.3.6.1.4.1.8072.9999.9999.3.1 integer 6650
.1.3.6.1.4.1.8072.9999.9999.3.2 integer 6650
.1.3.6.1.4.1.8072.9999.9999.3.3 integer 6650
.1.3.6.1.4.1.8072.9999.9999.3.4 integer 6650
.1.3.6.1.4.1.8072.9999.9999.4.1 integer 0
.1.3.6.1.4.1.8072.9999.9999.4.2 integer 0
.1.3.6.1.4.1.8072.9999.9999.4.3 integer 0
.1.3.6.1.4.1.8072.9999.9999.4.4 integer 0
.1.3.6.1.4.1.8072.9999.9999.4.5 integer 0
.1.3.6.1.4.1.8072.9999.9999.4.6 integer 0
.1.3.6.1.4.1.8072.9999.9999.4.7 integer 0
.1.3.6.1.4.1.8072.9999.9999.4.8 integer 0
.1.3.6.1.4.1.8072.9999.9999.4.9 integer 0
.1.3.6.1.4.1.8072.9999.9999.4.10 integer 0
.1.3.6.1.4.1.8072.9999.9999.4.11 integer 0
.1.3.6.1.4.1.8072.9999.9999.4.12 integer 0
并在从命令行运行时提供以下交互:
<- PING
-> PONG
<- get
<- .1.3.6.1.4.1.8072.9999.9999.1.1
-> .1.3.6.1.4.1.8072.9999.9999.1.1
-> integer
-> 35
<- PING
-> PONG
<- getnext
<- .1.3.6.1.4.1.8072.9999.9999.1.1
-> .1.3.6.1.4.1.8072.9999.9999.1.2
-> integer
-> 21
脚本的内容如下(但我认为您可能需要知道的是它的工作方式如上所示):
#!/usr/pkg/bin/ksh93
OIDDEFS=OIDDEFS
IFS=$'\n'
lines=($(< $OIDDEFS))
typeset -A gettype
typeset -A getvalue
typeset -A getnextoid
typeset -A getnexttype
typeset -A getnextvalue
for (( x=0; x<${#lines[*]}; ((x++)) ))
do IFS=$'\t\n '
words=($(echo ${lines[x]}))
gettype[${words[0]}]=${words[1]}
getvalue[${words[0]}]=$(printf "%i\n" ${words[2]})
if [[ x -gt 0 ]]; then
getnextoid[${lines[x-1]%% *}]=${words[0]}
getnexttype[${lines[x-1]%% *}]=${words[1]}
getnextvalue[${lines[x-1]%% *}]=$(printf "%i\n" ${words[2]})
fi
done
while true
do read
if [[ $REPLY == "PING" ]]; then
echo PONG
else
exit 1
fi
x=0
while [[ x -lt 2 ]];
do read REPLY$x
((x++))
done
if [[ $REPLY0 == get ]]; then
echo $REPLY1
echo ${gettype[$REPLY1]}
echo ${getvalue[$REPLY1]}
fi
if [[ $REPLY0 == getnext ]]; then
if [[ ! -v getnextoid[$REPLY1] ]]; then
echo NONE
else
echo ${getnextoid[$REPLY1]}
echo ${getnexttype[$REPLY1]}
echo ${getnextvalue[$REPLY1]}
fi
fi
done
我可以运行'snmpd -f'(虽然我不明白为什么没有-f标志它不会工作)并且做了
snmpgetnext -On -v 2c -c public 127.0.0.1 .1.3.6.1.4.1.8072.9999.9999.1.1
并得到回复:
.1.3.6.1.4.1.8072.9999.9999.1.2 = INTEGER: 21
我可以成功snmpget(net-snmp命令)我的MIB中的任何oid并获取它们的值或snmpgetnext任何oid并获得下一个oid和值。但是,我不能偷偷摸摸我的屁股。当我
snmpwalk -On -v 2c -c public 127.0.0.1 .1.3.6.1.4.1.8072.9999.9999.1.1
我得到了
.1.3.6.1.4.1.8072.9999.9999.1.1 = INTEGER: 35
这与我在该oid上的snmpget获得的响应相同。
snmpwalk -d -v 2c -c public 127.0.0.1 .1.3.6.1.4.1.8072.9999.9999.1.1
给了我:
Sending 48 bytes to UDP: [127.0.0.1]:161->[0.0.0.0]:0
0000: 30 2E 02 01 01 04 06 70 75 62 6C 69 63 A1 21 02 0......public.!.
0016: 04 7F 15 82 9A 02 01 00 02 01 00 30 13 30 11 06 ...........0.0..
0032: 0D 2B 06 01 04 01 BF 08 CE 0F CE 0F 01 01 05 00 .+..............
Received 49 byte packet from UDP: [127.0.0.1]:161->[0.0.0.0]:65489
0000: 30 2F 02 01 01 04 06 70 75 62 6C 69 63 A2 22 02 0/.....public.".
0016: 04 7F 15 82 9A 02 01 00 02 01 00 30 14 30 12 06 ...........0.0..
0032: 0D 2B 06 01 04 01 BF 08 CE 0F CE 0F 01 02 02 01 .+..............
0048: 15 .
Sending 48 bytes to UDP: [127.0.0.1]:161->[0.0.0.0]:0
0000: 30 2E 02 01 01 04 06 70 75 62 6C 69 63 A0 21 02 0......public.!.
0016: 04 7F 15 82 9B 02 01 00 02 01 00 30 13 30 11 06 ...........0.0..
0032: 0D 2B 06 01 04 01 BF 08 CE 0F CE 0F 01 01 05 00 .+..............
Received 49 byte packet from UDP: [127.0.0.1]:161->[0.0.0.0]:65489
0000: 30 2F 02 01 01 04 06 70 75 62 6C 69 63 A2 22 02 0/.....public.".
0016: 04 7F 15 82 9B 02 01 00 02 01 00 30 14 30 12 06 ...........0.0..
0032: 0D 2B 06 01 04 01 BF 08 CE 0F CE 0F 01 01 02 01 .+..............
0048: 23 #
NET-SNMP-MIB::monoCount = INTEGER: 35
,它似乎是.1.3.6.1.4.1.8072.9999.9999.1.1的snmpgetnext,后面跟着一个snmpgetresponse引用.1.3.6.1.4.1.8072.9999.9999.1.2,然后是.1.3.6.1的snmpget .4.1.8072.9999.9999.1.1,后跟snmpgetresponse引用.1.3.6.1.4.1.8072.9999.9999.1.1。
我的NET-SNMP-MIB.txt文件,我更改为添加MIB值如下:
NET-SNMP-MIB DEFINITIONS ::= BEGIN
--
-- Top-level infrastructure of the Net-SNMP project enterprise MIB tree
--
IMPORTS
MODULE-IDENTITY, Integer32, enterprises FROM SNMPv2-SMI;
netSnmp MODULE-IDENTITY
LAST-UPDATED "200201300000Z"
ORGANIZATION "www.net-snmp.org"
CONTACT-INFO
"postal: Wes Hardaker
P.O. Box 382
Davis CA 95617
email: net-snmp-coders@lists.sourceforge.net"
DESCRIPTION
"Top-level infrastructure of the Net-SNMP project enterprise MIB tree"
REVISION "200201300000Z"
DESCRIPTION
"First draft"
::= { enterprises 8072}
--
-- Net-SNMP enterprise-specific management objects
--
netSnmpObjects OBJECT IDENTIFIER ::= {netSnmp 1}
-- netSnmpExamples OBJECT IDENTIFIER ::= {netSnmp 2}
netSnmpEnumerations OBJECT IDENTIFIER ::= {netSnmp 3}
netSnmpModuleIDs OBJECT IDENTIFIER ::= {netSnmpEnumerations 1}
netSnmpAgentOIDs OBJECT IDENTIFIER ::= {netSnmpEnumerations 2}
netSnmpDomains OBJECT IDENTIFIER ::= {netSnmpEnumerations 3}
netSnmpExperimental OBJECT IDENTIFIER ::= {netSnmp 9999}
--
-- A subtree specifically designed for private testing purposes.
-- No "public" management objects should ever be defined within this tree.
--
-- It is provided for private experimentation, prior to transferring a MIB
-- structure to another part of the overall OID tree
--
netSnmpPlaypen OBJECT IDENTIFIER ::= {netSnmpExperimental 9999}
--
-- Notifications
--
netSnmpNotificationPrefix OBJECT IDENTIFIER ::= {netSnmp 4}
netSnmpNotifications OBJECT IDENTIFIER ::= {netSnmpNotificationPrefix 0}
netSnmpNotificationObjects OBJECT IDENTIFIER ::= {netSnmpNotificationPrefix 1}
--
-- Conformance
-- (No laughing at the back!)
--
netSnmpConformance OBJECT IDENTIFIER ::= {netSnmp 5}
netSnmpCompliances OBJECT IDENTIFIER ::= {netSnmpConformance 1}
netSnmpGroups OBJECT IDENTIFIER ::= {netSnmpConformance 2}
-- start additions:
pageCountsVals OBJECT IDENTIFIER ::= {netSnmpPlaypen 1}
tonerLevelsVals OBJECT IDENTIFIER ::= {netSnmpPlaypen 2}
tonerLevelsMaxVals OBJECT IDENTIFIER ::= {netSnmpPlaypen 3}
otherRandomVals OBJECT IDENTIFIER ::= {netSnmpPlaypen 4}
monoCount OBJECT-TYPE
SYNTAX Integer32
MAX-ACCESS read-write
STATUS current
DEFVAL { 0 }
::= {pageCountsVals 1}
colorCount OBJECT-TYPE
SYNTAX Integer32
MAX-ACCESS read-write
STATUS current
DEFVAL { 0 }
::= {pageCountsVals 2}
totalCount OBJECT-TYPE
SYNTAX Integer32
MAX-ACCESS read-write
STATUS current
DEFVAL { 0 }
::= {pageCountsVals 3}
cyanVal OBJECT-TYPE
SYNTAX Integer32
MAX-ACCESS read-write
STATUS current
DEFVAL { 0 }
::= {tonerLevelsVals 1}
magentaVal OBJECT-TYPE
SYNTAX Integer32
MAX-ACCESS read-write
STATUS current
DEFVAL { 0 }
::= {tonerLevelsVals 2}
yellowVal OBJECT-TYPE
SYNTAX Integer32
MAX-ACCESS read-write
STATUS current
DEFVAL { 0 }
::= {tonerLevelsVals 3}
blackVal OBJECT-TYPE
SYNTAX Integer32
MAX-ACCESS read-write
STATUS current
DEFVAL { 0 }
::= {tonerLevelsVals 4}
cyanMaxVal OBJECT-TYPE
SYNTAX Integer32
MAX-ACCESS read-write
STATUS current
DEFVAL { 0 }
::= {tonerLevelsMaxVals 1}
magentaMaxVal OBJECT-TYPE
SYNTAX Integer32
MAX-ACCESS read-write
STATUS current
DEFVAL { 0 }
::= {tonerLevelsMaxVals 2}
yellowMaxVal OBJECT-TYPE
SYNTAX Integer32
MAX-ACCESS read-write
STATUS current
DEFVAL { 0 }
::= {tonerLevelsMaxVals 3}
blackMaxVal OBJECT-TYPE
SYNTAX Integer32
MAX-ACCESS read-write
STATUS current
DEFVAL { 0 }
::= {tonerLevelsMaxVals 4}
randomVal1 OBJECT-TYPE
SYNTAX Integer32
MAX-ACCESS read-write
STATUS current
DEFVAL { 0 }
::= {otherRandomVals 1}
randomVal2 OBJECT-TYPE
SYNTAX Integer32
MAX-ACCESS read-write
STATUS current
DEFVAL { 0 }
::= {otherRandomVals 2}
randomVal3 OBJECT-TYPE
SYNTAX Integer32
MAX-ACCESS read-write
STATUS current
DEFVAL { 0 }
::= {otherRandomVals 3}
randomVal4 OBJECT-TYPE
SYNTAX Integer32
MAX-ACCESS read-write
STATUS current
DEFVAL { 0 }
::= {otherRandomVals 4}
randomVal5 OBJECT-TYPE
SYNTAX Integer32
MAX-ACCESS read-write
STATUS current
DEFVAL { 0 }
::= {otherRandomVals 5}
randomVal6 OBJECT-TYPE
SYNTAX Integer32
MAX-ACCESS read-write
STATUS current
DEFVAL { 0 }
::= {otherRandomVals 6}
randomVal7 OBJECT-TYPE
SYNTAX Integer32
MAX-ACCESS read-write
STATUS current
DEFVAL { 0 }
::= {otherRandomVals 7}
randomVal8 OBJECT-TYPE
SYNTAX Integer32
MAX-ACCESS read-write
STATUS current
DEFVAL { 0 }
::= {otherRandomVals 8}
randomVal9 OBJECT-TYPE
SYNTAX Integer32
MAX-ACCESS read-write
STATUS current
DEFVAL { 0 }
::= {otherRandomVals 9}
randomVal10 OBJECT-TYPE
SYNTAX Integer32
MAX-ACCESS read-write
STATUS current
DEFVAL { 0 }
::= {otherRandomVals 10}
randomVal11 OBJECT-TYPE
SYNTAX Integer32
MAX-ACCESS read-write
STATUS current
DEFVAL { 0 }
::= {otherRandomVals 11}
randomVal12 OBJECT-TYPE
SYNTAX Integer32
MAX-ACCESS read-write
STATUS current
DEFVAL { 0 }
::= {otherRandomVals 12}
END
我希望这会给经验丰富的snmper足够的信息,看看我做错了什么。如果没有,请询问。感谢。
答案 0 :(得分:0)
Snmpwalk获取您指定的OID下树中的所有OID。由于您指定了.1.3.6.1.4.1.8072.9999.9999.1.1,因此它只获取该特定OID,因为在该OID下没有其他OID。要走完您已经定义的所有OIDS,请执行以下操作:
snmpwalk -On -v 2c -c public 127.0.0.1 .1.3.6.1.4.1.8072.9999.9999
答案 1 :(得分:0)
@ user1693487问题是你的第3行;
OIDDEFS = OIDDEFS
当作为service / init.d运行时,这需要一个完整的路径;
type: 'taggings'
无论哪种方式,你的帖子帮助我,因为我面临同样的问题!谢谢