Code

internationalization fixes
authorBenoit Mortier <opensides@users.sourceforge.net>
Sat, 4 Dec 2004 12:12:30 +0000 (12:12 +0000)
committerBenoit Mortier <opensides@users.sourceforge.net>
Sat, 4 Dec 2004 12:12:30 +0000 (12:12 +0000)
bugfixes

git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1001 f882894a-f735-0410-b71e-b25c423dba1c

17 files changed:
plugins/Makefile.am
plugins/check_by_ssh.c
plugins/check_dig.c
plugins/check_http.c
plugins/check_ide-smart.c [deleted file]
plugins/check_ide_smart.c [new file with mode: 0644]
plugins/check_mrtg.c
plugins/check_nt.c
plugins/check_nwstat.c
plugins/check_overcr.c
plugins/check_real.c
plugins/check_smtp.c
plugins/check_swap.c
plugins/check_tcp.c
plugins/check_time.c
plugins/check_udp.c
po/POTFILES.in

index feccd0051e2bfd1aeb30160a97f7ad09976216ca..b87154d06ac39f835c8133e8d298182ed7c1f771 100644 (file)
@@ -21,7 +21,7 @@ check_tcp_programs = check_ftp check_imap check_nntp check_pop check_udp2 \
 
 EXTRA_PROGRAMS = check_mysql check_radius check_pgsql check_snmp check_hpjd \
        check_swap check_fping check_ldap check_game check_dig \
-       check_nagios check_by_ssh check_dns check_nt check_ide-smart check_procs
+       check_nagios check_by_ssh check_dns check_nt check_ide_smart check_procs
 
 EXTRA_DIST = t utils.c netutils.c popen.c utils.h netutils.h popen.h common.h \
        getaddrinfo.c getaddrinfo.h gethostbyname.c gethostbyname.h
@@ -76,6 +76,7 @@ check_udp_LDADD = $(NETLIBS)
 check_ups_LDADD = $(NETLIBS)
 check_users_LDADD = $(BASEOBJS) popen.o
 check_by_ssh_LDADD = $(NETLIBS) popen.o
+check_ide_smart_LDADD = $(BASEOBJS)
 negate_LDADD = $(BASEOBJS) popen.o
 urlize_LDADD = $(BASEOBJS) popen.o
 
@@ -111,6 +112,7 @@ check_udp_DEPENDENCIES = check_udp.c $(NETOBJS) $(DEPLIBS)
 check_ups_DEPENDENCIES = check_ups.c $(NETOBJS) $(DEPLIBS)
 check_users_DEPENDENCIES = check_users.c $(BASEOBJS) popen.o $(DEPLIBS)
 check_by_ssh_DEPENDENCIES = check_by_ssh.c $(NETOBJS) popen.o $(DEPLIBS)
+check_ide_smart_DEPENDENCIES = check_ide_smart.c $(BASEOBJS) $(DEPLIBS)
 negate_DEPENDENCIES = negate.c $(BASEOBJS) popen.o $(DEPLIBS)
 urlize_DEPENDENCIES = urlize.c $(BASEOBJS) popen.o $(DEPLIBS)
 check_icmp_DEPENDENCIES = check_icmp.c $(DEPLIBS)
index 6d0f4c2c8f4629ef37de99bc12706733f85c0e64..d34b2678fc9561fdfe6921a61e2e33c3c1dc7c07 100644 (file)
@@ -411,5 +411,5 @@ print_usage (void)
 {
        printf ("\n\
 Usage: %s [-f46] [-t timeout] [-i identity] [-l user] -H <host> -C <command>\n\
-          [-n name] [-s servicelist] [-O outputfile] [-p port]\n", progname);
+                  [-n name] [-s servicelist] [-O outputfile] [-p port]\n", progname);
 }
index 390718680685f7a638013fe3622d2cb8b43fbdd3..a44d578637bd84a6fa2451967e05f879ae18e6c1 100644 (file)
@@ -355,6 +355,6 @@ print_usage (void)
 {
        printf ("\
 Usage: %s -H host -l lookup [-p <server port>] [-T <query type>]\n\
-         [-w <warning interval>] [-c <critical interval>] [-t <timeout>]\n\
-         [-a <expected answer address>] [-v]\n", progname);
+                  [-w <warning interval>] [-c <critical interval>] [-t <timeout>]\n\
+                  [-a <expected answer address>] [-v]\n", progname);
 }
