Monitoring printer ink level and utilization

Note: This example is provided as an illustration only and is not supported. Technical support is available for the Context object, SNMP API, and scripting environment, but Ipswitch does not provide support for JScript, VBScript, or developing and debugging Active Script monitors or actions. For assistance with this example or with writing your own scripts, visit the WhatsUp Gold user community.

This active monitor polls an object of the printer mib to gather the ink level information and then computes the ink percent utilization of a printer.

The active monitor will fire an alert if the utilization exceeds a value set on the first line of the script.

Note: This script was tested on an HP MIB.

Run the SNMP MIB Walker net tool to check the OIDs of the two polled objects and eventually adjust their instance (1.1 in this example):

1.3.6.1.2.1.43.11.1.1.8.1.1 and 1.3.6.1.2.1.43.11.1.1.9.1.1.

Note: This script is included as a code example only. The Printer Active Monitor should be used to monitor printers.

var nMarkerPercentUtilization = 70; // This monitor will fail if the printer ink utilization is above this value %.
var oSnmpRqst = new ActiveXObject("CoreAsp.SnmpRqst");
var nDeviceID = Context.GetProperty("DeviceID");
var oComResult = oSnmpRqst.Initialize(nDeviceID);
if (oComResult.Failed) {
Context.SetResult(1, oComResult.GetErrorMsg);
}
else {
// poll the two counters
Context.LogMessage("Polling marker maximum level");
var oResponse = oSnmpRqst.Get("1.3.6.1.2.1.43.11.1.1.8.1.1");
if (oResponse.Failed) {
Context.SetResult(1, oResponse.GetErrorMsg);
}
var prtMarkerSuppliesMaxCapacity = oResponse.GetValue;
Context.LogMessage("Success. Value=" + prtMarkerSuppliesMaxCapacity);

Context.LogMessage("Polling marker current level");
oResponse = oSnmpRqst.Get("1.3.6.1.2.1.43.11.1.1.9.1.1");
if (oResponse.Failed) {
Context.SetResult(1, oResponse.GetErrorMsg);
}
var prtMarkerSuppliesLevel = oResponse.GetValue;
Context.LogMessage("Success. Value=" + prtMarkerSuppliesLevel);

var nPercentUtilization = 100 * prtMarkerSuppliesLevel / prtMarkerSuppliesMaxCapacity;

if (nPercentUtilization > nMarkerPercentUtilization) {
Context.SetResult(1, "Failure. Current Utilization (" + (nPercentUtilization + "%) is above the configured threshold (" + nMarkerPercentUtilization) + "%)");
}
else {
Context.SetResult(0, "Success. Current Utilization (" + (nPercentUtilization + "%) is below the configured threshold (" + nMarkerPercentUtilization) + "%)");
}
}

See Also

Example active script active monitors

Alert when temperature exceeds or drops out of range

Determine invalid user account activity

Monitor bandwidth utilization on an interface

Monitor an SNMP agent running on a non standard port

Monitor for unknown MAC addresses