启用NET-SNMP-PASS-MIB.txt

启用NET-SNMP-PASS-MIB.txt,net-snmp,snmpd,Net Snmp,Snmpd,我正在尝试使用SNMP协议的MIB特定扩展命令。 我有一个在嵌入式Linux环境中运行的snmpd代理。在snmpd.conf中,我取消了以下行的注释: pass .1.3.6.1.4.1.2021.255 /bin/sh /usr/local/passtest /usr/local/passtest如下所示: #!/bin/sh -f PLACE=".1.3.6.1.4.1.2021.255" # NET-SNMP-PASS-MIB::netSnmpPassExamples REQ="

我正在尝试使用SNMP协议的MIB特定扩展命令。 我有一个在嵌入式Linux环境中运行的snmpd代理。在snmpd.conf中,我取消了以下行的注释:

pass .1.3.6.1.4.1.2021.255 /bin/sh /usr/local/passtest 
/usr/local/passtest如下所示:

#!/bin/sh -f

PLACE=".1.3.6.1.4.1.2021.255"  # NET-SNMP-PASS-MIB::netSnmpPassExamples
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
root@sama5d2-xplained:/usr/share/snmp/mibs# cat NET-SNMP-PASS-MIB.txt 
NET-SNMP-PASS-MIB DEFINITIONS ::= BEGIN

--
-- Example MIB objects for "pass" and "pass-persist" extension script
--

IMPORTS
    MODULE-IDENTITY, OBJECT-TYPE, TimeTicks, IpAddress,
          Counter32, Gauge32, Integer32     FROM SNMPv2-SMI
    SnmpAdminString                         FROM SNMP-FRAMEWORK-MIB
    netSnmpExamples                         FROM NET-SNMP-EXAMPLES-MIB
;

netSnmpPassExamples MODULE-IDENTITY
    LAST-UPDATED "200905280000Z"
    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
        "Example MIB objects for pass/pass-persist extension script"
    ::= { netSnmpExamples 255 }

--
-- Example scalars
--

netSnmpPassString OBJECT-TYPE
    SYNTAX      SnmpAdminString
    MAX-ACCESS  read-write
    STATUS      current
    DESCRIPTION "Example string scalar object."
    DEFVAL { "Life, the Universe, and Everything" }
    ::= { netSnmpPassExamples 1 }

netSnmpPassTimeTicks OBJECT-TYPE
    SYNTAX      TimeTicks
    MAX-ACCESS  read-write
    STATUS      current
    DESCRIPTION "Example timetick object."
    DEFVAL { 363136200 }  -- 42 days, 0:42:42.00
    ::= { netSnmpPassExamples 3 }

netSnmpPassIpAddress OBJECT-TYPE
    SYNTAX      IpAddress
    MAX-ACCESS  read-write
    STATUS      current
    DESCRIPTION "Example IP Address object."
    DEFVAL { '7f000001'H }  -- 127.0.0.1
    ::= { netSnmpPassExamples 4 }

netSnmpPassCounter OBJECT-TYPE
    SYNTAX      Counter32
    MAX-ACCESS  read-only
    STATUS      current
    DESCRIPTION "Example counter object.
                 Note that this object will always return the value '42'."
    ::= { netSnmpPassExamples 5 }

netSnmpPassGauge OBJECT-TYPE
    SYNTAX      Gauge32
    MAX-ACCESS  read-write
    STATUS      current
    DESCRIPTION "Example Gauge object."
    DEFVAL { 42 }
    ::= { netSnmpPassExamples 6 }


netSnmpPassOIDValue OBJECT IDENTIFIER
    ::= { netSnmpPassExamples 99 }

--
--  Example Table
--

netSnmpPassTable OBJECT-TYPE
    SYNTAX      SEQUENCE OF NetSnmpPassEntry
    MAX-ACCESS  not-accessible
    STATUS      current
    DESCRIPTION "Example table"
    ::= { netSnmpPassExamples 2 }

netSnmpPassEntry OBJECT-TYPE
    SYNTAX      NetSnmpPassEntry
    MAX-ACCESS  not-accessible
    STATUS      current
    DESCRIPTION "Conceptual row in the example table."
    INDEX   { netSnmpPassIndex }
    ::= {netSnmpPassTable 1 }

NetSnmpPassEntry ::= SEQUENCE {
        netSnmpPassIndex   Integer32,
        netSnmpPassInteger Integer32,
        netSnmpPassOID     OBJECT IDENTIFIER
}

netSnmpPassIndex OBJECT-TYPE
    SYNTAX      Integer32
    MAX-ACCESS  not-accessible
    STATUS      current
    DESCRIPTION "Arbitrary index into the netSnmpPassTable.
                 Note that there will always be one row, with index 1"
    ::= { netSnmpPassEntry 1 }

netSnmpPassInteger OBJECT-TYPE
    SYNTAX      Integer32
    MAX-ACCESS  read-write
    STATUS      current
    DESCRIPTION "Example Integer (table) object."
    DEFVAL { 42 }
    ::= { netSnmpPassEntry 2 }

