Active Script Performance Monitor context code examples
The following table lists several active script performance monitor code examples that you can use to create useful performance monitors 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 Add Active Script Performance Monitor 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
|
Polling one reference variable and perform arithmetic calculation with it.
|
// this script is a jscript that demonstrates how to use a reference variable in a script. // The reference variable "RVsysUpTime" is an SNMP reference variable defined // with an OID of 1.3.6.1.2.1.1.3 and instance of 0. // Poll reference variable RVsysUpTime var RVsysUpTime = Context.GetReferenceVariable("RVsysUpTime"); if (RVsysUpTime == null) { // Pass a non zero error code upon failure with an error message. // The error message will be logged in the Performance Monitor Error Log // and in the eventviewer. Context.SetResult(1, "Failed to poll the reference variable."); } else { // Success, use the polled value to convert sysUpTime in hours. // sysUpTime is an SNMP timestamp which is in hundredths of seconds: var sysUpTimeHours = RVsysUpTime / 3600 / 100; // Save the final value to graph: Context.SetValue(sysUpTimeHours); }
|
Using SNMP "GetNext."
|
// This scripts walks hrStorageType to find hard disks in the storage table. // A hard disk as a hrStorageType of "1.3.6.1.2.1.25.2.1.4" (hrStorageFixedDisk). // Then it gets the indexes of the hard disk in that table and for each index, it polls two new // objects in that table, the storage size and the units of that entry. // It adds everything up and converts it in Gigabytes. var hrStorageType = "1.3.6.1.2.1.25.2.3.1.2"; // Create and initialize the snmp object var oSnmpRqst = new ActiveXObject("CoreAsp.SnmpRqst"); var nDeviceID = Context.GetProperty("DeviceID"); var oResult = oSnmpRqst.Initialize(nDeviceID); var arrIndexes = new Array(); // array containing the indexes of the disks we found // walk the column in the table: var oSnmpResponse = oSnmpRqst.GetNext(hrStorageType); if (oSnmpResponse.Failed) Context.SetResult(1, oSnmpResponse.GetPayload); var sOid = String(oSnmpResponse.GetOid); var sPayload = String(oSnmpResponse.GetPayload); while (!oSnmpResponse.Failed && sOid < (hrStorageType + ".99999999999")) { if (sPayload == "1.3.6.1.2.1.25.2.1.4") { // This storage entry is a disk, add the index to the table. // the index is the last element of the OID: var arrOid = sOid.split("."); arrIndexes.push(arrOid[arrOid.length-1]); } oSnmpResponse = oSnmpRqst.GetNext(sOid); if (oSnmpResponse.Failed) Context.SetResult(1, oSnmpResponse.GetPayload); sOid = String(oSnmpResponse.GetOid); sPayload = String(oSnmpResponse.GetPayload); } Context.LogMessage("Found disk indexes: " + arrIndexes.toString()); if (arrIndexes.length == 0) Context.SetResult(1, "No disk found"); // now that we have the indexes of the disks. Poll their utilization and units var nTotalDiskSize = 0; for (var i=0; i<arrIndexes.length; i++) { oSnmpResponse = oSnmpRqst.Get("1.3.6.1.2.1.25.2.3.1.5." + arrIndexes[i]) if (oSnmpResponse.Failed) Context.SetResult(1,oSnmpResponse.GetPayload); nSize = oSnmpResponse.GetPayload; oSnmpResponse = oSnmpRqst.Get("1.3.6.1.2.1.25.2.3.1.4." + arrIndexes[i]) if (oSnmpResponse.Failed) Context.SetResult(1, oSnmpResponse.GetPayload); nUnits = oSnmpResponse.GetPayload; nTotalDiskSize += (nSize * nUnits); } // return the total size in gigabytes. Context.SetValue(nTotalDiskSize / 1024 / 1024 / 1024); // output in Gigabytes
|
Polling multiple reference variables.
|
// This script is a Jscript that will allow you to graph the percentage of restransmitted TCP //' segments over time on a device. // For this script, we use two SNMP reference variables: //' The first Reference variable RVtcpOutSegs is defined with OID 1.3.6.1.2.1.6.11 and instance 0. It polls the //' SNMP object tcpOutSegs.0, the total number of tcp segments sent out on the network. var RVtcpOutSegs = parseInt(Context.GetReferenceVariable("RVtcpOutSegs")); // The second reference variable RVtcpRetransSegs is defined with OID 1.3.6.1.2.1.6.12 and instance 0. It polls // the SNMP object tcpRetransSegs.0, the total number of TCP segments that were retransmitted on the system. var RVtcpRetransSegs = parseInt(Context.GetReferenceVariable("RVtcpRetransSegs")); if (isNaN(RVtcpRetransSegs) || isNaN(RVtcpOutSegs)) { Context.SetResult(1, "Failed to poll the reference variables."); } else { // Compute the percentage: var TCPRetransmittedPercent = 100 * RVtcpRetransSegs / RVtcpOutSegs; // Set the performance monitor value to graph Context.SetValue(TCPRetransmittedPercent); }
|
The Active Script Performance Monitor context object
About the Active Script Performance Monitor context object
More example code
Active Script Monitor context code examples
Active Script Action context code examples
Information on the SNMP API
Using the SNMP API