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

This help page is for version 4.1. 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. A good VBScript reference is available at: http://msdn.microsoft.com/en-us/library/d1wf56tt.aspx

There are two Test buttons. One will run the script within the Console. The other will send the script to the monitoring service that is monitoring the target computer (Central Monitoring Service or a Satellite) and run the script there. This helps find any problems that might come up from the script possibly running on a different machine, or running as a different user (the service Log As user).

ionicons-v5-h

Keep in mind that when the script runs, it might run on a different computer than where you are editing it. That means drive mappings, HKEY_CURRENT_USER registry hive, Internet Explorer settings and the currently running user will often be different.

IMPORTANT: Do not show any user interface elements in the script -- they will not be visible in the monitoring service and will block the script from ever completing.

Additional Script Elements

Besides the VBScript objects and elements, the following additional 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.

Example:
   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).

Example:
   Details = "Alert! Can't contact remote system"

FireActions
SendNotification

This is a boolean value. Either FireActions or SendNotification 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.

Example:
   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.

Example:
   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.

Example:
   RecordStat statID, objectValue

GetValue

This method takes a text name and returns the value that was stored earlier via the StoreValue call described below. If nothing was ever stored with that name, an empty string is returned.

Example:
   prevState = GetValue "LastState"

MachineID

Returns the numeric value that uniquely identifies this computer within the application. Useful in conjunction with the External API.

SendMail

This method sends an email message to the recipient that you choose.

Example:
   SendMail "to_address@host.com", "from_address@host.com", "Subject of message", "Body of email message"

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.

Example:
   Sleep 1500

StoreValue

This method takes a text name, and a text value and stores it. This named value can be retrieved later (even when the script runs next) via GetValue. Note that these values will be persisted in the configuration database and kept in memory with the monitor, so they should be kept relatively small (a few hundred characters long or less).

Example:
   StoreValue "LastState", "1|15|OK"

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

Check a database value

Option Explicit
Dim objconnection
Dim objrecordset
Dim strDetails

Const adOpenStatic = 3
Const adLockOptimistic = 3

SendNotification = False

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

objconnection.Open _
 "Provider=SQLOLEDB;Data Source=<data_base_server>;" & _
 "Initial Catalog=<database_name>;" & _
 "User ID=<username>;Password=<password>;"

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

If objrecordset.RecordCount >= 1 Then
   objrecordset.MoveFirst
   'ensure there are at least 1000 rows
   If objrecordset.Fields(0) < 1000 Then
      SendNotification = True
      strDetails = "There are only " & objrecordset.Fields(0) & " rows in the table!"
   End If
Else
   strDetails = "CODE RED !!!! No rows found!"
   SendNotification = True
End If

Details = strDetails

Check 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

Check the size of a specific file and record to a 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

Check if the newest file is older than 6 hours old (to ensure new files are being created)

DirToCheck = "C:\Logs"
Dim fNewest
set oFolder=createobject("scripting.filesystemobject").getfolder(DirToCheck)
For Each aFile In oFolder.Files
   If fNewest = "" Then
      Set fNewest = aFile
   Else
      If fNewest.DateCreated < aFile.DateCreated Then
         Set fNewest = aFile
      End If
   End If
Next

if fNewest.DateCreated < (DateAdd("h",-6,Now())) then
   SendNotification = True
   Details = "NEWEST LOG FILE older than 6 hours (latest file " & fNewest.DateCreated & ")"
else
   SendNotification = False
end if

Launch a program and check the result code

Dim objShell
Set objShell = CreateObject("WScript.Shell")
'Spaces in the path below can cause trouble for the Run method
exitCode = objShell.Run("C:\Test\App.exe", 1, True)
Set objShell = Nothing

if (exitCode = 0) then 'assuming 0 means OK in this case
    FireActions = false
    Details = "Everything is OK"
Else
    FireActions = true
    Details = "Test app returned " + exitCode
End If

PA Server Monitor

Help Map