index c0b18fc84c46fdb4b27769645c7743d42493c52c..6f8ad9a42b52dd8f569e95720ae8f6c1c28c111b 100644 (file)
@@ -1496,5 +1496,5 @@ Usage: %s -H <vhost> | -I <IP-address>) [-u <uri>] [-p <port>]\n\
                   [-a auth] [-f <ok | warn | critcal | follow>] [-e <expect>]\n\
                   [-s string] [-l] [-r <regex> | -R <case-insensitive regex>]\n\
                   [-P string] [-m min_pg_size] [-4|-6] [-N] [-M <age>]\n\
-                                                                       [-A string] [-k string]\n"), progname);
+                  [-A string] [-k string]\n"), progname);
 }
diff --git a/plugins/check_ide-smart.c b/plugins/check_ide-smart.c
deleted file mode 100644 (file)
index 1c0af31..0000000
+++ /dev/null
@@ -1,523 +0,0 @@
-/*
- *  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 --net-saint option was added.
- *
- *        Run with:  check_ide-smart --net-saint [-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$
- */
-
-const char *progname = "check_ide_smart";
-const char *revision = "$Revision$";
-const char *copyright = "2000-2004";
-const char *email = "nagiosplug-devel@lists.sourceforge.net";
-       
-#include "common.h"
-#include "utils.h"
-
-#include <sys/stat.h>
-#include <sys/ioctl.h>
-#include <fcntl.h>
-#include <linux/hdreg.h>
-#include <linux/types.h>
-#include <errno.h>
-       
-#define NR_ATTRIBUTES  30
-       
-#ifndef TRUE
-#define TRUE 1
-#endif /*  */
-       
-#define PREFAILURE 2
-#define ADVISORY 1
-#define OPERATIONAL 0
-#define UNKNOWN -1
-
-typedef struct threshold_s
-{
-       __u8 id;
-       __u8 threshold;
-       __u8 reserved[10];
-}
-__attribute__ ((packed)) threshold_t;
-
-typedef struct thresholds_s
-{
-       __u16 revision;
-       threshold_t thresholds[NR_ATTRIBUTES];
-       __u8 reserved[18];
-       __u8 vendor[131];
-       __u8 checksum;
-}
-__attribute__ ((packed)) thresholds_t;
-
-typedef struct value_s
-{
-       __u8 id;
-       __u16 status;
-       __u8 value;
-       __u8 vendor[8];
-}
-__attribute__ ((packed)) value_t;
-
-typedef struct values_s
-{
-       __u16 revision;
-       value_t values[NR_ATTRIBUTES];
-       __u8 offline_status;
-       __u8 vendor1;
-       __u16 offline_timeout;
-       __u8 vendor2;
-       __u8 offline_capability;
-       __u16 smart_capability;
-       __u8 reserved[16];
-       __u8 vendor[125];
-       __u8 checksum;
-}
-__attribute__ ((packed)) values_t;
-
-struct
-{
-       __u8 value;
-       char *text;
-}
-
-offline_status_text[] =
-       {
-               {0x00, "NeverStarted"},
-               {0x02, "Completed"},
-               {0x04, "Suspended"},
-               {0x05, "Aborted"},
-               {0x06, "Failed"},
-               {0, 0}
-       };
-
-struct
-{
-       __u8 value;
-       char *text;
-}
-
-smart_command[] =
-       {
-               {SMART_ENABLE, "SMART_ENABLE"},
-               {SMART_DISABLE, "SMART_DISABLE"},
-               {SMART_IMMEDIATE_OFFLINE, "SMART_IMMEDIATE_OFFLINE"},
-               {SMART_AUTO_OFFLINE, "SMART_AUTO_OFFLINE"}
-       };
-
-
-/* Index to smart_command table, keep in order */ 
-enum SmartCommand 
-       { SMART_CMD_ENABLE,
-               SMART_CMD_DISABLE,
-               SMART_CMD_IMMEDIATE_OFFLINE,
-               SMART_CMD_AUTO_OFFLINE 
-       };
-
-
-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) 
-{
-       int i;
-       for (i = 0; offline_status_text[i].text; i++) {
-               if (offline_status_text[i].value == status) {
-                       return offline_status_text[i].text;
-               }
-       }
-       return "UNKNOW";
-}
-
-
-
-int
-smart_read_values (int fd, values_t * values) 
-{
-       int e;
-       __u8 args[4 + 512];
-       args[0] = WIN_SMART;
-       args[1] = 0;
-       args[2] = SMART_READ_VALUES;
-       args[3] = 1;
-       if (ioctl (fd, HDIO_DRIVE_CMD, &args)) {
-               e = errno;
-               printf (_("CRITICAL - SMART_READ_VALUES: %s\n"), strerror (errno));
-               return e;
-       }
-       memcpy (values, args + 4, 512);
-       return 0;
-}
-
-
-
-int
-values_not_passed (values_t * p, thresholds_t * t) 
-{
-       value_t * value = p->values;
-       threshold_t * threshold = t->thresholds;
-       int failed = 0;
-       int passed = 0;
-       int i;
-       for (i = 0; i < NR_ATTRIBUTES; i++) {
-               if (value->id && threshold->id && value->id == threshold->id) {
-                       if (value->value <= threshold->threshold) {
-                               ++failed;
-                       }
-                       else {
-                               ++passed;
-                       }
-               }
-               ++value;
-               ++threshold;
-       }
-       return (passed ? -failed : 2);
-}
-
-
-
-int
-net_saint (values_t * p, thresholds_t * t) 
-{
-       value_t * value = p->values;
-       threshold_t * threshold = t->thresholds;
-       int status = OPERATIONAL;
-       int prefailure = 0;
-       int advisory = 0;
-       int failed = 0;
-       int passed = 0;
-       int total = 0;
-       int i;
-       for (i = 0; i < NR_ATTRIBUTES; i++) {
-               if (value->id && threshold->id && value->id == threshold->id) {
-                       if (value->value <= threshold->threshold) {
-                               ++failed;
-                               if (value->status & 1) {
-                                       status = PREFAILURE;
-                                       ++prefailure;
-                               }
-                               else {
-                                       status = ADVISORY;
-                                       ++advisory;
-                               }
-                       }
-                       else {
-                               ++passed;
-                       }
-                       ++total;
-               }
-               ++value;
-               ++threshold;
-       }
-       switch (status) {
-       case PREFAILURE:
-               printf (_("CRITICAL - %d Harddrive PreFailure%cDetected! %d/%d tests failed.\n"),
-                       prefailure,
-                       prefailure > 1 ? 's' : ' ',
-                       failed,
-                 total);
-               break;
-       case ADVISORY:
-               printf (_("WARNING - %d Harddrive Advisor%s Detected. %d/%d tests failed.\n"),
-                       advisory,
-                       advisory > 1 ? "ies" : "y",
-                       failed,
-                       total);
-               break;
-       case OPERATIONAL:
-               printf (_("OK - Operational (%d/%d tests passed)\n"), passed, total);
-               break;
-       default:
-               printf (_("ERROR - Status '%d' uknown. %d/%d tests passed\n"), status,
-                                               passed, total);
-               status = -1;
-               break;
-       }
-       return status;
-}
-
-
-
-void
-print_value (value_t * p, threshold_t * t) 
-{
-       printf ("Id=%3d, Status=%2d {%s , %s}, Value=%3d, Threshold=%3d, %s\n",
-                                       p->id, p->status, p->status & 1 ? "PreFailure" : "Advisory   ",
-                                       p->status & 2 ? "OnLine " : "OffLine", p->value, t->threshold,
-                                       p->value > t->threshold ? "Passed" : "Failed");
-}
-
-
-
-void
-print_values (values_t * p, thresholds_t * t) 
-{
-       value_t * value = p->values;
-       threshold_t * threshold = t->thresholds;
-       int i;
-       for (i = 0; i < NR_ATTRIBUTES; i++) {
-               if (value->id && threshold->id && value->id == threshold->id) {
-                       print_value (value++, threshold++);
-               }
-       }
-       printf
-               (_("OffLineStatus=%d {%s}, AutoOffLine=%s, OffLineTimeout=%d minutes\n"),
-                p->offline_status,
-                get_offline_text (p->offline_status & 0x7f),
-                (p->offline_status & 0x80 ? "Yes" : "No"),
-                p->offline_timeout / 60);
-       printf
-               (_("OffLineCapability=%d {%s %s %s}\n"),
-                p->offline_capability,
-                p->offline_capability & 1 ? "Immediate" : "",
-                p->offline_capability & 2 ? "Auto" : "",
-                p->offline_capability & 4 ? "AbortOnCmd" : "SuspendOnCmd");
-       printf
-               (_("SmartRevision=%d, CheckSum=%d, SmartCapability=%d {%s %s}\n"),
-                p->revision,
-                p->checksum,
-                p->smart_capability,
-                p->smart_capability & 1 ? "SaveOnStandBy" : "",
-                p->smart_capability & 2 ? "AutoSave" : "");
-}
-
-
-
-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) 
-{
-       int e = 0;
-       __u8 args[4];
-       args[0] = WIN_SMART;
-       args[1] = val0;
-       args[2] = smart_command[command].value;
-       args[3] = 0;
-       if (ioctl (fd, HDIO_DRIVE_CMD, &args)) {
-               e = errno;
-               if (show_error) {
-                       printf (_("CRITICAL - %s: %s\n"), smart_command[command].text, strerror (errno));
-               }
-       }
-       return e;
-}
-
-
-
-int
-smart_read_thresholds (int fd, thresholds_t * thresholds) 
-{
-       int e;
-       __u8 args[4 + 512];
-       args[0] = WIN_SMART;
-  args[1] = 0;
-  args[2] = SMART_READ_THRESHOLDS;
-  args[3] = 1;
-       if (ioctl (fd, HDIO_DRIVE_CMD, &args)) {
-               e = errno;
-               printf (_("CRITICAL - SMART_READ_THRESHOLDS: %s\n"), strerror (errno));
-               return e;
-       }
-       memcpy (thresholds, args + 4, 512);
-       return 0;
-}
-
-
-
-void
-print_help () 
-{
-       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 (_("\
-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, --net-saint\n\
-    Output suitable for Net Saint\n", progname);
-}
-
-
-
-void
-print_usage (void)
-{
-       printf ("Usage: %s \n"), progname);
-}
diff --git a/plugins/check_ide_smart.c b/plugins/check_ide_smart.c
new file mode 100644 (file)
index 0000000..1c0af31
--- /dev/null
@@ -0,0 +1,523 @@
+/*
+ *  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 --net-saint option was added.
+ *
+ *        Run with:  check_ide-smart --net-saint [-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$
+ */
+
+const char *progname = "check_ide_smart";
+const char *revision = "$Revision$";
+const char *copyright = "2000-2004";
+const char *email = "nagiosplug-devel@lists.sourceforge.net";
+       
+#include "common.h"
+#include "utils.h"
+
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <linux/hdreg.h>
+#include <linux/types.h>
+#include <errno.h>
+       
+#define NR_ATTRIBUTES  30
+       
+#ifndef TRUE
+#define TRUE 1
+#endif /*  */
+       
+#define PREFAILURE 2
+#define ADVISORY 1
+#define OPERATIONAL 0
+#define UNKNOWN -1
+
+typedef struct threshold_s
+{
+       __u8 id;
+       __u8 threshold;
+       __u8 reserved[10];
+}
+__attribute__ ((packed)) threshold_t;
+
+typedef struct thresholds_s
+{
+       __u16 revision;
+       threshold_t thresholds[NR_ATTRIBUTES];
+       __u8 reserved[18];
+       __u8 vendor[131];
+       __u8 checksum;
+}
+__attribute__ ((packed)) thresholds_t;
+
+typedef struct value_s
+{
+       __u8 id;
+       __u16 status;
+       __u8 value;
+       __u8 vendor[8];
+}
+__attribute__ ((packed)) value_t;
+
+typedef struct values_s
+{
+       __u16 revision;
+       value_t values[NR_ATTRIBUTES];
+       __u8 offline_status;
+       __u8 vendor1;
+       __u16 offline_timeout;
+       __u8 vendor2;
+       __u8 offline_capability;
+       __u16 smart_capability;
+       __u8 reserved[16];
+       __u8 vendor[125];
+       __u8 checksum;
+}
+__attribute__ ((packed)) values_t;
+
+struct
+{
+       __u8 value;
+       char *text;
+}
+
+offline_status_text[] =
+       {
+               {0x00, "NeverStarted"},
+               {0x02, "Completed"},
+               {0x04, "Suspended"},
+               {0x05, "Aborted"},
+               {0x06, "Failed"},
+               {0, 0}
+       };
+
+struct
+{
+       __u8 value;
+       char *text;
+}
+
+smart_command[] =
+       {
+               {SMART_ENABLE, "SMART_ENABLE"},
+               {SMART_DISABLE, "SMART_DISABLE"},
+               {SMART_IMMEDIATE_OFFLINE, "SMART_IMMEDIATE_OFFLINE"},
+               {SMART_AUTO_OFFLINE, "SMART_AUTO_OFFLINE"}
+       };
+
+
+/* Index to smart_command table, keep in order */ 
+enum SmartCommand 
+       { SMART_CMD_ENABLE,
+               SMART_CMD_DISABLE,
+               SMART_CMD_IMMEDIATE_OFFLINE,
+               SMART_CMD_AUTO_OFFLINE 
+       };
+
+
+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) 
+{
+       int i;
+       for (i = 0; offline_status_text[i].text; i++) {
+               if (offline_status_text[i].value == status) {
+                       return offline_status_text[i].text;
+               }
+       }
+       return "UNKNOW";
+}
+
+
+
+int
+smart_read_values (int fd, values_t * values) 
+{
+       int e;
+       __u8 args[4 + 512];
+       args[0] = WIN_SMART;
+       args[1] = 0;
+       args[2] = SMART_READ_VALUES;
+       args[3] = 1;
+       if (ioctl (fd, HDIO_DRIVE_CMD, &args)) {
+               e = errno;
+               printf (_("CRITICAL - SMART_READ_VALUES: %s\n"), strerror (errno));
+               return e;
+       }
+       memcpy (values, args + 4, 512);
+       return 0;
+}
+
+
+
+int
+values_not_passed (values_t * p, thresholds_t * t) 
+{
+       value_t * value = p->values;
+       threshold_t * threshold = t->thresholds;
+       int failed = 0;
+       int passed = 0;
+       int i;
+       for (i = 0; i < NR_ATTRIBUTES; i++) {
+               if (value->id && threshold->id && value->id == threshold->id) {
+                       if (value->value <= threshold->threshold) {
+                               ++failed;
+                       }
+                       else {
+                               ++passed;
+                       }
+               }
+               ++value;
+               ++threshold;
+       }
+       return (passed ? -failed : 2);
+}
+
+
+
+int
+net_saint (values_t * p, thresholds_t * t) 
+{
+       value_t * value = p->values;
+       threshold_t * threshold = t->thresholds;
+       int status = OPERATIONAL;
+       int prefailure = 0;
+       int advisory = 0;
+       int failed = 0;
+       int passed = 0;
+       int total = 0;
+       int i;
+       for (i = 0; i < NR_ATTRIBUTES; i++) {
+               if (value->id && threshold->id && value->id == threshold->id) {
+                       if (value->value <= threshold->threshold) {
+                               ++failed;
+                               if (value->status & 1) {
+                                       status = PREFAILURE;
+                                       ++prefailure;
+                               }
+                               else {
+                                       status = ADVISORY;
+                                       ++advisory;
+                               }
+                       }
+                       else {
+                               ++passed;
+                       }
+                       ++total;
+               }
+               ++value;
+               ++threshold;
+       }
+       switch (status) {
+       case PREFAILURE:
+               printf (_("CRITICAL - %d Harddrive PreFailure%cDetected! %d/%d tests failed.\n"),
+                       prefailure,
+                       prefailure > 1 ? 's' : ' ',
+                       failed,
+                 total);
+               break;
+       case ADVISORY:
+               printf (_("WARNING - %d Harddrive Advisor%s Detected. %d/%d tests failed.\n"),
+                       advisory,
+                       advisory > 1 ? "ies" : "y",
+                       failed,
+                       total);
+               break;
+       case OPERATIONAL:
+               printf (_("OK - Operational (%d/%d tests passed)\n"), passed, total);
+               break;
+       default:
+               printf (_("ERROR - Status '%d' uknown. %d/%d tests passed\n"), status,
+                                               passed, total);
+               status = -1;
+               break;
+       }
+       return status;
+}
+
+
+
+void
+print_value (value_t * p, threshold_t * t) 
+{
+       printf ("Id=%3d, Status=%2d {%s , %s}, Value=%3d, Threshold=%3d, %s\n",
+                                       p->id, p->status, p->status & 1 ? "PreFailure" : "Advisory   ",
+                                       p->status & 2 ? "OnLine " : "OffLine", p->value, t->threshold,
+                                       p->value > t->threshold ? "Passed" : "Failed");
+}
+
+
+
+void
+print_values (values_t * p, thresholds_t * t) 
+{
+       value_t * value = p->values;
+       threshold_t * threshold = t->thresholds;
+       int i;
+       for (i = 0; i < NR_ATTRIBUTES; i++) {
+               if (value->id && threshold->id && value->id == threshold->id) {
+                       print_value (value++, threshold++);
+               }
+       }
+       printf
+               (_("OffLineStatus=%d {%s}, AutoOffLine=%s, OffLineTimeout=%d minutes\n"),
+                p->offline_status,
+                get_offline_text (p->offline_status & 0x7f),
+                (p->offline_status & 0x80 ? "Yes" : "No"),
+                p->offline_timeout / 60);
+       printf
+               (_("OffLineCapability=%d {%s %s %s}\n"),
+                p->offline_capability,
+                p->offline_capability & 1 ? "Immediate" : "",
+                p->offline_capability & 2 ? "Auto" : "",
+                p->offline_capability & 4 ? "AbortOnCmd" : "SuspendOnCmd");
+       printf
+               (_("SmartRevision=%d, CheckSum=%d, SmartCapability=%d {%s %s}\n"),
+                p->revision,
+                p->checksum,
+                p->smart_capability,
+                p->smart_capability & 1 ? "SaveOnStandBy" : "",
+                p->smart_capability & 2 ? "AutoSave" : "");
+}
+
+
+
+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) 
+{
+       int e = 0;
+       __u8 args[4];
+       args[0] = WIN_SMART;
+       args[1] = val0;
+       args[2] = smart_command[command].value;
+       args[3] = 0;
+       if (ioctl (fd, HDIO_DRIVE_CMD, &args)) {
+               e = errno;
+               if (show_error) {
+                       printf (_("CRITICAL - %s: %s\n"), smart_command[command].text, strerror (errno));
+               }
+       }
+       return e;
+}
+
+
+
+int
+smart_read_thresholds (int fd, thresholds_t * thresholds) 
+{
+       int e;
+       __u8 args[4 + 512];
+       args[0] = WIN_SMART;
+  args[1] = 0;
+  args[2] = SMART_READ_THRESHOLDS;
+  args[3] = 1;
+       if (ioctl (fd, HDIO_DRIVE_CMD, &args)) {
+               e = errno;
+               printf (_("CRITICAL - SMART_READ_THRESHOLDS: %s\n"), strerror (errno));
+               return e;
+       }
+       memcpy (thresholds, args + 4, 512);
+       return 0;
+}
+
+
+
+void
+print_help () 
+{
+       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 (_("\
+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, --net-saint\n\
+    Output suitable for Net Saint\n", progname);
+}
+
+
+
+void
+print_usage (void)
+{
+       printf ("Usage: %s \n"), progname);
+}
index f895321f742aa67af8612df9fe909caceebbc8f1..bd37aefff893d18c441b7cefdbd8d53b4093a5d0 100644 (file)
@@ -378,5 +378,5 @@ print_usage (void)
        printf ("\
 Usage: %s -F log_file -a <AVG | MAX> -v variable -w warning -c critical\n\
                   [-l label] [-u units] [-e expire_minutes] [-t timeout]\n\
-                                                                       [-v]\n", progname);
+                  [-v]\n", progname);
 }
index 03a7c5d64405b8f061a7116bbe5eb7d02df80b99..e52b5a211d6437c5c91757c0427ebf75412eca40 100644 (file)
@@ -688,5 +688,5 @@ void print_usage(void)
 {
        printf("\
 Usage: %s -H host -v variable [-p port] [-w warning] [-c critical]\n\
-                  [-l params] [-d SHOWALL] [-t timeout]\n", progname);
+                [-l params] [-d SHOWALL] [-t timeout]\n", progname);
 }
index 53e3f1d757d01e155aa70e617e235d4ff4f7ce34..d8913bce950772f46808d200ee39c2677e550702 100644 (file)
@@ -989,5 +989,5 @@ void print_usage(void)
 {
        printf ("\
 Usage: %s -H host [-p port] [-v variable] [-w warning] [-c critical]\n\
-                  [-t timeout].\n", progname);
+                    [-t timeout].\n", progname);
 }
index 756402bd34528be76a7a56893ab5f46e3ce97de6..9bf40d3cac151b90bd075516e183dbc29168cc43 100644 (file)
@@ -465,5 +465,5 @@ print_usage (void)
 {
        printf ("\
 Usage: %s -H host [-p port] [-v variable] [-w warning] [-c critical]\n\
-                  [-t timeout]\n", progname);
+                    [-t timeout]\n", progname);
 }
