Contact Info

Crumbtrail

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

Dns.vbs - Monitoring DNS 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 DNS 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 DNS check

Dns.vbs script source code

' ///////////////////////////////////////////////////////////////////////////////
' // ActiveXperts Network Monitor  - VBScript based checks
' // (c) 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 = CheckDns( "ns1.ascio.net", "smpp.activexperts-labs.com", "84.53.114.73" )
' WScript.Echo "Return value: [" & bResult & "]"
' WScript.Echo "SYSDATA: [" & SYSDATA & "]"
' WScript.Echo "SYSEXPLANATION: [" & SYSEXPLANATION & "]"
' ////////////////////////////////////////////////////////////////////////////////////////


Function CheckDns( strDnsServer, strHost, strExpectedValue )

' Description: 
'     Query a DNS server, and validate the response
'     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) strDnsServer - Host name or IP address of the (remote) DNS server
'     2) strHost - Hostname or domain to query
'     3) strExpectedValue - expected value 
' Usage:
'     CheckDns( "<Hostname | IP>", "host", "<expected value>" )
' Sample:
'     CheckDns( "ns1.ascio.net", "smpp.activexperts-labs.com", "84.53.114.73" )

    Dim objDnsServer, objConstants, objDnsRecord, bMatched

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

    bMatched            = False

    ' Create instance of SNMP object
    Set objDnsServer = CreateObject("ActiveXperts.DnsServer")
    Set objConstants = CreateObject ( "ActiveXperts.ASConstants")

    ' Lookup
    objDnsServer.Server = strDnsServer
    objDnsServer.Lookup strHost, objConstants.asDNS_TYPE_A
    If( objDnsServer.LastError <> 0 ) Then
        SYSEXPLANATION  = "Unable to connect to query [" & strDnsServer & "]"
        CheckDns        = retvalUnknown
        Exit Function
    End If

    Set objDnsRecord = objDnsServer.GetFirstRecord
    On Error Resume Next
	
    While ( objDnsServer.LastError = 0 )
       If( UCase( objDnsRecord.Name ) = UCase( strHost ) ) Then 
          If( SYSDATA <> "" ) Then
             SYSDATA    = SYSDATA  & "; " 
          End If

          SYSDATA       = SYSDATA  & objDnsRecord.Address

          If( UCase( objDnsRecord.Address ) = UCase( strExpectedValue ) ) Then
             bMatched = True
          End If
       End If
		
       Set objDnsRecord = objDnsServer.GetNextRecord
    WEnd

    If( bMatched ) Then
       CheckDns            = True
       SYSEXPLANATION      = "Response matched; response = [" & SYSDATA & "]"
    Else
       CheckDns            = True
       SYSEXPLANATION      = "Response did not match; response = [" & SYSDATA & "]"
    End If

End Function