diff options
Diffstat (limited to 'plugins/check_ide_smart.c')
-rw-r--r-- | plugins/check_ide_smart.c | 90 |
1 files changed, 49 insertions, 41 deletions
diff --git a/plugins/check_ide_smart.c b/plugins/check_ide_smart.c index 9640ef70..16fe3d01 100644 --- a/plugins/check_ide_smart.c +++ b/plugins/check_ide_smart.c | |||
@@ -56,7 +56,6 @@ void print_usage(void); | |||
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 */ | ||
60 | # include <sys/scsiio.h> | 59 | # include <sys/scsiio.h> |
61 | # include <sys/ataio.h> | 60 | # include <sys/ataio.h> |
62 | # include <dev/ata/atareg.h> | 61 | # include <dev/ata/atareg.h> |
@@ -79,48 +78,47 @@ void print_usage(void); | |||
79 | #define UNKNOWN -1 | 78 | #define UNKNOWN -1 |
80 | 79 | ||
81 | typedef struct threshold_s { | 80 | typedef struct threshold_s { |
82 | __u8 id; | 81 | uint8_t id; |
83 | __u8 threshold; | 82 | uint8_t threshold; |
84 | __u8 reserved[10]; | 83 | uint8_t reserved[10]; |
85 | } __attribute__((packed)) threshold_t; | 84 | } __attribute__((packed)) threshold_t; |
86 | 85 | ||
87 | typedef struct thresholds_s { | 86 | typedef struct thresholds_s { |
88 | __u16 revision; | 87 | uint16_t revision; |
89 | threshold_t thresholds[NR_ATTRIBUTES]; | 88 | threshold_t thresholds[NR_ATTRIBUTES]; |
90 | __u8 reserved[18]; | 89 | uint8_t reserved[18]; |
91 | __u8 vendor[131]; | 90 | uint8_t vendor[131]; |
92 | __u8 checksum; | 91 | uint8_t checksum; |
93 | } __attribute__((packed)) thresholds_t; | 92 | } __attribute__((packed)) thresholds_t; |
94 | 93 | ||
95 | typedef struct value_s { | 94 | typedef struct value_s { |
96 | __u8 id; | 95 | uint8_t id; |
97 | __u16 status; | 96 | uint16_t status; |
98 | __u8 value; | 97 | uint8_t value; |
99 | __u8 vendor[8]; | 98 | uint8_t vendor[8]; |
100 | } __attribute__((packed)) value_t; | 99 | } __attribute__((packed)) value_t; |
101 | 100 | ||
102 | typedef struct values_s { | 101 | typedef struct values_s { |
103 | __u16 revision; | 102 | uint16_t revision; |
104 | value_t values[NR_ATTRIBUTES]; | 103 | value_t values[NR_ATTRIBUTES]; |
105 | __u8 offline_status; | 104 | uint8_t offline_status; |
106 | __u8 vendor1; | 105 | uint8_t vendor1; |
107 | __u16 offline_timeout; | 106 | uint16_t offline_timeout; |
108 | __u8 vendor2; | 107 | uint8_t vendor2; |
109 | __u8 offline_capability; | 108 | uint8_t offline_capability; |
110 | __u16 smart_capability; | 109 | uint16_t smart_capability; |
111 | __u8 reserved[16]; | 110 | uint8_t reserved[16]; |
112 | __u8 vendor[125]; | 111 | uint8_t vendor[125]; |
113 | __u8 checksum; | 112 | uint8_t checksum; |
114 | } __attribute__((packed)) values_t; | 113 | } __attribute__((packed)) values_t; |
115 | 114 | ||
116 | static struct { | 115 | static struct { |
117 | __u8 value; | 116 | uint8_t value; |
118 | char *text; | 117 | char *text; |
119 | } offline_status_text[] = {{0x00, "NeverStarted"}, {0x02, "Completed"}, {0x04, "Suspended"}, | 118 | } offline_status_text[] = {{0x00, "NeverStarted"}, {0x02, "Completed"}, {0x04, "Suspended"}, {0x05, "Aborted"}, {0x06, "Failed"}, {0, 0}}; |
120 | {0x05, "Aborted"}, {0x06, "Failed"}, {0, 0}}; | ||
121 | 119 | ||
122 | static struct { | 120 | static struct { |
123 | __u8 value; | 121 | uint8_t value; |
124 | char *text; | 122 | char *text; |
125 | } smart_command[] = {{SMART_ENABLE, "SMART_ENABLE"}, | 123 | } smart_command[] = {{SMART_ENABLE, "SMART_ENABLE"}, |
126 | {SMART_DISABLE, "SMART_DISABLE"}, | 124 | {SMART_DISABLE, "SMART_DISABLE"}, |
@@ -140,7 +138,7 @@ static int smart_read_values(int, values_t *); | |||
140 | static int nagios(values_t *, thresholds_t *); | 138 | static int nagios(values_t *, thresholds_t *); |
141 | static void print_value(value_t *, threshold_t *); | 139 | static void print_value(value_t *, threshold_t *); |
142 | static void print_values(values_t *, thresholds_t *); | 140 | static void print_values(values_t *, thresholds_t *); |
143 | static int smart_cmd_simple(int, enum SmartCommand, __u8, bool); | 141 | static int smart_cmd_simple(int, enum SmartCommand, uint8_t, bool); |
144 | static int smart_read_thresholds(int, thresholds_t *); | 142 | static int smart_read_thresholds(int, thresholds_t *); |
145 | static bool verbose = false; | 143 | static bool verbose = false; |
146 | 144 | ||
@@ -175,8 +173,9 @@ int main(int argc, char *argv[]) { | |||
175 | 173 | ||
176 | o = getopt_long(argc, argv, "+d:iq10nhVv", longopts, &longindex); | 174 | o = getopt_long(argc, argv, "+d:iq10nhVv", longopts, &longindex); |
177 | 175 | ||
178 | if (o == -1 || o == EOF || o == 1) | 176 | if (o == -1 || o == EOF || o == 1) { |
179 | break; | 177 | break; |
178 | } | ||
180 | 179 | ||
181 | switch (o) { | 180 | switch (o) { |
182 | case 'd': | 181 | case 'd': |
@@ -234,8 +233,9 @@ int main(int argc, char *argv[]) { | |||
234 | smart_read_values(fd, &values); | 233 | smart_read_values(fd, &values); |
235 | smart_read_thresholds(fd, &thresholds); | 234 | smart_read_thresholds(fd, &thresholds); |
236 | retval = nagios(&values, &thresholds); | 235 | retval = nagios(&values, &thresholds); |
237 | if (verbose) | 236 | if (verbose) { |
238 | print_values(&values, &thresholds); | 237 | print_values(&values, &thresholds); |
238 | } | ||
239 | 239 | ||
240 | close(fd); | 240 | close(fd); |
241 | return retval; | 241 | return retval; |
@@ -254,7 +254,7 @@ char *get_offline_text(int status) { | |||
254 | int smart_read_values(int fd, values_t *values) { | 254 | int smart_read_values(int fd, values_t *values) { |
255 | #ifdef __linux__ | 255 | #ifdef __linux__ |
256 | int e; | 256 | int e; |
257 | __u8 args[4 + 512]; | 257 | uint8_t args[4 + 512]; |
258 | args[0] = WIN_SMART; | 258 | args[0] = WIN_SMART; |
259 | args[1] = 0; | 259 | args[1] = 0; |
260 | args[2] = SMART_READ_VALUES; | 260 | args[2] = SMART_READ_VALUES; |
@@ -282,8 +282,9 @@ int smart_read_values(int fd, values_t *values) { | |||
282 | req.cylinder = WDSMART_CYL; | 282 | req.cylinder = WDSMART_CYL; |
283 | 283 | ||
284 | if (ioctl(fd, ATAIOCCOMMAND, &req) == 0) { | 284 | if (ioctl(fd, ATAIOCCOMMAND, &req) == 0) { |
285 | if (req.retsts != ATACMD_OK) | 285 | if (req.retsts != ATACMD_OK) { |
286 | errno = ENODEV; | 286 | errno = ENODEV; |
287 | } | ||
287 | } | 288 | } |
288 | 289 | ||
289 | if (errno != 0) { | 290 | if (errno != 0) { |
@@ -370,22 +371,24 @@ void print_values(values_t *p, thresholds_t *t) { | |||
370 | p->smart_capability & 1 ? "SaveOnStandBy" : "", p->smart_capability & 2 ? "AutoSave" : ""); | 371 | p->smart_capability & 1 ? "SaveOnStandBy" : "", p->smart_capability & 2 ? "AutoSave" : ""); |
371 | } | 372 | } |
372 | 373 | ||
373 | int smart_cmd_simple(int fd, enum SmartCommand command, __u8 val0, bool show_error) { | 374 | int smart_cmd_simple(int fd, enum SmartCommand command, uint8_t val0, bool show_error) { |
374 | int e = STATE_UNKNOWN; | 375 | int e = STATE_UNKNOWN; |
375 | #ifdef __linux__ | 376 | #ifdef __linux__ |
376 | __u8 args[4]; | 377 | uint8_t args[4]; |
377 | args[0] = WIN_SMART; | 378 | args[0] = WIN_SMART; |
378 | args[1] = val0; | 379 | args[1] = val0; |
379 | args[2] = smart_command[command].value; | 380 | args[2] = smart_command[command].value; |
380 | args[3] = 0; | 381 | args[3] = 0; |
381 | if (ioctl(fd, HDIO_DRIVE_CMD, &args)) { | 382 | if (ioctl(fd, HDIO_DRIVE_CMD, &args)) { |
382 | e = STATE_CRITICAL; | 383 | e = STATE_CRITICAL; |
383 | if (show_error) | 384 | if (show_error) { |
384 | printf(_("CRITICAL - %s: %s\n"), smart_command[command].text, strerror(errno)); | 385 | printf(_("CRITICAL - %s: %s\n"), smart_command[command].text, strerror(errno)); |
386 | } | ||
385 | } else { | 387 | } else { |
386 | e = STATE_OK; | 388 | e = STATE_OK; |
387 | if (show_error) | 389 | if (show_error) { |
388 | printf(_("OK - Command sent (%s)\n"), smart_command[command].text); | 390 | printf(_("OK - Command sent (%s)\n"), smart_command[command].text); |
391 | } | ||
389 | } | 392 | } |
390 | 393 | ||
391 | #endif /* __linux__ */ | 394 | #endif /* __linux__ */ |
@@ -401,20 +404,24 @@ int smart_cmd_simple(int fd, enum SmartCommand command, __u8 val0, bool show_err | |||
401 | req.sec_count = val0; | 404 | req.sec_count = val0; |
402 | 405 | ||
403 | if (ioctl(fd, ATAIOCCOMMAND, &req) == 0) { | 406 | if (ioctl(fd, ATAIOCCOMMAND, &req) == 0) { |
404 | if (req.retsts != ATACMD_OK) | 407 | if (req.retsts != ATACMD_OK) { |
405 | errno = ENODEV; | 408 | errno = ENODEV; |
406 | if (req.cylinder != WDSMART_CYL) | 409 | } |
410 | if (req.cylinder != WDSMART_CYL) { | ||
407 | errno = ENODEV; | 411 | errno = ENODEV; |
412 | } | ||
408 | } | 413 | } |
409 | 414 | ||
410 | if (errno != 0) { | 415 | if (errno != 0) { |
411 | e = STATE_CRITICAL; | 416 | e = STATE_CRITICAL; |
412 | if (show_error) | 417 | if (show_error) { |
413 | printf(_("CRITICAL - %s: %s\n"), smart_command[command].text, strerror(errno)); | 418 | printf(_("CRITICAL - %s: %s\n"), smart_command[command].text, strerror(errno)); |
419 | } | ||
414 | } else { | 420 | } else { |
415 | e = STATE_OK; | 421 | e = STATE_OK; |
416 | if (show_error) | 422 | if (show_error) { |
417 | printf(_("OK - Command sent (%s)\n"), smart_command[command].text); | 423 | printf(_("OK - Command sent (%s)\n"), smart_command[command].text); |
424 | } | ||
418 | } | 425 | } |
419 | 426 | ||
420 | #endif /* __NetBSD__ */ | 427 | #endif /* __NetBSD__ */ |
@@ -424,7 +431,7 @@ int smart_cmd_simple(int fd, enum SmartCommand command, __u8 val0, bool show_err | |||
424 | int smart_read_thresholds(int fd, thresholds_t *thresholds) { | 431 | int smart_read_thresholds(int fd, thresholds_t *thresholds) { |
425 | #ifdef __linux__ | 432 | #ifdef __linux__ |
426 | int e; | 433 | int e; |
427 | __u8 args[4 + 512]; | 434 | uint8_t args[4 + 512]; |
428 | args[0] = WIN_SMART; | 435 | args[0] = WIN_SMART; |
429 | args[1] = 0; | 436 | args[1] = 0; |
430 | args[2] = SMART_READ_THRESHOLDS; | 437 | args[2] = SMART_READ_THRESHOLDS; |
@@ -452,8 +459,9 @@ int smart_read_thresholds(int fd, thresholds_t *thresholds) { | |||
452 | req.cylinder = WDSMART_CYL; | 459 | req.cylinder = WDSMART_CYL; |
453 | 460 | ||
454 | if (ioctl(fd, ATAIOCCOMMAND, &req) == 0) { | 461 | if (ioctl(fd, ATAIOCCOMMAND, &req) == 0) { |
455 | if (req.retsts != ATACMD_OK) | 462 | if (req.retsts != ATACMD_OK) { |
456 | errno = ENODEV; | 463 | errno = ENODEV; |
464 | } | ||
457 | } | 465 | } |
458 | 466 | ||
459 | if (errno != 0) { | 467 | if (errno != 0) { |