summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--NEWS1
-rw-r--r--THANKS.in1
-rw-r--r--configure.in32
-rw-r--r--plugins/check_ide_smart.c109
4 files changed, 135 insertions, 8 deletions
diff --git a/NEWS b/NEWS
index b16c4e41..1668dc4e 100644
--- a/NEWS
+++ b/NEWS
@@ -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
diff --git a/THANKS.in b/THANKS.in
index 54315afa..61181434 100644
--- a/THANKS.in
+++ b/THANKS.in
@@ -285,3 +285,4 @@ Roman Fiedler
285Fabio Rueda 285Fabio Rueda
286Gabriele Tozzi 286Gabriele Tozzi
287Sebastian Nohn 287Sebastian Nohn
288Emmanuel 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
319dnl Check for headers used by check_ide_smart 319dnl Check for headers used by check_ide_smart
320AC_CHECK_HEADER(linux/hdreg.h, FOUNDINCLUDE=yes, FOUNDINCLUDE=no) 320case $host in
321if 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)
323fi 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])
344esac
324 345
325if test "$FOUNDINCLUDE" = "yes" ; then 346if test "$FOUNDINCLUDE" = "yes" ; then
326 EXTRAS="$EXTRAS check_ide_smart" 347 EXTRAS="$EXTRAS check_ide_smart"
327else
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.])
330fi 348fi
331 349
332dnl Check for mysql libraries 350dnl 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)
284int 305int
285smart_read_values (int fd, values_t * values) 306smart_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
439smart_cmd_simple (int fd, enum SmartCommand command, __u8 val0, char show_error) 490smart_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)
458int 535int
459smart_read_thresholds (int fd, thresholds_t * thresholds) 536smart_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