Contact Info

Crumbtrail

ActiveXperts.com » Network Monitor » Scripts » Custom Script

snmp.vbs - vbscript script by ActiveXperts Software

snmp.vbs connects to the SNMP agent, reads the OID value and performs a match.

Use snmp.vbs directly from ActiveXperts Network Monitor; in the Manager's 'Monitor' menu, select 'New Check (Script)' and select snmp.vbs. Configure the required parameter, or press 'Load a working sample'.

In ActiveXperts Network Monitor, Administrators can use three different scripting languages: Powershell, VBScript and SSH.


snmp.vbs script code

' ///////////////////////////////////////////////////////////////////////////////
' // ActiveXperts Network Monitor  - VBScript based checks
' // For more information about ActiveXperts Network Monitor and VBScript, visit
' // http://www.activexperts.com/support/network-monitor/online/vbscript/
' ///////////////////////////////////////////////////////////////////////////////

Option Explicit

' Declaration of global variables
Dim   SYSDATA, SYSEXPLANATION   ' SYSDATA is displayed in the 'Data' column in the Manager; SYSEXPLANATION in the 'LastResponse' column

' Constants - return values
Const retvalUnknown = 1         ' ActiveXperts Network Monitor functions should always return True (-1, Success), False (0, Error) or retvalUnknown (1, Uncertain)

' // To test a function outside Network Monitor (e.g. using CSCRIPT from the
' // command line), remove the comment character (') in the following lines:
' Dim bResult
' bResult = CheckSnmp( "localhost", "public", "1.3.6.1.2.1.1.5.0", "My Computer Name" )
' WScript.Echo "Return value: [" & bResult & "]"
' WScript.Echo "SYSDATA: [" & SYSDATA & "]"
' WScript.Echo "SYSEXPLANATION: [" & SYSEXPLANATION & "]"


Function CheckSnmp( strHost, strCommunity, strOID, strExpectedValue  )
' Description: 
'     Connect to the (remote) SNMP agent, read the OID value and match it
'     This function uses ActiveXperts Network Component.
'     ActiveXperts Network Component is automatically licensed when ActiveXperts Network Monitor is purchased
'     For more information about ActiveXperts Network Component, see: www.activexperts.com/network-component
' Parameters:
'     1) strHost - Host name or IP address of the (remote) SNMP agent
'     2) strCommunity - Community string. Default: "public"
'     3) strOID - Retrieve value of this OID. 
'     4) strExpectedValue - Match retrieved value against this expected value
' Usage:
'     CheckSnmp( "<Hostname | IP>", "community name", "<x.x.x.x.x....>", "<expected value>" )
' Sample:
'     CheckSnmp( "localhost", "public", "1.3.6.1.2.1.1.5.0", "My Computer Name" )

  Dim objSnmpManager, objConstants, objSnmpObject

  CheckSnmp              = retvalUnknown  ' Default return value
  SYSDATA                = ""             ' Not used by this function
  SYSEXPLANATION         = ""             ' Set initial value

  ' Create instance of SNMP object
  Set objSnmpManager     = CreateObject( "AxNetwork.SnmpManager" )
  Set objConstants       = CreateObject( "AxNetwork.NwConstants" )

  ' Initialize SNMP object
  objSnmpManager.ProtocolVersion = objConstants.nwSNMP_VERSION_V2C
  objSnmpManager.Initialize
  If( objSnmpManager.LastError <> 0 ) Then
    SYSEXPLANATION = "Unable to initialize ActiveXperts Network Component SNMP object"
    CheckSnmp = retvalUnknown
    Exit Function
  End If

  ' Open connection to (remote) SNMP agent
  objSnmpManager.Open strHost, strCommunity
  If( objSnmpManager.LastError <> 0 ) Then
    SYSEXPLANATION     = "Unable to connect to agent [" & strHost & "] in [" & strCommunity & "] community. Make sure SNMP agent is running"
    CheckSnmp          = retvalUnknown
    Exit Function
  End If

  On Error Resume Next
  Set objSnmpObject      = objSnmpManager.Get( strOID )
  If( objSnmpManager.LastError <> 0 ) Then
    SYSEXPLANATION     = "Unable to retrieve [" & strOID & "]. Make sure SNMP agent is running"
    CheckSnmp          = retvalUnknown
    Exit Function
  End If

  If( UCase( objSnmpObject.Value  ) = UCase( strExpectedValue ) ) Then
    SYSEXPLANATION     = "Value read: [" & objSnmpObject.Value & "], expected:[" & strExpectedValue & "]"
    CheckSnmp          = True
  Else
    SYSEXPLANATION     = "Value read: [" & objSnmpObject.Value & "], expected:[" & strExpectedValue & "]"
    CheckSnmp          = False
  End If

  ' Note: type ID's are described in ActiveXperts Network Component manual, and included in ActiveXperts Network Component samples.

  objSnmpManager.Close()
  objSnmpManager.Shutdown()

End Function