The context object is available to the script programmer when scripts are executing. It delivers context aspects of the device that it is operating upon. All methods and properties are retrieved using the "Context" namespace.
All scripts used in the Active Script Monitor can be used in the Active Script Performance Monitor by making one small change:
At the end, instead of setting the status to either true or false using Context.SetResult
, you need to call Context.SetValue(YourNumericValue)
. This numeric value will be stored in the statistical table and will be used for custom performance monitor reports and graphs.
We have provided several code samples for you to create useful Active Script Performance Monitors for your devices.
Note: You may have to remove the copyright information from the cut and paste if it appears when you copy from this help file.
Methods |
Method description |
|
This method allows for a message to be written to the WhatsUp Gold debug log. Example: JScript: Context.LogMessage( "Checking Monitor name using Context.GetProperty()"); VBScript: Context.LogMessage "Checking Address using Context.GetProperty()" |
|
This method allows you to store a value in the INMSerialize object. This value is retained across polls. Example: JScript: var nCount = parselnt(nNum) +1; |
|
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 monitor succeeded or not. Important: Every script should have a result, otherwise it will report back positively. Example: JScript: Context.SetResult(0, " Everything is OK"); //Success VBScript: Context.SetResult 1, " Really big big error" |
|
This method allows the code to grab a reference variable to be used in the monitor. Example: JScript: Context.GetReferenceVariable("A") A reference variable "A" would have had to have been created. |
|
This method allows you to graph a value. Example: JScript: Context.SetValue(245) |
GetProperty(sPropertyName);
This property offers access to many device specific aspects. You obtain access to these items using the names listed. These names are case sensitive.
|
The performance monitor display name |
|
The IP address of the device |
|
The device ID |
|
1 = doing discovery |
|
SNMP V1 Read community |
|
SNMP V1 Write community |
|
SNMP V2 Read community |
|
SNMP V2 Write community |
|
SNMP V3 Username |
|
SNMP V3 Context |
|
SNMP V3 Authentication password |
|
SNMP V3 Authentication protocol |
|
SNMP V3 Encrypt password |
|
SNMP V3 Encrypt protocol |
|
Windows NT Domain and User ID |
|
Windows NT Password |
JScript:
var sAddress = Context.GetProperty("Address");
var sReadCommunity = Context.GetProperty("CredSnmpV1:ReadCommunity");
var nDeviceID = Context.GetProperty("DeviceID");
JScript:
//Sending log message to the WhatsUp Event Viewer
Context.LogMessage ( "Checking Mode flag");
var nFlag = Context.GetProperty("Mode");
if (nFlag == 1)
{
Context.LogMessage ("Doing a discovery");
}
else if (nFlag == 2)
{
Context.LogMessage ("Doing a poll");
}
else if (nFlag == 3)
{
Context.LogMessage ("Must be just a test.");
}
else
{
Context.LogMessage ("Do not know the mode.");
}
//Set the result code of the check (0=Success, 1=Error)
Context.SetResult (0, "No error");
(GetDB);
This property returns an open connection to the WhatsUp Gold database.
Examples:
This example gets the Open connection and reads some values out of the WhatsUp Gold "Device" table using the deviceID context. Please refer to the WhatsUp Gold Database Schema for more information about the WhatsUp Gold schema.
var oDb = Context.GetDB;
if (null == oDb)
{
Context.SetResult( 1, " Problem creating the PRO 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");
}