This script parses the results of the SNMPWalk to retrieve the value of SM_SerialNumber.
To create the script:
-
Start editing the ASL file.
# cd BASEDIR /smarts/bin # sm_edit --create rules/discovery/dynmodel-sn.asl
-
Type the following lines into the dynmodel-sn.asl file:
/* Create a handle to the SNMP Agent object */ agentObj=object(AgentName); /* Test that the results are not null */ if (agentObj->isNull() ) { print("***********Error in dynmodelsn.asl********"); stop(); } /* DEBUG= TRUE; */ /* Get a handle to the actual device by using the getSystem operation available through the agent object handle */ nodeObj=agentObj->getSystem(); print("NODE:".nodeObj->DisplayClassName); START{ SERIAL } /* fs is need as field separators in this parsing.*/ /* This OID matches what was defined in the import file */ serialNumberOID { ".1.3.6.1.4.1.9.3.6.3" } SERIAL{ oid:{ serialNumberOID.".".integer } fs serial:word fs } do{ /* As the snmpwalk returns a value without knowing the type, you need to use hexToString to convert the * result from hex to ASCII string */ serial=hexToString(serial); /* Assign the results to the new SM_SerialNumber attribute */ nodeObj->SM_SerialNumber=serial; stop(); }
-
Save and close the dynmodel-sn.asl file.
The dynmodel-sn.asl file is saved into the BASEDIR/smarts/local/rules/discovery directory.