index 492848c77ed9ed20ab06c3c4b117c2ef7b2c4d8d..30424656ef411a3c3af0646865b7298e5de2d172 100644 (file)
@@ -312,7 +312,7 @@ process_arguments (int argc, char **argv)
                                server_port = atoi (optarg);
                        }
                        else {
-                               usage (_("Port must be a positive integer\n"));
+                               usage4 (_("Port must be a positive integer"));
                        }
                        break;
                case 'w':                                                                       /* warning time threshold */
@@ -321,7 +321,7 @@ process_arguments (int argc, char **argv)
                                check_warning_time = TRUE;
                        }
                        else {
-                               usage (_("Warning time must be a positive integer\n"));
+                               usage4 (_("Warning time must be a positive integer"));
                        }
                        break;
                case 'c':                                                                       /* critical time threshold */
@@ -330,7 +330,7 @@ process_arguments (int argc, char **argv)
                                check_critical_time = TRUE;
                        }
                        else {
-                               usage (_("Critical time must be a nonnegative integer\n"));
+                               usage4 (_("Critical time must be a nonnegative integer"));
                        }
                        break;
                case 'v':                                                                       /* verbose */
@@ -341,7 +341,7 @@ process_arguments (int argc, char **argv)
                                socket_timeout = atoi (optarg);
                        }
                        else {
-                               usage (_("Time interval must be a nonnegative integer\n"));
+                               usage4 (_("Time interval must be a nonnegative integer"));
                        }
                        break;
                case 'V':                                                                       /* version */
index f12b69e99927928e2acd3d0ce3db17f03913b643..ab1b950797d4c32bed480261f88fe14756c26851 100644 (file)
@@ -295,7 +295,7 @@ process_arguments (int argc, char **argv)
                        if (is_intpos (optarg))
                                server_port = atoi (optarg);
                        else
-                               usage (_("Port must be a positive integer\n"));
+                               usage4 (_("Port must be a positive integer"));
                        break;
                case 'f':                                                                       /* from argument */
                        from_arg = optarg;
@@ -330,7 +330,7 @@ process_arguments (int argc, char **argv)
                                check_critical_time = TRUE;
                        }
                        else {
-                               usage (_("Critical time must be a positive integer\n"));
+                               usage4 (_("Critical time must be a positive integer"));
                        }
                        break;
                case 'w':                                                                       /* warning time threshold */
@@ -339,7 +339,7 @@ process_arguments (int argc, char **argv)
                                check_warning_time = TRUE;
                        }
                        else {
-                               usage (_("Warning time must be a positive integer\n"));
+                               usage4 (_("Warning time must be a positive integer"));
                        }
                        break;
                case 'v':                                                                       /* verbose */
@@ -350,7 +350,7 @@ process_arguments (int argc, char **argv)
                                socket_timeout = atoi (optarg);
                        }
                        else {
-                               usage (_("Time interval must be a positive integer\n"));
+                               usage4 (_("Time interval must be a positive integer"));
                        }
                        break;
                case '4':
@@ -360,7 +360,7 @@ process_arguments (int argc, char **argv)
 #ifdef USE_IPV6
                        address_family = AF_INET6;
 #else
-                       usage (_("IPv6 support not available\n"));
+                       usage4 (_("IPv6 support not available"));
 #endif
                        break;
                case 'V':                                                                       /* version */
index ba353bc0b89a44580860c6c94815806f61ecf2fa..3067f85cf240cc8a7e479a54e2a5eb0dd033e9fd 100644 (file)
@@ -515,6 +515,6 @@ void
 print_usage (void)
 {
        printf ("\
-       Usage: %s [-av] -w <percent_free>%% -c <percent_free>%%\n\
-         %s [-av] -w <bytes_free> -c <bytes_free>\n", progname, progname);
+Usage: %s [-av] -w <percent_free>%% -c <percent_free>%%\n\
+       %s [-av] -w <bytes_free> -c <bytes_free>\n", progname, progname);
 }
index 418438a3e7ea23631e782962564b4ddecdc7416f..ce57631a5c89543d35043ec855f36fcc012039cb 100644 (file)
@@ -474,7 +474,7 @@ process_arguments (int argc, char **argv)
 #ifdef USE_IPV6
                        address_family = AF_INET6;
 #else
-                       usage (_("IPv6 support not available\n"));
+                       usage4 (_("IPv6 support not available"));
 #endif
                        break;
                case 'H':                 /* hostname */
