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.
We have provided several code samples for you to create useful Active Script Monitors for your devices.
Methods |
Method description |
|
This method allows for a message to be written to the WhatsUp Gold debug log. Example: JScript:
VBScript:
|
|
This method allows you to store a value in the INMSerialize object. This value is retained across polls. Example: JScript:
|
|
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:
VBScript:
|
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 active monitor display name |
|
The IP address of the device |
|
The device ID |
|
1 = doing discovery |
|
The active monitor's type ID |
|
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. 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");
}