index 1c0af310873303ae2acb559153bd0570ba3707ac..4172483905899e4bd376a2af846576fd46adce38 100644 (file)
*
* Notes:
* ide-smart has the same functionality as before. Some return
*
* Notes:
* ide-smart has the same functionality as before. Some return
- * values were changed, otherwise the --net-saint option was added.
+ * values were changed, otherwise the --nagios option was added.
*
*
- * Run with: check_ide-smart --net-saint [-d] <DRIVE>
+ * Run with: check_ide-smart --nagios [-d] <DRIVE>
* Where DRIVE is an IDE drive, ie. /dev/hda, /dev/hdb, /dev/hdc
*
* - Returns 0 on no errors
* Where DRIVE is an IDE drive, ie. /dev/hda, /dev/hdb, /dev/hdc
*
* - Returns 0 on no errors
#include "common.h"
#include "utils.h"
#include "common.h"
#include "utils.h"
+void print_help (void);
+void print_usage (void);
+
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
SMART_CMD_AUTO_OFFLINE
};
SMART_CMD_AUTO_OFFLINE
};
+void print_values (values_t * p, thresholds_t * t);
+int smart_cmd_simple (int fd, enum SmartCommand command, __u8 val0, char show_error);
int
main (int argc, char *argv[])
int
main (int argc, char *argv[])
{"quiet-check", no_argument, 0, 'q'},
{"auto-on", no_argument, 0, '1'},
{"auto-off", no_argument, 0, '0'},
{"quiet-check", no_argument, 0, 'q'},
{"auto-on", no_argument, 0, '1'},
{"auto-off", no_argument, 0, '0'},
- {"net-saint", no_argument, 0, 'n'},
+ {"nagios", no_argument, 0, 'n'},
{"help", no_argument, 0, 'h'},
{"version", no_argument, 0, 'V'}, {0, 0, 0, 0}
};
{"help", no_argument, 0, 'h'},
{"version", no_argument, 0, 'V'}, {0, 0, 0, 0}
};
while (1) {
o = getopt_long (argc, argv, "+d:iq10nhV", longopts, &longindex);
while (1) {
o = getopt_long (argc, argv, "+d:iq10nhV", longopts, &longindex);
-
- if (o == -1 || o == EOF)
+
+ if (o == -1 || o == EOF || o == 1)
break;
switch (o) {
break;
switch (o) {
print_revision (progname, revision);
return STATE_OK;
default:
print_revision (progname, revision);
return STATE_OK;
default:
- printf (_("%s: Unknown argument: %s\n\n"), progname, optarg);
- print_usage ();
- exit (STATE_UNKNOWN);
+ usage2 (_("Unknown argument"), optarg);
}
}
+ }
- if (optind < argc) {
- device = argv[optind];
- }
+ if (optind < argc) {
+ device = argv[optind];
+ }
- if (!device) {
- show_help ();
- show_version ();
- return -1;
- }
+ if (!device) {
+ print_help ();
+ return STATE_OK;
+ }
- fd = open (device, O_RDONLY);
+ fd = open (device, O_RDONLY);
- if (fd < 0) {
- printf (_("CRITICAL - Couldn't open device: %s\n"), strerror (errno));
- return 2;
- }
+ if (fd < 0) {
+ printf (_("CRITICAL - Couldn't open device %s: %s\n"), device, strerror (errno));
+ return STATE_CRITICAL;
+ }
- if (smart_cmd_simple (fd, SMART_CMD_ENABLE, 0, TRUE)) {
- printf (_("CRITICAL - SMART_CMD_ENABLE\n"));
- return 2;
- }
+ if (smart_cmd_simple (fd, SMART_CMD_ENABLE, 0, TRUE)) {
+ printf (_("CRITICAL - SMART_CMD_ENABLE\n"));
+ return STATE_CRITICAL;
+ }
- switch (command) {
- case 0:
- retval = smart_cmd_simple (fd, SMART_CMD_AUTO_OFFLINE, 0, TRUE);
- break;
- case 1:
- retval = smart_cmd_simple (fd, SMART_CMD_AUTO_OFFLINE, 0xF8, TRUE);
- break;
- case 2:
- retval = smart_cmd_simple (fd, SMART_CMD_IMMEDIATE_OFFLINE, 0, TRUE);
- break;
- case 3:
- smart_read_values (fd, &values);
- smart_read_thresholds (fd, &thresholds);
- retval = values_not_passed (&values, &thresholds);
- break;
- case 4:
- smart_read_values (fd, &values);
- smart_read_thresholds (fd, &thresholds);
- retval = net_saint (&values, &thresholds);
- break;
- default:
- smart_read_values (fd, &values);
- smart_read_thresholds (fd, &thresholds);
- print_values (&values, &thresholds);
- break;
- }
- close (fd);
+ switch (command) {
+ case 0:
+ retval = smart_cmd_simple (fd, SMART_CMD_AUTO_OFFLINE, 0, TRUE);
+ break;
+ case 1:
+ retval = smart_cmd_simple (fd, SMART_CMD_AUTO_OFFLINE, 0xF8, TRUE);
+ break;
+ case 2:
+ retval = smart_cmd_simple (fd, SMART_CMD_IMMEDIATE_OFFLINE, 0, TRUE);
+ break;
+ case 3:
+ smart_read_values (fd, &values);
+ smart_read_thresholds (fd, &thresholds);
+ retval = values_not_passed (&values, &thresholds);
+ break;
+ case 4:
+ smart_read_values (fd, &values);
+ smart_read_thresholds (fd, &thresholds);
+ retval = nagios (&values, &thresholds);
+ break;
+ default:
+ smart_read_values (fd, &values);
+ smart_read_thresholds (fd, &thresholds);
+ print_values (&values, &thresholds);
+ break;
}
}
+ close (fd);
return retval;
}
return retval;
}
int
int
-net_saint (values_t * p, thresholds_t * t)
+nagios (values_t * p, thresholds_t * t)
{
value_t * value = p->values;
threshold_t * threshold = t->thresholds;
{
value_t * value = p->values;
threshold_t * threshold = t->thresholds;
prefailure > 1 ? 's' : ' ',
failed,
total);
prefailure > 1 ? 's' : ' ',
failed,
total);
+ status=STATE_CRITICAL;
break;
case ADVISORY:
printf (_("WARNING - %d Harddrive Advisor%s Detected. %d/%d tests failed.\n"),
break;
case ADVISORY:
printf (_("WARNING - %d Harddrive Advisor%s Detected. %d/%d tests failed.\n"),
advisory > 1 ? "ies" : "y",
failed,
total);
advisory > 1 ? "ies" : "y",
failed,
total);
+ status=STATE_WARNING;
break;
case OPERATIONAL:
printf (_("OK - Operational (%d/%d tests passed)\n"), passed, total);
break;
case OPERATIONAL:
printf (_("OK - Operational (%d/%d tests passed)\n"), passed, total);
+ status=STATE_OK;
break;
default:
break;
default:
- printf (_("ERROR - Status '%d' uknown. %d/%d tests passed\n"), status,
+ printf (_("ERROR - Status '%d' unkown. %d/%d tests passed\n"), status,
passed, total);
passed, total);
- status = -1;
+ status = STATE_UNKNOWN;
break;
}
return status;
break;
}
return status;
void
void
-print_values (values_t * p, thresholds_t * t)
+print_values (values_t * p, thresholds_t * t)
{
value_t * value = p->values;
threshold_t * threshold = t->thresholds;
{
value_t * value = p->values;
threshold_t * threshold = t->thresholds;
}
int
}
int
-smart_cmd_simple (int fd, enum SmartCommand command, __u8 val0,
- char show_error)
+smart_cmd_simple (int fd, enum SmartCommand command, __u8 val0, char show_error)
{
int e = 0;
__u8 args[4];
{
int e = 0;
__u8 args[4];
}
}
-
void
void
-print_help ()
+print_help (void)
{
print_revision (progname, revision);
printf ("Nagios feature - 1999 Robert Dale <rdale@digital-mission.com>\n");
printf ("(C) 1999 Ragnar Hojland Espinosa <ragnar@lightside.dhis.org>\n");
printf (COPYRIGHT, copyright, email);
{
print_revision (progname, revision);
printf ("Nagios feature - 1999 Robert Dale <rdale@digital-mission.com>\n");
printf ("(C) 1999 Ragnar Hojland Espinosa <ragnar@lightside.dhis.org>\n");
printf (COPYRIGHT, copyright, email);
+
+ printf(_("This plugin checks a local hard drive with the (Linux specific) SMART interface [http://smartlinux.sourceforge.net/smart/index.php].\n\n"));
- printf (_("\
-Usage: %s [DEVICE] [OPTION]\n\
+ printf ("\
+Usage: %s [OPTION] [DEVICE]\n\
-d, --device=DEVICE\n\
Select device DEVICE\n\
-d, --device=DEVICE\n\
Select device DEVICE\n\
+ Note: if the device is selected with this option, _no_ other options are accepted\n\
-i, --immediate\n\
Perform immediately offline tests\n\
-q, --quiet-check\n\
-i, --immediate\n\
Perform immediately offline tests\n\
-q, --quiet-check\n\
Turn on automatic offline tests\n\
-0, --auto-off\n\
Turn off automatic offline tests\n\
Turn on automatic offline tests\n\
-0, --auto-off\n\
Turn off automatic offline tests\n\
- -n, --net-saint\n\
- Output suitable for Net Saint\n", progname);
+ -n, --nagios\n\
+ Output suitable for Nagios\n", progname);
}
}
-
void
print_usage (void)
{
void
print_usage (void)
{
- printf ("Usage: %s \n"), progname);
+ printf ("\
+Usage: %s [-d <device>] [-i <immediate>] [-q quiet] [-1 <auto-on>]\n\
+ [-O <auto-off>] [-n <nagios>]\n", progname);
}
}