Script Action Context Code Examples
The following table lists several script action code examples that you can use to created useful script actions for your devices. To use these examples, select the text of the context and then copy and paste the code into the box of the Script Action dialog.
: You may need to remove the copyright information from the cut and paste if it appears when you copy from this help file.
Monitor
|
Code
|
How to return the results of the script back to WhatsUp Gold.
|
JScript
Context.SetResult(0, " Everything is OK"); //Success Context.SetResult(1, " Really big big error"); //Failure
VBScript
Context.SetResult 1, " Really big big error"
|
Logging a message to the WhatsUp Gold event viewer.
|
JScript
Context.LogMessage("This is the message");
|
Accessing the Device ID.
|
JScript
var nDeviceID = Context.GetProperty("DeviceID");
|
Accessing the IP address of the device.
|
JScript
var sAddress = Context.GetProperty("Address");
|
Accessing the WhatsUp Gold database.
|
This sample uses the device ID in context and access the 'Device' table.
JScript
// Get the Open DB connection from the Context NameSpace var oDb = Context.GetDB; if (null == oDb) { Context.SetResult( 1, " Problem creating the PRO DB object"); } else { // Get the device ID var nDeviceID = Context.GetProperty("DeviceID"); // Retrieve all columns for this device. var sSql = "SELECT * from Device WHERE nDeviceID = " + nDeviceID; var oRs = oDb.Execute(sSql); if ( !oRs.EOF ) { // Display various columns in the debug log (Event Viewer). 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"); }
|
Using Substitution variables in your script.
|
JScript
Context.NotifyProgress( "Date=%System.Date" ); Context.NotifyProgress( "Time=%System.Time" ); Context.NotifyProgress( "Names of down devices=%System.DisplayNamesDownDevices" ); Context.NotifyProgress( "Number of down devices=%System.NumberofDownDevices" ); Context.NotifyProgress( "Names of up devices=%System.DisplayNamesUpDevices" ); Context.NotifyProgress( "Number of up devices=%System.NumberofUpDevices" );
|