summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMicah Anderson <micah@riseup.net>2015-03-27 11:42:23 -0400
committerMicah Anderson <micah@riseup.net>2015-03-27 11:42:23 -0400
commit0c15a1f6da02cd0101eacc70a4abbed2dfbbcbe0 (patch)
treea06c1981f154a7b5160c1222762c1e94e0fb95be
parent70d2dd696696b14c5011580f994c6520b028f32a (diff)
parent0d0f29550aa0d099b0b35d0d0fdfd94af2ff82b8 (diff)
Merge remote-tracking branch 'tails/bugfix/8379-lastruncheck-compatibility-with-puppet-3.x'
-rw-r--r--files/master/lastruncheck54
1 files changed, 33 insertions, 21 deletions
diff --git a/files/master/lastruncheck b/files/master/lastruncheck
index 72c0eb5..eeeeafb 100644
--- a/files/master/lastruncheck
+++ b/files/master/lastruncheck
@@ -13,7 +13,10 @@ STATUS_CRITICAL=2
STATUS_UNKNOWN=3
INTERVAL_WARNING=$((60 * 60 * 2))
INTERVAL_CRITICAL=$((60 * 60 * 24))
+PUPPET="/usr/bin/puppet"
+COMMAND="cert"
PARAMS="-la"
+PERFDATA=no
# A space separated list of hostnames to ignore. These might for instance be
# laptops that just don't get used every day and thus don't sync.
@@ -39,6 +42,7 @@ w_count=0
w_string=""
e_count=0
e_string=""
+p_string=""
# Current time.
NOW=$(date +"%s")
@@ -48,29 +52,31 @@ NOW=$(date +"%s")
# Get all hostnames associated with active certificates, and check the time
# each of these last checked in with the server. Do this by converting the
# yaml file expiration datestamp to epoch format and subtracting it from now.
-for node in $(/usr/sbin/puppetca ${PARAMS} | awk '/^\+/ {print $2}' | tr -d '"'); do
+for node in $(${PUPPET} ${COMMAND} ${PARAMS} | awk '/^\+/ {print $2}' | tr -d '"'); do
- EXPIRATION=$(grep expiration ${YAMLPATH}/$node.yaml | awk '{printf("%s %s", $2, $3);}')
- typeset -i CHECKIN=$(date +"%s" -d "${EXPIRATION}")
- DIFFERENCE=$((${NOW} - ${CHECKIN}))
+ if [ -e "${YAMLPATH}/$node.yaml" ]; then
+ EXPIRATION=$(grep -m1 expiration ${YAMLPATH}/$node.yaml | awk '{printf("%s %s", $2, $3);}')
+ typeset -i CHECKIN=$(date +"%s" -d "${EXPIRATION}")
+ DIFFERENCE=$((${NOW} - ${CHECKIN}))
- # Count hosts and generate some output strings based on the status.
- if [ ${DIFFERENCE} -lt ${INTERVAL_WARNING} ]; then
- o_count=$((${o_count} + 1));
- else
- # If there is an issue, first check if we can ignore this host.
- if [ -n "${IGNORE_HOSTS}" ]; then
- if [[ ${IGNORE_HOSTS} =~ ${node} ]]; then
- i_count=$((${i_count} + 1))
- continue
- fi
- fi
- if [ ${DIFFERENCE} -gt ${INTERVAL_CRITICAL} ]; then
- e_count=$((${e_count} + 1))
- e_string="${e_string} ${node}"
+ # Count hosts and generate some output strings based on the status.
+ if [ ${DIFFERENCE} -lt ${INTERVAL_WARNING} ]; then
+ o_count=$((${o_count} + 1));
else
- w_count=$((${w_count} + 1))
- w_string="${w_string} ${node}"
+ # If there is an issue, first check if we can ignore this host.
+ if [ -n "${IGNORE_HOSTS}" ]; then
+ if [[ ${IGNORE_HOSTS} =~ ${node} ]]; then
+ i_count=$((${i_count} + 1))
+ continue
+ fi
+ fi
+ if [ ${DIFFERENCE} -gt ${INTERVAL_CRITICAL} ]; then
+ e_count=$((${e_count} + 1))
+ e_string="${e_string} ${node}"
+ else
+ w_count=$((${w_count} + 1))
+ w_string="${w_string} ${node}"
+ fi
fi
fi
done
@@ -96,6 +102,12 @@ elif [ ${w_count} -gt 0 ]; then
ret=${STATUS_WARNING}
fi
+# Optionally add perfdata to output.
+if [ "${PERFDATA}" = "yes" ]; then
+ p_string=" | ok=${o_count}, err=${e_count}, warn=${w_count}, ign=${i_count}"
+fi
+
+
# Output the status and inform the user about which hosts are lagging.
-echo -n "${status}:${s_string}"
+echo -n "${status}:${s_string}${p_string}"
exit $ret