[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Windows update check monitor added to the Shire



Here is a vbscript I use to test for needed updates. I did not put any checks in for the existence of bbwin. I run my script from a Windows task and so I don't use the file system object to write the file-I just redirect stdout to a file in my bbwin's tmp directory. Feel free to modify as you see fit.

Ray

'code begins here
'Change these to match your environment
Const AlarmRedLevel = 10
Const AlarmYellowLevel = 5
Const AlarmRed = "red"
Const AlarmYellow = "yellow"
Const AlarmGreen = "green"

Dim oSearcher, oResults, oUpdates, oShell
Set oSearcher = CreateObject("Microsoft.Update.Searcher")
Set oResults = oSearcher.Search("Type='Software'")
Set oUpdates = oResults.Updates
Set oShell = WScript.CreateObject("WScript.Shell")

Dim strOut, IsInstalled, strKBs, strURL, IsEven, iUpdates, iUpdatesNeeded, strClass, strAlarm, strSvrName
iUpdates = oUpdates.Count
strSvrName = LCase(oShell.ExpandEnvironmentStrings("%COMPUTERNAME%"))

iUpdatesNeeded = 0
For i = 0 to iUpdates - 1
                IsInstalled = oUpdates.Item(i).IsInstalled
                If (IsInstalled = False) Then
                                iUpdatesNeeded = iUpdatesNeeded + 1
                End If
Next

If (iUpdatesNeeded > AlarmRedLevel) Then
                strAlarm = AlarmRed & " " & Date & " " & LCase(Time) & " " & strSvrName & VbCrLf
Else
                If (iUpdatesNeeded > AlarmYellowLevel) Then
                                strAlarm = AlarmYellow & " " & Date & " " & LCase(Time) & " " & strSvrName & VbCrLf
                Else
                                strAlarm = AlarmGreen & " " & Date & " " & LCase(Time) & " " & strSvrName & VbCrLf
                End If
End If

WScript.Echo strAlarm & VbCrLf

strOut = "<style type=""text/css"">" & VbCrLf & _
                "table.updates { border-width: 3px; border-spacing: 0px; border-style: solid; border-color: black; border-collapse: separate; background-color: white; }" & VbCrLf & _
                "table.updates th { background-color: white; }" & VbCrLf & _
                "table.updates td.even { border-width: 1px; padding: 3px; border-style: solid; border-color: gray; background-color: #FCF6CF; }" & VbCrLf & _
                "table.updates td.odd { border-width: 1px; padding: 3px; border-style: solid; border-color: gray; background-color: #FEFEF2; }" & VbCrLf & _
                "</style>" & VbCrLf & _
                "<h2>" & UCase(strSvrName) & " Needs [" & CStr(iUpdatesNeeded) & "] Windows Updates</h2>" & VbCrLf & _
                "<table class='updates'>" & _
                "<th>Title</th>" & _
                "<th>Severity</th>" & _
                "<th>Description</th>" & _
                "<th>Size(bytes)</th>" & _
                "<th>Deadline</th>" & _
                "<th>URL</th>" & _
                "<th>KBs</th>" & _
                "</tr>" & VbCrLf
                IsEven = True
For i = 0 to iUpdates - 1
                IsInstalled = oUpdates.Item(i).IsInstalled
                If (IsInstalled = False) Then
                                strKBs = ""
                                strURL = oUpdates.Item(i).SupportURL
                                If (IsEven = True) Then
                                                strClass = "class='even'"
                                                IsEven = False
                                Else
                                                strClass = "class='odd'"
                                                IsEven = True
                                End If
                                strOut = strOut + "<tr><td " & strClass & ">" & oUpdates.Item(i).Title & "</td>" & _
                                                "<td " & strClass & ">" & oUpdates.Item(i).MsrcSeverity & "</td>" & _
                                                "<td " & strClass & ">" & oUpdates.Item(i).Description & "</td>" & _
                                                "<td " & strClass & ">" & oUpdates.Item(i).MaxDownloadSize & "</td>" & _
                                                "<td " & strClass & ">&nbsp;" & oUpdates.Item(i).Deadline & "</td>" & _
                                                "<td " & strClass & "><A href='" & strURL & "' target='_blank'>" & strURL & "</a></td>"
                                For Each strArticle in oUpdates.Item(i).KBArticleIDs
                                                If (Len(strKBs) > 0) Then
                                                                strKBs = strKBs & ", " & strArticle
                                                Else
                                                                strKBs = strArticle
                                                End If
                                Next 'each KB
                                strOut = strOut & "<td " & strClass & ">" & strKBs & "</td>"
                                strOut = strOut & "</tr>" & VbCrLf
                End If 'Installed?
Next 'each update
strOut = strOut & "</table>" & VbCrLf

WScript.Echo strOut

'Release our resources
Set oShell = Nothing
Set oUpdates = Nothing
Set oResults = Nothing
Set oSearcher = Nothing

From: Lennon, Padraig [mailto:Padraig.Lennon (at) pioneerinvestments.com]
Sent: Friday, June 26, 2009 3:52 AM
To: hobbit (at) hswn.dk
Subject: [hobbit] Windows update check monitor added to the Shire

I've added a quick and dirty monitor that might be of some use to someone here: http://xymonton.trantor.org/doku.php/monitors:winupd

At the moment its very basic in that it only checks for pending reboots required as a result of windows updates applied to a windows client. This has been useful here on site as sometimes updates are applied to production servers but downtime is not alllowed.. This monitor serves as a reminder to reboot to finish applying the updates

If you think you can enhance the script please do. My vb is poor..

Padraig Lennon

________________________________
CONFIDENTIALITY NOTICE: This email and any attachments are for the
exclusive and confidential use of the intended recipient. If you are not
the intended recipient, please do not read, distribute or take action in
reliance upon this message. If you have received this in error, please
notify us immediately by return email and promptly delete this message
and its attachments from your computer system. We do not waive
attorney-client or work product privilege by the transmission of this
message.