diff --git a/README.md b/README.md index cab0b5f..8859bc1 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,8 @@ object CheckCommand "puppetdb-node" { "--critical" = "$crit_lag$" "--warnfails" = "$warn_fails$" "--critfails" = "$crit_fails$" + "--warnnoops" = "$warn_noops$" + "--critnoops" = "$crit_noops$" } vars.node_name = "$host_name$" @@ -28,6 +30,8 @@ object CheckCommand "puppetdb-node" { vars.crit_lag = 120 vars.warn_fails = 1 vars.crit_fails = 1 + vars.warn_noops = 1 + vars.crit_noops = 999 } apply Service "puppet agent" { diff --git a/check_puppetdb_nodes b/check_puppetdb_nodes index f947d91..859a3cb 100755 --- a/check_puppetdb_nodes +++ b/check_puppetdb_nodes @@ -39,6 +39,7 @@ my $np = Monitoring::Plugin->new( usage => "Usage: %s [ -H|--hostname=] " . "[ -p|--port= ] [-s] [ -w|--warning= ] " . "[ -c|--critical= ] [ -W|--warnfails= ] " + . "[ --critnoops= ] [ --warnnoops= ] " . "[ -C|--critfails= ] [ -n|--node= ]" . "[ -a|--apiversion= ]", shortname => 'Check last node runs from PuppetDB', @@ -77,6 +78,20 @@ $np->add_arg( default => 1, ); +$np->add_arg( + spec => 'warnnoops', + help => "Exit with WARNING status if nodes had at least INTEGER " + . "noops in the last run (default: %s)", + default => 1, +); + +$np->add_arg( + spec => 'critnoops', + help => "Exit with CRITICAL status if nodes had at least INTEGER " + . "noops in the last run (default: %s)", + default => 999, +); + $np->add_arg( spec => 'hostname|H=s', help => 'Hostname of the PuppetDB (default: %s)', @@ -203,13 +218,29 @@ foreach my $node (@$data) { $failures = @$node_data[0]->{'failures'}; } + my $noops = 0; + if ( defined( @$node_data[0] ) + and defined( @$node_data[0]->{'noops'} ) ) + { + $noops = @$node_data[0]->{'noops'}; + } + if ( $failures >= $np->opts->critfails ) { $np->add_message( CRITICAL, - "$certname had $failures failures in the last run\n" ); + "$certname had $failures failures in the last run ($noops noops)\n" ); } elsif ( $failures >= $np->opts->warnfails ) { $np->add_message( WARNING, - "$certname had $failures failures in the last run\n" ); + "$certname had $failures failures in the last run ($noops noops)\n" ); + } + + if ( $noops >= $np->opts->critnoops ) { + $np->add_message( CRITICAL, + "$certname had $noops noops in the last run\n" ); + } + elsif ( $noops >= $np->opts->warnnoops ) { + $np->add_message( WARNING, + "$certname had $noops noops in the last run\n" ); } elsif ( exists $apiurls{$np->opts->apiversion}{'logs'} ) { my $apiurl = $apiurls{$np->opts->apiversion}{'logs'};