Monitor Everything with Monitis – And do it easily with PowerShell – Part 7

Hardware Inventory with Monitis Custom Monitors

In the last article, we introduced custom monitors, and explained the benefits of agentless monitoring, and we showed how you can use some of the built in PowerShell features to save time and typing when creating custom monitors.

Today, we’ll start on the first of several practical end-to-end scenarios.  We’re going to create a custom hardware inventory in Monitis with PowerShell, and update it in the same script.

To do this, we’re going to use 3 different custom monitor commands:

Add-MonitisCustomMonitor
Get-MonitisCustomMonitor
Update-MonitisCustomMonitor

 

With these 3 commands, we’ll be able to monitor absolutely anything with Monitis.  You will have a script that you can run right on any Windows box, because Powershell is installed by default on every Windows machine from Win7/Server2k8R2 onward.

PowerShell has access to an amazing motherload of information, and a very simple example of what you can do with is collecting hardware information from WMI.  WMI is a Windows operating system component that contains tons of information about every part of the operating system, organized into little types of information called “classes”.  For the next few days, we’re going to explore different parts of using WMI with PowerShell, walking thru how to use each class and why you’d monitor it with Monitis.

To start out with, let’s look at how you get hardware inventory.  WMI has tons of information you could use for a hardware inventory, but let’s start with the very basics.  There’s a class in WMI called Win32_ComputerSystem, and it contains the make and model of the PC.

Check it out by running:

Get-WmiObject Win32_ComputerSystem

To use this in a custom monitor, we’ll save it to a variable first.

$computerSystem = Get-WmiObject Win32_ComputerSystem

Now that we’ve got it in a variable, we can keep using the information from it without spending time to get it from WMI.   We want to upload two pieces of information to Monitis:  $computerSystem.Model and $computerSystem.Manufacturer .

To make a script that does this reliably, we’re going to quickly check that the monitor doesn’t exist, and create it if needed, and then update the monitor.

Update-MonitisCustomMonitor is the command that updates the monitor.  To use it, you’ll need to pass in a hashtable of values.   The format for this is

@{
   Key = $value
 }.

When you pass a hashtable into Update-CustomMonitor, it will add the items in the hashtable to the custom monitor.  In the script below, the first few lines check for the monitor, and create the monitor if it doesn’t exist.  Line 5 gets the values from WMI, and the Update-MonitisCustomMonitor command pushes the results.

$monitorExists = Get-MonitisCustomMonitor -Name HardwareInventory
if (-not $monitorExists) {
   Add-MonitisCustomMonitor -Name HardwareInventory -Parameter Model, Manufacturer
}

$computerSystem = Get-WmiObject Win32_ComputerSystem

Update-MonitisCustomMonitor -Name HardwareInventory -value @{
    Model = $computerSystem.Model
    Manufacturer = $computerSystem.Manufacturer
}

That’s it.  Run this on any box, and monitor your hardware with Monitis.

Next time, we’ll show more of how you can use information in WMI to keep an eye on your Windows installations with Monitis.

Monitor Everything with Monitis – And do it easily with PowerShell – Part 1

Monitor Everything with Monitis – And do it easily with PowerShell – Part 2

Monitor Everything with Monitis – And do it easily with PowerShell – Part 3

Monitor Everything with Monitis – And do it easily with PowerShell – Part 4

Monitor Everything with Monitis – And do it easily with PowerShell – Part 5

Monitor Everything with Monitis – And do it easily with PowerShell – Part 6

You might also like