Skip to content
Snippets Groups Projects
Commit 3c9108e9 authored by Bryan Horstmann-Allen's avatar Bryan Horstmann-Allen
Browse files

add -e for numeric checks against resmon with Nagios

parent adcca66a
No related branches found
No related tags found
No related merge requests found
......@@ -178,7 +178,7 @@ use utils qw($TIMEOUT %ERRORS &print_revision &support);
delete @ENV{'PATH', 'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
my ($port, $host, $module, $check, $age, $warning, $critical, $regex,
my ($port, $host, $module, $check, $age, $warning, $critical, $equals, $regex,
$metric, $url) = (81,"","","",0, "", "", "", "");
sub help {
......@@ -192,8 +192,8 @@ sub help {
print " -m | --metric metric name to check\n";
print " -w | --warning warning threshold (numeric metrics only)\n";
print " -c | --critical critical threshold (numeric metrics only)\n";
print " -r | --regex regex match against the metric (string";
print " 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 " -u | --url specify an alternate URL to fetch\n";
exit $ERRORS{'UNKNOWN'};
}
......@@ -279,6 +279,7 @@ GetOptions (
"m|metric=s" => \$metric,
"w|warning=s" => \$warning,
"c|critical=s" => \$critical,
"e|equals=i" => \$equals,
"r|regex=s" => \$regex,
"u|url=s" => \$url);
......@@ -286,11 +287,16 @@ unless ($host && $module && $check) {
short_help();
}
if (($warning || $critical) && $regex) {
if (($warning || $critical || $equals ) && $regex) {
print "Cannot specify both numeric thresholds and a string based match\n";
exit $ERRORS{'UNKNOWN'};
}
if (($warning || $critical ) && $equals) {
print "Cannot specify thresholds and equals\n";
exit $ERRORS{'UNKNOWN'};
}
my $ua = LWP::UserAgent->new;
$url = "/$module/$check" unless $url;
my $t = HTTP::Request->new('GET', "http://$host:$port$url");
......@@ -325,6 +331,16 @@ eval {
die "Numeric threshold specified for a non-numeric metric"
if (($warning || $critical) && $type !~ /[0IlLni]/);
if ($equals) {
if ($value eq $equals) {
$state = "OK";
} else {
$state = "CRITICAL";
}
print "$state: $value\n";
}
if ($regex) {
if ($value =~ /$regex/) {
$state = "OK";
......
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