netSnmpPassOID OBJECT-TYPE
    SYNTAX      OBJECT IDENTIFIER
    MAX-ACCESS  read-write
    STATUS      current
    DESCRIPTION "Example OID (table) object."
    DEFVAL { netSnmpPassOIDValue }
    ::= { netSnmpPassEntry 3 }

END
MIB如下所示:

#!/bin/sh -f

PLACE=".1.3.6.1.4.1.2021.255"  # NET-SNMP-PASS-MIB::netSnmpPassExamples
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
root@sama5d2-xplained:/usr/share/snmp/mibs# cat NET-SNMP-PASS-MIB.txt 
NET-SNMP-PASS-MIB DEFINITIONS ::= BEGIN

--
-- Example MIB objects for "pass" and "pass-persist" extension script
--

IMPORTS
    MODULE-IDENTITY, OBJECT-TYPE, TimeTicks, IpAddress,
          Counter32, Gauge32, Integer32     FROM SNMPv2-SMI
    SnmpAdminString                         FROM SNMP-FRAMEWORK-MIB
    netSnmpExamples                         FROM NET-SNMP-EXAMPLES-MIB
;

netSnmpPassExamples MODULE-IDENTITY
    LAST-UPDATED "200905280000Z"
    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
        "Example MIB objects for pass/pass-persist extension script"
    ::= { netSnmpExamples 255 }

--
-- Example scalars
--

netSnmpPassString OBJECT-TYPE
    SYNTAX      SnmpAdminString
    MAX-ACCESS  read-write
    STATUS      current
    DESCRIPTION "Example string scalar object."
    DEFVAL { "Life, the Universe, and Everything" }
    ::= { netSnmpPassExamples 1 }

netSnmpPassTimeTicks OBJECT-TYPE
    SYNTAX      TimeTicks
    MAX-ACCESS  read-write
    STATUS      current
    DESCRIPTION "Example timetick object."
    DEFVAL { 363136200 }  -- 42 days, 0:42:42.00
    ::= { netSnmpPassExamples 3 }

netSnmpPassIpAddress OBJECT-TYPE
    SYNTAX      IpAddress
    MAX-ACCESS  read-write
    STATUS      current
    DESCRIPTION "Example IP Address object."
    DEFVAL { '7f000001'H }  -- 127.0.0.1
    ::= { netSnmpPassExamples 4 }

netSnmpPassCounter OBJECT-TYPE
    SYNTAX      Counter32
    MAX-ACCESS  read-only
    STATUS      current
    DESCRIPTION "Example counter object.
                 Note that this object will always return the value '42'."
    ::= { netSnmpPassExamples 5 }

netSnmpPassGauge OBJECT-TYPE
    SYNTAX      Gauge32
    MAX-ACCESS  read-write
    STATUS      current
    DESCRIPTION "Example Gauge object."
    DEFVAL { 42 }
    ::= { netSnmpPassExamples 6 }


netSnmpPassOIDValue OBJECT IDENTIFIER
    ::= { netSnmpPassExamples 99 }

--
--  Example Table
--

netSnmpPassTable OBJECT-TYPE
    SYNTAX      SEQUENCE OF NetSnmpPassEntry
    MAX-ACCESS  not-accessible
    STATUS      current
    DESCRIPTION "Example table"
    ::= { netSnmpPassExamples 2 }

netSnmpPassEntry OBJECT-TYPE
    SYNTAX      NetSnmpPassEntry
    MAX-ACCESS  not-accessible
    STATUS      current
    DESCRIPTION "Conceptual row in the example table."
    INDEX   { netSnmpPassIndex }
    ::= {netSnmpPassTable 1 }

NetSnmpPassEntry ::= SEQUENCE {
        netSnmpPassIndex   Integer32,
        netSnmpPassInteger Integer32,
        netSnmpPassOID     OBJECT IDENTIFIER
}

netSnmpPassIndex OBJECT-TYPE
    SYNTAX      Integer32
    MAX-ACCESS  not-accessible
    STATUS      current
    DESCRIPTION "Arbitrary index into the netSnmpPassTable.
                 Note that there will always be one row, with index 1"
    ::= { netSnmpPassEntry 1 }

netSnmpPassInteger OBJECT-TYPE
    SYNTAX      Integer32
    MAX-ACCESS  read-write
    STATUS      current
    DESCRIPTION "Example Integer (table) object."
    DEFVAL { 42 }
    ::= { netSnmpPassEntry 2 }

netSnmpPassOID OBJECT-TYPE
    SYNTAX      OBJECT IDENTIFIER
    MAX-ACCESS  read-write
    STATUS      current
    DESCRIPTION "Example OID (table) object."
    DEFVAL { netSnmpPassOIDValue }
    ::= { netSnmpPassEntry 3 }

END
但是,当我尝试从主机执行snmpget时,我得到以下响应:

bernardo@bernardo-ThinkCentre-Edge72:~$ snmpget -v1 -c public 192.168.0.190 .1.3.6.1.4.1.2021.255.1
Error in packet
Reason: (noSuchName) There is no such variable name in this MIB.
Failed object: iso.3.6.1.4.1.2021.255.1
我错过了什么