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

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

  1. Hi Pawel

    Thank you for that nice and easy solution. I just found one error regarding the item prototype. It should be
    Key: UPNUMBER[{#UPNAME}]
    as you will get an error message when more than one type of updates has the same amount of pending updates, especially when they are all 0.

    Regards
    Ronald

    1. Hey!

      Well, just checked our production if I made any changes after that – for me it work well with “UPNUMBER[{#UPNUMBER}]”.

      I show what updates I check in “Number of pending “{#UPNAME}” updates” so the name of the item, and the number of the item is showed in the actual value.

      Cheers!
      J

  2. Hi Pafcio,
    It’s any change to improve your ps scripts for w2k3 (for rest works perfecto!)
    [root@SCMWRK03 ~]# zabbix_get -s xx.xx.xx.xx -k GetPendingUpdates[Updates:Security-Updates]

    Unexpected token ‘in’ in expression or statement.

    At C:\Program Files\Zabbix Agent\scripts\ZBX_GetPendingUpdates.ps1:24 char:26

    + if ($category.name in <<<< $AllUpdates){

    + CategoryInfo : ParserError: (in:String) [], ParseException

    + FullyQualifiedErrorId : UnexpectedToken

    https://ibb.co/sySZ1WR

    Regards,
    MR

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