使用 SNMP GetNext

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

此性能监控工具会游走 (Walk) hrStorageType MIB,以寻找保存表中的硬盘。找到硬盘后,监控工具会取得硬盘索引,并轮询新的对象 (保存空间大小与单位)。

// 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

另请参阅

活动脚本性能监控工具范例

以图形表示打印机墨水存量利用率

轮询参考变量并计算

以图形表示温度监控工具

轮询多个参考变量