We changed this slightly to report more accurate drive information
(hrStoreageSize or hrStorageUsed * hrStorageAllocationUnits gives size
in bytes).
 
--------------------
//JScript
//Assumption: All instances between the first and last are valid
(continuity)
//[EMAIL PROTECTED] and [EMAIL PROTECTED]
 
var oSnmpRqst =  new ActiveXObject("CoreAsp.SnmpRqst"); 
var nDeviceID = Context.GetProperty("DeviceID");
var oResult = oSnmpRqst.Initialize(nDeviceID);
if (oResult.Failed)
{
 Context.SetResult(1, "Initialization error " );
} 
else
{
 var sReturn = ""; //Good string to return
 var sBadReturn = ""; //Bad string to return
 var shrStorageDescr = "1.3.6.1.2.1.25.2.3.1.3."; //hrStorageDescr
 var shrStorageAllocationUnits = "1.3.6.1.2.1.25.2.3.1.4.";
//hrStorageAllocationUnits
 var shrStorageSize = "1.3.6.1.2.1.25.2.3.1.5."; //hrStorageSize
 var shrStorageUsed = "1.3.6.1.2.1.25.2.3.1.6."; //hrStorageUsed
 var i = 1; //First instance
 while(true) //Continue until we reach a non-existant instance
 {
  var shrDescr = oSnmpRqst.Get(shrStorageDescr + i); //hrStorageDescr
per instance
  var shrAUnits = oSnmpRqst.Get(shrStorageAllocationUnits + i);
//hrStorageAllocationUnitse per instance
  var shrSize = oSnmpRqst.Get(shrStorageSize + i); //hrStorageSize per
instance
  var shrUsed = oSnmpRqst.Get(shrStorageUsed + i); //hrStorageUsed per
instance
  if (shrDescr.Failed) //We hit an instance that doesn't exist, time to
return a string
  {
   if(sBadReturn == "") //If there was no error
   {
    //Get the Open DB connection from the Context NameSpace
    var oDb = Context.GetDB;
    var sSql = "UPDATE Device SET sNote = '' WHERE nDeviceID = " +
nDeviceID; //Clear the notes
    var oRs = oDb.Execute(sSql);
    Context.SetResult(0, sReturn); //Return our good string
   }
   else //Something went wrong
   {
    // Get the Open DB connection from the Context NameSpace
    var oDb = Context.GetDB;
    var sSql = "UPDATE Device SET sNote = '" + sBadReturn + "' WHERE
nDeviceID = " + nDeviceID; //Note all bad drives
    var oRs = oDb.Execute(sSql);
    Context.SetResult(1, sBadReturn); //Return our bad string and notify
What'sUp Gold
   }
   break; //Exit the loop
  }
  else //There are still instances
  {
   //hrStoreageSize or hrStorageUsed * hrStorageAllocationUnits gives
size in bytes
   iPercent = (parseInt(shrUsed) / parseInt(shrSize)) * 100; //Calculate
the % of drive space
   shrUsed = (shrUsed * shrAUnits) / 1073741824; //bytes to GB (shrUsed
* shrAUnits) / (1024 * 1024 * 1024)
   shrSize = (shrSize * shrAUnits) / 1073741824; //bytes to GB (shrSize
* shrAUnits) / (1024 * 1024 * 1024)
   if(iPercent >= 90) //Set the drive space percentage here (90 = 90%)
   {
    if(sBadReturn != "") //Formatting
     sBadReturn = sBadReturn + " || "; //Formatting
    sBadReturn = sBadReturn + "[" + shrDescr + "]: " +
shrUsed.toFixed(2) + "GB of " + shrSize.toFixed(2) + "GB (" +
iPercent.toFixed(1) + "%)";
   }
   if(sReturn != "") //Formatting
    sReturn = sReturn + " || "; //Formatting
   sReturn = sReturn + "[" + shrDescr + "]: " + shrUsed.toFixed(2) + "GB
of " + shrSize.toFixed(2) + "GB (" + iPercent.toFixed(1) + "%)";
   i++; //Move on to next instance
  }
 }
}
 
Semper-Fi 

  

<<att1eabf.gif>>

Reply via email to