summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2012-12-06 02:51:54 +0100
committerAlexander Sulfrian <alexander@sulfrian.net>2012-12-06 02:51:54 +0100
commiteb285190a2d605502885c3d1a1dc9992955f7950 (patch)
tree41f6a2b430996e2af2cca156a4d4c112b564b60e
parentc8f9c918bb5cf5385447c54994fab6b9e196c08e (diff)
downloadbcfg2-tools-eb285190a2d605502885c3d1a1dc9992955f7950.tar.gz
bcfg2-tools-eb285190a2d605502885c3d1a1dc9992955f7950.tar.bz2
bcfg2-tools-eb285190a2d605502885c3d1a1dc9992955f7950.zip
check-hosts: add stats for indivdual host
-rwxr-xr-xcheck-hosts63
1 files changed, 48 insertions, 15 deletions
diff --git a/check-hosts b/check-hosts
index f49a786..ecd66ab 100755
--- a/check-hosts
+++ b/check-hosts
@@ -26,21 +26,54 @@ get_clean() {
get_names -c | sed 's/ *$//'
}
-get_nagios() {
- clean=$(get_clean | wc -l)
- bad=$(get_bad | wc -l)
- extra=$(get_extra | wc -l)
- stale=$(get_stale | wc -l)
-
- status="OK"
- exit=0
- if [ "$bad" != "0" -o "$stale" != "0" ]; then
- status="CRITICAL"
- exit=2
+get_count() {
+ count=$(/usr/sbin/bcfg2-reports "$@" | wc -l)
+
+ if [ "$count" = "0" ]; then
+ echo 0
+ else
+ echo $((count - 1))
fi
+}
- echo "$status | clean=$clean; bad=$bad; extra=$extra; stale=$stale;"
- exit $exit
+get_nagios() {
+ if [ -z "$1" ]; then
+ clean=$(get_clean | wc -l)
+ bad=$(get_bad | wc -l)
+ extra=$(get_extra | wc -l)
+ stale=$(get_stale | wc -l)
+
+ status="OK"
+ exit=0
+ if [ "$bad" != "0" -o "$stale" != "0" ]; then
+ status="CRITICAL"
+ exit=2
+ fi
+
+ echo "$status | clean=$clean; bad=$bad; extra=$extra; stale=$stale;"
+ exit $exit
+ else
+ host="${1/%spline.de/spline.inf.fu-berlin.de}"
+ if ! get_names -a | grep -q "^$host$"; then
+ echo "CRITICAL $host not known to bcfg2"
+ exit 2
+ fi
+
+ if get_names --stale | grep -q "^$host$"; then
+ echo "CRITICAL $host is stale"
+ exit 2
+ fi
+
+ bad=$(get_count -b "$host")
+ if [ "$bad" != "0" ]; then
+ echo "CRITICAL $bad bad entries"
+ exit 2
+ fi
+
+ extra=$(get_count -e "$host")
+ total=$(bcfg2-reports -t "$host" | sed "s/good: [0-9]*)/extra: $extra)/")
+ echo "OK $total"
+ fi
}
get_stale_once() {
@@ -94,7 +127,7 @@ mode should be one of the following:
EOU
}
-ARGS="$(getopt -o 'absecn' --long 'all,bad,stale,extra,cron,nagios' -- "$@")"
+ARGS="$(getopt -o 'absecn::' --long 'all,bad,stale,extra,cron,nagios::' -- "$@")"
if [ $? -ne 0 ]; then
show_usage
@@ -127,7 +160,7 @@ while true; do
exit 0
;;
-n|--nagios)
- get_nagios
+ get_nagios "$2"
exit 0
;;
*)