Starting from Zabbix 2.0, there is an host inventory tab for every host you add to Zabbix.

By default, only the OS field get’s populated by System Information on a Windows host that’s being monitored using the Zabbix agent.

Zabbix_HostInventory_Default

However, you can use PowerShell using WMI queries to fill the Host Inventory tab of your Windows hosts with more useful data.

The PowerShell script below can be used to populate the following fields in the Host Inventory tab:

  • Name
  • OS (Full Details)
  • Serial Number A
  • HW Architecture
  • Vendor

You can of course, add more functions to the script to populate other fields.

Note: I have used Get-WmiObject in favour of the newer and better Get-CimInstance, because we still have servers running PowerShell version 2.0. Feel free however to change this if all your servers are running PowerShell v3 or higher.

Save the scrip as Get-HostInventory.ps1 and save it on the Windows server(s) where you want to use this. I store them in C:Zabbix, along with the agent.

Next, we need to add a userparameter to the Zabbix agent configuration file in order for Zabbix to use these PowerShell functions. This config file is usually named zabbix_agentd.conf and in my case it’s located in C:Zabbix.

Assuming your Zabbix folder is C:Zabbix and the script is stored in the same directory with the name Get-HostInventory.ps1, the userparameter line should look like this:

Restart the Zabbix agent for the change to take effect.

Make sure that the execution policy of PowerShell is set to RemoteSigned, otherwise, the script won’t be able to run.

To set the execution policy in PowerShell, open PowerShell in an elevated prompt and type the following oneliner:

To test the script using Zabbix server, you can use the Zabbix_get command. For example:

zabbix_get -s <IPaddress or fqdn> -p 10050 -k HostInventory_[ComputerName]

Where <IPaddress or fqdn> should be replaced by your server IP or fqdn.

If everything is working, we can start adding the querying the objects in Zabbix.

First thing you should do is set the Host Inventory to automatic on your host. By default, host inventory is disabled on a per-host base. I prefer to do a mass update of all Windows Host and set this to automatic. Here’s how:

  1. Login to your Zabbix FrontEnd environment
  2. Select all hosts you want to change and select Mass Update
  3. Switch to the Inventory tab and check the Inventory mode checkbox. Use the dropdown to set it to Automatic.
  4. Keep all other settings as they are and choose Update.

Here’s a graphical example:

Zabbix_HostInventory_FrontEnd_Automatic

 

Now we can start creating the items in Zabbix and link them to hostinventory lines, using the Zabbix frontend.
I prefer to use a Template for Hostinventory, so I can add all hosts that use the script and manage the items centrally. Feel free to create Host items if you like. Here’s how to create the items using a new template:

  1. Login to your Zabbix FrontEnd environment
  2. Go to Configuration-Templates and choose Create Template.
  3. Give your template a name. I’ve named it Template OS Windows Host Inventory
  4. Fill in the following details:
    1. Name: For example: HostInventory – ComputerName
    2. Type: Zabbix Agent
    3. Key: In this case, it should map to the ComputerName item as follows: HostInventory_[ComputerName]
    4. Type of information: Text
    5. Update Interval: I used 1 day as an interval, you don’t need to query these values too frequently. Value for 1 day is 86400.
    6. History storage period (in days): I’ve set this to 7 days.
    7. Application: I’ve created a new application call Host Inventory for easy sorting.
    8. Populates host inventory field: map this to the right field in the Host Inventory tab, in this case Name
  5. Save your Item and repeat for the other items in the script, which are:
    1. HostInventory_[HWArchitecture]
    2. HostInventory_[SerialNumberA]
    3. HostInventory_[Vendor]
    4. HostInventory_[OSFullDetails]
  6. Finally, link your template to the hosts you have configured with the hostinventory script. Items should start getting populated within the day.

Note: You could set the Update interval very short at first to test this script and start filling the host inventory fields quickly. Once they’re filled, I recommend to set the update interval of these kind of items to once a day.

Here’s a screenprint of a Host inventory item as an graphical example:

Zabbix hostinventory populated

I hope you’ll find this post useful and can use this in your own Zabbix environment 🙂

  1. You’ll need an API user with write permissions for the hosts. If you run the script periodically from cron, you won’t have to think about the inv. mode ever again

  2. You’ll need an API user with write permissions for the hosts. If you run the script periodically from cron, you won’t have to think about the inv. mode ever again

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">