From 83655083af68ddd87e5177f3dc4365b6d5721ed5 Mon Sep 17 00:00:00 2001 From: Sven Nierlein Date: Mon, 9 Apr 2012 22:12:21 +0200 Subject: check_by_ssh: added -F config file to specify alternative ssh config --- plugins/check_by_ssh.c | 11 +++++++++-- plugins/t/check_by_ssh.t | 13 ++++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) (limited to 'plugins') diff --git a/plugins/check_by_ssh.c b/plugins/check_by_ssh.c index ff27b396..87520166 100644 --- a/plugins/check_by_ssh.c +++ b/plugins/check_by_ssh.c @@ -187,6 +187,7 @@ process_arguments (int argc, char **argv) {"use-ipv6", no_argument, 0, '6'}, {"ssh-option", required_argument, 0, 'o'}, {"quiet", no_argument, 0, 'q'}, + {"configfile", optional_argument, 0, 'F'}, {0, 0, 0, 0} }; @@ -198,7 +199,7 @@ process_arguments (int argc, char **argv) strcpy (argv[c], "-t"); while (1) { - c = getopt_long (argc, argv, "Vvh1246fqt:H:O:p:i:u:l:C:S::E::n:s:o:", longopts, + c = getopt_long (argc, argv, "Vvh1246fqt:H:O:p:i:u:l:C:S::E::n:s:o:F:", longopts, &option); if (c == -1 || c == EOF) @@ -306,6 +307,10 @@ process_arguments (int argc, char **argv) case 'q': /* Tell the ssh command to be quiet */ comm_append("-q"); break; + case 'F': /* ssh configfile */ + comm_append("-F"); + comm_append(optarg); + break; default: /* help */ usage5(); } @@ -418,6 +423,8 @@ print_help (void) printf (" %s\n", _("short name of host in nagios configuration [optional]")); printf (" %s\n","-o, --ssh-option=OPTION"); printf (" %s\n", _("Call ssh with '-o OPTION' (may be used multiple times) [optional]")); + printf (" %s\n","-F, --configfile"); + printf (" %s\n", _("Tell ssh to use this configfile [optional]")); printf (" %s\n","-q, --quiet"); printf (" %s\n", _("Tell ssh to suppress warning and diagnostic messages [optional]")); printf (UT_WARN_CRIT); @@ -454,6 +461,6 @@ print_usage (void) printf (" %s -H -C [-fqv] [-1|-2] [-4|-6]\n" " [-S [lines]] [-E [lines]] [-t timeout] [-i identity]\n" " [-l user] [-n name] [-s servicelist] [-O outputfile]\n" - " [-p port] [-o ssh-option]\n", + " [-p port] [-o ssh-option] [-F configfile]\n", progname); } diff --git a/plugins/t/check_by_ssh.t b/plugins/t/check_by_ssh.t index 5f2c534d..cca72c96 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", "A key allowing access to NP_SSH_HOST", "~/.ssh/id_dsa"); +my $ssh_conf = getTestParameter( "NP_SSH_CONFIGFILE", + "A config file with ssh settings", + "~/.ssh/config"); + + plan skip_all => "SSH_HOST and SSH_IDENTITY must be defined" unless ($ssh_service && $ssh_key); -plan tests => 40; +plan tests => 42; # Some random check strings/response my @responce = ('OK: Everything is fine!', @@ -85,6 +90,12 @@ $result = NPTest->testCmd( cmp_ok($result->return_code, '==', 8, "Exit with return code 8 (out of bounds)"); is($result->output, $responce[4], "Return proper status text even with unknown status codes"); +$result = NPTest->testCmd( + "./check_by_ssh -i $ssh_key -H $ssh_service -F $ssh_conf -C 'exit 0'" + ); +cmp_ok($result->return_code, '==', 0, "Exit with return code 0 (OK)"); +is($result->output, 'OK - check_by_ssh: Remote command \'exit 0\' returned status 0', "Status text if command returned none (OK)"); + # Multiple active checks $result = NPTest->testCmd( "./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'" -- cgit v1.2.3