summaryrefslogtreecommitdiffstats
path: root/plugins/check_ide-smart.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/check_ide-smart.c')
-rw-r--r--plugins/check_ide-smart.c252
1 files changed, 127 insertions, 125 deletions
diff --git a/plugins/check_ide-smart.c b/plugins/check_ide-smart.c
index 9ebef6c..1c0af31 100644
--- a/plugins/check_ide-smart.c
+++ b/plugins/check_ide-smart.c
@@ -146,6 +146,125 @@ enum SmartCommand
146 }; 146 };
147 147
148 148
149int
150main (int argc, char *argv[])
151{
152 char *device = NULL;
153 int command = -1;
154 int o, longindex;
155 int retval = 0;
156
157 thresholds_t thresholds;
158 values_t values;
159 int fd;
160
161 static struct option longopts[] = {
162 {"device", required_argument, 0, 'd'},
163 {"immediate", no_argument, 0, 'i'},
164 {"quiet-check", no_argument, 0, 'q'},
165 {"auto-on", no_argument, 0, '1'},
166 {"auto-off", no_argument, 0, '0'},
167 {"net-saint", no_argument, 0, 'n'},
168 {"help", no_argument, 0, 'h'},
169 {"version", no_argument, 0, 'V'}, {0, 0, 0, 0}
170 };
171
172 setlocale (LC_ALL, "");
173 bindtextdomain (PACKAGE, LOCALEDIR);
174 textdomain (PACKAGE);
175
176 while (1) {
177
178 o = getopt_long (argc, argv, "+d:iq10nhV", longopts, &longindex);
179
180 if (o == -1 || o == EOF)
181 break;
182
183 switch (o) {
184 case 'd':
185 device = optarg;
186 break;
187 case 'q':
188 command = 3;
189 break;
190 case 'i':
191 command = 2;
192 break;
193 case '1':
194 command = 1;
195 break;
196 case '0':
197 command = 0;
198 break;
199 case 'n':
200 command = 4;
201 break;
202 case 'h':
203 print_help ();
204 return STATE_OK;
205 case 'V':
206 print_revision (progname, revision);
207 return STATE_OK;
208 default:
209 printf (_("%s: Unknown argument: %s\n\n"), progname, optarg);
210 print_usage ();
211 exit (STATE_UNKNOWN);
212 }
213
214 if (optind < argc) {
215 device = argv[optind];
216 }
217
218 if (!device) {
219 show_help ();
220 show_version ();
221 return -1;
222 }
223
224 fd = open (device, O_RDONLY);
225
226 if (fd < 0) {
227 printf (_("CRITICAL - Couldn't open device: %s\n"), strerror (errno));
228 return 2;
229 }
230
231 if (smart_cmd_simple (fd, SMART_CMD_ENABLE, 0, TRUE)) {
232 printf (_("CRITICAL - SMART_CMD_ENABLE\n"));
233 return 2;
234 }
235
236 switch (command) {
237 case 0:
238 retval = smart_cmd_simple (fd, SMART_CMD_AUTO_OFFLINE, 0, TRUE);
239 break;
240 case 1:
241 retval = smart_cmd_simple (fd, SMART_CMD_AUTO_OFFLINE, 0xF8, TRUE);
242 break;
243 case 2:
244 retval = smart_cmd_simple (fd, SMART_CMD_IMMEDIATE_OFFLINE, 0, TRUE);
245 break;
246 case 3:
247 smart_read_values (fd, &values);
248 smart_read_thresholds (fd, &thresholds);
249 retval = values_not_passed (&values, &thresholds);
250 break;
251 case 4:
252 smart_read_values (fd, &values);
253 smart_read_thresholds (fd, &thresholds);
254 retval = net_saint (&values, &thresholds);
255 break;
256 default:
257 smart_read_values (fd, &values);
258 smart_read_thresholds (fd, &thresholds);
259 print_values (&values, &thresholds);
260 break;
261 }
262 close (fd);
263 }
264 return retval;
265}
266
267
149 268
150char * 269char *
151get_offline_text (int status) 270get_offline_text (int status)
@@ -371,19 +490,14 @@ smart_read_thresholds (int fd, thresholds_t * thresholds)
371 490
372 491
373void 492void
374show_version () 493print_help ()
375{ 494{
376 printf ("check_ide-smart v.1 - FREE Software with NO WARRANTY\n"); 495 print_revision (progname, revision);
377 printf ("Nagios feature - Robert Dale <rdale@digital-mission.com>\n"); 496
497 printf ("Nagios feature - 1999 Robert Dale <rdale@digital-mission.com>\n");
378 printf ("(C) 1999 Ragnar Hojland Espinosa <ragnar@lightside.dhis.org>\n"); 498 printf ("(C) 1999 Ragnar Hojland Espinosa <ragnar@lightside.dhis.org>\n");
379 printf (COPYRIGHT, copyright, email); 499 printf (COPYRIGHT, copyright, email);
380} 500
381
382
383
384void
385show_help ()
386{
387 printf (_("\ 501 printf (_("\
388Usage: %s [DEVICE] [OPTION]\n\ 502Usage: %s [DEVICE] [OPTION]\n\
389 -d, --device=DEVICE\n\ 503 -d, --device=DEVICE\n\
@@ -402,120 +516,8 @@ Usage: %s [DEVICE] [OPTION]\n\
402 516
403 517
404 518
405int 519void
406main (int argc, char *argv[]) 520print_usage (void)
407{ 521{
408 char *device = NULL; 522 printf ("Usage: %s \n"), progname);
409 int command = -1;
410 int o, longindex;
411 int retval = 0;
412
413 thresholds_t thresholds;
414 values_t values;
415 int fd;
416
417 static struct option longopts[] = {
418 {"device", required_argument, 0, 'd'},
419 {"immediate", no_argument, 0, 'i'},
420 {"quiet-check", no_argument, 0, 'q'},
421 {"auto-on", no_argument, 0, '1'},
422 {"auto-off", no_argument, 0, '0'},
423 {"net-saint", no_argument, 0, 'n'},
424 {"help", no_argument, 0, 'h'},
425 {"version", no_argument, 0, 'V'}, {0, 0, 0, 0}
426 };
427
428 setlocale (LC_ALL, "");
429 bindtextdomain (PACKAGE, LOCALEDIR);
430 textdomain (PACKAGE);
431
432 while (1) {
433
434 o = getopt_long (argc, argv, "+d:iq10nhV", longopts, &longindex);
435
436 if (o == -1 || o == EOF)
437 break;
438
439 switch (o) {
440 case 'd':
441 device = optarg;
442 break;
443 case 'q':
444 command = 3;
445 break;
446 case 'i':
447 command = 2;
448 break;
449 case '1':
450 command = 1;
451 break;
452 case '0':
453 command = 0;
454 break;
455 case 'n':
456 command = 4;
457 break;
458 case 'h':
459 show_help ();
460 return 0;
461 case 'V':
462 show_version ();
463 return 0;
464 default:
465 printf (_("%s: Unknown argument: %s\n\n"), progname, optarg);
466 print_usage ();
467 exit (STATE_UNKNOWN);
468 }
469
470 if (optind < argc) {
471 device = argv[optind];
472 }
473
474 if (!device) {
475 show_help ();
476 show_version ();
477 return -1;
478 }
479
480 fd = open (device, O_RDONLY);
481
482 if (fd < 0) {
483 printf (_("CRITICAL - Couldn't open device: %s\n"), strerror (errno));
484 return 2;
485 }
486
487 if (smart_cmd_simple (fd, SMART_CMD_ENABLE, 0, TRUE)) {
488 printf (_("CRITICAL - SMART_CMD_ENABLE\n"));
489 return 2;
490 }
491
492 switch (command) {
493 case 0:
494 retval = smart_cmd_simple (fd, SMART_CMD_AUTO_OFFLINE, 0, TRUE);
495 break;
496 case 1:
497 retval = smart_cmd_simple (fd, SMART_CMD_AUTO_OFFLINE, 0xF8, TRUE);
498 break;
499 case 2:
500 retval = smart_cmd_simple (fd, SMART_CMD_IMMEDIATE_OFFLINE, 0, TRUE);
501 break;
502 case 3:
503 smart_read_values (fd, &values);
504 smart_read_thresholds (fd, &thresholds);
505 retval = values_not_passed (&values, &thresholds);
506 break;
507 case 4:
508 smart_read_values (fd, &values);
509 smart_read_thresholds (fd, &thresholds);
510 retval = net_saint (&values, &thresholds);
511 break;
512 default:
513 smart_read_values (fd, &values);
514 smart_read_thresholds (fd, &thresholds);
515 print_values (&values, &thresholds);
516 break;
517 }
518 close (fd);
519 }
520 return retval;
521} 523}