Skip to content
Snippets Groups Projects
Commit e038df46 authored by Sergey Joseph Ivanov's avatar Sergey Joseph Ivanov
Browse files

option to keep unknown/absent as unknown in addition to OK and Critical

parent 5a70963e
No related branches found
No related tags found
No related merge requests found
...@@ -90,6 +90,14 @@ the check information can be fetched, but the metric itself isn't listed in ...@@ -90,6 +90,14 @@ the check information can be fetched, but the metric itself isn't listed in
the XML output. If the check information cannot be fetched, then it is still a the XML output. If the check information cannot be fetched, then it is still a
critical error. critical error.
=item -k
Specify that an absence should be treated as an UNKNOWN value. By default, if a
metric is absent, it is treated as CRITICAL. A metric is considered absent if
the check information can be fetched, but the metric itself isn't listed in
the XML output. If the check information cannot be fetched, then it is still a
critical error.
=back =back
=head1 THRESHOLDS =head1 THRESHOLDS
...@@ -188,8 +196,8 @@ use utils qw($TIMEOUT %ERRORS &print_revision &support); ...@@ -188,8 +196,8 @@ use utils qw($TIMEOUT %ERRORS &print_revision &support);
delete @ENV{'PATH', 'IFS', 'CDPATH', 'ENV', 'BASH_ENV'}; delete @ENV{'PATH', 'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
my ($port, $host, $module, $check, $age, $warning, $critical, $equals, $regex, my ($port, $host, $module, $check, $age, $warning, $critical, $equals, $regex,
$metric, $url, $allow_absent) = (81, undef, undef, undef, 0, undef, undef, $metric, $url, $allow_absent, $keep_unknown) = (81, undef, undef, undef, 0, undef, undef,
undef, undef, 0); undef, undef, 0, 0);
sub help { sub help {
print "Usage: $0 [options]\n"; print "Usage: $0 [options]\n";
...@@ -205,6 +213,7 @@ sub help { ...@@ -205,6 +213,7 @@ sub help {
print " -e | --equals metric must equal this value (numerical metrics only)\n"; print " -e | --equals metric must equal this value (numerical metrics only)\n";
print " -r | --regex regex match against the metric (string print metrics only)\n"; print " -r | --regex regex match against the metric (string print metrics only)\n";
print " -u | --url specify an alternate URL to fetch\n"; print " -u | --url specify an alternate URL to fetch\n";
print " -k | --keepunkown Treat absences as UNKNOWN (default: critical)\n";
print " -a | --allowabsent Treat absences as OK (default: critical)\n"; print " -a | --allowabsent Treat absences as OK (default: critical)\n";
exit $ERRORS{'UNKNOWN'}; exit $ERRORS{'UNKNOWN'};
} }
...@@ -294,6 +303,7 @@ GetOptions ( ...@@ -294,6 +303,7 @@ GetOptions (
"e|equals=i" => \$equals, "e|equals=i" => \$equals,
"r|regex=s" => \$regex, "r|regex=s" => \$regex,
"u|url=s" => \$url, "u|url=s" => \$url,
"k|keepunknown" => \$keep_unknown,
"a|allowabsent" => \$allow_absent); "a|allowabsent" => \$allow_absent);
unless (defined $host && defined $module && defined $check) { unless (defined $host && defined $module && defined $check) {
...@@ -322,10 +332,10 @@ eval { ...@@ -322,10 +332,10 @@ eval {
my $res = $ua->request($t); my $res = $ua->request($t);
my $now_after = Time::HiRes::time(); my $now_after = Time::HiRes::time();
die "could not fetch http://$host:$port$url - " . $res->status_line ."\n" die "could not fetch http://$host:$port$url - " . $res->status_line ."\n"
unless($res && $res->is_success); unless($res && ( $res->is_success || $keep_unknown || $allow_absent) ) ;
# Parse the xml # Parse the xml
eval { $ref = $xs->XMLin($res->content, ForceArray => 1); }; eval { $ref = $xs->XMLin($res->content, ForceArray => 1); };
die "error parsing XML\n" if($@); die "error parsing XML\n" unless (!($@) || $keep_unknown || $allow_absent);
# Debugging # Debugging
# use Data::Dumper; # use Data::Dumper;
...@@ -361,6 +371,8 @@ eval { ...@@ -361,6 +371,8 @@ eval {
if (!defined($metricval)) { if (!defined($metricval)) {
if ($allow_absent) { if ($allow_absent) {
$state = "OK"; $state = "OK";
} elsif ($keep_unknown) {
$state = "UNKNOWN";
} else { } else {
$state = "CRITICAL"; $state = "CRITICAL";
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment