This is a public Media Gallery  publicRSS

Active Monitor

    WMI and AD Inventory for Windows Devices
    Active Monitor posted 6/26/09 by Bill Meyers, last edited 7/10/09 by Will Sansbury
    6254 Views, 10 Comments
    Name:
    WMI and AD Inventory for Windows Devices
    Description:

    I grabbed this code from forums.ipswitch.com (http://forums.ipswitch.com/Topic37592-14-1.aspx?Highlight=inventory) and customized it a bit more to obtain more info through WMI and AD.  It could probably use a little expert cleaning but it works great for us.  I set it to run everytime a monitor goes down.  We configure our actions to alert after 5 mins of down time so it has plenty of time to run...it only takes a few seconds...  When we receive the email we can then see all of the inventory results in the body of the message, which helps out a great deal.  It's good for low disk space alerts.  It keeps you from having to log into the server to see how much free space is actually left.  Also, if you want to inventory a device manually, just run a Test on thsi monitor from the Active Monitor library on any Windows device and it will populate the attribute fields.

    Language:
    VB Script
    Code:
    Disclaimer:
    All scripts found on wugSpace are provided as-is with no warranty or guarantee. These scripts are not supported by Ipswitch Technical Support. If you have a problem with this script, please post is in the comments.

    Comments

    • posted 6/26/09 by Stanley Johnson

      I love the idea behind this script.  I hadn't previously considered having the system do some additional "fact finding" before the time arrived to begin notifications.  

      Reply to this Comment

    • posted 11/30/09 by Oliver Lewis

      Hi,

      Can this be used as an Active Script Action? I can use it ok as an Active Script Monitor but I only want it triggured when a device is 'Up 5 mins'. When I set it as an action I get Object Required next to errors.

      Reply to this Comment

    • posted 11/30/09 by Bill Meyers

      Absolutely, that's how we do it except I have it run as soon as a device status changes to Down.  I have the script set up as an Active Monitor just so I can test it and manually populate attributes on devices.  I use the same script as an Action and have it applied to all Action Policies, again when a device status changes to Down. 

      I corrected the error handler so you can now see the actual error.  Just move line 57 (objWMIService.Security_.impersonationlevel = 3) to line 174 (below Else statement).

      I also updated the way that disk space is displayed.  Rather than each disk being seperated by a pipe | I have each disk on it's own line.  It's really just personal preference but I think it reads a lot better.  Replace lines 206 - 212 with the code below.  This also adds percentage full to the end of the line.  Keep in mind that the end of the string must end in a period otherwise Outlook will remove the extra line breaks and the entire string will end up on one line.

      ' *** Disk Space ***
      Set colDisks = objWMIService.ExecQuery ("Select * from Win32_LogicalDisk WHERE Description = 'Local Fixed Disk'")
         For each objDisk in colDisks
          sDiskID = objDisk.DeviceID
          sFree = Round(objDisk.FreeSpace / ConvertKB2GB, 2)
          sTotal = Round(objDisk.Size / ConvertKB2GB, 2)
          sUsed = sTotal-sFree
          sPercent = Round(sUsed / sTotal, 2) * 100
          sDisk = sDisk & "Disk " & sDiskID & " " & sFree & " GB Free of " & sTotal &  " GB (" & sPercent & "% Full)." & vbCrLf
      Next

      ' *** Remove last vbCrLf from end of string (sDisk) ***
          iLen = Len(sDisk)
          sDisk = Left(sDisk, iLen - 2)

      Reply to this Comment

    • posted 11/30/09 by Oliver Lewis

      Thanks for that. I will have to wait and see what the error is. Maybe I should manually populate attributes on the devices too. How can it work for you when a device status has just gone down? Wouldn't the device be unaccessible?

      I've added an additional attribute to the script to show the current user which I find pretty handy.

      ' *** Current User ***
      'Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & sAddress & "\root\cimv2")
      Set colSettings = objWMIService.ExecQuery ("SELECT * FROM Win32_ComputerSystem")

         For Each objComputer in colSettings
          sCurrentUser = objComputer.UserName
         Next

      Context.LogMessage "CurrentUser=" & sCurrentUser

      Reply to this Comment

    • posted 11/30/09 by Bill Meyers

      If ping is down, yes, but I originally created this script to provide actual disk space.  We use disk space WMI monitors to alert if a drive is 90% Full.  So when a disk exceeds that threshold we receive the alert with updated free mb/gb and actual percentage free.  This way we don't have to log onto the computer to see that a 300 GB drive still has 30 GB free, which means it doesn't need to be addressed immediately.  MS says that disk performance is degraded when it's running at 90% full or greater, which is why we have these alerts setup, but with most disks being quite large these days, these alerts often get put to the side since there is still actually plenty of space remaining.

      Reply to this Comment

    • posted 12/1/09 by Oliver Lewis

      Ok, I've had a chance to test this again. The error I am getting is 'Access is Denied'. I am using the exact same script that works as an active monitor test and the same windows credentials.

      Any ideas what this could be?

      Reply to this Comment

    • posted 12/1/09 by Oliver Lewis

      Got it working. The Ipswitch WhatsUp Engine service was running as local system. Changed it to domain admin and it worked.

      Reply to this Comment

    • posted Jan 12 by Lewis Palmer

      How is this information diplayed in an email. I can't seem to figure it out. Thanks.

      Reply to this Comment

    • posted Jan 14 by Bill Meyers

      Each value gets added to an attribute on the device that you run this script against.  Just add the percent variable for the attribute that you want to display in your email action.

      For example:
      %Device.Attribute.AttributeName

      If you wanted to display the attribute called SerialNumber you would use:
      %Device.Attribute.SerialNumber

      You can also add a title in front of the variable:
      Serial Number: %Device.Attribute.SerialNumber

      Reply to this Comment

    • posted Apr 20 by Raymond Au

      Thanks for the script. But I got errors during test run, the script seems getting into a dead looped at "Do Until objRecordSet.EOF"  til timeout

      Checking Address=192.168.10.10
      DeviceID=158
      IP Address=192.168.10.10
      OS=Microsoft Windows Server 2003 Enterprise Edition (Service Pack 2)
      HostName=HK-WN010
      Manufacturer=HP
      Model=ProLiant DL380 G5
      Domain=domain
      Serial=SGH646XXXX   
      Searchbase = domain
      Location=
      Owner=
      Location=
      Owner=

      .

      .

      .

      Location=
      Owner=

      Error: The script timed out because it exceeded 60 seconds.

      --------

      Platform: WhatsUp v14.1.2 / W2K8 SP2 / SQL2005 Ent.

      can anyone help ? thanks

      Reply to this Comment