首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Net: snmpbulkget - genError失败

Net: snmpbulkget - genError失败
EN

Stack Overflow用户
提问于 2020-10-28 22:41:12
回答 1查看 1.9K关注 0票数 0

我试图在64位Linux服务器上实现Net 5.7.3 .目前,我遇到了一个障碍,因为我无法确定为什么我的Linux服务器在getBulkRequest进入包含MIB的OID时返回错误代码。当我对相应的OID使用snmpget时,我能够获得每个MIB的信息,但是当我执行snmpbulkget时,我一直得到

代码语言:javascript
运行
复制
Error in packet.
Reason: (genError) A general failure occured
Failed object: MY-ELEMENT-MIB::myModel.0

我认为我的问题在于我的代理的SNMP配置文件,但我一直无法解决这个问题。无论如何,万一我错了,我会把我迄今为止所做的一切都张贴出来。希望我的“清理”代码更容易理解,并在未来帮助其他人;我很难做到这一点。

我的snmp.conf用来启动我的代理(放在/etc/snmp/中)。我正在使用v2c,并将其公开。

代码语言:javascript
运行
复制
###############################################################################
#
# EXAMPLE.conf:
#   An example configuration file for configuring the Net-SNMP agent ('snmpd')
#   See the 'snmpd.conf(5)' man page for details
#
#  Some entries are deliberately commented out, and will need to be explicitly activated
#
###############################################################################
#
#  AGENT BEHAVIOUR
#

#  Listen for connections from the local system only
#agentAddress  udp:127.0.0.1:161
#  Listen for connections on all interfaces (both IPv4 *and* IPv6)
agentAddress udp:161,udp6:[::1]:161


###############################################################################
#
#  ACCESS CONTROL
#

####
# First, map the community name (COMMUNITY) into a security name
# (local and mynetwork, depending on where the request is coming
# from):
#       sec.name  source          community
com2sec local     localhost       secret42
com2sec cust1_sec default         public

####
# Second, map the security names into group names:
#               sec.model  sec.name
group MyRWGroup v1         local
group MyRWGroup v2c        local
group cust1_grp v1         cust1_sec
group cust1_grp v2c        cust1_sec

####
# Third, create a view for us to let the groups have rights to:
#           incl/excl subtree                              mask
view all    included  .1
#view cust1_v excluded  .1
#view cust1_v included  sysUpTime.0
#view cust1_v included  interfaces.ifTable.ifEntry.ifIndex.1 ff.a0

####
# Finally, grant the groups access to their views:
#                context sec.model sec.level match  read     write  notif
access MyRWGroup ""      any       noauth    exact  all      all    none
access cust1_grp ""      any       noauth    exact  all      all    none

#  Full read-only access for SNMPv3
#rouser   authOnlyUser
#  Full write access for encrypted requests
#     Remember to activate the 'createUser' lines above
#rwuser   authPrivUser   priv


###############################################################################
#
#  SYSTEM INFORMATION
#

#  Note that setting these values here, results in the corresponding MIB objects being 'read-only'
#  See snmpd.conf(5) for more details
sysLocation    Server Room
sysContact     Me <me@example.org>
# Application + End-to-End layers
sysServices    72


###############################################################################
#
#  ACTIVE MONITORING
#

#   send SNMPv1  traps
#trapsink     localhost:162 public
#   send SNMPv2c traps
#trap2sink    localhost public
#   send SNMPv2c INFORMs
#informsink   localhost public

#  Note that you typically only want *one* of these three lines
#  Uncommenting two (or all three) will result in multiple copies of each notification.


#
#  Event MIB - automatically generate alerts
#
# Remember to activate the 'createUser' lines above
#iquerySecName   internalUser       
#rouser          internalUser
# generate traps on UCD error conditions
#defaultMonitors          yes
# generate traps on linkUp/Down
#linkUpDownNotifications  yes


###############################################################################
#
#  EXTENDING THE AGENT
#

