We use some of the wonderful scripts found the ipswitch script library to update our device attributes (in v14.3.x). Below is a version of the vbs to update the location setting on a cisco 2960-3560 model switch. It will work on others, but use the snmpwalker to your advantage. Credit goes to the original poster (I'm still trying to find the original article). Use at your own risk. YMMV.
' Get action on SNMP OID to retrieve values
set snmp = CreateObject("CoreAsp.SnmpRqst")
nDeviceID = Context.GetProperty("DeviceID")
set result = snmp.Initialize(nDeviceID)
set result = snmp.Get("1.3.6.1.2.1.1.6.0")
If Not result.Failed Then
value = result.GetPayload
End If
' Retrieve DB object
Set oDb = Context.GetDB
RESULT_ATTRIBUTE = "Location"
nDeviceID = Context.GetProperty("DeviceID")
' Checking if the attribute already exists. If not we create one, if yes we simply update it.
sqlCheck = "SELECT nDeviceAttributeID FROM DeviceAttribute WHERE (nDeviceID = " & nDeviceID & ") AND (sName = N'" & RESULT_ATTRIBUTE & "')"
Set oRs1 = oDb.Execute(sqlCheck)
' Storing it in DB as needed.
If oRs1.EOF Then
sqlStoreResult = "INSERT INTO DeviceAttribute (nDeviceID, sName, sValue) VALUES (" & _
nDeviceID & ", N'" & RESULT_ATTRIBUTE & "', N'" & value & "')"
Else
sqlStoreResult = "UPDATE DeviceAttribute SET sValue = N'" & value & _
"' WHERE (nDeviceID = " & nDeviceID & ") AND (sName = N'" & RESULT_ATTRIBUTE & "')"
End If
oDb.Execute(sqlStoreResult)
--
To tweak, modify the snmp oid in the snmp get statement and change the RESULT.ATTRIBUTE = statement to what are you retrieving. Simple enough. On our switches we snag location, code version, vendor, model, serial and some others.
No comments:
Post a Comment