The most exciting thing about this world is its ever changing quality.

Thursday, March 12, 2009

SNMP

Agent++ is a pretty good platform independent implementation of SNMP. I felt dizzy as well when first look at OID like this: .1.3.6.1.4.1.6827.50.19.3.29.0.
However, SNMP is an extremely powerful management protocol in most of the networking devices you can see. In fact, more and more other systems have now embedded SNMP capability in (by running SNMP Agent), such as the one I was working on today - Evertz broadcast video combiner. Sun also has a decent MIB toolset within Java Dynamic Management Kit
Other than those, if you are unlucky as I did, you'll have to start from MS SNMP library and plod through the MIB trees, for which I found this post quite helpful.

Btw, this project will pop up a heap corruption problem if you are trying to build the source in .Net environment. The problem is the way SNMP_realloc is used  to create SnmpVarBind. Here is the change of the code which works (.Net 2.0, 3.5):

int SNMP::action (string oid, int actionCode, SnmpVarBind * args) 
{
long int errorIndex = 0;
long int errorStatus = 0;
char * cOid = (char *)oid.c_str ();

if (SnmpMgrStrToOid (cOid, &args-> name)) 
{
SnmpVarBindList snmpVarList;
snmpVarList.list = NULL;
snmpVarList.len = 0;
snmpVarList.list = (SnmpVarBind *)SNMP_malloc(sizeof(SnmpVarBind)); 
snmpVarList.len++;
// Assigning OID to variable bindings list
SnmpUtilOidCpy(&snmpVarList.list[0].name,&args->name);
SNMP_CopyVarBind(&snmpVarList.list[0], args);

try 
{
SnmpMgrRequest(mgrSession,
actionCode,// SNMP_PDU_SET,
&snmpVarList,
 &errorIndex, 
&errorStatus);
catch ( ... ) {

PostError("Snmp Request Failed");
}
// free the list, to avoid memory leak
SnmpUtilVarBindFree(snmpVarList.list);
SnmpUtilVarBindListFree(&snmpVarList);
}
return errorStatus;
}


No comments: