| 1 | ' =========================================================
|
|---|
| 2 | ' Script to check for updates onwwindows machines.
|
|---|
| 3 | ' Shamelessly stolen from Micha³ Jankowski (fooky@pjwstk.edu.pl) script.
|
|---|
| 4 | ' =========================================================
|
|---|
| 5 |
|
|---|
| 6 | ' Required Variables
|
|---|
| 7 | Const PROGNAME = "check_updates"
|
|---|
| 8 | Const VERSION = "0.0.1"
|
|---|
| 9 |
|
|---|
| 10 | ' Default settings for your script.
|
|---|
| 11 | threshold_warning = 50
|
|---|
| 12 | threshold_critical = 20
|
|---|
| 13 |
|
|---|
| 14 | ' Create the NagiosPlugin object
|
|---|
| 15 | Set np = New NagiosPlugin
|
|---|
| 16 |
|
|---|
| 17 | ' Define what args that should be used
|
|---|
| 18 | np.add_arg "warning", "warning threshold", 0
|
|---|
| 19 | np.add_arg "critical", "critical threshold", 0
|
|---|
| 20 |
|
|---|
| 21 | ' If we have no args or arglist contains /help or not all of the required arguments are fulfilled show the usage output,.
|
|---|
| 22 | If Args.Exists("help") Then
|
|---|
| 23 | np.Usage
|
|---|
| 24 | End If
|
|---|
| 25 |
|
|---|
| 26 | ' If we define /warning /critical on commandline it should override the script default.
|
|---|
| 27 | If Args.Exists("warning") Then threshold_warning = Args("warning")
|
|---|
| 28 | If Args.Exists("critical") Then threshold_critical = Args("critical")
|
|---|
| 29 | np.set_thresholds threshold_warning, threshold_critical
|
|---|
| 30 |
|
|---|
| 31 | Set objAutoUpdate = CreateObject("Microsoft.Update.AutoUpdate")
|
|---|
| 32 |
|
|---|
| 33 | intResultDetect = objAutoUpdate.DetectNow
|
|---|
| 34 | If intResultDetect <> 0 Then: np.nagios_exit "UNKNOWN: Unable to detect Automatic Updates.", UNKNOWN
|
|---|
| 35 |
|
|---|
| 36 | Set objSession = CreateObject("Microsoft.Update.Session")
|
|---|
| 37 | Set objSearcher = objSession.CreateUpdateSearcher
|
|---|
| 38 |
|
|---|
| 39 | intUncompleted = 0
|
|---|
| 40 | intUncompletedSoftware = 0
|
|---|
| 41 |
|
|---|
| 42 | Set objSysInfo = CreateObject("Microsoft.Update.SystemInfo")
|
|---|
| 43 | If objSysInfo.RebootRequired Then: np.nagios_exit "WARNING: Reboot required.", WARNING
|
|---|
| 44 |
|
|---|
| 45 | Set result = objSearcher.Search("IsInstalled = 0 and IsHidden = 0")
|
|---|
| 46 | Set colDownloads = result.Updates
|
|---|
| 47 |
|
|---|
| 48 | For i = 0 to colDownloads.Count - 1
|
|---|
| 49 | If colDownloads.Item(i).AutoSelectOnWebsites Then
|
|---|
| 50 | updatesNames = colDownloads.Item(i).Title & "+ " & updatesNames
|
|---|
| 51 | intUncompleted = intUncompleted + 1
|
|---|
| 52 | Else
|
|---|
| 53 | intUncompletedSoftware = intUncompletedSoftware + 1
|
|---|
| 54 | End If
|
|---|
| 55 | Next
|
|---|
| 56 |
|
|---|
| 57 | return_code = OK
|
|---|
| 58 |
|
|---|
| 59 | If intUncompleted > 0 Then
|
|---|
| 60 | return_code = np.check_threshold(intUncompleted)
|
|---|
| 61 | np.nagios_exit "Number of critical updates not installed: " & intUncompleted & " <br />Number of software updates not installed: " & intUncompletedSoftware & " <br /> Critical updates name: " & updatesNames, return_code
|
|---|
| 62 | Else
|
|---|
| 63 | np.nagios_exit "There is no critical updates <br />Number of software or driver updates not installed: " & intUncompletedSoftware, OK
|
|---|
| 64 | End If
|
|---|