Code

Fix translations when extra-opts aren't enabled
[nagiosplug.git] / plugins / check_ide_smart.c
index b5021fd7287ebba2d95eed8f39c03d38fef6742b..3811dc12059739c7b3b8516c2e24ac6b29de2bb8 100644 (file)
@@ -1,45 +1,40 @@
-/*
- *  check_ide-smart v.1 - hacked version of ide-smart for Nagios
- *  Copyright (C) 2000 Robert Dale <rdale@digital-mission.com>
- *
- *  Nagios - http://www.nagios.org
- *
- *  Notes:
- *        ide-smart has the same functionality as before. Some return
- *        values were changed, otherwise the --nagios option was added.
- *
- *        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
- *          - Returns 1 on advisories
- *          - Returns 2 on prefailure
- *          - Returns -1 not too often
- *
- *  ide-smart 1.3 - IDE S.M.A.R.T. checking tool
- *  Copyright (C) 1998-1999 Ragnar Hojland Espinosa <ragnar@lightside.dhis.org>
- *               1998      Gadi Oxman <gadio@netvision.net.il>
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * $Id$
- */
+/*****************************************************************************
+* 
+* Nagios check_ide_smart plugin
+* ide-smart 1.3 - IDE S.M.A.R.T. checking tool
+* 
+* License: GPL
+* Copyright (C) 1998-1999 Ragnar Hojland Espinosa <ragnar@lightside.dhis.org>
+*               1998      Gadi Oxman <gadio@netvision.net.il>
+* Copyright (c) 2000 Robert Dale <rdale@digital-mission.com>
+* Copyright (c) 2000-2007 Nagios Plugins Development Team
+* 
+* Description:
+* 
+* This file contains the check_ide_smart plugin
+* 
+* This plugin checks a local hard drive with the (Linux specific) SMART
+* interface
+* 
+* 
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+* 
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU General Public License for more details.
+* 
+* You should have received a copy of the GNU General Public License
+* along with this program.  If not, see <http://www.gnu.org/licenses/>.
+* 
+* 
+*****************************************************************************/
 
 const char *progname = "check_ide_smart";
-const char *revision = "$Revision$";
-const char *copyright = "2000-2004";
+const char *copyright = "1998-2007";
 const char *email = "nagiosplug-devel@lists.sourceforge.net";
        
 #include "common.h"
@@ -171,9 +166,13 @@ main (int argc, char *argv[])
                {"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} 
+               {"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);
@@ -181,8 +180,8 @@ main (int argc, char *argv[])
        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) {
@@ -208,61 +207,61 @@ main (int argc, char *argv[])
                        print_help ();
                        return STATE_OK;
                case 'V':
-                       print_revision (progname, revision);
+                       print_revision (progname, NP_VERSION);
                        return STATE_OK;
                default:
-                       usage2 (_("Unknown argument"), optarg);
+                       usage5 ();
                }
+       }
 
-               if (optind < argc) {
-                       device = argv[optind];
-               }
+       if (optind < argc) {
+               device = argv[optind];
+       }
 
-               if (!device) {
-                       print_help ();
-                       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 = nagios (&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;
 }
 
@@ -367,6 +366,7 @@ nagios (values_t * p, thresholds_t * t)
                        prefailure > 1 ? 's' : ' ',
                        failed,
                  total);
+               status=STATE_CRITICAL;
                break;
        case ADVISORY:
                printf (_("WARNING - %d Harddrive Advisor%s Detected. %d/%d tests failed.\n"),
@@ -374,14 +374,16 @@ nagios (values_t * p, thresholds_t * t)
                        advisory > 1 ? "ies" : "y",
                        failed,
                        total);
+               status=STATE_WARNING;
                break;
        case OPERATIONAL:
                printf (_("OK - Operational (%d/%d tests passed)\n"), passed, total);
+               status=STATE_OK;
                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);
-               status = -1;
+               status = STATE_UNKNOWN;
                break;
        }
        return status;
@@ -433,23 +435,6 @@ print_values (values_t * p, thresholds_t * t)
 }
 
 
-
-void
-print_thresholds (thresholds_t * p) 
-{
-       threshold_t * threshold = p->thresholds;
-       int i;
-       printf ("\n");
-       printf ("SmartRevision=%d\n", p->revision);
-       for (i = 0; i < NR_ATTRIBUTES; i++) {
-               if (threshold->id) {
-                       printf ("Id=%3d, Threshold=%3d\n", threshold->id,
-                                                       threshold->threshold); }
-               ++threshold;
-       }
-       printf ("CheckSum=%d\n", p->checksum);
-}
-
 int
 smart_cmd_simple (int fd, enum SmartCommand command, __u8 val0, char show_error) 
 {
@@ -492,35 +477,60 @@ smart_read_thresholds (int fd, thresholds_t * thresholds)
 void
 print_help (void)
 {
-       print_revision (progname, revision);
+       print_revision (progname, NP_VERSION);
 
        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 this host's IDE hard drive through the (Linux specific) SMART command interface.\n\n"));
-       
-       printf ("\
-Usage: %s [DEVICE] [OPTION]\n\
- -d, --device=DEVICE\n\
-    Select device DEVICE\n\
- -i, --immediate\n\
-    Perform immediately offline tests\n\
- -q, --quiet-check\n\
-    Returns the number of failed tests\n\
- -1, --auto-on\n\
-    Turn on automatic offline tests\n\
- -0, --auto-off\n\
-    Turn off automatic offline tests\n\
- -n, --nagios\n\
-    Output suitable for Nagios\n", progname);
+       printf (_("This plugin checks a local hard drive with the (Linux specific) SMART interface [http://smartlinux.sourceforge.net/smart/index.php]."));
+
+  printf ("\n\n");
+
+  print_usage ();
+
+  printf (UT_HELP_VRSN);
+  printf (UT_EXTRA_OPTS);
+
+  printf (" %s\n", "-d, --device=DEVICE");
+  printf ("    %s\n", _("Select device DEVICE"));
+  printf ("    %s\n", _("Note: if the device is selected with this option, _no_ other options are accepted"));
+  printf (" %s\n", "-i, --immediate");
+  printf ("    %s\n", _("Perform immediately offline tests"));
+  printf (" %s\n", "-q, --quiet-check");
+  printf ("    %s\n", _("Returns the number of failed tests"));
+  printf (" %s\n", "-1, --auto-on");
+  printf ("    %s\n", _("Turn on automatic offline tests"));
+  printf (" %s\n", "-0, --auto-off");
+  printf ("    %s\n", _("Turn off automatic offline tests"));
+  printf (" %s\n", "-n, --nagios");
+  printf ("    %s\n", _("Output suitable for Nagios"));
+
+#ifdef NP_EXTRA_OPTS
+  printf ("\n");
+  printf ("%s\n", _("Notes:"));
+  printf (UT_EXTRA_OPTS_NOTES);
+#endif
+
+  printf (UT_SUPPORT);
 }
 
+ /* todo : add to the long nanual as example
+ *
+ *     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
+ *       - Returns 1 on advisories
+ *       - Returns 2 on prefailure
+ *       - Returns -1 not too often
+ */
+
 
 void
 print_usage (void)
 {
-       printf ("\
-Usage: %s [-d <device>] [-i <immediate>] [-q quiet] [-1 <auto-on>]\n\
-                        [-O <auto-off>] [-n <nagios>]\n", progname);
+  printf (_("Usage:"));
+  printf ("%s [-d <device>] [-i <immediate>] [-q quiet] [-1 <auto-on>]",progname);
+  printf (" [-O <auto-off>] [-n <nagios>]\n");
 }