summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorBenoit Mortier <opensides@users.sourceforge.net>2005-11-14 00:51:44 +0000
committerBenoit Mortier <opensides@users.sourceforge.net>2005-11-14 00:51:44 +0000
commitc68d99cee2d1b3de6a7e800440433a39a7436313 (patch)
treebecb58a009fd3b7016d16a44139f13d6f7b511d7 /plugins
parent7741c005fa10be018264f17e685d5bde34bc92a3 (diff)
downloadmonitoring-plugins-c68d99cee2d1b3de6a7e800440433a39a7436313.tar.gz
start of the cleaning of the localization
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1282 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_dig.c481
-rw-r--r--plugins/check_disk.c1073
-rw-r--r--plugins/check_dns.c667
-rw-r--r--plugins/check_dummy.c117
-rw-r--r--plugins/check_fping.c633
-rw-r--r--plugins/check_game.c453
6 files changed, 1806 insertions, 1618 deletions
diff --git a/plugins/check_dig.c b/plugins/check_dig.c
index bc4dcd5c..c9fce613 100644
--- a/plugins/check_dig.c
+++ b/plugins/check_dig.c
@@ -26,7 +26,7 @@
26 26
27const char *progname = "check_dig"; 27const char *progname = "check_dig";
28const char *revision = "$Revision$"; 28const char *revision = "$Revision$";
29const char *copyright = "2002-2004"; 29const char *copyright = "2002-2005";
30const char *email = "nagiosplug-devel@lists.sourceforge.net"; 30const char *email = "nagiosplug-devel@lists.sourceforge.net";
31 31
32#include "common.h" 32#include "common.h"
@@ -55,113 +55,113 @@ struct timeval tv;
55int 55int
56main (int argc, char **argv) 56main (int argc, char **argv)
57{ 57{
58 char *command_line; 58 char *command_line;
59 output chld_out, chld_err; 59 output chld_out, chld_err;
60 char *msg = NULL; 60 char *msg = NULL;
61 size_t i; 61 size_t i;
62 char *t; 62 char *t;
63 long microsec; 63 long microsec;
64 double elapsed_time; 64 double elapsed_time;
65 int result = STATE_UNKNOWN; 65 int result = STATE_UNKNOWN;
66 66
67 setlocale (LC_ALL, ""); 67 setlocale (LC_ALL, "");
68 bindtextdomain (PACKAGE, LOCALEDIR); 68 bindtextdomain (PACKAGE, LOCALEDIR);
69 textdomain (PACKAGE); 69 textdomain (PACKAGE);
70 70
71 /* Set signal handling and alarm */ 71 /* Set signal handling and alarm */
72 if (signal (SIGALRM, popen_timeout_alarm_handler) == SIG_ERR) 72 if (signal (SIGALRM, popen_timeout_alarm_handler) == SIG_ERR)
73 usage_va(_("Cannot catch SIGALRM")); 73 usage_va(_("Cannot catch SIGALRM"));
74 74
75 if (process_arguments (argc, argv) == ERROR) 75 if (process_arguments (argc, argv) == ERROR)
76 usage_va(_("Could not parse arguments")); 76 usage_va(_("Could not parse arguments"));
77 77
78 /* get the command to run */ 78 /* get the command to run */
79 asprintf (&command_line, "%s @%s -p %d %s -t %s", 79 asprintf (&command_line, "%s @%s -p %d %s -t %s",
80 PATH_TO_DIG, dns_server, server_port, query_address, record_type); 80 PATH_TO_DIG, dns_server, server_port, query_address, record_type);
81 81
82 alarm (timeout_interval); 82 alarm (timeout_interval);
83 gettimeofday (&tv, NULL); 83 gettimeofday (&tv, NULL);
84 84
85 if (verbose) { 85 if (verbose) {
86 printf ("%s\n", command_line); 86 printf ("%s\n", command_line);
87 if(expected_address != NULL) { 87 if(expected_address != NULL) {
88 printf (_("Looking for: '%s'\n"), expected_address); 88 printf (_("Looking for: '%s'\n"), expected_address);
89 } else { 89 } else {
90 printf (_("Looking for: '%s'\n"), query_address); 90 printf (_("Looking for: '%s'\n"), query_address);
91 } 91 }
92 } 92 }
93 93
94 /* run the command */ 94 /* run the command */
95 if(np_runcmd(command_line, &chld_out, &chld_err, 0) != 0) { 95 if(np_runcmd(command_line, &chld_out, &chld_err, 0) != 0) {
96 result = STATE_WARNING; 96 result = STATE_WARNING;
97 msg = (char *)_("dig returned an error status"); 97 msg = (char *)_("dig returned an error status");
98 } 98 }
99 99
100 for(i = 0; i < chld_out.lines; i++) { 100 for(i = 0; i < chld_out.lines; i++) {
101 /* the server is responding, we just got the host name... */ 101 /* the server is responding, we just got the host name... */
102 if (strstr (chld_out.line[i], ";; ANSWER SECTION:")) { 102 if (strstr (chld_out.line[i], ";; ANSWER SECTION:")) {
103 103
104 /* loop through the whole 'ANSWER SECTION' */ 104 /* loop through the whole 'ANSWER SECTION' */
105 for(; i < chld_out.lines; i++) { 105 for(; i < chld_out.lines; i++) {
106 /* get the host address */ 106 /* get the host address */
107 if (verbose) 107 if (verbose)
108 printf ("%s\n", chld_out.line[i]); 108 printf ("%s\n", chld_out.line[i]);
109 109
110 if (strstr (chld_out.line[i], (expected_address == NULL ? query_address : expected_address)) != NULL) { 110 if (strstr (chld_out.line[i], (expected_address == NULL ? query_address : expected_address)) != NULL) {
111 msg = chld_out.line[i]; 111 msg = chld_out.line[i];
112 result = STATE_OK; 112 result = STATE_OK;
113 113
114 /* Translate output TAB -> SPACE */ 114 /* Translate output TAB -> SPACE */
115 t = msg; 115 t = msg;
116 while ((t = strchr(t, '\t')) != NULL) *t = ' '; 116 while ((t = strchr(t, '\t')) != NULL) *t = ' ';
117 break; 117 break;
118 } 118 }
119 } 119 }
120 120
121 if (result == STATE_UNKNOWN) { 121 if (result == STATE_UNKNOWN) {
122 msg = (char *)_("Server not found in ANSWER SECTION"); 122 msg = (char *)_("Server not found in ANSWER SECTION");
123 result = STATE_WARNING; 123 result = STATE_WARNING;
124 } 124 }
125 125
126 /* we found the answer section, so break out of the loop */ 126 /* we found the answer section, so break out of the loop */
127 break; 127 break;
128 } 128 }
129 } 129 }
130 130
131 if (result == STATE_UNKNOWN) 131 if (result == STATE_UNKNOWN)
132 msg = (char *)_("No ANSWER SECTION found"); 132 msg = (char *)_("No ANSWER SECTION found");
133 133
134 /* If we get anything on STDERR, at least set warning */ 134 /* If we get anything on STDERR, at least set warning */
135 if(chld_err.buflen > 0) { 135 if(chld_err.buflen > 0) {
136 result = max_state(result, STATE_WARNING); 136 result = max_state(result, STATE_WARNING);
137 if(!msg) for(i = 0; i < chld_err.lines; i++) { 137 if(!msg) for(i = 0; i < chld_err.lines; i++) {
138 msg = strchr(chld_err.line[0], ':'); 138 msg = strchr(chld_err.line[0], ':');
139 if(msg) { 139 if(msg) {
140 msg++; 140 msg++;
141 break; 141 break;
142 } 142 }
143 } 143 }
144 } 144 }
145 145
146 microsec = deltime (tv); 146 microsec = deltime (tv);
147 elapsed_time = (double)microsec / 1.0e6; 147 elapsed_time = (double)microsec / 1.0e6;
148 148
149 if (critical_interval > UNDEFINED && elapsed_time > critical_interval) 149 if (critical_interval > UNDEFINED && elapsed_time > critical_interval)
150 result = STATE_CRITICAL; 150 result = STATE_CRITICAL;
151 151
152 else if (warning_interval > UNDEFINED && elapsed_time > warning_interval) 152 else if (warning_interval > UNDEFINED && elapsed_time > warning_interval)
153 result = STATE_WARNING; 153 result = STATE_WARNING;
154 154
155 printf ("DNS %s - %.3f seconds response time (%s)|%s\n", 155 printf ("DNS %s - %.3f seconds response time (%s)|%s\n",
156 state_text (result), elapsed_time, 156 state_text (result), elapsed_time,
157 msg ? msg : _("Probably a non-existent host/domain"), 157 msg ? msg : _("Probably a non-existent host/domain"),
158 fperfdata("time", elapsed_time, "s", 158 fperfdata("time", elapsed_time, "s",
159 (warning_interval>UNDEFINED?TRUE:FALSE), 159 (warning_interval>UNDEFINED?TRUE:FALSE),
160 warning_interval, 160 warning_interval,
161 (critical_interval>UNDEFINED?TRUE:FALSE), 161 (critical_interval>UNDEFINED?TRUE:FALSE),
162 critical_interval, 162 critical_interval,
163 TRUE, 0, FALSE, 0)); 163 TRUE, 0, FALSE, 0));
164 return result; 164 return result;
165} 165}
166 166
167 167
@@ -170,104 +170,104 @@ main (int argc, char **argv)
170int 170int
171process_arguments (int argc, char **argv) 171process_arguments (int argc, char **argv)
172{ 172{
173 int c; 173 int c;
174 174
175 int option = 0; 175 int option = 0;
176 static struct option longopts[] = { 176 static struct option longopts[] = {
177 {"hostname", required_argument, 0, 'H'}, 177 {"hostname", required_argument, 0, 'H'},
178 {"query_address", required_argument, 0, 'l'}, 178 {"query_address", required_argument, 0, 'l'},
179 {"warning", required_argument, 0, 'w'}, 179 {"warning", required_argument, 0, 'w'},
180 {"critical", required_argument, 0, 'c'}, 180 {"critical", required_argument, 0, 'c'},
181 {"timeout", required_argument, 0, 't'}, 181 {"timeout", required_argument, 0, 't'},
182 {"verbose", no_argument, 0, 'v'}, 182 {"verbose", no_argument, 0, 'v'},
183 {"version", no_argument, 0, 'V'}, 183 {"version", no_argument, 0, 'V'},
184 {"help", no_argument, 0, 'h'}, 184 {"help", no_argument, 0, 'h'},
185 {"record_type", required_argument, 0, 'T'}, 185 {"record_type", required_argument, 0, 'T'},
186 {"expected_address", required_argument, 0, 'a'}, 186 {"expected_address", required_argument, 0, 'a'},
187 {0, 0, 0, 0} 187 {0, 0, 0, 0}
188 }; 188 };
189 189
190 if (argc < 2) 190 if (argc < 2)
191 return ERROR; 191 return ERROR;
192 192
193 while (1) { 193 while (1) {
194 c = getopt_long (argc, argv, "hVvt:l:H:w:c:T:a:", longopts, &option); 194 c = getopt_long (argc, argv, "hVvt:l:H:w:c:T:a:", longopts, &option);
195 195
196 if (c == -1 || c == EOF) 196 if (c == -1 || c == EOF)
197 break; 197 break;
198 198
199 switch (c) { 199 switch (c) {
200 case 'h': /* help */ 200 case 'h': /* help */
201 print_help (); 201 print_help ();
202 exit (STATE_OK); 202 exit (STATE_OK);
203 case 'V': /* version */ 203 case 'V': /* version */
204 print_revision (progname, revision); 204 print_revision (progname, revision);
205 exit (STATE_OK); 205 exit (STATE_OK);
206 case 'H': /* hostname */ 206 case 'H': /* hostname */
207 host_or_die(optarg); 207 host_or_die(optarg);
208 dns_server = optarg; 208 dns_server = optarg;
209 break; 209 break;
210 case 'p': /* server port */ 210 case 'p': /* server port */
211 if (is_intpos (optarg)) { 211 if (is_intpos (optarg)) {
212 server_port = atoi (optarg); 212 server_port = atoi (optarg);
213 } 213 }
214 else { 214 else {
215 usage_va(_("Port must be a positive integer - %s"), optarg); 215 usage_va(_("Port must be a positive integer - %s"), optarg);
216 } 216 }
217 break; 217 break;
218 case 'l': /* address to lookup */ 218 case 'l': /* address to lookup */
219 query_address = optarg; 219 query_address = optarg;
220 break; 220 break;
221 case 'w': /* warning */ 221 case 'w': /* warning */
222 if (is_nonnegative (optarg)) { 222 if (is_nonnegative (optarg)) {
223 warning_interval = strtod (optarg, NULL); 223 warning_interval = strtod (optarg, NULL);
224 } 224 }
225 else { 225 else {
226 usage_va(_("Warning interval must be a positive integer - %s"), optarg); 226 usage_va(_("Warning interval must be a positive integer - %s"), optarg);
227 } 227 }
228 break; 228 break;
229 case 'c': /* critical */ 229 case 'c': /* critical */
230 if (is_nonnegative (optarg)) { 230 if (is_nonnegative (optarg)) {
231 critical_interval = strtod (optarg, NULL); 231 critical_interval = strtod (optarg, NULL);
232 } 232 }
233 else { 233 else {
234 usage_va(_("Critical interval must be a positive integer - %s"), optarg); 234 usage_va(_("Critical interval must be a positive integer - %s"), optarg);
235 } 235 }
236 break; 236 break;
237 case 't': /* timeout */ 237 case 't': /* timeout */
238 if (is_intnonneg (optarg)) { 238 if (is_intnonneg (optarg)) {
239 timeout_interval = atoi (optarg); 239 timeout_interval = atoi (optarg);
240 } 240 }
241 else { 241 else {
242 usage_va(_("Timeout interval must be a positive integer - %s"), optarg); 242 usage_va(_("Timeout interval must be a positive integer - %s"), optarg);
243 } 243 }
244 break; 244 break;
245 case 'v': /* verbose */ 245 case 'v': /* verbose */
246 verbose = TRUE; 246 verbose = TRUE;
247 break; 247 break;
248 case 'T': 248 case 'T':
249 record_type = optarg; 249 record_type = optarg;
250 break; 250 break;
251 case 'a': 251 case 'a':
252 expected_address = optarg; 252 expected_address = optarg;
253 break; 253 break;
254 default: /* usage_va */ 254 default: /* usage_va */
255 usage_va(_("Unknown argument - %s"), optarg); 255 usage_va(_("Unknown argument - %s"), optarg);
256 } 256 }
257 } 257 }
258 258
259 c = optind; 259 c = optind;
260 if (dns_server == NULL) { 260 if (dns_server == NULL) {
261 if (c < argc) { 261 if (c < argc) {
262 host_or_die(argv[c]); 262 host_or_die(argv[c]);
263 dns_server = argv[c]; 263 dns_server = argv[c];
264 } 264 }
265 else { 265 else {
266 dns_server = strdup ("127.0.0.1"); 266 dns_server = strdup ("127.0.0.1");
267 } 267 }
268 } 268 }
269 269
270 return validate_arguments (); 270 return validate_arguments ();
271} 271}
272 272
273 273
@@ -275,7 +275,7 @@ process_arguments (int argc, char **argv)
275int 275int
276validate_arguments (void) 276validate_arguments (void)
277{ 277{
278 return OK; 278 return OK;
279} 279}
280 280
281 281
@@ -283,43 +283,56 @@ validate_arguments (void)
283void 283void
284print_help (void) 284print_help (void)
285{ 285{
286 char *myport; 286 char *myport;
287 287
288 asprintf (&myport, "%d", DEFAULT_PORT); 288 asprintf (&myport, "%d", DEFAULT_PORT);
289 289
290 print_revision (progname, revision); 290 print_revision (progname, revision);
291 291
292 printf ("Copyright (c) 2000 Karl DeBisschop <kdebisschop@users.sourceforge.net>\n"); 292 printf ("Copyright (c) 2000 Karl DeBisschop <kdebisschop@users.sourceforge.net>\n");
293 printf (COPYRIGHT, copyright, email); 293 printf (COPYRIGHT, copyright, email);
294 294
295 printf (_("Test the DNS service on the specified host using dig\n\n")); 295 printf (_("This plugin test the DNS service on the specified host using dig"));
296 296
297 print_usage (); 297 printf ("\n\n");
298 298
299 printf (_(UT_HELP_VRSN)); 299 print_usage ();
300 300
301 printf (_(UT_HOST_PORT), 'P', myport); 301 printf (_(UT_HELP_VRSN));
302 302
303 printf (_("\ 303 printf (_(UT_HOST_PORT), 'P', myport);
304 -l, --lookup=STRING\n\
305 machine name to lookup\n"));
306 304
307 printf (_("\ 305 printf ("-l, --lookup=STRING");
308 -T, --record_type=STRING\n\ 306
309 record type to lookup (default: A)\n")); 307 printf ("\n");
310 308
311 printf (_("\ 309 printf (_("machine name to lookup"));
312 -a, --expected_address=STRING\n\
313 an address expected to be in the answer section.\n\
314 if not set, uses whatever was in -l\n"));
315 310
316 printf (_(UT_WARN_CRIT)); 311 printf ("\n");
317 312
318 printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); 313 printf ("-T, --record_type=STRING");
319 314
320 printf (_(UT_VERBOSE)); 315 printf ("\n");
321 316
322 printf (_(UT_SUPPORT)); 317 printf (_("record type to lookup (default: A)"));
318
319 printf ("\n");
320
321 printf ("-a, --expected_address=STRING");
322
323 printf ("\n");
324
325 printf (_("an address expected to be in the answer section.if not set, uses whatever was in -l"));
326
327 printf ("\n");
328
329 printf (_(UT_WARN_CRIT));
330
331 printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
332
333 printf (_(UT_VERBOSE));
334
335 printf (_(UT_SUPPORT));
323} 336}
324 337
325 338
@@ -327,8 +340,8 @@ print_help (void)
327void 340void
328print_usage (void) 341print_usage (void)
329{ 342{
330 printf ("\ 343 printf (_("Usage:"));
331Usage: %s -H host -l lookup [-p <server port>] [-T <query type>]\n\ 344 printf ("%s -H host -l lookup [-p <server port>] [-T <query type>]", progname);
332 [-w <warning interval>] [-c <critical interval>] [-t <timeout>]\n\ 345 printf (" [-w <warning interval>] [-c <critical interval>] [-t <timeout>]");
333 [-a <expected answer address>] [-v]\n", progname); 346 printf (" [-a <expected answer address>] [-v]\n");
334} 347}
diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index 81dd6c73..3a5f4761 100644
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
@@ -19,9 +19,9 @@
19*****************************************************************************/ 19*****************************************************************************/
20 20
21const char *progname = "check_disk"; 21const char *progname = "check_disk";
22const char *program_name = "check_disk"; /* Required for coreutils libs */ 22const char *program_name = "check_disk"; /* Required for coreutils libs */
23const char *revision = "$Revision$"; 23const char *revision = "$Revision$";
24const char *copyright = "1999-2004"; 24const char *copyright = "1999-2005";
25const char *email = "nagiosplug-devel@lists.sourceforge.net"; 25const char *email = "nagiosplug-devel@lists.sourceforge.net";
26 26
27 /* 27 /*
@@ -149,92 +149,92 @@ static struct mount_entry *mount_list;
149int 149int
150main (int argc, char **argv) 150main (int argc, char **argv)
151{ 151{
152 double usp = -1.0, uisp = -1.0; 152 double usp = -1.0, uisp = -1.0;
153 int result = STATE_UNKNOWN; 153 int result = STATE_UNKNOWN;
154 int disk_result = STATE_UNKNOWN; 154 int disk_result = STATE_UNKNOWN;
155 char file_system[MAX_INPUT_BUFFER]; 155 char file_system[MAX_INPUT_BUFFER];
156 char *output; 156 char *output;
157 char *details; 157 char *details;
158 char *perf; 158 char *perf;
159 uintmax_t psize; 159 uintmax_t psize;
160 float free_space, free_space_pct, total_space, inode_space_pct; 160 float free_space, free_space_pct, total_space, inode_space_pct;
161 161
162 struct mount_entry *me; 162 struct mount_entry *me;
163 struct fs_usage fsp; 163 struct fs_usage fsp;
164 struct name_list *temp_list; 164 struct name_list *temp_list;
165 165
166 output = strdup (" - free space:"); 166 output = strdup (" - free space:");
167 details = strdup (""); 167 details = strdup ("");
168 perf = strdup (""); 168 perf = strdup ("");
169 169
170 setlocale (LC_ALL, ""); 170 setlocale (LC_ALL, "");
171 bindtextdomain (PACKAGE, LOCALEDIR); 171 bindtextdomain (PACKAGE, LOCALEDIR);
172 textdomain (PACKAGE); 172 textdomain (PACKAGE);
173 173
174 mount_list = read_filesystem_list (0); 174 mount_list = read_filesystem_list (0);
175 175
176 if (process_arguments (argc, argv) == ERROR) 176 if (process_arguments (argc, argv) == ERROR)
177 usage4 (_("Could not parse arguments")); 177 usage4 (_("Could not parse arguments"));
178 178
179 /* if a list of paths has been selected, preseed the list with 179 /* if a list of paths has been selected, preseed the list with
180 * the longest matching filesystem name by iterating across 180 * the longest matching filesystem name by iterating across
181 * the mountlist once ahead of time. this will allow a query on 181 * the mountlist once ahead of time. this will allow a query on
182 * "/var/log" to return information about "/var" if no "/var/log" 182 * "/var/log" to return information about "/var" if no "/var/log"
183 * filesystem exists, etc. this is the default behavior already 183 * filesystem exists, etc. this is the default behavior already
184 * with df-based checks, but for systems with their own space 184 * with df-based checks, but for systems with their own space
185 * checking routines, this should make them more consistent. 185 * checking routines, this should make them more consistent.
186 */ 186 */
187 if(path_select_list){ 187 if(path_select_list){
188 for (me = mount_list; me; me = me->me_next) { 188 for (me = mount_list; me; me = me->me_next) {
189 walk_name_list(path_select_list, me->me_mountdir); 189 walk_name_list(path_select_list, me->me_mountdir);
190 walk_name_list(path_select_list, me->me_devname); 190 walk_name_list(path_select_list, me->me_devname);
191 } 191 }
192 /* now pretend we never saw anything, but keep found_len. 192 /* now pretend we never saw anything, but keep found_len.
193 * thus future searches will only match the best match */ 193 * thus future searches will only match the best match */
194 for (temp_list = path_select_list; temp_list; temp_list=temp_list->name_next){ 194 for (temp_list = path_select_list; temp_list; temp_list=temp_list->name_next){
195 temp_list->found=0; 195 temp_list->found=0;
196 } 196 }
197 } 197 }
198 198
199 /* for every mount entry */ 199 /* for every mount entry */
200 for (me = mount_list; me; me = me->me_next) { 200 for (me = mount_list; me; me = me->me_next) {
201 /* if there's a list of paths to select, the current mount 201 /* if there's a list of paths to select, the current mount
202 * entry matches in path or device name, get fs usage */ 202 * entry matches in path or device name, get fs usage */
203 if (path_select_list && 203 if (path_select_list &&
204 (walk_name_list (path_select_list, me->me_mountdir) || 204 (walk_name_list (path_select_list, me->me_mountdir) ||
205 walk_name_list (path_select_list, me->me_devname) ) ) { 205 walk_name_list (path_select_list, me->me_devname) ) ) {
206 get_fs_usage (me->me_mountdir, me->me_devname, &fsp); 206 get_fs_usage (me->me_mountdir, me->me_devname, &fsp);
207 /* else if there's a list of paths/devices to select (but 207 /* else if there's a list of paths/devices to select (but
208 * we didn't match above) skip to the next mount entry */ 208 * we didn't match above) skip to the next mount entry */
209 } else if (dev_select_list || path_select_list) { 209 } else if (dev_select_list || path_select_list) {
210 continue; 210 continue;
211 /* skip remote filesystems if we're not interested in them */ 211 /* skip remote filesystems if we're not interested in them */
212 } else if (me->me_remote && show_local_fs) { 212 } else if (me->me_remote && show_local_fs) {
213 continue; 213 continue;
214 /* skip pseudo fs's if we haven't asked for all fs's */ 214 /* skip pseudo fs's if we haven't asked for all fs's */
215 } else if (me->me_dummy && !show_all_fs) { 215 } else if (me->me_dummy && !show_all_fs) {
216 continue; 216 continue;
217 /* skip excluded fstypes */ 217 /* skip excluded fstypes */
218 } else if (fs_exclude_list && walk_name_list (fs_exclude_list, me->me_type)) { 218 } else if (fs_exclude_list && walk_name_list (fs_exclude_list, me->me_type)) {
219 continue; 219 continue;
220 /* skip excluded fs's */ 220 /* skip excluded fs's */
221 } else if (dp_exclude_list && 221 } else if (dp_exclude_list &&
222 (walk_name_list (dp_exclude_list, me->me_devname) || 222 (walk_name_list (dp_exclude_list, me->me_devname) ||
223 walk_name_list (dp_exclude_list, me->me_mountdir))) { 223 walk_name_list (dp_exclude_list, me->me_mountdir))) {
224 continue; 224 continue;
225 /* otherwise, get fs usage */ 225 /* otherwise, get fs usage */
226 } else { 226 } else {
227 get_fs_usage (me->me_mountdir, me->me_devname, &fsp); 227 get_fs_usage (me->me_mountdir, me->me_devname, &fsp);
228 } 228 }
229 229
230 if (fsp.fsu_blocks && strcmp ("none", me->me_mountdir)) { 230 if (fsp.fsu_blocks && strcmp ("none", me->me_mountdir)) {
231 usp = (double)(fsp.fsu_blocks - fsp.fsu_bavail) * 100 / fsp.fsu_blocks; 231 usp = (double)(fsp.fsu_blocks - fsp.fsu_bavail) * 100 / fsp.fsu_blocks;
232 uisp = (double)(fsp.fsu_files - fsp.fsu_ffree) * 100 / fsp.fsu_files; 232 uisp = (double)(fsp.fsu_files - fsp.fsu_ffree) * 100 / fsp.fsu_files;
233 disk_result = check_disk (usp, fsp.fsu_bavail, uisp); 233 disk_result = check_disk (usp, fsp.fsu_bavail, uisp);
234 234
235 235
236 result = max_state (disk_result, result); 236 result = max_state (disk_result, result);
237 psize = fsp.fsu_blocks*fsp.fsu_blocksize/mult; 237 psize = fsp.fsu_blocks*fsp.fsu_blocksize/mult;
238 238
239 239
240 /* Moved this computation up here so we can add it 240 /* Moved this computation up here so we can add it
@@ -242,56 +242,56 @@ main (int argc, char **argv)
242 inode_space_pct = (float)fsp.fsu_ffree*100/fsp.fsu_files; 242 inode_space_pct = (float)fsp.fsu_ffree*100/fsp.fsu_files;
243 243
244 244
245 asprintf (&perf, "%s %s", perf, 245 asprintf (&perf, "%s %s", perf,
246 perfdata ((!strcmp(file_system, "none") || display_mntp) ? me->me_devname : me->me_mountdir, 246 perfdata ((!strcmp(file_system, "none") || display_mntp) ? me->me_devname : me->me_mountdir,
247 psize-(fsp.fsu_bavail*fsp.fsu_blocksize/mult), units, 247 psize-(fsp.fsu_bavail*fsp.fsu_blocksize/mult), units,
248 TRUE, min ((uintmax_t)psize-(uintmax_t)w_df, (uintmax_t)((1.0-w_dfp/100.0)*psize)), 248 TRUE, min ((uintmax_t)psize-(uintmax_t)w_df, (uintmax_t)((1.0-w_dfp/100.0)*psize)),
249 TRUE, min ((uintmax_t)psize-(uintmax_t)c_df, (uintmax_t)((1.0-c_dfp/100.0)*psize)), 249 TRUE, min ((uintmax_t)psize-(uintmax_t)c_df, (uintmax_t)((1.0-c_dfp/100.0)*psize)),
250 TRUE, inode_space_pct, 250 TRUE, inode_space_pct,
251 251
252 TRUE, psize)); 252 TRUE, psize));
253 if (disk_result==STATE_OK && erronly && !verbose) 253 if (disk_result==STATE_OK && erronly && !verbose)
254 continue; 254 continue;
255 255
256 free_space = (float)fsp.fsu_bavail*fsp.fsu_blocksize/mult; 256 free_space = (float)fsp.fsu_bavail*fsp.fsu_blocksize/mult;
257 free_space_pct = (float)fsp.fsu_bavail*100/fsp.fsu_blocks; 257 free_space_pct = (float)fsp.fsu_bavail*100/fsp.fsu_blocks;
258 total_space = (float)fsp.fsu_blocks*fsp.fsu_blocksize/mult; 258 total_space = (float)fsp.fsu_blocks*fsp.fsu_blocksize/mult;
259 if (disk_result!=STATE_OK || verbose>=0) 259 if (disk_result!=STATE_OK || verbose>=0)
260 asprintf (&output, ("%s %s %.0f %s (%.0f%% inode=%.0f%%);"), 260 asprintf (&output, ("%s %s %.0f %s (%.0f%% inode=%.0f%%);"),
261 output, 261 output,
262 (!strcmp(file_system, "none") || display_mntp) ? me->me_devname : me->me_mountdir, 262 (!strcmp(file_system, "none") || display_mntp) ? me->me_devname : me->me_mountdir,
263 free_space, 263 free_space,
264 units, 264 units,
265 free_space_pct, 265 free_space_pct,
266 inode_space_pct); 266 inode_space_pct);
267 267
268 asprintf (&details, _("%s\n\ 268 asprintf (&details, _("%s\n\
269%.0f of %.0f %s (%.0f%% inode=%.0f%%) free on %s (type %s mounted on %s) warn:%lu crit:%lu warn%%:%.0f%% crit%%:%.0f%%"), 269%.0f of %.0f %s (%.0f%% inode=%.0f%%) free on %s (type %s mounted on %s) warn:%lu crit:%lu warn%%:%.0f%% crit%%:%.0f%%"),
270 details, free_space, total_space, units, free_space_pct, inode_space_pct, 270 details, free_space, total_space, units, free_space_pct, inode_space_pct,
271 me->me_devname, me->me_type, me->me_mountdir, 271 me->me_devname, me->me_type, me->me_mountdir,
272 (unsigned long)w_df, (unsigned long)c_df, w_dfp, c_dfp); 272 (unsigned long)w_df, (unsigned long)c_df, w_dfp, c_dfp);
273 273
274 } 274 }
275 275
276 } 276 }
277 277
278 asprintf (&output, "%s|%s", output, perf); 278 asprintf (&output, "%s|%s", output, perf);
279 279
280 if (verbose > 2) 280 if (verbose > 2)
281 asprintf (&output, "%s%s", output, details); 281 asprintf (&output, "%s%s", output, details);
282 282
283 /* Override result if paths specified and not found */ 283 /* Override result if paths specified and not found */
284 temp_list = path_select_list; 284 temp_list = path_select_list;
285 while (temp_list) { 285 while (temp_list) {
286 if (!temp_list->found) { 286 if (!temp_list->found) {
287 asprintf (&output, _("%s [%s not found]"), output, temp_list->name); 287 asprintf (&output, _("%s [%s not found]"), output, temp_list->name);
288 result = STATE_CRITICAL; 288 result = STATE_CRITICAL;
289 } 289 }
290 temp_list = temp_list->name_next; 290 temp_list = temp_list->name_next;
291 } 291 }
292 292
293 printf ("DISK %s%s\n", state_text (result), output); 293 printf ("DISK %s%s\n", state_text (result), output);
294 return result; 294 return result;
295} 295}
296 296
297 297
@@ -300,106 +300,106 @@ main (int argc, char **argv)
300int 300int
301process_arguments (int argc, char **argv) 301process_arguments (int argc, char **argv)
302{ 302{
303 int c; 303 int c;
304 struct name_list *se; 304 struct name_list *se;
305 struct name_list **pathtail = &path_select_list; 305 struct name_list **pathtail = &path_select_list;
306 struct name_list **fstail = &fs_exclude_list; 306 struct name_list **fstail = &fs_exclude_list;
307 struct name_list **dptail = &dp_exclude_list; 307 struct name_list **dptail = &dp_exclude_list;
308 struct name_list *temp_list; 308 struct name_list *temp_list;
309 int result = OK; 309 int result = OK;
310 310
311 unsigned long l; 311 unsigned long l;
312 312
313 int option = 0; 313 int option = 0;
314 static struct option longopts[] = { 314 static struct option longopts[] = {
315 {"timeout", required_argument, 0, 't'}, 315 {"timeout", required_argument, 0, 't'},
316 {"warning", required_argument, 0, 'w'}, 316 {"warning", required_argument, 0, 'w'},
317 {"critical", required_argument, 0, 'c'}, 317 {"critical", required_argument, 0, 'c'},
318 {"iwarning", required_argument, 0, 'W'}, 318 {"iwarning", required_argument, 0, 'W'},
319 /* Dang, -C is taken. We might want to reshuffle this. */ 319 /* Dang, -C is taken. We might want to reshuffle this. */
320 {"icritical", required_argument, 0, 'K'}, 320 {"icritical", required_argument, 0, 'K'},
321 {"local", required_argument, 0, 'l'}, 321 {"local", required_argument, 0, 'l'},
322 {"kilobytes", required_argument, 0, 'k'}, 322 {"kilobytes", required_argument, 0, 'k'},
323 {"megabytes", required_argument, 0, 'm'}, 323 {"megabytes", required_argument, 0, 'm'},
324 {"units", required_argument, 0, 'u'}, 324 {"units", required_argument, 0, 'u'},
325 {"path", required_argument, 0, 'p'}, 325 {"path", required_argument, 0, 'p'},
326 {"partition", required_argument, 0, 'p'}, 326 {"partition", required_argument, 0, 'p'},
327 {"exclude_device", required_argument, 0, 'x'}, 327 {"exclude_device", required_argument, 0, 'x'},
328 {"exclude-type", required_argument, 0, 'X'}, 328 {"exclude-type", required_argument, 0, 'X'},
329 {"mountpoint", no_argument, 0, 'M'}, 329 {"mountpoint", no_argument, 0, 'M'},
330 {"errors-only", no_argument, 0, 'e'}, 330 {"errors-only", no_argument, 0, 'e'},
331 {"verbose", no_argument, 0, 'v'}, 331 {"verbose", no_argument, 0, 'v'},
332 {"quiet", no_argument, 0, 'q'}, 332 {"quiet", no_argument, 0, 'q'},
333 {"clear", no_argument, 0, 'C'}, 333 {"clear", no_argument, 0, 'C'},
334 {"version", no_argument, 0, 'V'}, 334 {"version", no_argument, 0, 'V'},
335 {"help", no_argument, 0, 'h'}, 335 {"help", no_argument, 0, 'h'},
336 {0, 0, 0, 0} 336 {0, 0, 0, 0}
337 }; 337 };
338 338
339 if (argc < 2) 339 if (argc < 2)
340 return ERROR; 340 return ERROR;
341 341
342 se = (struct name_list *) malloc (sizeof (struct name_list)); 342 se = (struct name_list *) malloc (sizeof (struct name_list));
343 se->name = strdup ("iso9660"); 343 se->name = strdup ("iso9660");
344 se->name_next = NULL; 344 se->name_next = NULL;
345 se->found = 0; 345 se->found = 0;
346 se->found_len = 0; 346 se->found_len = 0;
347 *fstail = se; 347 *fstail = se;
348 fstail = &se->name_next; 348 fstail = &se->name_next;
349 349
350 for (c = 1; c < argc; c++) 350 for (c = 1; c < argc; c++)
351 if (strcmp ("-to", argv[c]) == 0) 351 if (strcmp ("-to", argv[c]) == 0)
352 strcpy (argv[c], "-t"); 352 strcpy (argv[c], "-t");
353 353
354 while (1) { 354 while (1) {
355 c = getopt_long (argc, argv, "+?VqhveCt:c:w:K:W:u:p:x:X:mklM", longopts, &option); 355 c = getopt_long (argc, argv, "+?VqhveCt:c:w:K:W:u:p:x:X:mklM", longopts, &option);
356 356
357 if (c == -1 || c == EOF) 357 if (c == -1 || c == EOF)
358 break; 358 break;
359 359
360 switch (c) { 360 switch (c) {
361 case 't': /* timeout period */ 361 case 't': /* timeout period */
362 if (is_integer (optarg)) { 362 if (is_integer (optarg)) {
363 timeout_interval = atoi (optarg); 363 timeout_interval = atoi (optarg);
364 break; 364 break;
365 } 365 }
366 else { 366 else {
367 usage2 (_("Timeout interval must be a positive integer"), optarg); 367 usage2 (_("Timeout interval must be a positive integer"), optarg);
368 } 368 }
369 case 'w': /* warning threshold */ 369 case 'w': /* warning threshold */
370 if (is_intnonneg (optarg)) { 370 if (is_intnonneg (optarg)) {
371 w_df = atoi (optarg); 371 w_df = atoi (optarg);
372 break; 372 break;
373 } 373 }
374 else if (strpbrk (optarg, ",:") && 374 else if (strpbrk (optarg, ",:") &&
375 strstr (optarg, "%") && 375 strstr (optarg, "%") &&
376 sscanf (optarg, "%lu%*[:,]%lf%%", &l, &w_dfp) == 2) { 376 sscanf (optarg, "%lu%*[:,]%lf%%", &l, &w_dfp) == 2) {
377 w_df = (uintmax_t)l; 377 w_df = (uintmax_t)l;
378 break; 378 break;
379 } 379 }
380 else if (strstr (optarg, "%") && sscanf (optarg, "%lf%%", &w_dfp) == 1) { 380 else if (strstr (optarg, "%") && sscanf (optarg, "%lf%%", &w_dfp) == 1) {
381 break; 381 break;
382 } 382 }
383 else { 383 else {
384 usage4 (_("Warning threshold must be integer or percentage!")); 384 usage4 (_("Warning threshold must be integer or percentage!"));
385 } 385 }
386 case 'c': /* critical threshold */ 386 case 'c': /* critical threshold */
387 if (is_intnonneg (optarg)) { 387 if (is_intnonneg (optarg)) {
388 c_df = atoi (optarg); 388 c_df = atoi (optarg);
389 break; 389 break;
390 } 390 }
391 else if (strpbrk (optarg, ",:") && 391 else if (strpbrk (optarg, ",:") &&
392 strstr (optarg, "%") && 392 strstr (optarg, "%") &&
393 sscanf (optarg, "%lu%*[,:]%lf%%", &l, &c_dfp) == 2) { 393 sscanf (optarg, "%lu%*[,:]%lf%%", &l, &c_dfp) == 2) {
394 c_df = (uintmax_t)l; 394 c_df = (uintmax_t)l;
395 break; 395 break;
396 } 396 }
397 else if (strstr (optarg, "%") && sscanf (optarg, "%lf%%", &c_dfp) == 1) { 397 else if (strstr (optarg, "%") && sscanf (optarg, "%lf%%", &c_dfp) == 1) {
398 break; 398 break;
399 } 399 }
400 else { 400 else {
401 usage4 (_("Critical threshold must be integer or percentage!")); 401 usage4 (_("Critical threshold must be integer or percentage!"));
402 } 402 }
403 403
404 404
405 case 'W': /* warning inode threshold */ 405 case 'W': /* warning inode threshold */
@@ -407,71 +407,71 @@ process_arguments (int argc, char **argv)
407 break; 407 break;
408 } 408 }
409 else { 409 else {
410 usage (_("Warning inode threshold must be percentage!\n")); 410 usage (_("Warning inode threshold must be percentage!\n"));
411 } 411 }
412 case 'K': /* kritical inode threshold */ 412 case 'K': /* kritical inode threshold */
413 if (strstr (optarg, "%") && sscanf (optarg, "%lf%%", &c_idfp) == 1) { 413 if (strstr (optarg, "%") && sscanf (optarg, "%lf%%", &c_idfp) == 1) {
414 break; 414 break;
415 } 415 }
416 else { 416 else {
417 usage (_("Critical inode threshold must be percentage!\n")); 417 usage (_("Critical inode threshold must be percentage!\n"));
418 } 418 }
419 case 'u': 419 case 'u':
420 if (units) 420 if (units)
421 free(units); 421 free(units);
422 if (! strcmp (optarg, "bytes")) { 422 if (! strcmp (optarg, "bytes")) {
423 mult = (uintmax_t)1; 423 mult = (uintmax_t)1;
424 units = strdup ("B"); 424 units = strdup ("B");
425 } else if (! strcmp (optarg, "kB")) { 425 } else if (! strcmp (optarg, "kB")) {
426 mult = (uintmax_t)1024; 426 mult = (uintmax_t)1024;
427 units = strdup ("kB"); 427 units = strdup ("kB");
428 } else if (! strcmp (optarg, "MB")) { 428 } else if (! strcmp (optarg, "MB")) {
429 mult = (uintmax_t)1024 * 1024; 429 mult = (uintmax_t)1024 * 1024;
430 units = strdup ("MB"); 430 units = strdup ("MB");
431 } else if (! strcmp (optarg, "GB")) { 431 } else if (! strcmp (optarg, "GB")) {
432 mult = (uintmax_t)1024 * 1024 * 1024; 432 mult = (uintmax_t)1024 * 1024 * 1024;
433 units = strdup ("GB"); 433 units = strdup ("GB");
434 } else if (! strcmp (optarg, "TB")) { 434 } else if (! strcmp (optarg, "TB")) {
435 mult = (uintmax_t)1024 * 1024 * 1024 * 1024; 435 mult = (uintmax_t)1024 * 1024 * 1024 * 1024;
436 units = strdup ("TB"); 436 units = strdup ("TB");
437 } else { 437 } else {
438 die (STATE_UNKNOWN, _("unit type %s not known\n"), optarg); 438 die (STATE_UNKNOWN, _("unit type %s not known\n"), optarg);
439 } 439 }
440 if (units == NULL) 440 if (units == NULL)
441 die (STATE_UNKNOWN, _("failed allocating storage for '%s'\n"), "units"); 441 die (STATE_UNKNOWN, _("failed allocating storage for '%s'\n"), "units");
442 break; 442 break;
443 case 'k': /* display mountpoint */ 443 case 'k': /* display mountpoint */
444 mult = 1024; 444 mult = 1024;
445 if (units) 445 if (units)
446 free(units); 446 free(units);
447 units = strdup ("kB"); 447 units = strdup ("kB");
448 break; 448 break;
449 case 'm': /* display mountpoint */ 449 case 'm': /* display mountpoint */
450 mult = 1024 * 1024; 450 mult = 1024 * 1024;
451 if (units) 451 if (units)
452 free(units); 452 free(units);
453 units = strdup ("MB"); 453 units = strdup ("MB");
454 break; 454 break;
455 case 'l': 455 case 'l':
456 show_local_fs = 1; 456 show_local_fs = 1;
457 break; 457 break;
458 case 'p': /* select path */ 458 case 'p': /* select path */
459 se = (struct name_list *) malloc (sizeof (struct name_list)); 459 se = (struct name_list *) malloc (sizeof (struct name_list));
460 se->name = optarg; 460 se->name = optarg;
461 se->name_next = NULL; 461 se->name_next = NULL;
462 se->w_df = w_df; 462 se->w_df = w_df;
463 se->c_df = c_df; 463 se->c_df = c_df;
464 se->w_dfp = w_dfp; 464 se->w_dfp = w_dfp;
465 se->c_dfp = c_dfp; 465 se->c_dfp = c_dfp;
466 se->found = 0; 466 se->found = 0;
467 se->found_len = 0; 467 se->found_len = 0;
468 *pathtail = se; 468 *pathtail = se;
469 pathtail = &se->name_next; 469 pathtail = &se->name_next;
470 break; 470 break;
471 case 'x': /* exclude path or partition */ 471 case 'x': /* exclude path or partition */
472 se = (struct name_list *) malloc (sizeof (struct name_list)); 472 se = (struct name_list *) malloc (sizeof (struct name_list));
473 se->name = optarg; 473 se->name = optarg;
474 se->name_next = NULL; 474 se->name_next = NULL;
475 475
476 /* If you don't clear the w_fd etc values here, they 476 /* If you don't clear the w_fd etc values here, they
477 * get processed when you walk the list and assigned 477 * get processed when you walk the list and assigned
@@ -481,15 +481,15 @@ process_arguments (int argc, char **argv)
481 se->c_df = 0; 481 se->c_df = 0;
482 se->w_dfp = 0; 482 se->w_dfp = 0;
483 se->c_dfp = 0; 483 se->c_dfp = 0;
484 se->found = 0; 484 se->found = 0;
485 se->found_len = 0; 485 se->found_len = 0;
486 *dptail = se; 486 *dptail = se;
487 dptail = &se->name_next; 487 dptail = &se->name_next;
488 break; 488 break;
489 case 'X': /* exclude file system type */ 489 case 'X': /* exclude file system type */
490 se = (struct name_list *) malloc (sizeof (struct name_list)); 490 se = (struct name_list *) malloc (sizeof (struct name_list));
491 se->name = optarg; 491 se->name = optarg;
492 se->name_next = NULL; 492 se->name_next = NULL;
493 /* If you don't clear the w_fd etc values here, they 493 /* If you don't clear the w_fd etc values here, they
494 * get processed when you walk the list and assigned 494 * get processed when you walk the list and assigned
495 * to the global w_df! 495 * to the global w_df!
@@ -498,78 +498,78 @@ process_arguments (int argc, char **argv)
498 se->c_df = 0; 498 se->c_df = 0;
499 se->w_dfp = 0; 499 se->w_dfp = 0;
500 se->c_dfp = 0; 500 se->c_dfp = 0;
501 se->found = 0; 501 se->found = 0;
502 se->found_len = 0; 502 se->found_len = 0;
503 *fstail = se; 503 *fstail = se;
504 fstail = &se->name_next; 504 fstail = &se->name_next;
505 break; 505 break;
506 case 'v': /* verbose */ 506 case 'v': /* verbose */
507 verbose++; 507 verbose++;
508 break; 508 break;
509 case 'q': /* verbose */ 509 case 'q': /* verbose */
510 verbose--; 510 verbose--;
511 break; 511 break;
512 case 'e': 512 case 'e':
513 erronly = TRUE; 513 erronly = TRUE;
514 break; 514 break;
515 case 'M': /* display mountpoint */ 515 case 'M': /* display mountpoint */
516 display_mntp = TRUE; 516 display_mntp = TRUE;
517 break; 517 break;
518 case 'C': 518 case 'C':
519 w_df = 0; 519 w_df = 0;
520 c_df = 0; 520 c_df = 0;
521 w_dfp = -1.0; 521 w_dfp = -1.0;
522 c_dfp = -1.0; 522 c_dfp = -1.0;
523 break; 523 break;
524 case 'V': /* version */ 524 case 'V': /* version */
525 print_revision (progname, revision); 525 print_revision (progname, revision);
526 exit (STATE_OK); 526 exit (STATE_OK);
527 case 'h': /* help */ 527 case 'h': /* help */
528 print_help (); 528 print_help ();
529 exit (STATE_OK); 529 exit (STATE_OK);
530 case '?': /* help */ 530 case '?': /* help */
531 usage2 (_("Unknown argument"), optarg); 531 usage (_("Unknown argument"));
532 } 532 }
533 } 533 }
534 534
535 /* Support for "check_disk warn crit [fs]" with thresholds at used level */ 535 /* Support for "check_disk warn crit [fs]" with thresholds at used level */
536 c = optind; 536 c = optind;
537 if (w_dfp < 0 && argc > c && is_intnonneg (argv[c])) 537 if (w_dfp < 0 && argc > c && is_intnonneg (argv[c]))
538 w_dfp = (100.0 - atof (argv[c++])); 538 w_dfp = (100.0 - atof (argv[c++]));
539 539
540 if (c_dfp < 0 && argc > c && is_intnonneg (argv[c])) 540 if (c_dfp < 0 && argc > c && is_intnonneg (argv[c]))
541 c_dfp = (100.0 - atof (argv[c++])); 541 c_dfp = (100.0 - atof (argv[c++]));
542 542
543 if (argc > c && path == NULL) { 543 if (argc > c && path == NULL) {
544 se = (struct name_list *) malloc (sizeof (struct name_list)); 544 se = (struct name_list *) malloc (sizeof (struct name_list));
545 se->name = strdup (argv[c++]); 545 se->name = strdup (argv[c++]);
546 se->name_next = NULL; 546 se->name_next = NULL;
547 se->w_df = w_df; 547 se->w_df = w_df;
548 se->c_df = c_df; 548 se->c_df = c_df;
549 se->w_dfp = w_dfp; 549 se->w_dfp = w_dfp;
550 se->c_dfp = c_dfp; 550 se->c_dfp = c_dfp;
551 se->found =0; 551 se->found =0;
552 se->found_len = 0; 552 se->found_len = 0;
553 *pathtail = se; 553 *pathtail = se;
554 } 554 }
555 555
556 if (path_select_list) { 556 if (path_select_list) {
557 temp_list = path_select_list; 557 temp_list = path_select_list;
558 while (temp_list) { 558 while (temp_list) {
559 if (validate_arguments (temp_list->w_df, 559 if (validate_arguments (temp_list->w_df,
560 temp_list->c_df, 560 temp_list->c_df,
561 temp_list->w_dfp, 561 temp_list->w_dfp,
562 temp_list->c_dfp, 562 temp_list->c_dfp,
563 temp_list->w_idfp, 563 temp_list->w_idfp,
564 temp_list->c_idfp, 564 temp_list->c_idfp,
565 temp_list->name) == ERROR) 565 temp_list->name) == ERROR)
566 result = ERROR; 566 result = ERROR;
567 temp_list = temp_list->name_next; 567 temp_list = temp_list->name_next;
568 } 568 }
569 return result; 569 return result;
570 } else { 570 } else {
571 return validate_arguments (w_df, c_df, w_dfp, c_dfp, w_idfp, c_idfp, NULL); 571 return validate_arguments (w_df, c_df, w_dfp, c_dfp, w_idfp, c_idfp, NULL);
572 } 572 }
573} 573}
574 574
575 575
@@ -577,12 +577,12 @@ process_arguments (int argc, char **argv)
577void 577void
578print_path (const char *mypath) 578print_path (const char *mypath)
579{ 579{
580 if (mypath == NULL) 580 if (mypath == NULL)
581 printf ("\n"); 581 printf ("\n");
582 else 582 else
583 printf (_(" for %s\n"), mypath); 583 printf (_(" for %s\n"), mypath);
584 584
585 return; 585 return;
586} 586}
587 587
588 588
@@ -590,40 +590,40 @@ print_path (const char *mypath)
590int 590int
591validate_arguments (uintmax_t w, uintmax_t c, double wp, double cp, double iwp, double icp, char *mypath) 591validate_arguments (uintmax_t w, uintmax_t c, double wp, double cp, double iwp, double icp, char *mypath)
592{ 592{
593 if (w < 0 && c < 0 && wp < 0.0 && cp < 0.0) { 593 if (w < 0 && c < 0 && wp < 0.0 && cp < 0.0) {
594 printf (_("INPUT ERROR: No thresholds specified")); 594 printf (_("INPUT ERROR: No thresholds specified"));
595 print_path (mypath); 595 print_path (mypath);
596 return ERROR; 596 return ERROR;
597 } 597 }
598 else if ((wp >= 0.0 || cp >= 0.0) && 598 else if ((wp >= 0.0 || cp >= 0.0) &&
599 (wp < 0.0 || cp < 0.0 || wp > 100.0 || cp > 100.0 || cp > wp)) { 599 (wp < 0.0 || cp < 0.0 || wp > 100.0 || cp > 100.0 || cp > wp)) {
600 printf (_("\ 600 printf (_("\
601INPUT ERROR: C_DFP (%f) should be less than W_DFP (%.1f) and both should be between zero and 100 percent, inclusive"), 601INPUT ERROR: C_DFP (%f) should be less than W_DFP (%.1f) and both should be between zero and 100 percent, inclusive"),
602 cp, wp); 602 cp, wp);
603 print_path (mypath); 603 print_path (mypath);
604 return ERROR; 604 return ERROR;
605 } 605 }
606 else if ((iwp >= 0.0 || icp >= 0.0) && 606 else if ((iwp >= 0.0 || icp >= 0.0) &&
607 (iwp < 0.0 || icp < 0.0 || iwp > 100.0 || icp > 100.0 || icp > iwp)) { 607 (iwp < 0.0 || icp < 0.0 || iwp > 100.0 || icp > 100.0 || icp > iwp)) {
608 printf (_("\ 608 printf (_("\
609INPUT ERROR: C_IDFP (%f) should be less than W_IDFP (%.1f) and both should be between zero and 100 percent, inclusive"), 609INPUT ERROR: C_IDFP (%f) should be less than W_IDFP (%.1f) and both should be between zero and 100 percent, inclusive"),
610 icp, iwp); 610 icp, iwp);
611 print_path (mypath); 611 print_path (mypath);
612 return ERROR; 612 return ERROR;
613 } 613 }
614 else if ((w > 0 || c > 0) && (w == 0 || c == 0 || c > w)) { 614 else if ((w > 0 || c > 0) && (w == 0 || c == 0 || c > w)) {
615 printf (_("\ 615 printf (_("\
616INPUT ERROR: C_DF (%lu) should be less than W_DF (%lu) and both should be greater than zero"), 616INPUT ERROR: C_DF (%lu) should be less than W_DF (%lu) and both should be greater than zero"),
617 (unsigned long)c, (unsigned long)w); 617 (unsigned long)c, (unsigned long)w);
618 print_path (mypath); 618 print_path (mypath);
619 return ERROR; 619 return ERROR;
620 } 620 }
621 621
622 if (units == NULL) { 622 if (units == NULL) {
623 units = strdup ("MB"); 623 units = strdup ("MB");
624 mult = (uintmax_t)1024 * 1024; 624 mult = (uintmax_t)1024 * 1024;
625 } 625 }
626 return OK; 626 return OK;
627} 627}
628 628
629 629
@@ -647,8 +647,8 @@ check_disk (double usp, uintmax_t free_disk, double uisp)
647 else if (w_df > 0 && free_disk <= w_df) 647 else if (w_df > 0 && free_disk <= w_df)
648 result = STATE_WARNING; 648 result = STATE_WARNING;
649 else if (usp >= 0.0) 649 else if (usp >= 0.0)
650 result = STATE_OK; 650 result = STATE_OK;
651 return result; 651 return result;
652} 652}
653 653
654 654
@@ -656,26 +656,26 @@ check_disk (double usp, uintmax_t free_disk, double uisp)
656int 656int
657walk_name_list (struct name_list *list, const char *name) 657walk_name_list (struct name_list *list, const char *name)
658{ 658{
659 int name_len; 659 int name_len;
660 name_len = strlen(name); 660 name_len = strlen(name);
661 while (list) { 661 while (list) {
662 /* if the paths match up to the length of the mount path, 662 /* if the paths match up to the length of the mount path,
663 * AND if the mount path name is longer than the longest 663 * AND if the mount path name is longer than the longest
664 * found match, we have a new winner */ 664 * found match, we have a new winner */
665 if (name_len >= list->found_len && 665 if (name_len >= list->found_len &&
666 ! strncmp(list->name, name, name_len)) { 666 ! strncmp(list->name, name, name_len)) {
667 list->found = 1; 667 list->found = 1;
668 list->found_len = name_len; 668 list->found_len = name_len;
669 /* if required for name_lists that have not saved w_df, etc (eg exclude lists) */ 669 /* if required for name_lists that have not saved w_df, etc (eg exclude lists) */
670 if (list->w_df) w_df = list->w_df; 670 if (list->w_df) w_df = list->w_df;
671 if (list->c_df) c_df = list->c_df; 671 if (list->c_df) c_df = list->c_df;
672 if (list->w_dfp>=0.0) w_dfp = list->w_dfp; 672 if (list->w_dfp>=0.0) w_dfp = list->w_dfp;
673 if (list->c_dfp>=0.0) c_dfp = list->c_dfp; 673 if (list->c_dfp>=0.0) c_dfp = list->c_dfp;
674 return TRUE; 674 return TRUE;
675 } 675 }
676 list = list->name_next; 676 list = list->name_next;
677 } 677 }
678 return FALSE; 678 return FALSE;
679} 679}
680 680
681 681
@@ -683,68 +683,163 @@ walk_name_list (struct name_list *list, const char *name)
683void 683void
684print_help (void) 684print_help (void)
685{ 685{
686 print_revision (progname, revision); 686 print_revision (progname, revision);
687 687
688 printf ("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n"); 688 printf ("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n");
689 printf (COPYRIGHT, copyright, email); 689 printf (COPYRIGHT, copyright, email);
690 690
691 printf (_("\ 691 printf (_("This plugin checks the amount of used disk space on a mounted file system"));
692This plugin checks the amount of used disk space on a mounted file system\n\ 692 printf (_("and generates an alert if free space is less than one of the threshold values"));
693and generates an alert if free space is less than one of the threshold values.\n\n")); 693
694 694 printf ("\n\n");
695 print_usage (); 695
696 696 print_usage ();
697 printf (_(UT_HELP_VRSN)); 697
698 698 printf (_(UT_HELP_VRSN));
699 printf (_("\ 699
700 -w, --warning=INTEGER\n\ 700 printf (" -w, --warning=INTEGER");
701 Exit with WARNING status if less than INTEGER --units of disk are free\n\ 701
702 -w, --warning=PERCENT%%\n\ 702 printf ("\n");
703 Exit with WARNING status if less than PERCENT of disk space is free\n\ 703
704 -W, --iwarning=PERCENT%%\n\ 704 printf (_("exit with WARNING status if less than INTEGER units of disk are free"));
705 Exit with WARNING status if less than PERCENT of inode space is free\n\ 705
706 -K, --icritical=PERCENT%%\n\ 706 printf (" -w, --warning=PERCENT%%");
707 Exit with CRITICAL status if less than PERCENT of inode space is free\n\ 707
708 -c, --critical=INTEGER\n\ 708 printf ("\n");
709 Exit with CRITICAL status if less than INTEGER --units of disk are free\n\ 709
710 -c, --critical=PERCENT%%\n\ 710 printf (_("exit with WARNING status if less than PERCENT of disk space is free"));
711 Exit with CRITCAL status if less than PERCENT of disk space is free\n\ 711
712 -C, --clear\n\ 712 printf ("\n");
713 Clear thresholds\n")); 713
714 714 printf (" -W, --iwarning=PERCENT%%");
715 printf (_("\ 715
716 -u, --units=STRING\n\ 716 printf ("\n");
717 Choose bytes, kB, MB, GB, TB (default: MB)\n\ 717
718 -k, --kilobytes\n\ 718 printf (_("exit with WARNING status if less than PERCENT of inode space is free"));
719 Same as '--units kB'\n\ 719
720 -m, --megabytes\n\ 720 printf ("\n");
721 Same as '--units MB'\n")); 721
722 722 printf (" -K, --icritical=PERCENT%%");
723 printf (_("\ 723
724 -l, --local\n\ 724 printf ("\n");
725 Only check local filesystems\n\ 725
726 -p, --path=PATH, --partition=PARTITION\n\ 726 printf (_("exit with CRITICAL status if less than PERCENT of inode space is free"));
727 Path or partition (may be repeated)\n\ 727
728 -x, --exclude_device=PATH <STRING>\n\ 728 printf ("\n");
729 Ignore device (only works if -p unspecified)\n\ 729
730 -X, --exclude-type=TYPE <STRING>\n\ 730 printf (" -c, --critical=INTEGER");
731 Ignore all filesystems of indicated type (may be repeated)\n\ 731
732 -M, --mountpoint\n\ 732 printf ("\n");
733 Display the mountpoint instead of the partition\n\ 733
734 -e, --errors-only\n\ 734 printf (_("exit with CRITICAL status if less than INTEGER --units of disk are free"));
735 Display only devices/mountpoints with errors\n")); 735
736 736 printf ("\n");
737 printf (_(UT_WARN_CRIT)); 737
738 738 printf (" -c, --critical=PERCENT%%");
739 printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); 739
740 740 printf ("\n");
741 printf (_(UT_VERBOSE)); 741
742 742 printf (_("exit with CRITCAL status if less than PERCENT of disk space is free"));
743 printf ("%s", _("Examples:\n\ 743
744 check_disk -w 10% -c 5% -p /tmp -p /var -C -w 100000 -c 50000 -p /\n\ 744 printf ("\n");
745 Checks /tmp and /var at 10%,5% and / at 100MB, 50MB\n")); 745
746 746 printf (" -C, --clear");
747 printf (_(UT_SUPPORT)); 747
748 printf ("\n");
749
750 printf (_("clear thresholds"));
751
752 printf ("\n");
753
754 printf (" -u, --units=STRING");
755
756 printf ("\n");
757
758 printf (_("choose bytes, kB, MB, GB, TB (default: MB)"));
759
760 printf ("\n");
761
762 printf (" -k, --kilobytes");
763
764 printf ("\n");
765
766 printf (_("same as '--units kB'"));
767
768 printf ("\n");
769
770 printf (" -m, --megabytes");
771
772 printf ("\n");
773
774 printf (_("same as '--units MB'\n"));
775
776 printf (" -l, --local");
777
778 printf ("\n");
779
780 printf (_("only check local filesystems"));
781
782 printf ("\n");
783
784 printf (" -p, --path=PATH, --partition=PARTITION");
785
786 printf ("\n");
787
788 printf (_("path or partition (may be repeated)"));
789
790 printf ("\n");
791
792 printf (" -x, --exclude_device=PATH <STRING>");
793
794 printf ("\n");
795
796 printf (_("ignore device (only works if -p unspecified)"));
797
798 printf ("\n");
799
800 printf (" -X, --exclude-type=TYPE <STRING>");
801
802 printf ("\n");
803
804 printf (_("ignore all filesystems of indicated type (may be repeated)"));
805
806 printf ("\n");
807
808 printf ("-m, --mountpoint");
809
810 printf ("\n");
811
812 printf (_("display the mountpoint instead of the partition"));
813
814 printf ("\n");
815
816 printf ("-e, --errors-only");
817
818 printf ("\n");
819
820 printf (_("display only devices/mountpoints with errors"));
821
822 printf ("\n");
823
824 printf (_(UT_WARN_CRIT));
825
826 printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
827
828 printf (_(UT_VERBOSE));
829
830 printf (_("examples:"));
831
832 printf ("\n");
833
834 printf ("check_disk -w 10% -c 5% -p /tmp -p /var -C -w 100000 -c 50000 -p /");
835
836 printf ("\n");
837
838 printf (_("checks /tmp and /var at 10% and 5% and / at 100MB, 50MB"));
839
840 printf ("\n");
841
842 printf (_(UT_SUPPORT));
748} 843}
749 844
750 845
@@ -752,7 +847,7 @@ and generates an alert if free space is less than one of the threshold values.\n
752void 847void
753print_usage (void) 848print_usage (void)
754{ 849{
755 printf ("\ 850 printf (_("Usage:"));
756Usage: %s -w limit -c limit [-p path | -x device] [-t timeout] [-m] [-e] [-W limit] [-K limit]\n\ 851 printf (" %s -w limit -c limit [-p path | -x device] [-t timeout]", progname);
757 [-v] [-q]\n", progname); 852 printf ("[-m] [-e] [-W limit] [-K limit] [-v] [-q]\n");
758} 853}
diff --git a/plugins/check_dns.c b/plugins/check_dns.c
index d6e8ca29..faa1e150 100644
--- a/plugins/check_dns.c
+++ b/plugins/check_dns.c
@@ -23,7 +23,7 @@
23 23
24const char *progname = "check_dns"; 24const char *progname = "check_dns";
25const char *revision = "$Revision$"; 25const char *revision = "$Revision$";
26const char *copyright = "2000-2004"; 26const char *copyright = "2000-2005";
27const char *email = "nagiosplug-devel@lists.sourceforge.net"; 27const char *email = "nagiosplug-devel@lists.sourceforge.net";
28 28
29#include "common.h" 29#include "common.h"
@@ -49,156 +49,156 @@ int expect_authority = FALSE;
49int 49int
50main (int argc, char **argv) 50main (int argc, char **argv)
51{ 51{
52 char *command_line = NULL; 52 char *command_line = NULL;
53 char input_buffer[MAX_INPUT_BUFFER]; 53 char input_buffer[MAX_INPUT_BUFFER];
54 char *address = NULL; 54 char *address = NULL;
55 char *msg = NULL; 55 char *msg = NULL;
56 char *temp_buffer = NULL; 56 char *temp_buffer = NULL;
57 int non_authoritative = FALSE; 57 int non_authoritative = FALSE;
58 int result = STATE_UNKNOWN; 58 int result = STATE_UNKNOWN;
59 double elapsed_time; 59 double elapsed_time;
60 long microsec; 60 long microsec;
61 struct timeval tv; 61 struct timeval tv;
62 int multi_address; 62 int multi_address;
63 int parse_address = FALSE; /* This flag scans for Address: but only after Name: */ 63 int parse_address = FALSE; /* This flag scans for Address: but only after Name: */
64 output chld_out, chld_err; 64 output chld_out, chld_err;
65 size_t i; 65 size_t i;
66 66
67 setlocale (LC_ALL, ""); 67 setlocale (LC_ALL, "");
68 bindtextdomain (PACKAGE, LOCALEDIR); 68 bindtextdomain (PACKAGE, LOCALEDIR);
69 textdomain (PACKAGE); 69 textdomain (PACKAGE);
70 70
71 /* Set signal handling and alarm */ 71 /* Set signal handling and alarm */
72 if (signal (SIGALRM, popen_timeout_alarm_handler) == SIG_ERR) { 72 if (signal (SIGALRM, popen_timeout_alarm_handler) == SIG_ERR) {
73 usage_va(_("Cannot catch SIGALRM")); 73 usage_va(_("Cannot catch SIGALRM"));
74 } 74 }
75 75
76 if (process_arguments (argc, argv) == ERROR) { 76 if (process_arguments (argc, argv) == ERROR) {
77 usage_va(_("Could not parse arguments")); 77 usage_va(_("Could not parse arguments"));
78 } 78 }
79 79
80 /* get the command to run */ 80 /* get the command to run */
81 asprintf (&command_line, "%s %s %s", NSLOOKUP_COMMAND, query_address, dns_server); 81 asprintf (&command_line, "%s %s %s", NSLOOKUP_COMMAND, query_address, dns_server);
82 82
83 alarm (timeout_interval); 83 alarm (timeout_interval);
84 gettimeofday (&tv, NULL); 84 gettimeofday (&tv, NULL);
85 85
86 if (verbose) 86 if (verbose)
87 printf ("%s\n", command_line); 87 printf ("%s\n", command_line);
88 88
89 /* run the command */ 89 /* run the command */
90 if((np_runcmd(command_line, &chld_out, &chld_err, 0)) != 0) { 90 if((np_runcmd(command_line, &chld_out, &chld_err, 0)) != 0) {
91 msg = (char *)_("nslookup returned error status"); 91 msg = (char *)_("nslookup returned an error status");
92 result = STATE_WARNING; 92 result = STATE_WARNING;
93 } 93 }
94 94
95 /* scan stdout */ 95 /* scan stdout */
96 for(i = 0; i < chld_out.lines; i++) { 96 for(i = 0; i < chld_out.lines; i++) {
97 if (verbose) 97 if (verbose)
98 puts(chld_out.line[i]); 98 puts(chld_out.line[i]);
99 99
100 if (strstr (chld_out.line[i], ".in-addr.arpa")) { 100 if (strstr (chld_out.line[i], ".in-addr.arpa")) {
101 if ((temp_buffer = strstr (chld_out.line[i], "name = "))) 101 if ((temp_buffer = strstr (chld_out.line[i], "name = ")))
102 address = strdup (temp_buffer + 7); 102 address = strdup (temp_buffer + 7);
103 else { 103 else {
104 msg = (char *)_("Warning plugin error"); 104 msg = (char *)_("Warning plugin error");
105 result = STATE_WARNING; 105 result = STATE_WARNING;
106 } 106 }
107 } 107 }
108 108
109 /* the server is responding, we just got the host name... */ 109 /* the server is responding, we just got the host name... */
110 if (strstr (chld_out.line[i], "Name:")) 110 if (strstr (chld_out.line[i], "Name:"))
111 parse_address = TRUE; 111 parse_address = TRUE;
112 else if (parse_address == TRUE && (strstr (chld_out.line[i], "Address:") || 112 else if (parse_address == TRUE && (strstr (chld_out.line[i], "Address:") ||
113 strstr (chld_out.line[i], "Addresses:"))) { 113 strstr (chld_out.line[i], "Addresses:"))) {
114 temp_buffer = index (chld_out.line[i], ':'); 114 temp_buffer = index (chld_out.line[i], ':');
115 temp_buffer++; 115 temp_buffer++;
116 116
117 /* Strip leading spaces */ 117 /* Strip leading spaces */
118 for (; *temp_buffer != '\0' && *temp_buffer == ' '; temp_buffer++) 118 for (; *temp_buffer != '\0' && *temp_buffer == ' '; temp_buffer++)
119 /* NOOP */; 119 /* NOOP */;
120 120
121 strip(temp_buffer); 121 strip(temp_buffer);
122 if (temp_buffer==NULL || strlen(temp_buffer)==0) { 122 if (temp_buffer==NULL || strlen(temp_buffer)==0) {
123 die (STATE_CRITICAL, 123 die (STATE_CRITICAL,
124 _("DNS CRITICAL - '%s' returned empty host name string\n"), 124 _("DNS CRITICAL - '%s' returned empty host name string\n"),
125 NSLOOKUP_COMMAND); 125 NSLOOKUP_COMMAND);
126 } 126 }
127 127
128 if (address == NULL) 128 if (address == NULL)
129 address = strdup (temp_buffer); 129 address = strdup (temp_buffer);
130 else 130 else
131 asprintf(&address, "%s,%s", address, temp_buffer); 131 asprintf(&address, "%s,%s", address, temp_buffer);
132 } 132 }
133 133
134 else if (strstr (chld_out.line[i], _("Non-authoritative answer:"))) { 134 else if (strstr (chld_out.line[i], _("Non-authoritative answer:"))) {
135 non_authoritative = TRUE; 135 non_authoritative = TRUE;
136 } 136 }
137 137
138 result = error_scan (chld_out.line[i]); 138 result = error_scan (chld_out.line[i]);
139 if (result != STATE_OK) { 139 if (result != STATE_OK) {
140 msg = strchr (chld_out.line[i], ':'); 140 msg = strchr (chld_out.line[i], ':');
141 if(msg) msg++; 141 if(msg) msg++;
142 break; 142 break;
143 } 143 }
144 } 144 }
145 145
146 /* scan stderr */ 146 /* scan stderr */
147 for(i = 0; i < chld_err.lines; i++) { 147 for(i = 0; i < chld_err.lines; i++) {
148 if (verbose) 148 if (verbose)
149 puts(chld_err.line[i]); 149 puts(chld_err.line[i]);
150 150
151 if (error_scan (chld_err.line[i]) != STATE_OK) { 151 if (error_scan (chld_err.line[i]) != STATE_OK) {
152 result = max_state (result, error_scan (chld_err.line[i])); 152 result = max_state (result, error_scan (chld_err.line[i]));
153 msg = strchr(input_buffer, ':'); 153 msg = strchr(input_buffer, ':');
154 if(msg) msg++; 154 if(msg) msg++;
155 } 155 }
156 } 156 }
157 157
158 /* If we got here, we should have an address string, 158 /* If we got here, we should have an address string,
159 * and we can segfault if we do not */ 159 * and we can segfault if we do not */
160 if (address==NULL || strlen(address)==0) 160 if (address==NULL || strlen(address)==0)
161 die (STATE_CRITICAL, 161 die (STATE_CRITICAL,
162 _("DNS CRITICAL - '%s' msg parsing exited with no address\n"), 162 _("DNS CRITICAL - '%s' msg parsing exited with no address\n"),
163 NSLOOKUP_COMMAND); 163 NSLOOKUP_COMMAND);
164 164
165 /* compare to expected address */ 165 /* compare to expected address */
166 if (result == STATE_OK && match_expected_address && strcmp(address, expected_address)) { 166 if (result == STATE_OK && match_expected_address && strcmp(address, expected_address)) {
167 result = STATE_CRITICAL; 167 result = STATE_CRITICAL;
168 asprintf(&msg, _("expected %s but got %s"), expected_address, address); 168 asprintf(&msg, _("expected %s but got %s"), expected_address, address);
169 } 169 }
170 170
171 /* check if authoritative */ 171 /* check if authoritative */
172 if (result == STATE_OK && expect_authority && non_authoritative) { 172 if (result == STATE_OK && expect_authority && non_authoritative) {
173 result = STATE_CRITICAL; 173 result = STATE_CRITICAL;
174 asprintf(&msg, _("server %s is not authoritative for %s"), dns_server, query_address); 174 asprintf(&msg, _("server %s is not authoritative for %s"), dns_server, query_address);
175 } 175 }
176 176
177 microsec = deltime (tv); 177 microsec = deltime (tv);
178 elapsed_time = (double)microsec / 1.0e6; 178 elapsed_time = (double)microsec / 1.0e6;
179 179
180 if (result == STATE_OK) { 180 if (result == STATE_OK) {
181 if (strchr (address, ',') == NULL) 181 if (strchr (address, ',') == NULL)
182 multi_address = FALSE; 182 multi_address = FALSE;
183 else 183 else
184 multi_address = TRUE; 184 multi_address = TRUE;
185 185
186 printf ("DNS %s: ", _("OK")); 186 printf ("DNS %s: ", _("OK"));
187 printf (ngettext("%.3f second response time", "%.3f seconds response time", elapsed_time), elapsed_time); 187 printf (ngettext("%.3f second response time", "%.3f seconds response time", elapsed_time), elapsed_time);
188 printf (_(". %s returns %s"), query_address, address); 188 printf (_(". %s returns %s"), query_address, address);
189 printf ("|%s\n", fperfdata ("time", elapsed_time, "s", FALSE, 0, FALSE, 0, TRUE, 0, FALSE, 0)); 189 printf ("|%s\n", fperfdata ("time", elapsed_time, "s", FALSE, 0, FALSE, 0, TRUE, 0, FALSE, 0));
190 } 190 }
191 else if (result == STATE_WARNING) 191 else if (result == STATE_WARNING)
192 printf (_("DNS WARNING - %s\n"), 192 printf (_("DNS WARNING - %s\n"),
193 !strcmp (msg, "") ? _(" Probably a non-existent host/domain") : msg); 193 !strcmp (msg, "") ? _(" Probably a non-existent host/domain") : msg);
194 else if (result == STATE_CRITICAL) 194 else if (result == STATE_CRITICAL)
195 printf (_("DNS CRITICAL - %s\n"), 195 printf (_("DNS CRITICAL - %s\n"),
196 !strcmp (msg, "") ? _(" Probably a non-existent host/domain") : msg); 196 !strcmp (msg, "") ? _(" Probably a non-existent host/domain") : msg);
197 else 197 else
198 printf (_("DNS UNKNOW - %s\n"), 198 printf (_("DNS UNKNOW - %s\n"),
199 !strcmp (msg, "") ? _(" Probably a non-existent host/domain") : msg); 199 !strcmp (msg, "") ? _(" Probably a non-existent host/domain") : msg);
200 200
201 return result; 201 return result;
202} 202}
203 203
204 204
@@ -207,56 +207,56 @@ int
207error_scan (char *input_buffer) 207error_scan (char *input_buffer)
208{ 208{
209 209
210 /* the DNS lookup timed out */ 210 /* the DNS lookup timed out */
211 if (strstr (input_buffer, _("Note: nslookup is deprecated and may be removed from future releases.")) || 211 if (strstr (input_buffer, _("Note: nslookup is deprecated and may be removed from future releases.")) ||
212 strstr (input_buffer, _("Consider using the `dig' or `host' programs instead. Run nslookup with")) || 212 strstr (input_buffer, _("Consider using the `dig' or `host' programs instead. Run nslookup with")) ||
213 strstr (input_buffer, _("the `-sil[ent]' option to prevent this message from appearing."))) 213 strstr (input_buffer, _("the `-sil[ent]' option to prevent this message from appearing.")))
214 return STATE_OK; 214 return STATE_OK;
215 215
216 /* DNS server is not running... */ 216 /* DNS server is not running... */
217 else if (strstr (input_buffer, "No response from server")) 217 else if (strstr (input_buffer, "No response from server"))
218 die (STATE_CRITICAL, _("No response from DNS %s\n"), dns_server); 218 die (STATE_CRITICAL, _("No response from DNS %s\n"), dns_server);
219 219
220 /* Host name is valid, but server doesn't have records... */ 220 /* Host name is valid, but server doesn't have records... */
221 else if (strstr (input_buffer, "No records")) 221 else if (strstr (input_buffer, "No records"))
222 die (STATE_CRITICAL, _("DNS %s has no records\n"), dns_server); 222 die (STATE_CRITICAL, _("DNS %s has no records\n"), dns_server);
223 223
224 /* Connection was refused */ 224 /* Connection was refused */
225 else if (strstr (input_buffer, "Connection refused") || 225 else if (strstr (input_buffer, "Connection refused") ||
226 strstr (input_buffer, "Couldn't find server") || 226 strstr (input_buffer, "Couldn't find server") ||
227 strstr (input_buffer, "Refused") || 227 strstr (input_buffer, "Refused") ||
228 (strstr (input_buffer, "** server can't find") && 228 (strstr (input_buffer, "** server can't find") &&
229 strstr (input_buffer, ": REFUSED"))) 229 strstr (input_buffer, ": REFUSED")))
230 die (STATE_CRITICAL, _("Connection to DNS %s was refused\n"), dns_server); 230 die (STATE_CRITICAL, _("Connection to DNS %s was refused\n"), dns_server);
231 231
232 /* Query refused (usually by an ACL in the namserver) */ 232 /* Query refused (usually by an ACL in the namserver) */
233 else if (strstr (input_buffer, "Query refused")) 233 else if (strstr (input_buffer, "Query refused"))
234 die (STATE_CRITICAL, _("Query was refused by DNS server at %s\n"), dns_server); 234 die (STATE_CRITICAL, _("Query was refused by DNS server at %s\n"), dns_server);
235 235
236 /* No information (e.g. nameserver IP has two PTR records) */ 236 /* No information (e.g. nameserver IP has two PTR records) */
237 else if (strstr (input_buffer, "No information")) 237 else if (strstr (input_buffer, "No information"))
238 die (STATE_CRITICAL, _("No information returned by DNS server at %s\n"), dns_server); 238 die (STATE_CRITICAL, _("No information returned by DNS server at %s\n"), dns_server);
239 239
240 /* Host or domain name does not exist */ 240 /* Host or domain name does not exist */
241 else if (strstr (input_buffer, "Non-existent") || 241 else if (strstr (input_buffer, "Non-existent") ||
242 strstr (input_buffer, "** server can't find") || 242 strstr (input_buffer, "** server can't find") ||
243 strstr (input_buffer,"NXDOMAIN")) 243 strstr (input_buffer,"NXDOMAIN"))
244 die (STATE_CRITICAL, _("Domain %s was not found by the server\n"), query_address); 244 die (STATE_CRITICAL, _("Domain %s was not found by the server\n"), query_address);
245 245
246 /* Network is unreachable */ 246 /* Network is unreachable */
247 else if (strstr (input_buffer, "Network is unreachable")) 247 else if (strstr (input_buffer, "Network is unreachable"))
248 die (STATE_CRITICAL, _("Network is unreachable\n")); 248 die (STATE_CRITICAL, _("Network is unreachable\n"));
249 249
250 /* Internal server failure */ 250 /* Internal server failure */
251 else if (strstr (input_buffer, "Server failure")) 251 else if (strstr (input_buffer, "Server failure"))
252 die (STATE_CRITICAL, _("DNS failure for %s\n"), dns_server); 252 die (STATE_CRITICAL, _("DNS failure for %s\n"), dns_server);
253 253
254 /* Request error or the DNS lookup timed out */ 254 /* Request error or the DNS lookup timed out */
255 else if (strstr (input_buffer, "Format error") || 255 else if (strstr (input_buffer, "Format error") ||
256 strstr (input_buffer, "Timed out")) 256 strstr (input_buffer, "Timed out"))
257 return STATE_WARNING; 257 return STATE_WARNING;
258 258
259 return STATE_OK; 259 return STATE_OK;
260 260
261} 261}
262 262
@@ -265,148 +265,177 @@ error_scan (char *input_buffer)
265int 265int
266process_arguments (int argc, char **argv) 266process_arguments (int argc, char **argv)
267{ 267{
268 int c; 268 int c;
269 269
270 int opt_index = 0; 270 int opt_index = 0;
271 static struct option long_opts[] = { 271 static struct option long_opts[] = {
272 {"help", no_argument, 0, 'h'}, 272 {"help", no_argument, 0, 'h'},
273 {"version", no_argument, 0, 'V'}, 273 {"version", no_argument, 0, 'V'},
274 {"verbose", no_argument, 0, 'v'}, 274 {"verbose", no_argument, 0, 'v'},
275 {"timeout", required_argument, 0, 't'}, 275 {"timeout", required_argument, 0, 't'},
276 {"hostname", required_argument, 0, 'H'}, 276 {"hostname", required_argument, 0, 'H'},
277 {"server", required_argument, 0, 's'}, 277 {"server", required_argument, 0, 's'},
278 {"reverse-server", required_argument, 0, 'r'}, 278 {"reverse-server", required_argument, 0, 'r'},
279 {"expected-address", required_argument, 0, 'a'}, 279 {"expected-address", required_argument, 0, 'a'},
280 {"expect-authority", no_argument, 0, 'A'}, 280 {"expect-authority", no_argument, 0, 'A'},
281 {0, 0, 0, 0} 281 {0, 0, 0, 0}
282 }; 282 };
283 283
284 if (argc < 2) 284 if (argc < 2)
285 return ERROR; 285 return ERROR;
286 286
287 for (c = 1; c < argc; c++) 287 for (c = 1; c < argc; c++)
288 if (strcmp ("-to", argv[c]) == 0) 288 if (strcmp ("-to", argv[c]) == 0)
289 strcpy (argv[c], "-t"); 289 strcpy (argv[c], "-t");
290 290
291 while (1) { 291 while (1) {
292 c = getopt_long (argc, argv, "hVvAt:H:s:r:a:", long_opts, &opt_index); 292 c = getopt_long (argc, argv, "hVvAt:H:s:r:a:", long_opts, &opt_index);
293 293
294 if (c == -1 || c == EOF) 294 if (c == -1 || c == EOF)
295 break; 295 break;
296 296
297 switch (c) { 297 switch (c) {
298 case 'h': /* help */ 298 case 'h': /* help */
299 print_help (); 299 print_help ();
300 exit (STATE_OK); 300 exit (STATE_OK);
301 case 'V': /* version */ 301 case 'V': /* version */
302 print_revision (progname, revision); 302 print_revision (progname, revision);
303 exit (STATE_OK); 303 exit (STATE_OK);
304 case 'v': /* version */ 304 case 'v': /* version */
305 verbose = TRUE; 305 verbose = TRUE;
306 break; 306 break;
307 case 't': /* timeout period */ 307 case 't': /* timeout period */
308 timeout_interval = atoi (optarg); 308 timeout_interval = atoi (optarg);
309 break; 309 break;
310 case 'H': /* hostname */ 310 case 'H': /* hostname */
311 if (strlen (optarg) >= ADDRESS_LENGTH) 311 if (strlen (optarg) >= ADDRESS_LENGTH)
312 die (STATE_UNKNOWN, _("Input buffer overflow\n")); 312 die (STATE_UNKNOWN, _("Input buffer overflow\n"));
313 strcpy (query_address, optarg); 313 strcpy (query_address, optarg);
314 break; 314 break;
315 case 's': /* server name */ 315 case 's': /* server name */
316 /* TODO: this host_or_die check is probably unnecessary. 316 /* TODO: this host_or_die check is probably unnecessary.
317 * Better to confirm nslookup response matches */ 317 * Better to confirm nslookup response matches */
318 host_or_die(optarg); 318 host_or_die(optarg);
319 if (strlen (optarg) >= ADDRESS_LENGTH) 319 if (strlen (optarg) >= ADDRESS_LENGTH)
320 die (STATE_UNKNOWN, _("Input buffer overflow\n")); 320 die (STATE_UNKNOWN, _("Input buffer overflow\n"));
321 strcpy (dns_server, optarg); 321 strcpy (dns_server, optarg);
322 break; 322 break;
323 case 'r': /* reverse server name */ 323 case 'r': /* reverse server name */
324 /* TODO: Is this host_or_die necessary? */ 324 /* TODO: Is this host_or_die necessary? */
325 host_or_die(optarg); 325 host_or_die(optarg);
326 if (strlen (optarg) >= ADDRESS_LENGTH) 326 if (strlen (optarg) >= ADDRESS_LENGTH)
327 die (STATE_UNKNOWN, _("Input buffer overflow\n")); 327 die (STATE_UNKNOWN, _("Input buffer overflow\n"));
328 strcpy (ptr_server, optarg); 328 strcpy (ptr_server, optarg);
329 break; 329 break;
330 case 'a': /* expected address */ 330 case 'a': /* expected address */
331 if (strlen (optarg) >= ADDRESS_LENGTH) 331 if (strlen (optarg) >= ADDRESS_LENGTH)
332 die (STATE_UNKNOWN, _("Input buffer overflow\n")); 332 die (STATE_UNKNOWN, _("Input buffer overflow\n"));
333 strcpy (expected_address, optarg); 333 strcpy (expected_address, optarg);
334 match_expected_address = TRUE; 334 match_expected_address = TRUE;
335 break; 335 break;
336 case 'A': /* expect authority */ 336 case 'A': /* expect authority */
337 expect_authority = TRUE; 337 expect_authority = TRUE;
338 break; 338 break;
339 default: /* args not parsable */ 339 default: /* args not parsable */
340 usage_va(_("Unknown argument - %s"), optarg); 340 usage_va(_("Unknown argument - %s"), optarg);
341 } 341 }
342 } 342 }
343 343
344 c = optind; 344 c = optind;
345 if (strlen(query_address)==0 && c<argc) { 345 if (strlen(query_address)==0 && c<argc) {
346 if (strlen(argv[c])>=ADDRESS_LENGTH) 346 if (strlen(argv[c])>=ADDRESS_LENGTH)
347 die (STATE_UNKNOWN, _("Input buffer overflow\n")); 347 die (STATE_UNKNOWN, _("Input buffer overflow\n"));
348 strcpy (query_address, argv[c++]); 348 strcpy (query_address, argv[c++]);
349 } 349 }
350 350
351 if (strlen(dns_server)==0 && c<argc) { 351 if (strlen(dns_server)==0 && c<argc) {
352 /* TODO: See -s option */ 352 /* TODO: See -s option */
353 host_or_die(argv[c]); 353 host_or_die(argv[c]);
354 if (strlen(argv[c]) >= ADDRESS_LENGTH) 354 if (strlen(argv[c]) >= ADDRESS_LENGTH)
355 die (STATE_UNKNOWN, _("Input buffer overflow\n")); 355 die (STATE_UNKNOWN, _("Input buffer overflow\n"));
356 strcpy (dns_server, argv[c++]); 356 strcpy (dns_server, argv[c++]);
357 } 357 }
358 358
359 return validate_arguments (); 359 return validate_arguments ();
360} 360}
361 361
362 362
363int 363int
364validate_arguments () 364validate_arguments ()
365{ 365{
366 if (query_address[0] == 0) 366 if (query_address[0] == 0)
367 return ERROR; 367 return ERROR;
368 368
369 return OK; 369 return OK;
370} 370}
371 371
372 372
373void 373void
374print_help (void) 374print_help (void)
375{ 375{
376 print_revision (progname, revision); 376 print_revision (progname, revision);
377 377
378 printf ("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n"); 378 printf ("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n");
379 printf (COPYRIGHT, copyright, email); 379 printf (COPYRIGHT, copyright, email);
380 380
381 printf (_("\ 381 printf (_("This plugin uses the nslookup program to obtain the IP address for the given host/domain query."));
382This plugin uses the nslookup program to obtain the IP address\n\ 382
383for the given host/domain query. A optional DNS server to use may\n\ 383 printf ("\n");
384be specified. If no DNS server is specified, the default server(s)\n\ 384
385specified in /etc/resolv.conf will be used.\n\n")); 385 printf (_("An optional DNS server to use may be specified."));
386
387 printf ("\n");
386 388
387 print_usage (); 389 printf (_("If no DNS server is specified, the default server(s)specified in /etc/resolv.conf will be used."));
388 390
389 printf (_(UT_HELP_VRSN)); 391 printf ("\n\n");
390 392
391 printf (_("\ 393 print_usage ();
392-H, --hostname=HOST\n\
393 The name or address you want to query\n\
394-s, --server=HOST\n\
395 Optional DNS server you want to use for the lookup\n\
396-a, --expected-address=IP-ADDRESS\n\
397 Optional IP address you expect the DNS server to return\n\
398-A, --expect-authority\n\
399 Optionally expect the DNS server to be authoritative for the lookup\n"));
400 394
401 printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); 395 printf (_(UT_HELP_VRSN));
402 396
403 printf (_(UT_SUPPORT)); 397 printf (" -H, --hostname=HOST");
398
399 printf ("\n");
400
401 printf (_("the name or address you want to query"));
402
403 printf ("\n");
404
405 printf (" -s, --server=HOST");
406
407 printf ("\n");
408
409 printf (_("optional DNS server you want to use for the lookup"));
410
411 printf ("\n");
412
413 printf (" -a, --expected-address=IP-ADDRESS");
414
415 printf ("\n");
416
417 printf (_("optional IP address you expect the DNS server to return"));
418
419 printf ("\n");
420
421 printf (" -A, --expect-authority");
422
423 printf ("\n");
424
425 printf (_("optionally expect the DNS server to be authoritative for the lookup"));
426
427 printf ("\n");
428
429 printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
430
431 printf (_(UT_SUPPORT));
404} 432}
405 433
406 434
407void 435void
408print_usage (void) 436print_usage (void)
409{ 437{
410 printf ("\ 438 printf (_("Usage:"));
411Usage: %s -H host [-s server] [-a expected-address] [-A] [-t timeout]\n", progname); 439
440 printf ("%s -H host [-s server] [-a expected-address] [-A] [-t timeout]\n", progname);
412} 441}
diff --git a/plugins/check_dummy.c b/plugins/check_dummy.c
index 08926115..0a7f472c 100644
--- a/plugins/check_dummy.c
+++ b/plugins/check_dummy.c
@@ -20,7 +20,7 @@
20 20
21const char *progname = "check_dummy"; 21const char *progname = "check_dummy";
22const char *revision = "$Revision$"; 22const char *revision = "$Revision$";
23const char *copyright = "1999-2004"; 23const char *copyright = "1999-2005";
24const char *email = "nagiosplug-devel@lists.sourceforge.net"; 24const char *email = "nagiosplug-devel@lists.sourceforge.net";
25 25
26#include "common.h" 26#include "common.h"
@@ -33,51 +33,51 @@ void print_usage (void);
33int 33int
34main (int argc, char **argv) 34main (int argc, char **argv)
35{ 35{
36 int result = STATE_UNKNOWN; 36 int result = STATE_UNKNOWN;
37 37
38 setlocale (LC_ALL, ""); 38 setlocale (LC_ALL, "");
39 bindtextdomain (PACKAGE, LOCALEDIR); 39 bindtextdomain (PACKAGE, LOCALEDIR);
40 textdomain (PACKAGE); 40 textdomain (PACKAGE);
41 41
42 if (argc < 2) 42 if (argc < 2)
43 usage4 (_("Could not parse arguments")); 43 usage4 (_("Could not parse arguments"));
44 else if (strcmp (argv[1], "-V") == 0 || strcmp (argv[1], "--version") == 0) { 44 else if (strcmp (argv[1], "-V") == 0 || strcmp (argv[1], "--version") == 0) {
45 print_revision (progname, revision); 45 print_revision (progname, revision);
46 exit (STATE_OK); 46 exit (STATE_OK);
47 } 47 }
48 else if (strcmp (argv[1], "-h") == 0 || strcmp (argv[1], "--help") == 0) { 48 else if (strcmp (argv[1], "-h") == 0 || strcmp (argv[1], "--help") == 0) {
49 print_help (); 49 print_help ();
50 exit (STATE_OK); 50 exit (STATE_OK);
51 } 51 }
52 else if (!is_integer (argv[1])) 52 else if (!is_integer (argv[1]))
53 usage4 (_("Arguments to check_dummy must be an integer")); 53 usage4 (_("Arguments to check_dummy must be an integer"));
54 else 54 else
55 result = atoi (argv[1]); 55 result = atoi (argv[1]);
56 56
57 switch (result) { 57 switch (result) {
58 case STATE_OK: 58 case STATE_OK:
59 printf (_("OK")); 59 printf (_("OK"));
60 break; 60 break;
61 case STATE_WARNING: 61 case STATE_WARNING:
62 printf (_("WARNING")); 62 printf (_("WARNING"));
63 break; 63 break;
64 case STATE_CRITICAL: 64 case STATE_CRITICAL:
65 printf (_("CRITICAL")); 65 printf (_("CRITICAL"));
66 break; 66 break;
67 case STATE_UNKNOWN: 67 case STATE_UNKNOWN:
68 printf (_("UNKNOWN")); 68 printf (_("UNKNOWN"));
69 break; 69 break;
70 default: 70 default:
71 printf (_("Status %d is not a supported error state\n"), result); 71 printf (_("Status %d is not a supported error state\n"), result);
72 break; 72 break;
73 } 73 }
74 74
75 if (argc >= 3) 75 if (argc >= 3)
76 printf (": %s", argv[2]); 76 printf (": %s", argv[2]);
77 77
78 printf("\n"); 78 printf("\n");
79 79
80 return result; 80 return result;
81} 81}
82 82
83 83
@@ -85,20 +85,24 @@ main (int argc, char **argv)
85void 85void
86print_help (void) 86print_help (void)
87{ 87{
88 print_revision (progname, revision); 88 print_revision (progname, revision);
89 89
90 printf ("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n"); 90 printf ("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n");
91 printf (COPYRIGHT, copyright, email); 91 printf (COPYRIGHT, copyright, email);
92 92
93 printf (_("\ 93 printf (_("This plugin will simply return the state corresponding to the numeric value"));
94This plugin will simply return the state corresponding to the numeric value\n\ 94
95of the <state> argument with optional text.\n\n")); 95 printf ("\n");
96
97 printf (_("of the <state> argument with optional text"));
96 98
97 print_usage (); 99 printf ("\n\n");
100
101 print_usage ();
98 102
99 printf (_(UT_HELP_VRSN)); 103 printf (_(UT_HELP_VRSN));
100 104
101 printf (_(UT_SUPPORT)); 105 printf (_(UT_SUPPORT));
102} 106}
103 107
104 108
@@ -106,5 +110,6 @@ of the <state> argument with optional text.\n\n"));
106void 110void
107print_usage (void) 111print_usage (void)
108{ 112{
109 printf ("Usage: %s <integer state> [optional text]\n", progname); 113 printf (_("Usage:"));
114 printf (" %s <integer state> [optional text]\n", progname);
110} 115}
diff --git a/plugins/check_fping.c b/plugins/check_fping.c
index 5ffcd16e..49615d13 100644
--- a/plugins/check_fping.c
+++ b/plugins/check_fping.c
@@ -29,10 +29,10 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net";
29#include "utils.h" 29#include "utils.h"
30 30
31enum { 31enum {
32 PACKET_COUNT = 1, 32 PACKET_COUNT = 1,
33 PACKET_SIZE = 56, 33 PACKET_SIZE = 56,
34 PL = 0, 34 PL = 0,
35 RTA = 1 35 RTA = 1
36}; 36};
37 37
38int textscan (char *buf); 38int textscan (char *buf);
@@ -57,65 +57,65 @@ int wrta_p = FALSE;
57int 57int
58main (int argc, char **argv) 58main (int argc, char **argv)
59{ 59{
60/* normaly should be int result = STATE_UNKNOWN; */ 60/* normaly should be int result = STATE_UNKNOWN; */
61 61
62 int status = STATE_UNKNOWN; 62 int status = STATE_UNKNOWN;
63 char *server = NULL; 63 char *server = NULL;
64 char *command_line = NULL; 64 char *command_line = NULL;
65 char *input_buffer = NULL; 65 char *input_buffer = NULL;
66 input_buffer = malloc (MAX_INPUT_BUFFER); 66 input_buffer = malloc (MAX_INPUT_BUFFER);
67 67
68 setlocale (LC_ALL, ""); 68 setlocale (LC_ALL, "");
69 bindtextdomain (PACKAGE, LOCALEDIR); 69 bindtextdomain (PACKAGE, LOCALEDIR);
70 textdomain (PACKAGE); 70 textdomain (PACKAGE);
71 71
72 if (process_arguments (argc, argv) == ERROR) 72 if (process_arguments (argc, argv) == ERROR)
73 usage4 (_("Could not parse arguments")); 73 usage4 (_("Could not parse arguments"));
74 74
75 server = strscpy (server, server_name); 75 server = strscpy (server, server_name);
76 76
77 /* compose the command */ 77 /* compose the command */
78 asprintf (&command_line, "%s -b %d -c %d %s", PATH_TO_FPING, 78 asprintf (&command_line, "%s -b %d -c %d %s", PATH_TO_FPING,
79 packet_size, packet_count, server); 79 packet_size, packet_count, server);
80 80
81 if (verbose) 81 if (verbose)
82 printf ("%s\n", command_line); 82 printf ("%s\n", command_line);
83 83
84 /* run the command */ 84 /* run the command */
85 child_process = spopen (command_line); 85 child_process = spopen (command_line);
86 if (child_process == NULL) { 86 if (child_process == NULL) {
87 printf (_("Could not open pipe: %s\n"), command_line); 87 printf (_("Could not open pipe: %s\n"), command_line);
88 return STATE_UNKNOWN; 88 return STATE_UNKNOWN;
89 } 89 }
90 90
91 child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r"); 91 child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r");
92 if (child_stderr == NULL) { 92 if (child_stderr == NULL) {
93 printf (_("Could not open stderr for %s\n"), command_line); 93 printf (_("Could not open stderr for %s\n"), command_line);
94 } 94 }
95 95
96 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) { 96 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) {
97 if (verbose) 97 if (verbose)
98 printf ("%s", input_buffer); 98 printf ("%s", input_buffer);
99 status = max_state (status, textscan (input_buffer)); 99 status = max_state (status, textscan (input_buffer));
100 } 100 }
101 101
102 /* If we get anything on STDERR, at least set warning */ 102 /* If we get anything on STDERR, at least set warning */
103 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) { 103 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) {
104 status = max_state (status, STATE_WARNING); 104 status = max_state (status, STATE_WARNING);
105 if (verbose) 105 if (verbose)
106 printf ("%s", input_buffer); 106 printf ("%s", input_buffer);
107 status = max_state (status, textscan (input_buffer)); 107 status = max_state (status, textscan (input_buffer));
108 } 108 }
109 (void) fclose (child_stderr); 109 (void) fclose (child_stderr);
110 110
111 /* close the pipe */ 111 /* close the pipe */
112 if (spclose (child_process)) 112 if (spclose (child_process))
113 /* need to use max_state not max */ 113 /* need to use max_state not max */
114 status = max_state (status, STATE_WARNING); 114 status = max_state (status, STATE_WARNING);
115 115
116 printf ("FPING %s - %s\n", state_text (status), server_name); 116 printf ("FPING %s - %s\n", state_text (status), server_name);
117 117
118 return status; 118 return status;
119} 119}
120 120
121 121
@@ -123,80 +123,80 @@ main (int argc, char **argv)
123int 123int
124textscan (char *buf) 124textscan (char *buf)
125{ 125{
126 char *rtastr = NULL; 126 char *rtastr = NULL;
127 char *losstr = NULL; 127 char *losstr = NULL;
128 double loss; 128 double loss;
129 double rta; 129 double rta;
130 int status = STATE_UNKNOWN; 130 int status = STATE_UNKNOWN;
131 131
132 if (strstr (buf, "not found")) { 132 if (strstr (buf, "not found")) {
133 die (STATE_CRITICAL, _("FPING UNKNOW - %s not found\n"), server_name); 133 die (STATE_CRITICAL, _("FPING UNKNOW - %s not found\n"), server_name);
134 134
135 } 135 }
136 else if (strstr (buf, "is unreachable") || strstr (buf, "Unreachable")) { 136 else if (strstr (buf, "is unreachable") || strstr (buf, "Unreachable")) {
137 die (STATE_CRITICAL, _("FPING CRITICAL - %s is unreachable\n"), 137 die (STATE_CRITICAL, _("FPING CRITICAL - %s is unreachable\n"),
138 "host"); 138 "host");
139 139
140 } 140 }
141 else if (strstr (buf, "is down")) { 141 else if (strstr (buf, "is down")) {
142 die (STATE_CRITICAL, _("FPING CRITICAL - %s is down\n"), server_name); 142 die (STATE_CRITICAL, _("FPING CRITICAL - %s is down\n"), server_name);
143 143
144 } 144 }
145 else if (strstr (buf, "is alive")) { 145 else if (strstr (buf, "is alive")) {
146 status = STATE_OK; 146 status = STATE_OK;
147 147
148 } 148 }
149 else if (strstr (buf, "xmt/rcv/%loss") && strstr (buf, "min/avg/max")) { 149 else if (strstr (buf, "xmt/rcv/%loss") && strstr (buf, "min/avg/max")) {
150 losstr = strstr (buf, "="); 150 losstr = strstr (buf, "=");
151 losstr = 1 + strstr (losstr, "/"); 151 losstr = 1 + strstr (losstr, "/");
152 losstr = 1 + strstr (losstr, "/"); 152 losstr = 1 + strstr (losstr, "/");
153 rtastr = strstr (buf, "min/avg/max"); 153 rtastr = strstr (buf, "min/avg/max");
154 rtastr = strstr (rtastr, "="); 154 rtastr = strstr (rtastr, "=");
155 rtastr = 1 + index (rtastr, '/'); 155 rtastr = 1 + index (rtastr, '/');
156 loss = strtod (losstr, NULL); 156 loss = strtod (losstr, NULL);
157 rta = strtod (rtastr, NULL); 157 rta = strtod (rtastr, NULL);
158 if (cpl_p == TRUE && loss > cpl) 158 if (cpl_p == TRUE && loss > cpl)
159 status = STATE_CRITICAL; 159 status = STATE_CRITICAL;
160 else if (crta_p == TRUE && rta > crta) 160 else if (crta_p == TRUE && rta > crta)
161 status = STATE_CRITICAL; 161 status = STATE_CRITICAL;
162 else if (wpl_p == TRUE && loss > wpl) 162 else if (wpl_p == TRUE && loss > wpl)
163 status = STATE_WARNING; 163 status = STATE_WARNING;
164 else if (wrta_p == TRUE && rta > wrta) 164 else if (wrta_p == TRUE && rta > wrta)
165 status = STATE_WARNING; 165 status = STATE_WARNING;
166 else 166 else
167 status = STATE_OK; 167 status = STATE_OK;
168 die (status, 168 die (status,
169 _("FPING %s - %s (loss=%.0f%%, rta=%f ms)|%s %s\n"), 169 _("FPING %s - %s (loss=%.0f%%, rta=%f ms)|%s %s\n"),
170 state_text (status), server_name, loss, rta, 170 state_text (status), server_name, loss, rta,
171 perfdata ("loss", (long int)loss, "%", wpl_p, wpl, cpl_p, cpl, TRUE, 0, TRUE, 100), 171 perfdata ("loss", (long int)loss, "%", wpl_p, wpl, cpl_p, cpl, TRUE, 0, TRUE, 100),
172 fperfdata ("rta", rta/1.0e3, "s", wrta_p, wrta/1.0e3, crta_p, crta/1.0e3, TRUE, 0, FALSE, 0)); 172 fperfdata ("rta", rta/1.0e3, "s", wrta_p, wrta/1.0e3, crta_p, crta/1.0e3, TRUE, 0, FALSE, 0));
173 173
174 } 174 }
175 else if(strstr (buf, "xmt/rcv/%loss") ) { 175 else if(strstr (buf, "xmt/rcv/%loss") ) {
176 /* no min/max/avg if host was unreachable in fping v2.2.b1 */ 176 /* no min/max/avg if host was unreachable in fping v2.2.b1 */
177 losstr = strstr (buf, "="); 177 losstr = strstr (buf, "=");
178 losstr = 1 + strstr (losstr, "/"); 178 losstr = 1 + strstr (losstr, "/");
179 losstr = 1 + strstr (losstr, "/"); 179 losstr = 1 + strstr (losstr, "/");
180 loss = strtod (losstr, NULL); 180 loss = strtod (losstr, NULL);
181 if (atoi(losstr) == 100) 181 if (atoi(losstr) == 100)
182 status = STATE_CRITICAL; 182 status = STATE_CRITICAL;
183 else if (cpl_p == TRUE && loss > cpl) 183 else if (cpl_p == TRUE && loss > cpl)
184 status = STATE_CRITICAL; 184 status = STATE_CRITICAL;
185 else if (wpl_p == TRUE && loss > wpl) 185 else if (wpl_p == TRUE && loss > wpl)
186 status = STATE_WARNING; 186 status = STATE_WARNING;
187 else 187 else
188 status = STATE_OK; 188 status = STATE_OK;
189 /* loss=%.0f%%;%d;%d;0;100 */ 189 /* loss=%.0f%%;%d;%d;0;100 */
190 die (status, _("FPING %s - %s (loss=%.0f%% )|%s\n"), 190 die (status, _("FPING %s - %s (loss=%.0f%% )|%s\n"),
191 state_text (status), server_name, loss , 191 state_text (status), server_name, loss ,
192 perfdata ("loss", (long int)loss, "%", wpl_p, wpl, cpl_p, cpl, TRUE, 0, TRUE, 100)); 192 perfdata ("loss", (long int)loss, "%", wpl_p, wpl, cpl_p, cpl, TRUE, 0, TRUE, 100));
193 193
194 } 194 }
195 else { 195 else {
196 status = max_state (status, STATE_WARNING); 196 status = max_state (status, STATE_WARNING);
197 } 197 }
198 198
199 return status; 199 return status;
200} 200}
201 201
202 202
@@ -205,145 +205,145 @@ textscan (char *buf)
205int 205int
206process_arguments (int argc, char **argv) 206process_arguments (int argc, char **argv)
207{ 207{
208 int c; 208 int c;
209 char *rv[2]; 209 char *rv[2];
210 210
211 int option = 0; 211 int option = 0;
212 static struct option longopts[] = { 212 static struct option longopts[] = {
213 {"hostname", required_argument, 0, 'H'}, 213 {"hostname", required_argument, 0, 'H'},
214 {"critical", required_argument, 0, 'c'}, 214 {"critical", required_argument, 0, 'c'},
215 {"warning", required_argument, 0, 'w'}, 215 {"warning", required_argument, 0, 'w'},
216 {"bytes", required_argument, 0, 'b'}, 216 {"bytes", required_argument, 0, 'b'},
217 {"number", required_argument, 0, 'n'}, 217 {"number", required_argument, 0, 'n'},
218 {"verbose", no_argument, 0, 'v'}, 218 {"verbose", no_argument, 0, 'v'},
219 {"version", no_argument, 0, 'V'}, 219 {"version", no_argument, 0, 'V'},
220 {"help", no_argument, 0, 'h'}, 220 {"help", no_argument, 0, 'h'},
221 {0, 0, 0, 0} 221 {0, 0, 0, 0}
222 }; 222 };
223 223
224 rv[PL] = NULL; 224 rv[PL] = NULL;
225 rv[RTA] = NULL; 225 rv[RTA] = NULL;
226 226
227 if (argc < 2) 227 if (argc < 2)
228 return ERROR; 228 return ERROR;
229 229
230 if (!is_option (argv[1])) { 230 if (!is_option (argv[1])) {
231 server_name = argv[1]; 231 server_name = argv[1];
232 argv[1] = argv[0]; 232 argv[1] = argv[0];
233 argv = &argv[1]; 233 argv = &argv[1];
234 argc--; 234 argc--;
235 } 235 }
236 236
237 while (1) { 237 while (1) {
238 c = getopt_long (argc, argv, "+hVvH:c:w:b:n:", longopts, &option); 238 c = getopt_long (argc, argv, "+hVvH:c:w:b:n:", longopts, &option);
239 239
240 if (c == -1 || c == EOF || c == 1) 240 if (c == -1 || c == EOF || c == 1)
241 break; 241 break;
242 242
243 switch (c) { 243 switch (c) {
244 case '?': /* print short usage statement if args not parsable */ 244 case '?': /* print short usage statement if args not parsable */
245 usage2 (_("Unknown argument"), optarg); 245 usage2 (_("Unknown argument"), optarg);
246 case 'h': /* help */ 246 case 'h': /* help */
247 print_help (); 247 print_help ();
248 exit (STATE_OK); 248 exit (STATE_OK);
249 case 'V': /* version */ 249 case 'V': /* version */
250 print_revision (progname, revision); 250 print_revision (progname, revision);
251 exit (STATE_OK); 251 exit (STATE_OK);
252 case 'v': /* verbose mode */ 252 case 'v': /* verbose mode */
253 verbose = TRUE; 253 verbose = TRUE;
254 break; 254 break;
255 case 'H': /* hostname */ 255 case 'H': /* hostname */
256 if (is_host (optarg) == FALSE) { 256 if (is_host (optarg) == FALSE) {
257 usage2 (_("Invalid hostname/address"), optarg); 257 usage2 (_("Invalid hostname/address"), optarg);
258 } 258 }
259 server_name = strscpy (server_name, optarg); 259 server_name = strscpy (server_name, optarg);
260 break; 260 break;
261 case 'c': 261 case 'c':
262 get_threshold (optarg, rv); 262 get_threshold (optarg, rv);
263 if (rv[RTA]) { 263 if (rv[RTA]) {
264 crta = strtod (rv[RTA], NULL); 264 crta = strtod (rv[RTA], NULL);
265 crta_p = TRUE; 265 crta_p = TRUE;
266 rv[RTA] = NULL; 266 rv[RTA] = NULL;
267 } 267 }
268 if (rv[PL]) { 268 if (rv[PL]) {
269 cpl = atoi (rv[PL]); 269 cpl = atoi (rv[PL]);
270 cpl_p = TRUE; 270 cpl_p = TRUE;
271 rv[PL] = NULL; 271 rv[PL] = NULL;
272 } 272 }
273 break; 273 break;
274 case 'w': 274 case 'w':
275 get_threshold (optarg, rv); 275 get_threshold (optarg, rv);
276 if (rv[RTA]) { 276 if (rv[RTA]) {
277 wrta = strtod (rv[RTA], NULL); 277 wrta = strtod (rv[RTA], NULL);
278 wrta_p = TRUE; 278 wrta_p = TRUE;
279 rv[RTA] = NULL; 279 rv[RTA] = NULL;
280 } 280 }
281 if (rv[PL]) { 281 if (rv[PL]) {
282 wpl = atoi (rv[PL]); 282 wpl = atoi (rv[PL]);
283 wpl_p = TRUE; 283 wpl_p = TRUE;
284 rv[PL] = NULL; 284 rv[PL] = NULL;
285 } 285 }
286 break; 286 break;
287 case 'b': /* bytes per packet */ 287 case 'b': /* bytes per packet */
288 if (is_intpos (optarg)) 288 if (is_intpos (optarg))
289 packet_size = atoi (optarg); 289 packet_size = atoi (optarg);
290 else 290 else
291 usage (_("Packet size must be a positive integer")); 291 usage (_("Packet size must be a positive integer"));
292 break; 292 break;
293 case 'n': /* number of packets */ 293 case 'n': /* number of packets */
294 if (is_intpos (optarg)) 294 if (is_intpos (optarg))
295 packet_count = atoi (optarg); 295 packet_count = atoi (optarg);
296 else 296 else
297 usage (_("Packet count must be a positive integer")); 297 usage (_("Packet count must be a positive integer"));
298 break; 298 break;
299 } 299 }
300 } 300 }
301 301
302 if (server_name == NULL) 302 if (server_name == NULL)
303 usage4 (_("Hostname was not supplied")); 303 usage4 (_("Hostname was not supplied"));
304 304
305 return OK; 305 return OK;
306} 306}
307 307
308 308
309int 309int
310get_threshold (char *arg, char *rv[2]) 310get_threshold (char *arg, char *rv[2])
311{ 311{
312 char *arg1 = NULL; 312 char *arg1 = NULL;
313 char *arg2 = NULL; 313 char *arg2 = NULL;
314 314
315 arg1 = strscpy (arg1, arg); 315 arg1 = strscpy (arg1, arg);
316 if (strpbrk (arg1, ",:")) 316 if (strpbrk (arg1, ",:"))
317 arg2 = 1 + strpbrk (arg1, ",:"); 317 arg2 = 1 + strpbrk (arg1, ",:");
318 318
319 if (arg2) { 319 if (arg2) {
320 arg1[strcspn (arg1, ",:")] = 0; 320 arg1[strcspn (arg1, ",:")] = 0;
321 if (strstr (arg1, "%") && strstr (arg2, "%")) 321 if (strstr (arg1, "%") && strstr (arg2, "%"))
322 die (STATE_UNKNOWN, 322 die (STATE_UNKNOWN,
323 _("%s: Only one threshold may be packet loss (%s)\n"), progname, 323 _("%s: Only one threshold may be packet loss (%s)\n"), progname,
324 arg); 324 arg);
325 if (!strstr (arg1, "%") && !strstr (arg2, "%")) 325 if (!strstr (arg1, "%") && !strstr (arg2, "%"))
326 die (STATE_UNKNOWN, 326 die (STATE_UNKNOWN,
327 _("%s: Only one threshold must be packet loss (%s)\n"), 327 _("%s: Only one threshold must be packet loss (%s)\n"),
328 progname, arg); 328 progname, arg);
329 } 329 }
330 330
331 if (arg2 && strstr (arg2, "%")) { 331 if (arg2 && strstr (arg2, "%")) {
332 rv[PL] = arg2; 332 rv[PL] = arg2;
333 rv[RTA] = arg1; 333 rv[RTA] = arg1;
334 } 334 }
335 else if (arg2) { 335 else if (arg2) {
336 rv[PL] = arg1; 336 rv[PL] = arg1;
337 rv[RTA] = arg2; 337 rv[RTA] = arg2;
338 } 338 }
339 else if (strstr (arg1, "%")) { 339 else if (strstr (arg1, "%")) {
340 rv[PL] = arg1; 340 rv[PL] = arg1;
341 } 341 }
342 else { 342 else {
343 rv[RTA] = arg1; 343 rv[RTA] = arg1;
344 } 344 }
345 345
346 return OK; 346 return OK;
347} 347}
348 348
349 349
@@ -351,47 +351,82 @@ void
351print_help (void) 351print_help (void)
352{ 352{
353 353
354 print_revision (progname, revision); 354 print_revision (progname, revision);
355 355
356 printf ("Copyright (c) 1999 Didi Rieder <adrieder@sbox.tu-graz.ac.at>\n"); 356 printf ("Copyright (c) 1999 Didi Rieder <adrieder@sbox.tu-graz.ac.at>\n");
357 printf (COPYRIGHT, copyright, email); 357 printf (COPYRIGHT, copyright, email);
358 358
359 printf (_("\ 359 printf (_("This plugin will use the fping command to ping the specified host for a fast check"));
360This plugin will use the /bin/fping command to ping the specified host\n\ 360
361for a fast check if the host is alive.\n\ 361 printf ("\n");
362Note that it is necessary to set the suid flag on fping.\n\n")); 362
363 printf (_("Note that it is necessary to set the suid flag on fping."));
363 364
364 print_usage (); 365 printf ("\n\n");
366
367 print_usage ();
365 368
366 printf (_(UT_HELP_VRSN)); 369 printf (_(UT_HELP_VRSN));
367 370
368 printf (_("\ 371 printf (" -H, --hostname=HOST");
369 -H, --hostname=HOST\n\ 372
370 Name or IP Address of host to ping (IP Address bypasses name lookup,\n\ 373 printf (_("name or IP Address of host to ping (IP Address bypasses name lookup, reducing system load)"));
371 reducing system load)\n\ 374
372 -w, --warning=THRESHOLD\n\ 375 printf ("\n");
373 warning threshold pair\n\ 376
374 -c, --critical=THRESHOLD\n\ 377 printf ("-w, --warning=THRESHOLD");
375 critical threshold pair\n\ 378
376 -b, --bytes=INTEGER\n\ 379 printf ("\n");
377 Size of ICMP packet (default: %d)\n\ 380
378 -n, --number=INTEGER\n\ 381 printf (_("warning threshold pair"));
379 Number of ICMP packets to send (default: %d)\n"), 382
380 PACKET_SIZE, PACKET_COUNT); 383 printf ("\n");
381 384
382 printf (_(UT_VERBOSE)); 385 printf (" -c, --critical=THRESHOLD");
386
387 printf ("\n");
383 388
384 printf (_("\n\ 389 printf (_("critical threshold pair"));
385THRESHOLD is <rta>,<pl>%% where <rta> is the round trip average travel\n\ 390
386time (ms) which triggers a WARNING or CRITICAL state, and <pl> is the\n\ 391 printf ("\n");
387percentage of packet loss to trigger an alarm state.\n"));
388 392
389 printf (_(UT_SUPPORT)); 393 printf (" -b, --bytes=INTEGER");
394
395 printf (_("size of ICMP packet (default: %d)"),PACKET_SIZE);
396
397 printf ("\n");
398
399 printf (" -n, --number=INTEGER");
400
401 printf ("\n");
402
403 printf (_("number of ICMP packets to send (default: %d)"),PACKET_COUNT);
404
405 printf ("\n");
406
407 printf (_(UT_VERBOSE));
408
409 printf ("\n");
410
411 printf (_("THRESHOLD is <rta>,<pl>%% where <rta> is the round trip average travel time (ms)"));
412
413 printf ("\n");
414
415 printf (_("which triggers a WARNING or CRITICAL state, and <pl> is the percentage of"));
416
417 printf ("\n");
418
419 printf (_("packet loss to trigger an alarm state."));
420
421 printf ("\n");
422
423 printf (_(UT_SUPPORT));
390} 424}
391 425
392 426
393void 427void
394print_usage (void) 428print_usage (void)
395{ 429{
396 printf ("Usage: %s <host_address>\n", progname); 430 printf (_("Usage:"));
431 printf (" %s <host_address>\n", progname);
397} 432}
diff --git a/plugins/check_game.c b/plugins/check_game.c
index 8548bbdb..9f9ff7d8 100644
--- a/plugins/check_game.c
+++ b/plugins/check_game.c
@@ -19,7 +19,7 @@
19 19
20const char *progname = "check_game"; 20const char *progname = "check_game";
21const char *revision = "$Revision$"; 21const char *revision = "$Revision$";
22const char *copyright = "2002-2004"; 22const char *copyright = "2002-2005";
23const char *email = "nagiosplug-devel@lists.sourceforge.net"; 23const char *email = "nagiosplug-devel@lists.sourceforge.net";
24 24
25#include "common.h" 25#include "common.h"
@@ -31,12 +31,12 @@ int validate_arguments (void);
31void print_help (void); 31void print_help (void);
32void print_usage (void); 32void print_usage (void);
33 33
34#define QSTAT_DATA_DELIMITER "," 34#define QSTAT_DATA_DELIMITER ","
35 35
36#define QSTAT_HOST_ERROR "ERROR" 36#define QSTAT_HOST_ERROR "ERROR"
37#define QSTAT_HOST_DOWN "DOWN" 37#define QSTAT_HOST_DOWN "DOWN"
38#define QSTAT_HOST_TIMEOUT "TIMEOUT" 38#define QSTAT_HOST_TIMEOUT "TIMEOUT"
39#define QSTAT_MAX_RETURN_ARGS 12 39#define QSTAT_MAX_RETURN_ARGS 12
40 40
41char *server_ip; 41char *server_ip;
42char *game_type; 42char *game_type;
@@ -54,239 +54,241 @@ int qstat_ping_field = -1;
54int 54int
55main (int argc, char **argv) 55main (int argc, char **argv)
56{ 56{
57 char *command_line; 57 char *command_line;
58 int result = STATE_UNKNOWN; 58 int result = STATE_UNKNOWN;
59 char *p, *ret[QSTAT_MAX_RETURN_ARGS]; 59 char *p, *ret[QSTAT_MAX_RETURN_ARGS];
60 size_t i = 0; 60 size_t i = 0;
61 output chld_out; 61 output chld_out;
62 62
63 setlocale (LC_ALL, ""); 63 setlocale (LC_ALL, "");
64 bindtextdomain (PACKAGE, LOCALEDIR); 64 bindtextdomain (PACKAGE, LOCALEDIR);
65 textdomain (PACKAGE); 65 textdomain (PACKAGE);
66 66
67 if (process_arguments (argc, argv) == ERROR) 67 if (process_arguments (argc, argv) == ERROR)
68 usage_va(_("Could not parse arguments")); 68 usage_va(_("Could not parse arguments"));
69 69
70 result = STATE_OK; 70 result = STATE_OK;
71 71
72 /* create the command line to execute */ 72 /* create the command line to execute */
73 asprintf (&command_line, "%s -raw %s -%s %s", 73 asprintf (&command_line, "%s -raw %s -%s %s",
74 PATH_TO_QSTAT, QSTAT_DATA_DELIMITER, game_type, server_ip); 74 PATH_TO_QSTAT, QSTAT_DATA_DELIMITER, game_type, server_ip);
75 75
76 if (port) 76 if (port)
77 asprintf (&command_line, "%s:%-d", command_line, port); 77 asprintf (&command_line, "%s:%-d", command_line, port);
78 78
79 if (verbose > 0) 79 if (verbose > 0)
80 printf ("%s\n", command_line); 80 printf ("%s\n", command_line);
81 81
82 /* run the command. historically, this plugin ignores output on stderr, 82 /* run the command. historically, this plugin ignores output on stderr,
83 * as well as return status of the qstat program */ 83 * as well as return status of the qstat program */
84 (void)np_runcmd(command_line, &chld_out, NULL, 0); 84 (void)np_runcmd(command_line, &chld_out, NULL, 0);
85 85
86 /* sanity check */ 86 /* sanity check */
87 /* was thinking about running qstat without any options, capturing the 87 /* was thinking about running qstat without any options, capturing the
88 -default line, parsing it & making an array of all know server types 88 -default line, parsing it & making an array of all know server types
89 but thought this would be too much hassle considering this is a tool 89 but thought this would be too much hassle considering this is a tool
90 for intelligent sysadmins (ha). Could put a static array of known 90 for intelligent sysadmins (ha). Could put a static array of known
91 server types in a header file but then we'd be limiting ourselves 91 server types in a header file but then we'd be limiting ourselves
92 92
93 In the end, I figured I'd simply let an error occur & then trap it 93 In the end, I figured I'd simply let an error occur & then trap it
94 */ 94 */
95 95
96 if (!strncmp (chld_out.line[0], "unknown option", 14)) { 96 if (!strncmp (chld_out.line[0], "unknown option", 14)) {
97 printf (_("CRITICAL - Host type parameter incorrect!\n")); 97 printf (_("CRITICAL - Host type parameter incorrect!\n"));
98 result = STATE_CRITICAL; 98 result = STATE_CRITICAL;
99 return result; 99 return result;
100 } 100 }
101 101
102 p = (char *) strtok (chld_out.line[0], QSTAT_DATA_DELIMITER); 102 p = (char *) strtok (chld_out.line[0], QSTAT_DATA_DELIMITER);
103 while (p != NULL) { 103 while (p != NULL) {
104 ret[i] = p; 104 ret[i] = p;
105 p = (char *) strtok (NULL, QSTAT_DATA_DELIMITER); 105 p = (char *) strtok (NULL, QSTAT_DATA_DELIMITER);
106 i++; 106 i++;
107 if (i >= QSTAT_MAX_RETURN_ARGS) 107 if (i >= QSTAT_MAX_RETURN_ARGS)
108 break; 108 break;
109 } 109 }
110 110
111 if (strstr (ret[2], QSTAT_HOST_ERROR)) { 111 if (strstr (ret[2], QSTAT_HOST_ERROR)) {
112 printf (_("CRITICAL - Host not found\n")); 112 printf (_("CRITICAL - Host not found\n"));
113 result = STATE_CRITICAL; 113 result = STATE_CRITICAL;
114 } 114 }
115 else if (strstr (ret[2], QSTAT_HOST_DOWN)) { 115 else if (strstr (ret[2], QSTAT_HOST_DOWN)) {
116 printf (_("CRITICAL - Game server down or unavailable\n")); 116 printf (_("CRITICAL - Game server down or unavailable\n"));
117 result = STATE_CRITICAL; 117 result = STATE_CRITICAL;
118 } 118 }
119 else if (strstr (ret[2], QSTAT_HOST_TIMEOUT)) { 119 else if (strstr (ret[2], QSTAT_HOST_TIMEOUT)) {
120 printf (_("CRITICAL - Game server timeout\n")); 120 printf (_("CRITICAL - Game server timeout\n"));
121 result = STATE_CRITICAL; 121 result = STATE_CRITICAL;
122 } 122 }
123 else { 123 else {
124 printf ("OK: %s/%s %s (%s), Ping: %s ms|%s %s\n", 124 printf ("OK: %s/%s %s (%s), Ping: %s ms|%s %s\n",
125 ret[qstat_game_players], 125 ret[qstat_game_players],
126 ret[qstat_game_players_max], 126 ret[qstat_game_players_max],
127 ret[qstat_game_field], 127 ret[qstat_game_field],
128 ret[qstat_map_field], 128 ret[qstat_map_field],
129 ret[qstat_ping_field], 129 ret[qstat_ping_field],
130 perfdata ("players", atol(ret[qstat_game_players]), "", 130 perfdata ("players", atol(ret[qstat_game_players]), "",
131 FALSE, 0, FALSE, 0, 131 FALSE, 0, FALSE, 0,
132 TRUE, 0, TRUE, atol(ret[qstat_game_players_max])), 132 TRUE, 0, TRUE, atol(ret[qstat_game_players_max])),
133 fperfdata ("ping", strtod(ret[qstat_ping_field], NULL), "", 133 fperfdata ("ping", strtod(ret[qstat_ping_field], NULL), "",
134 FALSE, 0, FALSE, 0, 134 FALSE, 0, FALSE, 0,
135 TRUE, 0, FALSE, 0)); 135 TRUE, 0, FALSE, 0));
136 } 136 }
137 137
138 return result; 138 return result;
139} 139}
140 140
141 141
142int 142int
143process_arguments (int argc, char **argv) 143process_arguments (int argc, char **argv)
144{ 144{
145 int c; 145 int c;
146 146
147 int opt_index = 0; 147 int opt_index = 0;
148 static struct option long_opts[] = { 148 static struct option long_opts[] = {
149 {"help", no_argument, 0, 'h'}, 149 {"help", no_argument, 0, 'h'},
150 {"version", no_argument, 0, 'V'}, 150 {"version", no_argument, 0, 'V'},
151 {"verbose", no_argument, 0, 'v'}, 151 {"verbose", no_argument, 0, 'v'},
152 {"timeout", required_argument, 0, 't'}, 152 {"timeout", required_argument, 0, 't'},
153 {"hostname", required_argument, 0, 'H'}, 153 {"hostname", required_argument, 0, 'H'},
154 {"port", required_argument, 0, 'P'}, 154 {"port", required_argument, 0, 'P'},
155 {"game-type", required_argument, 0, 'G'}, 155 {"game-type", required_argument, 0, 'G'},
156 {"map-field", required_argument, 0, 'm'}, 156 {"map-field", required_argument, 0, 'm'},
157 {"ping-field", required_argument, 0, 'p'}, 157 {"ping-field", required_argument, 0, 'p'},
158 {"game-field", required_argument, 0, 'g'}, 158 {"game-field", required_argument, 0, 'g'},
159 {"players-field", required_argument, 0, 129}, 159 {"players-field", required_argument, 0, 129},
160 {"max-players-field", required_argument, 0, 130}, 160 {"max-players-field", required_argument, 0, 130},
161 {0, 0, 0, 0} 161 {0, 0, 0, 0}
162 }; 162 };
163 163
164 if (argc < 2) 164 if (argc < 2)
165 return ERROR; 165 return ERROR;
166 166
167 for (c = 1; c < argc; c++) { 167 for (c = 1; c < argc; c++) {
168 if (strcmp ("-mf", argv[c]) == 0) 168 if (strcmp ("-mf", argv[c]) == 0)
169 strcpy (argv[c], "-m"); 169 strcpy (argv[c], "-m");
170 else if (strcmp ("-pf", argv[c]) == 0) 170 else if (strcmp ("-pf", argv[c]) == 0)
171 strcpy (argv[c], "-p"); 171 strcpy (argv[c], "-p");
172 else if (strcmp ("-gf", argv[c]) == 0) 172 else if (strcmp ("-gf", argv[c]) == 0)
173 strcpy (argv[c], "-g"); 173 strcpy (argv[c], "-g");
174 } 174 }
175 175
176 while (1) { 176 while (1) {
177 c = getopt_long (argc, argv, "hVvt:H:P:G:g:p:m:", long_opts, &opt_index); 177 c = getopt_long (argc, argv, "hVvt:H:P:G:g:p:m:", long_opts, &opt_index);
178 178
179 if (c == -1 || c == EOF) 179 if (c == -1 || c == EOF)
180 break; 180 break;
181 181
182 switch (c) { 182 switch (c) {
183 case 'h': /* help */ 183 case 'h': /* help */
184 print_help (); 184 print_help ();
185 exit (STATE_OK); 185 exit (STATE_OK);
186 case 'V': /* version */ 186 case 'V': /* version */
187 print_revision (progname, revision); 187 print_revision (progname, revision);
188 exit (STATE_OK); 188 exit (STATE_OK);
189 case 'v': /* version */ 189 case 'v': /* version */
190 verbose = TRUE; 190 verbose = TRUE;
191 break; 191 break;
192 case 't': /* timeout period */ 192 case 't': /* timeout period */
193 timeout_interval = atoi (optarg); 193 timeout_interval = atoi (optarg);
194 break; 194 break;
195 case 'H': /* hostname */ 195 case 'H': /* hostname */
196 if (strlen (optarg) >= MAX_HOST_ADDRESS_LENGTH) 196 if (strlen (optarg) >= MAX_HOST_ADDRESS_LENGTH)
197 die (STATE_UNKNOWN, _("Input buffer overflow\n")); 197 die (STATE_UNKNOWN, _("Input buffer overflow\n"));
198 server_ip = optarg; 198 server_ip = optarg;
199 break; 199 break;
200 case 'P': /* port */ 200 case 'P': /* port */
201 port = atoi (optarg); 201 port = atoi (optarg);
202 break; 202 break;
203 case 'G': /* hostname */ 203 case 'G': /* hostname */
204 if (strlen (optarg) >= MAX_INPUT_BUFFER) 204 if (strlen (optarg) >= MAX_INPUT_BUFFER)
205 die (STATE_UNKNOWN, _("Input buffer overflow\n")); 205 die (STATE_UNKNOWN, _("Input buffer overflow\n"));
206 game_type = optarg; 206 game_type = optarg;
207 break; 207 break;
208 case 'p': /* index of ping field */ 208 case 'p': /* index of ping field */
209 qstat_ping_field = atoi (optarg); 209 qstat_ping_field = atoi (optarg);
210 if (qstat_ping_field < 0 || qstat_ping_field > QSTAT_MAX_RETURN_ARGS) 210 if (qstat_ping_field < 0 || qstat_ping_field > QSTAT_MAX_RETURN_ARGS)
211 return ERROR; 211 return ERROR;
212 break; 212 break;
213 case 'm': /* index on map field */ 213 case 'm': /* index on map field */
214 qstat_map_field = atoi (optarg); 214 qstat_map_field = atoi (optarg);
215 if (qstat_map_field < 0 || qstat_map_field > QSTAT_MAX_RETURN_ARGS) 215 if (qstat_map_field < 0 || qstat_map_field > QSTAT_MAX_RETURN_ARGS)
216 return ERROR; 216 return ERROR;
217 break; 217 break;
218 case 'g': /* index of game field */ 218 case 'g': /* index of game field */
219 qstat_game_field = atoi (optarg); 219 qstat_game_field = atoi (optarg);
220 if (qstat_game_field < 0 || qstat_game_field > QSTAT_MAX_RETURN_ARGS) 220 if (qstat_game_field < 0 || qstat_game_field > QSTAT_MAX_RETURN_ARGS)
221 return ERROR; 221 return ERROR;
222 break; 222 break;
223 case 129: /* index of player count field */ 223 case 129: /* index of player count field */
224 qstat_game_players = atoi (optarg); 224 qstat_game_players = atoi (optarg);
225 if (qstat_game_players_max == 0) 225 if (qstat_game_players_max == 0)
226 qstat_game_players_max = qstat_game_players - 1; 226 qstat_game_players_max = qstat_game_players - 1;
227 if (qstat_game_players < 0 || qstat_game_players > QSTAT_MAX_RETURN_ARGS) 227 if (qstat_game_players < 0 || qstat_game_players > QSTAT_MAX_RETURN_ARGS)
228 return ERROR; 228 return ERROR;
229 break; 229 break;
230 case 130: /* index of max players field */ 230 case 130: /* index of max players field */
231 qstat_game_players_max = atoi (optarg); 231 qstat_game_players_max = atoi (optarg);
232 if (qstat_game_players_max < 0 || qstat_game_players_max > QSTAT_MAX_RETURN_ARGS) 232 if (qstat_game_players_max < 0 || qstat_game_players_max > QSTAT_MAX_RETURN_ARGS)
233 return ERROR; 233 return ERROR;
234 break; 234 break;
235 default: /* args not parsable */ 235 default: /* args not parsable */
236 usage_va(_("Unknown argument - %s"), optarg); 236 usage_va(_("Unknown argument - %s"), optarg);
237 } 237 }
238 } 238 }
239 239
240 c = optind; 240 c = optind;
241 /* first option is the game type */ 241 /* first option is the game type */
242 if (!game_type && c<argc) 242 if (!game_type && c<argc)
243 game_type = strdup (argv[c++]); 243 game_type = strdup (argv[c++]);
244 244
245 /* Second option is the server name */ 245 /* Second option is the server name */
246 if (!server_ip && c<argc) 246 if (!server_ip && c<argc)
247 server_ip = strdup (argv[c++]); 247 server_ip = strdup (argv[c++]);
248 248
249 return validate_arguments (); 249 return validate_arguments ();
250} 250}
251 251
252 252
253int 253int
254validate_arguments (void) 254validate_arguments (void)
255{ 255{
256 if (qstat_game_players_max < 0) 256 if (qstat_game_players_max < 0)
257 qstat_game_players_max = 4; 257 qstat_game_players_max = 4;
258 258
259 if (qstat_game_players < 0) 259 if (qstat_game_players < 0)
260 qstat_game_players = 5; 260 qstat_game_players = 5;
261 261
262 if (qstat_game_field < 0) 262 if (qstat_game_field < 0)
263 qstat_game_field = 2; 263 qstat_game_field = 2;
264 264
265 if (qstat_map_field < 0) 265 if (qstat_map_field < 0)
266 qstat_map_field = 3; 266 qstat_map_field = 3;
267 267
268 if (qstat_ping_field < 0) 268 if (qstat_ping_field < 0)
269 qstat_ping_field = 5; 269 qstat_ping_field = 5;
270 270
271 return OK; 271 return OK;
272} 272}
273 273
274 274
275void 275void
276print_help (void) 276print_help (void)
277{ 277{
278 print_revision (progname, revision); 278 print_revision (progname, revision);
279 279
280 printf ("Copyright (c) 1999 Ian Cass, Knowledge Matters Limited\n"); 280 printf ("Copyright (c) 1999 Ian Cass, Knowledge Matters Limited\n");
281 printf (COPYRIGHT, copyright, email); 281 printf (COPYRIGHT, copyright, email);
282 282
283 printf (_("This plugin tests game server connections with the specified host.")); 283 printf (_("This plugin tests game server connections with the specified host."));
284 284
285 print_usage (); 285 printf ("\n\n");
286
287 print_usage ();
286 288
287 printf (_(UT_HELP_VRSN)); 289 printf (_(UT_HELP_VRSN));
288 290
289 printf (_("\ 291 printf (_("\
290<game> = Game type that is recognised by qstat (without the leading dash)\n\ 292<game> = Game type that is recognised by qstat (without the leading dash)\n\
291<ip_address> = The IP address of the device you wish to query\n\ 293<ip_address> = The IP address of the device you wish to query\n\
292 [port] = Optional port of which to connect\n\ 294 [port] = Optional port of which to connect\n\
@@ -294,15 +296,25 @@ print_help (void)
294 [map_field] = Field number in raw qstat output that contains map name\n\ 296 [map_field] = Field number in raw qstat output that contains map name\n\
295 [ping_field] = Field number in raw qstat output that contains ping time\n")); 297 [ping_field] = Field number in raw qstat output that contains ping time\n"));
296 298
297 printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); 299 printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
298 300
299 printf (_("\n\ 301 printf (_("Notes:"));
300Notes:\n\ 302
301- This plugin uses the 'qstat' command, the popular game server status query tool .\n\ 303 printf ("\n");
302 If you don't have the package installed, you will need to download it from\n\
303 http://www.activesw.com/people/steve/qstat.html before you can use this plugin.\n"));
304 304
305 printf (_(UT_SUPPORT)); 305 printf (_("This plugin uses the 'qstat' command, the popular game server status query tool ."));
306
307 printf ("\n");
308
309 printf (_("If you don't have the package installed, you will need to download it from"));
310
311 printf ("\n");
312
313 printf (_("http://www.activesw.com/people/steve/qstat.html before you can use this plugin."));
314
315 printf ("\n");
316
317 printf (_(UT_SUPPORT));
306} 318}
307 319
308 320
@@ -310,9 +322,8 @@ Notes:\n\
310void 322void
311print_usage (void) 323print_usage (void)
312{ 324{
313 printf ("\ 325 printf (_("Usage:"));
314Usage: %s <game> <ip_address> [-p port] [-gf game_field] [-mf map_field]\n\ 326 printf (" %s <game> <ip_address> [-p port] [-gf game_field] [-mf map_field] [-pf ping_field]\n", progname);
315 [-pf ping_field]\n", progname);
316} 327}
317 328
318/****************************************************************************** 329/******************************************************************************