Execute Script Monitor

The Execute Script Monitor allows you to write your own custom scripts in the VBScript language to check anything that your script can access. This monitor makes use of the VBScript engine that is already installed on nearly all Windows computers.

The script window is where you enter your VBScript. The script can do anything that can be done in VBScript (including creating external ActiveX/COM components) with all the standard restrictions.

The script has two global variables: SendNotication and Details. The script signals to the monitoring service that the configured actions should be fired by setting SendNotification = True. The Details variable can be set to any text, and that text will get passed to all configured actions.

Pressing the Test Script button will cause the script to be launched and run from the Console, and will report on the final state of the SendNotification variable. Note that the script will run as the currently logged on user when this button is clicked, but while running from within the monitoring service it will execute as the "run as" user for the service. This may or may not have an effect on the resources that the script can access.

Like all monitors, this monitor has standard buttons on the right for Adding Actions, setting Advanced Monitor Options and setting the Monitor Schedule.

Below is an example script that checks a database connection:

Option Explicit
Dim objconnection
Dim objrecordset
Dim strDetails

Const adOpenStatic = 3
Const adLockOptimistic = 3

Set objconnection = CreateObject("ADODB.Connection")
Set objrecordset = CreateObject("ADODB.Recordset")

objconnection.Open _
 "Provider=SQLOLEDB;Data Source=;" & _
 "Initial Catalog=;" & _
 "User ID=;Password=;"

objrecordset.Open "SELECT COUNT(*) FROM ", _
 objconnection, adOpenStatic, adLockOptimistic

If objrecordset.RecordCount <> 0 Then
   SendNotification = False
Else
   objrecordset.MoveFirst
 strDetails = "CODE RED !!!! No rows found!"
 SendNotification = True
End If

Details = strDetails

This next example checks to see if there are a certain number of files in a directory:

dim highCount
highCount = 1000
Set fso = CreateObject("Scripting.FileSystemObject")
Set oSrcFolder = fso.GetFolder("\\server\dir\tocheck")
fileCount = oSrcFolder.Files.Count

if fileCount > highCount then
   SendNotification = True
else
   SendNotification = False
end if

The last example script checks the size of a specific file:

FileToCheck = "C:\Files\Backup\dump.db"

Set objFSO = CreateObject("Scripting.FileSystemObject")

If objFSO.FileExists(FileToCheck) Then
   Set objFile = objFSO.GetFile(FileToCheck)
   If objFile.Size < 1000 Then
      SendNotification = True
      Details = FileToCheck & " is too small!"
   Else
      SendNotification = False
   End If
Else
   SendNotification = True
   Details = FileToCheck & " does not exist!"
End If

PA Server Monitor