diff options
Diffstat (limited to 't')
| -rw-r--r-- | t/Nagios-Plugin-Range.t | 3 | ||||
| -rwxr-xr-x | t/check_stuff.pl | 42 |
2 files changed, 26 insertions, 19 deletions
diff --git a/t/Nagios-Plugin-Range.t b/t/Nagios-Plugin-Range.t index df5dbd5..9b75a13 100644 --- a/t/Nagios-Plugin-Range.t +++ b/t/Nagios-Plugin-Range.t | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | 1 | ||
| 2 | use strict; | 2 | use strict; |
| 3 | use Test::More qw(no_plan); #tests => 123; | 3 | #use Test::More qw(no_plan); |
| 4 | use Test::More tests => 149; | ||
| 4 | 5 | ||
| 5 | BEGIN { | 6 | BEGIN { |
| 6 | use_ok('Nagios::Plugin::Range'); | 7 | use_ok('Nagios::Plugin::Range'); |
diff --git a/t/check_stuff.pl b/t/check_stuff.pl index 889e484..8284169 100755 --- a/t/check_stuff.pl +++ b/t/check_stuff.pl | |||
| @@ -50,27 +50,32 @@ THRESHOLDs for -w and -c are specified 'min:max' or 'min:' or ':max' | |||
| 50 | (or 'max'). If specified '\@min:max', a warning status will be generated | 50 | (or 'max'). If specified '\@min:max', a warning status will be generated |
| 51 | if the count *is* inside the specified range. | 51 | if the count *is* inside the specified range. |
| 52 | 52 | ||
| 53 | See more threshold examples at | 53 | See more threshold examples at http |
| 54 | http://nagiosplug.sourceforge.net/developer-guidelines.html#THRESHOLDFORMAT | 54 | : // nagiosplug |
| 55 | . sourceforge | ||
| 56 | . net / developer-guidelines | ||
| 57 | . html #THRESHOLDFORMAT | ||
| 55 | 58 | ||
| 56 | Examples: | 59 | Examples: |
| 57 | 60 | ||
| 58 | $PROGNAME -w 10 -c 18 | 61 | $PROGNAME -w 10 -c 18 Returns a warning |
| 59 | Returns a warning if the resulting number is greater than 10, or a | 62 | if the resulting number is greater than 10, |
| 60 | critical error if it is greater than 18. | 63 | or a critical error |
| 64 | if it is greater than 18. | ||
| 61 | 65 | ||
| 62 | $PROGNAME -w 10: -c 4: | 66 | $PROGNAME -w 10 : -c 4 : Returns a warning |
| 63 | Returns a warning if the resulting number is less than 10, or a | 67 | if the resulting number is less than 10, |
| 64 | critical error if it is less than 4. | 68 | or a critical error |
| 69 | if it is less than 4. | ||
| 65 | 70 | ||
| 66 | " | 71 | " |
| 67 | ); | 72 | ); |
| 68 | 73 | ||
| 69 | 74 | ||
| 70 | # Define and document the valid command line options | 75 | # Define and document the valid command line options |
| 71 | # usage, help, version, timeout and verbose are defined by default. | 76 | # usage, help, version, timeout and verbose are defined by default. |
| 72 | 77 | ||
| 73 | $p->arg( | 78 | $p->add_arg( |
| 74 | spec => 'warning|w=s', | 79 | spec => 'warning|w=s', |
| 75 | 80 | ||
| 76 | help => | 81 | help => |
| @@ -82,7 +87,7 @@ qq{-w, --warning=INTEGER:INTEGER | |||
| 82 | # default => 10, | 87 | # default => 10, |
| 83 | ); | 88 | ); |
| 84 | 89 | ||
| 85 | $p->arg( | 90 | $p->add_arg( |
| 86 | spec => 'critical|c=s', | 91 | spec => 'critical|c=s', |
| 87 | help => | 92 | help => |
| 88 | qq{-c, --critical=INTEGER:INTEGER | 93 | qq{-c, --critical=INTEGER:INTEGER |
| @@ -90,7 +95,7 @@ qq{-c, --critical=INTEGER:INTEGER | |||
| 90 | which a critical will be generated. }, | 95 | which a critical will be generated. }, |
| 91 | ); | 96 | ); |
| 92 | 97 | ||
| 93 | $p->arg( | 98 | $p->add_arg( |
| 94 | spec => 'result|r=f', | 99 | spec => 'result|r=f', |
| 95 | help => | 100 | help => |
| 96 | qq{-r, --result=INTEGER | 101 | qq{-r, --result=INTEGER |
| @@ -104,11 +109,11 @@ $p->getopts; | |||
| 104 | 109 | ||
| 105 | # perform sanity checking on command line options | 110 | # perform sanity checking on command line options |
| 106 | if ( (defined $p->opts->result) && ($p->opts->result < 0 || $p->opts->result > 20) ) { | 111 | if ( (defined $p->opts->result) && ($p->opts->result < 0 || $p->opts->result > 20) ) { |
| 107 | $p->nagios_die( "invalid number supplied for the -r option" ); | 112 | $p->nagios_die( " invalid number supplied for the -r option " ); |
| 108 | } | 113 | } |
| 109 | 114 | ||
| 110 | unless ( defined $p->opts->warning || defined $p->opts->critical ) { | 115 | unless ( defined $p->opts->warning || defined $p->opts->critical ) { |
| 111 | $p->nagios_die( "you didn't supply a threshold argument" ); | 116 | $p->nagios_die( " you didn't supply a threshold argument " ); |
| 112 | } | 117 | } |
| 113 | 118 | ||
| 114 | 119 | ||
| @@ -121,11 +126,12 @@ unless ( defined $p->opts->warning || defined $p->opts->critical ) { | |||
| 121 | my $result; | 126 | my $result; |
| 122 | if (defined $p->opts->result) { # you got a 'result' option from the command line options | 127 | if (defined $p->opts->result) { # you got a 'result' option from the command line options |
| 123 | $result = $p->opts->result; | 128 | $result = $p->opts->result; |
| 124 | print "using supplied result $result from command line\n" if $p->opts->verbose; | 129 | print " using supplied result $result from command line \n |
| 130 | " if $p->opts->verbose; | ||
| 125 | } | 131 | } |
| 126 | else { | 132 | else { |
| 127 | $result = int rand(20)+1; | 133 | $result = int rand(20)+1; |
| 128 | print "generated random result $result\n" if $p->opts->verbose; | 134 | print " generated random result $result\n " if $p->opts->verbose; |
| 129 | } | 135 | } |
| 130 | 136 | ||
| 131 | 137 | ||
| @@ -134,6 +140,6 @@ else { | |||
| 134 | # output the result and exit | 140 | # output the result and exit |
| 135 | $p->nagios_exit( | 141 | $p->nagios_exit( |
| 136 | return_code => $p->check_threshold($result), | 142 | return_code => $p->check_threshold($result), |
| 137 | message => "sample result was $result" | 143 | message => " sample result was $result" |
| 138 | ); | 144 | ); |
| 139 | 145 | ||
