因为显然你正在使用Windows操作系统与SNMP的工作,那么你需要为了在添加自定义SNMP的OID和相应的陷阱,来创建自定义SNMP扩展代理您的系统。每个OID都会提供一个可以存储信息的变量。 Here is an example of such DLL。据我所知,MIB文件仅在Windows中用作SNMP代理的参考,不能用于在不创建自定义SNMP代理的情况下添加新的OID。
当您拥有自定义SNMP代理DLL时,需要将其指向注册表中。可以这样做(例如):
[HKEY_LOCAL_MACHINE\SOFTWARE\Symbol\MyAgent\CurrentVersion]
"Pathname"="C:\\MyCustomAgent\\MyAgent.dll"
;Add number of agent to the list (max num registered + 1)
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SNMP\Parameters\ExtensionAgents]
"10"="SOFTWARE\\Symbol\\MyAgent\\CurrentVersion"
之后,您将需要重新启动您的SNMP服务。如果一切正常,您可以使用新的自定义OID设置\获取一些数据。
为了读取\写入您的SNMP变量,您需要使用SNMP管理器。我通常使用Sharpsnmplib来这样做。还有一些GUI管理器在调试过程中非常有用,例如:iReasoning MIB Browser。
下面是示例代码使用LIB:
using System.Collections.Generic;
using System.Net;
using System.Net.Sockets;
// SNMP Lib references
using Lextm.SharpSnmpLib;
using Mono.Options;
using Lextm.SharpSnmpLib.Messaging;
using Lextm.SharpSnmpLib.Security;
...
List vList = new List();
ISnmpData data;
data = new OctetString("test"); // variable to add in to string OID
Variable test = new Variable(new ObjectIdentifier("1.3.6.1.2.1.1.6.0"), data); // OID
vList.Add(test);
VersionCode versionH = VersionCode.V2; // SNMP protocol version to use
IPAddress ipH;
IPAddress.TryParse("127.0.0.1", out ipH);
IPEndPoint receiverH = new IPEndPoint(ipH, 161);
foreach (Variable variable in
Messenger.Set(versionH, receiverH, new OctetString("private"), vList, 10))// set variable
// Arguments: (ver of SNMP, IP, group, iList containing OID and variable, timeoout)
{
// output variable
}
...
你也可以阅读文章关于Windows操作系统与SNMP工作TechNet上:link。本文不是新的,但可以帮助您了解如何在Windows中使用SNMP。
如果是这样,那么如何定义SNMP陷阱的格式('数据字段')? – Tom 2012-02-08 15:12:30