From 5e3fc41c6143676cf01b7aad789fc5f2cae5ce84 Mon Sep 17 00:00:00 2001 From: Benoit Mortier Date: Fri, 3 Dec 2004 23:02:04 +0000 Subject: print_help and print_usage() cleanup other misc cleanups git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@996 f882894a-f735-0410-b71e-b25c423dba1c --- plugins/check_ide-smart.c | 252 +++++++++++++++++++++++----------------------- 1 file changed, 127 insertions(+), 125 deletions(-) (limited to 'plugins/check_ide-smart.c') diff --git a/plugins/check_ide-smart.c b/plugins/check_ide-smart.c index 9ebef6cd..1c0af310 100644 --- a/plugins/check_ide-smart.c +++ b/plugins/check_ide-smart.c @@ -146,6 +146,125 @@ enum SmartCommand }; +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'}, + {"net-saint", no_argument, 0, 'n'}, + {"help", no_argument, 0, 'h'}, + {"version", no_argument, 0, 'V'}, {0, 0, 0, 0} + }; + + setlocale (LC_ALL, ""); + bindtextdomain (PACKAGE, LOCALEDIR); + textdomain (PACKAGE); + + while (1) { + + o = getopt_long (argc, argv, "+d:iq10nhV", longopts, &longindex); + + if (o == -1 || o == EOF) + 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, revision); + return STATE_OK; + default: + printf (_("%s: Unknown argument: %s\n\n"), progname, optarg); + print_usage (); + exit (STATE_UNKNOWN); + } + + if (optind < argc) { + device = argv[optind]; + } + + if (!device) { + show_help (); + show_version (); + return -1; + } + + fd = open (device, O_RDONLY); + + if (fd < 0) { + printf (_("CRITICAL - Couldn't open device: %s\n"), strerror (errno)); + return 2; + } + + if (smart_cmd_simple (fd, SMART_CMD_ENABLE, 0, TRUE)) { + printf (_("CRITICAL - SMART_CMD_ENABLE\n")); + return 2; + } + + 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); + } + return retval; +} + + char * get_offline_text (int status) @@ -371,19 +490,14 @@ smart_read_thresholds (int fd, thresholds_t * thresholds) void -show_version () +print_help () { - printf ("check_ide-smart v.1 - FREE Software with NO WARRANTY\n"); - printf ("Nagios feature - Robert Dale \n"); + print_revision (progname, revision); + + printf ("Nagios feature - 1999 Robert Dale \n"); printf ("(C) 1999 Ragnar Hojland Espinosa \n"); printf (COPYRIGHT, copyright, email); -} - - - -void -show_help () -{ + printf (_("\ Usage: %s [DEVICE] [OPTION]\n\ -d, --device=DEVICE\n\ @@ -402,120 +516,8 @@ Usage: %s [DEVICE] [OPTION]\n\ -int -main (int argc, char *argv[]) +void +print_usage (void) { - 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'}, - {"net-saint", no_argument, 0, 'n'}, - {"help", no_argument, 0, 'h'}, - {"version", no_argument, 0, 'V'}, {0, 0, 0, 0} - }; - - setlocale (LC_ALL, ""); - bindtextdomain (PACKAGE, LOCALEDIR); - textdomain (PACKAGE); - - while (1) { - - o = getopt_long (argc, argv, "+d:iq10nhV", longopts, &longindex); - - if (o == -1 || o == EOF) - 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': - show_help (); - return 0; - case 'V': - show_version (); - return 0; - default: - printf (_("%s: Unknown argument: %s\n\n"), progname, optarg); - print_usage (); - exit (STATE_UNKNOWN); - } - - if (optind < argc) { - device = argv[optind]; - } - - if (!device) { - show_help (); - show_version (); - return -1; - } - - fd = open (device, O_RDONLY); - - if (fd < 0) { - printf (_("CRITICAL - Couldn't open device: %s\n"), strerror (errno)); - return 2; - } - - if (smart_cmd_simple (fd, SMART_CMD_ENABLE, 0, TRUE)) { - printf (_("CRITICAL - SMART_CMD_ENABLE\n")); - return 2; - } - - 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); - } - return retval; + printf ("Usage: %s \n"), progname); } -- cgit v1.2.3-74-g34f1