summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorintrigeri <intrigeri@boum.org>2014-12-03 15:11:34 +0000
committerintrigeri <intrigeri@boum.org>2014-12-03 15:11:34 +0000
commit0d0f29550aa0d099b0b35d0d0fdfd94af2ff82b8 (patch)
tree27c3825dc985975d8b38d80e13f12dc0df6d6ef5
parent4810d7ea6b199d97939cc0a85091403e08407557 (diff)
Upgrade lastruncheck to the latest upstream version (Closes: #8379).
For a while, we've been copying that file from https://github.com/cafuego/check_puppetmaster.git. Before this commit, we had the version from upstream commit c121464. Since then, upstream has improved a few things, in particular they now call puppet in a way that works with 3.x too. Detailed --no-merges log: 89a3971c Add optional perfdata to output. 4d352938 - Use "-m1" argument to `grep` to only get the first match. - Check if yaml report exists before running grep against it. If the certificates and reports get out of sync (say, you deleted some reports) you'll get some "No such file or directory" 09c4c1a7 Use non-deprecated cert syntax (3.x) and make binary path and command configurable.
-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