From 285db2a9fa25519cacd48a76347ae2dee0c06605 Mon Sep 17 00:00:00 2001
From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>
Date: Tue, 18 Mar 2025 14:36:20 +0100
Subject: Move disk specific stuff from lib to plugin specific directory
---
lib/Makefile.am | 3 +-
lib/utils_disk.c | 255 -------------------------------------------------------
lib/utils_disk.h | 48 -----------
3 files changed, 1 insertion(+), 305 deletions(-)
delete mode 100644 lib/utils_disk.c
delete mode 100644 lib/utils_disk.h
(limited to 'lib')
diff --git a/lib/Makefile.am b/lib/Makefile.am
index e41201c4..a9f3ff40 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -7,10 +7,9 @@ noinst_LIBRARIES = libmonitoringplug.a
AM_CPPFLAGS = -DNP_STATE_DIR_PREFIX=\"$(localstatedir)\" \
-I$(srcdir) -I$(top_srcdir)/gl -I$(top_srcdir)/intl -I$(top_srcdir)/plugins
-libmonitoringplug_a_SOURCES = utils_base.c utils_disk.c utils_tcp.c utils_cmd.c maxfd.c output.c perfdata.c output.c thresholds.c vendor/cJSON/cJSON.c
+libmonitoringplug_a_SOURCES = utils_base.c utils_tcp.c utils_cmd.c maxfd.c output.c perfdata.c output.c thresholds.c vendor/cJSON/cJSON.c
EXTRA_DIST = utils_base.h \
- utils_disk.h \
utils_tcp.h \
utils_cmd.h \
parse_ini.h \
diff --git a/lib/utils_disk.c b/lib/utils_disk.c
deleted file mode 100644
index 2b761f5e..00000000
--- a/lib/utils_disk.c
+++ /dev/null
@@ -1,255 +0,0 @@
-/*****************************************************************************
- *
- * Library for check_disk
- *
- * License: GPL
- * Copyright (c) 1999-2024 Monitoring Plugins Development Team
- *
- * Description:
- *
- * This file contains utilities for check_disk. These are tested by libtap
- *
- *
- * 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 "gl/fsusage.h"
-#include
-
-void np_add_name(struct name_list **list, const char *name) {
- struct name_list *new_entry;
- new_entry = (struct name_list *)malloc(sizeof *new_entry);
- new_entry->name = (char *)name;
- new_entry->next = *list;
- *list = new_entry;
-}
-
-/* @brief Initialises a new regex at the begin of list via regcomp(3)
- *
- * @details if the regex fails to compile the error code of regcomp(3) is returned
- * and list is not modified, otherwise list is modified to point to the new
- * element
- * @param list Pointer to a linked list of regex_list elements
- * @param regex the string containing the regex which should be inserted into the list
- * @param clags the cflags parameter for regcomp(3)
- */
-int np_add_regex(struct regex_list **list, const char *regex, int cflags) {
- struct regex_list *new_entry = (struct regex_list *)malloc(sizeof *new_entry);
-
- if (new_entry == NULL) {
- die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), strerror(errno));
- }
-
- int regcomp_result = regcomp(&new_entry->regex, regex, cflags);
-
- if (!regcomp_result) {
- // regcomp succeeded
- new_entry->next = *list;
- *list = new_entry;
-
- return 0;
- } else {
- // regcomp failed
- free(new_entry);
-
- return regcomp_result;
- }
-}
-
-/* Initialises a new parameter at the end of list */
-struct parameter_list *np_add_parameter(struct parameter_list **list, const char *name) {
- struct parameter_list *current = *list;
- struct parameter_list *new_path;
- new_path = (struct parameter_list *)malloc(sizeof *new_path);
- new_path->name = (char *)malloc(strlen(name) + 1);
- new_path->best_match = NULL;
- new_path->name_next = NULL;
- new_path->name_prev = NULL;
- new_path->freespace_bytes = NULL;
- new_path->freespace_units = NULL;
- new_path->freespace_percent = NULL;
- new_path->usedspace_bytes = NULL;
- new_path->usedspace_units = NULL;
- new_path->usedspace_percent = NULL;
- new_path->usedinodes_percent = NULL;
- new_path->freeinodes_percent = NULL;
- new_path->group = NULL;
- new_path->dfree_pct = -1;
- new_path->dused_pct = -1;
- new_path->total = 0;
- new_path->available = 0;
- new_path->available_to_root = 0;
- new_path->used = 0;
- new_path->dused_units = 0;
- new_path->dfree_units = 0;
- new_path->dtotal_units = 0;
- new_path->inodes_total = 0;
- new_path->inodes_free = 0;
- new_path->inodes_free_to_root = 0;
- new_path->inodes_used = 0;
- new_path->dused_inodes_percent = 0;
- new_path->dfree_inodes_percent = 0;
-
- strcpy(new_path->name, name);
-
- if (current == NULL) {
- *list = new_path;
- new_path->name_prev = NULL;
- } else {
- while (current->name_next) {
- current = current->name_next;
- }
- current->name_next = new_path;
- new_path->name_prev = current;
- }
- return new_path;
-}
-
-/* Delete a given parameter from list and return pointer to next element*/
-struct parameter_list *np_del_parameter(struct parameter_list *item, struct parameter_list *prev) {
- if (item == NULL) {
- return NULL;
- }
- struct parameter_list *next;
-
- if (item->name_next)
- next = item->name_next;
- else
- next = NULL;
-
- if (next)
- next->name_prev = prev;
-
- if (prev)
- prev->name_next = next;
-
- if (item->name) {
- free(item->name);
- }
- free(item);
-
- return next;
-}
-
-/* returns a pointer to the struct found in the list */
-struct parameter_list *np_find_parameter(struct parameter_list *list, const char *name) {
- struct parameter_list *temp_list;
- for (temp_list = list; temp_list; temp_list = temp_list->name_next) {
- if (!strcmp(temp_list->name, name))
- return temp_list;
- }
-
- return NULL;
-}
-
-void np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list, bool exact) {
- struct parameter_list *d;
- for (d = desired; d; d = d->name_next) {
- if (!d->best_match) {
- struct mount_entry *me;
- size_t name_len = strlen(d->name);
- size_t best_match_len = 0;
- struct mount_entry *best_match = NULL;
- struct fs_usage fsp;
-
- /* set best match if path name exactly matches a mounted device name */
- for (me = mount_list; me; me = me->me_next) {
- if (strcmp(me->me_devname, d->name) == 0) {
- if (get_fs_usage(me->me_mountdir, me->me_devname, &fsp) >= 0) {
- best_match = me;
- }
- }
- }
-
- /* set best match by directory name if no match was found by devname */
- if (!best_match) {
- for (me = mount_list; me; me = me->me_next) {
- size_t len = strlen(me->me_mountdir);
- if ((!exact &&
- (best_match_len <= len && len <= name_len && (len == 1 || strncmp(me->me_mountdir, d->name, len) == 0))) ||
- (exact && strcmp(me->me_mountdir, d->name) == 0)) {
- if (get_fs_usage(me->me_mountdir, me->me_devname, &fsp) >= 0) {
- best_match = me;
- best_match_len = len;
- }
- }
- }
- }
-
- if (best_match) {
- d->best_match = best_match;
- } else {
- d->best_match = NULL; /* Not sure why this is needed as it should be null on initialisation */
- }
- }
- }
-}
-
-/* Returns true if name is in list */
-bool np_find_name(struct name_list *list, const char *name) {
- const struct name_list *n;
-
- if (list == NULL || name == NULL) {
- return false;
- }
- for (n = list; n; n = n->next) {
- if (!strcmp(name, n->name)) {
- return true;
- }
- }
- return false;
-}
-
-/* Returns true if name is in list */
-bool np_find_regmatch(struct regex_list *list, const char *name) {
- int len;
- regmatch_t m;
-
- if (name == NULL) {
- return false;
- }
-
- len = strlen(name);
-
- for (; list; list = list->next) {
- /* Emulate a full match as if surrounded with ^( )$
- by checking whether the match spans the whole name */
- if (!regexec(&list->regex, name, 1, &m, 0) && m.rm_so == 0 && m.rm_eo == len) {
- return true;
- }
- }
-
- return false;
-}
-
-bool np_seen_name(struct name_list *list, const char *name) {
- const struct name_list *s;
- for (s = list; s; s = s->next) {
- if (!strcmp(s->name, name)) {
- return true;
- }
- }
- return false;
-}
-
-bool np_regex_match_mount_entry(struct mount_entry *me, regex_t *re) {
- if (regexec(re, me->me_devname, (size_t)0, NULL, 0) == 0 || regexec(re, me->me_mountdir, (size_t)0, NULL, 0) == 0) {
- return true;
- }
- return false;
-}
diff --git a/lib/utils_disk.h b/lib/utils_disk.h
deleted file mode 100644
index c5e81dc1..00000000
--- a/lib/utils_disk.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/* Header file for utils_disk */
-
-#include "mountlist.h"
-#include "utils_base.h"
-#include "regex.h"
-
-struct name_list {
- char *name;
- struct name_list *next;
-};
-
-struct regex_list {
- regex_t regex;
- struct regex_list *next;
-};
-
-struct parameter_list {
- char *name;
- thresholds *freespace_bytes;
- thresholds *freespace_units;
- thresholds *freespace_percent;
- thresholds *usedspace_bytes;
- thresholds *usedspace_units;
- thresholds *usedspace_percent;
- thresholds *usedinodes_percent;
- thresholds *freeinodes_percent;
- char *group;
- struct mount_entry *best_match;
- struct parameter_list *name_next;
- struct parameter_list *name_prev;
- uintmax_t total, available, available_to_root, used, inodes_free, inodes_free_to_root, inodes_used, inodes_total;
- double dfree_pct, dused_pct;
- uint64_t dused_units, dfree_units, dtotal_units;
- double dused_inodes_percent, dfree_inodes_percent;
-};
-
-void np_add_name(struct name_list **list, const char *name);
-bool np_find_name(struct name_list *list, const char *name);
-bool np_seen_name(struct name_list *list, const char *name);
-int np_add_regex(struct regex_list **list, const char *regex, int cflags);
-bool np_find_regmatch(struct regex_list *list, const char *name);
-struct parameter_list *np_add_parameter(struct parameter_list **list, const char *name);
-struct parameter_list *np_find_parameter(struct parameter_list *list, const char *name);
-struct parameter_list *np_del_parameter(struct parameter_list *item, struct parameter_list *prev);
-
-int search_parameter_list(struct parameter_list *list, const char *name);
-void np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list, bool exact);
-bool np_regex_match_mount_entry(struct mount_entry *me, regex_t *re);
--
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 'lib')
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 f84f614f219b395810e4ca35d5eb5f5a8d2f1d5b Mon Sep 17 00:00:00 2001
From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>
Date: Sun, 30 Mar 2025 22:34:20 +0200
Subject: Bugfix in output
---
lib/output.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
(limited to 'lib')
diff --git a/lib/output.c b/lib/output.c
index 61fbf832..01e50770 100644
--- a/lib/output.c
+++ b/lib/output.c
@@ -13,6 +13,7 @@
// == Global variables
static mp_output_format output_format = MP_FORMAT_DEFAULT;
+static mp_output_detail_level level_of_detail = MP_DETAIL_ALL;
// == Prototypes ==
static char *fmt_subcheck_output(mp_output_format output_format, mp_subcheck check, unsigned int indentation);
@@ -202,7 +203,12 @@ mp_state_enum mp_compute_subcheck_state(const mp_subcheck check) {
}
mp_subcheck_list *scl = check.subchecks;
- mp_state_enum result = check.default_state;
+
+ if (scl == NULL) {
+ return check.default_state;
+ }
+
+ mp_state_enum result = STATE_OK;
while (scl != NULL) {
result = max_state_alt(result, mp_compute_subcheck_state(scl->subcheck));
--
cgit v1.2.3-74-g34f1
From f413ac38e30e606beda4ef7f6bf1db40b49682d3 Mon Sep 17 00:00:00 2001
From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>
Date: Sun, 30 Mar 2025 22:34:42 +0200
Subject: Add selectable level of detail for output
---
lib/output.c | 8 +++++++-
lib/output.h | 16 +++++++++++++---
2 files changed, 20 insertions(+), 4 deletions(-)
(limited to 'lib')
diff --git a/lib/output.c b/lib/output.c
index 01e50770..c408a2f5 100644
--- a/lib/output.c
+++ b/lib/output.c
@@ -253,7 +253,9 @@ char *mp_fmt_output(mp_check check) {
mp_subcheck_list *subchecks = check.subchecks;
while (subchecks != NULL) {
- asprintf(&result, "%s\n%s", result, fmt_subcheck_output(MP_FORMAT_MULTI_LINE, subchecks->subcheck, 1));
+ if (level_of_detail == MP_DETAIL_ALL || mp_compute_subcheck_state(subchecks->subcheck) != STATE_OK) {
+ asprintf(&result, "%s\n%s", result, fmt_subcheck_output(MP_FORMAT_MULTI_LINE, subchecks->subcheck, 1));
+ }
subchecks = subchecks->next;
}
@@ -545,3 +547,7 @@ parsed_output_format mp_parse_output_format(char *format_string) {
void mp_set_format(mp_output_format format) { output_format = format; }
mp_output_format mp_get_format(void) { return output_format; }
+
+void mp_set_level_of_detail(mp_output_detail_level level) { level_of_detail = level; }
+
+mp_output_detail_level mp_get_level_of_detail(void) { return level_of_detail; }
diff --git a/lib/output.h b/lib/output.h
index 2bdfa074..3bd91f90 100644
--- a/lib/output.h
+++ b/lib/output.h
@@ -38,8 +38,18 @@ typedef enum output_format {
/*
* Format related functions
*/
- void mp_set_format(mp_output_format format);
- mp_output_format mp_get_format(void);
+void mp_set_format(mp_output_format format);
+mp_output_format mp_get_format(void);
+
+// Output detail level
+
+typedef enum output_detail_level {
+ MP_DETAIL_ALL,
+ MP_DETAIL_NON_OK_ONLY,
+} mp_output_detail_level;
+
+void mp_set_level_of_detail(mp_output_detail_level level);
+mp_output_detail_level mp_get_level_of_detail(void);
/*
* The main state object of a plugin. Exists only ONCE per plugin.
@@ -48,7 +58,7 @@ typedef enum output_format {
* in the first layer of subchecks
*/
typedef struct {
- char *summary; // Overall summary, if not set a summary will be automatically generated
+ char *summary; // Overall summary, if not set a summary will be automatically generated
mp_subcheck_list *subchecks;
} mp_check;
--
cgit v1.2.3-74-g34f1
From 1921cfccd6d83edb15a04fdb143a3176fb96dd22 Mon Sep 17 00:00:00 2001
From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>
Date: Sun, 30 Mar 2025 22:35:29 +0200
Subject: Always quote perfdata labels
---
lib/perfdata.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'lib')
diff --git a/lib/perfdata.c b/lib/perfdata.c
index 661756c5..4f9c9558 100644
--- a/lib/perfdata.c
+++ b/lib/perfdata.c
@@ -33,7 +33,7 @@ char *pd_value_to_string(const mp_perfdata_value pd) {
char *pd_to_string(mp_perfdata pd) {
assert(pd.label != NULL);
char *result = NULL;
- asprintf(&result, "%s=", pd.label);
+ asprintf(&result, "'%s'=", pd.label);
asprintf(&result, "%s%s", result, pd_value_to_string(pd.value));
--
cgit v1.2.3-74-g34f1
From 6e108cc25e75ec74013838620b26dabdd480718a Mon Sep 17 00:00:00 2001
From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>
Date: Sun, 30 Mar 2025 22:36:07 +0200
Subject: Add more helpers to perfdata functions
---
lib/perfdata.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
lib/perfdata.h | 12 ++++++++
2 files changed, 99 insertions(+)
(limited to 'lib')
diff --git a/lib/perfdata.c b/lib/perfdata.c
index 4f9c9558..1742342e 100644
--- a/lib/perfdata.c
+++ b/lib/perfdata.c
@@ -514,3 +514,90 @@ perfdata_value_parser_wrapper parse_pd_value(const char *input) {
}
return result;
}
+
+mp_perfdata mp_set_pd_max_value(mp_perfdata perfdata, mp_perfdata_value value) {
+ perfdata.max = value;
+ perfdata.max_present = true;
+ return perfdata;
+}
+
+mp_perfdata mp_set_pd_min_value(mp_perfdata perfdata, mp_perfdata_value value) {
+ perfdata.min = value;
+ perfdata.min_present = true;
+ return perfdata;
+}
+
+double mp_get_pd_value(mp_perfdata_value value) {
+ assert(value.type != PD_TYPE_NONE);
+ switch (value.type) {
+ case PD_TYPE_DOUBLE:
+ return value.pd_double;
+ case PD_TYPE_INT:
+ return (double)value.pd_int;
+ case PD_TYPE_UINT:
+ return (double)value.pd_uint;
+ default:
+ return 0; // just to make the compiler happy
+ }
+}
+
+mp_perfdata_value mp_pd_value_multiply(mp_perfdata_value left, mp_perfdata_value right) {
+ if (left.type == right.type) {
+ switch (left.type) {
+ case PD_TYPE_DOUBLE:
+ left.pd_double *= right.pd_double;
+ return left;
+ case PD_TYPE_INT:
+ left.pd_int *= right.pd_int;
+ return left;
+ case PD_TYPE_UINT:
+ left.pd_uint *= right.pd_uint;
+ return left;
+ default:
+ // what to here?
+ return left;
+ }
+ }
+
+ // Different types, oh boy, just do the lazy thing for now and switch to double
+ switch (left.type) {
+ case PD_TYPE_INT:
+ left.pd_double = (double)left.pd_int;
+ left.type = PD_TYPE_DOUBLE;
+ break;
+ case PD_TYPE_UINT:
+ left.pd_double = (double)left.pd_uint;
+ left.type = PD_TYPE_DOUBLE;
+ break;
+ case PD_TYPE_DOUBLE:
+ default:
+ // already there
+ }
+
+ switch (right.type) {
+ case PD_TYPE_INT:
+ right.pd_double = (double)right.pd_int;
+ right.type = PD_TYPE_DOUBLE;
+ break;
+ case PD_TYPE_UINT:
+ right.pd_double = (double)right.pd_uint;
+ right.type = PD_TYPE_DOUBLE;
+ break;
+ case PD_TYPE_DOUBLE:
+ default:
+ // already there
+ }
+
+ left.pd_double *= right.pd_double;
+ return left;
+}
+
+mp_range mp_range_multiply(mp_range range, mp_perfdata_value factor) {
+ if (!range.end_infinity) {
+ range.end = mp_pd_value_multiply(range.end, factor);
+ }
+ if (!range.start_infinity) {
+ range.start = mp_pd_value_multiply(range.start, factor);
+ }
+ return range;
+}
diff --git a/lib/perfdata.h b/lib/perfdata.h
index 74583ee5..cb552678 100644
--- a/lib/perfdata.h
+++ b/lib/perfdata.h
@@ -171,6 +171,11 @@ mp_perfdata_value mp_create_pd_value_u_long(unsigned long);
mp_perfdata_value mp_create_pd_value_long_long(long long);
mp_perfdata_value mp_create_pd_value_u_long_long(unsigned long long);
+mp_perfdata mp_set_pd_max_value(mp_perfdata perfdata, mp_perfdata_value value);
+mp_perfdata mp_set_pd_min_value(mp_perfdata perfdata, mp_perfdata_value value);
+
+double mp_get_pd_value(mp_perfdata_value value);
+
/*
* Free the memory used by a pd_list
*/
@@ -178,6 +183,13 @@ void pd_list_free(pd_list[1]);
int cmp_perfdata_value(mp_perfdata_value, mp_perfdata_value);
+// ================
+// Helper functions
+// ================
+
+mp_perfdata_value mp_pd_value_multiply(mp_perfdata_value left, mp_perfdata_value right);
+mp_range mp_range_multiply(mp_range range, mp_perfdata_value factor);
+
// =================
// String formatters
// =================
--
cgit v1.2.3-74-g34f1
From 0205694ce977af97a71c58e0ae3c431299ceb7bb Mon Sep 17 00:00:00 2001
From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>
Date: Sun, 30 Mar 2025 22:36:38 +0200
Subject: Fix wrong return state in threshold function
---
lib/thresholds.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'lib')
diff --git a/lib/thresholds.c b/lib/thresholds.c
index ddefae37..171f5093 100644
--- a/lib/thresholds.c
+++ b/lib/thresholds.c
@@ -51,7 +51,7 @@ mp_state_enum mp_get_pd_status(mp_perfdata perfdata) {
}
if (perfdata.warn_present) {
if (mp_check_range(perfdata.value, perfdata.warn)) {
- return STATE_CRITICAL;
+ return STATE_WARNING;
}
}
--
cgit v1.2.3-74-g34f1
From 0bca1d1aa36b13723e77672eae162352e9be99c9 Mon Sep 17 00:00:00 2001
From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>
Date: Sun, 30 Mar 2025 22:36:55 +0200
Subject: Implement some helper functions for thresholds
---
lib/thresholds.c | 12 ++++++++++++
lib/thresholds.h | 3 +++
2 files changed, 15 insertions(+)
(limited to 'lib')
diff --git a/lib/thresholds.c b/lib/thresholds.c
index 171f5093..de2b9315 100644
--- a/lib/thresholds.c
+++ b/lib/thresholds.c
@@ -57,3 +57,15 @@ mp_state_enum mp_get_pd_status(mp_perfdata perfdata) {
return STATE_OK;
}
+
+mp_thresholds mp_thresholds_set_warn(mp_thresholds thlds, mp_range warn) {
+ thlds.warning = warn;
+ thlds.warning_is_set = true;
+ return thlds;
+}
+
+mp_thresholds mp_thresholds_set_crit(mp_thresholds thlds, mp_range crit) {
+ thlds.critical = crit;
+ thlds.critical_is_set = true;
+ return thlds;
+}
diff --git a/lib/thresholds.h b/lib/thresholds.h
index 4e7defee..5f9f9247 100644
--- a/lib/thresholds.h
+++ b/lib/thresholds.h
@@ -24,5 +24,8 @@ mp_perfdata mp_pd_set_thresholds(mp_perfdata /* pd */, mp_thresholds /* th */);
mp_state_enum mp_get_pd_status(mp_perfdata /* pd */);
+mp_thresholds mp_thresholds_set_warn(mp_thresholds thlds, mp_range warn);
+mp_thresholds mp_thresholds_set_crit(mp_thresholds thlds, mp_range crit);
+
char *fmt_threshold_warning(thresholds th);
char *fmt_threshold_critical(thresholds th);
--
cgit v1.2.3-74-g34f1
From 430c641d9c6c3efb3fb0493b35e11dbc6ede2faa Mon Sep 17 00:00:00 2001
From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>
Date: Sun, 30 Mar 2025 23:55:16 +0200
Subject: Try to circumvent some old compiler errors
---
lib/perfdata.c | 6 ------
1 file changed, 6 deletions(-)
(limited to 'lib')
diff --git a/lib/perfdata.c b/lib/perfdata.c
index 1742342e..f425ffcf 100644
--- a/lib/perfdata.c
+++ b/lib/perfdata.c
@@ -569,9 +569,6 @@ mp_perfdata_value mp_pd_value_multiply(mp_perfdata_value left, mp_perfdata_value
left.pd_double = (double)left.pd_uint;
left.type = PD_TYPE_DOUBLE;
break;
- case PD_TYPE_DOUBLE:
- default:
- // already there
}
switch (right.type) {
@@ -583,9 +580,6 @@ mp_perfdata_value mp_pd_value_multiply(mp_perfdata_value left, mp_perfdata_value
right.pd_double = (double)right.pd_uint;
right.type = PD_TYPE_DOUBLE;
break;
- case PD_TYPE_DOUBLE:
- default:
- // already there
}
left.pd_double *= right.pd_double;
--
cgit v1.2.3-74-g34f1
From d0647ec7e1500c0e6164ac9820a7d623582bdde2 Mon Sep 17 00:00:00 2001
From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>
Date: Mon, 31 Mar 2025 23:41:51 +0200
Subject: Some code simplifications
---
lib/utils_base.c | 18 +++---------------
1 file changed, 3 insertions(+), 15 deletions(-)
(limited to 'lib')
diff --git a/lib/utils_base.c b/lib/utils_base.c
index ff9540c7..c49a473f 100644
--- a/lib/utils_base.c
+++ b/lib/utils_base.c
@@ -225,27 +225,15 @@ bool mp_check_range(const mp_perfdata_value value, const mp_range my_range) {
if (my_range.end_infinity == false && my_range.start_infinity == false) {
// range: .........|---inside---|...........
// value
- if ((cmp_perfdata_value(my_range.start, value) < 1) && (cmp_perfdata_value(value, my_range.end) <= 0)) {
- is_inside = true;
- } else {
- is_inside = false;
- }
+ is_inside = ((cmp_perfdata_value(my_range.start, value) < 1) && (cmp_perfdata_value(value, my_range.end) <= 0));
} else if (my_range.start_infinity == false && my_range.end_infinity == true) {
// range: .........|---inside---------
// value
- if (cmp_perfdata_value(my_range.start, value) < 0) {
- is_inside = true;
- } else {
- is_inside = false;
- }
+ is_inside = (cmp_perfdata_value(my_range.start, value) < 0);
} else if (my_range.start_infinity == true && my_range.end_infinity == false) {
// range: -inside--------|....................
// value
- if (cmp_perfdata_value(value, my_range.end) == -1) {
- is_inside = true;
- } else {
- is_inside = false;
- }
+ is_inside = (cmp_perfdata_value(value, my_range.end) == -1);
} else {
// range from -inf to inf, so always inside
is_inside = true;
--
cgit v1.2.3-74-g34f1