From 16c3e2499309af654bcf92a4cc516521122e8d66 Mon Sep 17 00:00:00 2001
From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>
Date: Wed, 12 Mar 2025 14:53:54 +0100
Subject: check_procs: general refactoring
---
configure.ac | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'configure.ac')
diff --git a/configure.ac b/configure.ac
index 204fc6e3..c66f9b2f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -796,7 +796,7 @@ elif ps axwo 'stat comm vsz rss user uid pid ppid etime args' 2>/dev/null | \
then
ac_cv_ps_varlist="[procstat,&procuid,&procpid,&procppid,&procvsz,&procrss,&procpcpu,procetime,procprog,&pos]"
ac_cv_ps_command="$PATH_TO_PS axwo 'stat uid pid ppid vsz rss pcpu etime comm args'"
- ac_cv_ps_format="%s %d %d %d %d %d %f %s %s %n"
+ ac_cv_ps_format="%s %u %d %d %d %d %f %s %s %n"
ac_cv_ps_cols=10
AC_MSG_RESULT([$ac_cv_ps_command])
--
cgit v1.2.3-74-g34f1
From 59e0a258f9c0f393bf29cced1f35743f74e7b10c Mon Sep 17 00:00:00 2001
From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>
Date: Tue, 18 Mar 2025 15:57:44 +0100
Subject: Migrate disk tests from lib, tool
---
.gitignore | 3 +-
configure.ac | 4 +-
lib/tests/Makefile.am | 6 +-
lib/tests/test_disk.c | 192 --------------------------------------
lib/tests/test_disk.t | 6 --
plugins/Makefile.am | 8 +-
plugins/check_disk.d/utils_disk.c | 4 +-
plugins/check_disk.d/utils_disk.h | 2 +-
plugins/common.h | 6 +-
plugins/tests/test_check_disk.c | 192 ++++++++++++++++++++++++++++++++++++++
plugins/tests/test_check_disk.t | 6 ++
11 files changed, 216 insertions(+), 213 deletions(-)
delete mode 100644 lib/tests/test_disk.c
delete mode 100755 lib/tests/test_disk.t
create mode 100644 plugins/tests/test_check_disk.c
create mode 100755 plugins/tests/test_check_disk.t
(limited to 'configure.ac')
diff --git a/.gitignore b/.gitignore
index 5245495e..8b14f429 100644
--- a/.gitignore
+++ b/.gitignore
@@ -114,7 +114,6 @@ NP-VERSION-FILE
/lib/tests/Makefile.in
/lib/tests/test_base64
/lib/tests/test_cmd
-/lib/tests/test_disk
/lib/tests/test_tcp
/lib/tests/test_utils
/lib/tests/utils_base.Po
@@ -223,7 +222,7 @@ plugins/check_disk.d/.dirstamp
/plugins/tests/Makefile
/plugins/tests/Makefile.in
/plugins/tests/test_utils
-/plugins/tests/test_disk
+/plugins/tests/test_check_disk
/plugins/tests/test_check_swap
/plugins/tests/.deps
/plugins/tests/.dirstamp
diff --git a/configure.ac b/configure.ac
index 204fc6e3..fdc9b699 100644
--- a/configure.ac
+++ b/configure.ac
@@ -181,10 +181,10 @@ fi
# Finally, define tests if we use libtap
if test "$enable_libtap" = "yes" ; then
- EXTRA_TEST="test_utils test_disk test_tcp test_cmd test_base64"
+ EXTRA_TEST="test_utils test_tcp test_cmd test_base64"
AC_SUBST(EXTRA_TEST)
- EXTRA_PLUGIN_TESTS="tests/test_check_swap"
+ EXTRA_PLUGIN_TESTS="tests/test_check_swap tests/test_check_disk"
AC_SUBST(EXTRA_PLUGIN_TESTS)
fi
diff --git a/lib/tests/Makefile.am b/lib/tests/Makefile.am
index 9be94f6d..7798a72e 100644
--- a/lib/tests/Makefile.am
+++ b/lib/tests/Makefile.am
@@ -8,9 +8,9 @@ check_PROGRAMS = @EXTRA_TEST@
AM_CPPFLAGS = -DNP_STATE_DIR_PREFIX=\"$(localstatedir)\" \
-I$(top_srcdir)/lib -I$(top_srcdir)/gl -I$(top_srcdir)/intl -I$(top_srcdir)/plugins
-EXTRA_PROGRAMS = test_utils test_disk test_tcp test_cmd test_base64 test_ini1 test_ini3 test_opts1 test_opts2 test_opts3 test_generic_output
+EXTRA_PROGRAMS = test_utils test_tcp test_cmd test_base64 test_ini1 test_ini3 test_opts1 test_opts2 test_opts3 test_generic_output
-np_test_scripts = test_base64.t test_cmd.t test_disk.t test_ini1.t test_ini3.t test_opts1.t test_opts2.t test_opts3.t test_tcp.t test_utils.t test_generic_output.t
+np_test_scripts = test_base64.t test_cmd.t test_ini1.t test_ini3.t test_opts1.t test_opts2.t test_opts3.t test_tcp.t test_utils.t test_generic_output.t
np_test_files = config-dos.ini config-opts.ini config-tiny.ini plugin.ini plugins.ini
EXTRA_DIST = $(np_test_scripts) $(np_test_files) var
@@ -29,7 +29,7 @@ AM_CFLAGS = -g -I$(top_srcdir)/lib -I$(top_srcdir)/gl $(tap_cflags)
AM_LDFLAGS = $(tap_ldflags) -ltap
LDADD = $(top_srcdir)/lib/libmonitoringplug.a $(top_srcdir)/gl/libgnu.a $(LIB_CRYPTO)
-SOURCES = test_utils.c test_disk.c test_tcp.c test_cmd.c test_base64.c test_ini1.c test_ini3.c test_opts1.c test_opts2.c test_opts3.c test_generic_output.c
+SOURCES = test_utils.c test_tcp.c test_cmd.c test_base64.c test_ini1.c test_ini3.c test_opts1.c test_opts2.c test_opts3.c test_generic_output.c
test: ${noinst_PROGRAMS}
perl -MTest::Harness -e '$$Test::Harness::switches=""; runtests(map {$$_ .= ".t"} @ARGV)' $(EXTRA_PROGRAMS)
diff --git a/lib/tests/test_disk.c b/lib/tests/test_disk.c
deleted file mode 100644
index c18db7a4..00000000
--- a/lib/tests/test_disk.c
+++ /dev/null
@@ -1,192 +0,0 @@
-/*****************************************************************************
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- *
- *
- *****************************************************************************/
-
-#include "common.h"
-#include "utils_disk.h"
-#include "tap.h"
-#include "regex.h"
-
-void np_test_mount_entry_regex(struct mount_entry *dummy_mount_list, char *regstr, int cflags, int expect, char *desc);
-
-int main(int argc, char **argv) {
- struct name_list *exclude_filesystem = NULL;
- struct name_list *exclude_fstype = NULL;
- struct name_list *dummy_mountlist = NULL;
- struct name_list *temp_name;
- struct parameter_list *paths = NULL;
- struct parameter_list *p, *prev = NULL, *last = NULL;
-
- struct mount_entry *dummy_mount_list;
- struct mount_entry *me;
- struct mount_entry **mtail = &dummy_mount_list;
- int cflags = REG_NOSUB | REG_EXTENDED;
- int found = 0, count = 0;
-
- plan_tests(33);
-
- ok(np_find_name(exclude_filesystem, "/var/log") == false, "/var/log not in list");
- np_add_name(&exclude_filesystem, "/var/log");
- ok(np_find_name(exclude_filesystem, "/var/log") == true, "is in list now");
- ok(np_find_name(exclude_filesystem, "/home") == false, "/home not in list");
- np_add_name(&exclude_filesystem, "/home");
- ok(np_find_name(exclude_filesystem, "/home") == true, "is in list now");
- ok(np_find_name(exclude_filesystem, "/var/log") == true, "/var/log still in list");
-
- ok(np_find_name(exclude_fstype, "iso9660") == false, "iso9660 not in list");
- np_add_name(&exclude_fstype, "iso9660");
- ok(np_find_name(exclude_fstype, "iso9660") == true, "is in list now");
-
- ok(np_find_name(exclude_filesystem, "iso9660") == false, "Make sure no clashing in variables");
-
- /*
- for (temp_name = exclude_filesystem; temp_name; temp_name = temp_name->next) {
- printf("Name: %s\n", temp_name->name);
- }
- */
-
- me = (struct mount_entry *)malloc(sizeof *me);
- me->me_devname = strdup("/dev/c0t0d0s0");
- me->me_mountdir = strdup("/");
- *mtail = me;
- mtail = &me->me_next;
-
- me = (struct mount_entry *)malloc(sizeof *me);
- me->me_devname = strdup("/dev/c1t0d1s0");
- me->me_mountdir = strdup("/var");
- *mtail = me;
- mtail = &me->me_next;
-
- me = (struct mount_entry *)malloc(sizeof *me);
- me->me_devname = strdup("/dev/c2t0d0s0");
- me->me_mountdir = strdup("/home");
- *mtail = me;
- mtail = &me->me_next;
-
- np_test_mount_entry_regex(dummy_mount_list, strdup("/"), cflags, 3, strdup("a"));
- np_test_mount_entry_regex(dummy_mount_list, strdup("/dev"), cflags, 3, strdup("regex on dev names:"));
- np_test_mount_entry_regex(dummy_mount_list, strdup("/foo"), cflags, 0, strdup("regex on non existent dev/path:"));
- np_test_mount_entry_regex(dummy_mount_list, strdup("/Foo"), cflags | REG_ICASE, 0, strdup("regi on non existent dev/path:"));
- np_test_mount_entry_regex(dummy_mount_list, strdup("/c.t0"), cflags, 3, strdup("partial devname regex match:"));
- np_test_mount_entry_regex(dummy_mount_list, strdup("c0t0"), cflags, 1, strdup("partial devname regex match:"));
- np_test_mount_entry_regex(dummy_mount_list, strdup("C0t0"), cflags | REG_ICASE, 1, strdup("partial devname regi match:"));
- np_test_mount_entry_regex(dummy_mount_list, strdup("home"), cflags, 1, strdup("partial pathname regex match:"));
- np_test_mount_entry_regex(dummy_mount_list, strdup("hOme"), cflags | REG_ICASE, 1, strdup("partial pathname regi match:"));
- np_test_mount_entry_regex(dummy_mount_list, strdup("(/home)|(/var)"), cflags, 2, strdup("grouped regex pathname match:"));
- np_test_mount_entry_regex(dummy_mount_list, strdup("(/homE)|(/Var)"), cflags | REG_ICASE, 2, strdup("grouped regi pathname match:"));
-
- np_add_parameter(&paths, "/home/groups");
- np_add_parameter(&paths, "/var");
- np_add_parameter(&paths, "/tmp");
- np_add_parameter(&paths, "/home/tonvoon");
- np_add_parameter(&paths, "/dev/c2t0d0s0");
-
- np_set_best_match(paths, dummy_mount_list, false);
- for (p = paths; p; p = p->name_next) {
- struct mount_entry *temp_me;
- temp_me = p->best_match;
- if (!strcmp(p->name, "/home/groups")) {
- ok(temp_me && !strcmp(temp_me->me_mountdir, "/home"), "/home/groups got right best match: /home");
- } else if (!strcmp(p->name, "/var")) {
- ok(temp_me && !strcmp(temp_me->me_mountdir, "/var"), "/var got right best match: /var");
- } else if (!strcmp(p->name, "/tmp")) {
- ok(temp_me && !strcmp(temp_me->me_mountdir, "/"), "/tmp got right best match: /");
- } else if (!strcmp(p->name, "/home/tonvoon")) {
- ok(temp_me && !strcmp(temp_me->me_mountdir, "/home"), "/home/tonvoon got right best match: /home");
- } else if (!strcmp(p->name, "/dev/c2t0d0s0")) {
- ok(temp_me && !strcmp(temp_me->me_devname, "/dev/c2t0d0s0"), "/dev/c2t0d0s0 got right best match: /dev/c2t0d0s0");
- }
- }
-
- paths = NULL; /* Bad boy - should free, but this is a test suite */
- np_add_parameter(&paths, "/home/groups");
- np_add_parameter(&paths, "/var");
- np_add_parameter(&paths, "/tmp");
- np_add_parameter(&paths, "/home/tonvoon");
- np_add_parameter(&paths, "/home");
-
- np_set_best_match(paths, dummy_mount_list, true);
- for (p = paths; p; p = p->name_next) {
- if (!strcmp(p->name, "/home/groups")) {
- ok(!p->best_match, "/home/groups correctly not found");
- } else if (!strcmp(p->name, "/var")) {
- ok(p->best_match, "/var found");
- } else if (!strcmp(p->name, "/tmp")) {
- ok(!p->best_match, "/tmp correctly not found");
- } else if (!strcmp(p->name, "/home/tonvoon")) {
- ok(!p->best_match, "/home/tonvoon not found");
- } else if (!strcmp(p->name, "/home")) {
- ok(p->best_match, "/home found");
- }
- }
-
- /* test deleting first element in paths */
- paths = np_del_parameter(paths, NULL);
- for (p = paths; p; p = p->name_next) {
- if (!strcmp(p->name, "/home/groups"))
- found = 1;
- }
- ok(found == 0, "first element successfully deleted");
- found = 0;
-
- p = paths;
- while (p) {
- if (!strcmp(p->name, "/tmp"))
- p = np_del_parameter(p, prev);
- else {
- prev = p;
- p = p->name_next;
- }
- }
-
- for (p = paths; p; p = p->name_next) {
- if (!strcmp(p->name, "/tmp"))
- found = 1;
- if (p->name_next)
- prev = p;
- else
- last = p;
- }
- ok(found == 0, "/tmp element successfully deleted");
-
- p = np_del_parameter(last, prev);
- for (p = paths; p; p = p->name_next) {
- if (!strcmp(p->name, "/home"))
- found = 1;
- last = p;
- count++;
- }
- ok(found == 0, "last (/home) element successfully deleted");
- ok(count == 2, "two elements remaining");
-
- return exit_status();
-}
-
-void np_test_mount_entry_regex(struct mount_entry *dummy_mount_list, char *regstr, int cflags, int expect, char *desc) {
- int matches = 0;
- regex_t re;
- struct mount_entry *me;
- if (regcomp(&re, regstr, cflags) == 0) {
- for (me = dummy_mount_list; me; me = me->me_next) {
- if (np_regex_match_mount_entry(me, &re))
- matches++;
- }
- ok(matches == expect, "%s '%s' matched %i/3 entries. ok: %i/3", desc, regstr, expect, matches);
-
- } else
- ok(false, "regex '%s' not compilable", regstr);
-}
diff --git a/lib/tests/test_disk.t b/lib/tests/test_disk.t
deleted file mode 100755
index da84dfdf..00000000
--- a/lib/tests/test_disk.t
+++ /dev/null
@@ -1,6 +0,0 @@
-#!/usr/bin/perl
-use Test::More;
-if (! -e "./test_disk") {
- plan skip_all => "./test_disk not compiled - please enable libtap library to test";
-}
-exec "./test_disk";
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index 30283cb4..04fb7ed2 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -40,11 +40,13 @@ EXTRA_PROGRAMS = check_mysql check_radius check_pgsql check_snmp check_hpjd \
check_nagios check_by_ssh check_dns check_nt check_ide_smart \
check_procs check_mysql_query check_apt check_dbi check_curl \
\
- tests/test_check_swap
+ tests/test_check_swap \
+ tests/test_check_disk
SUBDIRS = picohttpparser
-np_test_scripts = tests/test_check_swap.t
+np_test_scripts = tests/test_check_swap.t \
+ tests/test_check_disk.t
EXTRA_DIST = t \
tests \
@@ -167,6 +169,8 @@ endif
tests_test_check_swap_LDADD = $(BASEOBJS) $(tap_ldflags) -ltap
tests_test_check_swap_SOURCES = tests/test_check_swap.c check_swap.d/swap.c
+tests_test_check_disk_LDADD = $(BASEOBJS) $(tap_ldflags) check_disk.d/utils_disk.c -ltap
+tests_test_check_disk_SOURCES = tests/test_check_disk.c
##############################################################################
# secondary dependencies
diff --git a/plugins/check_disk.d/utils_disk.c b/plugins/check_disk.d/utils_disk.c
index 1d806715..369c85d5 100644
--- a/plugins/check_disk.d/utils_disk.c
+++ b/plugins/check_disk.d/utils_disk.c
@@ -26,9 +26,9 @@
*
*****************************************************************************/
-#include "common.h"
+#include "../common.h"
#include "utils_disk.h"
-#include "gl/fsusage.h"
+#include "../../gl/fsusage.h"
#include
void np_add_name(struct name_list **list, const char *name) {
diff --git a/plugins/check_disk.d/utils_disk.h b/plugins/check_disk.d/utils_disk.h
index 1c68fed9..0c69f987 100644
--- a/plugins/check_disk.d/utils_disk.h
+++ b/plugins/check_disk.d/utils_disk.h
@@ -2,7 +2,7 @@
#include "../../config.h"
#include "../../gl/mountlist.h"
-#include "utils_base.h"
+#include "../../lib/utils_base.h"
#include "regex.h"
#include
diff --git a/plugins/common.h b/plugins/common.h
index 603bae55..35d1e549 100644
--- a/plugins/common.h
+++ b/plugins/common.h
@@ -31,7 +31,7 @@
#ifndef _COMMON_H_
#define _COMMON_H_
-#include "config.h"
+#include "../config.h"
#include "../lib/monitoringplug.h"
#ifdef HAVE_FEATURES_H
@@ -110,7 +110,7 @@
/* GNU Libraries */
#include
-#include "dirname.h"
+#include "../gl/dirname.h"
#include
@@ -190,7 +190,7 @@ enum {
* Internationalization
*
*/
-#include "gettext.h"
+#include "../gl/gettext.h"
#define _(String) gettext (String)
#if ! ENABLE_NLS
# undef textdomain
diff --git a/plugins/tests/test_check_disk.c b/plugins/tests/test_check_disk.c
new file mode 100644
index 00000000..92d0d270
--- /dev/null
+++ b/plugins/tests/test_check_disk.c
@@ -0,0 +1,192 @@
+/*****************************************************************************
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ *
+ *****************************************************************************/
+
+#include "common.h"
+#include "../check_disk.d/utils_disk.h"
+#include "../../tap/tap.h"
+#include "regex.h"
+
+void np_test_mount_entry_regex(struct mount_entry *dummy_mount_list, char *regstr, int cflags, int expect, char *desc);
+
+int main(int argc, char **argv) {
+ struct name_list *exclude_filesystem = NULL;
+ struct name_list *exclude_fstype = NULL;
+ struct name_list *dummy_mountlist = NULL;
+ struct name_list *temp_name;
+ struct parameter_list *paths = NULL;
+ struct parameter_list *p, *prev = NULL, *last = NULL;
+
+ struct mount_entry *dummy_mount_list;
+ struct mount_entry *me;
+ struct mount_entry **mtail = &dummy_mount_list;
+ int cflags = REG_NOSUB | REG_EXTENDED;
+ int found = 0, count = 0;
+
+ plan_tests(33);
+
+ ok(np_find_name(exclude_filesystem, "/var/log") == false, "/var/log not in list");
+ np_add_name(&exclude_filesystem, "/var/log");
+ ok(np_find_name(exclude_filesystem, "/var/log") == true, "is in list now");
+ ok(np_find_name(exclude_filesystem, "/home") == false, "/home not in list");
+ np_add_name(&exclude_filesystem, "/home");
+ ok(np_find_name(exclude_filesystem, "/home") == true, "is in list now");
+ ok(np_find_name(exclude_filesystem, "/var/log") == true, "/var/log still in list");
+
+ ok(np_find_name(exclude_fstype, "iso9660") == false, "iso9660 not in list");
+ np_add_name(&exclude_fstype, "iso9660");
+ ok(np_find_name(exclude_fstype, "iso9660") == true, "is in list now");
+
+ ok(np_find_name(exclude_filesystem, "iso9660") == false, "Make sure no clashing in variables");
+
+ /*
+ for (temp_name = exclude_filesystem; temp_name; temp_name = temp_name->next) {
+ printf("Name: %s\n", temp_name->name);
+ }
+ */
+
+ me = (struct mount_entry *)malloc(sizeof *me);
+ me->me_devname = strdup("/dev/c0t0d0s0");
+ me->me_mountdir = strdup("/");
+ *mtail = me;
+ mtail = &me->me_next;
+
+ me = (struct mount_entry *)malloc(sizeof *me);
+ me->me_devname = strdup("/dev/c1t0d1s0");
+ me->me_mountdir = strdup("/var");
+ *mtail = me;
+ mtail = &me->me_next;
+
+ me = (struct mount_entry *)malloc(sizeof *me);
+ me->me_devname = strdup("/dev/c2t0d0s0");
+ me->me_mountdir = strdup("/home");
+ *mtail = me;
+ mtail = &me->me_next;
+
+ np_test_mount_entry_regex(dummy_mount_list, strdup("/"), cflags, 3, strdup("a"));
+ np_test_mount_entry_regex(dummy_mount_list, strdup("/dev"), cflags, 3, strdup("regex on dev names:"));
+ np_test_mount_entry_regex(dummy_mount_list, strdup("/foo"), cflags, 0, strdup("regex on non existent dev/path:"));
+ np_test_mount_entry_regex(dummy_mount_list, strdup("/Foo"), cflags | REG_ICASE, 0, strdup("regi on non existent dev/path:"));
+ np_test_mount_entry_regex(dummy_mount_list, strdup("/c.t0"), cflags, 3, strdup("partial devname regex match:"));
+ np_test_mount_entry_regex(dummy_mount_list, strdup("c0t0"), cflags, 1, strdup("partial devname regex match:"));
+ np_test_mount_entry_regex(dummy_mount_list, strdup("C0t0"), cflags | REG_ICASE, 1, strdup("partial devname regi match:"));
+ np_test_mount_entry_regex(dummy_mount_list, strdup("home"), cflags, 1, strdup("partial pathname regex match:"));
+ np_test_mount_entry_regex(dummy_mount_list, strdup("hOme"), cflags | REG_ICASE, 1, strdup("partial pathname regi match:"));
+ np_test_mount_entry_regex(dummy_mount_list, strdup("(/home)|(/var)"), cflags, 2, strdup("grouped regex pathname match:"));
+ np_test_mount_entry_regex(dummy_mount_list, strdup("(/homE)|(/Var)"), cflags | REG_ICASE, 2, strdup("grouped regi pathname match:"));
+
+ np_add_parameter(&paths, "/home/groups");
+ np_add_parameter(&paths, "/var");
+ np_add_parameter(&paths, "/tmp");
+ np_add_parameter(&paths, "/home/tonvoon");
+ np_add_parameter(&paths, "/dev/c2t0d0s0");
+
+ np_set_best_match(paths, dummy_mount_list, false);
+ for (p = paths; p; p = p->name_next) {
+ struct mount_entry *temp_me;
+ temp_me = p->best_match;
+ if (!strcmp(p->name, "/home/groups")) {
+ ok(temp_me && !strcmp(temp_me->me_mountdir, "/home"), "/home/groups got right best match: /home");
+ } else if (!strcmp(p->name, "/var")) {
+ ok(temp_me && !strcmp(temp_me->me_mountdir, "/var"), "/var got right best match: /var");
+ } else if (!strcmp(p->name, "/tmp")) {
+ ok(temp_me && !strcmp(temp_me->me_mountdir, "/"), "/tmp got right best match: /");
+ } else if (!strcmp(p->name, "/home/tonvoon")) {
+ ok(temp_me && !strcmp(temp_me->me_mountdir, "/home"), "/home/tonvoon got right best match: /home");
+ } else if (!strcmp(p->name, "/dev/c2t0d0s0")) {
+ ok(temp_me && !strcmp(temp_me->me_devname, "/dev/c2t0d0s0"), "/dev/c2t0d0s0 got right best match: /dev/c2t0d0s0");
+ }
+ }
+
+ paths = NULL; /* Bad boy - should free, but this is a test suite */
+ np_add_parameter(&paths, "/home/groups");
+ np_add_parameter(&paths, "/var");
+ np_add_parameter(&paths, "/tmp");
+ np_add_parameter(&paths, "/home/tonvoon");
+ np_add_parameter(&paths, "/home");
+
+ np_set_best_match(paths, dummy_mount_list, true);
+ for (p = paths; p; p = p->name_next) {
+ if (!strcmp(p->name, "/home/groups")) {
+ ok(!p->best_match, "/home/groups correctly not found");
+ } else if (!strcmp(p->name, "/var")) {
+ ok(p->best_match, "/var found");
+ } else if (!strcmp(p->name, "/tmp")) {
+ ok(!p->best_match, "/tmp correctly not found");
+ } else if (!strcmp(p->name, "/home/tonvoon")) {
+ ok(!p->best_match, "/home/tonvoon not found");
+ } else if (!strcmp(p->name, "/home")) {
+ ok(p->best_match, "/home found");
+ }
+ }
+
+ /* test deleting first element in paths */
+ paths = np_del_parameter(paths, NULL);
+ for (p = paths; p; p = p->name_next) {
+ if (!strcmp(p->name, "/home/groups"))
+ found = 1;
+ }
+ ok(found == 0, "first element successfully deleted");
+ found = 0;
+
+ p = paths;
+ while (p) {
+ if (!strcmp(p->name, "/tmp"))
+ p = np_del_parameter(p, prev);
+ else {
+ prev = p;
+ p = p->name_next;
+ }
+ }
+
+ for (p = paths; p; p = p->name_next) {
+ if (!strcmp(p->name, "/tmp"))
+ found = 1;
+ if (p->name_next)
+ prev = p;
+ else
+ last = p;
+ }
+ ok(found == 0, "/tmp element successfully deleted");
+
+ p = np_del_parameter(last, prev);
+ for (p = paths; p; p = p->name_next) {
+ if (!strcmp(p->name, "/home"))
+ found = 1;
+ last = p;
+ count++;
+ }
+ ok(found == 0, "last (/home) element successfully deleted");
+ ok(count == 2, "two elements remaining");
+
+ return exit_status();
+}
+
+void np_test_mount_entry_regex(struct mount_entry *dummy_mount_list, char *regstr, int cflags, int expect, char *desc) {
+ int matches = 0;
+ regex_t re;
+ struct mount_entry *me;
+ if (regcomp(&re, regstr, cflags) == 0) {
+ for (me = dummy_mount_list; me; me = me->me_next) {
+ if (np_regex_match_mount_entry(me, &re))
+ matches++;
+ }
+ ok(matches == expect, "%s '%s' matched %i/3 entries. ok: %i/3", desc, regstr, expect, matches);
+
+ } else
+ ok(false, "regex '%s' not compilable", regstr);
+}
diff --git a/plugins/tests/test_check_disk.t b/plugins/tests/test_check_disk.t
new file mode 100755
index 00000000..56354650
--- /dev/null
+++ b/plugins/tests/test_check_disk.t
@@ -0,0 +1,6 @@
+#!/usr/bin/perl
+use Test::More;
+if (! -e "./test_check_disk") {
+ plan skip_all => "./test_check_disk not compiled - please enable libtap library to test";
+}
+exec "./test_check_disk";
--
cgit v1.2.3-74-g34f1
From 1fb9300a2f10d5c649df484e1b8d7550f9a5f846 Mon Sep 17 00:00:00 2001
From: William
Date: Wed, 7 May 2025 13:17:47 +1000
Subject: Remove un-needed flags
---
configure.ac | 7 -------
plugins/check_fping.c | 42 ------------------------------------------
2 files changed, 49 deletions(-)
(limited to 'configure.ac')
diff --git a/configure.ac b/configure.ac
index fdc9b699..bd3de196 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1524,17 +1524,10 @@ AC_PATH_PROG(PATH_TO_FPING6,fping6)
AC_ARG_WITH(fping_command,
ACX_HELP_STRING([--with-fping-command=PATH],
[Path to fping command]), PATH_TO_FPING=$withval)
-AC_ARG_WITH(fping6_command,
- ACX_HELP_STRING([--with-fping6-command=PATH],
- [Path to fping6 command]), PATH_TO_FPING6=$withval)
-
if test -n "$PATH_TO_FPING"
then
AC_DEFINE_UNQUOTED(PATH_TO_FPING,"$PATH_TO_FPING",[path to fping])
EXTRAS="$EXTRAS check_fping\$(EXEEXT)"
- if test x"$with_ipv6" != xno && test -n "$PATH_TO_FPING6"; then
- AC_DEFINE_UNQUOTED(PATH_TO_FPING6,"$PATH_TO_FPING6",[path to fping6])
- fi
else
AC_MSG_WARN([Get fping from http://www.fping.com in order to make check_fping plugin])
fi
diff --git a/plugins/check_fping.c b/plugins/check_fping.c
index 9dadcec7..e05056b2 100644
--- a/plugins/check_fping.c
+++ b/plugins/check_fping.c
@@ -82,28 +82,8 @@ int main(int argc, char **argv) {
char *fping_prog = NULL;
/* First determine if the target is dualstack or ipv6 only. */
-#ifdef USE_IPV6
bool server_is_inet6_addr = is_inet6_addr(server);
-#else
- bool server_is_inet6_addr = false;
-#endif
- /* PATH_TO_FPING6 implies USE_IPV6 */
-#ifdef PATH_TO_FPING6
- /*
- * If the user requested -6 OR the user made no assertion and the address is v6 or dualstack
- * -> we use ipv6
- * If the user requested -4 OR the user made no assertion and the address is v4 ONLY
- * -> we use ipv4
- */
- if (address_family == AF_INET6 || (address_family == AF_UNSPEC && server_is_inet6_addr)) {
- fping_prog = strdup(PATH_TO_FPING6);
- } else {
- xasprintf(&option_string, "%s-4 ", option_string);
- fping_prog = strdup(PATH_TO_FPING);
- }
-#else
-#ifdef USE_IPV6
/*
* If the user requested -6 OR the user made no assertion and the address is v6 or dualstack
* -> we use ipv6
@@ -115,25 +95,7 @@ int main(int argc, char **argv) {
} else {
xasprintf(&option_string, "%s-4 ", option_string);
}
-#else
- /*
- * If the user requested -6
- * -> warn that v6 is not available
- * -> we use ipv4
- */
- if (address_family == AF_INET6) {
- usage4(_("IPv6 support not available"));
- }
- /*
- * Note here we still have to call with -4, else in the case of a dual stacked target
- * we could potentially silently use ipv6 despite having just warned that it is not available
- */
- xasprintf(&option_string, "%s-4 ", option_string);
- /* end USE_IPV6 */
-#endif
fping_prog = strdup(PATH_TO_FPING);
- /* end PATH_TO_FPING6 */
-#endif
/* compose the command */
if (config.target_timeout) {
@@ -385,11 +347,7 @@ check_fping_config_wrapper process_arguments(int argc, char **argv) {
address_family = AF_INET;
break;
case '6': /* IPv6 only */
-#ifdef USE_IPV6
address_family = AF_INET6;
-#else
- usage(_("IPv6 support not available\n"));
-#endif
break;
case 'c':
get_threshold(optarg, rv);
--
cgit v1.2.3-74-g34f1
From 1187374e745af310a2e346ab1df5250d07c65a69 Mon Sep 17 00:00:00 2001
From: Lorenz Kästle
Date: Wed, 11 Jun 2025 13:11:04 +0200
Subject: Remove unused FPING6 variable
---
configure.ac | 1 -
1 file changed, 1 deletion(-)
(limited to 'configure.ac')
diff --git a/configure.ac b/configure.ac
index bd3de196..ae704361 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1519,7 +1519,6 @@ then
fi
AC_PATH_PROG(PATH_TO_FPING,fping)
-AC_PATH_PROG(PATH_TO_FPING6,fping6)
AC_ARG_WITH(fping_command,
ACX_HELP_STRING([--with-fping-command=PATH],
--
cgit v1.2.3-74-g34f1
From 88683af1da8baae6b252795ab5d85a48e9cd3e63 Mon Sep 17 00:00:00 2001
From: Lorenz Kästle
Date: Wed, 11 Jun 2025 17:09:27 +0200
Subject: Implement autoconf logic for fping version detection
---
configure.ac | 38 ++++++++++++++++++++++++++++++++++++--
1 file changed, 36 insertions(+), 2 deletions(-)
(limited to 'configure.ac')
diff --git a/configure.ac b/configure.ac
index ae704361..bec50cb4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1523,10 +1523,44 @@ AC_PATH_PROG(PATH_TO_FPING,fping)
AC_ARG_WITH(fping_command,
ACX_HELP_STRING([--with-fping-command=PATH],
[Path to fping command]), PATH_TO_FPING=$withval)
-if test -n "$PATH_TO_FPING"
-then
+if test -n "$PATH_TO_FPING"; then
AC_DEFINE_UNQUOTED(PATH_TO_FPING,"$PATH_TO_FPING",[path to fping])
EXTRAS="$EXTRAS check_fping\$(EXEEXT)"
+
+ if test -z "$($PATH_TO_FPING --version)" ; then
+ AC_MSG_NOTICE([failed to get version of fping])
+ else
+ FPING_MAJOR_VERSION="$($PATH_TO_FPING --version | sed 's/.*fping: Version //' | sed 's/\..*//')"
+ FPING_MINOR_VERSION="$($PATH_TO_FPING --version | sed 's/.*fping: Version //' | sed 's/.*\.//')"
+
+ if test $FPING_MAJOR_VERSION -eq 5 ; then
+ if test $FPING_MINOR_VERSION -ge 3 ; then
+ AC_DEFINE(FPING_VERSION_5_3_OR_HIGHER, "true", [fping is of version 5.3 or higher])
+ AC_MSG_NOTICE([fping is of version 5.3 or higher])
+ AC_DEFINE(FPING_VERSION_5_2_OR_HIGHER, "true", [fping is of version 5.2 or higher])
+ AC_MSG_NOTICE([fping is of version 5.2 or higher])
+ elif test $FPING_MINOR_VERSION -ge 2 ; then
+ AC_DEFINE(FPING_VERSION_5_2_OR_HIGHER, "true", [fping is of version 5.2 or higher])
+ AC_MSG_NOTICE([fping is of version 5.2 or higher])
+ else
+ AC_MSG_NOTICE([fping is of a version lower then 5.2])
+ fi
+
+ elif $FPING_MAJOR_VERSION > 5 ; then
+ AC_DEFINE(FPING_VERSION_5_2_OR_HIGHER, "true", [fping is of version 5.2 or higher])
+ AC_MSG_NOTICE([fping is of version 5.2 or higher])
+ AC_DEFINE(FPING_VERSION_5_3_OR_HIGHER, "true", [fping is of version 5.2 or higher])
+ AC_MSG_NOTICE([fping is of version 5.3 or higher])
+ fi
+
+ if test "`fping --version | sed 's/.*fping: Version //'`" = "5.2" ; then
+ AC_DEFINE(FPING_VERSION, "5.2", [the version of fping available])
+ AC_MSG_NOTICE([fping version: 5.2])
+ elif test "`fping --version | sed 's/.*fping: Version //'`" = "5.3"; then
+ AC_DEFINE(FPING_VERSION, "5.3", [the version of fping available])
+ AC_MSG_NOTICE([fping version: 5.3])
+ fi
+ fi
else
AC_MSG_WARN([Get fping from http://www.fping.com in order to make check_fping plugin])
fi
--
cgit v1.2.3-74-g34f1
From b65f94fe0ea13dcbdc7ff5f3d1241eab2685cddc Mon Sep 17 00:00:00 2001
From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>
Date: Thu, 28 Aug 2025 11:24:16 +0200
Subject: Remove testing for SNMPGETNEXT from autotools stuff
---
configure.ac | 11 -----------
1 file changed, 11 deletions(-)
(limited to 'configure.ac')
diff --git a/configure.ac b/configure.ac
index ce140218..5f00b478 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1470,17 +1470,6 @@ AC_ARG_WITH(snmpgetnext_command,
AS_IF([test -n "$PATH_TO_SNMPGET"], [
AC_DEFINE_UNQUOTED(PATH_TO_SNMPGET,"$PATH_TO_SNMPGET",[path to snmpget binary])
EXTRAS="$EXTRAS check_hpjd"
-
- dnl PATH_TO_SNMPGETNEXT is used unconditionally in check_snmp:
- dnl
- dnl https://github.com/nagios-plugins/nagios-plugins/issues/788
- dnl
- AS_IF([test -n "$PATH_TO_SNMPGETNEXT"], [
- AC_DEFINE_UNQUOTED(PATH_TO_SNMPGETNEXT,"$PATH_TO_SNMPGETNEXT",[path to snmpgetnext binary])
- EXTRAS="$EXTRAS check_snmp\$(EXEEXT)"
- ], [
- AC_MSG_WARN([Get snmpgetnext from https://net-snmp.sourceforge.io/ to build the check_snmp plugin])
- ])
], [
AC_MSG_WARN([Get snmpget from https://net-snmp.sourceforge.io/ to build the check_hpjd and check_snmp plugins])
])
--
cgit v1.2.3-74-g34f1
From ebc2415330df963358b1e49beab0279a70ff4c84 Mon Sep 17 00:00:00 2001
From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>
Date: Thu, 28 Aug 2025 12:12:27 +0200
Subject: check_snmp: fix DES availability detection(?)
---
configure.ac | 10 ++++++++++
plugins/check_snmp.c | 6 +++---
2 files changed, 13 insertions(+), 3 deletions(-)
(limited to 'configure.ac')
diff --git a/configure.ac b/configure.ac
index 5f00b478..705183a2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1482,6 +1482,16 @@ else
AC_MSG_WARN([Tried $PERL - install Net::SNMP perl module if you want to use the perl snmp plugins])
fi
+dnl Check whether DES encryption is available (might not on RHEL)
+AC_COMPILE_IFELSE(
+ [AC_LANG_PROGRAM(
+ [[#include
+ #include ]], [[oid *foo = usmDESPrivProtocol;]]
+ )],
+ [AC_DEFINE(HAVE_USM_DES_PRIV_PROTOCOL,1,Define whether we have DES Privacy Protocol)],
+ []
+)
+
AC_PATH_PROG(PATH_TO_QUAKESTAT,quakestat)
AC_PATH_PROG(PATH_TO_QSTAT,qstat)
AC_ARG_WITH(qstat_command,
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c
index d0f01721..6c672793 100644
--- a/plugins/check_snmp.c
+++ b/plugins/check_snmp.c
@@ -69,7 +69,7 @@ const char DEFAULT_COMMUNITY[] = "public";
const char DEFAULT_MIBLIST[] = "ALL";
#define DEFAULT_AUTH_PROTOCOL "MD5"
-#ifdef usmDESPrivProtocol
+#ifdef HAVE_USM_DES_PRIV_PROTOCOL
# define DEFAULT_PRIV_PROTOCOL "DES"
#else
# define DEFAULT_PRIV_PROTOCOL "AES"
@@ -623,7 +623,7 @@ static process_arguments_wrapper process_arguments(int argc, char **argv) {
break;
case 'x': /* priv protocol */
if (strcasecmp("DES", optarg) == 0) {
-#ifdef usmDESPrivProtocol
+#ifdef HAVE_USM_DES_PRIV_PROTOCOL
config.snmp_session.securityAuthProto = usmDESPrivProtocol;
config.snmp_session.securityAuthProtoLen = OID_LENGTH(usmDESPrivProtocol);
#else
@@ -997,7 +997,7 @@ void print_help(void) {
printf(" %s\n", _("SNMPv3 securityLevel"));
printf(" %s\n", "-a, --authproto=[MD5|SHA]");
printf(" %s\n", _("SNMPv3 auth proto"));
-#ifdef usmDESPrivProtocol
+#ifdef HAVE_USM_DES_PRIV_PROTOCOL
printf(" %s\n", "-x, --privproto=[DES|AES]");
printf(" %s\n", _("SNMPv3 priv proto (default DES)"));
#else
--
cgit v1.2.3-74-g34f1
From 30a9908d8d02fe7ffc813adfe80e24663dcee654 Mon Sep 17 00:00:00 2001
From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>
Date: Wed, 3 Dec 2025 22:39:19 +0100
Subject: Remove check_nt (#2195)
check_nt was used to connect NSclient++ on windows, both the method
and the target are pretty much dead.
Therefor check_nt gets removed.
---
.github/monitoring-plugins.spec | 13 -
.gitignore | 1 -
REQUIREMENTS | 8 +-
configure.ac | 5 -
plugins/Makefile.am | 4 +-
plugins/check_nt.c | 789 ----------------------------------------
plugins/check_nt.d/config.h | 53 ---
plugins/tests/check_nt.t | 80 ----
8 files changed, 3 insertions(+), 950 deletions(-)
delete mode 100644 plugins/check_nt.c
delete mode 100644 plugins/check_nt.d/config.h
delete mode 100755 plugins/tests/check_nt.t
(limited to 'configure.ac')
diff --git a/.github/monitoring-plugins.spec b/.github/monitoring-plugins.spec
index ce22606b..5878a862 100644
--- a/.github/monitoring-plugins.spec
+++ b/.github/monitoring-plugins.spec
@@ -652,19 +652,6 @@ Provides check_nagios of the Monitoring Plugins.
-# check_nt
-%package nt
-Summary: Monitoring Plugins - check_nt
-Requires: %{name} = %{version}-%{release}
-
-%description nt
-Provides check_nt of the Monitoring Plugins.
-
-%files nt
-%{plugindir}/check_nt
-
-
-
# check_ntp
%package ntp
Summary: Monitoring Plugins - check_ntp
diff --git a/.gitignore b/.gitignore
index 00e19d52..a91edd7c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -174,7 +174,6 @@ plugins/check_disk.d/.dirstamp
/plugins/check_netsaint
/plugins/check_nntp
/plugins/check_nntps
-/plugins/check_nt
/plugins/check_ntp
/plugins/check_ntp_peer
/plugins/check_ntp_time
diff --git a/REQUIREMENTS b/REQUIREMENTS
index 551fdb1a..8f1befbd 100644
--- a/REQUIREMENTS
+++ b/REQUIREMENTS
@@ -26,7 +26,7 @@ check_curl:
other SSL implementations are currently not supported
- uriparser 0.7.5 or later
https://uriparser.github.io/
-
+
check_fping:
- Requires the fping utility distributed with SATAN. Either
download and install SATAN or grab the fping program from
@@ -87,16 +87,12 @@ check_ifstatus/check_ifoperstatus
- Requires Net::SNMP perl module
http://www.perl.com/CPAN/modules/by-authors/id/D/DT/DTOWN/
-check_nt:
- - Requires NSClient to run on the NT server to monitor
- http://nsclient.ready2run.nl/
-
check_ups:
- Requires Network UPS Tools (>= 1.4) to run on the server to monitor
http://www.networkupstools.org/
check_ide_smart:
- - Uses the Linux specific SMART interface [http://smartlinux.sourceforge.net/smart/index.php].
+ - Uses the Linux specific SMART interface [http://smartlinux.sourceforge.net/smart/index.php].
OS Specific Issues
------------------
diff --git a/configure.ac b/configure.ac
index 705183a2..2bf94014 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1832,11 +1832,6 @@ if test -n "$PATH_TO_APTGET" ; then
fi
-if test -f $srcdir/plugins/check_nt.c ; then
- EXTRAS="$EXTRAS check_nt\$(EXEEXT)"
-fi
-
-
dnl used in check_dhcp
AC_CHECK_HEADERS(sys/sockio.h)
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index 1a9399f0..877c0947 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -44,7 +44,7 @@ check_tcp_programs = check_ftp check_imap check_nntp check_pop \
EXTRA_PROGRAMS = check_mysql check_radius check_pgsql check_hpjd \
check_swap check_fping check_ldap check_game check_dig \
- check_nagios check_by_ssh check_dns check_nt check_ide_smart \
+ check_nagios check_by_ssh check_dns check_ide_smart \
check_procs check_mysql_query check_apt check_dbi check_curl \
\
tests/test_check_swap \
@@ -76,7 +76,6 @@ EXTRA_DIST = t \
check_tcp.d \
check_real.d \
check_ssh.d \
- check_nt.d \
check_dns.d \
check_mrtgtraf.d \
check_mysql_query.d \
@@ -157,7 +156,6 @@ check_mysql_query_CFLAGS = $(AM_CFLAGS) $(MYSQLCFLAGS)
check_mysql_query_CPPFLAGS = $(AM_CPPFLAGS) $(MYSQLINCLUDE)
check_mysql_query_LDADD = $(NETLIBS) $(MYSQLLIBS)
check_nagios_LDADD = $(BASEOBJS)
-check_nt_LDADD = $(NETLIBS)
check_ntp_LDADD = $(NETLIBS) $(MATHLIBS)
check_ntp_peer_LDADD = $(NETLIBS) $(MATHLIBS)
check_pgsql_LDADD = $(NETLIBS) $(PGLIBS)
diff --git a/plugins/check_nt.c b/plugins/check_nt.c
deleted file mode 100644
index 35ca92cd..00000000
--- a/plugins/check_nt.c
+++ /dev/null
@@ -1,789 +0,0 @@
-/*****************************************************************************
- *
- * Monitoring check_nt plugin
- *
- * License: GPL
- * Copyright (c) 2000-2002 Yves Rubin (rubiyz@yahoo.com)
- * Copyright (c) 2003-2024 Monitoring Plugins Development Team
- *
- * Description:
- *
- * This file contains the check_nt plugin
- *
- * This plugin collects data from the NSClient service running on a
- * Windows NT/2000/XP/2003 server.
- * This plugin requires NSClient software to run on NT
- * (https://nsclient.org/)
- *
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- *
- *
- *****************************************************************************/
-
-const char *progname = "check_nt";
-const char *copyright = "2000-2024";
-const char *email = "devel@monitoring-plugins.org";
-
-#include "common.h"
-#include "netutils.h"
-#include "utils.h"
-#include "check_nt.d/config.h"
-
-enum {
- MAX_VALUE_LIST = 30,
-};
-
-static char recv_buffer[MAX_INPUT_BUFFER];
-
-static void fetch_data(const char *address, int port, const char *sendb);
-
-typedef struct {
- int errorcode;
- check_nt_config config;
-} check_nt_config_wrapper;
-static check_nt_config_wrapper process_arguments(int /*argc*/, char ** /*argv*/);
-
-static void preparelist(char *string);
-static bool strtoularray(unsigned long *array, char *string, const char *delim);
-static void print_help(void);
-void print_usage(void);
-
-int main(int argc, char **argv) {
- setlocale(LC_ALL, "");
- bindtextdomain(PACKAGE, LOCALEDIR);
- textdomain(PACKAGE);
-
- /* Parse extra opts if any */
- argv = np_extra_opts(&argc, argv, progname);
-
- check_nt_config_wrapper tmp_config = process_arguments(argc, argv);
- if (tmp_config.errorcode == ERROR) {
- usage4(_("Could not parse arguments"));
- }
-
- const check_nt_config config = tmp_config.config;
-
- /* initialize alarm signal handling */
- signal(SIGALRM, socket_timeout_alarm_handler);
-
- /* set socket timeout */
- alarm(socket_timeout);
-
- int return_code = STATE_UNKNOWN;
- char *send_buffer = NULL;
- char *output_message = NULL;
- char *perfdata = NULL;
- char *temp_string = NULL;
- char *temp_string_perf = NULL;
- char *description = NULL;
- char *counter_unit = NULL;
- char *errcvt = NULL;
- unsigned long lvalue_list[MAX_VALUE_LIST];
- switch (config.vars_to_check) {
- case CHECK_CLIENTVERSION:
- xasprintf(&send_buffer, "%s&1", config.req_password);
- fetch_data(config.server_address, config.server_port, send_buffer);
- if (config.value_list != NULL && strcmp(recv_buffer, config.value_list) != 0) {
- xasprintf(&output_message, _("Wrong client version - running: %s, required: %s"),
- recv_buffer, config.value_list);
- return_code = STATE_WARNING;
- } else {
- xasprintf(&output_message, "%s", recv_buffer);
- return_code = STATE_OK;
- }
- break;
- case CHECK_CPULOAD:
- if (config.value_list == NULL) {
- output_message = strdup(_("missing -l parameters"));
- } else if (!strtoularray(lvalue_list, config.value_list, ",")) {
- output_message = strdup(_("wrong -l parameter."));
- } else {
- /* -l parameters is present with only integers */
- return_code = STATE_OK;
- temp_string = strdup(_("CPU Load"));
- temp_string_perf = strdup(" ");
-
- /* loop until one of the parameters is wrong or not present */
- int offset = 0;
- while (lvalue_list[0 + offset] > (unsigned long)0 &&
- lvalue_list[0 + offset] <= (unsigned long)17280 &&
- lvalue_list[1 + offset] > (unsigned long)0 &&
- lvalue_list[1 + offset] <= (unsigned long)100 &&
- lvalue_list[2 + offset] > (unsigned long)0 &&
- lvalue_list[2 + offset] <= (unsigned long)100) {
-
- /* Send request and retrieve data */
- xasprintf(&send_buffer, "%s&2&%lu", config.req_password, lvalue_list[0 + offset]);
- fetch_data(config.server_address, config.server_port, send_buffer);
-
- unsigned long utilization = strtoul(recv_buffer, NULL, 10);
-
- /* Check if any of the request is in a warning or critical state */
- if (utilization >= lvalue_list[2 + offset]) {
- return_code = STATE_CRITICAL;
- } else if (utilization >= lvalue_list[1 + offset] && return_code < STATE_WARNING) {
- return_code = STATE_WARNING;
- }
-
- xasprintf(&output_message, _(" %lu%% (%lu min average)"), utilization,
- lvalue_list[0 + offset]);
- xasprintf(&temp_string, "%s%s", temp_string, output_message);
- xasprintf(&perfdata, _(" '%lu min avg Load'=%lu%%;%lu;%lu;0;100"),
- lvalue_list[0 + offset], utilization, lvalue_list[1 + offset],
- lvalue_list[2 + offset]);
- xasprintf(&temp_string_perf, "%s%s", temp_string_perf, perfdata);
- offset += 3; /* move across the array */
- }
-
- if (strlen(temp_string) > 10) { /* we had at least one loop */
- output_message = strdup(temp_string);
- perfdata = temp_string_perf;
- } else {
- output_message = strdup(_("not enough values for -l parameters"));
- }
- }
- break;
- case CHECK_UPTIME: {
- char *tmp_value_list = config.value_list;
- if (config.value_list == NULL) {
- tmp_value_list = "minutes";
- }
- if (strncmp(tmp_value_list, "seconds", strlen("seconds") + 1) &&
- strncmp(tmp_value_list, "minutes", strlen("minutes") + 1) &&
- strncmp(config.value_list, "hours", strlen("hours") + 1) &&
- strncmp(tmp_value_list, "days", strlen("days") + 1)) {
-
- output_message = strdup(_("wrong -l argument"));
- } else {
- xasprintf(&send_buffer, "%s&3", config.req_password);
- fetch_data(config.server_address, config.server_port, send_buffer);
- unsigned long uptime = strtoul(recv_buffer, NULL, 10);
- int updays = uptime / 86400;
- int uphours = (uptime % 86400) / 3600;
- int upminutes = ((uptime % 86400) % 3600) / 60;
-
- if (!strncmp(tmp_value_list, "minutes", strlen("minutes"))) {
- uptime = uptime / 60;
- } else if (!strncmp(tmp_value_list, "hours", strlen("hours"))) {
- uptime = uptime / 3600;
- } else if (!strncmp(tmp_value_list, "days", strlen("days"))) {
- uptime = uptime / 86400;
- }
- /* else uptime in seconds, nothing to do */
-
- xasprintf(&output_message,
- _("System Uptime - %u day(s) %u hour(s) %u minute(s) |uptime=%lu"), updays,
- uphours, upminutes, uptime);
-
- if (config.check_critical_value && uptime <= config.critical_value) {
- return_code = STATE_CRITICAL;
- } else if (config.check_warning_value && uptime <= config.warning_value) {
- return_code = STATE_WARNING;
- } else {
- return_code = STATE_OK;
- }
- }
- } break;
- case CHECK_USEDDISKSPACE:
- if (config.value_list == NULL) {
- output_message = strdup(_("missing -l parameters"));
- } else if (strlen(config.value_list) != 1) {
- output_message = strdup(_("wrong -l argument"));
- } else {
- xasprintf(&send_buffer, "%s&4&%s", config.req_password, config.value_list);
- fetch_data(config.server_address, config.server_port, send_buffer);
- char *fds = strtok(recv_buffer, "&");
- char *tds = strtok(NULL, "&");
- double total_disk_space = 0;
- double free_disk_space = 0;
- if (fds != NULL) {
- free_disk_space = atof(fds);
- }
- if (tds != NULL) {
- total_disk_space = atof(tds);
- }
-
- if (total_disk_space > 0 && free_disk_space >= 0) {
- double percent_used_space =
- ((total_disk_space - free_disk_space) / total_disk_space) * 100;
- double warning_used_space = ((float)config.warning_value / 100) * total_disk_space;
- double critical_used_space =
- ((float)config.critical_value / 100) * total_disk_space;
-
- xasprintf(
- &temp_string,
- _("%s:\\ - total: %.2f Gb - used: %.2f Gb (%.0f%%) - free %.2f Gb (%.0f%%)"),
- config.value_list, total_disk_space / 1073741824,
- (total_disk_space - free_disk_space) / 1073741824, percent_used_space,
- free_disk_space / 1073741824, (free_disk_space / total_disk_space) * 100);
- xasprintf(&temp_string_perf, _("'%s:\\ Used Space'=%.2fGb;%.2f;%.2f;0.00;%.2f"),
- config.value_list, (total_disk_space - free_disk_space) / 1073741824,
- warning_used_space / 1073741824, critical_used_space / 1073741824,
- total_disk_space / 1073741824);
-
- if (config.check_critical_value && percent_used_space >= config.critical_value) {
- return_code = STATE_CRITICAL;
- } else if (config.check_warning_value &&
- percent_used_space >= config.warning_value) {
- return_code = STATE_WARNING;
- } else {
- return_code = STATE_OK;
- }
-
- output_message = strdup(temp_string);
- perfdata = temp_string_perf;
- } else {
- output_message = strdup(_("Free disk space : Invalid drive"));
- return_code = STATE_UNKNOWN;
- }
- }
- break;
- case CHECK_SERVICESTATE:
- case CHECK_PROCSTATE:
- if (config.value_list == NULL) {
- output_message = strdup(_("No service/process specified"));
- } else {
- preparelist(
- config.value_list); /* replace , between services with & to send the request */
- xasprintf(&send_buffer, "%s&%u&%s&%s", config.req_password,
- (config.vars_to_check == CHECK_SERVICESTATE) ? 5 : 6,
- (config.show_all) ? "ShowAll" : "ShowFail", config.value_list);
- fetch_data(config.server_address, config.server_port, send_buffer);
- char *numstr = strtok(recv_buffer, "&");
- if (numstr == NULL) {
- die(STATE_UNKNOWN, _("could not fetch information from server\n"));
- }
- return_code = atoi(numstr);
- temp_string = strtok(NULL, "&");
- output_message = strdup(temp_string);
- }
- break;
- case CHECK_MEMUSE:
- xasprintf(&send_buffer, "%s&7", config.req_password);
- fetch_data(config.server_address, config.server_port, send_buffer);
- char *numstr = strtok(recv_buffer, "&");
- if (numstr == NULL) {
- die(STATE_UNKNOWN, _("could not fetch information from server\n"));
- }
- double mem_commitLimit = atof(numstr);
- numstr = strtok(NULL, "&");
- if (numstr == NULL) {
- die(STATE_UNKNOWN, _("could not fetch information from server\n"));
- }
- double mem_commitByte = atof(numstr);
- double percent_used_space = (mem_commitByte / mem_commitLimit) * 100;
- double warning_used_space = ((float)config.warning_value / 100) * mem_commitLimit;
- double critical_used_space = ((float)config.critical_value / 100) * mem_commitLimit;
-
- /* Divisor should be 1048567, not 3044515, as we are measuring "Commit Charge" here,
- which equals RAM + Pagefiles. */
- xasprintf(
- &output_message,
- _("Memory usage: total:%.2f MB - used: %.2f MB (%.0f%%) - free: %.2f MB (%.0f%%)"),
- mem_commitLimit / 1048567, mem_commitByte / 1048567, percent_used_space,
- (mem_commitLimit - mem_commitByte) / 1048567,
- (mem_commitLimit - mem_commitByte) / mem_commitLimit * 100);
- xasprintf(&perfdata, _("'Memory usage'=%.2fMB;%.2f;%.2f;0.00;%.2f"),
- mem_commitByte / 1048567, warning_used_space / 1048567,
- critical_used_space / 1048567, mem_commitLimit / 1048567);
-
- return_code = STATE_OK;
- if (config.check_critical_value && percent_used_space >= config.critical_value) {
- return_code = STATE_CRITICAL;
- } else if (config.check_warning_value && percent_used_space >= config.warning_value) {
- return_code = STATE_WARNING;
- }
-
- break;
- case CHECK_COUNTER: {
- /*
- CHECK_COUNTER has been modified to provide extensive perfdata information.
- In order to do this, some modifications have been done to the code
- and some constraints have been introduced.
-
- 1) For the sake of simplicity of the code, perfdata information will only be
- provided when the "description" field is added.
-
- 2) If the counter you're going to measure is percent-based, the code will detect
- the percent sign in its name and will attribute minimum (0%) and maximum (100%)
- values automagically, as well the "%" sign to graph units.
-
- 3) OTOH, if the counter is "absolute", you'll have to provide the following
- the counter unit - that is, the dimensions of the counter you're getting. Examples:
- pages/s, packets transferred, etc.
-
- 4) If you want, you may provide the minimum and maximum values to expect. They aren't
- mandatory, but once specified they MUST have the same order of magnitude and units of -w and
- -c; otherwise. strange things will happen when you make graphs of your data.
- */
-
- double counter_value = 0.0;
- if (config.value_list == NULL) {
- output_message = strdup(_("No counter specified"));
- } else {
- preparelist(
- config.value_list); /* replace , between services with & to send the request */
- bool isPercent = (strchr(config.value_list, '%') != NULL);
-
- strtok(config.value_list, "&"); /* burn the first parameters */
- description = strtok(NULL, "&");
- counter_unit = strtok(NULL, "&");
- xasprintf(&send_buffer, "%s&8&%s", config.req_password, config.value_list);
- fetch_data(config.server_address, config.server_port, send_buffer);
- counter_value = atof(recv_buffer);
-
- bool allRight = false;
- if (description == NULL) {
- xasprintf(&output_message, "%.f", counter_value);
- } else if (isPercent) {
- counter_unit = strdup("%");
- allRight = true;
- }
-
- char *minval = NULL;
- char *maxval = NULL;
- double fminval = 0;
- double fmaxval = 0;
- if ((counter_unit != NULL) && (!allRight)) {
- minval = strtok(NULL, "&");
- maxval = strtok(NULL, "&");
-
- /* All parameters specified. Let's check the numbers */
-
- fminval = (minval != NULL) ? strtod(minval, &errcvt) : -1;
- fmaxval = (minval != NULL) ? strtod(maxval, &errcvt) : -1;
-
- if ((fminval == 0) && (minval == errcvt)) {
- output_message = strdup(_("Minimum value contains non-numbers"));
- } else {
- if ((fmaxval == 0) && (maxval == errcvt)) {
- output_message = strdup(_("Maximum value contains non-numbers"));
- } else {
- allRight = true; /* Everything is OK. */
- }
- }
- } else if ((counter_unit == NULL) && (description != NULL)) {
- output_message = strdup(_("No unit counter specified"));
- }
-
- if (allRight) {
- /* Let's format the output string, finally... */
- if (strstr(description, "%") == NULL) {
- xasprintf(&output_message, "%s = %.2f %s", description, counter_value,
- counter_unit);
- } else {
- /* has formatting, will segv if wrong */
- xasprintf(&output_message, description, counter_value);
- }
- xasprintf(&output_message, "%s |", output_message);
- xasprintf(&output_message, "%s %s", output_message,
- fperfdata(description, counter_value, counter_unit, 1,
- config.warning_value, 1, config.critical_value,
- (!(isPercent) && (minval != NULL)), fminval,
- (!(isPercent) && (minval != NULL)), fmaxval));
- }
- }
-
- if (config.critical_value > config.warning_value) { /* Normal thresholds */
- if (config.check_critical_value && counter_value >= config.critical_value) {
- return_code = STATE_CRITICAL;
- } else if (config.check_warning_value && counter_value >= config.warning_value) {
- return_code = STATE_WARNING;
- } else {
- return_code = STATE_OK;
- }
- } else { /* inverse thresholds */
- return_code = STATE_OK;
- if (config.check_critical_value && counter_value <= config.critical_value) {
- return_code = STATE_CRITICAL;
- } else if (config.check_warning_value && counter_value <= config.warning_value) {
- return_code = STATE_WARNING;
- }
- }
- } break;
- case CHECK_FILEAGE:
- if (config.value_list == NULL) {
- output_message = strdup(_("No counter specified"));
- } else {
- preparelist(
- config.value_list); /* replace , between services with & to send the request */
- xasprintf(&send_buffer, "%s&9&%s", config.req_password, config.value_list);
- fetch_data(config.server_address, config.server_port, send_buffer);
- unsigned long age_in_minutes = atoi(strtok(recv_buffer, "&"));
- description = strtok(NULL, "&");
- output_message = strdup(description);
-
- if (config.critical_value > config.warning_value) { /* Normal thresholds */
- if (config.check_critical_value && age_in_minutes >= config.critical_value) {
- return_code = STATE_CRITICAL;
- } else if (config.check_warning_value && age_in_minutes >= config.warning_value) {
- return_code = STATE_WARNING;
- } else {
- return_code = STATE_OK;
- }
- } else { /* inverse thresholds */
- if (config.check_critical_value && age_in_minutes <= config.critical_value) {
- return_code = STATE_CRITICAL;
- } else if (config.check_warning_value && age_in_minutes <= config.warning_value) {
- return_code = STATE_WARNING;
- } else {
- return_code = STATE_OK;
- }
- }
- }
- break;
-
- case CHECK_INSTANCES:
- if (config.value_list == NULL) {
- output_message = strdup(_("No counter specified"));
- } else {
- xasprintf(&send_buffer, "%s&10&%s", config.req_password, config.value_list);
- fetch_data(config.server_address, config.server_port, send_buffer);
- if (!strncmp(recv_buffer, "ERROR", 5)) {
- printf("NSClient - %s\n", recv_buffer);
- exit(STATE_UNKNOWN);
- }
- xasprintf(&output_message, "%s", recv_buffer);
- return_code = STATE_OK;
- }
- break;
-
- case CHECK_NONE:
- default:
- usage4(_("Please specify a variable to check"));
- break;
- }
-
- /* reset timeout */
- alarm(0);
-
- if (perfdata == NULL) {
- printf("%s\n", output_message);
- } else {
- printf("%s | %s\n", output_message, perfdata);
- }
- return return_code;
-}
-
-/* process command-line arguments */
-check_nt_config_wrapper process_arguments(int argc, char **argv) {
- static struct option longopts[] = {{"port", required_argument, 0, 'p'},
- {"timeout", required_argument, 0, 't'},
- {"critical", required_argument, 0, 'c'},
- {"warning", required_argument, 0, 'w'},
- {"variable", required_argument, 0, 'v'},
- {"hostname", required_argument, 0, 'H'},
- {"params", required_argument, 0, 'l'},
- {"secret", required_argument, 0, 's'},
- {"display", required_argument, 0, 'd'},
- {"unknown-timeout", no_argument, 0, 'u'},
- {"version", no_argument, 0, 'V'},
- {"help", no_argument, 0, 'h'},
- {0, 0, 0, 0}};
-
- check_nt_config_wrapper result = {
- .errorcode = OK,
- .config = check_nt_config_init(),
- };
-
- /* no options were supplied */
- if (argc < 2) {
- result.errorcode = ERROR;
- return result;
- }
-
- /* backwards compatibility */
- if (!is_option(argv[1])) {
- result.config.server_address = strdup(argv[1]);
- argv[1] = argv[0];
- argv = &argv[1];
- argc--;
- }
-
- for (int index = 1; index < argc; index++) {
- if (strcmp("-to", argv[index]) == 0) {
- strcpy(argv[index], "-t");
- } else if (strcmp("-wv", argv[index]) == 0) {
- strcpy(argv[index], "-w");
- } else if (strcmp("-cv", argv[index]) == 0) {
- strcpy(argv[index], "-c");
- }
- }
-
- int option = 0;
- while (true) {
- int option_index = getopt_long(argc, argv, "+hVH:t:c:w:p:v:l:s:d:u", longopts, &option);
-
- if (option_index == -1 || option_index == EOF || option_index == 1) {
- break;
- }
-
- switch (option_index) {
- case '?': /* print short usage statement if args not parsable */
- usage5();
- case 'h': /* help */
- print_help();
- exit(STATE_UNKNOWN);
- case 'V': /* version */
- print_revision(progname, NP_VERSION);
- exit(STATE_UNKNOWN);
- case 'H': /* hostname */
- result.config.server_address = optarg;
- break;
- case 's': /* password */
- result.config.req_password = optarg;
- break;
- case 'p': /* port */
- if (is_intnonneg(optarg)) {
- result.config.server_port = atoi(optarg);
- } else {
- die(STATE_UNKNOWN, _("Server port must be an integer\n"));
- }
- break;
- case 'v':
- if (strlen(optarg) < 4) {
- result.errorcode = ERROR;
- return result;
- }
- if (!strcmp(optarg, "CLIENTVERSION")) {
- result.config.vars_to_check = CHECK_CLIENTVERSION;
- } else if (!strcmp(optarg, "CPULOAD")) {
- result.config.vars_to_check = CHECK_CPULOAD;
- } else if (!strcmp(optarg, "UPTIME")) {
- result.config.vars_to_check = CHECK_UPTIME;
- } else if (!strcmp(optarg, "USEDDISKSPACE")) {
- result.config.vars_to_check = CHECK_USEDDISKSPACE;
- } else if (!strcmp(optarg, "SERVICESTATE")) {
- result.config.vars_to_check = CHECK_SERVICESTATE;
- } else if (!strcmp(optarg, "PROCSTATE")) {
- result.config.vars_to_check = CHECK_PROCSTATE;
- } else if (!strcmp(optarg, "MEMUSE")) {
- result.config.vars_to_check = CHECK_MEMUSE;
- } else if (!strcmp(optarg, "COUNTER")) {
- result.config.vars_to_check = CHECK_COUNTER;
- } else if (!strcmp(optarg, "FILEAGE")) {
- result.config.vars_to_check = CHECK_FILEAGE;
- } else if (!strcmp(optarg, "INSTANCES")) {
- result.config.vars_to_check = CHECK_INSTANCES;
- } else {
- result.errorcode = ERROR;
- return result;
- }
- break;
- case 'l': /* value list */
- result.config.value_list = optarg;
- break;
- case 'w': /* warning threshold */
- result.config.warning_value = strtoul(optarg, NULL, 10);
- result.config.check_warning_value = true;
- break;
- case 'c': /* critical threshold */
- result.config.critical_value = strtoul(optarg, NULL, 10);
- result.config.check_critical_value = true;
- break;
- case 'd': /* Display select for services */
- if (!strcmp(optarg, "SHOWALL")) {
- result.config.show_all = true;
- }
- break;
- case 'u':
- socket_timeout_state = STATE_UNKNOWN;
- break;
- case 't': /* timeout */
- socket_timeout = atoi(optarg);
- if (socket_timeout <= 0) {
- result.errorcode = ERROR;
- return result;
- }
- }
- }
- if (result.config.server_address == NULL) {
- usage4(_("You must provide a server address or host name"));
- }
-
- if (result.config.vars_to_check == CHECK_NONE) {
- result.errorcode = ERROR;
- return result;
- }
-
- if (result.config.req_password == NULL) {
- result.config.req_password = strdup(_("None"));
- }
-
- return result;
-}
-
-void fetch_data(const char *address, int port, const char *sendb) {
- int result = process_tcp_request(address, port, sendb, recv_buffer, sizeof(recv_buffer));
-
- if (result != STATE_OK) {
- die(result, _("could not fetch information from server\n"));
- }
-
- if (!strncmp(recv_buffer, "ERROR", 5)) {
- die(STATE_UNKNOWN, "NSClient - %s\n", recv_buffer);
- }
-}
-
-bool strtoularray(unsigned long *array, char *string, const char *delim) {
- /* split a delimited string into a long array */
- for (int idx = 0; idx < MAX_VALUE_LIST; idx++) {
- array[idx] = 0;
- }
-
- int idx = 0;
- for (char *t1 = strtok(string, delim); t1 != NULL; t1 = strtok(NULL, delim)) {
- if (is_numeric(t1) && idx < MAX_VALUE_LIST) {
- array[idx] = strtoul(t1, NULL, 10);
- idx++;
- } else {
- return false;
- }
- }
- return true;
-}
-
-void preparelist(char *string) {
- /* Replace all , with & which is the delimiter for the request */
- for (int i = 0; (size_t)i < strlen(string); i++) {
- if (string[i] == ',') {
- string[i] = '&';
- }
- }
-}
-
-void print_help(void) {
- print_revision(progname, NP_VERSION);
-
- printf("Copyright (c) 2000 Yves Rubin (rubiyz@yahoo.com)\n");
- printf(COPYRIGHT, copyright, email);
-
- printf("%s\n", _("This plugin collects data from the NSClient service running on a"));
- printf("%s\n", _("Windows NT/2000/XP/2003 server."));
-
- printf("\n\n");
-
- print_usage();
-
- printf(UT_HELP_VRSN);
- printf(UT_EXTRA_OPTS);
-
- printf("%s\n", _("Options:"));
- printf(" %s\n", "-H, --hostname=HOST");
- printf(" %s\n", _("Name of the host to check"));
- printf(" %s\n", "-p, --port=INTEGER");
- printf(" %s", _("Optional port number (default: "));
- printf("%d)\n", PORT);
- printf(" %s\n", "-s, --secret=");
- printf(" %s\n", _("Password needed for the request"));
- printf(" %s\n", "-w, --warning=INTEGER");
- printf(" %s\n", _("Threshold which will result in a warning status"));
- printf(" %s\n", "-c, --critical=INTEGER");
- printf(" %s\n", _("Threshold which will result in a critical status"));
- printf(" %s\n", "-t, --timeout=INTEGER");
- printf(" %s", _("Seconds before connection attempt times out (default: "));
- printf(" %s\n", "-l, --params=");
- printf(" %s", _("Parameters passed to specified check (see below)"));
- printf(" %s\n", "-d, --display={SHOWALL}");
- printf(" %s", _("Display options (currently only SHOWALL works)"));
- printf(" %s\n", "-u, --unknown-timeout");
- printf(" %s", _("Return UNKNOWN on timeouts"));
- printf("%d)\n", DEFAULT_SOCKET_TIMEOUT);
- printf(" %s\n", "-h, --help");
- printf(" %s\n", _("Print this help screen"));
- printf(" %s\n", "-V, --version");
- printf(" %s\n", _("Print version information"));
- printf(" %s\n", "-v, --variable=STRING");
- printf(" %s\n\n", _("Variable to check"));
- printf("%s\n", _("Valid variables are:"));
- printf(" %s", "CLIENTVERSION =");
- printf(" %s\n", _("Get the NSClient version"));
- printf(" %s\n", _("If -l is specified, will return warning if versions differ."));
- printf(" %s\n", "CPULOAD =");
- printf(" %s\n", _("Average CPU load on last x minutes."));
- printf(" %s\n", _("Request a -l parameter with the following syntax:"));
- printf(" %s\n", _("-l ,,."));
- printf(" %s\n", _(" should be less than 24*60."));
- printf(" %s\n", _("Thresholds are percentage and up to 10 requests can be done in one shot."));
- printf(" %s\n", "ie: -l 60,90,95,120,90,95");
- printf(" %s\n", "UPTIME =");
- printf(" %s\n", _("Get the uptime of the machine."));
- printf(" %s\n", _("-l "));
- printf(" %s\n", _(" = seconds, minutes, hours, or days. (default: minutes)"));
- printf(" %s\n", _("Thresholds will use the unit specified above."));
- printf(" %s\n", "USEDDISKSPACE =");
- printf(" %s\n", _("Size and percentage of disk use."));
- printf(" %s\n", _("Request a -l parameter containing the drive letter only."));
- printf(" %s\n", _("Warning and critical thresholds can be specified with -w and -c."));
- printf(" %s\n", "MEMUSE =");
- printf(" %s\n", _("Memory use."));
- printf(" %s\n", _("Warning and critical thresholds can be specified with -w and -c."));
- printf(" %s\n", "SERVICESTATE =");
- printf(" %s\n", _("Check the state of one or several services."));
- printf(" %s\n", _("Request a -l parameters with the following syntax:"));
- printf(" %s\n", _("-l ,,,..."));
- printf(" %s\n", _("You can specify -d SHOWALL in case you want to see working services"));
- printf(" %s\n", _("in the returned string."));
- printf(" %s\n", "PROCSTATE =");
- printf(" %s\n", _("Check if one or several process are running."));
- printf(" %s\n", _("Same syntax as SERVICESTATE."));
- printf(" %s\n", "COUNTER =");
- printf(" %s\n", _("Check any performance counter of Windows NT/2000."));
- printf(" %s\n", _("Request a -l parameters with the following syntax:"));
- printf(" %s\n", _("-l \"\\\\\\\\counter\",\""));
- printf(" %s\n", _("The parameter is optional and is given to a printf "));
- printf(" %s\n", _("output command which requires a float parameter."));
- printf(" %s\n", _("If does not include \"%%\", it is used as a label."));
- printf(" %s\n", _("Some examples:"));
- printf(" %s\n", "\"Paging file usage is %%.2f %%%%\"");
- printf(" %s\n", "\"%%.f %%%% paging file used.\"");
- printf(" %s\n", "INSTANCES =");
- printf(" %s\n", _("Check any performance counter object of Windows NT/2000."));
- printf(" %s\n",
- _("Syntax: check_nt -H -p -v INSTANCES -l "));
- printf(" %s\n", _(" is a Windows Perfmon Counter object (eg. Process),"));
- printf(" %s\n", _("if it is two words, it should be enclosed in quotes"));
- printf(" %s\n", _("The returned results will be a comma-separated list of instances on "));
- printf(" %s\n", _(" the selected computer for that object."));
- printf(" %s\n",
- _("The purpose of this is to be run from command line to determine what instances"));
- printf(" %s\n",
- _(" are available for monitoring without having to log onto the Windows server"));
- printf(" %s\n", _(" to run Perfmon directly."));
- printf(" %s\n",
- _("It can also be used in scripts that automatically create the monitoring service"));
- printf(" %s\n", _(" configuration files."));
- printf(" %s\n", _("Some examples:"));
- printf(" %s\n\n", _("check_nt -H 192.168.1.1 -p 1248 -v INSTANCES -l Process"));
-
- printf("%s\n", _("Notes:"));
- printf(" %s\n",
- _("- The NSClient service should be running on the server to get any information"));
- printf(" %s\n", "(http://nsclient.ready2run.nl).");
- printf(" %s\n", _("- Critical thresholds should be lower than warning thresholds"));
- printf(" %s\n", _("- Default port 1248 is sometimes in use by other services. The error"));
- printf(" %s\n",
- _("output when this happens contains \"Cannot map xxxxx to protocol number\"."));
- printf(" %s\n", _("One fix for this is to change the port to something else on check_nt "));
- printf(" %s\n", _("and on the client service it\'s connecting to."));
-
- printf(UT_SUPPORT);
-}
-
-void print_usage(void) {
- printf("%s\n", _("Usage:"));
- printf("%s -H host -v variable [-p port] [-w warning] [-c critical]\n", progname);
- printf("[-l params] [-d SHOWALL] [-u] [-t timeout]\n");
-}
diff --git a/plugins/check_nt.d/config.h b/plugins/check_nt.d/config.h
deleted file mode 100644
index 431889cb..00000000
--- a/plugins/check_nt.d/config.h
+++ /dev/null
@@ -1,53 +0,0 @@
-#pragma once
-
-#include "../../config.h"
-#include
-
-enum {
- PORT = 1248,
-};
-
-enum checkvars {
- CHECK_NONE,
- CHECK_CLIENTVERSION,
- CHECK_CPULOAD,
- CHECK_UPTIME,
- CHECK_USEDDISKSPACE,
- CHECK_SERVICESTATE,
- CHECK_PROCSTATE,
- CHECK_MEMUSE,
- CHECK_COUNTER,
- CHECK_FILEAGE,
- CHECK_INSTANCES
-};
-
-typedef struct {
- char *server_address;
- int server_port;
- char *req_password;
- enum checkvars vars_to_check;
- bool show_all;
- char *value_list;
- bool check_warning_value;
- unsigned long warning_value;
- bool check_critical_value;
- unsigned long critical_value;
-} check_nt_config;
-
-check_nt_config check_nt_config_init() {
- check_nt_config tmp = {
- .server_address = NULL,
- .server_port = PORT,
- .req_password = NULL,
-
- .vars_to_check = CHECK_NONE,
- .show_all = false,
- .value_list = NULL,
-
- .check_warning_value = false,
- .warning_value = 0,
- .check_critical_value = false,
- .critical_value = 0,
- };
- return tmp;
-}
diff --git a/plugins/tests/check_nt.t b/plugins/tests/check_nt.t
deleted file mode 100755
index 223d4933..00000000
--- a/plugins/tests/check_nt.t
+++ /dev/null
@@ -1,80 +0,0 @@
-#! /usr/bin/perl -w -I ..
-#
-# Test check_nt by having a stub check_nt daemon
-#
-
-use strict;
-use Test::More;
-use NPTest;
-use FindBin qw($Bin);
-
-use IO::Socket;
-use IO::Select;
-use POSIX;
-
-my $port = 50000 + int(rand(1000));
-
-my $pid = fork();
-if ($pid) {
- # Parent
- #print "parent\n";
- # give our webserver some time to startup
- sleep(1);
-} else {
- # Child
- #print "child\n";
-
- my $server = IO::Socket::INET->new(
- LocalPort => $port,
- Type => SOCK_STREAM,
- Reuse => 1,
- Proto => "tcp",
- Listen => 10,
- ) or die "Cannot be a tcp server on port $port: $@";
-
- $server->autoflush(1);
-
- print "Please contact me at port $port\n";
- while (my $client = $server->accept ) {
- my $data = "";
- my $rv = $client->recv($data, POSIX::BUFSIZ, 0);
-
- my ($password, $command, $arg) = split('&', $data);
-
- if ($command eq "4") {
- if ($arg eq "c") {
- print $client "930000000&1000000000";
- } elsif ($arg eq "d") {
- print $client "UNKNOWN: Drive is not a fixed drive";
- }
- }
- }
- exit;
-}
-
-END { if ($pid) { print "Killing $pid\n"; kill "INT", $pid } };
-
-if ($ARGV[0] && $ARGV[0] eq "-d") {
- sleep 1000;
-}
-
-if (-x "./check_nt") {
- plan tests => 5;
-} else {
- plan skip_all => "No check_nt compiled";
-}
-
-my $result;
-my $command = "./check_nt -H 127.0.0.1 -p $port";
-
-$result = NPTest->testCmd( "$command -v USEDDISKSPACE -l c" );
-is( $result->return_code, 0, "USEDDISKSPACE c");
-is( $result->output, q{c:\ - total: 0.93 Gb - used: 0.07 Gb (7%) - free 0.87 Gb (93%) | 'c:\ Used Space'=0.07Gb;0.00;0.00;0.00;0.93}, "Output right" );
-
-$result = NPTest->testCmd( "$command -v USEDDISKSPACE -l d" );
-is( $result->return_code, 3, "USEDDISKSPACE d - invalid");
-is( $result->output, "Free disk space : Invalid drive", "Output right" );
-
-$result = NPTest->testCmd( "./check_nt -v USEDDISKSPACE -l d" );
-is( $result->return_code, 3, "Fail if -H missing");
-
--
cgit v1.2.3-74-g34f1
From 59d7d1c2f12363331d03d956cfce0936034c34f8 Mon Sep 17 00:00:00 2001
From: Alvar Penning
Date: Wed, 10 Dec 2025 20:55:56 +0100
Subject: configure.ac: Fix PostgreSQL Check for OpenBSD
On OpenBSD, crypt is named crypto. This diff is a portable version of a
patch residing in the OpenBSD ports since ages.
https://codeberg.org/OpenBSD/ports/src/commit/1f15238782c26deb728250cbf591f1ffcd10422f/net/monitoring-plugins/patches/patch-configure_ac
---
configure.ac | 28 +++++++++++++++++++++-------
1 file changed, 21 insertions(+), 7 deletions(-)
(limited to 'configure.ac')
diff --git a/configure.ac b/configure.ac
index 2bf94014..abd90413 100644
--- a/configure.ac
+++ b/configure.ac
@@ -205,32 +205,46 @@ fi
dnl Check for PostgreSQL libraries
_SAVEDLIBS="$LIBS"
_SAVEDCPPFLAGS="$CPPFLAGS"
+case $host in
+ *openbsd*)
+ _CRYPTLIB="crypto"
+ ;;
+ *)
+ _CRYPTLIB="crypt"
+esac
+
AC_ARG_WITH(pgsql,
ACX_HELP_STRING([--with-pgsql=DIR],
[sets path to pgsql installation]),
PGSQL=$withval,)
AC_CHECK_LIB(crypt,main)
-if test "$ac_cv_lib_crypt_main" = "yes" -a "x$PGSQL" != "xno"; then
+AC_CHECK_LIB(crypto,main)
+if test \( "$ac_cv_lib_crypt_main" = "yes" -o "$ac_cv_lib_crypto_main" = "yes" \) -a "x$PGSQL" != "xno"; then
if test -n "$PGSQL"; then
LDFLAGS="$LDFLAGS -L$PGSQL/lib"
CPPFLAGS="$CPPFLAGS -I$PGSQL/include"
fi
- AC_CHECK_LIB(pq,PQsetdbLogin,,,-lcrypt)
+ AC_CHECK_LIB(pq,PQsetdbLogin,,,"-l$_CRYPTLIB")
if test "$ac_cv_lib_pq_PQsetdbLogin" = "yes"; then
AC_CHECK_HEADERS(pgsql/libpq-fe.h)
AC_CHECK_HEADERS(postgresql/libpq-fe.h)
AC_CHECK_HEADERS(libpq-fe.h)
if [[ -n "$PGSQL" -a "$ac_cv_header_libpq_fe_h" = "yes" ]]; then
- PGLIBS="-L$PGSQL/lib -lpq -lcrypt"
+ PGLIBS="-L$PGSQL/lib -lpq -l$_CRYPTLIB"
PGINCLUDE="-I$PGSQL/include"
elif test "$ac_cv_header_pgsql_libpq_fe_h" = "yes"; then
- PGLIBS="-lpq -lcrypt"
+ PGLIBS="-lpq -l$_CRYPTLIB"
PGINCLUDE="-I/usr/include/pgsql"
elif test "$ac_cv_header_postgresql_libpq_fe_h" = "yes"; then
- PGLIBS="-L$PGSQL/lib -lpq -lcrypt"
- PGINCLUDE="-I/usr/include/postgresql"
+ PGLIBS="-L$PGSQL/lib -lpq -l$_CRYPTLIB"
+ case $host in
+ *openbsd*)
+ PGINCLUDE="-I$PGSQL/include/postgresql" ;;
+ *)
+ PGINCLUDE="-I/usr/include/postgresql"
+ esac
elif test "$ac_cv_header_libpq_fe_h" = "yes"; then
- PGLIBS="-L$PGSQL/lib -lpq -lcrypt"
+ PGLIBS="-L$PGSQL/lib -lpq -l$_CRYPTLIB"
PGINCLUDE="-I$PGSQL/include"
fi
if test -z "$PGINCLUDE"; then
--
cgit v1.2.3-74-g34f1
From 7484fcc2606fe1e49dff1ab5f24a69290786b78d Mon Sep 17 00:00:00 2001
From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>
Date: Fri, 9 Jan 2026 14:08:41 +0100
Subject: Fix PS_FORMAT
---
configure.ac | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'configure.ac')
diff --git a/configure.ac b/configure.ac
index abd90413..7361434a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -810,7 +810,7 @@ elif ps axwo 'stat comm vsz rss user uid pid ppid etime args' 2>/dev/null | \
then
ac_cv_ps_varlist="[procstat,&procuid,&procpid,&procppid,&procvsz,&procrss,&procpcpu,procetime,procprog,&pos]"
ac_cv_ps_command="$PATH_TO_PS axwo 'stat uid pid ppid vsz rss pcpu etime comm args'"
- ac_cv_ps_format="%s %u %d %d %d %d %f %s %s %n"
+ ac_cv_ps_format="%s %d %d %d %d %d %f %s %s %n"
ac_cv_ps_cols=10
AC_MSG_RESULT([$ac_cv_ps_command])
--
cgit v1.2.3-74-g34f1