@@ -484,7 +484,7 @@ process_arguments (int argc, char **argv)
                        break;
                case 'c':                 /* critical */
                        if (!is_intnonneg (optarg))
-                               usage (_("Critical threshold must be a positive integer\n"));
+                               usage4 (_("Critical threshold must be a positive integer"));
                        else
                                critical_time = strtod (optarg, NULL);
                        check_critical_time = TRUE;
@@ -494,7 +494,7 @@ process_arguments (int argc, char **argv)
                        break;
                case 'w':                 /* warning */
                        if (!is_intnonneg (optarg))
-                               usage (_("Warning threshold must be a positive integer\n"));
+                               usage4 (_("Warning threshold must be a positive integer"));
                        else
                                warning_time = strtod (optarg, NULL);
                        check_warning_time = TRUE;
@@ -509,13 +509,13 @@ process_arguments (int argc, char **argv)
                        break;
                case 't':                 /* timeout */
                        if (!is_intpos (optarg))
-                               usage (_("Timeout interval must be a positive integer\n"));
+                               usage4 (_("Timeout interval must be a positive integer"));
                        else
                                socket_timeout = atoi (optarg);
                        break;
                case 'p':                 /* port */
                        if (!is_intpos (optarg))
-                               usage (_("Port must be a positive integer\n"));
+                               usage4 (_("Port must be a positive integer"));
                        else
                                server_port = atoi (optarg);
                        break;
@@ -532,7 +532,7 @@ process_arguments (int argc, char **argv)
                        break;
                case 'm':
                        if (!is_intpos (optarg))
-                               usage (_("Maxbytes must be a positive integer\n"));
+                               usage4 (_("Maxbytes must be a positive integer"));
                        else
                                maxbytes = atoi (optarg);
                case 'q':
