diff options
| author | Holger Weiss <holger@zedat.fu-berlin.de> | 2013-08-20 00:41:16 +0200 | 
|---|---|---|
| committer | Holger Weiss <holger@zedat.fu-berlin.de> | 2013-08-20 00:41:16 +0200 | 
| commit | 36a9b52caeae27e44e9f336e2701bda67a3959a2 (patch) | |
| tree | ef38bbae3ae16ee565bd33510d11e91c9455fbca | |
| parent | a15b062e44ae0da805d5569f25015e28dd8552fd (diff) | |
| download | monitoring-plugins-36a9b52caeae27e44e9f336e2701bda67a3959a2.tar.gz | |
check_ide_smart: Add support for NetBSD
Thanks to Emmanuel Dreyfus for providing the patch.
| -rw-r--r-- | NEWS | 1 | ||||
| -rw-r--r-- | THANKS.in | 1 | ||||
| -rw-r--r-- | configure.in | 32 | ||||
| -rw-r--r-- | plugins/check_ide_smart.c | 109 | 
4 files changed, 135 insertions, 8 deletions
| @@ -29,6 +29,7 @@ This file documents the major additions and syntax changes between releases. | |||
| 29 | New check_mysql -f option to specify a client options file | 29 | New check_mysql -f option to specify a client options file | 
| 30 | New check_mysql -g option to specify a client options group | 30 | New check_mysql -g option to specify a client options group | 
| 31 | New check_snmp --offset option to allow for adding/substracting an offset value to sensor data | 31 | New check_snmp --offset option to allow for adding/substracting an offset value to sensor data | 
| 32 | Let check_ide_smart support NetBSD | ||
| 32 | 33 | ||
| 33 | FIXES | 34 | FIXES | 
| 34 | Change the MAIL FROM command generated by check_smtp to be RFC compliant | 35 | Change the MAIL FROM command generated by check_smtp to be RFC compliant | 
| @@ -285,3 +285,4 @@ Roman Fiedler | |||
| 285 | Fabio Rueda | 285 | Fabio Rueda | 
| 286 | Gabriele Tozzi | 286 | Gabriele Tozzi | 
| 287 | Sebastian Nohn | 287 | Sebastian Nohn | 
| 288 | Emmanuel Dreyfus | ||
| diff --git a/configure.in b/configure.in index bbcbb71c..de75e532 100644 --- a/configure.in +++ b/configure.in | |||
| @@ -317,16 +317,34 @@ AS_IF([test "x$with_ldap" != "xno"], [ | |||
| 317 | ]) | 317 | ]) | 
| 318 | 318 | ||
| 319 | dnl Check for headers used by check_ide_smart | 319 | dnl Check for headers used by check_ide_smart | 
| 320 | AC_CHECK_HEADER(linux/hdreg.h, FOUNDINCLUDE=yes, FOUNDINCLUDE=no) | 320 | case $host in | 
| 321 | if test "$FOUNDINCLUDE" = "yes" ; then | 321 | *linux*) | 
| 322 | AC_CHECK_HEADER(linux/types.h, FOUNDINCLUDE=yes, FOUNDINCLUDE=no) | 322 | AC_CHECK_HEADER(linux/hdreg.h, FOUNDINCLUDE=yes, FOUNDINCLUDE=no) | 
| 323 | fi | 323 | if test "$FOUNDINCLUDE" = "yes" ; then | 
| 324 | AC_CHECK_HEADER(linux/types.h, FOUNDINCLUDE=yes, FOUNDINCLUDE=no) | ||
| 325 | fi | ||
| 326 | if test "$FOUNDINCLUDE" = "no" ; then | ||
| 327 | AC_MSG_WARN([Skipping check_ide_smart plugin.]) | ||
| 328 | AC_MSG_WARN([check_ide_smart requires linux/hdreg.h and linux/types.h.]) | ||
| 329 | fi | ||
| 330 | ;; | ||
| 331 | *netbsd*) | ||
| 332 | AC_CHECK_HEADER(dev/ata/atareg.h, FOUNDINCLUDE=yes, FOUNDINCLUDE=no) | ||
| 333 | if test "$FOUNDINCLUDE" = "yes" ; then | ||
| 334 | AC_CHECK_HEADER(dev/ic/wdcreg.h, FOUNDINCLUDE=yes, FOUNDINCLUDE=no) | ||
| 335 | fi | ||
| 336 | if test "$FOUNDINCLUDE" = "no" ; then | ||
| 337 | AC_MSG_WARN([Skipping check_ide_smart plugin.]) | ||
| 338 | AC_MSG_WARN([check_ide_smart requires dev/ata/atareg.h and dev/ic/wdcreg.h]) | ||
| 339 | fi | ||
| 340 | ;; | ||
| 341 | *) | ||
| 342 | AC_MSG_WARN([Skipping check_ide_smart plugin.]) | ||
| 343 | AC_MSG_WARN([check_ide_smart works only on Linux and NetBSD]) | ||
| 344 | esac | ||
| 324 | 345 | ||
| 325 | if test "$FOUNDINCLUDE" = "yes" ; then | 346 | if test "$FOUNDINCLUDE" = "yes" ; then | 
| 326 | EXTRAS="$EXTRAS check_ide_smart" | 347 | EXTRAS="$EXTRAS check_ide_smart" | 
| 327 | else | ||
| 328 | AC_MSG_WARN([Skipping check_ide_smart plugin.]) | ||
| 329 | AC_MSG_WARN([check_ide_smart is linux specific. It requires linux/hdreg.h and linux/types.h.]) | ||
| 330 | fi | 348 | fi | 
| 331 | 349 | ||
| 332 | dnl Check for mysql libraries | 350 | dnl Check for mysql libraries | 
| diff --git a/plugins/check_ide_smart.c b/plugins/check_ide_smart.c index b942461b..e1a75ce3 100644 --- a/plugins/check_ide_smart.c +++ b/plugins/check_ide_smart.c | |||
| @@ -46,8 +46,29 @@ void print_usage (void); | |||
| 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 | #include <linux/hdreg.h> | 50 | #include <linux/hdreg.h> | 
| 50 | #include <linux/types.h> | 51 | #include <linux/types.h> | 
| 52 | |||
| 53 | #define OPEN_MODE O_RDONLY | ||
| 54 | #endif /* linux */ | ||
| 55 | #ifdef __NetBSD__ | ||
| 56 | #include <sys/device.h> | ||
| 57 | #include <sys/param.h> | ||
| 58 | #include <sys/sysctl.h> | ||
| 59 | #include <sys/videoio.h> /* for __u8 and friends */ | ||
| 60 | #include <sys/scsiio.h> | ||
| 61 | #include <sys/ataio.h> | ||
| 62 | #include <dev/ata/atareg.h> | ||
| 63 | #include <dev/ic/wdcreg.h> | ||
| 64 | |||
| 65 | #define SMART_ENABLE WDSM_ENABLE_OPS | ||
| 66 | #define SMART_DISABLE WDSM_DISABLE_OPS | ||
| 67 | #define SMART_IMMEDIATE_OFFLINE WDSM_EXEC_OFFL_IMM | ||
| 68 | #define SMART_AUTO_OFFLINE 0xdb /* undefined in NetBSD headers */ | ||
| 69 | |||
| 70 | #define OPEN_MODE O_RDWR | ||
| 71 | #endif /* __NetBSD__ */ | ||
| 51 | #include <errno.h> | 72 | #include <errno.h> | 
| 52 | 73 | ||
| 53 | #define NR_ATTRIBUTES 30 | 74 | #define NR_ATTRIBUTES 30 | 
| @@ -223,7 +244,7 @@ main (int argc, char *argv[]) | |||
| 223 | return STATE_OK; | 244 | return STATE_OK; | 
| 224 | } | 245 | } | 
| 225 | 246 | ||
| 226 | fd = open (device, O_RDONLY); | 247 | fd = open (device, OPEN_MODE); | 
| 227 | 248 | ||
| 228 | if (fd < 0) { | 249 | if (fd < 0) { | 
| 229 | printf (_("CRITICAL - Couldn't open device %s: %s\n"), device, strerror (errno)); | 250 | printf (_("CRITICAL - Couldn't open device %s: %s\n"), device, strerror (errno)); | 
| @@ -284,6 +305,7 @@ get_offline_text (int status) | |||
| 284 | int | 305 | int | 
| 285 | smart_read_values (int fd, values_t * values) | 306 | smart_read_values (int fd, values_t * values) | 
| 286 | { | 307 | { | 
| 308 | #ifdef linux | ||
| 287 | int e; | 309 | int e; | 
| 288 | __u8 args[4 + 512]; | 310 | __u8 args[4 + 512]; | 
| 289 | args[0] = WIN_SMART; | 311 | args[0] = WIN_SMART; | 
| @@ -296,6 +318,35 @@ smart_read_values (int fd, values_t * values) | |||
| 296 | return e; | 318 | return e; | 
| 297 | } | 319 | } | 
| 298 | memcpy (values, args + 4, 512); | 320 | memcpy (values, args + 4, 512); | 
| 321 | #endif /* linux */ | ||
| 322 | #ifdef __NetBSD__ | ||
| 323 | struct atareq req; | ||
| 324 | unsigned char inbuf[DEV_BSIZE]; | ||
| 325 | |||
| 326 | memset(&req, 0, sizeof(req)); | ||
| 327 | req.timeout = 1000; | ||
| 328 | memset(&inbuf, 0, sizeof(inbuf)); | ||
| 329 | |||
| 330 | req.flags = ATACMD_READ; | ||
| 331 | req.features = WDSM_RD_DATA; | ||
| 332 | req.command = WDCC_SMART; | ||
| 333 | req.databuf = (char *)inbuf; | ||
| 334 | req.datalen = sizeof(inbuf); | ||
| 335 | req.cylinder = WDSMART_CYL; | ||
| 336 | |||
| 337 | if (ioctl(fd, ATAIOCCOMMAND, &req) == 0) { | ||
| 338 | if (req.retsts != ATACMD_OK) | ||
| 339 | errno = ENODEV; | ||
| 340 | } | ||
| 341 | |||
| 342 | if (errno != 0) { | ||
| 343 | int e = errno; | ||
| 344 | printf (_("CRITICAL - SMART_READ_VALUES: %s\n"), strerror (errno)); | ||
| 345 | return e; | ||
| 346 | } | ||
| 347 | |||
| 348 | (void)memcpy(values, inbuf, 512); | ||
| 349 | #endif /* __NetBSD__ */ | ||
| 299 | return 0; | 350 | return 0; | 
| 300 | } | 351 | } | 
| 301 | 352 | ||
| @@ -439,6 +490,7 @@ int | |||
| 439 | smart_cmd_simple (int fd, enum SmartCommand command, __u8 val0, char show_error) | 490 | smart_cmd_simple (int fd, enum SmartCommand command, __u8 val0, char show_error) | 
| 440 | { | 491 | { | 
| 441 | int e = 0; | 492 | int e = 0; | 
| 493 | #ifdef linux | ||
| 442 | __u8 args[4]; | 494 | __u8 args[4]; | 
| 443 | args[0] = WIN_SMART; | 495 | args[0] = WIN_SMART; | 
| 444 | args[1] = val0; | 496 | args[1] = val0; | 
| @@ -450,6 +502,31 @@ smart_cmd_simple (int fd, enum SmartCommand command, __u8 val0, char show_error) | |||
| 450 | printf (_("CRITICAL - %s: %s\n"), smart_command[command].text, strerror (errno)); | 502 | printf (_("CRITICAL - %s: %s\n"), smart_command[command].text, strerror (errno)); | 
| 451 | } | 503 | } | 
| 452 | } | 504 | } | 
| 505 | #endif /* linux */ | ||
| 506 | #ifdef __NetBSD__ | ||
| 507 | struct atareq req; | ||
| 508 | |||
| 509 | memset(&req, 0, sizeof(req)); | ||
| 510 | req.timeout = 1000; | ||
| 511 | req.flags = ATACMD_READREG; | ||
| 512 | req.features = smart_command[command].value; | ||
| 513 | req.command = WDCC_SMART; | ||
| 514 | req.cylinder = WDSMART_CYL; | ||
| 515 | req.sec_count = val0; | ||
| 516 | |||
| 517 | if (ioctl(fd, ATAIOCCOMMAND, &req) == 0) { | ||
| 518 | if (req.retsts != ATACMD_OK) | ||
| 519 | errno = ENODEV; | ||
| 520 | if (req.cylinder != WDSMART_CYL) | ||
| 521 | errno = ENODEV; | ||
| 522 | } | ||
| 523 | |||
| 524 | if (errno != 0) { | ||
| 525 | e = errno; | ||
| 526 | printf (_("CRITICAL - %s: %s\n"), smart_command[command].text, strerror (errno)); | ||
| 527 | return e; | ||
| 528 | } | ||
| 529 | #endif /* __NetBSD__ */ | ||
| 453 | return e; | 530 | return e; | 
| 454 | } | 531 | } | 
| 455 | 532 | ||
| @@ -458,6 +535,7 @@ smart_cmd_simple (int fd, enum SmartCommand command, __u8 val0, char show_error) | |||
| 458 | int | 535 | int | 
| 459 | smart_read_thresholds (int fd, thresholds_t * thresholds) | 536 | smart_read_thresholds (int fd, thresholds_t * thresholds) | 
| 460 | { | 537 | { | 
| 538 | #ifdef linux | ||
| 461 | int e; | 539 | int e; | 
| 462 | __u8 args[4 + 512]; | 540 | __u8 args[4 + 512]; | 
| 463 | args[0] = WIN_SMART; | 541 | args[0] = WIN_SMART; | 
| @@ -470,6 +548,35 @@ smart_read_thresholds (int fd, thresholds_t * thresholds) | |||
| 470 | return e; | 548 | return e; | 
| 471 | } | 549 | } | 
| 472 | memcpy (thresholds, args + 4, 512); | 550 | memcpy (thresholds, args + 4, 512); | 
| 551 | #endif /* linux */ | ||
| 552 | #ifdef __NetBSD__ | ||
| 553 | struct atareq req; | ||
| 554 | unsigned char inbuf[DEV_BSIZE]; | ||
| 555 | |||
| 556 | memset(&req, 0, sizeof(req)); | ||
| 557 | req.timeout = 1000; | ||
| 558 | memset(&inbuf, 0, sizeof(inbuf)); | ||
| 559 | |||
| 560 | req.flags = ATACMD_READ; | ||
| 561 | req.features = WDSM_RD_THRESHOLDS; | ||
| 562 | req.command = WDCC_SMART; | ||
| 563 | req.databuf = (char *)inbuf; | ||
| 564 | req.datalen = sizeof(inbuf); | ||
| 565 | req.cylinder = WDSMART_CYL; | ||
| 566 | |||
| 567 | if (ioctl(fd, ATAIOCCOMMAND, &req) == 0) { | ||
| 568 | if (req.retsts != ATACMD_OK) | ||
| 569 | errno = ENODEV; | ||
| 570 | } | ||
| 571 | |||
| 572 | if (errno != 0) { | ||
| 573 | int e = errno; | ||
| 574 | printf (_("CRITICAL - SMART_READ_THRESHOLDS: %s\n"), strerror (errno)); | ||
| 575 | return e; | ||
| 576 | } | ||
| 577 | |||
| 578 | (void)memcpy(thresholds, inbuf, 512); | ||
| 579 | #endif /* __NetBSD__ */ | ||
| 473 | return 0; | 580 | return 0; | 
| 474 | } | 581 | } | 
| 475 | 582 | ||
