summaryrefslogtreecommitdiffstats
path: root/plugins/check_ide_smart.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/check_ide_smart.c')
-rw-r--r--plugins/check_ide_smart.c496
1 files changed, 207 insertions, 289 deletions
diff --git a/plugins/check_ide_smart.c b/plugins/check_ide_smart.c
index 3872e34..9640ef7 100644
--- a/plugins/check_ide_smart.c
+++ b/plugins/check_ide_smart.c
@@ -1,112 +1,105 @@
1/***************************************************************************** 1/*****************************************************************************
2* 2 *
3* Monitoring check_ide_smart plugin 3 * Monitoring check_ide_smart plugin
4* ide-smart 1.3 - IDE S.M.A.R.T. checking tool 4 * ide-smart 1.3 - IDE S.M.A.R.T. checking tool
5* 5 *
6* License: GPL 6 * License: GPL
7* Copyright (C) 1998-1999 Ragnar Hojland Espinosa <ragnar@lightside.dhis.org> 7 * Copyright (C) 1998-1999 Ragnar Hojland Espinosa <ragnar@lightside.dhis.org>
8* 1998 Gadi Oxman <gadio@netvision.net.il> 8 * 1998 Gadi Oxman <gadio@netvision.net.il>
9* Copyright (c) 2000 Robert Dale <rdale@digital-mission.com> 9 * Copyright (c) 2000 Robert Dale <rdale@digital-mission.com>
10* Copyright (c) 2000-2007 Monitoring Plugins Development Team 10 * Copyright (c) 2000-2024 Monitoring Plugins Development Team
11* 11 *
12* Description: 12 * Description:
13* 13 *
14* This file contains the check_ide_smart plugin 14 * This file contains the check_ide_smart plugin
15* 15 *
16* This plugin checks a local hard drive with the (Linux specific) SMART 16 * This plugin checks a local hard drive with the (Linux specific) SMART
17* interface 17 * interface
18* 18 *
19* 19 *
20* This program is free software: you can redistribute it and/or modify 20 * This program is free software: you can redistribute it and/or modify
21* it under the terms of the GNU General Public License as published by 21 * it under the terms of the GNU General Public License as published by
22* the Free Software Foundation, either version 3 of the License, or 22 * the Free Software Foundation, either version 3 of the License, or
23* (at your option) any later version. 23 * (at your option) any later version.
24* 24 *
25* This program is distributed in the hope that it will be useful, 25 * This program is distributed in the hope that it will be useful,
26* but WITHOUT ANY WARRANTY; without even the implied warranty of 26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28* GNU General Public License for more details. 28 * GNU General Public License for more details.
29* 29 *
30* You should have received a copy of the GNU General Public License 30 * You should have received a copy of the GNU General Public License
31* along with this program. If not, see <http://www.gnu.org/licenses/>. 31 * along with this program. If not, see <http://www.gnu.org/licenses/>.
32* 32 *
33* 33 *
34*****************************************************************************/ 34 *****************************************************************************/
35 35
36const char *progname = "check_ide_smart"; 36const char *progname = "check_ide_smart";
37const char *copyright = "1998-2007"; 37const char *copyright = "1998-2024";
38const char *email = "devel@monitoring-plugins.org"; 38const char *email = "devel@monitoring-plugins.org";
39 39
40#include "common.h" 40#include "common.h"
41#include "utils.h" 41#include "utils.h"
42 42
43void print_help (void); 43static void print_help(void);
44void print_usage (void); 44void print_usage(void);
45 45
46#include <sys/stat.h> 46#include <sys/stat.h>
47#include <sys/ioctl.h> 47#include <sys/ioctl.h>
48#include <fcntl.h> 48#include <fcntl.h>
49#ifdef __linux__ 49#ifdef __linux__
50#include <linux/hdreg.h> 50# include <linux/hdreg.h>
51#include <linux/types.h> 51# include <linux/types.h>
52 52
53#define OPEN_MODE O_RDONLY 53# define OPEN_MODE O_RDONLY
54#endif /* __linux__ */ 54#endif /* __linux__ */
55#ifdef __NetBSD__ 55#ifdef __NetBSD__
56#include <sys/device.h> 56# include <sys/device.h>
57#include <sys/param.h> 57# include <sys/param.h>
58#include <sys/sysctl.h> 58# include <sys/sysctl.h>
59#include <sys/videoio.h> /* for __u8 and friends */ 59# include <sys/videoio.h> /* for __u8 and friends */
60#include <sys/scsiio.h> 60# include <sys/scsiio.h>
61#include <sys/ataio.h> 61# include <sys/ataio.h>
62#include <dev/ata/atareg.h> 62# include <dev/ata/atareg.h>
63#include <dev/ic/wdcreg.h> 63# include <dev/ic/wdcreg.h>
64 64
65#define SMART_ENABLE WDSM_ENABLE_OPS 65# define SMART_ENABLE WDSM_ENABLE_OPS
66#define SMART_DISABLE WDSM_DISABLE_OPS 66# define SMART_DISABLE WDSM_DISABLE_OPS
67#define SMART_IMMEDIATE_OFFLINE WDSM_EXEC_OFFL_IMM 67# define SMART_IMMEDIATE_OFFLINE WDSM_EXEC_OFFL_IMM
68#define SMART_AUTO_OFFLINE 0xdb /* undefined in NetBSD headers */ 68# define SMART_AUTO_OFFLINE 0xdb /* undefined in NetBSD headers */
69 69
70#define OPEN_MODE O_RDWR 70# define OPEN_MODE O_RDWR
71#endif /* __NetBSD__ */ 71#endif /* __NetBSD__ */
72#include <errno.h> 72#include <errno.h>
73 73
74#define NR_ATTRIBUTES 30 74#define NR_ATTRIBUTES 30
75 75
76#define PREFAILURE 2 76#define PREFAILURE 2
77#define ADVISORY 1 77#define ADVISORY 1
78#define OPERATIONAL 0 78#define OPERATIONAL 0
79#define UNKNOWN -1 79#define UNKNOWN -1
80 80
81typedef struct threshold_s 81typedef struct threshold_s {
82{
83 __u8 id; 82 __u8 id;
84 __u8 threshold; 83 __u8 threshold;
85 __u8 reserved[10]; 84 __u8 reserved[10];
86} 85} __attribute__((packed)) threshold_t;
87__attribute__ ((packed)) threshold_t;
88 86
89typedef struct thresholds_s 87typedef struct thresholds_s {
90{
91 __u16 revision; 88 __u16 revision;
92 threshold_t thresholds[NR_ATTRIBUTES]; 89 threshold_t thresholds[NR_ATTRIBUTES];
93 __u8 reserved[18]; 90 __u8 reserved[18];
94 __u8 vendor[131]; 91 __u8 vendor[131];
95 __u8 checksum; 92 __u8 checksum;
96} 93} __attribute__((packed)) thresholds_t;
97__attribute__ ((packed)) thresholds_t;
98 94
99typedef struct value_s 95typedef struct value_s {
100{
101 __u8 id; 96 __u8 id;
102 __u16 status; 97 __u16 status;
103 __u8 value; 98 __u8 value;
104 __u8 vendor[8]; 99 __u8 vendor[8];
105} 100} __attribute__((packed)) value_t;
106__attribute__ ((packed)) value_t;
107 101
108typedef struct values_s 102typedef struct values_s {
109{
110 __u16 revision; 103 __u16 revision;
111 value_t values[NR_ATTRIBUTES]; 104 value_t values[NR_ATTRIBUTES];
112 __u8 offline_status; 105 __u8 offline_status;
@@ -118,90 +111,69 @@ typedef struct values_s
118 __u8 reserved[16]; 111 __u8 reserved[16];
119 __u8 vendor[125]; 112 __u8 vendor[125];
120 __u8 checksum; 113 __u8 checksum;
121} 114} __attribute__((packed)) values_t;
122__attribute__ ((packed)) values_t;
123 115
124struct 116static struct {
125{
126 __u8 value; 117 __u8 value;
127 char *text; 118 char *text;
128} 119} offline_status_text[] = {{0x00, "NeverStarted"}, {0x02, "Completed"}, {0x04, "Suspended"},
120 {0x05, "Aborted"}, {0x06, "Failed"}, {0, 0}};
129 121
130offline_status_text[] = 122static struct {
131 {
132 {0x00, "NeverStarted"},
133 {0x02, "Completed"},
134 {0x04, "Suspended"},
135 {0x05, "Aborted"},
136 {0x06, "Failed"},
137 {0, 0}
138 };
139
140struct
141{
142 __u8 value; 123 __u8 value;
143 char *text; 124 char *text;
144} 125} smart_command[] = {{SMART_ENABLE, "SMART_ENABLE"},
145 126 {SMART_DISABLE, "SMART_DISABLE"},
146smart_command[] = 127 {SMART_IMMEDIATE_OFFLINE, "SMART_IMMEDIATE_OFFLINE"},
147 { 128 {SMART_AUTO_OFFLINE, "SMART_AUTO_OFFLINE"}};
148 {SMART_ENABLE, "SMART_ENABLE"}, 129
149 {SMART_DISABLE, "SMART_DISABLE"}, 130/* Index to smart_command table, keep in order */
150 {SMART_IMMEDIATE_OFFLINE, "SMART_IMMEDIATE_OFFLINE"}, 131enum SmartCommand {
151 {SMART_AUTO_OFFLINE, "SMART_AUTO_OFFLINE"} 132 SMART_CMD_ENABLE,
152 }; 133 SMART_CMD_DISABLE,
153 134 SMART_CMD_IMMEDIATE_OFFLINE,
154 135 SMART_CMD_AUTO_OFFLINE
155/* Index to smart_command table, keep in order */ 136};
156enum SmartCommand 137
157 { SMART_CMD_ENABLE, 138static char *get_offline_text(int);
158 SMART_CMD_DISABLE, 139static int smart_read_values(int, values_t *);
159 SMART_CMD_IMMEDIATE_OFFLINE, 140static int nagios(values_t *, thresholds_t *);
160 SMART_CMD_AUTO_OFFLINE 141static void print_value(value_t *, threshold_t *);
161 }; 142static void print_values(values_t *, thresholds_t *);
162 143static int smart_cmd_simple(int, enum SmartCommand, __u8, bool);
163char *get_offline_text (int); 144static int smart_read_thresholds(int, thresholds_t *);
164int smart_read_values (int, values_t *); 145static bool verbose = false;
165int nagios (values_t *, thresholds_t *); 146
166void print_value (value_t *, threshold_t *); 147int main(int argc, char *argv[]) {
167void print_values (values_t *, thresholds_t *);
168int smart_cmd_simple (int, enum SmartCommand, __u8, bool);
169int smart_read_thresholds (int, thresholds_t *);
170bool verbose = false;
171
172int
173main (int argc, char *argv[])
174{
175 char *device = NULL; 148 char *device = NULL;
176 int o, longindex; 149 int o;
150 int longindex;
177 int retval = 0; 151 int retval = 0;
178 152
179 thresholds_t thresholds; 153 thresholds_t thresholds;
180 values_t values; 154 values_t values;
181 int fd; 155 int fd;
182 156
183 static struct option longopts[] = { 157 static struct option longopts[] = {{"device", required_argument, 0, 'd'},
184 {"device", required_argument, 0, 'd'}, 158 {"immediate", no_argument, 0, 'i'},
185 {"immediate", no_argument, 0, 'i'}, 159 {"quiet-check", no_argument, 0, 'q'},
186 {"quiet-check", no_argument, 0, 'q'}, 160 {"auto-on", no_argument, 0, '1'},
187 {"auto-on", no_argument, 0, '1'}, 161 {"auto-off", no_argument, 0, '0'},
188 {"auto-off", no_argument, 0, '0'}, 162 {"nagios", no_argument, 0, 'n'}, /* DEPRECATED, but we still accept it */
189 {"nagios", no_argument, 0, 'n'}, /* DEPRECATED, but we still accept it */ 163 {"help", no_argument, 0, 'h'},
190 {"help", no_argument, 0, 'h'}, 164 {"version", no_argument, 0, 'V'},
191 {"version", no_argument, 0, 'V'}, 165 {0, 0, 0, 0}};
192 {0, 0, 0, 0}
193 };
194 166
195 /* Parse extra opts if any */ 167 /* Parse extra opts if any */
196 argv=np_extra_opts (&argc, argv, progname); 168 argv = np_extra_opts(&argc, argv, progname);
197 169
198 setlocale (LC_ALL, ""); 170 setlocale(LC_ALL, "");
199 bindtextdomain (PACKAGE, LOCALEDIR); 171 bindtextdomain(PACKAGE, LOCALEDIR);
200 textdomain (PACKAGE); 172 textdomain(PACKAGE);
201 173
202 while (true) { 174 while (true) {
203 175
204 o = getopt_long (argc, argv, "+d:iq10nhVv", longopts, &longindex); 176 o = getopt_long(argc, argv, "+d:iq10nhVv", longopts, &longindex);
205 177
206 if (o == -1 || o == EOF || o == 1) 178 if (o == -1 || o == EOF || o == 1)
207 break; 179 break;
@@ -211,30 +183,30 @@ main (int argc, char *argv[])
211 device = optarg; 183 device = optarg;
212 break; 184 break;
213 case 'q': 185 case 'q':
214 fprintf (stderr, "%s\n", _("DEPRECATION WARNING: the -q switch (quiet output) is no longer \"quiet\".")); 186 fprintf(stderr, "%s\n", _("DEPRECATION WARNING: the -q switch (quiet output) is no longer \"quiet\"."));
215 fprintf (stderr, "%s\n", _("Nagios-compatible output is now always returned.")); 187 fprintf(stderr, "%s\n", _("Nagios-compatible output is now always returned."));
216 break; 188 break;
217 case 'i': 189 case 'i':
218 case '1': 190 case '1':
219 case '0': 191 case '0':
220 printf ("%s\n", _("SMART commands are broken and have been disabled (See Notes in --help).")); 192 printf("%s\n", _("SMART commands are broken and have been disabled (See Notes in --help)."));
221 return STATE_CRITICAL; 193 return STATE_CRITICAL;
222 break; 194 break;
223 case 'n': 195 case 'n':
224 fprintf (stderr, "%s\n", _("DEPRECATION WARNING: the -n switch (Nagios-compatible output) is now the")); 196 fprintf(stderr, "%s\n", _("DEPRECATION WARNING: the -n switch (Nagios-compatible output) is now the"));
225 fprintf (stderr, "%s\n", _("default and will be removed from future releases.")); 197 fprintf(stderr, "%s\n", _("default and will be removed from future releases."));
226 break; 198 break;
227 case 'v': /* verbose */ 199 case 'v': /* verbose */
228 verbose = true; 200 verbose = true;
229 break; 201 break;
230 case 'h': 202 case 'h':
231 print_help (); 203 print_help();
232 return STATE_UNKNOWN; 204 return STATE_UNKNOWN;
233 case 'V': 205 case 'V':
234 print_revision (progname, NP_VERSION); 206 print_revision(progname, NP_VERSION);
235 return STATE_UNKNOWN; 207 return STATE_UNKNOWN;
236 default: 208 default:
237 usage5 (); 209 usage5();
238 } 210 }
239 } 211 }
240 212
@@ -243,36 +215,33 @@ main (int argc, char *argv[])
243 } 215 }
244 216
245 if (!device) { 217 if (!device) {
246 print_help (); 218 print_help();
247 return STATE_UNKNOWN; 219 return STATE_UNKNOWN;
248 } 220 }
249 221
250 fd = open (device, OPEN_MODE); 222 fd = open(device, OPEN_MODE);
251 223
252 if (fd < 0) { 224 if (fd < 0) {
253 printf (_("CRITICAL - Couldn't open device %s: %s\n"), device, strerror (errno)); 225 printf(_("CRITICAL - Couldn't open device %s: %s\n"), device, strerror(errno));
254 return STATE_CRITICAL; 226 return STATE_CRITICAL;
255 } 227 }
256 228
257 if (smart_cmd_simple (fd, SMART_CMD_ENABLE, 0, false)) { 229 if (smart_cmd_simple(fd, SMART_CMD_ENABLE, 0, false)) {
258 printf (_("CRITICAL - SMART_CMD_ENABLE\n")); 230 printf(_("CRITICAL - SMART_CMD_ENABLE\n"));
259 return STATE_CRITICAL; 231 return STATE_CRITICAL;
260 } 232 }
261 233
262 smart_read_values (fd, &values); 234 smart_read_values(fd, &values);
263 smart_read_thresholds (fd, &thresholds); 235 smart_read_thresholds(fd, &thresholds);
264 retval = nagios (&values, &thresholds); 236 retval = nagios(&values, &thresholds);
265 if (verbose) print_values (&values, &thresholds); 237 if (verbose)
238 print_values(&values, &thresholds);
266 239
267 close (fd); 240 close(fd);
268 return retval; 241 return retval;
269} 242}
270 243
271 244char *get_offline_text(int status) {
272
273char *
274get_offline_text (int status)
275{
276 int i; 245 int i;
277 for (i = 0; offline_status_text[i].text; i++) { 246 for (i = 0; offline_status_text[i].text; i++) {
278 if (offline_status_text[i].value == status) { 247 if (offline_status_text[i].value == status) {
@@ -282,11 +251,7 @@ get_offline_text (int status)
282 return "UNKNOWN"; 251 return "UNKNOWN";
283} 252}
284 253
285 254int smart_read_values(int fd, values_t *values) {
286
287int
288smart_read_values (int fd, values_t * values)
289{
290#ifdef __linux__ 255#ifdef __linux__
291 int e; 256 int e;
292 __u8 args[4 + 512]; 257 __u8 args[4 + 512];
@@ -294,12 +259,12 @@ smart_read_values (int fd, values_t * values)
294 args[1] = 0; 259 args[1] = 0;
295 args[2] = SMART_READ_VALUES; 260 args[2] = SMART_READ_VALUES;
296 args[3] = 1; 261 args[3] = 1;
297 if (ioctl (fd, HDIO_DRIVE_CMD, &args)) { 262 if (ioctl(fd, HDIO_DRIVE_CMD, &args)) {
298 e = errno; 263 e = errno;
299 printf (_("CRITICAL - SMART_READ_VALUES: %s\n"), strerror (errno)); 264 printf(_("CRITICAL - SMART_READ_VALUES: %s\n"), strerror(errno));
300 return e; 265 return e;
301 } 266 }
302 memcpy (values, args + 4, 512); 267 memcpy(values, args + 4, 512);
303#endif /* __linux__ */ 268#endif /* __linux__ */
304#ifdef __NetBSD__ 269#ifdef __NetBSD__
305 struct atareq req; 270 struct atareq req;
@@ -323,7 +288,7 @@ smart_read_values (int fd, values_t * values)
323 288
324 if (errno != 0) { 289 if (errno != 0) {
325 int e = errno; 290 int e = errno;
326 printf (_("CRITICAL - SMART_READ_VALUES: %s\n"), strerror (errno)); 291 printf(_("CRITICAL - SMART_READ_VALUES: %s\n"), strerror(errno));
327 return e; 292 return e;
328 } 293 }
329 294
@@ -332,13 +297,9 @@ smart_read_values (int fd, values_t * values)
332 return 0; 297 return 0;
333} 298}
334 299
335 300int nagios(values_t *p, thresholds_t *t) {
336 301 value_t *value = p->values;
337int 302 threshold_t *threshold = t->thresholds;
338nagios (values_t * p, thresholds_t * t)
339{
340 value_t * value = p->values;
341 threshold_t * threshold = t->thresholds;
342 int status = OPERATIONAL; 303 int status = OPERATIONAL;
343 int prefailure = 0; 304 int prefailure = 0;
344 int advisory = 0; 305 int advisory = 0;
@@ -353,13 +314,11 @@ nagios (values_t * p, thresholds_t * t)
353 if (value->status & 1) { 314 if (value->status & 1) {
354 status = PREFAILURE; 315 status = PREFAILURE;
355 ++prefailure; 316 ++prefailure;
356 } 317 } else {
357 else {
358 status = ADVISORY; 318 status = ADVISORY;
359 ++advisory; 319 ++advisory;
360 } 320 }
361 } 321 } else {
362 else {
363 ++passed; 322 ++passed;
364 } 323 }
365 ++total; 324 ++total;
@@ -369,81 +328,49 @@ nagios (values_t * p, thresholds_t * t)
369 } 328 }
370 switch (status) { 329 switch (status) {
371 case PREFAILURE: 330 case PREFAILURE:
372 printf (_("CRITICAL - %d Harddrive PreFailure%cDetected! %d/%d tests failed.\n"), 331 printf(_("CRITICAL - %d Harddrive PreFailure%cDetected! %d/%d tests failed.\n"), prefailure, prefailure > 1 ? 's' : ' ', failed,
373 prefailure, 332 total);
374 prefailure > 1 ? 's' : ' ', 333 status = STATE_CRITICAL;
375 failed,
376 total);
377 status=STATE_CRITICAL;
378 break; 334 break;
379 case ADVISORY: 335 case ADVISORY:
380 printf (_("WARNING - %d Harddrive Advisor%s Detected. %d/%d tests failed.\n"), 336 printf(_("WARNING - %d Harddrive Advisor%s Detected. %d/%d tests failed.\n"), advisory, advisory > 1 ? "ies" : "y", failed, total);
381 advisory, 337 status = STATE_WARNING;
382 advisory > 1 ? "ies" : "y",
383 failed,
384 total);
385 status=STATE_WARNING;
386 break; 338 break;
387 case OPERATIONAL: 339 case OPERATIONAL:
388 printf (_("OK - Operational (%d/%d tests passed)\n"), passed, total); 340 printf(_("OK - Operational (%d/%d tests passed)\n"), passed, total);
389 status=STATE_OK; 341 status = STATE_OK;
390 break; 342 break;
391 default: 343 default:
392 printf (_("ERROR - Status '%d' unknown. %d/%d tests passed\n"), status, 344 printf(_("ERROR - Status '%d' unknown. %d/%d tests passed\n"), status, passed, total);
393 passed, total);
394 status = STATE_UNKNOWN; 345 status = STATE_UNKNOWN;
395 break; 346 break;
396 } 347 }
397 return status; 348 return status;
398} 349}
399 350
400 351void print_value(value_t *p, threshold_t *t) {
401 352 printf("Id=%3d, Status=%2d {%s , %s}, Value=%3d, Threshold=%3d, %s\n", p->id, p->status, p->status & 1 ? "PreFailure" : "Advisory ",
402void 353 p->status & 2 ? "OnLine " : "OffLine", p->value, t->threshold, p->value >= t->threshold ? "Passed" : "Failed");
403print_value (value_t * p, threshold_t * t)
404{
405 printf ("Id=%3d, Status=%2d {%s , %s}, Value=%3d, Threshold=%3d, %s\n",
406 p->id, p->status, p->status & 1 ? "PreFailure" : "Advisory ",
407 p->status & 2 ? "OnLine " : "OffLine", p->value, t->threshold,
408 p->value >= t->threshold ? "Passed" : "Failed");
409} 354}
410 355
411 356void print_values(values_t *p, thresholds_t *t) {
412 357 value_t *value = p->values;
413void 358 threshold_t *threshold = t->thresholds;
414print_values (values_t * p, thresholds_t * t)
415{
416 value_t * value = p->values;
417 threshold_t * threshold = t->thresholds;
418 int i; 359 int i;
419 for (i = 0; i < NR_ATTRIBUTES; i++) { 360 for (i = 0; i < NR_ATTRIBUTES; i++) {
420 if (value->id && threshold->id && value->id == threshold->id) { 361 if (value->id && threshold->id && value->id == threshold->id) {
421 print_value (value++, threshold++); 362 print_value(value++, threshold++);
422 } 363 }
423 } 364 }
424 printf 365 printf(_("OffLineStatus=%d {%s}, AutoOffLine=%s, OffLineTimeout=%d minutes\n"), p->offline_status,
425 (_("OffLineStatus=%d {%s}, AutoOffLine=%s, OffLineTimeout=%d minutes\n"), 366 get_offline_text(p->offline_status & 0x7f), (p->offline_status & 0x80 ? "Yes" : "No"), p->offline_timeout / 60);
426 p->offline_status, 367 printf(_("OffLineCapability=%d {%s %s %s}\n"), p->offline_capability, p->offline_capability & 1 ? "Immediate" : "",
427 get_offline_text (p->offline_status & 0x7f), 368 p->offline_capability & 2 ? "Auto" : "", p->offline_capability & 4 ? "AbortOnCmd" : "SuspendOnCmd");
428 (p->offline_status & 0x80 ? "Yes" : "No"), 369 printf(_("SmartRevision=%d, CheckSum=%d, SmartCapability=%d {%s %s}\n"), p->revision, p->checksum, p->smart_capability,
429 p->offline_timeout / 60); 370 p->smart_capability & 1 ? "SaveOnStandBy" : "", p->smart_capability & 2 ? "AutoSave" : "");
430 printf
431 (_("OffLineCapability=%d {%s %s %s}\n"),
432 p->offline_capability,
433 p->offline_capability & 1 ? "Immediate" : "",
434 p->offline_capability & 2 ? "Auto" : "",
435 p->offline_capability & 4 ? "AbortOnCmd" : "SuspendOnCmd");
436 printf
437 (_("SmartRevision=%d, CheckSum=%d, SmartCapability=%d {%s %s}\n"),
438 p->revision,
439 p->checksum,
440 p->smart_capability,
441 p->smart_capability & 1 ? "SaveOnStandBy" : "",
442 p->smart_capability & 2 ? "AutoSave" : "");
443} 371}
444 372
445 373int smart_cmd_simple(int fd, enum SmartCommand command, __u8 val0, bool show_error) {
446int smart_cmd_simple (int fd, enum SmartCommand command, __u8 val0, bool show_error) {
447 int e = STATE_UNKNOWN; 374 int e = STATE_UNKNOWN;
448#ifdef __linux__ 375#ifdef __linux__
449 __u8 args[4]; 376 __u8 args[4];
@@ -451,14 +378,14 @@ int smart_cmd_simple (int fd, enum SmartCommand command, __u8 val0, bool show_er
451 args[1] = val0; 378 args[1] = val0;
452 args[2] = smart_command[command].value; 379 args[2] = smart_command[command].value;
453 args[3] = 0; 380 args[3] = 0;
454 if (ioctl (fd, HDIO_DRIVE_CMD, &args)) { 381 if (ioctl(fd, HDIO_DRIVE_CMD, &args)) {
455 e = STATE_CRITICAL; 382 e = STATE_CRITICAL;
456 if (show_error) 383 if (show_error)
457 printf (_("CRITICAL - %s: %s\n"), smart_command[command].text, strerror (errno)); 384 printf(_("CRITICAL - %s: %s\n"), smart_command[command].text, strerror(errno));
458 } else { 385 } else {
459 e = STATE_OK; 386 e = STATE_OK;
460 if (show_error) 387 if (show_error)
461 printf (_("OK - Command sent (%s)\n"), smart_command[command].text); 388 printf(_("OK - Command sent (%s)\n"), smart_command[command].text);
462 } 389 }
463 390
464#endif /* __linux__ */ 391#endif /* __linux__ */
@@ -483,35 +410,31 @@ int smart_cmd_simple (int fd, enum SmartCommand command, __u8 val0, bool show_er
483 if (errno != 0) { 410 if (errno != 0) {
484 e = STATE_CRITICAL; 411 e = STATE_CRITICAL;
485 if (show_error) 412 if (show_error)
486 printf (_("CRITICAL - %s: %s\n"), smart_command[command].text, strerror (errno)); 413 printf(_("CRITICAL - %s: %s\n"), smart_command[command].text, strerror(errno));
487 } else { 414 } else {
488 e = STATE_OK; 415 e = STATE_OK;
489 if (show_error) 416 if (show_error)
490 printf (_("OK - Command sent (%s)\n"), smart_command[command].text); 417 printf(_("OK - Command sent (%s)\n"), smart_command[command].text);
491 } 418 }
492 419
493#endif /* __NetBSD__ */ 420#endif /* __NetBSD__ */
494 return e; 421 return e;
495} 422}
496 423
497 424int smart_read_thresholds(int fd, thresholds_t *thresholds) {
498
499int
500smart_read_thresholds (int fd, thresholds_t * thresholds)
501{
502#ifdef __linux__ 425#ifdef __linux__
503 int e; 426 int e;
504 __u8 args[4 + 512]; 427 __u8 args[4 + 512];
505 args[0] = WIN_SMART; 428 args[0] = WIN_SMART;
506 args[1] = 0; 429 args[1] = 0;
507 args[2] = SMART_READ_THRESHOLDS; 430 args[2] = SMART_READ_THRESHOLDS;
508 args[3] = 1; 431 args[3] = 1;
509 if (ioctl (fd, HDIO_DRIVE_CMD, &args)) { 432 if (ioctl(fd, HDIO_DRIVE_CMD, &args)) {
510 e = errno; 433 e = errno;
511 printf (_("CRITICAL - SMART_READ_THRESHOLDS: %s\n"), strerror (errno)); 434 printf(_("CRITICAL - SMART_READ_THRESHOLDS: %s\n"), strerror(errno));
512 return e; 435 return e;
513 } 436 }
514 memcpy (thresholds, args + 4, 512); 437 memcpy(thresholds, args + 4, 512);
515#endif /* __linux__ */ 438#endif /* __linux__ */
516#ifdef __NetBSD__ 439#ifdef __NetBSD__
517 struct atareq req; 440 struct atareq req;
@@ -535,7 +458,7 @@ smart_read_thresholds (int fd, thresholds_t * thresholds)
535 458
536 if (errno != 0) { 459 if (errno != 0) {
537 int e = errno; 460 int e = errno;
538 printf (_("CRITICAL - SMART_READ_THRESHOLDS: %s\n"), strerror (errno)); 461 printf(_("CRITICAL - SMART_READ_THRESHOLDS: %s\n"), strerror(errno));
539 return e; 462 return e;
540 } 463 }
541 464
@@ -544,45 +467,43 @@ smart_read_thresholds (int fd, thresholds_t * thresholds)
544 return 0; 467 return 0;
545} 468}
546 469
470void print_help(void) {
471 print_revision(progname, NP_VERSION);
547 472
548void 473 printf("(C) 1999 Ragnar Hojland Espinosa <ragnar@lightside.dhis.org>\n");
549print_help (void) 474 printf("Plugin implementation - 1999 Robert Dale <rdale@digital-mission.com>\n");
550{ 475 printf(COPYRIGHT, copyright, email);
551 print_revision (progname, NP_VERSION);
552 476
553 printf ("(C) 1999 Ragnar Hojland Espinosa <ragnar@lightside.dhis.org>\n"); 477 printf(_("This plugin checks a local hard drive with the (Linux specific) SMART interface "
554 printf ("Plugin implementation - 1999 Robert Dale <rdale@digital-mission.com>\n"); 478 "[http://smartlinux.sourceforge.net/smart/index.php]."));
555 printf (COPYRIGHT, copyright, email);
556 479
557 printf (_("This plugin checks a local hard drive with the (Linux specific) SMART interface [http://smartlinux.sourceforge.net/smart/index.php].")); 480 printf("\n\n");
558 481
559 printf ("\n\n"); 482 print_usage();
560 483
561 print_usage (); 484 printf(UT_HELP_VRSN);
485 printf(UT_EXTRA_OPTS);
562 486
563 printf (UT_HELP_VRSN); 487 printf(" %s\n", "-d, --device=DEVICE");
564 printf (UT_EXTRA_OPTS); 488 printf(" %s\n", _("Select device DEVICE"));
489 printf(" %s\n", _("Note: if the device is specified without this option, any further option will"));
490 printf(" %s\n", _("be ignored."));
565 491
566 printf (" %s\n", "-d, --device=DEVICE"); 492 printf(UT_VERBOSE);
567 printf (" %s\n", _("Select device DEVICE"));
568 printf (" %s\n", _("Note: if the device is specified without this option, any further option will"));
569 printf (" %s\n", _("be ignored."));
570 493
571 printf (UT_VERBOSE); 494 printf("\n");
495 printf("%s\n", _("Notes:"));
496 printf(" %s\n", _("The SMART command modes (-i/--immediate, -0/--auto-off and -1/--auto-on) were"));
497 printf(" %s\n", _("broken in an underhand manner and have been disabled. You can use smartctl"));
498 printf(" %s\n", _("instead:"));
499 printf(" %s\n", _("-0/--auto-off: use \"smartctl --offlineauto=off\""));
500 printf(" %s\n", _("-1/--auto-on: use \"smartctl --offlineauto=on\""));
501 printf(" %s\n", _("-i/--immediate: use \"smartctl --test=offline\""));
572 502
573 printf ("\n"); 503 printf(UT_SUPPORT);
574 printf ("%s\n", _("Notes:"));
575 printf (" %s\n", _("The SMART command modes (-i/--immediate, -0/--auto-off and -1/--auto-on) were"));
576 printf (" %s\n", _("broken in an underhand manner and have been disabled. You can use smartctl"));
577 printf (" %s\n", _("instead:"));
578 printf (" %s\n", _("-0/--auto-off: use \"smartctl --offlineauto=off\""));
579 printf (" %s\n", _("-1/--auto-on: use \"smartctl --offlineauto=on\""));
580 printf (" %s\n", _("-i/--immediate: use \"smartctl --test=offline\""));
581
582 printf (UT_SUPPORT);
583} 504}
584 505
585 /* todo : add to the long nanual as example 506/* todo : add to the long nanual as example
586 * 507 *
587 * Run with: check_ide-smart --nagios [-d] <DRIVE> 508 * Run with: check_ide-smart --nagios [-d] <DRIVE>
588 * Where DRIVE is an IDE drive, ie. /dev/hda, /dev/hdb, /dev/hdc 509 * Where DRIVE is an IDE drive, ie. /dev/hda, /dev/hdb, /dev/hdc
@@ -593,10 +514,7 @@ print_help (void)
593 * - Returns -1 not too often 514 * - Returns -1 not too often
594 */ 515 */
595 516
596 517void print_usage(void) {
597void 518 printf("%s\n", _("Usage:"));
598print_usage (void) 519 printf("%s [-d <device>] [-v]", progname);
599{
600 printf ("%s\n", _("Usage:"));
601 printf ("%s [-d <device>] [-v]", progname);
602} 520}