forked from jedda/OSX-Monitoring-Tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_osx_swupdate.sh
executable file
·74 lines (58 loc) · 3.26 KB
/
check_osx_swupdate.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash
# Check OS X Software Update Server
# by Jedda Wignall
# http://jedda.me
# v1.0 - 03 Dec 2012
# Initial release.
# Script that uses serveradmin to check that the OS X Software Update service is listed as running.
# If all is OK, it returns performance data for the number of mirrored and enabled packages, as well as the size of the update store.
# Can also ensure that updates are auto syncing with Apple, and that the latest check was OK.
# Optional Flags:
# -a Tells the script to ensure that automatic mirroring of updates is on, and that the last check succeeded. If your setup is manual, don't use this.
# Example:
# ./check_osx_swupdate.sh -a
# Performance Data - this script returns the followng Nagios performance data:
# mirroredPkgs - Number of packages mirrored by your Software Update Server.
# enabledPkgs - Number of packages currently enabled by your Software Update Server.
# sizeOfUpdates - Size of your specified updates directory in Kilobytes.
# Compatibility - this script has been tested on and functions on the following stock OSes:
# 10.6 Server
# 10.7 Server
# 10.8 Server
if [[ $EUID -ne 0 ]]; then
printf "ERROR - This script must be run as root.\n"
exit 1
fi
# check that the swupdate service is running
swupdateStatus=`serveradmin fullstatus swupdate | grep 'swupdate:state' | sed -E 's/swupdate:state.+"(.+)"/\1/'`
if [ "$swupdateStatus" != "RUNNING" ]; then
printf "CRITICAL - Software Update service is not running!\n"
exit 2
fi
# grab our performance data
numOfMirroredPkg=`serveradmin fullstatus swupdate | grep 'swupdate:numOfMirroredPkg ' | grep -E -o "[0-9]+$"`
numOfEnabledPkg=`serveradmin fullstatus swupdate | grep 'swupdate:numOfEnabledPkg ' | grep -E -o "[0-9]+$"`
updatesDocRoot=`serveradmin fullstatus swupdate | grep 'swupdate:updatesDocRoot' | sed -E 's/swupdate:updatesDocRoot.+"(.+)"/\1/'`
sizeOfUpdatesDocRoot=`du -sk "$updatesDocRoot" | grep -E -o "[0-9]+"`
# see if we need to check auto mirror status
if [ "$1" == "-a" ]; then
autoMirrorToggle=`serveradmin fullstatus swupdate | grep 'swupdate:autoMirror ' | grep -E -o "[a-z]+$"`
if [ "$autoMirrorToggle" != "yes" ]; then
printf "WARNING - Auto mirroring of packages is off! | mirroredPkgs=$numOfMirroredPkg; enabledPkgs=$numOfEnabledPkg; sizeOfUpdates=$sizeOfUpdatesDocRoot;\n"
exit 1
fi
autoMirrorCheckError=`serveradmin fullstatus swupdate | grep 'swupdate:checkError ' | grep -E -o "[a-z]+$"`
if [ "$autoMirrorCheckError" != "no" ]; then
printf "WARNING - Auto mirroring of packages encountered an error on last check! | mirroredPkgs=$numOfMirroredPkg; enabledPkgs=$numOfEnabledPkg; sizeOfUpdates=$sizeOfUpdatesDocRoot;\n"
exit 1
fi
fi
# lastly, make sure that we can connect to the service port
swupdateServicePort=`serveradmin settings swupdate | grep 'swupdate:portToUse' | grep -E -o "[0-9]+$"`
curl -silent localhost:$swupdateServicePort > /dev/null
if [ $? == 7 ]; then
printf "CRITICAL - Could not connect to the Software Update service port ($swupdateServicePort). | mirroredPkgs=$numOfMirroredPkg; enabledPkgs=$numOfEnabledPkg; sizeOfUpdates=$sizeOfUpdatesDocRoot;\n"
exit 2
fi
printf "OK - Software Update service appears to be running OK. | mirroredPkgs=$numOfMirroredPkg; enabledPkgs=$numOfEnabledPkg; sizeOfUpdates=$sizeOfUpdatesDocRoot;\n"
exit 0