summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2013-06-29 20:55:48 +0200
committerAlexander Sulfrian <alexander@sulfrian.net>2013-06-29 20:55:48 +0200
commitfdacb9a574e3aa6b17405c05131d833474e22fc3 (patch)
treecc2346cc1d69a13200724f12ea02f839b1749494
parent20c769227dcc7ce218bab62fe9c5a2403cb0361d (diff)
downloadbcfg2-tools-fdacb9a574e3aa6b17405c05131d833474e22fc3.tar.gz
bcfg2-tools-fdacb9a574e3aa6b17405c05131d833474e22fc3.tar.bz2
bcfg2-tools-fdacb9a574e3aa6b17405c05131d833474e22fc3.zip
remove nagios output from check-hosts, add nagios passive check
-rwxr-xr-xcheck-hosts45
-rwxr-xr-xhosts-state53
2 files changed, 54 insertions, 44 deletions
diff --git a/check-hosts b/check-hosts
index 8cbb28f..ac64741 100755
--- a/check-hosts
+++ b/check-hosts
@@ -32,44 +32,6 @@ get_count() {
fi
}
-get_nagios() {
- if [ -z "$1" ]; then
- clean=$(get_clean | wc -l)
- bad=$(get_bad | 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; stale=$stale;"
- exit $exit
- else
- if ! get_names -a | grep -q "^$1$"; then
- echo "CRITICAL $1 not known to bcfg2"
- exit 2
- fi
-
- if get_names --stale | grep -q "^$1$"; then
- echo "CRITICAL $1 is stale"
- exit 2
- fi
-
- bad=$(get_count -b "$1")
- if [ "$bad" != "0" ]; then
- echo "CRITICAL $bad bad entries"
- exit 2
- fi
-
- extra=$(get_count -e "$1")
- total=$(bcfg2-reports -t "$1" | sed "s/good: [0-9]*)/extra: $extra)/")
- echo "OK $total"
- fi
-}
-
get_stale_once() {
get_stale | while read host; do
STALE_FILE="${STALE_DIR}/${host}"
@@ -117,11 +79,10 @@ mode should be one of the following:
-e|--extra display hosts with extra entries
-c|--cron run in cron mode (report new stale hosts)
- -n|--nagios run in nagios mode (report count hosts in groups)
EOU
}
-ARGS="$(getopt -o 'absecn::' --long 'all,bad,stale,extra,cron,nagios::' -- "$@")"
+ARGS="$(getopt -o 'absec::' --long 'all,bad,stale,extra,cron::' -- "$@")"
if [ $? -ne 0 ]; then
show_usage
@@ -153,10 +114,6 @@ while true; do
cron
exit 0
;;
- -n|--nagios)
- get_nagios "$2"
- exit 0
- ;;
*)
show_usage
exit 1
diff --git a/hosts-state b/hosts-state
new file mode 100755
index 0000000..42fb938
--- /dev/null
+++ b/hosts-state
@@ -0,0 +1,53 @@
+#!/usr/bin/perl -w
+# The output of this script is formated to be usable as input for
+# send_nsca (nsca-ng) and submit status data for all hosts known
+# by bcfg2.
+
+use strict;
+use DateTime;
+use DateTime::Format::Strptime;
+
+# some date initialization
+my $parser = DateTime::Format::Strptime->new(pattern => '%Y-%m-%d %H:%M:%S');
+my $stale = DateTime->now(time_zone => 'local')->set_time_zone('floating');
+$stale->subtract( hours => 24 );
+
+
+open(my $reports, '-|', 'bcfg2-reports', '-a', '--fields=state,time,total,good,bad,extra,modified');
+
+my $header = 1;
+while(<$reports>) {
+ if ($header) {
+ $header = 0;
+ next;
+ }
+
+ my ($host, $state, $date, $time, $total, $good, $bad, $extra, $modified) = split(/\s+/, $_);
+ my $short_host = $host;
+ $short_host =~ s/\.spline\.inf\.fu-berlin\.de$//;
+
+ my $msg = '';
+ my $perf = "total=$total;;;0 good=$good;;;0 bad=$bad;;;0 extra=$extra;;;0 modified=$modified;;;0";
+ my $status = 3; # UNKNOWN
+
+ my $dt = $parser->parse_datetime("$date $time");
+ if ($dt < $stale) {
+ $msg = "CRITICAL $host is stale";
+ $status = 2;
+ }
+ else {
+ if ($bad > 0) {
+ $msg = "CRITICAL $bad bad entries";
+ $status = 2;
+ }
+ else {
+ $msg = "OK Total managed entries: $total (extra: $extra)";
+ $status = 0;
+ }
+ }
+
+ #host[tab]service[tab]status[tab]message[newline]
+ print("$short_host\tBcfg2\t$status\t$msg | $perf\n\x17");
+}
+
+close($reports);