Contact Info

Crumbtrail

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

Database.vbs - Monitor a database 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 Database 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 Database check

Database.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 = CheckDatabase( "DRIVER=Microsoft Access Driver (*.mdb);DBQ=C:\Program Files\ActiveXperts\Network Monitor\Samples\Northwind.mdb", "Customers", 1 )
' WScript.Echo "Return value: [" & bResult & "]"
' WScript.Echo "SYSDATA: [" & SYSDATA & "]"
' WScript.Echo "SYSEXPLANATION: [" & SYSEXPLANATION & "]"

' ////////////////////////////////////////////////////////////////////////////////////////


Function CheckDatabase( strConnectionString, strTable, nMinimumCount )

' Description: 
'     Check a database by counting the number of records. When this count is less than expected, it is 
'     considered as error
' Parameters:
'     1) strConnectionString As String - An OLE/DB connection string
'     2) strTable As String - Table that will be checked
'     3) nMinimumCount As Number - Minimum number of records required in the database table
' Usage:
'     CheckDatabase( "<OLE/DB Connection String>"", "<table>", Num_Records )
' Sample:
'     CheckDatabase( "DRIVER=Microsoft Access Driver (*.mdb);DBQ=C:\Program Files\ActiveXperts\Network Monitor\Samples\Northwind.mdb", "Customers", 1 )


    Dim objConn, strSqlQuery, RS

    CheckDatabase         = retvalUnknown  ' Default return value
    SYSDATA               = ""             ' Will hold the number of records
    SYSEXPLANATION        = ""             ' Set initial value

    Set objConn           = CreateObject( "ADODB.Connection" )
On Error Resume Next
    objConn.Open strConnectionString
    If( Err.Number <> 0 ) Then
        CheckDatabase     = retvalUnknown
        SYSDATA           = ""
        SYSEXPLANATION    = "Open database failed; Error 0x" & Hex( Err.Number ) & ": " & Err.Description
        Exit Function
    End If
On Error Goto 0

    strSqlQuery           = "SELECT COUNT(*) FROM " & strTable & " WHERE Phone = '8000002'"
On Error Resume Next
    Set RS                = objConn.Execute( strSqlQuery )
    If( Err.Number <> 0 ) Then
        CheckDatabase     = retvalUnknown
        SYSDATA           = ""
        SYSEXPLANATION    = "Execute query failed; Error 0x" & Hex( Err.Number ) & ": " & Err.Description
        Exit Function
    End If
On Error Goto 0

    If( RS( 0 ) >= nMinimumCount ) Then 
      CheckDatabase       = True
     Else
      CheckDatabase       = False
    End If 
  
    SYSDATA               = RS( 0 )
    SYSEXPLANATION        = "Database checked, #records found=[" & RS( 0 ) & "], minimum required=[" & nMinimumCount & "]"
	 
    RS.Close

    Set RS = Nothing
    Set objConn = Nothing

End Function