int main (int argc, char *argv[]) { char *device = NULL; int command = -1; int o, longindex; int retval = 0; thresholds_t thresholds; values_t values; int fd; static struct option longopts[] = { {"device", required_argument, 0, 'd'}, {"immediate", no_argument, 0, 'i'}, {"quiet-check", no_argument, 0, 'q'}, {"auto-on", no_argument, 0, '1'}, {"auto-off", no_argument, 0, '0'}, {"nagios", no_argument, 0, 'n'}, {"help", no_argument, 0, 'h'}, {"version", no_argument, 0, 'V'}, {0, 0, 0, 0} }; /* Parse extra opts if any */ argv=np_extra_opts (&argc, argv, progname); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); while (1) { o = getopt_long (argc, argv, "+d:iq10nhV", longopts, &longindex); if (o == -1 || o == EOF || o == 1) break; switch (o) { case 'd': device = optarg; break; case 'q': command = 3; break; case 'i': command = 2; break; case '1': command = 1; break; case '0': command = 0; break; case 'n': command = 4; break; case 'h': print_help (); return STATE_OK; case 'V': print_revision (progname, NP_VERSION); return STATE_OK; default: usage5 (); } } if (optind < argc) { device = argv[optind]; } if (!device) { print_help (); return STATE_OK; } fd = open (device, O_RDONLY); 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 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 = nagios (&values, &thresholds); break; default: smart_read_values (fd, &values); smart_read_thresholds (fd, &thresholds); print_values (&values, &thresholds); break; } close (fd); return retval; }
int main (int argc, char *argv[]) { char *device = NULL; int o, longindex; int retval = 0; thresholds_t thresholds; values_t values; int fd; static struct option longopts[] = { {"device", required_argument, 0, 'd'}, {"immediate", no_argument, 0, 'i'}, {"quiet-check", no_argument, 0, 'q'}, {"auto-on", no_argument, 0, '1'}, {"auto-off", no_argument, 0, '0'}, {"nagios", no_argument, 0, 'n'}, /* DEPRECATED, but we still accept it */ {"help", no_argument, 0, 'h'}, {"version", no_argument, 0, 'V'}, {0, 0, 0, 0} }; /* Parse extra opts if any */ argv=np_extra_opts (&argc, argv, progname); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); while (1) { o = getopt_long (argc, argv, "+d:iq10nhVv", longopts, &longindex); if (o == -1 || o == EOF || o == 1) break; switch (o) { case 'd': device = optarg; break; case 'q': fprintf (stderr, "%s\n", _("DEPRECATION WARNING: the -q switch (quiet output) is no longer \"quiet\".")); fprintf (stderr, "%s\n", _("Nagios-compatible output is now always returned.")); break; case 'i': case '1': case '0': printf ("%s\n", _("SMART commands are broken and have been disabled (See Notes in --help).")); return STATE_CRITICAL; break; case 'n': fprintf (stderr, "%s\n", _("DEPRECATION WARNING: the -n switch (Nagios-compatible output) is now the")); fprintf (stderr, "%s\n", _("default and will be removed from future releases.")); break; case 'v': /* verbose */ verbose = TRUE; break; case 'h': print_help (); return STATE_OK; case 'V': print_revision (progname, NP_VERSION); return STATE_OK; default: usage5 (); } } if (optind < argc) { device = argv[optind]; } if (!device) { print_help (); return STATE_OK; } fd = open (device, OPEN_MODE); 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, FALSE)) { printf (_("CRITICAL - SMART_CMD_ENABLE\n")); return STATE_CRITICAL; } smart_read_values (fd, &values); smart_read_thresholds (fd, &thresholds); retval = nagios (&values, &thresholds); if (verbose) print_values (&values, &thresholds); close (fd); return retval; }