SNMP 开发

本文介绍了如何使用SNMP扩展API在Windows操作系统中开发DLL,以获取和监控系统性能数据。通过SnmpExtensionInit和SnmpExtensionQueryEx等函数实现GET方式的数据获取,DLL注册在系统注册表中,由SNMP服务加载执行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.
......

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值