如何使用pass\u persist with shell脚本创建可行走的snmpd扩展
我在snmpd.conf文件中添加了以下两行:如何使用pass\u persist with shell脚本创建可行走的snmpd扩展,snmp,net-snmp,mib,Snmp,Net Snmp,Mib,我在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的行、类型和值(用空格分隔): 并在从命令行运行时提供以下交互: <- PING -> PONG <- get
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的行、类型和值(用空格分隔):
并在从命令行运行时提供以下交互:
<- 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
并得到回应:
.1.3.6.1.4.1.8072.9999.9999.1.2 = INTEGER: 21
我可以成功地snmpget(netsnmp命令)我的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
我明白了
这和我在那个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旁边的snmpget,后面是引用.1.3.6.1.4.1.8072.9999.9999.1.2的snmpget,后面是引用.1.3.6.1.4.1.8072.9999.1.1的snmpgetresponse,后面是引用.1.3.6.1.4.1.8072.9999.1.1.1.1的snmpgetresponse
我更改了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
我希望这将给一个有经验的snmp'er足够的信息,看看我做错了什么。如果没有,请询问。谢谢。Snmpwalk获取树中指定OID下的所有OID。由于您指定了.1.3.6.1.4.1.8072.9999.9999.1.1,因此它只获取该特定OID,因为该OID下没有其他OID。要遍历您定义的所有OID,请执行以下操作:
snmpwalk -On -v 2c -c public 127.0.0.1 .1.3.6.1.4.1.8072.9999.9999
@用户1693487问题是你的第三行 OIDDEFS=OIDDEFS 当作为服务/init.d运行时,需要完整的路径
OIDDEFS=/usr/bla/path/OIDDEFS
不管怎样,你的帖子帮助了我,因为我正面临着同样的问题!!因此,非常感谢下面的示例snmpd-f的行为与snmpd作为服务或从init.d运行时的行为不同。无论您如何处理OID,Walk/or Get都会失败。
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
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
snmpwalk -On -v 2c -c public 127.0.0.1 .1.3.6.1.4.1.8072.9999.9999
OIDDEFS=/usr/bla/path/OIDDEFS