diff options
Diffstat (limited to 'plugins/check_nagios.c')
-rw-r--r-- | plugins/check_nagios.c | 162 |
1 files changed, 75 insertions, 87 deletions
diff --git a/plugins/check_nagios.c b/plugins/check_nagios.c index 64a828b9..7ae0ff85 100644 --- a/plugins/check_nagios.c +++ b/plugins/check_nagios.c | |||
@@ -1,40 +1,72 @@ | |||
1 | /****************************************************************************** | 1 | /****************************************************************************** |
2 | * | 2 | |
3 | * CHECK_NAGIOS.C | 3 | This program is free software; you can redistribute it and/or modify |
4 | * | 4 | it under the terms of the GNU General Public License as published by |
5 | * Program: Nagios process plugin for Nagios | 5 | the Free Software Foundation; either version 2 of the License, or |
6 | * License: GPL | 6 | (at your option) any later version. |
7 | * Copyright (c) 1999 Ethan Galstad (nagios@nagios.org) | 7 | |
8 | * | 8 | This program is distributed in the hope that it will be useful, |
9 | * $Id$ | 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * | 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * License Information: | 11 | GNU General Public License for more details. |
12 | * | 12 | |
13 | * This program is free software; you can redistribute it and/or modify | 13 | You should have received a copy of the GNU General Public License |
14 | * it under the terms of the GNU General Public License as published by | 14 | along with this program; if not, write to the Free Software |
15 | * the Free Software Foundation; either version 2 of the License, or | 15 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
16 | * (at your option) any later version. | 16 | |
17 | * | 17 | ******************************************************************************/ |
18 | * This program is distributed in the hope that it will be useful, | 18 | |
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 19 | const char *progname = "check_nagios"; |
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 20 | const char *revision = "$Revision$"; |
21 | * GNU General Public License for more details. | 21 | const char *copyright = "1999-2003"; |
22 | * | 22 | const char *email = "nagiosplug-devel@lists.sourceforge.net"; |
23 | * You should have received a copy of the GNU General Public License | ||
24 | * along with this program; if not, write to the Free Software | ||
25 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
26 | * | ||
27 | *****************************************************************************/ | ||
28 | 23 | ||
29 | #include "common.h" | 24 | #include "common.h" |
30 | #include "popen.h" | 25 | #include "popen.h" |
31 | #include "utils.h" | 26 | #include "utils.h" |
32 | 27 | ||
33 | const char *progname = "check_nagios"; | 28 | void |
29 | print_usage (void) | ||
30 | { | ||
31 | printf (_("\ | ||
32 | Usage: %s -F <status log file> -e <expire_minutes> -C <process_string>\n"), | ||
33 | progname); | ||
34 | } | ||
34 | 35 | ||
36 | void | ||
37 | print_help (void) | ||
38 | { | ||
39 | print_revision (progname, revision); | ||
40 | |||
41 | printf (_(COPYRIGHT), copyright, email); | ||
42 | |||
43 | printf (_("\ | ||
44 | This plugin attempts to check the status of the Nagios process on the local\n\ | ||
45 | machine. The plugin will check to make sure the Nagios status log is no older\n\ | ||
46 | than the number of minutes specified by the <expire_minutes> option. It also\n\ | ||
47 | uses the /bin/ps command to check for a process matching whatever you specify\n\ | ||
48 | by the <process_string> argument.\n")); | ||
49 | |||
50 | print_usage (); | ||
51 | |||
52 | printf (_(UT_HELP_VRSN)); | ||
53 | |||
54 | printf (_("\ | ||
55 | -F, --filename=FILE\n\ | ||
56 | Name of the log file to check\n\ | ||
57 | -e, --expires=INTEGER\n\ | ||
58 | Seconds aging afterwhich logfile is condsidered stale\n\ | ||
59 | -C, --command=STRING\n\ | ||
60 | Command to search for in process table\n")); | ||
61 | |||
62 | printf (_("\ | ||
63 | Example:\n\ | ||
64 | ./check_nagios -e 5 \\\ | ||
65 | -F /usr/local/nagios/var/status.log \\\ | ||
66 | -C /usr/local/nagios/bin/nagios\n")); | ||
67 | } | ||
68 | |||
35 | int process_arguments (int, char **); | 69 | int process_arguments (int, char **); |
36 | void print_usage (void); | ||
37 | void print_help (void); | ||
38 | 70 | ||
39 | char *status_log = NULL; | 71 | char *status_log = NULL; |
40 | char *process_string = NULL; | 72 | char *process_string = NULL; |
@@ -64,11 +96,11 @@ main (int argc, char **argv) | |||
64 | int pos, cols; | 96 | int pos, cols; |
65 | 97 | ||
66 | if (process_arguments (argc, argv) == ERROR) | 98 | if (process_arguments (argc, argv) == ERROR) |
67 | usage ("Could not parse arguments\n"); | 99 | usage (_("Could not parse arguments\n")); |
68 | 100 | ||
69 | /* Set signal handling and alarm */ | 101 | /* Set signal handling and alarm */ |
70 | if (signal (SIGALRM, timeout_alarm_handler) == SIG_ERR) { | 102 | if (signal (SIGALRM, timeout_alarm_handler) == SIG_ERR) { |
71 | printf ("Cannot catch SIGALRM"); | 103 | printf (_("Cannot catch SIGALRM")); |
72 | return STATE_UNKNOWN; | 104 | return STATE_UNKNOWN; |
73 | } | 105 | } |
74 | 106 | ||
@@ -78,7 +110,7 @@ main (int argc, char **argv) | |||
78 | /* open the status log */ | 110 | /* open the status log */ |
79 | fp = fopen (status_log, "r"); | 111 | fp = fopen (status_log, "r"); |
80 | if (fp == NULL) { | 112 | if (fp == NULL) { |
81 | printf ("Error: Cannot open status log for reading!\n"); | 113 | printf (_("Error: Cannot open status log for reading!\n")); |
82 | return STATE_CRITICAL; | 114 | return STATE_CRITICAL; |
83 | } | 115 | } |
84 | 116 | ||
@@ -95,13 +127,13 @@ main (int argc, char **argv) | |||
95 | /* run the command to check for the Nagios process.. */ | 127 | /* run the command to check for the Nagios process.. */ |
96 | child_process = spopen (PS_COMMAND); | 128 | child_process = spopen (PS_COMMAND); |
97 | if (child_process == NULL) { | 129 | if (child_process == NULL) { |
98 | printf ("Could not open pipe: %s\n", PS_COMMAND); | 130 | printf (_("Could not open pipe: %s\n"), PS_COMMAND); |
99 | return STATE_UNKNOWN; | 131 | return STATE_UNKNOWN; |
100 | } | 132 | } |
101 | 133 | ||
102 | child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r"); | 134 | child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r"); |
103 | if (child_stderr == NULL) { | 135 | if (child_stderr == NULL) { |
104 | printf ("Could not open stderr for %s\n", PS_COMMAND); | 136 | printf (_("Could not open stderr for %s\n"), PS_COMMAND); |
105 | } | 137 | } |
106 | 138 | ||
107 | fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process); | 139 | fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process); |
@@ -116,7 +148,7 @@ main (int argc, char **argv) | |||
116 | if (!strstr(procargs, argv[0]) && strstr(procargs, process_string)) { | 148 | if (!strstr(procargs, argv[0]) && strstr(procargs, process_string)) { |
117 | proc_entries++; | 149 | proc_entries++; |
118 | if (verbose) | 150 | if (verbose) |
119 | printf ("Found process: %s\n", procargs); | 151 | printf (_("Found process: %s\n"), procargs); |
120 | } | 152 | } |
121 | } | 153 | } |
122 | } | 154 | } |
@@ -136,18 +168,18 @@ main (int argc, char **argv) | |||
136 | alarm (0); | 168 | alarm (0); |
137 | 169 | ||
138 | if (proc_entries == 0) { | 170 | if (proc_entries == 0) { |
139 | printf ("Could not locate a running Nagios process!\n"); | 171 | printf (_("Could not locate a running Nagios process!\n")); |
140 | return STATE_CRITICAL; | 172 | return STATE_CRITICAL; |
141 | } | 173 | } |
142 | 174 | ||
143 | result = STATE_OK; | 175 | result = STATE_OK; |
144 | 176 | ||
145 | time (¤t_time); | 177 | time (¤t_time); |
146 | if ((current_time - latest_entry_time) > (expire_minutes * 60)) | 178 | if ((int)(current_time - latest_entry_time) > (expire_minutes * 60)) |
147 | result = STATE_WARNING; | 179 | result = STATE_WARNING; |
148 | 180 | ||
149 | printf | 181 | printf |
150 | ("Nagios %s: located %d process%s, status log updated %d second%s ago\n", | 182 | (_("Nagios %s: located %d process%s, status log updated %d second%s ago\n"), |
151 | (result == STATE_OK) ? "ok" : "problem", proc_entries, | 183 | (result == STATE_OK) ? "ok" : "problem", proc_entries, |
152 | (proc_entries == 1) ? "" : "es", | 184 | (proc_entries == 1) ? "" : "es", |
153 | (int) (current_time - latest_entry_time), | 185 | (int) (current_time - latest_entry_time), |
@@ -186,7 +218,7 @@ process_arguments (int argc, char **argv) | |||
186 | expire_minutes = atoi (argv[2]); | 218 | expire_minutes = atoi (argv[2]); |
187 | else | 219 | else |
188 | terminate (STATE_UNKNOWN, | 220 | terminate (STATE_UNKNOWN, |
189 | "Expiration time must be an integer (seconds)\nType '%s -h' for additional help\n", | 221 | _("Expiration time must be an integer (seconds)\nType '%s -h' for additional help\n"), |
190 | progname); | 222 | progname); |
191 | process_string = argv[3]; | 223 | process_string = argv[3]; |
192 | return OK; | 224 | return OK; |
@@ -200,7 +232,7 @@ process_arguments (int argc, char **argv) | |||
200 | 232 | ||
201 | switch (c) { | 233 | switch (c) { |
202 | case '?': /* print short usage statement if args not parsable */ | 234 | case '?': /* print short usage statement if args not parsable */ |
203 | printf ("%s: Unknown argument: %c\n\n", progname, optopt); | 235 | printf (_("%s: Unknown argument: %c\n\n"), progname, optopt); |
204 | print_usage (); | 236 | print_usage (); |
205 | exit (STATE_UNKNOWN); | 237 | exit (STATE_UNKNOWN); |
206 | case 'h': /* help */ | 238 | case 'h': /* help */ |
@@ -220,7 +252,7 @@ process_arguments (int argc, char **argv) | |||
220 | expire_minutes = atoi (optarg); | 252 | expire_minutes = atoi (optarg); |
221 | else | 253 | else |
222 | terminate (STATE_UNKNOWN, | 254 | terminate (STATE_UNKNOWN, |
223 | "Expiration time must be an integer (seconds)\nType '%s -h' for additional help\n", | 255 | _("Expiration time must be an integer (seconds)\nType '%s -h' for additional help\n"), |
224 | progname); | 256 | progname); |
225 | break; | 257 | break; |
226 | case 'v': | 258 | case 'v': |
@@ -232,56 +264,12 @@ process_arguments (int argc, char **argv) | |||
232 | 264 | ||
233 | if (status_log == NULL) | 265 | if (status_log == NULL) |
234 | terminate (STATE_UNKNOWN, | 266 | terminate (STATE_UNKNOWN, |
235 | "You must provide the status_log\nType '%s -h' for additional help\n", | 267 | _("You must provide the status_log\nType '%s -h' for additional help\n"), |
236 | progname); | 268 | progname); |
237 | else if (process_string == NULL) | 269 | else if (process_string == NULL) |
238 | terminate (STATE_UNKNOWN, | 270 | terminate (STATE_UNKNOWN, |
239 | "You must provide a process string\nType '%s -h' for additional help\n", | 271 | _("You must provide a process string\nType '%s -h' for additional help\n"), |
240 | progname); | 272 | progname); |
241 | 273 | ||
242 | return OK; | 274 | return OK; |
243 | } | 275 | } |
244 | |||
245 | |||
246 | |||
247 | |||
248 | |||
249 | void | ||
250 | print_usage (void) | ||
251 | { | ||
252 | printf | ||
253 | ("Usage: %s -F <status log file> -e <expire_minutes> -C <process_string>\n", | ||
254 | progname); | ||
255 | } | ||
256 | |||
257 | |||
258 | |||
259 | |||
260 | |||
261 | void | ||
262 | print_help (void) | ||
263 | { | ||
264 | print_revision (progname, "$Revision$"); | ||
265 | printf | ||
266 | ("Copyright (c) 2000 Ethan Galstad/Karl DeBisschop\n\n" | ||
267 | "This plugin attempts to check the status of the Nagios process on the local\n" | ||
268 | "machine. The plugin will check to make sure the Nagios status log is no older\n" | ||
269 | "than the number of minutes specified by the <expire_minutes> option. It also\n" | ||
270 | "uses the /bin/ps command to check for a process matching whatever you specify\n" | ||
271 | "by the <process_string> argument.\n"); | ||
272 | print_usage (); | ||
273 | printf | ||
274 | ("\nOptions:\n" | ||
275 | "-F, --filename=FILE\n" | ||
276 | " Name of the log file to check\n" | ||
277 | "-e, --expires=INTEGER\n" | ||
278 | " Seconds aging afterwhich logfile is condsidered stale\n" | ||
279 | "-C, --command=STRING\n" | ||
280 | " Command to search for in process table\n" | ||
281 | "-h, --help\n" | ||
282 | " Print this help screen\n" | ||
283 | "-V, --version\n" | ||
284 | " Print version information\n\n" | ||
285 | "Example:\n" | ||
286 | " ./check_nagios -F /usr/local/nagios/var/status.log -e 5 -C /usr/local/nagios/bin/nagios\n"); | ||
287 | } | ||