From 7b0f37ebbdaa3c1264a8db124cede72b1df53840 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georg=20Sch=C3=B6nberger?= Date: Tue, 30 Sep 2014 15:21:39 +0200 Subject: [PATCH] Add method to check thresholds --- check_lsi_raid | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/check_lsi_raid b/check_lsi_raid index f3b2b7e..8165c9a 100755 --- a/check_lsi_raid +++ b/check_lsi_raid @@ -776,6 +776,48 @@ sub getThresholds { } } +# Generate an alert if x... +# -Tw 10 < 0 or > 10, (outside the range of {0 .. 10}) +# -Tw 10: < 10, (outside {10 .. inf}) +# -Tw ~:10 > 10, (outside the range of {-inf .. 10}) +# -Tw 10:20 < 10 or > 20, (outside the range of {10 .. 20}) +# -Tw @10:20 >= 10 and <= 20, (inside the range of {10 .. 20}) +sub checkThreshs{ + my $value = shift; + my $pattern = shift; + + if($pattern =~ /(^[0-9]+$)/){ + if($value < 0 || $value > $1){ + return 0; + } + } + elsif($pattern =~ /(^[0-9]+)\:$/){ + if($value < $1){ + return 0; + } + } + elsif($pattern =~ /^\~\:([0-9]+)$/){ + if($value > $1){ + return 0; + } + } + elsif($pattern =~ /^([0-9]+)\:([0-9]+)$/){ + if($value < $1 || $value > $2){ + return 0; + } + } + elsif($pattern =~ /^\@([0-9]+)\:([0-9]+)$/){ + if($value >= $1 and $value <= $2){ + return 0; + } + } + else{ + print "Invalid temperature parameter: \"$pattern\"!"; + exit(STATE_UNKNOWN); + } + return 1; +} + MAIN: { my ($storcli, $sudo, $noSudo, $version, $exitCode); # Create default sensor arrays and push them to status level