#
#  AgentX Sub-agents
#
#  Run as an AgentX master agent
master          agentx

#  Listen for network connections (from localhost)
#    rather than the default named socket /var/agentx/master
#agentXSocket    tcp:localhost:705

启动snmpd (代理)之后,在我的C++应用程序中启动一个子代理守护进程。下面是我遵循http://www.net-snmp.org/tutorial/tutorial-5/toolkit/demon/example-demon.c的守护进程示例

下面是我实现的C++子代理代码。Daemon调用我的init_myMibSubAgent()而不是init_nstAgentSubagentObject()。

代码语言:javascript
运行
复制
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include "myMibSubAgent.h"
#include "SNMPAppData.h"
#include <string>

using namespace std;

void CMyMibSubAgent::init_myMibSubAgent(void)
{
    static oid myGeneral_oid[] = { 1, 3, 6, 1, 4, 1, 1234, 2, 1, 2};


    // myModel; DisplayString
    static oid myModel_oid[] = { 1, 3, 6, 1, 4, 1, 1234, 2, 1, 2, 1}; // We dont add 0 to end of watch scalar registration oid
    netsnmp_register_watched_scalar(
        netsnmp_create_handler_registration("myModel", NULL,
            myModel_oid, OID_LENGTH(myModel_oid),
            HANDLER_CAN_RWRITE),
        netsnmp_create_watcher_info(&gSNMPAppData.myGeneral.data.myModel, sizeof(gSNMPAppData.myGeneral.data.myModel),
            ASN_OCTET_STR, WATCHER_SIZE_STRLEN));
            
    // mySerialCode; DisplayString
    static oid mySerialCode_oid[] = { 1, 3, 6, 1, 4, 1, 1234, 2, 1, 2, 2}; // We dont add 0 to end of watch scalar registration oid
    netsnmp_register_watched_scalar(
        netsnmp_create_handler_registration("mySerialCode", NULL,
            mySerialCode_oid, OID_LENGTH(mySerialCode_oid),
            HANDLER_CAN_RWRITE),
        netsnmp_create_watcher_info(&gSNMPAppData.myGeneral.data.mySerialCode, sizeof(gSNMPAppData.myGeneral.data.mySerialCode),
            ASN_OCTET_STR, WATCHER_SIZE_STRLEN));
    
    // myType; INTEGER
    static oid myType_oid[] = { 1, 3, 6, 1, 4, 1, 1234, 2, 1, 2, 3, 0};
    netsnmp_register_int_instance("myType", myType_oid, OID_LENGTH(myType_oid), &gSNMPAppData.myGeneral.data.myType, NULL );
    
    // mySoftwareRev; DisplayString
    static oid mySoftwareRev_oid[] = { 1, 3, 6, 1, 4, 1, 1234, 2, 1, 2, 4}; // We dont add 0 to end of watch scalar registration oid
    netsnmp_register_watched_scalar(
        netsnmp_create_handler_registration("mySoftwareRev", NULL,
            mySoftwareRev_oid, OID_LENGTH(mySoftwareRev_oid),
            HANDLER_CAN_RWRITE),
        netsnmp_create_watcher_info(&gSNMPAppData.myGeneral.data.mySoftwareRev, sizeof(gSNMPAppData.myGeneral.data.mySoftwareRev),
            ASN_OCTET_STR, WATCHER_SIZE_STRLEN));
            
    // myState; INTEGER
    static oid myState_oid[] = { 1, 3, 6, 1, 4, 1, 1234, 2, 1, 2, 5, 0};
    netsnmp_register_int_instance("myState", myState_oid, OID_LENGTH(myState_oid), &gSNMPAppData.myGeneral.data.myState, NULL );
    
    // mySeverityLevel; INTEGER
    //static oid mySeverityLevel_oid[] = { 1, 3, 6, 1, 4, 1, 1234, 2, 1, 2, 6, 0};
    //netsnmp_register_int_instance("mySeverityLevel", mySeverityLevel_oid, OID_LENGTH(mySeverityLevel_oid), &gSNMPAppData.myGeneral.data.mySeverityLevel, NULL );
    
    // myAssetTag; DisplayString
    static oid myAssetTag_oid[] = { 1, 3, 6, 1, 4, 1, 1234, 2, 1, 2, 7}; // We dont add 0 to end of watch scalar registration oid
    netsnmp_register_watched_scalar(
        netsnmp_create_handler_registration("myAssetTag", NULL,
            myAssetTag_oid, OID_LENGTH(myAssetTag_oid),
            HANDLER_CAN_RWRITE),
        netsnmp_create_watcher_info(&gSNMPAppData.myGeneral.data.myAssetTag, sizeof(gSNMPAppData.myGeneral.data.myAssetTag),
            ASN_OCTET_STR, WATCHER_SIZE_STRLEN));
            
    // myTtMaxTargets; Integer32
    static oid myTtMaxTargets_oid[] = { 1, 3, 6, 1, 4, 1, 1234, 2, 1, 3, 1, 0};
    netsnmp_register_int_instance("myTtMaxTargets", myTtMaxTargets_oid, OID_LENGTH(myTtMaxTargets_oid), &gSNMPAppData.myTrapTargets.data.myTtMaxTargets, NULL );
    
    // myTtCfgTableNextIndex; Integer32
    static oid myTtCfgTableNextIndex_oid[] = { 1, 3, 6, 1, 4, 1, 1234, 2, 1, 3, 2, 0};
    netsnmp_register_int_instance("myTtCfgTableNextIndex", myTtCfgTableNextIndex_oid, OID_LENGTH(myTtCfgTableNextIndex_oid), &gSNMPAppData.myTrapTargets.data.myTtCfgTableNextIndex, NULL );
    
    // myTtCfgTable
    for (int i=0; i < vsmNcIpCfgEntry_MAXROWS; i++)
    {
        // myTtCfgIndex; Integer32
        //static oid myTtCfgIndex_oid[] = { 1, 3, 6, 1, 4, 1, 1234, 2, 1, 3, 3, 1, 1, i+1};
        //string myTtCfgIndexStr = "myTtCfgIndex."+i;
        //netsnmp_register_int_instance(myTtCfgIndexStr.c_str(), myTtCfgIndex_oid, OID_LENGTH(myTtCfgIndex_oid), &gSNMPAppData.vsmNcIpCfgEntry.data[i].myTtCfgIndex, NULL );
        
        // myTtCfgIpAddress; IpAddress
        oid myTtCfgIpAddress_oid[] = { 1, 3, 6, 1, 4, 1, 1234, 2, 1, 3, 3, 1, 2, i+1};
        string myTtCfgIpAddressStr = "myTtCfgIpAddress." + std::to_string(i);
        netsnmp_register_handler(
            netsnmp_create_handler_registration(myTtCfgIpAddressStr.c_str(), handle_myTtCfgIpAddress,
                myTtCfgIpAddress_oid, OID_LENGTH(myTtCfgIpAddress_oid), HANDLER_CAN_RWRITE));
            
        // myTtCfgCommunity; OCTET STRING
        oid myTtCfgCommunity_oid[] = { 1, 3, 6, 1, 4, 1, 1234, 2, 1, 3, 3, 1, 3, i+1};
        string myTtCfgCommunityStr = "myTtCfgCommunity." + std::to_string(i);
        netsnmp_register_watched_instance(
            netsnmp_create_handler_registration(myTtCfgCommunityStr.c_str(), NULL,
                myTtCfgCommunity_oid, OID_LENGTH(myTtCfgCommunity_oid),
                HANDLER_CAN_RWRITE),
            netsnmp_create_watcher_info(&gSNMPAppData.myTtCfgEntry.data[i].myTtCfgCommunity, sizeof(gSNMPAppData.myTtCfgEntry.data[i].myTtCfgCommunity),
                ASN_OCTET_STR, WATCHER_SIZE_STRLEN));
        
        // myTtCfgEntryStatus; RowStatus
        oid myTtCfgEntryStatus_oid[]    = { 1, 3, 6, 1, 4, 1, 1234, 2, 1, 3, 3, 1, 4, i+1};
        string myTtCfgEntryStatusStr = "myTtCfgEntryStatus." + std::to_string(i);
        netsnmp_register_int_instance(myTtCfgEntryStatusStr.c_str(), myTtCfgEntryStatus_oid, OID_LENGTH(myTtCfgEntryStatus_oid), &gSNMPAppData.myTtCfgEntry.data[i].myTtCfgEntryStatus, NULL );
    }
}

