summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorThomas Guyot-Sionnest <dermoth@aei.ca>2009-03-20 06:28:02 (GMT)
committerThomas Guyot-Sionnest <dermoth@aei.ca>2009-03-20 06:28:02 (GMT)
commitd36c97612990ac81d2dc0452b980e8708477df76 (patch)
treef3c9948efc6a27a8aab8c14a68073eb70f7327fb /plugins
parentc459ca07706ee315da3eac91344c2f1d9a152685 (diff)
downloadmonitoring-plugins-d36c97612990ac81d2dc0452b980e8708477df76.tar.gz
negate: make timeouts configurable
Diffstat (limited to 'plugins')
-rw-r--r--plugins/negate.c14
-rw-r--r--plugins/t/negate.t31
2 files changed, 37 insertions, 8 deletions
diff --git a/plugins/negate.c b/plugins/negate.c
index e8be83d..ebbb152 100644
--- a/plugins/negate.c
+++ b/plugins/negate.c
@@ -130,6 +130,7 @@ process_arguments (int argc, char **argv)
130 {"help", no_argument, 0, 'h'}, 130 {"help", no_argument, 0, 'h'},
131 {"version", no_argument, 0, 'V'}, 131 {"version", no_argument, 0, 'V'},
132 {"timeout", required_argument, 0, 't'}, 132 {"timeout", required_argument, 0, 't'},
133 {"timeout-result", required_argument, 0, 'T'},
133 {"ok", required_argument, 0, 'o'}, 134 {"ok", required_argument, 0, 'o'},
134 {"warning", required_argument, 0, 'w'}, 135 {"warning", required_argument, 0, 'w'},
135 {"critical", required_argument, 0, 'c'}, 136 {"critical", required_argument, 0, 'c'},
@@ -139,7 +140,7 @@ process_arguments (int argc, char **argv)
139 }; 140 };
140 141
141 while (1) { 142 while (1) {
142 c = getopt_long (argc, argv, "+hVt:o:w:c:u:s", longopts, &option); 143 c = getopt_long (argc, argv, "+hVt:T:o:w:c:u:s", longopts, &option);
143 144
144 if (c == -1 || c == EOF) 145 if (c == -1 || c == EOF)
145 break; 146 break;
@@ -161,6 +162,10 @@ process_arguments (int argc, char **argv)
161 else 162 else
162 timeout_interval = atoi (optarg); 163 timeout_interval = atoi (optarg);
163 break; 164 break;
165 case 'T': /* Result to return on timeouts */
166 if ((timeout_state = translate_state(optarg)) == ERROR)
167 usage4 (_("timeout result must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or integer (0-3)."));
168 break;
164 case 'o': /* replacement for OK */ 169 case 'o': /* replacement for OK */
165 if ((state[STATE_OK] = translate_state(optarg)) == ERROR) 170 if ((state[STATE_OK] = translate_state(optarg)) == ERROR)
166 usage4 (_("Ok must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or integer (0-3).")); 171 usage4 (_("Ok must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or integer (0-3)."));
@@ -246,6 +251,8 @@ print_help (void)
246 251
247 printf (_(UT_TIMEOUT), timeout_interval); 252 printf (_(UT_TIMEOUT), timeout_interval);
248 printf (" %s\n", _("Keep timeout longer than the plugin timeout to retain CRITICAL status.")); 253 printf (" %s\n", _("Keep timeout longer than the plugin timeout to retain CRITICAL status."));
254 printf (" -T, --timeout-result=STATUS\n");
255 printf (" %s\n", _("Custom result on Negate timeouts; see below for STATUS definition\n"));
249 256
250 printf(" -o, --ok=STATUS\n"); 257 printf(" -o, --ok=STATUS\n");
251 printf(" -w, --warning=STATUS\n"); 258 printf(" -w, --warning=STATUS\n");
@@ -270,6 +277,9 @@ print_help (void)
270 printf (" %s\n", _("If the wrapped plugin returns OK, the wrapper will return CRITICAL.")); 277 printf (" %s\n", _("If the wrapped plugin returns OK, the wrapper will return CRITICAL."));
271 printf (" %s\n", _("If the wrapped plugin returns CRITICAL, the wrapper will return OK.")); 278 printf (" %s\n", _("If the wrapped plugin returns CRITICAL, the wrapper will return OK."));
272 printf (" %s\n", _("Otherwise, the output state of the wrapped plugin is unchanged.")); 279 printf (" %s\n", _("Otherwise, the output state of the wrapped plugin is unchanged."));
280 printf ("\n");
281 printf (" %s\n", _("Using timeout-result, it is possible to override the timeout behaviour or a"));
282 printf (" %s\n", _("plugin by setting the negate timeout a bit lower."));
273 283
274 printf (_(UT_SUPPORT)); 284 printf (_(UT_SUPPORT));
275} 285}
@@ -280,5 +290,5 @@ void
280print_usage (void) 290print_usage (void)
281{ 291{
282 printf (_("Usage:")); 292 printf (_("Usage:"));
283 printf ("%s [-t timeout] [-owcu STATE] [-s] <definition of wrapped plugin>\n", progname); 293 printf ("%s [-t timeout] [-Towcu STATE] [-s] <definition of wrapped plugin>\n", progname);
284} 294}
diff --git a/plugins/t/negate.t b/plugins/t/negate.t
index 989bf01..0afe3ae 100644
--- a/plugins/t/negate.t
+++ b/plugins/t/negate.t
@@ -8,8 +8,8 @@ use strict;
8use Test::More; 8use Test::More;
9use NPTest; 9use NPTest;
10 10
11# 15 tests in the first part and 32 in the last loop 11# 15 tests in the first part, 9 in timeout tests and 2 * 32 in the last loops
12plan tests => 47; 12plan tests => 88;
13 13
14my $res; 14my $res;
15 15
@@ -53,18 +53,37 @@ is( $res->output, "No data returned from command", "Bad command, as expected (tr
53$res = NPTest->testCmd( './negate $PWD/check_dummy 0 \'$$ a dummy okay\'' ); 53$res = NPTest->testCmd( './negate $PWD/check_dummy 0 \'$$ a dummy okay\'' );
54is( $res->output, 'OK: $$ a dummy okay', 'Proves that $$ is not being expanded again' ); 54is( $res->output, 'OK: $$ a dummy okay', 'Proves that $$ is not being expanded again' );
55 55
56
57my %state = ( 56my %state = (
58 ok => 0, 57 ok => 0,
59 warning => 1, 58 warning => 1,
60 critical => 2, 59 critical => 2,
61 unknown => 3, 60 unknown => 3,
62 ); 61 );
63foreach my $current_state (qw(ok warning critical unknown)) { 62
64 foreach my $new_state (qw(ok warning critical unknown)) { 63# Timeout tests
64$res = NPTest->testCmd( "./negate -t 2 /bin/sh -c 'sleep 5'" );
65is( $res->output, 'CRITICAL - Plugin timed out after 2 seconds' );
66
67foreach my $state (keys(%state)) {
68 $res = NPTest->testCmd( "./negate -t 2 -T $state /bin/sh -c 'sleep 5'" );
69 is( $res->return_code, $state{$state}, "Got timeout state $state" );
70 is( $res->output, uc($state)." - Plugin timed out after 2 seconds", "Timeout state $state output");
71}
72
73foreach my $current_state (keys(%state)) {
74 foreach my $new_state (keys(%state)) {
65 $res = NPTest->testCmd( "./negate --$current_state=$new_state ./check_dummy ".$state{$current_state}." 'Fake $new_state'" ); 75 $res = NPTest->testCmd( "./negate --$current_state=$new_state ./check_dummy ".$state{$current_state}." 'Fake $new_state'" );
66 is( $res->return_code, $state{$new_state}, "Got fake $new_state" ); 76 is( $res->return_code, $state{$new_state}, "Got fake $new_state" );
67 is( $res->output, uc($current_state).": Fake $new_state" ); 77 is( $res->output, uc($current_state).": Fake $new_state", "Fake $new_state output");
78 }
79}
80
81# Same as aboce with substitute
82foreach my $current_state (keys(%state)) {
83 foreach my $new_state (keys(%state)) {
84 $res = NPTest->testCmd( "./negate -s --$current_state=$new_state ./check_dummy ".$state{$current_state}." 'Fake $new_state'" );
85 is( $res->return_code, $state{$new_state}, "Got fake $new_state (with substitute)" );
86 is( $res->output, uc($new_state).": Fake $new_state", "Substitued fake $new_state output");
68 } 87 }
69} 88}
70 89