From 0645c9fc2c7f801ba3c7d68a17c137a63ada299f Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Tue, 18 Feb 2025 21:58:34 +0100 Subject: Implement new output functionality --- plugins/common.h | 9 +-------- plugins/popen.c | 1 - plugins/runcmd.c | 1 + plugins/sslutils.c | 1 + plugins/utils.c | 48 ------------------------------------------------ plugins/utils.h | 11 ++++------- 6 files changed, 7 insertions(+), 64 deletions(-) (limited to 'plugins') diff --git a/plugins/common.h b/plugins/common.h index 833479ce..47b1e4df 100644 --- a/plugins/common.h +++ b/plugins/common.h @@ -32,6 +32,7 @@ #define _COMMON_H_ #include "config.h" +#include "../lib/monitoringplug.h" #ifdef HAVE_FEATURES_H #include @@ -184,14 +185,6 @@ enum { ERROR = -1 }; -enum { - STATE_OK, - STATE_WARNING, - STATE_CRITICAL, - STATE_UNKNOWN, - STATE_DEPENDENT -}; - enum { DEFAULT_SOCKET_TIMEOUT = 10, /* timeout after 10 seconds */ MAX_INPUT_BUFFER = 8192, /* max size of most buffers we use */ diff --git a/plugins/popen.c b/plugins/popen.c index 2b9824bc..cfe930b6 100644 --- a/plugins/popen.c +++ b/plugins/popen.c @@ -40,7 +40,6 @@ #include "./common.h" #include "./utils.h" -#include "../lib/maxfd.h" /* extern so plugin has pid to kill exec'd process on timeouts */ extern pid_t *childpid; diff --git a/plugins/runcmd.c b/plugins/runcmd.c index 74843149..4429ceb0 100644 --- a/plugins/runcmd.c +++ b/plugins/runcmd.c @@ -40,6 +40,7 @@ /** includes **/ #include "runcmd.h" +#include "../lib/monitoringplug.h" #ifdef HAVE_SYS_WAIT_H # include #endif diff --git a/plugins/sslutils.c b/plugins/sslutils.c index 3c928413..719de575 100644 --- a/plugins/sslutils.c +++ b/plugins/sslutils.c @@ -29,6 +29,7 @@ #define MAX_CN_LENGTH 256 #include "common.h" #include "netutils.h" +#include "../lib/monitoringplug.h" #ifdef HAVE_SSL static SSL_CTX *ctx = NULL; diff --git a/plugins/utils.c b/plugins/utils.c index 6d366e3d..09649429 100644 --- a/plugins/utils.c +++ b/plugins/utils.c @@ -42,54 +42,6 @@ extern const char *progname; time_t start_time, end_time; -/* ************************************************************************** - * max_state(STATE_x, STATE_y) - * compares STATE_x to STATE_y and returns result based on the following - * STATE_UNKNOWN < STATE_OK < STATE_WARNING < STATE_CRITICAL - * - * Note that numerically the above does not hold - ****************************************************************************/ - -int max_state(int a, int b) { - if (a == STATE_CRITICAL || b == STATE_CRITICAL) - return STATE_CRITICAL; - else if (a == STATE_WARNING || b == STATE_WARNING) - return STATE_WARNING; - else if (a == STATE_OK || b == STATE_OK) - return STATE_OK; - else if (a == STATE_UNKNOWN || b == STATE_UNKNOWN) - return STATE_UNKNOWN; - else if (a == STATE_DEPENDENT || b == STATE_DEPENDENT) - return STATE_DEPENDENT; - else - return max(a, b); -} - -/* ************************************************************************** - * max_state_alt(STATE_x, STATE_y) - * compares STATE_x to STATE_y and returns result based on the following - * STATE_OK < STATE_DEPENDENT < STATE_UNKNOWN < STATE_WARNING < STATE_CRITICAL - * - * The main difference between max_state_alt and max_state it that it doesn't - * allow setting a default to UNKNOWN. It will instead prioritixe any valid - * non-OK state. - ****************************************************************************/ - -int max_state_alt(int a, int b) { - if (a == STATE_CRITICAL || b == STATE_CRITICAL) - return STATE_CRITICAL; - else if (a == STATE_WARNING || b == STATE_WARNING) - return STATE_WARNING; - else if (a == STATE_UNKNOWN || b == STATE_UNKNOWN) - return STATE_UNKNOWN; - else if (a == STATE_DEPENDENT || b == STATE_DEPENDENT) - return STATE_DEPENDENT; - else if (a == STATE_OK || b == STATE_OK) - return STATE_OK; - else - return max(a, b); -} - void usage(const char *msg) { printf("%s\n", msg); print_usage(); diff --git a/plugins/utils.h b/plugins/utils.h index f939e337..c7073990 100644 --- a/plugins/utils.h +++ b/plugins/utils.h @@ -13,11 +13,11 @@ in order to resist overflow attacks. In addition, a few functions are provided to standardize version and error reporting across the entire suite of plugins. */ -/* now some functions etc are being defined in ../lib/utils_base.c */ -#include "utils_base.h" - +#include "../config.h" #include - +#include +#include +#include #ifdef NP_EXTRA_OPTS /* Include extra-opts functions if compiled in */ @@ -78,9 +78,6 @@ char *strpcat (char *, const char *, const char *); int xvasprintf (char **strp, const char *fmt, va_list ap); int xasprintf (char **strp, const char *fmt, ...); -int max_state (int a, int b); -int max_state_alt (int a, int b); - void usage (const char *) __attribute__((noreturn)); void usage2(const char *, const char *) __attribute__((noreturn)); void usage3(const char *, int) __attribute__((noreturn)); -- cgit v1.2.3-74-g34f1