Get pending windows updates status on ZABBIX using custom LLD (Low Level Discovery) and PowerShell

Just recently I got some time, and was rethinking the solution of reading windows updates.

At the beginning I thought I will use PowerShell to get update list and later use dependent items to parse the script output, but this wouldn’t be so nice, as I would need to manually work on parsing the file on the zabbix side, create items etc. + so far zabbix does not offer (I work on 3.4, at the time being 4.0 available) LLD on dependent items.

Well, why not use current LLD to read them?

Zabbix_pendingupdates4

You can do it – I will show you how.

First you need to increate yout timeout for scripts from the default 3 to 30 seconds, remember to restart the zabbix-server service after that.

Then, you need to have this PowerShell script:

https://github.com/zaicnupagadi/ZabbixWindowsUpdatesLLDPowerShell

Put it as your userparameter like this:

UserParameter=GetPendingUpdates[*],%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -nologo -command “& ‘c:\Program Files\Zabbix Agent\scripts\ZBX_GetPendingUpdates.ps1’ $1”

Now create template with dicovery rule:

Zabbix_pendingupdates1

Discovery rule:
Name: GetAllPendingUpdates
Type: Zabbix agent
Key: GetPendingUpdates[{$GETUPDATESTATE}]
{$GETUPDATESTATE} is defined in my case at the template level like this: Updates:Security-Updates

This GETUPDATESTATE need to be like that as Zabbix does not allow for many special characters in the parameters, this will be parsed later in the userparameter script so don’t worry. Just remember that “:” divides types of updates, and “-” is for space, so eventually Updates:Security-Update equals “Updates”,”Security Update” in the script.

Zabbix_pendingupdates2

You can test it with zabbix_get:

$ zabbix_get -s -k GetPendingUpdates[Updates:Security-Updates:Windows-10]
{
“data”:

[
{
“{#UPNAME}”: “Updates”,
“{#UPNUMBER}”: 3
},
{
“{#UPNAME}”: “Security Updates”,
“{#UPNUMBER}”: 20
},
{
“{#UPNAME}”: “Windows 10”,
“{#UPNUMBER}”: 0
}
]
}

Now create an item prototype:

Zabbix_pendingupdates3

Item prototype:
Name: Number of pending “{#UPNAME}” updates
Type: Calculted
Key: UPNUMBER[{#UPNUMBER}]
Formula: {#UPNUMBER}

After few minutes you will get:

Zabbix_pendingupdates4

Zabbix_pendingupdates5

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s