'Desc: Checks status of interfaces on a SNMP device. This script can be used as a timed event to poll every hour or so and generate event on 'the status of the device. This is an alternate to receiving SNMP traps and good for getting basic heartbeats of Non Windows devices. 'Note: Please make sure this script runs on a computer that has the WMI SNMP provider installed. This is just another component of the Windows install 'Thanks to the people out on the internet for these sample scripts credit to them and all i did was rewrote it for MOM ' Bao Do 2/2006 ' 'Parameters: ' SNMPIP - IP address of the remote device ' SNMPCommunity - The Read only Community name ' DeviceDescription - Logical name of the device for event description purpose ie CiscoRouter-SomeLocation dim strCommunityName, strTargetSnmpDevice, strDeviceDesc Dim oParams Dim objMOMEvent dim sysdescr, sysname, sysServices, sysUpTime, sysLocation, syscontact dim sysinfo 'Getting Parameter settings strTargetSnmpDevice = GetParam("SNMPIP") strCommunityName = GetParam("SNMPCommunity") strDeviceDesc = GetParam("DeviceDescription") Set objWmiLocator = CreateObject("WbemScripting.SWbemLocator") Set objWmiServices = objWmiLocator.ConnectServer("", "root\snmp\localhost") Set objWmiNamedValueSet = CreateObject("WbemScripting.SWbemNamedValueSet") objWmiNamedValueSet.Add "AgentAddress", strTargetSnmpDevice objWmiNamedValueSet.Add "AgentReadCommunityName", strCommunityName Set colIfTable = objWmiServices.InstancesOf("SNMP_RFC1213_MIB_ifTable", , _ objWmiNamedValueSet) Set colSystem = objWmiServices.InstancesOf("SNMP_RFC1213_MIB_system", , _ objWmiNamedValueSet) For Each objSystem In colSystem sysinfo = "System Name: " & objSystem.sysName & vbCrLf & _ "Description: " & objSystem.sysDescr & vbCrLf & _ "Contact: " & objSystem.sysContact & vbCrLf & _ "Location: " & objSystem.sysLocation & vbCrLf & _ "Service: " & objSystem.sysServices & vbCrLf & _ "Uptime: " & Secondstotext(objSystem.sysUpTime/100) & vbCrLf Next For Each objInterface In colIfTable if objInterface.ifOperStatus = "down" then Set objMOMEvent = ScriptContext.CreateEvent() objMOMEvent.EventSource = "SNMP Device Status" objMOMEvent.EventNumber = 10001 objMOMEvent.EventType = 1 objMOMEvent.Message = strDeviceDesc & ": " & strTargetSnmpDevice & " - Interface # " & objInterface.ifIndex & " " & objInterface.ifDescr & " is " & objInterface.ifOperStatus & " Type - " & objInterface.ifType & vbCrLf & _ "System Info " & sysinfo & vbCrLf & _ "ifIndex [Key]: " & objInterface.ifIndex & vbCrLf & _ " ifAdminStatus: " & objInterface.ifAdminStatus & vbCrLf & _ " ifDescr: " & objInterface.ifDescr & vbCrLf & _ " ifOperStatus: " & objInterface.ifOperStatus & vbCrLf & _ " ifSpeed: " & objInterface.ifSpeed & vbCrLf & _ " ifType: " & objInterface.ifType & vbCrLf ScriptContext.submit(objMOMEvent) else Set objMOMEvent = ScriptContext.CreateEvent() objMOMEvent.EventSource = "SNMP Device Status" objMOMEvent.EventNumber = 10000 objMOMEvent.EventType = 4 objMOMEvent.Message = strDeviceDesc & ": " & strTargetSnmpDevice & " - Interface # " & objInterface.ifIndex & " " & objInterface.ifDescr & " is " & objInterface.ifOperStatus & vbCrLf & _ "System Info " & sysinfo & vbCrLf & _ "ifIndex [Key]: " & objInterface.ifIndex & vbCrLf & _ " ifAdminStatus: " & objInterface.ifAdminStatus & vbCrLf & _ " ifDescr: " & objInterface.ifDescr & vbCrLf & _ " ifOperStatus: " & objInterface.ifOperStatus & vbCrLf & _ " ifSpeed: " & objInterface.ifSpeed & vbCrLf & _ " ifType: " & objInterface.ifType & vbCrLf ScriptContext.submit(objMOMEvent) end if Next ' Get Parameter Function Function GetParam(sParam) GetParam = ScriptContext.Parameters.Get(sParam) If IsEmpty(GetParam) Then ScriptContext.Echo "Script parameter '" & sParam & "' not provided." 'Throw Script Error Event End If End Function 'Function SecondsToText(Seconds) As String Function SecondsToText(Seconds) 'Dim bAddComma As Boolean 'Dim Result As String 'Dim sTemp As String Dim bAddComma Dim Result Dim sTemp If Seconds <= 0 Or Not IsNumeric(Seconds) Then SecondsToText = "0 seconds" Exit Function End If Seconds = Fix(Seconds) If Seconds >= 86400 Then days = Fix(Seconds / 86400) Else days = 0 End If If Seconds - (days * 86400) >= 3600 Then hours = Fix((Seconds - (days * 86400)) / 3600) Else hours = 0 End If If Seconds - (hours * 3600) - (days * 86400) >= 60 Then minutes = Fix((Seconds - (hours * 3600) - (days * 86400)) / 60) Else minutes = 0 End If Seconds = Seconds - (minutes * 60) - (hours * 3600) - _ (days * 86400) If Seconds > 0 Then Result = Seconds & " second" & AutoS(Seconds) If minutes > 0 Then bAddComma = Result <> "" sTemp = minutes & " minute" & AutoS(minutes) If bAddComma Then sTemp = sTemp & ", " Result = sTemp & Result End If If hours > 0 Then bAddComma = Result <> "" sTemp = hours & " hour" & AutoS(hours) If bAddComma Then sTemp = sTemp & ", " Result = sTemp & Result End If If days > 0 Then bAddComma = Result <> "" sTemp = days & " day" & AutoS(days) If bAddComma Then sTemp = sTemp & ", " Result = sTemp & Result End If SecondsToText = Result 'wscript.echo SecondsToText End Function Function AutoS(Number) If Number = 1 Then AutoS = "" Else AutoS = "s" End Function