summaryrefslogtreecommitdiffstats
path: root/plugins/check_ide_smart.c
diff options
context:
space:
mode:
authorLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2024-10-31 13:57:43 (GMT)
committerGitHub <noreply@github.com>2024-10-31 13:57:43 (GMT)
commitb1d260a821b7d4916d6bf1a026fbc9b4f2b268ae (patch)
tree84a3fc6b26b181a1ed10d7ca55c32ac9170efbd4 /plugins/check_ide_smart.c
parentb4c5956591e9741ce9b190210e7b10940a6adbdd (diff)
parent8955f56de355403941bc8f02a4edb2bc72d1397a (diff)
downloadmonitoring-plugins-b1d260a821b7d4916d6bf1a026fbc9b4f2b268ae.tar.gz
Merge pull request #2035 from RincewindsHat/cleanup/rest-of-plugins
Cleanup for some more plugins
Diffstat (limited to 'plugins/check_ide_smart.c')
-rw-r--r--plugins/check_ide_smart.c496
1 files changed, 208 insertions, 288 deletions
diff --git a/plugins/check_ide_smart.c b/plugins/check_ide_smart.c
index 3872e34..381dbd8 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,71 @@ 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 116struct {
125{
126 __u8 value; 117 __u8 value;
127 char *text; 118 char *text;
128} 119}
129 120
130offline_status_text[] = 121static offline_status_text[] = {{0x00, "NeverStarted"}, {0x02, "Completed"}, {0x04, "Suspended"},
131 { 122 {0x05, "Aborted"}, {0x06, "Failed"}, {0, 0}};
132 {0x00, "NeverStarted"}, 123
133 {0x02, "Completed"}, 124static struct {
134 {0x04, "Suspended"},
135 {0x05, "Aborted"},
136 {0x06, "Failed"},
137 {0, 0}
138 };
139
140struct
141{
142 __u8 value; 125 __u8 value;
143 char *text; 126 char *text;
144} 127} smart_command[] = {{SMART_ENABLE, "SMART_ENABLE"},
145 128 {SMART_DISABLE, "SMART_DISABLE"},
146smart_command[] = 129 {SMART_IMMEDIATE_OFFLINE, "SMART_IMMEDIATE_OFFLINE"},
147 { 130 {SMART_AUTO_OFFLINE, "SMART_AUTO_OFFLINE"}};
148 {SMART_ENABLE, "SMART_ENABLE"}, 131
149 {SMART_DISABLE, "SMART_DISABLE"}, 132/* Index to smart_command table, keep in order */
150 {SMART_IMMEDIATE_OFFLINE, "SMART_IMMEDIATE_OFFLINE"}, 133enum SmartCommand {
151 {SMART_AUTO_OFFLINE, "SMART_AUTO_OFFLINE"} 134 SMART_CMD_ENABLE,
152 }; 135 SMART_CMD_DISABLE,
153 136 SMART_CMD_IMMEDIATE_OFFLINE,
154 137 SMART_CMD_AUTO_OFFLINE
155/* Index to smart_command table, keep in order */ 138};
156enum SmartCommand 139
157 { SMART_CMD_ENABLE, 140static char *get_offline_text(int);
158 SMART_CMD_DISABLE, 141static int smart_read_values(int, values_t *);
159 SMART_CMD_IMMEDIATE_OFFLINE, 142static int nagios(values_t *, thresholds_t *);
160 SMART_CMD_AUTO_OFFLINE 143static void print_value(value_t *, threshold_t *);
161 }; 144static void print_values(values_t *, thresholds_t *);
162 145static int smart_cmd_simple(int, enum SmartCommand, __u8, bool);
163char *get_offline_text (int); 146static int smart_read_thresholds(int, thresholds_t *);
164int smart_read_values (int, values_t *); 147static bool verbose = false;
165int nagios (values_t *, thresholds_t *); 148
166void print_value (value_t *, threshold_t *); 149int 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; 150 char *device = NULL;
176 int o, longindex; 151 int o;
152 int longindex;
177 int retval = 0; 153 int retval = 0;
178 154
179 thresholds_t thresholds; 155 thresholds_t thresholds;
180 values_t values; 156 values_t values;
181 int fd; 157 int fd;
182 158
183 static struct option longopts[] = { 159 static struct option longopts[] = {{"device", required_argument, 0, 'd'},
184 {"device", required_argument, 0, 'd'}, 160 {"immediate", no_argument, 0, 'i'},
185 {"immediate", no_argument, 0, 'i'}, 161 {"quiet-check", no_argument, 0, 'q'},
186 {"quiet-check", no_argument, 0, 'q'}, 162 {"auto-on", no_argument, 0, '1'},
187 {"auto-on", no_argument, 0, '1'}, 163 {"auto-off", no_argument, 0, '0'},
188 {"auto-off", no_argument, 0, '0'}, 164 {"nagios", no_argument, 0, 'n'}, /* DEPRECATED, but we still accept it */
189 {"nagios", no_argument, 0, 'n'}, /* DEPRECATED, but we still accept it */ 165 {"help", no_argument, 0, 'h'},
190 {"help", no_argument, 0, 'h'}, 166 {"version", no_argument, 0, 'V'},
191 {"version", no_argument, 0, 'V'}, 167 {0, 0, 0, 0}};
192 {0, 0, 0, 0}
193 };
194 168
195 /* Parse extra opts if any */ 169 /* Parse extra opts if any */
196 argv=np_extra_opts (&argc, argv, progname); 170 argv = np_extra_opts(&argc, argv, progname);
197 171
198 setlocale (LC_ALL, ""); 172 setlocale(LC_ALL, "");
199 bindtextdomain (PACKAGE, LOCALEDIR); 173 bindtextdomain(PACKAGE, LOCALEDIR);
200 textdomain (PACKAGE); 174 textdomain(PACKAGE);
201 175
202 while (true) { 176 while (true) {
203 177
204 o = getopt_long (argc, argv, "+d:iq10nhVv", longopts, &longindex); 178 o = getopt_long(argc, argv, "+d:iq10nhVv", longopts, &longindex);
205 179
206 if (o == -1 || o == EOF || o == 1) 180 if (o == -1 || o == EOF || o == 1)
207 break; 181 break;
@@ -211,30 +185,30 @@ main (int argc, char *argv[])
211 device = optarg; 185 device = optarg;
212 break; 186 break;
213 case 'q': 187 case 'q':
214 fprintf (stderr, "%s\n", _("DEPRECATION WARNING: the -q switch (quiet output) is no longer \"quiet\".")); 188 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.")); 189 fprintf(stderr, "%s\n", _("Nagios-compatible output is now always returned."));
216 break; 190 break;
217 case 'i': 191 case 'i':
218 case '1': 192 case '1':
219 case '0': 193 case '0':
220 printf ("%s\n", _("SMART commands are broken and have been disabled (See Notes in --help).")); 194 printf("%s\n", _("SMART commands are broken and have been disabled (See Notes in --help)."));
221 return STATE_CRITICAL; 195 return STATE_CRITICAL;
222 break; 196 break;
223 case 'n': 197 case 'n':
224 fprintf (stderr, "%s\n", _("DEPRECATION WARNING: the -n switch (Nagios-compatible output) is now the")); 198 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.")); 199 fprintf(stderr, "%s\n", _("default and will be removed from future releases."));
226 break; 200 break;
227 case 'v': /* verbose */ 201 case 'v': /* verbose */
228 verbose = true; 202 verbose = true;
229 break; 203 break;
230 case 'h': 204 case 'h':
231 print_help (); 205 print_help();
232 return STATE_UNKNOWN; 206 return STATE_UNKNOWN;
233 case 'V': 207 case 'V':
234 print_revision (progname, NP_VERSION); 208 print_revision(progname, NP_VERSION);
235 return STATE_UNKNOWN; 209 return STATE_UNKNOWN;
236 default: 210 default:
237 usage5 (); 211 usage5();
238 } 212 }
239 } 213 }
240 214
@@ -243,36 +217,33 @@ main (int argc, char *argv[])
243 } 217 }
244 218
245 if (!device) { 219 if (!device) {
246 print_help (); 220 print_help();
247 return STATE_UNKNOWN; 221 return STATE_UNKNOWN;
248 } 222 }
249 223
250 fd = open (device, OPEN_MODE); 224 fd = open(device, OPEN_MODE);
251 225
252 if (fd < 0) { 226 if (fd < 0) {
253 printf (_("CRITICAL - Couldn't open device %s: %s\n"), device, strerror (errno)); 227 printf(_("CRITICAL - Couldn't open device %s: %s\n"), device, strerror(errno));
254 return STATE_CRITICAL; 228 return STATE_CRITICAL;
255 } 229 }
256 230
257 if (smart_cmd_simple (fd, SMART_CMD_ENABLE, 0, false)) { 231 if (smart_cmd_simple(fd, SMART_CMD_ENABLE, 0, false)) {
258 printf (_("CRITICAL - SMART_CMD_ENABLE\n")); 232 printf(_("CRITICAL - SMART_CMD_ENABLE\n"));
259 return STATE_CRITICAL; 233 return STATE_CRITICAL;
260 } 234 }
261 235
262 smart_read_values (fd, &values); 236 smart_read_values(fd, &values);
263 smart_read_thresholds (fd, &thresholds); 237 smart_read_thresholds(fd, &thresholds);
264 retval = nagios (&values, &thresholds); 238 retval = nagios(&values, &thresholds);
265 if (verbose) print_values (&values, &thresholds); 239 if (verbose)
240 print_values(&values, &thresholds);
266 241
267 close (fd); 242 close(fd);
268 return retval; 243 return retval;
269} 244}
270 245
271 246char *get_offline_text(int status) {
272
273char *
274get_offline_text (int status)
275{
276 int i; 247 int i;
277 for (i = 0; offline_status_text[i].text; i++) { 248 for (i = 0; offline_status_text[i].text; i++) {
278 if (offline_status_text[i].value == status) { 249 if (offline_status_text[i].value == status) {
@@ -282,11 +253,7 @@ get_offline_text (int status)
282 return "UNKNOWN"; 253 return "UNKNOWN";
283} 254}
284 255
285 256int smart_read_values(int fd, values_t *values) {
286
287int
288smart_read_values (int fd, values_t * values)
289{
290#ifdef __linux__ 257#ifdef __linux__
291 int e; 258 int e;
292 __u8 args[4 + 512]; 259 __u8 args[4 + 512];
@@ -294,12 +261,12 @@ smart_read_values (int fd, values_t * values)
294 args[1] = 0; 261 args[1] = 0;
295 args[2] = SMART_READ_VALUES; 262 args[2] = SMART_READ_VALUES;
296 args[3] = 1; 263 args[3] = 1;
297 if (ioctl (fd, HDIO_DRIVE_CMD, &args)) { 264 if (ioctl(fd, HDIO_DRIVE_CMD, &args)) {
298 e = errno; 265 e = errno;
299 printf (_("CRITICAL - SMART_READ_VALUES: %s\n"), strerror (errno)); 266 printf(_("CRITICAL - SMART_READ_VALUES: %s\n"), strerror(errno));
300 return e; 267 return e;
301 } 268 }
302 memcpy (values, args + 4, 512); 269 memcpy(values, args + 4, 512);
303#endif /* __linux__ */ 270#endif /* __linux__ */
304#ifdef __NetBSD__ 271#ifdef __NetBSD__
305 struct atareq req; 272 struct atareq req;
@@ -323,7 +290,7 @@ smart_read_values (int fd, values_t * values)
323 290
324 if (errno != 0) { 291 if (errno != 0) {
325 int e = errno; 292 int e = errno;
326 printf (_("CRITICAL - SMART_READ_VALUES: %s\n"), strerror (errno)); 293 printf(_("CRITICAL - SMART_READ_VALUES: %s\n"), strerror(errno));
327 return e; 294 return e;
328 } 295 }
329 296
@@ -332,13 +299,9 @@ smart_read_values (int fd, values_t * values)
332 return 0; 299 return 0;
333} 300}
334 301
335 302int nagios(values_t *p, thresholds_t *t) {
336 303 value_t *value = p->values;
337int 304 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; 305 int status = OPERATIONAL;
343 int prefailure = 0; 306 int prefailure = 0;
344 int advisory = 0; 307 int advisory = 0;
@@ -353,13 +316,11 @@ nagios (values_t * p, thresholds_t * t)
353 if (value->status & 1) { 316 if (value->status & 1) {
354 status = PREFAILURE; 317 status = PREFAILURE;
355 ++prefailure; 318 ++prefailure;
356 } 319 } else {
357 else {
358 status = ADVISORY; 320 status = ADVISORY;
359 ++advisory; 321 ++advisory;
360 } 322 }
361 } 323 } else {
362 else {
363 ++passed; 324 ++passed;
364 } 325 }
365 ++total; 326 ++total;
@@ -369,81 +330,49 @@ nagios (values_t * p, thresholds_t * t)
369 } 330 }
370 switch (status) { 331 switch (status) {
371 case PREFAILURE: 332 case PREFAILURE:
372 printf (_("CRITICAL - %d Harddrive PreFailure%cDetected! %d/%d tests failed.\n"), 333 printf(_("CRITICAL - %d Harddrive PreFailure%cDetected! %d/%d tests failed.\n"), prefailure, prefailure > 1 ? 's' : ' ', failed,
373 prefailure, 334 total);
374 prefailure > 1 ? 's' : ' ', 335 status = STATE_CRITICAL;
375 failed,
376 total);
377 status=STATE_CRITICAL;
378 break; 336 break;
379 case ADVISORY: 337 case ADVISORY:
380 printf (_("WARNING - %d Harddrive Advisor%s Detected. %d/%d tests failed.\n"), 338 printf(_("WARNING - %d Harddrive Advisor%s Detected. %d/%d tests failed.\n"), advisory, advisory > 1 ? "ies" : "y", failed, total);
381 advisory, 339 status = STATE_WARNING;
382 advisory > 1 ? "ies" : "y",
383 failed,
384 total);
385 status=STATE_WARNING;
386 break; 340 break;
387 case OPERATIONAL: 341 case OPERATIONAL:
388 printf (_("OK - Operational (%d/%d tests passed)\n"), passed, total); 342 printf(_("OK - Operational (%d/%d tests passed)\n"), passed, total);
389 status=STATE_OK; 343 status = STATE_OK;
390 break; 344 break;
391 default: 345 default:
392 printf (_("ERROR - Status '%d' unknown. %d/%d tests passed\n"), status, 346 printf(_("ERROR - Status '%d' unknown. %d/%d tests passed\n"), status, passed, total);
393 passed, total);
394 status = STATE_UNKNOWN; 347 status = STATE_UNKNOWN;
395 break; 348 break;
396 } 349 }
397 return status; 350 return status;
398} 351}
399 352
400 353void print_value(value_t *p, threshold_t *t) {
401 354 printf("Id=%3d, Status=%2d {%s , %s}, Value=%3d, Threshold=%3d, %s\n", p->id, p->status, p->status & 1 ? "PreFailure" : "Advisory ",
402void 355 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} 356}
410 357
411 358void print_values(values_t *p, thresholds_t *t) {
412 359 value_t *value = p->values;
413void 360 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; 361 int i;
419 for (i = 0; i < NR_ATTRIBUTES; i++) { 362 for (i = 0; i < NR_ATTRIBUTES; i++) {
420 if (value->id && threshold->id && value->id == threshold->id) { 363 if (value->id && threshold->id && value->id == threshold->id) {
421 print_value (value++, threshold++); 364 print_value(value++, threshold++);
422 } 365 }
423 } 366 }
424 printf 367 printf(_("OffLineStatus=%d {%s}, AutoOffLine=%s, OffLineTimeout=%d minutes\n"), p->offline_status,
425 (_("OffLineStatus=%d {%s}, AutoOffLine=%s, OffLineTimeout=%d minutes\n"), 368 get_offline_text(p->offline_status & 0x7f), (p->offline_status & 0x80 ? "Yes" : "No"), p->offline_timeout / 60);
426 p->offline_status, 369 printf(_("OffLineCapability=%d {%s %s %s}\n"), p->offline_capability, p->offline_capability & 1 ? "Immediate" : "",
427 get_offline_text (p->offline_status & 0x7f), 370 p->offline_capability & 2 ? "Auto" : "", p->offline_capability & 4 ? "AbortOnCmd" : "SuspendOnCmd");
428 (p->offline_status & 0x80 ? "Yes" : "No"), 371 printf(_("SmartRevision=%d, CheckSum=%d, SmartCapability=%d {%s %s}\n"), p->revision, p->checksum, p->smart_capability,
429 p->offline_timeout / 60); 372 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} 373}
444 374
445 375int 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; 376 int e = STATE_UNKNOWN;
448#ifdef __linux__ 377#ifdef __linux__
449 __u8 args[4]; 378 __u8 args[4];
@@ -451,14 +380,14 @@ int smart_cmd_simple (int fd, enum SmartCommand command, __u8 val0, bool show_er
451 args[1] = val0; 380 args[1] = val0;
452 args[2] = smart_command[command].value; 381 args[2] = smart_command[command].value;
453 args[3] = 0; 382 args[3] = 0;
454 if (ioctl (fd, HDIO_DRIVE_CMD, &args)) { 383 if (ioctl(fd, HDIO_DRIVE_CMD, &args)) {
455 e = STATE_CRITICAL; 384 e = STATE_CRITICAL;
456 if (show_error) 385 if (show_error)
457 printf (_("CRITICAL - %s: %s\n"), smart_command[command].text, strerror (errno)); 386 printf(_("CRITICAL - %s: %s\n"), smart_command[command].text, strerror(errno));
458 } else { 387 } else {
459 e = STATE_OK; 388 e = STATE_OK;
460 if (show_error) 389 if (show_error)
461 printf (_("OK - Command sent (%s)\n"), smart_command[command].text); 390 printf(_("OK - Command sent (%s)\n"), smart_command[command].text);
462 } 391 }
463 392
464#endif /* __linux__ */ 393#endif /* __linux__ */
@@ -483,35 +412,31 @@ int smart_cmd_simple (int fd, enum SmartCommand command, __u8 val0, bool show_er
483 if (errno != 0) { 412 if (errno != 0) {
484 e = STATE_CRITICAL; 413 e = STATE_CRITICAL;
485 if (show_error) 414 if (show_error)
486 printf (_("CRITICAL - %s: %s\n"), smart_command[command].text, strerror (errno)); 415 printf(_("CRITICAL - %s: %s\n"), smart_command[command].text, strerror(errno));
487 } else { 416 } else {
488 e = STATE_OK; 417 e = STATE_OK;
489 if (show_error) 418 if (show_error)
490 printf (_("OK - Command sent (%s)\n"), smart_command[command].text); 419 printf(_("OK - Command sent (%s)\n"), smart_command[command].text);
491 } 420 }
492 421
493#endif /* __NetBSD__ */ 422#endif /* __NetBSD__ */
494 return e; 423 return e;
495} 424}
496 425
497 426int smart_read_thresholds(int fd, thresholds_t *thresholds) {
498
499int
500smart_read_thresholds (int fd, thresholds_t * thresholds)
501{
502#ifdef __linux__ 427#ifdef __linux__
503 int e; 428 int e;
504 __u8 args[4 + 512]; 429 __u8 args[4 + 512];
505 args[0] = WIN_SMART; 430 args[0] = WIN_SMART;
506 args[1] = 0; 431 args[1] = 0;
507 args[2] = SMART_READ_THRESHOLDS; 432 args[2] = SMART_READ_THRESHOLDS;
508 args[3] = 1; 433 args[3] = 1;
509 if (ioctl (fd, HDIO_DRIVE_CMD, &args)) { 434 if (ioctl(fd, HDIO_DRIVE_CMD, &args)) {
510 e = errno; 435 e = errno;
511 printf (_("CRITICAL - SMART_READ_THRESHOLDS: %s\n"), strerror (errno)); 436 printf(_("CRITICAL - SMART_READ_THRESHOLDS: %s\n"), strerror(errno));
512 return e; 437 return e;
513 } 438 }
514 memcpy (thresholds, args + 4, 512); 439 memcpy(thresholds, args + 4, 512);
515#endif /* __linux__ */ 440#endif /* __linux__ */
516#ifdef __NetBSD__ 441#ifdef __NetBSD__
517 struct atareq req; 442 struct atareq req;
@@ -535,7 +460,7 @@ smart_read_thresholds (int fd, thresholds_t * thresholds)
535 460
536 if (errno != 0) { 461 if (errno != 0) {
537 int e = errno; 462 int e = errno;
538 printf (_("CRITICAL - SMART_READ_THRESHOLDS: %s\n"), strerror (errno)); 463 printf(_("CRITICAL - SMART_READ_THRESHOLDS: %s\n"), strerror(errno));
539 return e; 464 return e;
540 } 465 }
541 466
@@ -544,45 +469,43 @@ smart_read_thresholds (int fd, thresholds_t * thresholds)
544 return 0; 469 return 0;
545} 470}
546 471
472void print_help(void) {
473 print_revision(progname, NP_VERSION);
547 474
548void 475 printf("(C) 1999 Ragnar Hojland Espinosa <ragnar@lightside.dhis.org>\n");
549print_help (void) 476 printf("Plugin implementation - 1999 Robert Dale <rdale@digital-mission.com>\n");
550{ 477 printf(COPYRIGHT, copyright, email);
551 print_revision (progname, NP_VERSION);
552 478
553 printf ("(C) 1999 Ragnar Hojland Espinosa <ragnar@lightside.dhis.org>\n"); 479 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"); 480 "[http://smartlinux.sourceforge.net/smart/index.php]."));
555 printf (COPYRIGHT, copyright, email);
556 481
557 printf (_("This plugin checks a local hard drive with the (Linux specific) SMART interface [http://smartlinux.sourceforge.net/smart/index.php].")); 482 printf("\n\n");
558 483
559 printf ("\n\n"); 484 print_usage();
560 485
561 print_usage (); 486 printf(UT_HELP_VRSN);
487 printf(UT_EXTRA_OPTS);
562 488
563 printf (UT_HELP_VRSN); 489 printf(" %s\n", "-d, --device=DEVICE");
564 printf (UT_EXTRA_OPTS); 490 printf(" %s\n", _("Select device DEVICE"));
491 printf(" %s\n", _("Note: if the device is specified without this option, any further option will"));
492 printf(" %s\n", _("be ignored."));
565 493
566 printf (" %s\n", "-d, --device=DEVICE"); 494 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 495
571 printf (UT_VERBOSE); 496 printf("\n");
497 printf("%s\n", _("Notes:"));
498 printf(" %s\n", _("The SMART command modes (-i/--immediate, -0/--auto-off and -1/--auto-on) were"));
499 printf(" %s\n", _("broken in an underhand manner and have been disabled. You can use smartctl"));
500 printf(" %s\n", _("instead:"));
501 printf(" %s\n", _("-0/--auto-off: use \"smartctl --offlineauto=off\""));
502 printf(" %s\n", _("-1/--auto-on: use \"smartctl --offlineauto=on\""));
503 printf(" %s\n", _("-i/--immediate: use \"smartctl --test=offline\""));
572 504
573 printf ("\n"); 505 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} 506}
584 507
585 /* todo : add to the long nanual as example 508/* todo : add to the long nanual as example
586 * 509 *
587 * Run with: check_ide-smart --nagios [-d] <DRIVE> 510 * Run with: check_ide-smart --nagios [-d] <DRIVE>
588 * Where DRIVE is an IDE drive, ie. /dev/hda, /dev/hdb, /dev/hdc 511 * Where DRIVE is an IDE drive, ie. /dev/hda, /dev/hdb, /dev/hdc
@@ -593,10 +516,7 @@ print_help (void)
593 * - Returns -1 not too often 516 * - Returns -1 not too often
594 */ 517 */
595 518
596 519void print_usage(void) {
597void 520 printf("%s\n", _("Usage:"));
598print_usage (void) 521 printf("%s [-d <device>] [-v]", progname);
599{
600 printf ("%s\n", _("Usage:"));
601 printf ("%s [-d <device>] [-v]", progname);
602} 522}