[nagiosplug] check_ide_smart: Add support for NetBSD
Nagios Plugin Development
nagios-plugins at users.sourceforge.net
Tue Aug 20 01:00:13 CEST 2013
Module: nagiosplug
Branch: master
Commit: 36a9b52caeae27e44e9f336e2701bda67a3959a2
Author: Holger Weiss <holger at zedat.fu-berlin.de>
Date: Tue Aug 20 00:41:16 2013 +0200
URL: http://nagiosplug.git.sf.net/git/gitweb.cgi?p=nagiosplug/nagiosplug;a=commit;h=36a9b52
check_ide_smart: Add support for NetBSD
Thanks to Emmanuel Dreyfus for providing the patch.
---
NEWS | 1 +
THANKS.in | 1 +
configure.in | 32 ++++++++++---
plugins/check_ide_smart.c | 109 ++++++++++++++++++++++++++++++++++++++++++++-
4 files changed, 135 insertions(+), 8 deletions(-)
diff --git a/NEWS b/NEWS
index b16c4e4..1668dc4 100644
--- a/NEWS
+++ b/NEWS
@@ -29,6 +29,7 @@ This file documents the major additions and syntax changes between releases.
New check_mysql -f option to specify a client options file
New check_mysql -g option to specify a client options group
New check_snmp --offset option to allow for adding/substracting an offset value to sensor data
+ Let check_ide_smart support NetBSD
FIXES
Change the MAIL FROM command generated by check_smtp to be RFC compliant
diff --git a/THANKS.in b/THANKS.in
index 54315af..6118143 100644
--- a/THANKS.in
+++ b/THANKS.in
@@ -285,3 +285,4 @@ Roman Fiedler
Fabio Rueda
Gabriele Tozzi
Sebastian Nohn
+Emmanuel Dreyfus
diff --git a/configure.in b/configure.in
index bbcbb71..de75e53 100644
--- a/configure.in
+++ b/configure.in
@@ -317,16 +317,34 @@ AS_IF([test "x$with_ldap" != "xno"], [
])
dnl Check for headers used by check_ide_smart
-AC_CHECK_HEADER(linux/hdreg.h, FOUNDINCLUDE=yes, FOUNDINCLUDE=no)
-if test "$FOUNDINCLUDE" = "yes" ; then
- AC_CHECK_HEADER(linux/types.h, FOUNDINCLUDE=yes, FOUNDINCLUDE=no)
-fi
+case $host in
+ *linux*)
+ AC_CHECK_HEADER(linux/hdreg.h, FOUNDINCLUDE=yes, FOUNDINCLUDE=no)
+ if test "$FOUNDINCLUDE" = "yes" ; then
+ AC_CHECK_HEADER(linux/types.h, FOUNDINCLUDE=yes, FOUNDINCLUDE=no)
+ fi
+ if test "$FOUNDINCLUDE" = "no" ; then
+ AC_MSG_WARN([Skipping check_ide_smart plugin.])
+ AC_MSG_WARN([check_ide_smart requires linux/hdreg.h and linux/types.h.])
+ fi
+ ;;
+ *netbsd*)
+ AC_CHECK_HEADER(dev/ata/atareg.h, FOUNDINCLUDE=yes, FOUNDINCLUDE=no)
+ if test "$FOUNDINCLUDE" = "yes" ; then
+ AC_CHECK_HEADER(dev/ic/wdcreg.h, FOUNDINCLUDE=yes, FOUNDINCLUDE=no)
+ fi
+ if test "$FOUNDINCLUDE" = "no" ; then
+ AC_MSG_WARN([Skipping check_ide_smart plugin.])
+ AC_MSG_WARN([check_ide_smart requires dev/ata/atareg.h and dev/ic/wdcreg.h])
+ fi
+ ;;
+ *)
+ AC_MSG_WARN([Skipping check_ide_smart plugin.])
+ AC_MSG_WARN([check_ide_smart works only on Linux and NetBSD])
+esac
if test "$FOUNDINCLUDE" = "yes" ; then
EXTRAS="$EXTRAS check_ide_smart"
-else
- AC_MSG_WARN([Skipping check_ide_smart plugin.])
- AC_MSG_WARN([check_ide_smart is linux specific. It requires linux/hdreg.h and linux/types.h.])
fi
dnl Check for mysql libraries
diff --git a/plugins/check_ide_smart.c b/plugins/check_ide_smart.c
index b942461..e1a75ce 100644
--- a/plugins/check_ide_smart.c
+++ b/plugins/check_ide_smart.c
@@ -46,8 +46,29 @@ void print_usage (void);
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
+#ifdef linux
#include <linux/hdreg.h>
#include <linux/types.h>
+
+#define OPEN_MODE O_RDONLY
+#endif /* linux */
+#ifdef __NetBSD__
+#include <sys/device.h>
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#include <sys/videoio.h> /* for __u8 and friends */
+#include <sys/scsiio.h>
+#include <sys/ataio.h>
+#include <dev/ata/atareg.h>
+#include <dev/ic/wdcreg.h>
+
+#define SMART_ENABLE WDSM_ENABLE_OPS
+#define SMART_DISABLE WDSM_DISABLE_OPS
+#define SMART_IMMEDIATE_OFFLINE WDSM_EXEC_OFFL_IMM
+#define SMART_AUTO_OFFLINE 0xdb /* undefined in NetBSD headers */
+
+#define OPEN_MODE O_RDWR
+#endif /* __NetBSD__ */
#include <errno.h>
#define NR_ATTRIBUTES 30
@@ -223,7 +244,7 @@ main (int argc, char *argv[])
return STATE_OK;
}
- fd = open (device, O_RDONLY);
+ fd = open (device, OPEN_MODE);
if (fd < 0) {
printf (_("CRITICAL - Couldn't open device %s: %s\n"), device, strerror (errno));
@@ -284,6 +305,7 @@ get_offline_text (int status)
int
smart_read_values (int fd, values_t * values)
{
+#ifdef linux
int e;
__u8 args[4 + 512];
args[0] = WIN_SMART;
@@ -296,6 +318,35 @@ smart_read_values (int fd, values_t * values)
return e;
}
memcpy (values, args + 4, 512);
+#endif /* linux */
+#ifdef __NetBSD__
+ struct atareq req;
+ unsigned char inbuf[DEV_BSIZE];
+
+ memset(&req, 0, sizeof(req));
+ req.timeout = 1000;
+ memset(&inbuf, 0, sizeof(inbuf));
+
+ req.flags = ATACMD_READ;
+ req.features = WDSM_RD_DATA;
+ req.command = WDCC_SMART;
+ req.databuf = (char *)inbuf;
+ req.datalen = sizeof(inbuf);
+ req.cylinder = WDSMART_CYL;
+
+ if (ioctl(fd, ATAIOCCOMMAND, &req) == 0) {
+ if (req.retsts != ATACMD_OK)
+ errno = ENODEV;
+ }
+
+ if (errno != 0) {
+ int e = errno;
+ printf (_("CRITICAL - SMART_READ_VALUES: %s\n"), strerror (errno));
+ return e;
+ }
+
+ (void)memcpy(values, inbuf, 512);
+#endif /* __NetBSD__ */
return 0;
}
@@ -439,6 +490,7 @@ int
smart_cmd_simple (int fd, enum SmartCommand command, __u8 val0, char show_error)
{
int e = 0;
+#ifdef linux
__u8 args[4];
args[0] = WIN_SMART;
args[1] = val0;
@@ -450,6 +502,31 @@ smart_cmd_simple (int fd, enum SmartCommand command, __u8 val0, char show_error)
printf (_("CRITICAL - %s: %s\n"), smart_command[command].text, strerror (errno));
}
}
+#endif /* linux */
+#ifdef __NetBSD__
+ struct atareq req;
+
+ memset(&req, 0, sizeof(req));
+ req.timeout = 1000;
+ req.flags = ATACMD_READREG;
+ req.features = smart_command[command].value;
+ req.command = WDCC_SMART;
+ req.cylinder = WDSMART_CYL;
+ req.sec_count = val0;
+
+ if (ioctl(fd, ATAIOCCOMMAND, &req) == 0) {
+ if (req.retsts != ATACMD_OK)
+ errno = ENODEV;
+ if (req.cylinder != WDSMART_CYL)
+ errno = ENODEV;
+ }
+
+ if (errno != 0) {
+ e = errno;
+ printf (_("CRITICAL - %s: %s\n"), smart_command[command].text, strerror (errno));
+ return e;
+ }
+#endif /* __NetBSD__ */
return e;
}
@@ -458,6 +535,7 @@ smart_cmd_simple (int fd, enum SmartCommand command, __u8 val0, char show_error)
int
smart_read_thresholds (int fd, thresholds_t * thresholds)
{
+#ifdef linux
int e;
__u8 args[4 + 512];
args[0] = WIN_SMART;
@@ -470,6 +548,35 @@ smart_read_thresholds (int fd, thresholds_t * thresholds)
return e;
}
memcpy (thresholds, args + 4, 512);
+#endif /* linux */
+#ifdef __NetBSD__
+ struct atareq req;
+ unsigned char inbuf[DEV_BSIZE];
+
+ memset(&req, 0, sizeof(req));
+ req.timeout = 1000;
+ memset(&inbuf, 0, sizeof(inbuf));
+
+ req.flags = ATACMD_READ;
+ req.features = WDSM_RD_THRESHOLDS;
+ req.command = WDCC_SMART;
+ req.databuf = (char *)inbuf;
+ req.datalen = sizeof(inbuf);
+ req.cylinder = WDSMART_CYL;
+
+ if (ioctl(fd, ATAIOCCOMMAND, &req) == 0) {
+ if (req.retsts != ATACMD_OK)
+ errno = ENODEV;
+ }
+
+ if (errno != 0) {
+ int e = errno;
+ printf (_("CRITICAL - SMART_READ_THRESHOLDS: %s\n"), strerror (errno));
+ return e;
+ }
+
+ (void)memcpy(thresholds, inbuf, 512);
+#endif /* __NetBSD__ */
return 0;
}
More information about the Commits
mailing list