From 16498c974e3666003c6bb0dbf01669acd01f2412 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Sat, 29 Jun 2013 22:20:49 +0200 Subject: hosts-state: add summary --- hosts-state | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'hosts-state') diff --git a/hosts-state b/hosts-state index 8327fbd..e410654 100755 --- a/hosts-state +++ b/hosts-state @@ -12,6 +12,13 @@ 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 ); +my $summary = { + stale => 0, + bad => 0, + clean => 0, + msg => 'OK', + status => 0 +}; open(my $reports, '-|', '/usr/sbin/bcfg2-reports', '-a', '--fields=state,time,total,good,bad,extra,modified'); @@ -34,15 +41,18 @@ while(<$reports>) { if ($dt < $stale) { $msg = "CRITICAL $host is stale"; $status = 2; + $summary->{stale}++; } else { if ($bad > 0) { $msg = "CRITICAL $bad bad entries"; $status = 2; + $summary->{bad}++; } else { $msg = "OK Total managed entries: $total (extra: $extra)"; $status = 0; + $summary->{clean}++; } } @@ -50,4 +60,11 @@ while(<$reports>) { print("$short_host\tBcfg2\t$status\t$msg | $perf\n\x17"); } +if ($summary->{bad} > 0 or $summary->stale > 0) { + $summary->{msg} = 'CRITICAL'; + $summary->{status} = 2; +} + +print("vm-bcfg2\tBcfg2 Status\t$summary->{status}\t$summary->{msg} | clean=$summary->{clean};;;0 bad=$summary->{bad};;;0 stale=$summary->{stale};;;0\n\x17"); + close($reports); -- cgit v1.2.3-1-g7c22