summaryrefslogtreecommitdiffstats
path: root/plugins/check_by_ssh.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/check_by_ssh.c')
-rw-r--r--plugins/check_by_ssh.c203
1 files changed, 104 insertions, 99 deletions
diff --git a/plugins/check_by_ssh.c b/plugins/check_by_ssh.c
index 1211daa3..8527b727 100644
--- a/plugins/check_by_ssh.c
+++ b/plugins/check_by_ssh.c
@@ -1,25 +1,19 @@
1/****************************************************************************** 1/******************************************************************************
2 * 2
3 * This file is part of the Nagios Plugins. 3 The Nagios Plugins are free software; you can redistribute them
4 * 4 and/or modify them under the terms of the GNU General Public
5 * Copyright (c) 1999, 2000, 2001 Karl DeBisschop <karl@debisschop.net> 5 License as published by the Free Software Foundation; either
6 * 6 version 2 of the License, or (at your option) any later version.
7 * The Nagios Plugins are free software; you can redistribute them 7
8 * and/or modify them under the terms of the GNU General Public 8 This program is distributed in the hope that it will be useful, but
9 * License as published by the Free Software Foundation; either 9 WITHOUT ANY WARRANTY; without even the implied warranty of
10 * version 2 of the License, or (at your option) any later version. 10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * 11 General Public License for more details.
12 * This program is distributed in the hope that it will be useful, but 12
13 * WITHOUT ANY WARRANTY; without even the implied warranty of 13 You should have received a copy of the GNU General Public License
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 along with this program; if not, write to the Free Software
15 * General Public License for more details. 15 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16 * 16
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 *
21 * $Id$
22 *
23 *****************************************************************************/ 17 *****************************************************************************/
24 18
25const char *progname = "check_by_ssh"; 19const char *progname = "check_by_ssh";
@@ -27,7 +21,6 @@ const char *revision = "$Revision$";
27const char *copyright = "2000-2003"; 21const char *copyright = "2000-2003";
28const char *email = "nagiosplug-devel@lists.sourceforge.net"; 22const char *email = "nagiosplug-devel@lists.sourceforge.net";
29 23
30#include "config.h"
31#include "common.h" 24#include "common.h"
32#include "netutils.h" 25#include "netutils.h"
33#include "utils.h" 26#include "utils.h"
@@ -38,83 +31,10 @@ int validate_arguments (void);
38void print_help (void); 31void print_help (void);
39void print_usage (void); 32void print_usage (void);
40 33
41void
42print_help (void)
43{
44 print_revision (progname, revision);
45
46 printf (_(COPYRIGHT), copyright, email);
47
48 printf (_("This plugin uses SSH to execute commands on a remote host\n\n"));
49
50 print_usage ();
51
52 printf (_(UT_HELP_VRSN));
53
54 printf (_(UT_HOST_PORT), 'p', "none");
55
56 printf (_(UT_IPv46));
57
58 printf (_("\
59 -1, --proto1\n\
60 tell ssh to use Protocol 1\n\
61 -2, --proto2\n\
62 tell ssh to use Protocol 2\n\
63 -f\n\
64 tells ssh to fork rather than create a tty\n"));
65
66 printf (_("\
67 -C, --command='COMMAND STRING'\n\
68 command to execute on the remote machine\n\
69 -l, --logname=USERNAME\n\
70 SSH user name on remote host [optional]\n\
71 -i, --identity=KEYFILE\n\
72 identity of an authorized key [optional]\n\
73 -O, --output=FILE\n\
74 external command file for nagios [optional]\n\
75 -s, --services=LIST\n\
76 list of nagios service names, separated by ':' [optional]\n\
77 -n, --name=NAME\n\
78 short name of host in nagios configuration [optional]\n"));
79
80 printf (_(UT_WARN_CRIT));
81
82 printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
83
84 printf (_("\n\
85The most common mode of use is to refer to a local identity file with\n\
86the '-i' option. In this mode, the identity pair should have a null\n\
87passphrase and the public key should be listed in the authorized_keys\n\
88file of the remote host. Usually the key will be restricted to running\n\
89only one command on the remote server. If the remote SSH server tracks\n\
90invocation agruments, the one remote program may be an agent that can\n\
91execute additional commands as proxy\n"));
92
93 printf (_("\n\
94To use passive mode, provide multiple '-C' options, and provide\n\
95all of -O, -s, and -n options (servicelist order must match '-C'\n\
96options)\n"));
97}
98
99
100
101
102
103void
104print_usage (void)
105{
106 printf (_("Usage:\n\
107check_by_ssh [-f46] [-t timeout] [-i identity] [-l user] -H <host> -C <command>\n\
108 [-n name] [-s servicelist] [-O outputfile] [-p port]\n\
109check_by_ssh -V prints version info\n\
110check_by_ssh -h prints more detailed help\n"));
111}
112
113
114int commands = 0; 34int commands = 0;
115int services = 0; 35int services = 0;
116char *remotecmd = ""; 36char *remotecmd = NULL;
117char *comm = SSH_COMMAND; 37char *comm = NULL;
118char *hostname = NULL; 38char *hostname = NULL;
119char *outputfile = NULL; 39char *outputfile = NULL;
120char *host_shortname = NULL; 40char *host_shortname = NULL;
@@ -123,20 +43,26 @@ int passive = FALSE;
123int verbose = FALSE; 43int verbose = FALSE;
124 44
125 45
46
47
48
49
126int 50int
127main (int argc, char **argv) 51main (int argc, char **argv)
128{ 52{
129 53
130 char input_buffer[MAX_INPUT_BUFFER]; 54 char input_buffer[MAX_INPUT_BUFFER];
131 char *result_text = ""; 55 char *result_text;
132 char *status_text; 56 char *status_text;
133 char *output = ""; 57 char *output;
134 char *eol = NULL; 58 char *eol = NULL;
135 int cresult; 59 int cresult;
136 int result = STATE_UNKNOWN; 60 int result = STATE_UNKNOWN;
137 time_t local_time; 61 time_t local_time;
138 FILE *fp = NULL; 62 FILE *fp = NULL;
139 63
64 asprintf (&remotecmd, "%s", "");
65 asprintf (&comm, "%s", SSH_COMMAND);
140 66
141 /* process arguments */ 67 /* process arguments */
142 if (process_arguments (argc, argv) == ERROR) 68 if (process_arguments (argc, argv) == ERROR)
@@ -235,6 +161,7 @@ main (int argc, char **argv)
235 161
236 162
237 163
164
238/* process command-line arguments */ 165/* process command-line arguments */
239int 166int
240process_arguments (int argc, char **argv) 167process_arguments (int argc, char **argv)
@@ -392,3 +319,81 @@ validate_arguments (void)
392 319
393 return OK; 320 return OK;
394} 321}
322
323
324
325
326
327
328void
329print_help (void)
330{
331 print_revision (progname, revision);
332
333 printf (_("Copyright (c) 1999 Karl DeBisschop <kdebisschop@users.sourceforge.net>\n"));
334 printf (_(COPYRIGHT), copyright, email);
335
336 printf (_("This plugin uses SSH to execute commands on a remote host\n\n"));
337
338 print_usage ();
339
340 printf (_(UT_HELP_VRSN));
341
342 printf (_(UT_HOST_PORT), 'p', "none");
343
344 printf (_(UT_IPv46));
345
346 printf (_("\
347 -1, --proto1\n\
348 tell ssh to use Protocol 1\n\
349 -2, --proto2\n\
350 tell ssh to use Protocol 2\n\
351 -f\n\
352 tells ssh to fork rather than create a tty\n"));
353
354 printf (_("\
355 -C, --command='COMMAND STRING'\n\
356 command to execute on the remote machine\n\
357 -l, --logname=USERNAME\n\
358 SSH user name on remote host [optional]\n\
359 -i, --identity=KEYFILE\n\
360 identity of an authorized key [optional]\n\
361 -O, --output=FILE\n\
362 external command file for nagios [optional]\n\
363 -s, --services=LIST\n\
364 list of nagios service names, separated by ':' [optional]\n\
365 -n, --name=NAME\n\
366 short name of host in nagios configuration [optional]\n"));
367
368 printf (_(UT_WARN_CRIT));
369
370 printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
371
372 printf (_("\n\
373The most common mode of use is to refer to a local identity file with\n\
374the '-i' option. In this mode, the identity pair should have a null\n\
375passphrase and the public key should be listed in the authorized_keys\n\
376file of the remote host. Usually the key will be restricted to running\n\
377only one command on the remote server. If the remote SSH server tracks\n\
378invocation agruments, the one remote program may be an agent that can\n\
379execute additional commands as proxy\n"));
380
381 printf (_("\n\
382To use passive mode, provide multiple '-C' options, and provide\n\
383all of -O, -s, and -n options (servicelist order must match '-C'\n\
384options)\n"));
385}
386
387
388
389
390
391void
392print_usage (void)
393{
394 printf (_("\n\
395Usage: %s [-f46] [-t timeout] [-i identity] [-l user] -H <host> \n\
396 -C <command> [-n name] [-s servicelist] [-O outputfile] [-p port]\n"),
397 progname);
398 printf (_(UT_HLP_VRS), progname, progname);
399}