summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2013-06-29 22:20:49 +0200
committerAlexander Sulfrian <alexander@sulfrian.net>2013-06-29 22:20:49 +0200
commit16498c974e3666003c6bb0dbf01669acd01f2412 (patch)
treeb69b4a0d566c3e3307ee09d7041d7bb360dc3698
parent58cd1ce541d464fce8b01222caa3af009c49c366 (diff)
downloadbcfg2-tools-16498c974e3666003c6bb0dbf01669acd01f2412.tar.gz
bcfg2-tools-16498c974e3666003c6bb0dbf01669acd01f2412.tar.bz2
bcfg2-tools-16498c974e3666003c6bb0dbf01669acd01f2412.zip
hosts-state: add summary
-rwxr-xr-xhosts-state17
1 files changed, 17 insertions, 0 deletions
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);