Monitoring Windows Updates Zabbix

The following VB script has the ability to check last time Windows update was run, the number of priority updates, the number of total updates (sum of optional and priority), as well as a listing of available updates.

Note that the script can take a few seconds to run for all but checking the time of the last updates, so when running this as a Zabbix check, it may be better to do this as an active check, to run the script as an scheduled that writes to file every X hours, and then have the Zabbix agent check the values in the file, or to increase time outs.

First the VB script:

Set args = WScript.Arguments

IF (WScript.Arguments.Count > 0) Then
	IF (WScript.Arguments.Item(0) = "last") Then
		Set objSession = CreateObject("Microsoft.Update.Session")
		Set objSearcher = objSession.CreateUpdateSearcher
		Set colHistory = objSearcher.QueryHistory(0,1)
		
		For Each objEntry in colHistory
			WScript.Echo  date2epoch(objEntry.Date)
		Next
		
	Else
		Wscript.Echo getUpdates(WScript.Arguments.Item(0))
	End IF	
Else
	Wscript.Echo "ERROR in CheckWinUpdate parameter"
End IF


Function getUpdates(updateType)
	Set objSearcher = CreateObject("Microsoft.Update.Searcher")
	Set objResults = objSearcher.Search("IsInstalled=0")
	Set colUpdates = objResults.Updates

	updatesHigh = 0
	updatesOptional = 0
	priorityUpdateList = "Priority Updates:" & vbCrLf
	optionalUpdateList = "Optional Updates:" & vbCrLf

	For i = 0 to colUpdates.Count - 1
		If (colUpdates.Item(i).IsInstalled = False AND colUpdates.Item(i).AutoSelectOnWebSites = False) Then
			updatesOptional = updatesOptional + 1
			title = "Optional Update"
			optionalUpdateList = optionalUpdateList & colUpdates.Item(i).Title & vbCrLf
		ElseIf (colUpdates.Item(i).IsInstalled = False AND colUpdates.Item(i).AutoSelectOnWebSites = True) Then
			updatesHigh = updatesHigh + 1
			title = "High Priority Update"
			priorityUpdateList = priorityUpdateList & colUpdates.Item(i).Title & vbCrLf
		End IF
	Next

	IF (updateType = "priority") Then
		getUpdates = updatesHigh
	ElseIf (updateType = "optional") Then
		getUpdates = updatesOptional
	ElseIf (updateType = "total") Then
		getUpdates = (updatesHigh + updatesOptional)
	ElseIf (updateType = "full") Then
		getUpdates = priorityUpdateList & vbCrLf & optionalUpdateList
	Else
		getUpdates = "ERROR in CheckWinUpdate parameter"
	End IF
End function

Function getmydat(wmitime) 
  dtmInstallDate.Value = wmitime 
  getmydat = dtmInstallDate.GetVarDate
End function


function date2epoch(myDate)
date2epoch = DateDiff("s", "01/01/1970 00:00:00", myDate)
end function

For the remainder of the examples, I have this script saved in C:\Program Files\Zabbix Agent\Scripts\CheckWinUpdate.vbs”. If you save it somewhere else, be sure that you call it with the correct path.

The script can be called like:

C:\> cscript //NoLogo "C:\Program Files\Zabbix Agent\Scripts\CheckWinUpdate.vbs" [type]

Valid values for [type] are:

  • last – Will return the timestamp (in seconds from epoch) of the last time that Windows Updates was run.
  • optional – The number of “optional” updates that are available for installation.
  • priority – The number of “priority” updates that are available for installation.
  • total – The total number of updates that are available for installation. (sum of “optional” and “priority”)
  • full Returns a list of updates available.

Once this script is created, add a UserParam like this:

UserParameter=custom.check_win_update[*],cscript //NoLogo "C:\Program Files\Zabbix Agent\Scripts\CheckWinUpdate.vbs" $1

This can then be added as a Zabbix item like:

custom.check_win_update["last"]

For the “last” type, set the unit as “unixtime” to have it convert to human dates. Use unsigned integer for the optional, priority, and total types. Use text or log for the full type.

Taken from – http://zabbix.org/wiki/Monitoring_Windows_Updates

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.