SNMP 开发

    技术2022-05-19  23

    SNMP(Simple Network managerment protocol)简单网络管理协议 SNMP extension API function 应用开发 对于不同的操作系统的OID之间存在差别,虽有公共的OID定义,但是应用范围并不能满足所有应用要求.我们通过 start-->run-->perfmon 打开windows 操作系统的 Performance窗口,会缺省显示memory,disk和cpu的性能监控数据,当打开System Monitor Properties窗口,单击Add 打开Add Counters窗口,可以看到系统提供了非常丰富的系统性能数据监控选项,而这些选择只有很少一部分定义在公共的OID列表中,所以我们若要应用这些系统性能监控选择,就需要通过SNMP extension API 来开发DLL,并将DLL注册在系统注册表记录中,当SNMP服务启动时加载DLL获取我们所需要的系统性能监控数据. SNMP Extension Agent API Functions The SNMP extension agent functions define the interface between the SNMP service and the third-party SNMP extension agent DLLs. The following table lists functions that applications can use to resolve variable bindings specified by incoming SNMP protocol data units (PDUs). SNMP Extension Agent API Function    Description SnmpExtensionClose     Requests that the SNMP extension agent deallocate resources and terminate operations. SnmpExtensionInit     Initializes the SNMP extension agent DLL. SnmpExtensionInitEx     Identifies any additional management information base (MIB) subtrees that the SNMP extension agent supports. SnmpExtensionMonitor     Provides the SNMP extension agent with information about the internal counters and parameters of the service. SnmpExtensionQuery     Resolves SNMP requests that contain variables in one or more of the registered MIB subtrees of the SNMP extension agent. SnmpExtensionQueryEx     Processes SNMP requests that specify variables in one or more MIB subtrees that are registered by SNMP extension agents. SnmpExtensionTrap     Retrieves information that the service requires to generate traps for the SNMP extension agent. SNMP有三种获取数据的方式GET,GETNEXT和trap.这里只介绍GET方式,GET方式固名思义就是client发送一次请求,service就会向client端响应一次请求. 该方式主要用到两个SNMP extension agent api function SnmpExtensionInit 和 SnmpExtensionQueryEx BOOL SnmpExtensionInit(   __in   DWORD dwUptimeReference,   __out  HANDLE *phSubagentTrapEvent,   __out  AsnObjectIdentifier *pFirstSupportedRegion ); 主要用来初始化DLL,为pFirstSupportedRegion赋值,下面是该参数在API中的原文: Pointer to an AsnObjectIdentifier structure to receive the first MIB subtree that the extension agent supports. For additional information about allocating and deallocating resources for this structure, see the following Remarks section. The extension agent can register additional MIB subtrees by implementing the SnmpExtensionInitEx entry point function. 大概意思是指定一个7位的OID做过对发送过来的OID列表的过滤,即自己开发的DLL只对以这个7位OID开头的OID进行处理.并将收集到的OID列表做过参数传入SnmpExtensionQueryEx进行处理并响应client请求. BOOL SnmpExtensionQueryEx(   __in     DWORD dwRequestType,   __in     DWORD dwTransactionId,   __inout  SnmpVarBindList *pVarBindList,   __inout  AsnOctetString *pContextInfo,   __out    AsnInteger32 *pErrorStatus,   __out    AsnInteger32 *pErrorIndex ); process SNMP requests that specify variables in one or more MIB subtrees registered by SNMP extension agents. ......


    最新回复(0)