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

check_resmon_metric to match changes to check system time

parent fff40704
No related branches found
No related tags found
No related merge requests found
...@@ -182,6 +182,7 @@ use Time::HiRes qw( gettimeofday tv_interval ); ...@@ -182,6 +182,7 @@ use Time::HiRes qw( gettimeofday tv_interval );
use XML::Simple; use XML::Simple;
use Getopt::Long; use Getopt::Long;
use lib "/usr/lib64/nagios/plugins";
use utils qw($TIMEOUT %ERRORS &print_revision &support); use utils qw($TIMEOUT %ERRORS &print_revision &support);
delete @ENV{'PATH', 'IFS', 'CDPATH', 'ENV', 'BASH_ENV'}; delete @ENV{'PATH', 'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
...@@ -326,8 +327,8 @@ eval { ...@@ -326,8 +327,8 @@ eval {
die "error parsing XML\n" if($@); die "error parsing XML\n" if($@);
# Debugging # Debugging
#use Data::Dumper; # use Data::Dumper;
#print Dumper($ref->{ResmonResult}); # print Dumper($ref->{ResmonResult});
my $idx; my $idx;
for ($idx=0; $idx < $#{$ref->{ResmonResult}}; $idx++) { for ($idx=0; $idx < $#{$ref->{ResmonResult}}; $idx++) {
...@@ -336,9 +337,21 @@ eval { ...@@ -336,9 +337,21 @@ eval {
} }
# If we have stale information, then go critical # If we have stale information, then go critical
my $last_update = time() - $ref->{ResmonResult}->[$idx]->{last_update}->[0]; if($age) {
die "Stale metrics. Last updated $last_update seconds ago" my $last_update;
if($age && $age < $last_update); if ($module eq 'System::Time' && $check eq 'now') {
$last_update = Time::HiRes::time() - $ref->{ResmonResult}->[$idx]->{metric}->{now}->{content};
} else {
$last_update = Time::HiRes::time() - $ref->{ResmonResult}->[$idx]->{last_update}->[0];
}
if ($age < abs($last_update)){
$state = "CRITICAL";
} else {
$state = "OK";
}
print "$state: updated in $last_update secs from now | diff=$last_update";
exit $ERRORS{$state};
}
# Get the metrics # Get the metrics
my $metricval = $ref->{ResmonResult}->[$idx]->{metric}->{$metric}; my $metricval = $ref->{ResmonResult}->[$idx]->{metric}->{$metric};
...@@ -350,7 +363,7 @@ eval { ...@@ -350,7 +363,7 @@ eval {
} else { } else {
$state = "CRITICAL"; $state = "CRITICAL";
} }
print "$state: Metric $metric is absent\n"; print "$state: Metric $metric is absent for module $module in check $check fetched by url $url\n";
exit $ERRORS{$state}; exit $ERRORS{$state};
} }
...@@ -363,6 +376,15 @@ eval { ...@@ -363,6 +376,15 @@ eval {
die "Numeric threshold specified for a non-numeric metric" die "Numeric threshold specified for a non-numeric metric"
if ((defined $warning || defined $critical) && $type !~ /[0IlLni]/); if ((defined $warning || defined $critical) && $type !~ /[0IlLni]/);
my $metrics=$ref->{ResmonResult}->[$idx]->{metric};
my $performance='';
foreach my $key ( sort keys %$metrics ) {
my $mtype= $metrics->{$key}{type} || "0";
if ($mtype ~~ /[0IlLni]/) {
$performance .= $key."=".$metrics->{$key}{content}.";";
}
}
if (defined $equals) { if (defined $equals) {
if ($value eq $equals) { if ($value eq $equals) {
...@@ -388,7 +410,7 @@ eval { ...@@ -388,7 +410,7 @@ eval {
if (defined $warning || defined $critical) { if (defined $warning || defined $critical) {
my $message; my $message;
($state, $message) = check_threshold($value, $warning, $critical); ($state, $message) = check_threshold($value, $warning, $critical);
print "$state: $metric - $message\n"; print "$state: $metric - $message | ${performance} \[$value\]\n";
} }
}; };
......
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