diff options
Diffstat (limited to 'web/attachments/112620-check_range.patch')
| -rw-r--r-- | web/attachments/112620-check_range.patch | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/web/attachments/112620-check_range.patch b/web/attachments/112620-check_range.patch new file mode 100644 index 0000000..2ddd8a3 --- /dev/null +++ b/web/attachments/112620-check_range.patch | |||
| @@ -0,0 +1,116 @@ | |||
| 1 | ? plugins-scripts/t/utils.pm.t | ||
| 2 | Index: test.pl.in | ||
| 3 | =================================================================== | ||
| 4 | RCS file: /cvsroot/nagiosplug/nagiosplug/test.pl.in,v | ||
| 5 | retrieving revision 1.2 | ||
| 6 | diff -u -w -u -r1.2 test.pl.in | ||
| 7 | --- test.pl.in 25 Nov 2004 05:06:24 -0000 1.2 | ||
| 8 | +++ test.pl.in 15 Dec 2004 23:59:46 -0000 | ||
| 9 | @@ -69,7 +69,7 @@ | ||
| 10 | $tstdir = './t' unless ($tstdir); | ||
| 11 | opendir(DIR, $tstdir) || die "can't opendir $tstdir: $!"; | ||
| 12 | while ($file = readdir(DIR)) { | ||
| 13 | - push @dots, "$tstdir/$file" if ($file =~ m/^[^\.]+\.t$/); | ||
| 14 | + push @dots, "$tstdir/$file" if ($file =~ m/^[^\.]+.*\.t$/); | ||
| 15 | } | ||
| 16 | closedir DIR; | ||
| 17 | } | ||
| 18 | Index: plugins-scripts/utils.pm.in | ||
| 19 | =================================================================== | ||
| 20 | RCS file: /cvsroot/nagiosplug/nagiosplug/plugins-scripts/utils.pm.in,v | ||
| 21 | retrieving revision 1.7 | ||
| 22 | diff -u -w -u -r1.7 utils.pm.in | ||
| 23 | --- plugins-scripts/utils.pm.in 13 Apr 2003 04:25:36 -0000 1.7 | ||
| 24 | +++ plugins-scripts/utils.pm.in 15 Dec 2004 23:59:46 -0000 | ||
| 25 | @@ -25,13 +25,14 @@ | ||
| 26 | |||
| 27 | require Exporter; | ||
| 28 | @ISA = qw(Exporter); | ||
| 29 | -@EXPORT_OK = qw($TIMEOUT %ERRORS &print_revision &support &usage); | ||
| 30 | +@EXPORT_OK = qw($TIMEOUT %ERRORS &print_revision &support &usage &check_range); | ||
| 31 | |||
| 32 | #use strict; | ||
| 33 | #use vars($TIMEOUT %ERRORS); | ||
| 34 | sub print_revision ($$); | ||
| 35 | sub usage; | ||
| 36 | sub support(); | ||
| 37 | +sub check_range($$); | ||
| 38 | sub is_hostname; | ||
| 39 | |||
| 40 | ## updated by autoconf | ||
| 41 | @@ -80,4 +81,75 @@ | ||
| 42 | } | ||
| 43 | } | ||
| 44 | |||
| 45 | +sub check_range ($$) | ||
| 46 | +{ | ||
| 47 | + # Takes two parameters. The first is a metric. The second is | ||
| 48 | + # a range using Nagios plugin range syntax. | ||
| 49 | + # No explicit checking is done that the metric or the range consists | ||
| 50 | + # of non-numeric values - they will be treated as zero. | ||
| 51 | + | ||
| 52 | + # Accepts ranges of the following form: | ||
| 53 | + # | ||
| 54 | + # min:max (between min and max inclusive) | ||
| 55 | + # min: (equivalent to min:infinity) | ||
| 56 | + # :max (equivalent to 0:max) | ||
| 57 | + # max (equivalent :max which is equivalent to 0:max) | ||
| 58 | + # 0 (equivalent to 0:infinity) | ||
| 59 | + # | ||
| 60 | + # The symbol ~ may be specified as the minimum portion of a range | ||
| 61 | + # to represent -infinity. The range may be prefixed by @ to negate | ||
| 62 | + # the result (so the metric is critical if within the range). | ||
| 63 | + # Note that ~:~ is treated as an invalid range | ||
| 64 | + | ||
| 65 | + my($metric) = shift(@_); | ||
| 66 | + my($range) = shift(@_); | ||
| 67 | + | ||
| 68 | + # Take third and any subsequent parameters and concatenate with spaces | ||
| 69 | + # to form the name of the range for use in error messages. | ||
| 70 | + my($range_name) = join(' ', @_); | ||
| 71 | + $range_name = " for $range_name." if ($range_name); | ||
| 72 | + | ||
| 73 | + # Use strict doesn't let us do string/numeric conversions, so turn | ||
| 74 | + # off warnings to get around that problem and the problem of undefined | ||
| 75 | + # variables from the regex below. | ||
| 76 | + local($^W) = 0; | ||
| 77 | + | ||
| 78 | + my($range_ok) = 0; | ||
| 79 | + | ||
| 80 | + # Split the range into the optional 'invert range' prefix (@), minimum | ||
| 81 | + # bound and upper bound, allowing all the variations. | ||
| 82 | + my($invert_range, $lower, $upper) = $range =~ /^(\@)?(?:([^:])*:)?(.*)?$/; | ||
| 83 | + | ||
| 84 | + # The above regex has problems with 0 (which means 0:infinity), so | ||
| 85 | + # we have to correct for that (but not for :0, which means 0:0 and is | ||
| 86 | + # handled correctly by the regex). | ||
| 87 | + ($lower, $upper) = ($upper, $lower) if | ||
| 88 | + (($upper eq '0' and not $lower) and $range !~ /:/); | ||
| 89 | + | ||
| 90 | + # Check that upper >= lower, including the case when lower or upper is | ||
| 91 | + # ~ (negative infinity). | ||
| 92 | + if ($upper eq '~' or ($lower ne '~' and $upper ne '' and $lower > $upper )) | ||
| 93 | + { | ||
| 94 | + return -1; | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + # If the lower bound is not ~ (negative infinity) then check that the | ||
| 98 | + # metric is greater than or equal to the lower bound. If the lower bound | ||
| 99 | + # is ~ then the metric has to be OK because any metric has to be higher | ||
| 100 | + # than negative infinity. | ||
| 101 | + if ($lower ne '~') | ||
| 102 | + { | ||
| 103 | + $range_ok++ if ($metric >= $lower + 0); | ||
| 104 | + } | ||
| 105 | + else | ||
| 106 | + { | ||
| 107 | + $range_ok++; | ||
| 108 | + } | ||
| 109 | + | ||
| 110 | + $range_ok = 0 if ($upper ne '' and $metric > $upper + 0); | ||
| 111 | + $range_ok ^= 1 if ($invert_range); | ||
| 112 | + | ||
| 113 | + return($range_ok); | ||
| 114 | +} | ||
| 115 | + | ||
| 116 | 1; | ||