int CMyMibSubAgent::handle_myTtCfgIpAddress(netsnmp_mib_handler             *handler,
                                                     netsnmp_handler_registration   *reginfo,
                                                     netsnmp_agent_request_info     *reqinfo,
                                                     netsnmp_request_info           *requests)
{
    switch(reqinfo->mode) 
    {
        case MODE_GET:
        {
            snmp_set_var_typed_value(requests->requestvb, ASN_IPADDRESS,
                (u_char *)&gSNMPAppData.vsmNcIpCfgEntry.data[1].vsmIpAddress,
                sizeof(gSNMPAppData.vsmNcIpCfgEntry.data[1].vsmIpAddress));
        }
            break;

        case MODE_SET_RESERVE1:
            break;

        case MODE_SET_RESERVE2:
            break;

        case MODE_SET_FREE:
            break;

        case MODE_SET_ACTION:
            break;

        case MODE_SET_COMMIT:
            break;

        case MODE_SET_UNDO:
            break;

        default:
            return SNMP_ERR_GENERR;
    }

    return SNMP_ERR_NOERROR;
}

最后,下面是我放置在Manager /usr/share/snmp/mibs/目录中的MIB模块,它调用snmpbulkget和snmpget

代码语言:javascript
运行
复制
--
-- Common Object Definitions for My Element MIB
--