@@ -546,13 +546,13 @@ process_arguments (int argc, char **argv)
                        else if (!strncmp(optarg,"crit",4))
                                econn_refuse_state = STATE_CRITICAL;
                        else
-                               usage (_("Refuse must be one of ok, warn, crit\n"));
+                               usage4 (_("Refuse must be one of ok, warn, crit"));
                        break;
                case 'd':
                        if (is_intpos (optarg))
                                delay = atoi (optarg);
                        else
-                               usage (_("Delay must be a positive integer\n"));
+                               usage4 (_("Delay must be a positive integer"));
                        break;
                  case 'D': /* Check SSL cert validity - days 'til certificate expiration */
 #ifdef HAVE_SSL
index dae2dd5ad031f3371614fcabcd06696d9e04b4db..63d7ee255bb94ed0dc2a21196ed728161dbe80b8 100644 (file)
@@ -241,11 +241,11 @@ process_arguments (int argc, char **argv)
                                        check_warning_time = TRUE;
                                }
                                else {
-                                       usage (_("Warning thresholds must be a positive integer\n"));
+                                       usage4 (_("Warning thresholds must be a positive integer"));
                                }
                        }
                        else {
-                               usage (_("Warning threshold must be a positive integer\n"));
+                               usage4 (_("Warning threshold must be a positive integer"));
                        }
                        break;
                case 'c':                                                                       /* critical-variance */
@@ -260,30 +260,30 @@ process_arguments (int argc, char **argv)
                                        check_critical_time = TRUE;
                                }
                                else {
-                                       usage (_("Critical thresholds must be a positive integer\n"));
+                                       usage4 (_("Critical thresholds must be a positive integer"));
                                }
                        }
                        else {
-                               usage (_("Critical threshold must be a positive integer\n"));
+                               usage4 (_("Critical threshold must be a positive integer"));
                        }
                        break;
                case 'W':                                                                       /* warning-connect */
                        if (!is_intnonneg (optarg))
-                               usage (_("Warning threshold must be a positive integer\n"));
+                               usage4 (_("Warning threshold must be a positive integer"));
                        else
                                warning_time = atoi (optarg);
                        check_warning_time = TRUE;
                        break;
                case 'C':                                                                       /* critical-connect */
                        if (!is_intnonneg (optarg))
-                               usage (_("Critical threshold must be a positive integer\n"));
+                               usage4 (_("Critical threshold must be a positive integer"));
                        else
                                critical_time = atoi (optarg);
                        check_critical_time = TRUE;
                        break;
                case 'p':                                                                       /* port */
                        if (!is_intnonneg (optarg))
-                               usage (_("Port must be a positive integer\n"));
+                               usage4 (_("Port must be a positive integer"));
                        else
                                server_port = atoi (optarg);
                        break;
@@ -306,7 +306,7 @@ process_arguments (int argc, char **argv)
                        server_address = argv[c];
                }
                else {
-                       usage (_("Hostname was not supplied\n"));
+                       usage4 (_("Hostname was not supplied"));
                }
        }
 
index aa8be1c2731d6dd5b4326b7d8cc2068d5d4f53a1..b79f31f76495faebffebf82a47146b486449c683 100644 (file)
@@ -165,14 +165,14 @@ process_arguments (int argc, char **argv)
                        break;
                case 'c':                                                                       /* critical */
                        if (!is_intnonneg (optarg))
-                               usage (_("Critical threshold must be a positive integer\n"));
+                               usage4 (_("Critical threshold must be a positive integer"));
                        else
                                critical_time = atoi (optarg);
                        check_critical_time = TRUE;
                        break;
                case 'w':                                                                       /* warning */
                        if (!is_intnonneg (optarg))
-                               usage (_("Warning threshold must be a positive integer\n"));
+                               usage4 (_("Warning threshold must be a positive integer"));
                        else
                                warning_time = atoi (optarg);
                        check_warning_time = TRUE;
@@ -185,7 +185,7 @@ process_arguments (int argc, char **argv)
                        break;
                case 'p':                                                                       /* port */
                        if (!is_intnonneg (optarg))
-                               usage (_("Port must be a positive integer\n"));
+                               usage4 (_("Port must be a positive integer"));
                        else
                                server_port = atoi (optarg);
                        break;
index 993bd9005c91837ca25a40db3a884e3e85d66664..51a84c7657c1eb020c91040399e88877661081ae 100644 (file)
@@ -31,6 +31,7 @@ plugins/check_time.c
 plugins/check_udp.c
 plugins/check_ups.c
 plugins/check_users.c
+plugins/check_ide_smart.c
 plugins/getaddrinfo.c
 plugins/gethostbyname.c
 plugins/negate.c