Script Action Context Object

This context object is available to the script programmer when scripts are executing. It delivers context aspects of the device that it is operating on. All methods and properties are retrieved using the "Context" namespace.

Note: This context object only applies to the script action plug-in.

Methods

LogMessage(sText);

This methods allows for a message to be written to the WhatsUp Gold debug log.  Messages are displayed in the Event Viewer.

Example:

JScript

Context.LogMessage( "Checking action name using Context.GetProperty()");

VBScript

Context.LogMessage "Checking Address using Context.GetProperty()"

SetResult(LONG nCode, sText);

This method allows for a result code and result message to be set. This is how you can tell the WhatsUp Gold system if the action succeeded or not.

Example:

JScript

Context.SetResult(0, "    Everything is OK"); //Success
Context.SetResult(1, "    Really big big error"); //Failure

VBScript

Context.SetResult 1, "    Really big big error"

NotifyProgress(sText);

This method allows for a message to be written to the actions progress dialog.  Messages are displayed in the Test dialog and Running Actions dialog.

Example:

JScript

Context.NotifyProgress( "Checking action name using Context.GetProperty()");

VBScript

Context.NotifyProgress "Checking Address using Context.GetProperty()"

IsCancelled();

This method is used to test whether this action has been cancelled by the user.  It is highly recommended that the script writer test this on a regular basis.  If the return is true then you must terminate your script.  A cancel can be issued by the user in the action progress dialog and by the WhatsUp Gold engine when shutting down.

Properties

GetProperty(bsPropertyName);
This property offers access to many device specific aspects. You obtain access to these items using the names listed. Theses names are case sensitive.

"ActionTypeName"

The action display name

"Address"

The IP Address of the device

"Name"

Network name of the device

"DisplayName"

Display name of the device

"DeviceID"

The device ID

"ActionTypeID"

The action type ID

"TriggerCondition"

The reason the action was fired.

Trigger values:

 1 Monitor changed from DOWN to UP
 2 Monitor changed from UP to DOWN
 4 A Passive Monitor was received...
 8 The "Test" Button was hit
16 This is a recurring action...
32 Device is UP
64 Device is DOWN

Examples:

JScript

var sAddress = Context.GetProperty("Address");
var nDeviceID = Context.GetProperty("DeviceID");

get_GetDB;

This property returns an open connection to the WhatsUp PRO database.

Examples:

JScript

This examples gets the Open connection and reads some values out of the WhatsUp Gold Device table using the deviceID in context.

var oDb = Context.GetDB;
if (null == oDb)
{
 Context.SetResult( 1, "  Problem creating the DB object");
}
else
{
 var oRs = new ActiveXObject("ADODB.Recordset");
 // Get the device ID
 var nDeviceID = Context.GetProperty("DeviceID");
 var sSql = "SELECT * from Device WHERE nDeviceID = " + nDeviceID;
 oRs = oDb.Execute(sSql);
 if ( !oRs.EOF )
 {
    var sDisplay;
    sDisplay = "" + oRs("sDisplayName");
    Context.LogMessage("Display Name=" + sDisplay);
    sDisplay = "" + oRs("nWorstStateID");
    Context.LogMessage("WorstStateID=" + sDisplay);  
    sDisplay = "" + oRs("sNote");
    Context.LogMessage("Note=" + sDisplay);   
    sDisplay = "" + oRs("sStatus");
    Context.LogMessage("Status=" + sDisplay);
 }   
 Context.SetResult( 0, "   Ok");
}