Javascript must be enabled to download our products and perform other essential functions on the website.

This help page is for version 3.8. The latest available help is for version 9.4.

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.

Globals

The following global variables and methods are available within the scripting engine:

ComputerName

This read-only string variable is the name of the computer that the monitor is attached to.
Ex: myStr = ComputerName

Details

This is a string value. This value is passed to any attached actions as the details for the action (ie the content of an email notification for example).
Ex: Details = "Alert! Can't contact remote system"

FireActions
SendNotifications

This is a boolean value. Either FireActions or SendNotifications can be used -- they are identical. If the value is set to True, actions attached to the monitor will fire. If it is False, they will not fire. The value defaults to False.
Ex: FireActions = true

GetStatID
RecordStat

GetStatID and RecordStat are used together to record integral data values to the database for reports.

GetStatID is a function that takes a single string value and returns an integer statID. The string value should be a useful name to you, such as the name of the thing you're probing with the script. Including the server/device name in the string would be a good idea if a similar script will run on multiple computers -- it will make it easier to choose the specific data that you want when you create reports.
Ex: statID = GetStatID("ftpSvr1-myObject")

RecordStat is a method that takes two inputs -- the statID obtained from GetStatID above, and the integer value to record to the database. The time the value is recorded also gets saved to the database for use in line charts, etc.
Ex: RecordStat statID, objectValue

Sleep

This method takes a single integer value, which is the number of milliseconds that the script should stop and sleep. Be careful about using this causing too many monitors to sleep for very long means other monitors may not get run. Ex: Sleep 1500

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.

Standard Configuration Options

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

Example Scripts

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 and records it to the database:

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

Set objFSO = CreateObject("Scripting.FileSystemObject")

If objFSO.FileExists(FileToCheck) Then
   Set objFile = objFSO.GetFile(FileToCheck)

   statID = GetStatID(FileToCheck)
   RecordStat statID, objFile.Size

   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