-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_apt_motd.sh
41 lines (41 loc) · 1.21 KB
/
check_apt_motd.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
#!/bin/sh
#
# check_apt_packages - nagios plugin
#
# Checks for any packages to be applied
# Built for Ubuntu 10 (LTS), see following URL for further info
# - http://www.sandfordit.com/vwiki/index.php/Nagios#Ubuntu_Software_Updates_Monitor
#
# By Simon Strutt
# Version 1 - Jan 2012
# Include standard Nagios library
. /usr/lib/nagios/plugins/utils.sh || exit 3
if [ ! -f /usr/lib/update-notifier/apt-check ]; then
exit $STATE_UNKNOWN
fi
APTRES=$(/usr/lib/update-notifier/apt-check 2>&1)
PKGS=$(echo $APTRES | cut -f1 -d';')
SEC=$(echo $APTRES | cut -f2 -d';')
if [ -f /var/run/reboot-required ]; then
REBOOT=1
TOAPPLY=`cat /var/run/reboot-required.pkgs`
else
REBOOT=0
fi
if [ "${PKGS}" -eq 0 ]; then
if [ "${REBOOT}" -eq 1 ]; then
RET=$STATE_WARNING
RESULT="Reboot required to apply ${TOAPPLY}"
else
RET=$STATE_OK
RESULT="No packages to be updated"
fi
elif [ "${SEC}" -eq 0 ]; then
RET=$STATE_WARNING
RESULT="${PKGS} packages to update (no security updates)"
else
RET=$STATE_CRITICAL
RESULT="${PKGS} packages (including ${SEC} security) packages to update"
fi
echo $RESULT
exit $RET