MY-ELEMENT-MIB DEFINITIONS ::= BEGIN

    --  Relationship to Other MIBs
    --
    --
    --  The objects defined in this MIB are located under the
    --  private.enterprises subtree as shown below:
    --
    --               iso(1).org(3).dod(6).internet(1)
    --                            |
    --                         private(4)
    --                            |
    --                       enterprises(1)
    --                            |
    --                        myOID(1234)
    --                            |
    --                   myRegistrations(2)
    --                            |
    --                     myElementMIB(1)
    --                                 
    --
    --
    --  Object Synopsis
    --  
    --
    --  All objects within this MIB are prefixed with the OBJECT
    --  IDENTIFIER "p", where "p" is:
    --
    --  iso(1).org(3).dod(6).internet(1).private(4).enterprises(1).
    --          myOID(1234).myRegistrations(2).myElementMIB(1)
    --  
    --  or, 1.3.6.1.4.1.1234.2.1
    --
    --
    --  Object Name                               Object Id         
    --  ================================          ==============
    --
    --  myMIBNotifications                      p.0
    --    myStateChange                         p.0.1
    --  myGeneral                               p.2
    --    myModel                               p.2.1.0
    --    mySerialCode                          p.2.2.0
    --    myType                                p.2.3.0
    --    mySoftwareRev                         p.2.4.0
    --    myState                               p.2.5.0
    --    mySeverityLevel                       p.2.6.0
    --    myAssetTag                            p.2.7.0
    --  myTrapTargets                           p.3
    --    myTtMaxTargets                          p.3.1.0
    --    myTtCfgTableNextIndex                   p.3.2.0
    --    myTtCfgTable                            p.3.3
    --      myTtCfgEntry                          p.3.3.1
    --        myTtCfgIndex                        p.3.3.1.1.n
    --        myTtCfgIpAddress                    p.3.3.1.2.n
    --        myTtCfgCommunity                    p.3.3.1.3.n
    --        myTtCfgEntryStatus                  p.3.3.1.4.n
    --
    
    IMPORTS
        MODULE-IDENTITY, NOTIFICATION-TYPE, OBJECT-TYPE,
        IpAddress, TimeTicks, Integer32
            FROM SNMPv2-SMI
        TEXTUAL-CONVENTION,
        DisplayString, RowStatus
            FROM SNMPv2-TC
        myRegistrations
            FROM MY-REG;

    myElementMIB MODULE-IDENTITY
        LAST-UPDATED "200503230000Z"
        ORGANIZATION "My Solutions, Inc."
        CONTACT-INFO
            "   
                My Solutions, Inc.
                123 Smith Ave
                Los Angeles, CA 12345, 
                USA.

                phone: +1 (123) 123-4567
                e-mail: me@example.org
                http://www.website.com/support" 
    DESCRIPTION
        "This MIB module describes the generic 
        characteristics of a manageable physical
        element beneath the my enterprise."
    REVISION      "9911120000Z"
    DESCRIPTION
        "First draft."
    REVISION      "200004100000Z"
    ::= { myRegistrations 1 }

    --
    -- Element MIB Textual Conventions
    --

    MyFloatingPoint ::= TEXTUAL-CONVENTION
        DISPLAY-HINT
            "63a"
        STATUS current
        DESCRIPTION
            "FloatingPoint provides a way of representing 
            non-integer numbers in SNMP. Numbers are 
            represented as a string of ASCII characters in
            the natural way. So for example, '3', '3.142' 
            and '0.3142E1' are all valid numbers. 
            
            The syntax for the string is as follows. [] 
            enclose an optional element, | is the separator 
            for a set of alternatives. () enclose syntax 
            which is to be viewed as a unit.

            FloatingPoint ::= [Sign]
                              (Float1 | Float2 | DigitSequence)
                              [ExponentPart]

            Float1 ::= DigitSequence '.' [DigitSequence]
            Float2 ::= '.' DigitSequence
            DigitSequence ::= Digit [DigitSequence]

            ExponentPart ::= ('e' | 'E') [Sign] DigitSequence

            Digit ::= '0'..'9'
            Sign ::= '+' | '-'"
        SYNTAX OCTET STRING (SIZE (1..63))

    MyTimecode ::= TEXTUAL-CONVENTION
        DISPLAY-HINT
            "11a"
        STATUS current
        DESCRIPTION
            "A display representation for timecode which
            essentially provides a machine readable address 
            for video and audio. Timecodes are represented as 
            a string of ASCII characters as hh:mm:ss:ff where
            hh is hours, mm is minutes, ss is seconds and
            ff is video frames."
        SYNTAX OCTET STRING (SIZE (0..11))


    --
    --  The Element MIB top-level groups
    --

    -- NOTE: { myElementMIB 1 } is reserved for internal use
    myGeneral        OBJECT IDENTIFIER ::= { myElementMIB 2 }
    myTrapTargets    OBJECT IDENTIFIER ::= { myElementMIB 3 }


    --
    --  The Element MIB Object Definitions
    --


    --
    -- The General Group
    -- The myGeneral group provides general
    -- information for the my managed element.
    --

    myModel OBJECT-TYPE
        SYNTAX      DisplayString (SIZE(0..64))
        MAX-ACCESS  read-only
        STATUS      current
        DESCRIPTION
            "The element model string. The preferred value is
            the customer-visible part number, which may be 
            printed on the physical managed element itself.
            
            If the element being managed does not have 
            a model descriptor, or the model descriptor is
            unknown to the agent, the value of this variable 
            will be a null string."
    ::= { myGeneral 1 }

    mySerialCode OBJECT-TYPE
        SYNTAX      DisplayString (SIZE(0..64))
        MAX-ACCESS  read-only
        STATUS      current
        DESCRIPTION
            "The manufacturing serial code of the
            element on which the management software
            is running.  The preferred value is the serial 
            number string actually printed on the CCU itself
            (if present).
            
            If the element being managed does not have 
            a serial code, the value of this variable 
            will be a null string."
    ::= { myGeneral 2 }

    myType OBJECT-TYPE
        SYNTAX      INTEGER {
                        myTypeUnknown(1),

                        -- My Type
                        myType1(2),
                            
                        -- My Type
                        myType2(3),
                        
                        -- My Type
                        myType3(4)
                    }
        MAX-ACCESS  read-only
        STATUS      current
        DESCRIPTION
            "Identifies the type of the element being managed."
    ::= { myGeneral 3 }

    mySoftwareRev OBJECT-TYPE
        SYNTAX      DisplayString (SIZE(0..64))
        MAX-ACCESS  read-only
        STATUS      current
        DESCRIPTION
            "The revision stamp of the software running on 
            the element that supports this MIB module."
    ::= { myGeneral 4 }

    myState OBJECT-TYPE
        SYNTAX      INTEGER {
                        myElementRunning(1),
                        myElementInMaintenance(2),
                        myElementFaulty(3),
                        myElementDisabled(4),
                        myElementIdling(5),
                        myElementInitializing(6),
                        myElementResetting(7),
                        myElementHalted(8),
                        myElementSwLicenseExpired(9),
                        myElementImntSwLicExpiry(10),
                        myElementSwLicRecovered(11)
                    }
        MAX-ACCESS  read-only
        STATUS      current
        DESCRIPTION
            "The operational state of an element."
    ::= { myGeneral 5 }
    
    mySeverityLevel OBJECT-TYPE
        SYNTAX      INTEGER {
                        levelUnknown(1),
                        levelTrace(2),
                        levelInformational(3),
                        levelNormal(4),
                        levelWarning(5),
                        levelAlarm(6),
                        levelResentWarning(7),
                        levelResentAlarm(8)
                    }
        MAX-ACCESS  accessible-for-notify
        STATUS      current
        DESCRIPTION
            "Defines the typical severity levels"
    ::= { myGeneral 6 }


    myAssetTag OBJECT-TYPE
        SYNTAX      DisplayString (SIZE(0..64))
        MAX-ACCESS  read-only
        STATUS      current
        DESCRIPTION
            "This object is a user-assigned asset tracking identifier for 
            the element"
    ::= { myGeneral 7 }


    --
    -- The Trap Targets Group
    -- The myTrapTargets group provides means to
    -- configure the trap target specifics using which an 
    -- element can dispatch traps.
    --


    myTtMaxTargets OBJECT-TYPE
        SYNTAX      Integer32
        MAX-ACCESS  read-only
        STATUS      current
        DESCRIPTION
            "The maximum number of trap targets that this
            element can support. 
            
            If the value of this variable is -1, the element
            element is capable of supporting a theoretically
            infinite number of trap targets dynamically. In
            othercases, the maximum number of trap targets 
            that can be supported by this element is limited
            to the value of this variable."
    ::= { myTrapTargets 1 }

    myTtCfgTableNextIndex OBJECT-TYPE
        SYNTAX      Integer32
        MAX-ACCESS  read-only
        STATUS      current
        DESCRIPTION
            "Identifies a hint for the next value of  
            myTtCfgIndex to be used in a row creation attempt
            for the myTtCfgTable table. If no new rows can be
            created, this object will have a value of 0."
    ::= { myTrapTargets 2 }

    myTtCfgTable OBJECT-TYPE
        SYNTAX  SEQUENCE OF MyTtCfgEntry
        MAX-ACCESS  not-accessible
        STATUS  current
        DESCRIPTION
            "A list of trap target configuration entries on
            this element.

            Trap Target Configuration Entry Creation:
            =========================================

            When creating a trap target configuration entry
            the manager should use a GET operation to 
            determine the value of myTtCfgTableNextIndex.0.
            If this value is non-zero, the manager can then 
            use this value as the index while creating a 
            table row.
            
            The process of creating and activating a row of 
            this table takes two forms: the one-set mode and 
            the multiple-set mode.
            
            In the one-set mode, a manager must specify the
            values of myTtCfgIpAddress and myTtCfgCommunity
            required to activate a row in a single SET operation
            along with an assignment of the myTtCfgEntryStatus
            to 'createAndGo(4)'. If the values and instances
            supplied are correct, an instance of the trap target
            configuration is created and the value of 
            myTtCfgEntryStatus transitions to 'active(1)'.

            for example:
            ============

            SnmpGet(<myTtCfgTableNextIndex.0, NULL>)
                returns
                    <myTtCfgTableNextIndex.0, 2>

            SnmpSet(<myTtCfgIpAddress.2, 192.158.104.93>,
                    <myTtCfgCommunity.2, 'public'>,
                    <myTtCfgEntryStatus.2, createAndGo(4)>)
                returns 
                    <myTtCfgIpAddress.2, 192.158.104.93>,
                    <myTtCfgCommunity.2, 'public'>,
                    <myTtCfgEntryStatus.2, active(1)>
                
            In the multiple-set mode, creating a trap target
            configuration table row, filling it with values,
            and activating it are carried out in discrete steps.

            To create the row, the manager specifies a value
            of 'createAndWait(5)' for the myTtCfgEntryStatus
            status variable. This SET request could contain
            values of myTtCfgIpAddress and myTtCfgCommunity
            but it is not required. More often, the values for 
            these columnar objects are specified in additional
            SET requests. After each SET operation, the 
            myTtCfgEntryStatus variable takes on the value 
            'notReady(3)' or 'notInService(2)'. To place the
            entry into service, the manager requests that the
            myTtCfgEntryStatus variable transition to the
            'active(1)' state.

            for example:
            ============

            SnmpGet(<myTtCfgTableNextIndex.0>, NULL)
                returns
                    <myTtCfgTableNextIndex.0, 2>

            SnmpSet(<myTtCfgEntryStatus.2, createAndWait(5)>)
                returns
                    <myTtCfgEntryStatus.2, notReady(3)>

            SnmpSet(<myTtCfgIpAddress.2, 192.158.104.93>,
                    <myTtCfgCommunity.2, 'public'>)
                returns
                    <myTtCfgIpAddress.2, 192.158.104.93>,
                    <myTtCfgCommunity.2, 'public'>

            SnmpSet(<myTtCfgEntryStatus.2, active(1)>)
                returns
                    <myTtCfgEntryStatus.2, active(1)>


            Trap Target Configuration Entry Deletion:
            =========================================

            To delete an existing trap target configuration
            entry, the manager performs a SET operation on the
            myTtCfgEntryStatus variable with the value
            'destroy(6)'."
        ::= { myTrapTargets 3 }

    myTtCfgEntry OBJECT-TYPE
        SYNTAX  MyTtCfgEntry
        MAX-ACCESS  not-accessible
        STATUS current  
        DESCRIPTION
            "A trap target configuration entry."
        INDEX   { myTtCfgIndex }
        ::= { myTtCfgTable 1 }

    MyTtCfgEntry ::=
        SEQUENCE {
            myTtCfgIndex
                Integer32,
            myTtCfgIpAddress
                IpAddress,
            myTtCfgCommunity
                OCTET STRING,
            myTtCfgEntryStatus
                RowStatus
        }

    myTtCfgIndex OBJECT-TYPE
        SYNTAX  Integer32 (1..2147483647)
        MAX-ACCESS  not-accessible
        STATUS  current
        DESCRIPTION
            "The index of a trap target configuration row.
            
            Note that the value of this object will not
            be visible to a manager and any GET/SET 
            operations on this variable will fail."
        ::= { myTtCfgEntry 1 }

    myTtCfgIpAddress OBJECT-TYPE
        SYNTAX  IpAddress
        MAX-ACCESS  read-only
        STATUS  current
        DESCRIPTION
            "The IP address of the target/manager to which
            this element is supposed to send notifications."
        ::= { myTtCfgEntry 2 }

    myTtCfgCommunity OBJECT-TYPE
        SYNTAX  OCTET STRING (SIZE(0..128))
        MAX-ACCESS  read-only
        STATUS  current
        DESCRIPTION
            "The community name to be used when this element
            sends notifications to the target identified by 
            this value of this entries myTtCfgIpAddress."
        ::= { myTtCfgEntry 3 }

    myTtCfgEntryStatus OBJECT-TYPE
        SYNTAX  RowStatus
        MAX-ACCESS  read-only
        STATUS  current
        DESCRIPTION
            "This object controls the creation, activation
            and deletion of a row in trap target configuration
            table."
        ::= { myTtCfgEntry 4 }



    --
    --  The Element MIB Notifications
    --

    --
    --  The notifications group is being assigned the OID "0" so as
    --  to comply with the trap handling in the different SNMP versions
    --
    myMIBNotifications OBJECT IDENTIFIER ::= { myElementMIB 0 }

    myStateChange NOTIFICATION-TYPE
        OBJECTS {
            myState
        }
        STATUS  current
        DESCRIPTION
            "Notifies when a state change occurs on an element.

            The myState variable will hold the new state that
            the element is operating in."
        ::= { myMIBNotifications 1 }
    
