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.c119
1 files changed, 55 insertions, 64 deletions
diff --git a/plugins/check_ide_smart.c b/plugins/check_ide_smart.c
index 1f0549c..55faacc 100644
--- a/plugins/check_ide_smart.c
+++ b/plugins/check_ide_smart.c
@@ -1,13 +1,13 @@
1/***************************************************************************** 1/*****************************************************************************
2* 2*
3* Nagios check_ide_smart plugin 3* Monitoring check_ide_smart plugin
4* ide-smart 1.3 - IDE S.M.A.R.T. checking tool 4* ide-smart 1.3 - IDE S.M.A.R.T. checking tool
5* 5*
6* License: GPL 6* License: GPL
7* Copyright (C) 1998-1999 Ragnar Hojland Espinosa <ragnar@lightside.dhis.org> 7* Copyright (C) 1998-1999 Ragnar Hojland Espinosa <ragnar@lightside.dhis.org>
8* 1998 Gadi Oxman <gadio@netvision.net.il> 8* 1998 Gadi Oxman <gadio@netvision.net.il>
9* Copyright (c) 2000 Robert Dale <rdale@digital-mission.com> 9* Copyright (c) 2000 Robert Dale <rdale@digital-mission.com>
10* Copyright (c) 2000-2007 Nagios Plugins Development Team 10* Copyright (c) 2000-2007 Monitoring Plugins Development Team
11* 11*
12* Description: 12* Description:
13* 13*
@@ -35,7 +35,7 @@
35 35
36const char *progname = "check_ide_smart"; 36const char *progname = "check_ide_smart";
37const char *copyright = "1998-2007"; 37const char *copyright = "1998-2007";
38const char *email = "devel@nagios-plugins.org"; 38const char *email = "devel@monitoring-plugins.org";
39 39
40#include "common.h" 40#include "common.h"
41#include "utils.h" 41#include "utils.h"
@@ -172,12 +172,12 @@ void print_value (value_t *, threshold_t *);
172void print_values (values_t *, thresholds_t *); 172void print_values (values_t *, thresholds_t *);
173int smart_cmd_simple (int, enum SmartCommand, __u8, char); 173int smart_cmd_simple (int, enum SmartCommand, __u8, char);
174int smart_read_thresholds (int, thresholds_t *); 174int smart_read_thresholds (int, thresholds_t *);
175int verbose = FALSE;
175 176
176int 177int
177main (int argc, char *argv[]) 178main (int argc, char *argv[])
178{ 179{
179 char *device = NULL; 180 char *device = NULL;
180 int command = -1;
181 int o, longindex; 181 int o, longindex;
182 int retval = 0; 182 int retval = 0;
183 183
@@ -191,7 +191,7 @@ main (int argc, char *argv[])
191 {"quiet-check", no_argument, 0, 'q'}, 191 {"quiet-check", no_argument, 0, 'q'},
192 {"auto-on", no_argument, 0, '1'}, 192 {"auto-on", no_argument, 0, '1'},
193 {"auto-off", no_argument, 0, '0'}, 193 {"auto-off", no_argument, 0, '0'},
194 {"nagios", no_argument, 0, 'n'}, 194 {"nagios", no_argument, 0, 'n'}, /* DEPRECATED, but we still accept it */
195 {"help", no_argument, 0, 'h'}, 195 {"help", no_argument, 0, 'h'},
196 {"version", no_argument, 0, 'V'}, 196 {"version", no_argument, 0, 'V'},
197 {0, 0, 0, 0} 197 {0, 0, 0, 0}
@@ -206,7 +206,7 @@ main (int argc, char *argv[])
206 206
207 while (1) { 207 while (1) {
208 208
209 o = getopt_long (argc, argv, "+d:iq10nhV", longopts, &longindex); 209 o = getopt_long (argc, argv, "+d:iq10nhVv", longopts, &longindex);
210 210
211 if (o == -1 || o == EOF || o == 1) 211 if (o == -1 || o == EOF || o == 1)
212 break; 212 break;
@@ -216,19 +216,21 @@ main (int argc, char *argv[])
216 device = optarg; 216 device = optarg;
217 break; 217 break;
218 case 'q': 218 case 'q':
219 command = 3; 219 fprintf (stderr, "%s\n", _("DEPRECATION WARNING: the -q switch (quiet output) is no longer \"quiet\"."));
220 fprintf (stderr, "%s\n", _("Nagios-compatible output is now always returned."));
220 break; 221 break;
221 case 'i': 222 case 'i':
222 command = 2;
223 break;
224 case '1': 223 case '1':
225 command = 1;
226 break;
227 case '0': 224 case '0':
228 command = 0; 225 printf ("%s\n", _("SMART commands are broken and have been disabled (See Notes in --help)."));
226 return STATE_CRITICAL;
229 break; 227 break;
230 case 'n': 228 case 'n':
231 command = 4; 229 fprintf (stderr, "%s\n", _("DEPRECATION WARNING: the -n switch (Nagios-compatible output) is now the"));
230 fprintf (stderr, "%s\n", _("default and will be removed from future releases."));
231 break;
232 case 'v': /* verbose */
233 verbose = TRUE;
232 break; 234 break;
233 case 'h': 235 case 'h':
234 print_help (); 236 print_help ();
@@ -257,37 +259,16 @@ main (int argc, char *argv[])
257 return STATE_CRITICAL; 259 return STATE_CRITICAL;
258 } 260 }
259 261
260 if (smart_cmd_simple (fd, SMART_CMD_ENABLE, 0, TRUE)) { 262 if (smart_cmd_simple (fd, SMART_CMD_ENABLE, 0, FALSE)) {
261 printf (_("CRITICAL - SMART_CMD_ENABLE\n")); 263 printf (_("CRITICAL - SMART_CMD_ENABLE\n"));
262 return STATE_CRITICAL; 264 return STATE_CRITICAL;
263 } 265 }
264 266
265 switch (command) { 267 smart_read_values (fd, &values);
266 case 0: 268 smart_read_thresholds (fd, &thresholds);
267 retval = smart_cmd_simple (fd, SMART_CMD_AUTO_OFFLINE, 0, TRUE); 269 retval = nagios (&values, &thresholds);
268 break; 270 if (verbose) print_values (&values, &thresholds);
269 case 1: 271
270 retval = smart_cmd_simple (fd, SMART_CMD_AUTO_OFFLINE, 0xF8, TRUE);
271 break;
272 case 2:
273 retval = smart_cmd_simple (fd, SMART_CMD_IMMEDIATE_OFFLINE, 0, TRUE);
274 break;
275 case 3:
276 smart_read_values (fd, &values);
277 smart_read_thresholds (fd, &thresholds);
278 retval = values_not_passed (&values, &thresholds);
279 break;
280 case 4:
281 smart_read_values (fd, &values);
282 smart_read_thresholds (fd, &thresholds);
283 retval = nagios (&values, &thresholds);
284 break;
285 default:
286 smart_read_values (fd, &values);
287 smart_read_thresholds (fd, &thresholds);
288 print_values (&values, &thresholds);
289 break;
290 }
291 close (fd); 272 close (fd);
292 return retval; 273 return retval;
293} 274}
@@ -368,7 +349,7 @@ values_not_passed (values_t * p, thresholds_t * t)
368 int i; 349 int i;
369 for (i = 0; i < NR_ATTRIBUTES; i++) { 350 for (i = 0; i < NR_ATTRIBUTES; i++) {
370 if (value->id && threshold->id && value->id == threshold->id) { 351 if (value->id && threshold->id && value->id == threshold->id) {
371 if (value->value <= threshold->threshold) { 352 if (value->value < threshold->threshold) {
372 ++failed; 353 ++failed;
373 } 354 }
374 else { 355 else {
@@ -397,7 +378,7 @@ nagios (values_t * p, thresholds_t * t)
397 int i; 378 int i;
398 for (i = 0; i < NR_ATTRIBUTES; i++) { 379 for (i = 0; i < NR_ATTRIBUTES; i++) {
399 if (value->id && threshold->id && value->id == threshold->id) { 380 if (value->id && threshold->id && value->id == threshold->id) {
400 if (value->value <= threshold->threshold) { 381 if (value->value < threshold->threshold) {
401 ++failed; 382 ++failed;
402 if (value->status & 1) { 383 if (value->status & 1) {
403 status = PREFAILURE; 384 status = PREFAILURE;
@@ -454,7 +435,7 @@ print_value (value_t * p, threshold_t * t)
454 printf ("Id=%3d, Status=%2d {%s , %s}, Value=%3d, Threshold=%3d, %s\n", 435 printf ("Id=%3d, Status=%2d {%s , %s}, Value=%3d, Threshold=%3d, %s\n",
455 p->id, p->status, p->status & 1 ? "PreFailure" : "Advisory ", 436 p->id, p->status, p->status & 1 ? "PreFailure" : "Advisory ",
456 p->status & 2 ? "OnLine " : "OffLine", p->value, t->threshold, 437 p->status & 2 ? "OnLine " : "OffLine", p->value, t->threshold,
457 p->value > t->threshold ? "Passed" : "Failed"); 438 p->value >= t->threshold ? "Passed" : "Failed");
458} 439}
459 440
460 441
@@ -495,7 +476,7 @@ print_values (values_t * p, thresholds_t * t)
495int 476int
496smart_cmd_simple (int fd, enum SmartCommand command, __u8 val0, char show_error) 477smart_cmd_simple (int fd, enum SmartCommand command, __u8 val0, char show_error)
497{ 478{
498 int e = 0; 479 int e = STATE_UNKNOWN;
499#ifdef __linux__ 480#ifdef __linux__
500 __u8 args[4]; 481 __u8 args[4];
501 args[0] = WIN_SMART; 482 args[0] = WIN_SMART;
@@ -503,11 +484,15 @@ smart_cmd_simple (int fd, enum SmartCommand command, __u8 val0, char show_error)
503 args[2] = smart_command[command].value; 484 args[2] = smart_command[command].value;
504 args[3] = 0; 485 args[3] = 0;
505 if (ioctl (fd, HDIO_DRIVE_CMD, &args)) { 486 if (ioctl (fd, HDIO_DRIVE_CMD, &args)) {
506 e = errno; 487 e = STATE_CRITICAL;
507 if (show_error) { 488 if (show_error)
508 printf (_("CRITICAL - %s: %s\n"), smart_command[command].text, strerror (errno)); 489 printf (_("CRITICAL - %s: %s\n"), smart_command[command].text, strerror (errno));
509 } 490 } else {
491 e = STATE_OK;
492 if (show_error)
493 printf (_("OK - Command sent (%s)\n"), smart_command[command].text);
510 } 494 }
495
511#endif /* __linux__ */ 496#endif /* __linux__ */
512#ifdef __NetBSD__ 497#ifdef __NetBSD__
513 struct atareq req; 498 struct atareq req;
@@ -528,10 +513,15 @@ smart_cmd_simple (int fd, enum SmartCommand command, __u8 val0, char show_error)
528 } 513 }
529 514
530 if (errno != 0) { 515 if (errno != 0) {
531 e = errno; 516 e = STATE_CRITICAL;
532 printf (_("CRITICAL - %s: %s\n"), smart_command[command].text, strerror (errno)); 517 if (show_error)
533 return e; 518 printf (_("CRITICAL - %s: %s\n"), smart_command[command].text, strerror (errno));
519 } else {
520 e = STATE_OK;
521 if (show_error)
522 printf (_("OK - Command sent (%s)\n"), smart_command[command].text);
534 } 523 }
524
535#endif /* __NetBSD__ */ 525#endif /* __NetBSD__ */
536 return e; 526 return e;
537} 527}
@@ -592,8 +582,8 @@ print_help (void)
592{ 582{
593 print_revision (progname, NP_VERSION); 583 print_revision (progname, NP_VERSION);
594 584
595 printf ("Nagios feature - 1999 Robert Dale <rdale@digital-mission.com>\n");
596 printf ("(C) 1999 Ragnar Hojland Espinosa <ragnar@lightside.dhis.org>\n"); 585 printf ("(C) 1999 Ragnar Hojland Espinosa <ragnar@lightside.dhis.org>\n");
586 printf ("Plugin implementation - 1999 Robert Dale <rdale@digital-mission.com>\n");
597 printf (COPYRIGHT, copyright, email); 587 printf (COPYRIGHT, copyright, email);
598 588
599 printf (_("This plugin checks a local hard drive with the (Linux specific) SMART interface [http://smartlinux.sourceforge.net/smart/index.php].")); 589 printf (_("This plugin checks a local hard drive with the (Linux specific) SMART interface [http://smartlinux.sourceforge.net/smart/index.php]."));
@@ -607,17 +597,19 @@ print_help (void)
607 597
608 printf (" %s\n", "-d, --device=DEVICE"); 598 printf (" %s\n", "-d, --device=DEVICE");
609 printf (" %s\n", _("Select device DEVICE")); 599 printf (" %s\n", _("Select device DEVICE"));
610 printf (" %s\n", _("Note: if the device is selected with this option, _no_ other options are accepted")); 600 printf (" %s\n", _("Note: if the device is specified without this option, any further option will"));
611 printf (" %s\n", "-i, --immediate"); 601 printf (" %s\n", _("be ignored."));
612 printf (" %s\n", _("Perform immediately offline tests")); 602
613 printf (" %s\n", "-q, --quiet-check"); 603 printf (UT_VERBOSE);
614 printf (" %s\n", _("Returns the number of failed tests")); 604
615 printf (" %s\n", "-1, --auto-on"); 605 printf ("\n");
616 printf (" %s\n", _("Turn on automatic offline tests")); 606 printf ("%s\n", _("Notes:"));
617 printf (" %s\n", "-0, --auto-off"); 607 printf (" %s\n", _("The SMART command modes (-i/--immediate, -0/--auto-off and -1/--auto-on) were"));
618 printf (" %s\n", _("Turn off automatic offline tests")); 608 printf (" %s\n", _("broken in an underhand manner and have been disabled. You can use smartctl"));
619 printf (" %s\n", "-n, --nagios"); 609 printf (" %s\n", _("instead:"));
620 printf (" %s\n", _("Output suitable for Nagios")); 610 printf (" %s\n", _("-0/--auto-off: use \"smartctl --offlineauto=off\""));
611 printf (" %s\n", _("-1/--auto-on: use \"smartctl --offlineauto=on\""));
612 printf (" %s\n", _("-i/--immediate: use \"smartctl --test=offline\""));
621 613
622 printf (UT_SUPPORT); 614 printf (UT_SUPPORT);
623} 615}
@@ -638,6 +630,5 @@ void
638print_usage (void) 630print_usage (void)
639{ 631{
640 printf ("%s\n", _("Usage:")); 632 printf ("%s\n", _("Usage:"));
641 printf ("%s [-d <device>] [-i <immediate>] [-q quiet] [-1 <auto-on>]",progname); 633 printf ("%s [-d <device>] [-v]", progname);
642 printf (" [-O <auto-off>] [-n <nagios>]\n");
643} 634}