Contact Info

Crumbtrail

ActiveXperts.com » Administration » VBScript » Network Monitor » SNMP

Snmp.vbs - Monitoring SNMP using ActiveXperts Network Monitor

ActiveXperts Network Monitor ships with a powerful set of pre-defined checks. Each individual check has a static number of configuration items. To monitor other items, or to combine monitoring items, you can make use of custom VBScript checks.

Most of the built-in checks have a VBScript equivalent, implemented as a Function in a VBScript (.vbs) file. Out-of-the-box, each VBScript function monitors the same items as the built-in check. Feel free to modify a function. The VBScript check can be customized by editing the VBScript function.

To add a new VBScript-based SNMP monitoring check, do the following:

To customize the above monitoring check, click on the 'Edit button' next to the 'File selection box'. Notepad will be launched. You can now make changes to the VBScript function(s).

Screenshot of a VBScript SNMP check

Snmp.vbs script source code

' ///////////////////////////////////////////////////////////////////////////////
' // ActiveXperts Network Monitor  - VBScript based checks
' //  ActiveXperts Software B.V.
' //
' // For more information about ActiveXperts Network Monitor and VBScript, please
' // visit the online ActiveXperts Network Monitor VBScript Guidelines at:
' //    https://www.activexperts.com/support/network-monitor/online/vbscript/
' // 
' ///////////////////////////////////////////////////////////////////////////////
'  

Option Explicit
Const  retvalUnknown = 1
Dim    SYSDATA, SYSEXPLANATION  ' Used by Network Monitor, don't change the names


' //////////////////////////////////////////////////////////////////////////////
' // To test a function outside Network Monitor (e.g. using CSCRIPT from the
' // command line), remove the comment character (') in the following 5 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( strAgent, strCommunity, strOID, strExpectedValue  )

' Description: 
'     Connect to the (remote) SNMP agent, read the OID value and match it
'     This function uses the Network Component, an ActiveXperts product.
'     Network Component is automatically licensed when ActiveXperts Network Monitor is purchased
'     For more information about Network Component, see: www.activexperts.com/network-component
' Parameters:
'     1) strAgent - 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( "", "community name", "", "" )
' 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("ActiveXperts.SnmpManager")
    Set objConstants       = CreateObject ( "ActiveXperts.ASConstants" )

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

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

    Set objSnmpObject      = objSnmpManager.Get( strOID )
    If( objSnmpManager.LastError <> 0 ) Then
        SYSEXPLANATION     = "Unable to retrieve [" & strOID & "]. . Be 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 & "], Type:[" & objSnmpObject.Type & "], result: SUCCESS"
        CheckSnmp          = True
    Else
        SYSEXPLANATION     = "Value read: [" & objSnmpObject.Value & "], expected:[" & strExpectedValue & "], Type:[" & objSnmpObject.Type & "], result: ERROR"
        CheckSnmp          = False
    End If

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

    objSnmpManager.Close()
    objSnmpManager.Shutdown()

End Function