diff options
author | Sven Nierlein <sven@nierlein.de> | 2012-04-09 20:12:21 (GMT) |
---|---|---|
committer | Sven Nierlein <sven@nierlein.de> | 2012-04-09 20:16:39 (GMT) |
commit | 83655083af68ddd87e5177f3dc4365b6d5721ed5 (patch) | |
tree | 0dcef0520f32a2168892a25a86c5635ff025b172 /plugins | |
parent | 019c9263708d48f2140eeaafb6577ce9ad013c5e (diff) | |
download | monitoring-plugins-83655083af68ddd87e5177f3dc4365b6d5721ed5.tar.gz |
check_by_ssh: added -F config file to specify alternative ssh config
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/check_by_ssh.c | 11 | ||||
-rw-r--r-- | plugins/t/check_by_ssh.t | 13 |
2 files changed, 21 insertions, 3 deletions
diff --git a/plugins/check_by_ssh.c b/plugins/check_by_ssh.c index ff27b39..8752016 100644 --- a/plugins/check_by_ssh.c +++ b/plugins/check_by_ssh.c | |||
@@ -187,6 +187,7 @@ process_arguments (int argc, char **argv) | |||
187 | {"use-ipv6", no_argument, 0, '6'}, | 187 | {"use-ipv6", no_argument, 0, '6'}, |
188 | {"ssh-option", required_argument, 0, 'o'}, | 188 | {"ssh-option", required_argument, 0, 'o'}, |
189 | {"quiet", no_argument, 0, 'q'}, | 189 | {"quiet", no_argument, 0, 'q'}, |
190 | {"configfile", optional_argument, 0, 'F'}, | ||
190 | {0, 0, 0, 0} | 191 | {0, 0, 0, 0} |
191 | }; | 192 | }; |
192 | 193 | ||
@@ -198,7 +199,7 @@ process_arguments (int argc, char **argv) | |||
198 | strcpy (argv[c], "-t"); | 199 | strcpy (argv[c], "-t"); |
199 | 200 | ||
200 | while (1) { | 201 | while (1) { |
201 | c = getopt_long (argc, argv, "Vvh1246fqt:H:O:p:i:u:l:C:S::E::n:s:o:", longopts, | 202 | c = getopt_long (argc, argv, "Vvh1246fqt:H:O:p:i:u:l:C:S::E::n:s:o:F:", longopts, |
202 | &option); | 203 | &option); |
203 | 204 | ||
204 | if (c == -1 || c == EOF) | 205 | if (c == -1 || c == EOF) |
@@ -306,6 +307,10 @@ process_arguments (int argc, char **argv) | |||
306 | case 'q': /* Tell the ssh command to be quiet */ | 307 | case 'q': /* Tell the ssh command to be quiet */ |
307 | comm_append("-q"); | 308 | comm_append("-q"); |
308 | break; | 309 | break; |
310 | case 'F': /* ssh configfile */ | ||
311 | comm_append("-F"); | ||
312 | comm_append(optarg); | ||
313 | break; | ||
309 | default: /* help */ | 314 | default: /* help */ |
310 | usage5(); | 315 | usage5(); |
311 | } | 316 | } |
@@ -418,6 +423,8 @@ print_help (void) | |||
418 | printf (" %s\n", _("short name of host in nagios configuration [optional]")); | 423 | printf (" %s\n", _("short name of host in nagios configuration [optional]")); |
419 | printf (" %s\n","-o, --ssh-option=OPTION"); | 424 | printf (" %s\n","-o, --ssh-option=OPTION"); |
420 | printf (" %s\n", _("Call ssh with '-o OPTION' (may be used multiple times) [optional]")); | 425 | printf (" %s\n", _("Call ssh with '-o OPTION' (may be used multiple times) [optional]")); |
426 | printf (" %s\n","-F, --configfile"); | ||
427 | printf (" %s\n", _("Tell ssh to use this configfile [optional]")); | ||
421 | printf (" %s\n","-q, --quiet"); | 428 | printf (" %s\n","-q, --quiet"); |
422 | printf (" %s\n", _("Tell ssh to suppress warning and diagnostic messages [optional]")); | 429 | printf (" %s\n", _("Tell ssh to suppress warning and diagnostic messages [optional]")); |
423 | printf (UT_WARN_CRIT); | 430 | printf (UT_WARN_CRIT); |
@@ -454,6 +461,6 @@ print_usage (void) | |||
454 | printf (" %s -H <host> -C <command> [-fqv] [-1|-2] [-4|-6]\n" | 461 | printf (" %s -H <host> -C <command> [-fqv] [-1|-2] [-4|-6]\n" |
455 | " [-S [lines]] [-E [lines]] [-t timeout] [-i identity]\n" | 462 | " [-S [lines]] [-E [lines]] [-t timeout] [-i identity]\n" |
456 | " [-l user] [-n name] [-s servicelist] [-O outputfile]\n" | 463 | " [-l user] [-n name] [-s servicelist] [-O outputfile]\n" |
457 | " [-p port] [-o ssh-option]\n", | 464 | " [-p port] [-o ssh-option] [-F configfile]\n", |
458 | progname); | 465 | progname); |
459 | } | 466 | } |
diff --git a/plugins/t/check_by_ssh.t b/plugins/t/check_by_ssh.t index 5f2c534..cca72c9 100644 --- a/plugins/t/check_by_ssh.t +++ b/plugins/t/check_by_ssh.t | |||
@@ -17,9 +17,14 @@ my $ssh_key = getTestParameter( "NP_SSH_IDENTITY", | |||
17 | "A key allowing access to NP_SSH_HOST", | 17 | "A key allowing access to NP_SSH_HOST", |
18 | "~/.ssh/id_dsa"); | 18 | "~/.ssh/id_dsa"); |
19 | 19 | ||
20 | my $ssh_conf = getTestParameter( "NP_SSH_CONFIGFILE", | ||
21 | "A config file with ssh settings", | ||
22 | "~/.ssh/config"); | ||
23 | |||
24 | |||
20 | plan skip_all => "SSH_HOST and SSH_IDENTITY must be defined" unless ($ssh_service && $ssh_key); | 25 | plan skip_all => "SSH_HOST and SSH_IDENTITY must be defined" unless ($ssh_service && $ssh_key); |
21 | 26 | ||
22 | plan tests => 40; | 27 | plan tests => 42; |
23 | 28 | ||
24 | # Some random check strings/response | 29 | # Some random check strings/response |
25 | my @responce = ('OK: Everything is fine!', | 30 | my @responce = ('OK: Everything is fine!', |
@@ -85,6 +90,12 @@ $result = NPTest->testCmd( | |||
85 | cmp_ok($result->return_code, '==', 8, "Exit with return code 8 (out of bounds)"); | 90 | cmp_ok($result->return_code, '==', 8, "Exit with return code 8 (out of bounds)"); |
86 | is($result->output, $responce[4], "Return proper status text even with unknown status codes"); | 91 | is($result->output, $responce[4], "Return proper status text even with unknown status codes"); |
87 | 92 | ||
93 | $result = NPTest->testCmd( | ||
94 | "./check_by_ssh -i $ssh_key -H $ssh_service -F $ssh_conf -C 'exit 0'" | ||
95 | ); | ||
96 | cmp_ok($result->return_code, '==', 0, "Exit with return code 0 (OK)"); | ||
97 | is($result->output, 'OK - check_by_ssh: Remote command \'exit 0\' returned status 0', "Status text if command returned none (OK)"); | ||
98 | |||
88 | # Multiple active checks | 99 | # Multiple active checks |
89 | $result = NPTest->testCmd( | 100 | $result = NPTest->testCmd( |
90 | "./check_by_ssh -i $ssh_key -H $ssh_service -C '$check[1]; sh -c exit\\ 1' -C '$check[0]; sh -c exit\\ 0' -C '$check[3]; sh -c exit\\ 3' -C '$check[2]; sh -c exit\\ 2'" | 101 | "./check_by_ssh -i $ssh_key -H $ssh_service -C '$check[1]; sh -c exit\\ 1' -C '$check[0]; sh -c exit\\ 0' -C '$check[3]; sh -c exit\\ 3' -C '$check[2]; sh -c exit\\ 2'" |