END

我在Manager上使用的snmpget命令

代码语言:javascript
运行
复制
snmpget -v 2c -c public 10.16.20.191 MY-ELEMENT-MIB::myModel.0
MY-ELEMENT-MIB::myModel.0 = STRING: Hello World

我在Manager上使用的snmpbulkget命令

代码语言:javascript
运行
复制
snmpbulkget -v 2c -c public 10.16.20.191 MY-ELEMENT-MIB::myGeneral
Error in packet.
Reason: (genError) A general failure occured
Failed object: MY-ELEMENT-MIB::myModel.0

其他注意事项:

  • 使用OID直接产生相同的结果。
  • 使用Wireshark,我看到我的Linux系统对getBulkRequest的响应,并在OID下找到了所有MIBs的信息。
  • 我在snmpbulkget命令中使用了-DALL开关,我看到了在OID下找到的所有MIB的信息。此外,我看到了错误状态= 5,这解释了为什么我得到genError响应
EN

回答 1

Stack Overflow用户

发布于 2021-02-16 23:36:36

我发现了我的问题。我的问题在于我用来注册Netsnmp_Node_Handler OID的myTtCfgIpAddress方法。我在MODE_GETNEXT ()中漏掉了一个MODE_GETBULK和CMyMibSubAgent::handle_myTtCfgIpAddress的案例。因此,我的开关情况默认返回SNMP_ERR_GENERR。

现在向遇到这个问题的任何人推荐,不要只依赖SNMP 。snmpbulkget -DALL命令告诉我,问题在于我的第一个OID对象(在我的例子中是myModel.0 MIB::myModel.0)。然而,在使用Wireshark之后,我发现最初的几个OID返回的是有效值,但是在到达我的myTtCfgTable之后,它开始出现问题。从这里开始,我开始使用snmpgetnext和Wireshark来确定导致genError的特定OID。之后,它只是对OID实现的回顾(在我的例子中,我不得不使用调试器来确定我得到的reqinfo->模式是MODE_GETNEXT)。希望这个解释能对将来的人有所帮助。

还有一件事,我只使用Wireshark过滤器"udp.port==161 \ udp.port==162“来观察SNMP通信量。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64582349

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档