在温度超过或低于范围时发出警报

<注意> 此范例仅供说明之用,本公司不提供技术支持。Ipswitch 为内容对象、SNMP API 和脚本环璄提供技术支持服务,但不对 JScript、VBScript,或活动脚本监控工具或操作的开发及侦错提供支持服务。如需此范例或自行编写脚本方面的协助,请造访 WhatsUp Gold 用户社群论坛

此主动监控工具会轮询启用 SNMP 功能的温度传感器。若温度超过或低于所配置的可接受范围,则会触发警报。

// This jscript script polls the temperature from an snmp-enabled sensor from "uptime devices" (www.uptimedevices.com),
// and makes sure the temperature is within an acceptable range configured right below.
// The OID of the temperature object for that device is 1.3.6.1.4.1.3854.1.2.2.1.16.1.14.1
var nMinAllowedTemp = 65;
var nMaxAllowedTemp = 75;
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 the temperature");
var oResponse = oSnmpRqst.Get("1.3.6.1.4.1.3854.1.2.2.1.16.1.14.1");
if (oResponse.Failed) {
Context.SetResult(1, oResponse.GetErrorMsg);
}
else {
var nTemperature = oResponse.GetValue / 10.0;
// comment out the following line to convert the temperature to Celcius degrees
//nTemperature = (nTemperature - 32) * 5 / 9;
Context.LogMessage("Success.Value=" + nTemperature + " degrees");

if (nTemperature < nMinAllowedTemp || nTemperature > nMaxAllowedTemp) {
Context.SetResult(1, "Polled temperature " + nTemperature + " is outside of the defined range " + nMinAllowedTemp + " - " + nMaxAllowedTemp);
}
else {
Context.SetResult(0, "Success");
}
}
}

另请参阅

活动脚本主动监控工具范例

监控打印机墨水存量与利用率

判断无效的用户账号活动

网络接口的监控工具带宽利用率

监控在非标准端口上执行的 SNMP 代理程序

监控不明的 MAC 地址