The original request was here: http://www.zabbix.com/forum/showthread.php?p=49493. Someone was looking for a way to monitor available Windows updates. I put together a crude script based on the one here: http://www.microsoft.com/technet/scr....mspx?mfr=true
The script below, coupled with a scheduled task, will allow you to make triggers based on the count of available Windows updates on a Windows 2000, 2003, XP, Vista, and maybe Windows 7 machine.
The WSH script. Save this to a file (such as winupdate.wsh):
You will need to change variables serverName, hostName, and zbxSender. They are the Zabbix Server, Agent Hostname, and location of the zabbix_sender binary.
You will need to add a scheduled task to run this script as often as you want to get Windows Update data (I run it every 6 hours since I only really care about Windows Update data daily).
Then create some new items for your Template or Host to use it. Create an item for each of these 3 keys:
Settings for win_updates[total], win_updates[high], and win_updates[optional]:
Settings for win_updates[reboot]:
Example triggers for high priority updates and reboot required:
High priority updates:
{Your_Template:win_updates[high].last(0)}>0
Reboot required:
({Your_Template:win_updates[high].last(0)}=0)&({Your_Template:win_updates[reboot].str(True)}=1)
You may also wish to trigger in case no data has been received from the script after a set time (which could indicate a problem with the script running):
{Your_Template:win_updates[total].nodata(86400)}=1
This would trigger when no data has been received for 86400 seconds (24 hours).
Hope someone finds this helpful!
The script below, coupled with a scheduled task, will allow you to make triggers based on the count of available Windows updates on a Windows 2000, 2003, XP, Vista, and maybe Windows 7 machine.
The WSH script. Save this to a file (such as winupdate.wsh):
Code:
serverName = "zabbix.mydoamin.com"
hostName = "web_server.mydomain.com"
zbxSender = "C:\Program Files\Zabbix Agent\zabbix_sender.exe"
updatesHigh = 0
updatesOptional = 0
Set objSearcher = CreateObject("Microsoft.Update.Searcher")
Set objSysInfo = CreateObject("Microsoft.Update.SystemInfo")
Set objResults = objSearcher.Search("IsInstalled=0")
Set colUpdates = objResults.Updates
Set WSHShell = CreateObject("WScript.Shell")
For i = 0 to colUpdates.Count - 1
If (colUpdates.Item(i).IsInstalled = False AND colUpdates.Item(i).AutoSelectOnWebSites = False) Then
updatesOptional = updatesOptional + 1
ElseIf (colUpdates.Item(i).IsInstalled = False AND colUpdates.Item(i).AutoSelectOnWebSites = True) Then
updatesHigh = updatesHigh + 1
End IF
Next
updatesTotal = (updatesHigh + updatesOptional)
WSHShell.Exec zbxSender & " -z " & serverName & " -s " & hostName & " -k win_updates[total] -o " & updatesTotal
WSHShell.Exec zbxSender & " -z " & serverName & " -s " & hostName & " -k win_updates[high] -o " & updatesHigh
WSHShell.Exec zbxSender & " -z " & serverName & " -s " & hostName & " -k win_updates[optional] -o " & updatesOptional
WSHShell.Exec zbxSender & " -z " & serverName & " -s " & hostName & " -k win_updates[reboot] -o " & objSysInfo.RebootRequired
WScript.Quit 0
You will need to add a scheduled task to run this script as often as you want to get Windows Update data (I run it every 6 hours since I only really care about Windows Update data daily).
- Click to 'Add Scheduled Task' in the Scheduled Tasks window.
- For program to run, click the Browse button and locate the check_updates.vbs file and select it.
- Check to perform this task Daily or on a time schedule you want (customizable).
- For user to run as, enter in without the quotes, "NT AUTHORITY\SYSTEM", it doesn't need a password (or an administrator use if you wish).
- Right click on the schedule and clock 'Run' to have it send data to the Zabbix Server
Then create some new items for your Template or Host to use it. Create an item for each of these 3 keys:
- win_updates[total]
- win_updates[high]
- win_updates[optional]
- win_updates[reboot]
Settings for win_updates[total], win_updates[high], and win_updates[optional]:
- Type: Zabbix trapper
- Type of information: Numeric (unsigned)
- Keep history: 7
Settings for win_updates[reboot]:
- Type: Zabbix trapper
- Type of information: Character
- Keep history: 7
Example triggers for high priority updates and reboot required:
High priority updates:
{Your_Template:win_updates[high].last(0)}>0
Reboot required:
({Your_Template:win_updates[high].last(0)}=0)&({Your_Template:win_updates[reboot].str(True)}=1)
You may also wish to trigger in case no data has been received from the script after a set time (which could indicate a problem with the script running):
{Your_Template:win_updates[total].nodata(86400)}=1
This would trigger when no data has been received for 86400 seconds (24 hours).
Hope someone finds this helpful!

Comment