-
Notifications
You must be signed in to change notification settings - Fork 7
/
check_puppet_pe_version.sh
executable file
·80 lines (66 loc) · 1.66 KB
/
check_puppet_pe_version.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
75
76
77
78
79
#!/bin/bash -e
#
# Checks for the availability of a new puppet PE version.
#
# Tested against puppet 4, and runs via Nagios/NRPE, so assumes the current host is the puppetmaster
#
# Nagios states
OK=0
WARNING=1
CRITICAL=2
UNKNOWN=3
# Defaults
ALERT=$WARNING
STATUS="WARNING"
usage() {
cat <<-EOF
Script to check for a new Puppet PE version. Assumes that the host on which this script is run is the puppetmaster.
Designed to run as an NRPE check, from nagios. Type of alert is configurable. If both flags are set, the last
listed will take precedence.
usage: ${0} [-h] [-w num] [-c num] [-W num] [-C num]
-h Usage.
-w Send warning alert if new version available. Default.
-c Send critical alert if new version available.
Returns standard Nagios return codes:
- 0 for success
- 1 for warning
- 2 for critical
- 3 for unknown
EOF
}
while getopts "hwc" opt; do
case $opt in
h)
usage
exit 3
;;
w)
ALERT=$WARNING
STATUS="WARNING"
;;
c)
ALERT=$CRITICAL
STATUS="CRITICAL"
;;
\?)
echo "Invalid option: -$OPTARG" >&2
usage
exit 3
;;
esac
done
# This script returns no output if no version updates are available, or
# text as follows when there is a version update:
# Version 2016.2.0 is now available! (currently 2016.1.2).
# http://links.puppet.com/enterpriseupgrade
#
VERSION_DATA=$(/opt/puppetlabs/bin/puppet-enterprise-version-check)
if [[ -z $VERSION_DATA ]] ; then
EXIT=$OK
MESSAGE="OK: Puppet PE version is up to date."
else
EXIT=$ALERT
MESSAGE="$STATUS: ${VERSION_DATA}"
fi
echo $MESSAGE
exit $EXIT