From fdacb9a574e3aa6b17405c05131d833474e22fc3 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Sat, 29 Jun 2013 20:55:48 +0200 Subject: remove nagios output from check-hosts, add nagios passive check --- hosts-state | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100755 hosts-state (limited to 'hosts-state') 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); -- cgit v1.2.3-1-g7c22