Merge branch 'development'

This commit is contained in:
Jan Wagner 2023-10-18 12:04:51 +02:00
commit acef571e14
24 changed files with 14 additions and 3514 deletions

17
debian/changelog vendored
View file

@ -1,8 +1,19 @@
monitoring-plugins (2.3.3-7) UNRELEASED; urgency=medium
monitoring-plugins (2.3.5-1) unstable; urgency=medium
*
[ Jan Wagner ]
* [a20810f] Adding d/p/36_check_smtp_adding_proxy_header from upstream
* [0250eb9] Adding d/p/37_check_smtp_Adding_SNI from upstream
* [1381a20] Remove left over d/p/31_checl_mailq_separate_submission_queue
-- Jan Wagner <waja@cyconet.org> Mon, 12 Jun 2023 21:55:02 +0200
[ Bas Couwenberg ]
* [7c86d65] Explicitly enable test-build-twice job.
[ Jan Wagner ]
* [de72f6f] New upstream version 2.3.4
* [5956793] New upstream version 2.3.5
* [f07f4db] Drop patches integrated by upstream
-- Jan Wagner <waja@cyconet.org> Wed, 18 Oct 2023 12:04:05 +0200
monitoring-plugins (2.3.3-6) unstable; urgency=medium

View file

@ -1,166 +0,0 @@
From 6d3e44d2d8395076060e9c741e9b173dc5d57b76 Mon Sep 17 00:00:00 2001
From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com>
Date: Mon, 6 Feb 2023 11:39:44 +0100
Subject: [PATCH 1/2] check_http: Handle chunked encoding without actual
content correctly
---
plugins/check_http.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/plugins/check_http.c b/plugins/check_http.c
index 5fa310f5d..8dda046ff 100644
--- a/plugins/check_http.c
+++ b/plugins/check_http.c
@@ -1462,7 +1462,13 @@ char *unchunk_content(const char *content) {
memcpy(result + (overall_size - size_of_chunk), start_of_chunk, size_of_chunk);
}
- result[overall_size] = '\0';
+ if (overall_size == 0 && result == NULL) {
+ // We might just have received the end chunk without previous content, so result is never allocated
+ result = calloc(1, sizeof(char));
+ // No error handling here, we can only return NULL anyway
+ } else {
+ result[overall_size] = '\0';
+ }
return result;
}
From 03efbb8e4f736bf2df5d9477dd4191501fe035ea Mon Sep 17 00:00:00 2001
From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com>
Date: Mon, 6 Feb 2023 12:15:46 +0100
Subject: [PATCH 2/2] check_http: Implement special case test for zero size
chunk only
---
plugins/tests/check_http.t | 70 +++++++++++++++++++++++++++++++++++++-
1 file changed, 69 insertions(+), 1 deletion(-)
diff --git a/plugins/tests/check_http.t b/plugins/tests/check_http.t
index d766ac372..6078b2745 100755
--- a/plugins/tests/check_http.t
+++ b/plugins/tests/check_http.t
@@ -9,12 +9,14 @@ use strict;
use Test::More;
use NPTest;
use FindBin qw($Bin);
+use IO::Socket::INET;
$ENV{'LC_TIME'} = "C";
my $common_tests = 71;
my $virtual_port_tests = 8;
my $ssl_only_tests = 12;
+my $chunked_encoding_special_tests = 1;
# Check that all dependent modules are available
eval "use HTTP::Daemon 6.01;";
plan skip_all => 'HTTP::Daemon >= 6.01 required' if $@;
@@ -30,7 +32,7 @@ if ($@) {
plan skip_all => "Missing required module for test: $@";
} else {
if (-x "./$plugin") {
- plan tests => $common_tests * 2 + $ssl_only_tests + $virtual_port_tests;
+ plan tests => $common_tests * 2 + $ssl_only_tests + $virtual_port_tests + $chunked_encoding_special_tests;
} else {
plan skip_all => "No $plugin compiled";
}
@@ -51,6 +53,7 @@ my $port_http = 50000 + int(rand(1000));
my $port_https = $port_http + 1;
my $port_https_expired = $port_http + 2;
my $port_https_clientcert = $port_http + 3;
+my $port_hacked_http = $port_http + 4;
# This array keeps sockets around for implementing timeouts
my @persist;
@@ -72,6 +75,28 @@ if (!$pid) {
}
push @pids, $pid;
+# Fork the hacked HTTP server
+undef $pid;
+$pid = fork;
+defined $pid or die "Failed to fork";
+if (!$pid) {
+ # this is the fork
+ undef @pids;
+ my $socket = new IO::Socket::INET (
+ LocalHost => '0.0.0.0',
+ LocalPort => $port_hacked_http,
+ Proto => 'tcp',
+ Listen => 5,
+ Reuse => 1
+ );
+ die "cannot create socket $!n" unless $socket;
+ my $local_sock = $socket->sockport();
+ print "server waiting for client connection on port $local_sock\n";
+ run_hacked_http_server ( $socket );
+ die "hacked http server stopped";
+}
+push @pids, $pid;
+
if (exists $servers->{https}) {
# Fork a normal HTTPS server
$pid = fork;
@@ -207,6 +232,37 @@ sub run_server {
}
}
+sub run_hacked_http_server {
+ my $socket = shift;
+
+ # auto-flush on socket
+ $| = 1;
+
+
+ while(1)
+ {
+ # waiting for a new client connection
+ my $client_socket = $socket->accept();
+
+ # get information about a newly connected client
+ my $client_address = $client_socket->peerhost();
+ my $client_portn = $client_socket->peerport();
+ print "connection from $client_address:$client_portn";
+
+ # read up to 1024 characters from the connected client
+ my $data = "";
+ $client_socket->recv($data, 1024);
+ print "received data: $data";
+
+ # write response data to the connected client
+ $data = "HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n0\r\n\r\n";
+ $client_socket->send($data);
+
+ # notify client that response has been sent
+ shutdown($client_socket, 1);
+ }
+}
+
END {
foreach my $pid (@pids) {
if ($pid) { print "Killing $pid\n"; kill "INT", $pid }
@@ -222,6 +278,7 @@ if ($ARGV[0] && $ARGV[0] eq "-d") {
my $result;
my $command = "./$plugin -H 127.0.0.1";
+run_chunked_encoding_special_test( {command => "$command -p $port_hacked_http"});
run_common_tests( { command => "$command -p $port_http" } );
SKIP: {
skip "HTTP::Daemon::SSL not installed", $common_tests + $ssl_only_tests if ! exists $servers->{https};
@@ -511,3 +568,14 @@ sub run_common_tests {
};
is( $@, "", $cmd );
}
+
+sub run_chunked_encoding_special_test {
+ my ($opts) = @_;
+ my $command = $opts->{command};
+
+ $cmd = "$command -u / -s 'ChunkedEncodingSpecialTest'";
+ eval {
+ $result = NPTest->testCmd( $cmd, 5 );
+ };
+ is( $@, "", $cmd );
+}

View file

@ -1,62 +0,0 @@
From 6f0ce3804a396ce89c09f50123e5f31b5b525b31 Mon Sep 17 00:00:00 2001
From: Andreas Baumann <mail@andreasbaumann.cc>
Date: Sat, 4 Feb 2023 16:19:46 +0100
Subject: [PATCH 1/2] fallback to SSL_CTX_use_certificate_file for gnutls
---
plugins/sslutils.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/plugins/sslutils.c b/plugins/sslutils.c
index 286273f61..d542c499f 100644
--- a/plugins/sslutils.c
+++ b/plugins/sslutils.c
@@ -134,7 +134,18 @@ int np_net_ssl_init_with_hostname_version_and_cert(int sd, char *host_name, int
return STATE_CRITICAL;
}
if (cert && privkey) {
- SSL_CTX_use_certificate_chain_file(c, cert);
+#ifdef USE_OPENSSL
+ if (!SSL_CTX_use_certificate_chain_file(c, cert)) {
+#else
+#if USE_GNUTLS
+ if (!SSL_CTX_use_certificate_file(c, cert, SSL_FILETYPE_PEM)) {
+#else
+#error Unported for unknown SSL library
+#endif
+#endif
+ printf ("%s\n", _("CRITICAL - Unable to open certificate chain file!\n"));
+ return STATE_CRITICAL;
+ }
SSL_CTX_use_PrivateKey_file(c, privkey, SSL_FILETYPE_PEM);
#ifdef USE_OPENSSL
if (!SSL_CTX_check_private_key(c)) {
From 28b5a1cc454774474b98037acd283a1da4c3f7ad Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lorenz=20K=C3=A4stle?=
<12514511+RincewindsHat@users.noreply.github.com>
Date: Thu, 9 Feb 2023 00:35:20 +0100
Subject: [PATCH 2/2] Make preprocessor fallback for gnutls more readable
---
plugins/sslutils.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/plugins/sslutils.c b/plugins/sslutils.c
index d542c499f..a7d801963 100644
--- a/plugins/sslutils.c
+++ b/plugins/sslutils.c
@@ -136,12 +136,10 @@ int np_net_ssl_init_with_hostname_version_and_cert(int sd, char *host_name, int
if (cert && privkey) {
#ifdef USE_OPENSSL
if (!SSL_CTX_use_certificate_chain_file(c, cert)) {
-#else
-#if USE_GNUTLS
+#elif USE_GNUTLS
if (!SSL_CTX_use_certificate_file(c, cert, SSL_FILETYPE_PEM)) {
#else
#error Unported for unknown SSL library
-#endif
#endif
printf ("%s\n", _("CRITICAL - Unable to open certificate chain file!\n"));
return STATE_CRITICAL;

View file

@ -1,906 +0,0 @@
From 53f07a468db98247dc4012de0ee678f29cc2bfec Mon Sep 17 00:00:00 2001
From: Andreas Baumann <mail@andreasbaumann.cc>
Date: Sun, 5 Feb 2023 20:34:41 +0100
Subject: [PATCH 1/7] using CURLOPT_REDIR_PROTOCOLS_STR instead of
CURLOPT_REDIR_PROTOCOLS for curl >= 7.85.0
---
plugins/check_curl.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/plugins/check_curl.c b/plugins/check_curl.c
index c6593df1a..7916eb55a 100644
--- a/plugins/check_curl.c
+++ b/plugins/check_curl.c
@@ -688,9 +688,13 @@ check_http (void)
handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_MAXREDIRS, max_depth+1), "CURLOPT_MAXREDIRS");
/* for now allow only http and https (we are a http(s) check plugin in the end) */
+#if LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 85, 0)
+ handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_REDIR_PROTOCOLS_STR, "http,https"), "CURLOPT_REDIR_PROTOCOLS_STR");
+#else
#if LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 19, 4)
handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS), "CURLOPT_REDIRECT_PROTOCOLS");
#endif /* LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 19, 4) */
+#endif /* LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 85, 4) */
/* TODO: handle the following aspects of redirection, make them
* command line options too later:
From 27b0c6964559ba60ff6c7a626d51e62e5256ed62 Mon Sep 17 00:00:00 2001
From: Andreas Baumann <mail@andreasbaumann.cc>
Date: Sat, 11 Feb 2023 18:39:24 +0100
Subject: [PATCH 2/7] fixed regerror is MAX_INPUT_BUFFER writting into too
small errbuf
---
plugins/check_curl.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/plugins/check_curl.c b/plugins/check_curl.c
index 7916eb55a..406f6f884 100644
--- a/plugins/check_curl.c
+++ b/plugins/check_curl.c
@@ -173,7 +173,7 @@ double time_connect;
double time_appconnect;
double time_headers;
double time_firstbyte;
-char errbuf[CURL_ERROR_SIZE+1];
+char errbuf[MAX_INPUT_BUFFER];
CURLcode res;
char url[DEFAULT_BUFFER_SIZE];
char msg[DEFAULT_BUFFER_SIZE];
From f6978deaa1bf7c6a7196363104ebfcef143080ab Mon Sep 17 00:00:00 2001
From: Andreas Baumann <mail@andreasbaumann.cc>
Date: Sat, 11 Feb 2023 19:11:07 +0100
Subject: [PATCH 3/7] added --cookie-jar and doing proper cleanup of libcurl
---
plugins/check_curl.c | 47 ++++++++++++++++++++++++++++++++------------
1 file changed, 34 insertions(+), 13 deletions(-)
diff --git a/plugins/check_curl.c b/plugins/check_curl.c
index 406f6f884..35d1237b8 100644
--- a/plugins/check_curl.c
+++ b/plugins/check_curl.c
@@ -214,6 +214,7 @@ int address_family = AF_UNSPEC;
curlhelp_ssl_library ssl_library = CURLHELP_SSL_LIBRARY_UNKNOWN;
int curl_http_version = CURL_HTTP_VERSION_NONE;
int automatic_decompression = FALSE;
+char *cookie_jar_file = NULL;
int process_arguments (int, char**);
void handle_curl_option_return_code (CURLcode res, const char* option);
@@ -412,6 +413,19 @@ lookup_host (const char *host, char *buf, size_t buflen)
return 0;
}
+static void
+cleanup (void)
+{
+ curlhelp_free_statusline(&status_line);
+ curl_easy_cleanup (curl);
+ curl_global_cleanup ();
+ curlhelp_freewritebuffer (&body_buf);
+ curlhelp_freewritebuffer (&header_buf);
+ if (!strcmp (http_method, "PUT")) {
+ curlhelp_freereadbuffer (&put_buf);
+ }
+}
+
int
check_http (void)
{
@@ -743,7 +757,16 @@ check_http (void)
handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_INFILESIZE, (curl_off_t)strlen (http_post_data)), "CURLOPT_INFILESIZE");
}
}
+
+ /* cookie handling */
+ if (cookie_jar_file != NULL) {
+ handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_COOKIEJAR, cookie_jar_file), "CURLOPT_COOKIEJAR");
+ handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_COOKIEFILE, cookie_jar_file), "CURLOPT_COOKIEFILE");
+ }
+ /* register cleanup function to shut down libcurl properly */
+ atexit (cleanup);
+
/* do the request */
res = curl_easy_perform(curl);
@@ -1021,7 +1044,7 @@ check_http (void)
else
msg[strlen(msg)-3] = '\0';
}
-
+
/* TODO: separate _() msg and status code: die (result, "HTTP %s: %s\n", state_text(result), msg); */
die (result, "HTTP %s: %s %d %s%s%s - %d bytes in %.3f second response time %s|%s\n%s%s",
state_text(result), string_statuscode (status_line.http_major, status_line.http_minor),
@@ -1033,16 +1056,6 @@ check_http (void)
(show_body ? body_buf.buf : ""),
(show_body ? "\n" : "") );
- /* proper cleanup after die? */
- curlhelp_free_statusline(&status_line);
- curl_easy_cleanup (curl);
- curl_global_cleanup ();
- curlhelp_freewritebuffer (&body_buf);
- curlhelp_freewritebuffer (&header_buf);
- if (!strcmp (http_method, "PUT")) {
- curlhelp_freereadbuffer (&put_buf);
- }
-
return result;
}
@@ -1239,7 +1252,8 @@ process_arguments (int argc, char **argv)
CONTINUE_AFTER_CHECK_CERT,
CA_CERT_OPTION,
HTTP_VERSION_OPTION,
- AUTOMATIC_DECOMPRESSION
+ AUTOMATIC_DECOMPRESSION,
+ COOKIE_JAR
};
int option = 0;
@@ -1285,6 +1299,7 @@ process_arguments (int argc, char **argv)
{"max-redirs", required_argument, 0, MAX_REDIRS_OPTION},
{"http-version", required_argument, 0, HTTP_VERSION_OPTION},
{"enable-automatic-decompression", no_argument, 0, AUTOMATIC_DECOMPRESSION},
+ {"cookie-jar", required_argument, 0, COOKIE_JAR},
{0, 0, 0, 0}
};
@@ -1691,6 +1706,9 @@ process_arguments (int argc, char **argv)
case AUTOMATIC_DECOMPRESSION:
automatic_decompression = TRUE;
break;
+ case COOKIE_JAR:
+ cookie_jar_file = optarg;
+ break;
case '?':
/* print short usage statement if args not parsable */
usage5 ();
@@ -1910,6 +1928,8 @@ print_help (void)
printf (" %s\n", _("1.0 = HTTP/1.0, 1.1 = HTTP/1.1, 2.0 = HTTP/2 (HTTP/2 will fail without -S)"));
printf (" %s\n", "--enable-automatic-decompression");
printf (" %s\n", _("Enable automatic decompression of body (CURLOPT_ACCEPT_ENCODING)."));
+ printf (" %s\n", "---cookie-jar=FILE");
+ printf (" %s\n", _("Store cookies in the cookie jar and send them out when requested."));
printf ("\n");
printf (UT_WARN_CRIT);
@@ -1994,7 +2014,8 @@ print_usage (void)
printf (" [-P string] [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>]\n");
printf (" [-A string] [-k string] [-S <version>] [--sni]\n");
printf (" [-T <content-type>] [-j method]\n");
- printf (" [--http-version=<version>]\n");
+ printf (" [--http-version=<version>] [--enable-automatic-decompression]\n");
+ printf (" [--cookie-jar=<cookie jar file>\n");
printf (" %s -H <vhost> | -I <IP-address> -C <warn_age>[,<crit_age>]\n",progname);
printf (" [-p <port>] [-t <timeout>] [-4|-6] [--sni]\n");
printf ("\n");
From 40da85e6913ba4898f5a80772c7b3ea0cba0d3eb Mon Sep 17 00:00:00 2001
From: Andreas Baumann <mail@andreasbaumann.cc>
Date: Sun, 12 Feb 2023 12:11:38 +0100
Subject: [PATCH 4/7] better cleanup of curl structures and buffers
---
plugins/check_curl.c | 31 ++++++++++++++++++++-----------
1 file changed, 20 insertions(+), 11 deletions(-)
diff --git a/plugins/check_curl.c b/plugins/check_curl.c
index 35d1237b8..a49cac8a3 100644
--- a/plugins/check_curl.c
+++ b/plugins/check_curl.c
@@ -161,9 +161,13 @@ char *http_post_data = NULL;
char *http_content_type = NULL;
CURL *curl;
struct curl_slist *header_list = NULL;
+int body_buf_initialized = 0;
curlhelp_write_curlbuf body_buf;
+int header_buf_initialized = 0;
curlhelp_write_curlbuf header_buf;
+int status_line_initialized = 0;
curlhelp_statusline status_line;
+int put_buf_initialized = 0;
curlhelp_read_curlbuf put_buf;
char http_header[DEFAULT_BUFFER_SIZE];
long code;
@@ -416,14 +420,12 @@ lookup_host (const char *host, char *buf, size_t buflen)
static void
cleanup (void)
{
- curlhelp_free_statusline(&status_line);
+ if (status_line_initialized) curlhelp_free_statusline(&status_line);
curl_easy_cleanup (curl);
curl_global_cleanup ();
- curlhelp_freewritebuffer (&body_buf);
- curlhelp_freewritebuffer (&header_buf);
- if (!strcmp (http_method, "PUT")) {
- curlhelp_freereadbuffer (&put_buf);
- }
+ if (body_buf_initialized) curlhelp_freewritebuffer (&body_buf);
+ if (header_buf_initialized) curlhelp_freewritebuffer (&header_buf);
+ if (put_buf_initialized) curlhelp_freereadbuffer (&put_buf);
}
int
@@ -441,9 +443,14 @@ check_http (void)
if (curl_global_init (CURL_GLOBAL_DEFAULT) != CURLE_OK)
die (STATE_UNKNOWN, "HTTP UNKNOWN - curl_global_init failed\n");
- if ((curl = curl_easy_init()) == NULL)
+ if ((curl = curl_easy_init()) == NULL) {
+ curl_global_cleanup ();
die (STATE_UNKNOWN, "HTTP UNKNOWN - curl_easy_init failed\n");
+ }
+ /* register cleanup function to shut down libcurl properly */
+ atexit (cleanup);
+
if (verbose >= 1)
handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_VERBOSE, TRUE), "CURLOPT_VERBOSE");
@@ -460,12 +467,14 @@ check_http (void)
/* initialize buffer for body of the answer */
if (curlhelp_initwritebuffer(&body_buf) < 0)
die (STATE_UNKNOWN, "HTTP CRITICAL - out of memory allocating buffer for body\n");
+ body_buf_initialized = 1;
handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, (curl_write_callback)curlhelp_buffer_write_callback), "CURLOPT_WRITEFUNCTION");
handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_WRITEDATA, (void *)&body_buf), "CURLOPT_WRITEDATA");
/* initialize buffer for header of the answer */
if (curlhelp_initwritebuffer( &header_buf ) < 0)
die (STATE_UNKNOWN, "HTTP CRITICAL - out of memory allocating buffer for header\n" );
+ header_buf_initialized = 1;
handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_HEADERFUNCTION, (curl_write_callback)curlhelp_buffer_write_callback), "CURLOPT_HEADERFUNCTION");
handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_WRITEHEADER, (void *)&header_buf), "CURLOPT_WRITEHEADER");
@@ -752,7 +761,9 @@ check_http (void)
handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_POSTFIELDS, http_post_data), "CURLOPT_POSTFIELDS");
} else if (!strcmp(http_method, "PUT")) {
handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_READFUNCTION, (curl_read_callback)curlhelp_buffer_read_callback), "CURLOPT_READFUNCTION");
- curlhelp_initreadbuffer (&put_buf, http_post_data, strlen (http_post_data));
+ if (curlhelp_initreadbuffer (&put_buf, http_post_data, strlen (http_post_data)) < 0)
+ die (STATE_UNKNOWN, "HTTP CRITICAL - out of memory allocating read buffer for PUT\n");
+ put_buf_initialized = 1;
handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_READDATA, (void *)&put_buf), "CURLOPT_READDATA");
handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_INFILESIZE, (curl_off_t)strlen (http_post_data)), "CURLOPT_INFILESIZE");
}
@@ -764,9 +775,6 @@ check_http (void)
handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_COOKIEFILE, cookie_jar_file), "CURLOPT_COOKIEFILE");
}
- /* register cleanup function to shut down libcurl properly */
- atexit (cleanup);
-
/* do the request */
res = curl_easy_perform(curl);
@@ -2159,6 +2167,7 @@ curlhelp_parse_statusline (const char *buf, curlhelp_statusline *status_line)
first_line_len = (size_t)(first_line_end - buf);
status_line->first_line = (char *)malloc (first_line_len + 1);
+ status_line_initialized = 1;
if (status_line->first_line == NULL) return -1;
memcpy (status_line->first_line, buf, first_line_len);
status_line->first_line[first_line_len] = '\0';
From 6563267c3ad84bcc4779d282b5ae20520a4a2a6b Mon Sep 17 00:00:00 2001
From: Andreas Baumann <mail@andreasbaumann.cc>
Date: Sun, 12 Feb 2023 13:16:25 +0100
Subject: [PATCH 5/7] fixed double frees when doing old-style redirects
---
plugins/check_curl.c | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/plugins/check_curl.c b/plugins/check_curl.c
index a49cac8a3..1127d6019 100644
--- a/plugins/check_curl.c
+++ b/plugins/check_curl.c
@@ -160,6 +160,8 @@ char *http_method = NULL;
char *http_post_data = NULL;
char *http_content_type = NULL;
CURL *curl;
+int curl_global_initialized = 0;
+int curl_easy_initialized = 0;
struct curl_slist *header_list = NULL;
int body_buf_initialized = 0;
curlhelp_write_curlbuf body_buf;
@@ -421,11 +423,17 @@ static void
cleanup (void)
{
if (status_line_initialized) curlhelp_free_statusline(&status_line);
- curl_easy_cleanup (curl);
- curl_global_cleanup ();
+ status_line_initialized = 0;
+ if (curl_easy_initialized) curl_easy_cleanup (curl);
+ curl_easy_initialized = 0;
+ if (curl_global_initialized) curl_global_cleanup ();
+ curl_global_initialized = 0;
if (body_buf_initialized) curlhelp_freewritebuffer (&body_buf);
+ body_buf_initialized = 0;
if (header_buf_initialized) curlhelp_freewritebuffer (&header_buf);
+ header_buf_initialized = 0;
if (put_buf_initialized) curlhelp_freereadbuffer (&put_buf);
+ put_buf_initialized = 0;
}
int
@@ -442,11 +450,12 @@ check_http (void)
/* initialize curl */
if (curl_global_init (CURL_GLOBAL_DEFAULT) != CURLE_OK)
die (STATE_UNKNOWN, "HTTP UNKNOWN - curl_global_init failed\n");
+ curl_global_initialized = 1;
if ((curl = curl_easy_init()) == NULL) {
- curl_global_cleanup ();
die (STATE_UNKNOWN, "HTTP UNKNOWN - curl_easy_init failed\n");
}
+ curl_easy_initialized = 1;
/* register cleanup function to shut down libcurl properly */
atexit (cleanup);
@@ -903,6 +912,7 @@ check_http (void)
/* we cannot know the major/minor version here for sure as we cannot parse the first line */
die (STATE_CRITICAL, "HTTP CRITICAL HTTP/x.x %ld unknown - %s", code, msg);
}
+ status_line_initialized = 1;
/* get result code from cURL */
handle_curl_option_return_code (curl_easy_getinfo (curl, CURLINFO_RESPONSE_CODE, &code), "CURLINFO_RESPONSE_CODE");
@@ -1234,6 +1244,7 @@ redir (curlhelp_write_curlbuf* header_buf)
* attached to the URL in Location
*/
+ cleanup ();
check_http ();
}
@@ -2167,7 +2178,6 @@ curlhelp_parse_statusline (const char *buf, curlhelp_statusline *status_line)
first_line_len = (size_t)(first_line_end - buf);
status_line->first_line = (char *)malloc (first_line_len + 1);
- status_line_initialized = 1;
if (status_line->first_line == NULL) return -1;
memcpy (status_line->first_line, buf, first_line_len);
status_line->first_line[first_line_len] = '\0';
From 8e1bbf5e6ed4069d4256bf549a408bb8759861fa Mon Sep 17 00:00:00 2001
From: Andreas Baumann <mail@andreasbaumann.cc>
Date: Sun, 12 Feb 2023 15:09:02 +0100
Subject: [PATCH 6/7] changed #else/#if to #elif in libcurl library checks
---
plugins/check_curl.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/plugins/check_curl.c b/plugins/check_curl.c
index 1127d6019..284cf4eab 100644
--- a/plugins/check_curl.c
+++ b/plugins/check_curl.c
@@ -722,11 +722,9 @@ check_http (void)
/* for now allow only http and https (we are a http(s) check plugin in the end) */
#if LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 85, 0)
handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_REDIR_PROTOCOLS_STR, "http,https"), "CURLOPT_REDIR_PROTOCOLS_STR");
-#else
-#if LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 19, 4)
+#elif LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 19, 4)
handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS), "CURLOPT_REDIRECT_PROTOCOLS");
-#endif /* LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 19, 4) */
-#endif /* LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 85, 4) */
+#endif
/* TODO: handle the following aspects of redirection, make them
* command line options too later:
From ad6b638acb420f4416b10cf52fdd6c75c3c8e6fa Mon Sep 17 00:00:00 2001
From: Andreas Baumann <mail@andreasbaumann.cc>
Date: Fri, 17 Feb 2023 14:03:55 +0100
Subject: [PATCH 7/7] using real boolean in check_curl
---
plugins/check_curl.c | 160 ++++++++++++++++++++++---------------------
1 file changed, 82 insertions(+), 78 deletions(-)
diff --git a/plugins/check_curl.c b/plugins/check_curl.c
index 284cf4eab..c37d45d91 100644
--- a/plugins/check_curl.c
+++ b/plugins/check_curl.c
@@ -37,6 +37,7 @@ const char *progname = "check_curl";
const char *copyright = "2006-2019";
const char *email = "devel@monitoring-plugins.org";
+#include <stdbool.h>
#include <ctype.h>
#include "common.h"
@@ -131,14 +132,14 @@ regmatch_t pmatch[REGS];
char regexp[MAX_RE_SIZE];
int cflags = REG_NOSUB | REG_EXTENDED | REG_NEWLINE;
int errcode;
-int invert_regex = 0;
+bool invert_regex = false;
char *server_address = NULL;
char *host_name = NULL;
char *server_url = 0;
char server_ip[DEFAULT_BUFFER_SIZE];
struct curl_slist *server_ips = NULL;
-int specify_port = FALSE;
+bool specify_port = false;
unsigned short server_port = HTTP_PORT;
unsigned short virtual_port = 0;
int host_name_length;
@@ -150,8 +151,8 @@ int days_till_exp_warn, days_till_exp_crit;
thresholds *thlds;
char user_agent[DEFAULT_BUFFER_SIZE];
int verbose = 0;
-int show_extended_perfdata = FALSE;
-int show_body = FALSE;
+bool show_extended_perfdata = false;
+bool show_body = false;
int min_page_len = 0;
int max_page_len = 0;
int redir_depth = 0;
@@ -160,16 +161,16 @@ char *http_method = NULL;
char *http_post_data = NULL;
char *http_content_type = NULL;
CURL *curl;
-int curl_global_initialized = 0;
-int curl_easy_initialized = 0;
+bool curl_global_initialized = false;
+bool curl_easy_initialized = false;
struct curl_slist *header_list = NULL;
-int body_buf_initialized = 0;
+bool body_buf_initialized = false;
curlhelp_write_curlbuf body_buf;
-int header_buf_initialized = 0;
+bool header_buf_initialized = false;
curlhelp_write_curlbuf header_buf;
-int status_line_initialized = 0;
+bool status_line_initialized = false;
curlhelp_statusline status_line;
-int put_buf_initialized = 0;
+bool put_buf_initialized = false;
curlhelp_read_curlbuf put_buf;
char http_header[DEFAULT_BUFFER_SIZE];
long code;
@@ -192,14 +193,14 @@ char user_auth[MAX_INPUT_BUFFER] = "";
char proxy_auth[MAX_INPUT_BUFFER] = "";
char **http_opt_headers;
int http_opt_headers_count = 0;
-int display_html = FALSE;
+bool display_html = false;
int onredirect = STATE_OK;
int followmethod = FOLLOW_HTTP_CURL;
int followsticky = STICKY_NONE;
-int use_ssl = FALSE;
-int use_sni = TRUE;
-int check_cert = FALSE;
-int continue_after_check_cert = FALSE;
+bool use_ssl = false;
+bool use_sni = true;
+bool check_cert = false;
+bool continue_after_check_cert = false;
typedef union {
struct curl_slist* to_info;
struct curl_certinfo* to_certinfo;
@@ -209,20 +210,20 @@ int ssl_version = CURL_SSLVERSION_DEFAULT;
char *client_cert = NULL;
char *client_privkey = NULL;
char *ca_cert = NULL;
-int verify_peer_and_host = FALSE;
-int is_openssl_callback = FALSE;
+bool verify_peer_and_host = false;
+bool is_openssl_callback = false;
#if defined(HAVE_SSL) && defined(USE_OPENSSL)
X509 *cert = NULL;
#endif /* defined(HAVE_SSL) && defined(USE_OPENSSL) */
-int no_body = FALSE;
+bool no_body = false;
int maximum_age = -1;
int address_family = AF_UNSPEC;
curlhelp_ssl_library ssl_library = CURLHELP_SSL_LIBRARY_UNKNOWN;
int curl_http_version = CURL_HTTP_VERSION_NONE;
-int automatic_decompression = FALSE;
+bool automatic_decompression = false;
char *cookie_jar_file = NULL;
-int process_arguments (int, char**);
+bool process_arguments (int, char**);
void handle_curl_option_return_code (CURLcode res, const char* option);
int check_http (void);
void redir (curlhelp_write_curlbuf*);
@@ -276,10 +277,10 @@ main (int argc, char **argv)
progname, NP_VERSION, VERSION, curl_version());
/* parse arguments */
- if (process_arguments (argc, argv) == ERROR)
+ if (process_arguments (argc, argv) == false)
usage4 (_("Could not parse arguments"));
- if (display_html == TRUE)
+ if (display_html)
printf ("<A HREF=\"%s://%s:%d%s\" target=\"_blank\">",
use_ssl ? "https" : "http",
host_name ? host_name : server_address,
@@ -423,17 +424,17 @@ static void
cleanup (void)
{
if (status_line_initialized) curlhelp_free_statusline(&status_line);
- status_line_initialized = 0;
+ status_line_initialized = false;
if (curl_easy_initialized) curl_easy_cleanup (curl);
- curl_easy_initialized = 0;
+ curl_easy_initialized = false;
if (curl_global_initialized) curl_global_cleanup ();
- curl_global_initialized = 0;
+ curl_global_initialized = false;
if (body_buf_initialized) curlhelp_freewritebuffer (&body_buf);
- body_buf_initialized = 0;
+ body_buf_initialized = false;
if (header_buf_initialized) curlhelp_freewritebuffer (&header_buf);
- header_buf_initialized = 0;
+ header_buf_initialized = false;
if (put_buf_initialized) curlhelp_freereadbuffer (&put_buf);
- put_buf_initialized = 0;
+ put_buf_initialized = false;
}
int
@@ -450,18 +451,18 @@ check_http (void)
/* initialize curl */
if (curl_global_init (CURL_GLOBAL_DEFAULT) != CURLE_OK)
die (STATE_UNKNOWN, "HTTP UNKNOWN - curl_global_init failed\n");
- curl_global_initialized = 1;
+ curl_global_initialized = true;
if ((curl = curl_easy_init()) == NULL) {
die (STATE_UNKNOWN, "HTTP UNKNOWN - curl_easy_init failed\n");
}
- curl_easy_initialized = 1;
+ curl_easy_initialized = true;
/* register cleanup function to shut down libcurl properly */
atexit (cleanup);
if (verbose >= 1)
- handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_VERBOSE, TRUE), "CURLOPT_VERBOSE");
+ handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_VERBOSE, 1), "CURLOPT_VERBOSE");
/* print everything on stdout like check_http would do */
handle_curl_option_return_code (curl_easy_setopt(curl, CURLOPT_STDERR, stdout), "CURLOPT_STDERR");
@@ -476,14 +477,14 @@ check_http (void)
/* initialize buffer for body of the answer */
if (curlhelp_initwritebuffer(&body_buf) < 0)
die (STATE_UNKNOWN, "HTTP CRITICAL - out of memory allocating buffer for body\n");
- body_buf_initialized = 1;
+ body_buf_initialized = true;
handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, (curl_write_callback)curlhelp_buffer_write_callback), "CURLOPT_WRITEFUNCTION");
handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_WRITEDATA, (void *)&body_buf), "CURLOPT_WRITEDATA");
/* initialize buffer for header of the answer */
if (curlhelp_initwritebuffer( &header_buf ) < 0)
die (STATE_UNKNOWN, "HTTP CRITICAL - out of memory allocating buffer for header\n" );
- header_buf_initialized = 1;
+ header_buf_initialized = true;
handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_HEADERFUNCTION, (curl_write_callback)curlhelp_buffer_write_callback), "CURLOPT_HEADERFUNCTION");
handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_WRITEHEADER, (void *)&header_buf), "CURLOPT_WRITEHEADER");
@@ -544,7 +545,7 @@ check_http (void)
/* disable body for HEAD request */
if (http_method && !strcmp (http_method, "HEAD" )) {
- no_body = TRUE;
+ no_body = true;
}
/* set HTTP protocol version */
@@ -641,7 +642,7 @@ check_http (void)
#ifdef USE_OPENSSL
/* libcurl and monitoring plugins built with OpenSSL, good */
handle_curl_option_return_code (curl_easy_setopt(curl, CURLOPT_SSL_CTX_FUNCTION, sslctxfun), "CURLOPT_SSL_CTX_FUNCTION");
- is_openssl_callback = TRUE;
+ is_openssl_callback = true;
#else /* USE_OPENSSL */
#endif /* USE_OPENSSL */
/* libcurl is built with OpenSSL, monitoring plugins, so falling
@@ -770,7 +771,7 @@ check_http (void)
handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_READFUNCTION, (curl_read_callback)curlhelp_buffer_read_callback), "CURLOPT_READFUNCTION");
if (curlhelp_initreadbuffer (&put_buf, http_post_data, strlen (http_post_data)) < 0)
die (STATE_UNKNOWN, "HTTP CRITICAL - out of memory allocating read buffer for PUT\n");
- put_buf_initialized = 1;
+ put_buf_initialized = true;
handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_READDATA, (void *)&put_buf), "CURLOPT_READDATA");
handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_INFILESIZE, (curl_off_t)strlen (http_post_data)), "CURLOPT_INFILESIZE");
}
@@ -801,15 +802,15 @@ check_http (void)
/* certificate checks */
#ifdef LIBCURL_FEATURE_SSL
- if (use_ssl == TRUE) {
- if (check_cert == TRUE) {
+ if (use_ssl) {
+ if (check_cert) {
if (is_openssl_callback) {
#ifdef USE_OPENSSL
/* check certificate with OpenSSL functions, curl has been built against OpenSSL
* and we actually have OpenSSL in the monitoring tools
*/
result = np_net_ssl_check_certificate(cert, days_till_exp_warn, days_till_exp_crit);
- if (continue_after_check_cert == FALSE) {
+ if (!continue_after_check_cert) {
return result;
}
#else /* USE_OPENSSL */
@@ -851,7 +852,7 @@ check_http (void)
}
BIO_free (cert_BIO);
result = np_net_ssl_check_certificate(cert, days_till_exp_warn, days_till_exp_crit);
- if (continue_after_check_cert == FALSE) {
+ if (!continue_after_check_cert) {
return result;
}
#else /* USE_OPENSSL */
@@ -859,7 +860,7 @@ check_http (void)
* so we use the libcurl CURLINFO data
*/
result = net_noopenssl_check_certificate(&cert_ptr, days_till_exp_warn, days_till_exp_crit);
- if (continue_after_check_cert == FALSE) {
+ if (!continue_after_check_cert) {
return result;
}
#endif /* USE_OPENSSL */
@@ -887,7 +888,7 @@ check_http (void)
perfd_time(total_time),
perfd_size(page_len),
perfd_time_connect(time_connect),
- use_ssl == TRUE ? perfd_time_ssl (time_appconnect-time_connect) : "",
+ use_ssl ? perfd_time_ssl (time_appconnect-time_connect) : "",
perfd_time_headers(time_headers - time_appconnect),
perfd_time_firstbyte(time_firstbyte - time_headers),
perfd_time_transfer(total_time-time_firstbyte)
@@ -910,7 +911,7 @@ check_http (void)
/* we cannot know the major/minor version here for sure as we cannot parse the first line */
die (STATE_CRITICAL, "HTTP CRITICAL HTTP/x.x %ld unknown - %s", code, msg);
}
- status_line_initialized = 1;
+ status_line_initialized = true;
/* get result code from cURL */
handle_curl_option_return_code (curl_easy_getinfo (curl, CURLINFO_RESPONSE_CODE, &code), "CURLINFO_RESPONSE_CODE");
@@ -1023,12 +1024,12 @@ check_http (void)
if (strlen (regexp)) {
errcode = regexec (&preg, body_buf.buf, REGS, pmatch, 0);
- if ((errcode == 0 && invert_regex == 0) || (errcode == REG_NOMATCH && invert_regex == 1)) {
+ if ((errcode == 0 && !invert_regex) || (errcode == REG_NOMATCH && invert_regex)) {
/* OK - No-op to avoid changing the logic around it */
result = max_state_alt(STATE_OK, result);
}
- else if ((errcode == REG_NOMATCH && invert_regex == 0) || (errcode == 0 && invert_regex == 1)) {
- if (invert_regex == 0)
+ else if ((errcode == REG_NOMATCH && !invert_regex) || (errcode == 0 && invert_regex)) {
+ if (!invert_regex)
snprintf (msg, DEFAULT_BUFFER_SIZE, _("%spattern not found, "), msg);
else
snprintf (msg, DEFAULT_BUFFER_SIZE, _("%spattern found, "), msg);
@@ -1167,7 +1168,10 @@ redir (curlhelp_write_curlbuf* header_buf)
}
}
- use_ssl = !uri_strcmp (uri.scheme, "https");
+ if (!uri_strcmp (uri.scheme, "https"))
+ use_ssl = true;
+ else
+ use_ssl = false;
/* we do a sloppy test here only, because uriparser would have failed
* above, if the port would be invalid, we just check for MAX_PORT
@@ -1255,7 +1259,7 @@ test_file (char *path)
usage2 (_("file does not exist or is not readable"), path);
}
-int
+bool
process_arguments (int argc, char **argv)
{
char *p;
@@ -1321,7 +1325,7 @@ process_arguments (int argc, char **argv)
};
if (argc < 2)
- return ERROR;
+ return false;
/* support check_http compatible arguments */
for (c = 1; c < argc; c++) {
@@ -1401,7 +1405,7 @@ process_arguments (int argc, char **argv)
if( strtol(optarg, NULL, 10) > MAX_PORT)
usage2 (_("Invalid port number, supplied port number is too big"), optarg);
server_port = (unsigned short)strtol(optarg, NULL, 10);
- specify_port = TRUE;
+ specify_port = true;
}
break;
case 'a': /* authorization info */
@@ -1435,10 +1439,10 @@ process_arguments (int argc, char **argv)
http_opt_headers[http_opt_headers_count - 1] = optarg;
break;
case 'L': /* show html link */
- display_html = TRUE;
+ display_html = true;
break;
case 'n': /* do not show html link */
- display_html = FALSE;
+ display_html = false;
break;
case 'C': /* Check SSL cert validity */
#ifdef LIBCURL_FEATURE_SSL
@@ -1459,12 +1463,12 @@ process_arguments (int argc, char **argv)
usage2 (_("Invalid certificate expiration period"), optarg);
days_till_exp_warn = atoi (optarg);
}
- check_cert = TRUE;
+ check_cert = true;
goto enable_ssl;
#endif
case CONTINUE_AFTER_CHECK_CERT: /* don't stop after the certificate is checked */
#ifdef HAVE_SSL
- continue_after_check_cert = TRUE;
+ continue_after_check_cert = true;
break;
#endif
case 'J': /* use client certificate */
@@ -1487,13 +1491,13 @@ process_arguments (int argc, char **argv)
#endif
#ifdef LIBCURL_FEATURE_SSL
case 'D': /* verify peer certificate & host */
- verify_peer_and_host = TRUE;
+ verify_peer_and_host = true;
break;
#endif
case 'S': /* use SSL */
#ifdef LIBCURL_FEATURE_SSL
enable_ssl:
- use_ssl = TRUE;
+ use_ssl = true;
/* ssl_version initialized to CURL_SSLVERSION_DEFAULT as a default.
* Only set if it's non-zero. This helps when we include multiple
* parameters, like -S and -C combinations */
@@ -1567,15 +1571,15 @@ process_arguments (int argc, char **argv)
#endif /* LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 54, 0) */
if (verbose >= 2)
printf(_("* Set SSL/TLS version to %d\n"), ssl_version);
- if (specify_port == FALSE)
+ if (!specify_port)
server_port = HTTPS_PORT;
break;
#else /* LIBCURL_FEATURE_SSL */
/* -C -J and -K fall through to here without SSL */
usage4 (_("Invalid option - SSL is not available"));
break;
- case SNI_OPTION: /* --sni is parsed, but ignored, the default is TRUE with libcurl */
- use_sni = TRUE;
+ case SNI_OPTION: /* --sni is parsed, but ignored, the default is true with libcurl */
+ use_sni = true;
break;
#endif /* LIBCURL_FEATURE_SSL */
case MAX_REDIRS_OPTION:
@@ -1636,11 +1640,11 @@ process_arguments (int argc, char **argv)
if (errcode != 0) {
(void) regerror (errcode, &preg, errbuf, MAX_INPUT_BUFFER);
printf (_("Could Not Compile Regular Expression: %s"), errbuf);
- return ERROR;
+ return false;
}
break;
case INVERT_REGEX:
- invert_regex = 1;
+ invert_regex = true;
break;
case '4':
address_family = AF_INET;
@@ -1675,7 +1679,7 @@ process_arguments (int argc, char **argv)
break;
}
case 'N': /* no-body */
- no_body = TRUE;
+ no_body = true;
break;
case 'M': /* max-age */
{
@@ -1698,10 +1702,10 @@ process_arguments (int argc, char **argv)
}
break;
case 'E': /* show extended perfdata */
- show_extended_perfdata = TRUE;
+ show_extended_perfdata = true;
break;
case 'B': /* print body content after status line */
- show_body = TRUE;
+ show_body = true;
break;
case HTTP_VERSION_OPTION:
curl_http_version = CURL_HTTP_VERSION_NONE;
@@ -1721,7 +1725,7 @@ process_arguments (int argc, char **argv)
}
break;
case AUTOMATIC_DECOMPRESSION:
- automatic_decompression = TRUE;
+ automatic_decompression = true;
break;
case COOKIE_JAR:
cookie_jar_file = optarg;
@@ -1765,52 +1769,52 @@ process_arguments (int argc, char **argv)
virtual_port = server_port;
else {
if ((use_ssl && server_port == HTTPS_PORT) || (!use_ssl && server_port == HTTP_PORT))
- if(specify_port == FALSE)
+ if(!specify_port)
server_port = virtual_port;
}
- return TRUE;
+ return true;
}
char *perfd_time (double elapsed_time)
{
return fperfdata ("time", elapsed_time, "s",
- thlds->warning?TRUE:FALSE, thlds->warning?thlds->warning->end:0,
- thlds->critical?TRUE:FALSE, thlds->critical?thlds->critical->end:0,
- TRUE, 0, TRUE, socket_timeout);
+ thlds->warning?true:false, thlds->warning?thlds->warning->end:0,
+ thlds->critical?true:false, thlds->critical?thlds->critical->end:0,
+ true, 0, true, socket_timeout);
}
char *perfd_time_connect (double elapsed_time_connect)
{
- return fperfdata ("time_connect", elapsed_time_connect, "s", FALSE, 0, FALSE, 0, FALSE, 0, TRUE, socket_timeout);
+ return fperfdata ("time_connect", elapsed_time_connect, "s", false, 0, false, 0, false, 0, true, socket_timeout);
}
char *perfd_time_ssl (double elapsed_time_ssl)
{
- return fperfdata ("time_ssl", elapsed_time_ssl, "s", FALSE, 0, FALSE, 0, FALSE, 0, TRUE, socket_timeout);
+ return fperfdata ("time_ssl", elapsed_time_ssl, "s", false, 0, false, 0, false, 0, true, socket_timeout);
}
char *perfd_time_headers (double elapsed_time_headers)
{
- return fperfdata ("time_headers", elapsed_time_headers, "s", FALSE, 0, FALSE, 0, FALSE, 0, TRUE, socket_timeout);
+ return fperfdata ("time_headers", elapsed_time_headers, "s", false, 0, false, 0, false, 0, true, socket_timeout);
}
char *perfd_time_firstbyte (double elapsed_time_firstbyte)
{
- return fperfdata ("time_firstbyte", elapsed_time_firstbyte, "s", FALSE, 0, FALSE, 0, FALSE, 0, TRUE, socket_timeout);
+ return fperfdata ("time_firstbyte", elapsed_time_firstbyte, "s", false, 0, false, 0, false, 0, true, socket_timeout);
}
char *perfd_time_transfer (double elapsed_time_transfer)
{
- return fperfdata ("time_transfer", elapsed_time_transfer, "s", FALSE, 0, FALSE, 0, FALSE, 0, TRUE, socket_timeout);
+ return fperfdata ("time_transfer", elapsed_time_transfer, "s", false, 0, false, 0, false, 0, true, socket_timeout);
}
char *perfd_size (int page_len)
{
return perfdata ("size", page_len, "B",
- (min_page_len>0?TRUE:FALSE), min_page_len,
- (min_page_len>0?TRUE:FALSE), 0,
- TRUE, 0, FALSE, 0);
+ (min_page_len>0?true:false), min_page_len,
+ (min_page_len>0?true:false), 0,
+ true, 0, false, 0);
}
void

View file

@ -1,200 +0,0 @@
From 413af1955538b06803458c628099f1ba9da1966b Mon Sep 17 00:00:00 2001
From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com>
Date: Fri, 4 Nov 2022 16:51:32 +0100
Subject: [PATCH 1/5] Remove trailing whitespaces
---
plugins-root/check_icmp.c | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c
index f8f153512..abd88c4e7 100644
--- a/plugins-root/check_icmp.c
+++ b/plugins-root/check_icmp.c
@@ -1,39 +1,39 @@
/*****************************************************************************
-*
+*
* Monitoring check_icmp plugin
-*
+*
* License: GPL
* Copyright (c) 2005-2008 Monitoring Plugins Development Team
* Original Author : Andreas Ericsson <ae@op5.se>
-*
+*
* Description:
-*
+*
* This file contains the check_icmp plugin
-*
+*
* Relevant RFC's: 792 (ICMP), 791 (IP)
-*
+*
* This program was modeled somewhat after the check_icmp program,
* which was in turn a hack of fping (www.fping.org) but has been
* completely rewritten since to generate higher precision rta values,
* and support several different modes as well as setting ttl to control.
* redundant routes. The only remainders of fping is currently a few
* function names.
-*
-*
+*
+*
* 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 <http://www.gnu.org/licenses/>.
-*
-*
+*
+*
*****************************************************************************/
/* progname may change */
From 7d074091dba8c1d4081971bf62e694d0b1a03d41 Mon Sep 17 00:00:00 2001
From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com>
Date: Fri, 4 Nov 2022 16:53:57 +0100
Subject: [PATCH 2/5] Remove hardcoded DBL_MAX definition
---
plugins-root/check_icmp.c | 4 ----
1 file changed, 4 deletions(-)
diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c
index abd88c4e7..0d10d22db 100644
--- a/plugins-root/check_icmp.c
+++ b/plugins-root/check_icmp.c
@@ -95,10 +95,6 @@ const char *email = "devel@monitoring-plugins.org";
# define ICMP_UNREACH_PRECEDENCE_CUTOFF 15
#endif
-#ifndef DBL_MAX
-# define DBL_MAX 9.9999999999e999
-#endif
-
typedef unsigned short range_t; /* type for get_range() -- unimplemented */
typedef struct rta_host {
From 9a73a94258689cd9337fe7a7937fe85e4670aaeb Mon Sep 17 00:00:00 2001
From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com>
Date: Fri, 4 Nov 2022 17:08:36 +0100
Subject: [PATCH 3/5] Replace DBL_MAX with INFITY to check if value was set
---
plugins-root/check_icmp.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c
index 0d10d22db..7f3c4b5ba 100644
--- a/plugins-root/check_icmp.c
+++ b/plugins-root/check_icmp.c
@@ -55,6 +55,7 @@ const char *email = "devel@monitoring-plugins.org";
#include <errno.h>
#include <signal.h>
#include <ctype.h>
+#include <float.h>
#include <net/if.h>
#include <netinet/in_systm.h>
#include <netinet/in.h>
@@ -1220,7 +1221,7 @@ finish(int sig)
host->rta / 1000, (float)warn.rta / 1000, (float)crit.rta / 1000,
(targets > 1) ? host->name : "", host->pl, warn.pl, crit.pl,
(targets > 1) ? host->name : "", (float)host->rtmax / 1000,
- (targets > 1) ? host->name : "", (host->rtmin < DBL_MAX) ? (float)host->rtmin / 1000 : (float)0);
+ (targets > 1) ? host->name : "", (host->rtmin < INFINITY) ? (float)host->rtmin / 1000 : (float)0);
host = host->next;
}
@@ -1323,7 +1324,7 @@ add_target_ip(char *arg, struct sockaddr_storage *in)
memcpy(host_sin6->sin6_addr.s6_addr, sin6->sin6_addr.s6_addr, sizeof host_sin6->sin6_addr.s6_addr);
}
- host->rtmin = DBL_MAX;
+ host->rtmin = INFINITY;
if(!list) list = cursor = host;
else cursor->next = host;
From d3a4bad51d72a3c5bcc06ceb5e0a823dcc24bf49 Mon Sep 17 00:00:00 2001
From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com>
Date: Sun, 19 Feb 2023 14:31:21 +0100
Subject: [PATCH 4/5] check_icmp: Fix compiler warning
This fixes a compiler warning with no real world impact.
The compiler complains about a missing return, which is correct, but
in that scenario the program would crash anyways, so this has no impact.
---
plugins-root/check_icmp.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c
index 7f3c4b5ba..317cd5357 100644
--- a/plugins-root/check_icmp.c
+++ b/plugins-root/check_icmp.c
@@ -1430,20 +1430,21 @@ set_source_ip(char *arg)
static in_addr_t
get_ip_address(const char *ifname)
{
+ // TODO: Rewrite this so the function return an error and we exit somewhere else
+ struct sockaddr_in ip;
#if defined(SIOCGIFADDR)
struct ifreq ifr;
- struct sockaddr_in ip;
strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name) - 1);
ifr.ifr_name[sizeof(ifr.ifr_name) - 1] = '\0';
if(ioctl(icmp_sock, SIOCGIFADDR, &ifr) == -1)
crash("Cannot determine IP address of interface %s", ifname);
memcpy(&ip, &ifr.ifr_addr, sizeof(ip));
- return ip.sin_addr.s_addr;
#else
errno = 0;
crash("Cannot get interface IP address on this platform.");
#endif
+ return ip.sin_addr.s_addr;
}
/*
From 423284edfa980fc3fdb51ab20af96685a988ba97 Mon Sep 17 00:00:00 2001
From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com>
Date: Sun, 19 Feb 2023 14:34:29 +0100
Subject: [PATCH 5/5] check_icmp: Fix compiler warning
This fixes a compiler warning which complains about an uninitialized
value for a variable which is then returned.
This had no real world impact, since the program would crash in the
branch where result is not set.
The variable is initialized to "-1" which would be the error for
inet_pton.
---
plugins-root/check_icmp.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c
index 317cd5357..e59e92d33 100644
--- a/plugins-root/check_icmp.c
+++ b/plugins-root/check_icmp.c
@@ -1339,7 +1339,7 @@ add_target_ip(char *arg, struct sockaddr_storage *in)
static int
add_target(char *arg)
{
- int error, result;
+ int error, result = -1;
struct sockaddr_storage ip;
struct addrinfo hints, *res, *p;
struct sockaddr_in *sin;

View file

@ -1,211 +0,0 @@
From 03f86b5d0809967855fbaafb4d600dc5b82081fa Mon Sep 17 00:00:00 2001
From: Andreas Baumann <mail@andreasbaumann.cc>
Date: Tue, 7 Mar 2023 19:51:33 +0100
Subject: [PATCH 1/4] check_curl: in SSL host caching mode try to connect and
bind and take the first getaddrinfo result which succeeds
---
plugins/check_curl.c | 22 +++++++++++++++-------
1 file changed, 15 insertions(+), 7 deletions(-)
diff --git a/plugins/check_curl.c b/plugins/check_curl.c
index c37d45d91..e1bc98dc9 100644
--- a/plugins/check_curl.c
+++ b/plugins/check_curl.c
@@ -386,6 +386,7 @@ lookup_host (const char *host, char *buf, size_t buflen)
struct addrinfo hints, *res, *result;
int errcode;
void *ptr;
+ int s;
memset (&hints, 0, sizeof (hints));
hints.ai_family = address_family;
@@ -399,19 +400,26 @@ lookup_host (const char *host, char *buf, size_t buflen)
res = result;
while (res) {
- inet_ntop (res->ai_family, res->ai_addr->sa_data, buf, buflen);
- switch (res->ai_family) {
- case AF_INET:
- ptr = &((struct sockaddr_in *) res->ai_addr)->sin_addr;
+ inet_ntop (res->ai_family, res->ai_addr->sa_data, buf, buflen);
+ switch (res->ai_family) {
+ case AF_INET:
+ ptr = &((struct sockaddr_in *) res->ai_addr)->sin_addr;
+ break;
+ case AF_INET6:
+ ptr = &((struct sockaddr_in6 *) res->ai_addr)->sin6_addr;
break;
- case AF_INET6:
- ptr = &((struct sockaddr_in6 *) res->ai_addr)->sin6_addr;
- break;
}
+
inet_ntop (res->ai_family, ptr, buf, buflen);
if (verbose >= 1)
printf ("* getaddrinfo IPv%d address: %s\n",
res->ai_family == PF_INET6 ? 6 : 4, buf);
+
+ if (s = socket (res->ai_family, res->ai_socktype, res->ai_protocol) == -1)
+ continue;
+ if (bind (s, res->ai_addr, res->ai_addrlen == 0) )
+ break;
+
res = res->ai_next;
}
From 2902381c5de01f69d61569b0c8dae6a92e2b9843 Mon Sep 17 00:00:00 2001
From: Barak Shohat <barak@bazzisoft.com>
Date: Wed, 8 Mar 2023 11:56:43 +0200
Subject: [PATCH 2/4] check_curl.c: Include all IPs from getaddrinfo() in curl
DNS cache
---
plugins/check_curl.c | 39 ++++++++++++++++++++++++++-------------
1 file changed, 26 insertions(+), 13 deletions(-)
diff --git a/plugins/check_curl.c b/plugins/check_curl.c
index e1bc98dc9..512fb88a6 100644
--- a/plugins/check_curl.c
+++ b/plugins/check_curl.c
@@ -384,9 +384,12 @@ int
lookup_host (const char *host, char *buf, size_t buflen)
{
struct addrinfo hints, *res, *result;
+ char addrstr[100];
+ size_t addrstr_len;
int errcode;
void *ptr;
int s;
+ size_t buflen_remaining = buflen - 1;
memset (&hints, 0, sizeof (hints));
hints.ai_family = address_family;
@@ -396,33 +399,40 @@ lookup_host (const char *host, char *buf, size_t buflen)
errcode = getaddrinfo (host, NULL, &hints, &result);
if (errcode != 0)
return errcode;
-
+
+ strcpy(buf, "");
res = result;
while (res) {
- inet_ntop (res->ai_family, res->ai_addr->sa_data, buf, buflen);
switch (res->ai_family) {
case AF_INET:
ptr = &((struct sockaddr_in *) res->ai_addr)->sin_addr;
break;
case AF_INET6:
ptr = &((struct sockaddr_in6 *) res->ai_addr)->sin6_addr;
- break;
+ break;
}
- inet_ntop (res->ai_family, ptr, buf, buflen);
- if (verbose >= 1)
+ inet_ntop (res->ai_family, ptr, addrstr, 100);
+ if (verbose >= 1) {
printf ("* getaddrinfo IPv%d address: %s\n",
- res->ai_family == PF_INET6 ? 6 : 4, buf);
+ res->ai_family == PF_INET6 ? 6 : 4, addrstr);
+ }
- if (s = socket (res->ai_family, res->ai_socktype, res->ai_protocol) == -1)
- continue;
- if (bind (s, res->ai_addr, res->ai_addrlen == 0) )
- break;
+ // Append all IPs to buf as a comma-separated string
+ addrstr_len = strlen(addrstr);
+ if (buflen_remaining > addrstr_len + 1) {
+ if (buf[0] != NULL) {
+ strncat(buf, ",", 1);
+ buflen_remaining -= 1;
+ }
+ strncat(buf, addrstr, buflen_remaining);
+ buflen_remaining -= addrstr_len;
+ }
res = res->ai_next;
}
-
+
freeaddrinfo(result);
return 0;
@@ -453,7 +463,7 @@ check_http (void)
int i;
char *force_host_header = NULL;
struct curl_slist *host = NULL;
- char addrstr[100];
+ char addrstr[DEFAULT_BUFFER_SIZE/2];
char dnscache[DEFAULT_BUFFER_SIZE];
/* initialize curl */
@@ -505,7 +515,7 @@ check_http (void)
// fill dns resolve cache to make curl connect to the given server_address instead of the host_name, only required for ssl, because we use the host_name later on to make SNI happy
if(use_ssl && host_name != NULL) {
- if ( (res=lookup_host (server_address, addrstr, 100)) != 0) {
+ if ( (res=lookup_host (server_address, addrstr, DEFAULT_BUFFER_SIZE/2)) != 0) {
snprintf (msg, DEFAULT_BUFFER_SIZE, _("Unable to lookup IP address for '%s': getaddrinfo returned %d - %s"),
server_address, res, gai_strerror (res));
die (STATE_CRITICAL, "HTTP CRITICAL - %s\n", msg);
@@ -800,6 +810,9 @@ check_http (void)
/* free header and server IP resolve lists, we don't need it anymore */
curl_slist_free_all (header_list); header_list = NULL;
curl_slist_free_all (server_ips); server_ips = NULL;
+ if (host) {
+ curl_slist_free_all (host); host = NULL;
+ }
/* Curl errors, result in critical Nagios state */
if (res != CURLE_OK) {
From fc927e98db73850e760f490117ed36f2de20270c Mon Sep 17 00:00:00 2001
From: Andreas Baumann <mail@andreasbaumann.cc>
Date: Wed, 8 Mar 2023 16:10:45 +0100
Subject: [PATCH 3/4] fixed a wrong compare and a wrong size in strncat
---
plugins/check_curl.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/plugins/check_curl.c b/plugins/check_curl.c
index 512fb88a6..cc17ef58a 100644
--- a/plugins/check_curl.c
+++ b/plugins/check_curl.c
@@ -422,8 +422,8 @@ lookup_host (const char *host, char *buf, size_t buflen)
// Append all IPs to buf as a comma-separated string
addrstr_len = strlen(addrstr);
if (buflen_remaining > addrstr_len + 1) {
- if (buf[0] != NULL) {
- strncat(buf, ",", 1);
+ if (buf[0] != '\0') {
+ strncat(buf, ",", buflen_remaining);
buflen_remaining -= 1;
}
strncat(buf, addrstr, buflen_remaining);
From ea53555f2d6254da5fec0c1061899a01dd5321ec Mon Sep 17 00:00:00 2001
From: Andreas Baumann <mail@andreasbaumann.cc>
Date: Sat, 11 Mar 2023 11:40:00 +0100
Subject: [PATCH 4/4] check_curl: removed a superflous variable
---
plugins/check_curl.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/plugins/check_curl.c b/plugins/check_curl.c
index cc17ef58a..e5be1ad56 100644
--- a/plugins/check_curl.c
+++ b/plugins/check_curl.c
@@ -388,7 +388,6 @@ lookup_host (const char *host, char *buf, size_t buflen)
size_t addrstr_len;
int errcode;
void *ptr;
- int s;
size_t buflen_remaining = buflen - 1;
memset (&hints, 0, sizeof (hints));

View file

@ -1,23 +0,0 @@
From 8a8ee58e8925019b7532e7d14ebe488bb21fb3e6 Mon Sep 17 00:00:00 2001
From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com>
Date: Thu, 16 Mar 2023 15:26:52 +0100
Subject: [PATCH] check_swap: Remove unnecessary and problematic includes
---
plugins/check_swap.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/plugins/check_swap.c b/plugins/check_swap.c
index a607da1e9..25d5f21d0 100644
--- a/plugins/check_swap.c
+++ b/plugins/check_swap.c
@@ -34,9 +34,6 @@ const char *email = "devel@monitoring-plugins.org";
#include "common.h"
#include "popen.h"
#include "utils.h"
-#include <string.h>
-#include <math.h>
-#include <libintl.h>
#ifdef HAVE_DECL_SWAPCTL
# ifdef HAVE_SYS_PARAM_H

View file

@ -1,90 +0,0 @@
From c874f950e8e5b6a805d8adf759d521501b22c7ce Mon Sep 17 00:00:00 2001
From: Sven Nierlein <Sven.Nierlein@consol.de>
Date: Wed, 15 Mar 2023 09:51:18 +0100
Subject: [PATCH 1/2] check_snmp: disable multiplier when unused
- if no multiplier is set, simply return the given string. Otherwise we would strip off the unit.
- if used, allocate new space to hold the result which might be larger than the initial input
Signed-off-by: Sven Nierlein <sven@consol.de>
---
plugins/check_snmp.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c
index d3968a27d..c4ddd0edd 100644
--- a/plugins/check_snmp.c
+++ b/plugins/check_snmp.c
@@ -46,6 +46,7 @@ const char *email = "devel@monitoring-plugins.org";
#define DEFAULT_PRIV_PROTOCOL "DES"
#define DEFAULT_DELIMITER "="
#define DEFAULT_OUTPUT_DELIMITER " "
+#define DEFAULT_BUFFER_SIZE 100
#define mark(a) ((a)!=0?"*":"")
@@ -157,6 +158,7 @@ int perf_labels = 1;
char* ip_version = "";
double multiplier = 1.0;
char *fmtstr = "";
+char buffer[DEFAULT_BUFFER_SIZE];
static char *fix_snmp_range(char *th)
{
@@ -1169,6 +1171,9 @@ multiply (char *str)
double val;
char *conv = "%f";
+ if(multiplier == 1)
+ return(str);
+
if(verbose>2)
printf(" multiply input: %s\n", str);
@@ -1187,15 +1192,15 @@ multiply (char *str)
conv = fmtstr;
}
if (val == (int)val) {
- sprintf(str, "%.0f", val);
+ snprintf(buffer, DEFAULT_BUFFER_SIZE, "%.0f", val);
} else {
if(verbose>2)
printf(" multiply using format: %s\n", conv);
- sprintf(str, conv, val);
+ snprintf(buffer, DEFAULT_BUFFER_SIZE, conv, val);
}
if(verbose>2)
- printf(" multiply result: %s\n", str);
- return str;
+ printf(" multiply result: %s\n", buffer);
+ return buffer;
}
From 6e64973a4486248ff6c3de7d72637e44b6474c3e Mon Sep 17 00:00:00 2001
From: Sven Nierlein <sven@consol.de>
Date: Mon, 27 Mar 2023 12:59:53 +0200
Subject: [PATCH 2/2] simplify code
if statement is always true at this point, so remove it.
---
plugins/check_snmp.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c
index c4ddd0edd..aefda3d29 100644
--- a/plugins/check_snmp.c
+++ b/plugins/check_snmp.c
@@ -1179,10 +1179,7 @@ multiply (char *str)
val = strtod (str, &endptr);
if ((val == 0.0) && (endptr == str)) {
- if(multiplier != 1) {
- die(STATE_UNKNOWN, _("multiplier set (%.1f), but input is not a number: %s"), multiplier, str);
- }
- return str;
+ die(STATE_UNKNOWN, _("multiplier set (%.1f), but input is not a number: %s"), multiplier, str);
}
if(verbose>2)

View file

@ -1,166 +0,0 @@
From 5af4db7b4169acee20bfa2d637ce3f3eb5bdef47 Mon Sep 17 00:00:00 2001
From: MisterMountain <bjoern.berg@netways.de>
Date: Tue, 11 Apr 2023 16:26:12 +0200
Subject: [PATCH 1/3] fixed the outputs of the --versions options on 3 scripts
---
plugins-scripts/check_log.sh | 2 +-
plugins-scripts/check_oracle.sh | 2 +-
plugins-scripts/check_sensors.sh | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/plugins-scripts/check_log.sh b/plugins-scripts/check_log.sh
index c623a8d6b..10c56f14b 100755
--- a/plugins-scripts/check_log.sh
+++ b/plugins-scripts/check_log.sh
@@ -109,7 +109,7 @@ while test -n "$1"; do
;;
-V | --version)
print_revision "$PROGNAME" "$REVISION"
- exit "$STATE_OK"
+ exit "$STATE_UNKNOWN"
;;
-F | --filename)
logfile=$2
diff --git a/plugins-scripts/check_oracle.sh b/plugins-scripts/check_oracle.sh
index b14ec50ed..f340b97c4 100755
--- a/plugins-scripts/check_oracle.sh
+++ b/plugins-scripts/check_oracle.sh
@@ -95,7 +95,7 @@ case "$cmd" in
;;
--version)
print_revision "$PROGNAME" "$REVISION"
- exit "$STATE_OK"
+ exit "$STATE_UNKNOWN"
;;
-V)
print_revision "$PROGNAME" "$REVISION"
diff --git a/plugins-scripts/check_sensors.sh b/plugins-scripts/check_sensors.sh
index 921e7b365..3c4cf01bf 100755
--- a/plugins-scripts/check_sensors.sh
+++ b/plugins-scripts/check_sensors.sh
@@ -34,7 +34,7 @@ case "$1" in
;;
--version)
print_revision "$PROGNAME" "$REVISION"
- exit "$STATE_OK"
+ exit "$STATE_UNKNOWN"
;;
-V)
print_revision "$PROGNAME" "$REVISION"
From 3dc677e4f1f990e7b26bc714a02608070379cf85 Mon Sep 17 00:00:00 2001
From: MisterMountain <bjoern.berg@netways.de>
Date: Tue, 11 Apr 2023 17:11:06 +0200
Subject: [PATCH 2/3] fixed the identation (and also patched -V on check_oracle
to behave exactly like --version again)
---
plugins-scripts/check_oracle.sh | 10 +++++-----
plugins-scripts/check_sensors.sh | 2 +-
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/plugins-scripts/check_oracle.sh b/plugins-scripts/check_oracle.sh
index f340b97c4..d58cfbea3 100755
--- a/plugins-scripts/check_oracle.sh
+++ b/plugins-scripts/check_oracle.sh
@@ -86,20 +86,20 @@ esac
# Information options
case "$cmd" in
--help)
- print_help
+ print_help
exit "$STATE_OK"
;;
-h)
- print_help
+ print_help
exit "$STATE_OK"
;;
--version)
- print_revision "$PROGNAME" "$REVISION"
+ print_revision "$PROGNAME" "$REVISION"
exit "$STATE_UNKNOWN"
;;
-V)
- print_revision "$PROGNAME" "$REVISION"
- exit "$STATE_OK"
+ print_revision "$PROGNAME" "$REVISION"
+ exit "$STATE_UNKNOWN"
;;
esac
diff --git a/plugins-scripts/check_sensors.sh b/plugins-scripts/check_sensors.sh
index 3c4cf01bf..adbfc533f 100755
--- a/plugins-scripts/check_sensors.sh
+++ b/plugins-scripts/check_sensors.sh
@@ -38,7 +38,7 @@ case "$1" in
;;
-V)
print_revision "$PROGNAME" "$REVISION"
- exit "$STATE_OK"
+ exit "$STATE_UNKNOWN"
;;
*)
sensordata=$(sensors 2>&1)
From 21885d85d54ce2afe7b9bf962348dc60e31442e0 Mon Sep 17 00:00:00 2001
From: MisterMountain <bjoern.berg@netways.de>
Date: Tue, 2 May 2023 09:40:35 +0200
Subject: [PATCH 3/3] also fixed the --help returns
---
plugins-scripts/check_log.sh | 2 +-
plugins-scripts/check_oracle.sh | 4 ++--
plugins-scripts/check_sensors.sh | 4 ++--
3 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/plugins-scripts/check_log.sh b/plugins-scripts/check_log.sh
index 10c56f14b..8ecdd3164 100755
--- a/plugins-scripts/check_log.sh
+++ b/plugins-scripts/check_log.sh
@@ -105,7 +105,7 @@ while test -n "$1"; do
case "$1" in
-h | --help)
print_help
- exit "$STATE_OK"
+ exit "$STATE_UNKNOWN"
;;
-V | --version)
print_revision "$PROGNAME" "$REVISION"
diff --git a/plugins-scripts/check_oracle.sh b/plugins-scripts/check_oracle.sh
index d58cfbea3..599813865 100755
--- a/plugins-scripts/check_oracle.sh
+++ b/plugins-scripts/check_oracle.sh
@@ -87,11 +87,11 @@ esac
case "$cmd" in
--help)
print_help
- exit "$STATE_OK"
+ exit "$STATE_UNKNOWN"
;;
-h)
print_help
- exit "$STATE_OK"
+ exit "$STATE_UNKNOWN"
;;
--version)
print_revision "$PROGNAME" "$REVISION"
diff --git a/plugins-scripts/check_sensors.sh b/plugins-scripts/check_sensors.sh
index adbfc533f..866e0e0f0 100755
--- a/plugins-scripts/check_sensors.sh
+++ b/plugins-scripts/check_sensors.sh
@@ -26,11 +26,11 @@ print_help() {
case "$1" in
--help)
print_help
- exit "$STATE_OK"
+ exit "$STATE_UNKNOWN"
;;
-h)
print_help
- exit "$STATE_OK"
+ exit "$STATE_UNKNOWN"
;;
--version)
print_revision "$PROGNAME" "$REVISION"

View file

@ -1,22 +0,0 @@
From d10ee31d89c2c599ee4c502e82d632aef8554020 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lorenz=20K=C3=A4stle?= <lorenz.kaestle@netways.de>
Date: Fri, 28 Apr 2023 16:51:39 +0200
Subject: [PATCH] Typo in check_mysql
---
plugins/check_mysql.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/plugins/check_mysql.c b/plugins/check_mysql.c
index 0cba50e6d..6cfa70edb 100644
--- a/plugins/check_mysql.c
+++ b/plugins/check_mysql.c
@@ -551,7 +551,7 @@ print_help (void)
printf (" %s\n", _("Exit with CRITICAL status if slave server is more then INTEGER seconds"));
printf (" %s\n", _("behind master"));
printf (" %s\n", "-l, --ssl");
- printf (" %s\n", _("Use ssl encryptation"));
+ printf (" %s\n", _("Use ssl encryption"));
printf (" %s\n", "-C, --ca-cert=STRING");
printf (" %s\n", _("Path to CA signing the cert"));
printf (" %s\n", "-a, --cert=STRING");

View file

@ -1,64 +0,0 @@
From cc69e8f76bcde8f75b5828b920bb937682673f49 Mon Sep 17 00:00:00 2001
From: donien <matthias.doehler@netways.de>
Date: Thu, 13 Apr 2023 17:15:16 +0200
Subject: [PATCH] Fix 'requres' typo
---
plugins/check_nwstat.c | 2 +-
po/de.po | 2 +-
po/fr.po | 2 +-
po/monitoring-plugins.pot | 2 +-
4 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/plugins/check_nwstat.c b/plugins/check_nwstat.c
index e7e8de05b..3c9d23e2e 100644
--- a/plugins/check_nwstat.c
+++ b/plugins/check_nwstat.c
@@ -1668,7 +1668,7 @@ void print_help(void)
printf ("\n");
printf ("%s\n", _("Notes:"));
- printf (" %s\n", _("- This plugin requres that the MRTGEXT.NLM file from James Drews' MRTG"));
+ printf (" %s\n", _("- This plugin requires that the MRTGEXT.NLM file from James Drews' MRTG"));
printf (" %s\n", _(" extension for NetWare be loaded on the Novell servers you wish to check."));
printf (" %s\n", _(" (available from http://www.engr.wisc.edu/~drews/mrtg/)"));
printf (" %s\n", _("- Values for critical thresholds should be lower than warning thresholds"));
diff --git a/po/de.po b/po/de.po
index 919fae32b..c29cbbbac 100644
--- a/po/de.po
+++ b/po/de.po
@@ -3315,7 +3315,7 @@ msgid "Include server version string in results"
msgstr ""
#: plugins/check_nwstat.c:1671
-msgid "- This plugin requres that the MRTGEXT.NLM file from James Drews' MRTG"
+msgid "- This plugin requires that the MRTGEXT.NLM file from James Drews' MRTG"
msgstr ""
#: plugins/check_nwstat.c:1672
diff --git a/po/fr.po b/po/fr.po
index e44cf88cb..b4de17ed6 100644
--- a/po/fr.po
+++ b/po/fr.po
@@ -3372,7 +3372,7 @@ msgid "Include server version string in results"
msgstr ""
#: plugins/check_nwstat.c:1671
-msgid "- This plugin requres that the MRTGEXT.NLM file from James Drews' MRTG"
+msgid "- This plugin requires that the MRTGEXT.NLM file from James Drews' MRTG"
msgstr ""
#: plugins/check_nwstat.c:1672
diff --git a/po/monitoring-plugins.pot b/po/monitoring-plugins.pot
index 5bc236373..45f46a899 100644
--- a/po/monitoring-plugins.pot
+++ b/po/monitoring-plugins.pot
@@ -3225,7 +3225,7 @@ msgid "Include server version string in results"
msgstr ""
#: plugins/check_nwstat.c:1671
-msgid "- This plugin requres that the MRTGEXT.NLM file from James Drews' MRTG"
+msgid "- This plugin requires that the MRTGEXT.NLM file from James Drews' MRTG"
msgstr ""
#: plugins/check_nwstat.c:1672

View file

@ -1,46 +0,0 @@
From b2659391aba7e4a79b678aba5cc21b443626f81f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lorenz=20K=C3=A4stle?= <lorenz.kaestle@netways.de>
Date: Wed, 26 Apr 2023 10:13:51 +0200
Subject: [PATCH 1/2] check_nt: change encoding from latin1 to utf8
---
plugins/check_nt.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/plugins/check_nt.c b/plugins/check_nt.c
index 59c135dba..babe3b642 100644
--- a/plugins/check_nt.c
+++ b/plugins/check_nt.c
@@ -341,7 +341,7 @@ int main(int argc, char **argv){
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.
+ 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:
From fcf68d702e590bd3e58fb7556f420330ddf0a0ae Mon Sep 17 00:00:00 2001
From: Lorenz <12514511+RincewindsHat@users.noreply.github.com>
Date: Thu, 27 Apr 2023 00:42:30 +0200
Subject: [PATCH 2/2] Update plugins/check_nt.c
Co-authored-by: datamuc <m@rbfh.de>
---
plugins/check_nt.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/plugins/check_nt.c b/plugins/check_nt.c
index babe3b642..d73d83cea 100644
--- a/plugins/check_nt.c
+++ b/plugins/check_nt.c
@@ -341,7 +341,7 @@ int main(int argc, char **argv){
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.
+ 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:

View file

@ -1,46 +0,0 @@
From 9f15dac8e789a4b13d4f9e8897ee03fee84f494a Mon Sep 17 00:00:00 2001
From: phowen <phowen@cisco.com>
Date: Wed, 26 Apr 2017 13:40:27 +0100
Subject: [PATCH] add extra output to pgsql check
---
plugins/check_pgsql.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/plugins/check_pgsql.c b/plugins/check_pgsql.c
index c26cd439c..05fdc1568 100644
--- a/plugins/check_pgsql.c
+++ b/plugins/check_pgsql.c
@@ -517,7 +517,10 @@ print_help (void)
printf (" %s\n", _("connecting to the server. The result from the query has to be numeric."));
printf (" %s\n", _("Multiple SQL commands, separated by semicolon, are allowed but the result "));
printf (" %s\n", _("of the last command is taken into account only. The value of the first"));
- printf (" %s\n\n", _("column in the first row is used as the check result."));
+ printf (" %s\n", _("column in the first row is used as the check result. If a second column is"));
+ printf (" %s\n", _("present in the result set, this is added to the plugin output with a"));
+ printf (" %s\n", _("prefix of \"Extra Info:\". This information can be displayed in the system"));
+ printf (" %s\n\n", _("executing the plugin."));
printf (" %s\n", _("See the chapter \"Monitoring Database Activity\" of the PostgreSQL manual"));
printf (" %s\n\n", _("for details about how to access internal statistics of the database server."));
@@ -557,6 +560,7 @@ do_query (PGconn *conn, char *query)
PGresult *res;
char *val_str;
+ char *extra_info;
double value;
char *endptr = NULL;
@@ -621,6 +625,12 @@ do_query (PGconn *conn, char *query)
printf ("|query=%f;%s;%s;;\n", value,
query_warning ? query_warning : "",
query_critical ? query_critical : "");
+ if (PQnfields (res) > 1) {
+ extra_info = PQgetvalue (res, 0, 1);
+ if (extra_info != NULL) {
+ printf ("Extra Info: %s\n", extra_info);
+ }
+ }
return my_status;
}

View file

@ -1,47 +0,0 @@
From 0dd11100aa92bab172293ec9615a8a56b0e35ee6 Mon Sep 17 00:00:00 2001
From: Stefan Taferner <stefan.taferner@porscheinformatik.com>
Date: Wed, 10 May 2023 19:28:05 +0200
Subject: [PATCH] avoid mounting when searching for matching mount points
---
lib/utils_disk.c | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/lib/utils_disk.c b/lib/utils_disk.c
index 468769b19..582d3ea17 100644
--- a/lib/utils_disk.c
+++ b/lib/utils_disk.c
@@ -147,24 +147,25 @@ np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list
/* set best match if path name exactly matches a mounted device name */
for (me = mount_list; me; me = me->me_next) {
- if (get_fs_usage(me->me_mountdir, me->me_devname, &fsp) < 0)
- continue; /* skip if permissions do not suffice for accessing device */
- if (strcmp(me->me_devname, d->name)==0)
- best_match = me;
+ 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) {
- if (get_fs_usage(me->me_mountdir, me->me_devname, &fsp) < 0)
- continue; /* skip if permissions do not suffice for accessing device */
size_t len = strlen (me->me_mountdir);
if ((exact == FALSE && (best_match_len <= len && len <= name_len &&
(len == 1 || strncmp (me->me_mountdir, d->name, len) == 0)))
|| (exact == TRUE && strcmp(me->me_mountdir, d->name)==0))
{
- best_match = me;
- best_match_len = len;
+ if (get_fs_usage(me->me_mountdir, me->me_devname, &fsp) >= 0) {
+ best_match = me;
+ best_match_len = len;
+ }
}
}
}

View file

@ -1,28 +0,0 @@
From 10863265324a9a9fdf8ce771271af15b7e2f5a4a Mon Sep 17 00:00:00 2001
From: Platon Pronko <platon7pronko@gmail.com>
Date: Fri, 19 May 2023 15:05:02 +0800
Subject: [PATCH] check_mysql: handle ER_ACCESS_DENIED_NO_PASSWORD_ERROR if
ignore_auth=1
In some situations MySQL might return ER_ACCESS_DENIED_NO_PASSWORD_ERROR
instead of ER_ACCESS_DENIED_ERROR. Semantically these errors are the same.
---
plugins/check_mysql.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/plugins/check_mysql.c b/plugins/check_mysql.c
index 6cfa70edb..91e150fbd 100644
--- a/plugins/check_mysql.c
+++ b/plugins/check_mysql.c
@@ -138,7 +138,10 @@ main (int argc, char **argv)
mysql_ssl_set(&mysql,key,cert,ca_cert,ca_dir,ciphers);
/* establish a connection to the server and error checking */
if (!mysql_real_connect(&mysql,db_host,db_user,db_pass,db,db_port,db_socket,0)) {
- if (ignore_auth && mysql_errno (&mysql) == ER_ACCESS_DENIED_ERROR)
+ /* Depending on internally-selected auth plugin MySQL might return */
+ /* ER_ACCESS_DENIED_NO_PASSWORD_ERROR or ER_ACCESS_DENIED_ERROR. */
+ /* Semantically these errors are the same. */
+ if (ignore_auth && (mysql_errno (&mysql) == ER_ACCESS_DENIED_ERROR || mysql_errno (&mysql) == ER_ACCESS_DENIED_NO_PASSWORD_ERROR))
{
printf("MySQL OK - Version: %s (protocol %d)\n",
mysql_get_server_info(&mysql),

View file

@ -1,56 +0,0 @@
From bf8eb6dcc7f9d1318ddeac16fe62a5b5f818524b Mon Sep 17 00:00:00 2001
From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com>
Date: Fri, 26 May 2023 08:43:24 +0200
Subject: [PATCH] check_disk: Display SI units correctly
---
plugins/check_disk.c | 27 +++++++++++++++++++++------
1 file changed, 21 insertions(+), 6 deletions(-)
diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index a99f35e33..39dc6cd21 100644
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
@@ -626,21 +626,36 @@ process_arguments (int argc, char **argv)
if (! strcasecmp (optarg, "bytes")) {
mult = (uintmax_t)1;
units = strdup ("B");
- } else if ( (! strcmp (optarg, "kB")) || (!strcmp(optarg, "KiB")) ) {
+ } else if (!strcmp(optarg, "KiB")) {
mult = (uintmax_t)1024;
- units = strdup ("kiB");
- } else if ( (! strcmp (optarg, "MB")) || (!strcmp(optarg, "MiB")) ) {
+ units = strdup ("KiB");
+ } else if (! strcmp (optarg, "kB")) {
+ mult = (uintmax_t)1000;
+ units = strdup ("kB");
+ } else if (!strcmp(optarg, "MiB")) {
mult = (uintmax_t)1024 * 1024;
units = strdup ("MiB");
- } else if ( (! strcmp (optarg, "GB")) || (!strcmp(optarg, "GiB")) ) {
+ } else if (! strcmp (optarg, "MB")) {
+ mult = (uintmax_t)1000 * 1000;
+ units = strdup ("MB");
+ } else if (!strcmp(optarg, "GiB")) {
mult = (uintmax_t)1024 * 1024 * 1024;
units = strdup ("GiB");
- } else if ( (! strcmp (optarg, "TB")) || (!strcmp(optarg, "TiB")) ) {
+ } else if (! strcmp (optarg, "GB")){
+ mult = (uintmax_t)1000 * 1000 * 1000;
+ units = strdup ("GB");
+ } else if (!strcmp(optarg, "TiB")) {
mult = (uintmax_t)1024 * 1024 * 1024 * 1024;
units = strdup ("TiB");
- } else if ( (! strcmp (optarg, "PB")) || (!strcmp(optarg, "PiB")) ) {
+ } else if (! strcmp (optarg, "TB")) {
+ mult = (uintmax_t)1000 * 1000 * 1000 * 1000;
+ units = strdup ("TB");
+ } else if (!strcmp(optarg, "PiB")) {
mult = (uintmax_t)1024 * 1024 * 1024 * 1024 * 1024;
units = strdup ("PiB");
+ } else if (! strcmp (optarg, "PB")){
+ mult = (uintmax_t)1000 * 1000 * 1000 * 1000 * 1000;
+ units = strdup ("PB");
} else {
die (STATE_UNKNOWN, _("unit type %s not known\n"), optarg);
}

View file

@ -1,26 +0,0 @@
From 6bbe0b7b0f609ecab831dec9be7690842bf0a0fc Mon Sep 17 00:00:00 2001
From: Stuart Henderson <sthen@users.noreply.github.com>
Date: Wed, 8 Feb 2023 16:35:22 +0000
Subject: [PATCH] cope with radcli-1.3.1 RC_BUFFER_LEN
radcli 1.3.1 now uses RC_BUFFER_LEN instead of BUFFER_LEN. Add an #ifdef to allow working with either.
---
plugins/check_radius.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/plugins/check_radius.c b/plugins/check_radius.c
index be1001b4d..96a955536 100644
--- a/plugins/check_radius.c
+++ b/plugins/check_radius.c
@@ -155,7 +155,11 @@ main (int argc, char **argv)
{
struct sockaddr_storage ss;
char name[HOST_NAME_MAX];
+#ifdef RC_BUFFER_LEN
+ char msg[RC_BUFFER_LEN];
+#else
char msg[BUFFER_LEN];
+#endif
SEND_DATA data;
int result = STATE_UNKNOWN;
uint32_t client_id, service;

View file

@ -1,77 +0,0 @@
From 12ae1fb6627bfef419fb4571a7189909107f5e6e Mon Sep 17 00:00:00 2001
From: Jan Wagner <waja@cyconet.org>
Date: Tue, 1 Oct 2013 15:06:51 +0200
Subject: [PATCH] check_mailq.pl: separate submission queue
check_mailq.pl ignores the separate submission queue used in (modern?) sendmail
implementations.
For the queue output below with one message in the submission queue and no
messages in the transport queue, check_mailq.pl reports zero messages in the
queue because the request count from the last queue always overwrites previous
queues. If the sendmail MTA isn't running or has become wedged, messages will
sit in the submission queue forever.
The attached patch fixes this in a backwards compatible way (i.e., it shouldn't
break any of the currently supported formats).
--
Just turning attached patch of github issue #972 into a push request.
(Closes #972)
---
diff --git a/plugins-scripts/check_mailq.pl b/plugins-scripts/check_mailq.pl
index 27073d3cc..f02c90fbc 100755
--- a/plugins-scripts/check_mailq.pl
+++ b/plugins-scripts/check_mailq.pl
@@ -149,7 +149,26 @@
##/var/spool/mqueue/qF/df is empty
## Total Requests: 1
-
+# separate submission/transport queues, empty
+## MSP Queue status...
+## /var/spool/mqueue-client is empty
+## Total requests: 0
+## MTA Queue status...
+## /var/spool/mqueue is empty
+## Total requests: 0
+# separate submission/transport queues: 1
+## MSP Queue status...
+## /var/spool/mqueue-client (1 request)
+## -----Q-ID----- --Size-- -----Q-Time----- ------------Sender/Recipient-----------
+## oAJEfhdW014123 5 Fri Nov 19 14:41 jwm
+## (Deferred: Connection refused by [127.0.0.1])
+## root
+## Total requests: 1
+## MTA Queue status...
+## /var/spool/mqueue is empty
+## Total requests: 0
+
+ my $this_msg_q = 0;
while (<MAILQ>) {
# match email addr on queue listing
@@ -189,13 +208,18 @@
#
# single queue: first line
# multi queue: one for each queue. overwrite on multi queue below
- $msg_q = $1 ;
+ $this_msg_q = $1 ;
+ $msg_q += $1 ;
}
} elsif (/^\s+Total\sRequests:\s(\d+)$/i) {
- print "$utils::PATH_TO_MAILQ = $_ \n" if $verbose ;
- #
- # multi queue: last line
- $msg_q = $1 ;
+ if ($this_msg_q) {
+ $this_msg_q = 0 ;
+ } else {
+ print "$utils::PATH_TO_MAILQ = $_ \n" if $verbose ;
+ #
+ # multi queue: last line
+ $msg_q += $1 ;
+ }
}
}

View file

@ -1,839 +0,0 @@
From 8cf31437e99167ad9c260e6677b4d1ed31a34d56 Mon Sep 17 00:00:00 2001
From: Kristian Schuster <116557017+KriSchu@users.noreply.github.com>
Date: Mon, 24 Oct 2022 17:29:53 +0200
Subject: [PATCH 1/9] check_disk: add ignore-missing option to return OK for
missing fs There a situations where UNKNOWN or CRITICAL services are not
wanted when a filesystem is missing, a regex does not match or the filesystem
is inaccessible on a system. This new option helps to have the service in
state OK.
---
plugins/check_disk.c | 29 ++++++++++++++++++++++++-----
1 file changed, 24 insertions(+), 5 deletions(-)
diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index 7018c6fd5..8df9e7ec8 100644
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
@@ -112,7 +112,8 @@ enum
{
SYNC_OPTION = CHAR_MAX + 1,
NO_SYNC_OPTION,
- BLOCK_SIZE_OPTION
+ BLOCK_SIZE_OPTION,
+ IGNORE_MISSING
};
#ifdef _AIX
@@ -140,6 +141,7 @@ int verbose = 0;
int erronly = FALSE;
int display_mntp = FALSE;
int exact_match = FALSE;
+int ignore_missing = FALSE;
int freespace_ignore_reserved = FALSE;
int display_inodes_perfdata = FALSE;
char *warn_freespace_units = NULL;
@@ -219,7 +221,9 @@ main (int argc, char **argv)
temp_list = path_select_list;
while (temp_list) {
- if (! temp_list->best_match) {
+ if (! temp_list->best_match && ignore_missing == 1) {
+ die (STATE_OK, _("DISK %s: %s not found (ignoring)\n"), _("OK"), temp_list->name);
+ } else if (! temp_list->best_match) {
die (STATE_CRITICAL, _("DISK %s: %s not found\n"), _("CRITICAL"), temp_list->name);
}
@@ -481,6 +485,7 @@ process_arguments (int argc, char **argv)
{"ignore-ereg-partition", required_argument, 0, 'i'},
{"ignore-eregi-path", required_argument, 0, 'I'},
{"ignore-eregi-partition", required_argument, 0, 'I'},
+ {"ignore-missing", no_argument, 0, IGNORE_MISSING},
{"local", no_argument, 0, 'l'},
{"stat-remote-fs", no_argument, 0, 'L'},
{"iperfdata", no_argument, 0, 'P'},
@@ -718,6 +723,9 @@ process_arguments (int argc, char **argv)
cflags = default_cflags;
break;
+ case IGNORE_MISSING:
+ ignore_missing = 1;
+ break;
case 'A':
optarg = strdup(".*");
// Intentional fallthrough
@@ -753,7 +761,10 @@ process_arguments (int argc, char **argv)
}
}
- if (!fnd)
+ if (!fnd && ignore_missing == 1)
+ die (STATE_OK, "DISK %s: %s - %s\n",_("OK"),
+ _("Regular expression did not match any path or disk (ignoring)"), optarg);
+ else if (!fnd)
die (STATE_UNKNOWN, "DISK %s: %s - %s\n",_("UNKNOWN"),
_("Regular expression did not match any path or disk"), optarg);
@@ -923,6 +934,9 @@ print_help (void)
printf (" %s\n", _("Regular expression to ignore selected path/partition (case insensitive) (may be repeated)"));
printf (" %s\n", "-i, --ignore-ereg-path=PATH, --ignore-ereg-partition=PARTITION");
printf (" %s\n", _("Regular expression to ignore selected path or partition (may be repeated)"));
+ printf (" %s\n", "--ignore-missing");
+ printf (" %s\n", _("Return OK if no filesystem matches, filesystem does not exist or is inaccessible."));
+ printf (" %s\n", _("(Provide this option before -r / --ereg-path if used)"));
printf (UT_PLUG_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);
printf (" %s\n", "-u, --units=STRING");
printf (" %s\n", _("Choose bytes, kB, MB, GB, TB (default: MB)"));
@@ -965,8 +979,13 @@ stat_path (struct parameter_list *p)
if (stat (p->name, &stat_buf[0])) {
if (verbose >= 3)
printf("stat failed on %s\n", p->name);
- printf("DISK %s - ", _("CRITICAL"));
- die (STATE_CRITICAL, _("%s %s: %s\n"), p->name, _("is not accessible"), strerror(errno));
+ if (ignore_missing == 1) {
+ printf("DISK %s - ", _("OK"));
+ die (STATE_OK, _("%s %s: %s\n"), p->name, _("is not accessible (ignoring)"), strerror(errno));
+ } else {
+ printf("DISK %s - ", _("CRITICAL"));
+ die (STATE_CRITICAL, _("%s %s: %s\n"), p->name, _("is not accessible"), strerror(errno));
+ }
}
}
From 0d562a356f45f645014c3908178fc13876006f6e Mon Sep 17 00:00:00 2001
From: Kristian Schuster <116557017+KriSchu@users.noreply.github.com>
Date: Tue, 25 Oct 2022 20:49:51 +0200
Subject: [PATCH 2/9] check_disk: add tests for new option --ignore-missing
---
plugins/t/check_disk.t | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/plugins/t/check_disk.t b/plugins/t/check_disk.t
index ec527e7f6..bea34a4c9 100644
--- a/plugins/t/check_disk.t
+++ b/plugins/t/check_disk.t
@@ -351,3 +351,18 @@ unlike( $result->output, qr/$mountpoint2_valid/, "output data does not have $mou
$result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p $mountpoint_valid -p $mountpoint2_valid -i '^barbazJodsf\$'");
like( $result->output, qr/$mountpoint_valid/, "ignore: output data does have $mountpoint_valid when regex doesn't match");
like( $result->output, qr/$mountpoint2_valid/,"ignore: output data does have $mountpoint2_valid when regex doesn't match");
+
+# ignore-missing: exit okay, when fs is not accessible
+$result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -p /bob");
+cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for not existing filesystem /bob");
+like( $result->output, '/^DISK OK - /bob is not accessible .*$/', 'Output OK');
+
+# ignore-missing: exit okay, when regex does not match
+$result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -r /bob");
+cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching");
+like( $result->output, '/^DISK OK: Regular expression did not match any path or disk.*$/', 'Output OK');
+
+# ignore-missing: exit okay, when fs with exact match (-E) is not found
+$result = NPTest->testCmd( "./check_disk --ignore-missing -E -w 0% -c 0% -p /etc");
+cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay when exact match does not find fs");
+like( $result->output, '/^DISK OK: /etc not found.*$/', 'Output OK');
From bacacd2cb38c7d7a695a6f75f699168d9df0132d Mon Sep 17 00:00:00 2001
From: Sven Nierlein <sven@nierlein.org>
Date: Wed, 26 Oct 2022 14:03:22 +0200
Subject: [PATCH 3/9] check_disk: adjust test plan
---
plugins/t/check_disk.t | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/plugins/t/check_disk.t b/plugins/t/check_disk.t
index bea34a4c9..a534fd4a5 100644
--- a/plugins/t/check_disk.t
+++ b/plugins/t/check_disk.t
@@ -23,7 +23,7 @@ my $mountpoint2_valid = getTestParameter( "NP_MOUNTPOINT2_VALID", "Path to anoth
if ($mountpoint_valid eq "" or $mountpoint2_valid eq "") {
plan skip_all => "Need 2 mountpoints to test";
} else {
- plan tests => 78;
+ plan tests => 84;
}
$result = NPTest->testCmd(
From 9898a8ad7dabfabfe80785585a5bbc30b678bdb0 Mon Sep 17 00:00:00 2001
From: Kristian Schuster <116557017+KriSchu@users.noreply.github.com>
Date: Sun, 19 Feb 2023 13:44:04 +0100
Subject: [PATCH 4/9] utils_disk: add name_prev pointer to struct
parameter_list
Also added handling of name_prev in np_add_parameter and np_delete_parameter.
This make calling the np_delete_parameter function easier, because it requires
the previous element as second argument.
---
lib/utils_disk.c | 19 +++++++++++++++++--
lib/utils_disk.h | 1 +
2 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/lib/utils_disk.c b/lib/utils_disk.c
index c7c9126e4..a1181d37b 100644
--- a/lib/utils_disk.c
+++ b/lib/utils_disk.c
@@ -46,9 +46,10 @@ 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 *) name;
+ 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;
@@ -74,13 +75,17 @@ np_add_parameter(struct parameter_list **list, const char *name)
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;
}
@@ -89,6 +94,9 @@ np_add_parameter(struct parameter_list **list, const char *name)
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)
@@ -96,10 +104,17 @@ np_del_parameter(struct parameter_list *item, struct parameter_list *prev)
else
next = NULL;
- free(item);
+ if (next)
+ next->name_prev = prev;
+
if (prev)
prev->name_next = next;
+ if (item->name) {
+ free(item->name);
+ }
+ free(item);
+
return next;
}
diff --git a/lib/utils_disk.h b/lib/utils_disk.h
index bf52e4ce9..3b5a45f86 100644
--- a/lib/utils_disk.h
+++ b/lib/utils_disk.h
@@ -24,6 +24,7 @@ struct parameter_list
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;
From ba78c32018658608a31c293beef89ec82b9ba9d3 Mon Sep 17 00:00:00 2001
From: Kristian Schuster <116557017+KriSchu@users.noreply.github.com>
Date: Sun, 19 Feb 2023 22:49:30 +0100
Subject: [PATCH 5/9] check_disk: still allow check of available disks with
ignore-missing param used
Also add reporting of ignored paths. When paths are provided by -p and/ or -r and
one path does not match a mounted disk, checking available disks is still
possible. Paths provided by -p are reported as ignored, when not available. Due
to code structure, this is not possible for -r unfortunately.
---
plugins/check_disk.c | 103 ++++++++++++++++++++++++++++++++-----------
1 file changed, 78 insertions(+), 25 deletions(-)
diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index 8df9e7ec8..c1cfb13c0 100644
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
@@ -117,7 +117,7 @@ enum
};
#ifdef _AIX
- #pragma alloca
+#pragma alloca
#endif
int process_arguments (int, char **);
@@ -127,7 +127,7 @@ int validate_arguments (uintmax_t, uintmax_t, double, double, double, double, ch
void print_help (void);
void print_usage (void);
double calculate_percent(uintmax_t, uintmax_t);
-void stat_path (struct parameter_list *p);
+bool stat_path (struct parameter_list *p);
void get_stats (struct parameter_list *p, struct fs_usage *fsp);
void get_path_stats (struct parameter_list *p, struct fs_usage *fsp);
@@ -157,6 +157,7 @@ char *crit_usedinodes_percent = NULL;
char *warn_freeinodes_percent = NULL;
char *crit_freeinodes_percent = NULL;
int path_selected = FALSE;
+int path_ignored = FALSE;
char *group = NULL;
struct stat *stat_buf;
struct name_list *seen = NULL;
@@ -168,10 +169,12 @@ main (int argc, char **argv)
int result = STATE_UNKNOWN;
int disk_result = STATE_UNKNOWN;
char *output;
+ char *ignored;
char *details;
char *perf;
char *perf_ilabel;
char *preamble;
+ char *ignored_preamble;
char *flag_header;
int temp_result;
@@ -183,8 +186,10 @@ main (int argc, char **argv)
char mountdir[32];
#endif
- preamble = strdup (" - free space:");
+ preamble = strdup (" free space:");
+ ignored_preamble = strdup (" ignored paths:");
output = strdup ("");
+ ignored = strdup ("");
details = strdup ("");
perf = strdup ("");
perf_ilabel = strdup ("");
@@ -205,7 +210,7 @@ main (int argc, char **argv)
/* If a list of paths has not been selected, find entire
mount list and create list of paths
*/
- if (path_selected == FALSE) {
+ if (path_selected == FALSE && path_ignored == FALSE) {
for (me = mount_list; me; me = me->me_next) {
if (! (path = np_find_parameter(path_select_list, me->me_mountdir))) {
path = np_add_parameter(&path_select_list, me->me_mountdir);
@@ -215,19 +220,40 @@ main (int argc, char **argv)
set_all_thresholds(path);
}
}
- np_set_best_match(path_select_list, mount_list, exact_match);
+
+ if (path_ignored == FALSE) {
+ np_set_best_match(path_select_list, mount_list, exact_match);
+ }
/* Error if no match found for specified paths */
temp_list = path_select_list;
- while (temp_list) {
- if (! temp_list->best_match && ignore_missing == 1) {
- die (STATE_OK, _("DISK %s: %s not found (ignoring)\n"), _("OK"), temp_list->name);
- } else if (! temp_list->best_match) {
- die (STATE_CRITICAL, _("DISK %s: %s not found\n"), _("CRITICAL"), temp_list->name);
+ while (path_select_list) {
+ if (! path_select_list->best_match && ignore_missing == 1) {
+ /* If the first element will be deleted, the temp_list must be updated with the new start address as well */
+ if (path_select_list == temp_list) {
+ temp_list = path_select_list->name_next;
+ }
+ /* Add path argument to list of ignored paths to inform about missing paths being ignored and not alerted */
+ xasprintf (&ignored, "%s %s;", ignored, path_select_list->name);
+ /* Delete the path from the list so that it is not stat-checked later in the code. */
+ path_select_list = np_del_parameter(path_select_list, path_select_list->name_prev);
+ } else if (! path_select_list->best_match) {
+ /* Without --ignore-missing option, exit with Critical state. */
+ die (STATE_CRITICAL, _("DISK %s: %s not found\n"), _("CRITICAL"), path_select_list->name);
+ } else {
+ /* Continue jumping through the list */
+ path_select_list = path_select_list->name_next;
}
+ }
+
+ path_select_list = temp_list;
- temp_list = temp_list->name_next;
+ if (! path_select_list && ignore_missing == 1) {
+ result = STATE_OK;
+ if (verbose >= 2) {
+ printf ("None of the provided paths were found\n");
+ }
}
/* Process for every path in list */
@@ -246,6 +272,10 @@ main (int argc, char **argv)
me = path->best_match;
+ if (!me) {
+ continue;
+ }
+
#ifdef __CYGWIN__
if (strncmp(path->name, "/cygdrive/", 10) != 0 || strlen(path->name) > 11)
continue;
@@ -264,8 +294,12 @@ main (int argc, char **argv)
if (path->group == NULL) {
/* Skip remote filesystems if we're not interested in them */
if (me->me_remote && show_local_fs) {
- if (stat_remote_fs)
- stat_path(path);
+ if (stat_remote_fs) {
+ if (!stat_path(path) && ignore_missing == 1) {
+ result = STATE_OK;
+ xasprintf (&ignored, "%s %s;", ignored, path->name);
+ }
+ }
continue;
/* Skip pseudo fs's if we haven't asked for all fs's */
} else if (me->me_dummy && !show_all_fs) {
@@ -284,7 +318,13 @@ main (int argc, char **argv)
}
}
- stat_path(path);
+ if (!stat_path(path)) {
+ if (ignore_missing == 1) {
+ result = STATE_OK;
+ xasprintf (&ignored, "%s %s;", ignored, path->name);
+ }
+ continue;
+ }
get_fs_usage (me->me_mountdir, me->me_devname, &fsp);
if (fsp.fsu_blocks && strcmp ("none", me->me_mountdir)) {
@@ -415,8 +455,12 @@ main (int argc, char **argv)
if (verbose >= 2)
xasprintf (&output, "%s%s", output, details);
+ if (strcmp(output, "") == 0) {
+ preamble = "";
+ xasprintf (&output, " No disks were found for provided parameters;");
+ }
- printf ("DISK %s%s%s|%s\n", state_text (result), (erronly && result==STATE_OK) ? "" : preamble, output, perf);
+ printf ("DISK %s -%s%s%s%s|%s\n", state_text (result), ((erronly && result==STATE_OK)) ? "" : preamble, output, (strcmp(ignored, "") == 0) ? "" : ignored_preamble, ignored, perf);
return result;
}
@@ -637,12 +681,19 @@ process_arguments (int argc, char **argv)
/* add parameter if not found. overwrite thresholds if path has already been added */
if (! (se = np_find_parameter(path_select_list, optarg))) {
se = np_add_parameter(&path_select_list, optarg);
+
+ if (stat(optarg, &stat_buf[0]) && ignore_missing == 1) {
+ path_ignored = TRUE;
+ break;
+ }
}
se->group = group;
set_all_thresholds(se);
/* With autofs, it is required to stat() the path before re-populating the mount_list */
- stat_path(se);
+ if (!stat_path(se)) {
+ break;
+ }
/* NB: We can't free the old mount_list "just like that": both list pointers and struct
* pointers are copied around. One of the reason it wasn't done yet is that other parts
* of check_disk need the same kind of cleanup so it'd better be done as a whole */
@@ -761,10 +812,11 @@ process_arguments (int argc, char **argv)
}
}
- if (!fnd && ignore_missing == 1)
- die (STATE_OK, "DISK %s: %s - %s\n",_("OK"),
- _("Regular expression did not match any path or disk (ignoring)"), optarg);
- else if (!fnd)
+ if (!fnd && ignore_missing == 1) {
+ path_ignored = TRUE;
+ /* path_selected = TRUE;*/
+ break;
+ } else if (!fnd)
die (STATE_UNKNOWN, "DISK %s: %s - %s\n",_("UNKNOWN"),
_("Regular expression did not match any path or disk"), optarg);
@@ -936,7 +988,7 @@ print_help (void)
printf (" %s\n", _("Regular expression to ignore selected path or partition (may be repeated)"));
printf (" %s\n", "--ignore-missing");
printf (" %s\n", _("Return OK if no filesystem matches, filesystem does not exist or is inaccessible."));
- printf (" %s\n", _("(Provide this option before -r / --ereg-path if used)"));
+ printf (" %s\n", _("(Provide this option before -p / -r / --ereg-path if used)"));
printf (UT_PLUG_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);
printf (" %s\n", "-u, --units=STRING");
printf (" %s\n", _("Choose bytes, kB, MB, GB, TB (default: MB)"));
@@ -970,7 +1022,7 @@ print_usage (void)
printf ("[-t timeout] [-u unit] [-v] [-X type] [-N type]\n");
}
-void
+bool
stat_path (struct parameter_list *p)
{
/* Stat entry to check that dir exists and is accessible */
@@ -980,13 +1032,13 @@ stat_path (struct parameter_list *p)
if (verbose >= 3)
printf("stat failed on %s\n", p->name);
if (ignore_missing == 1) {
- printf("DISK %s - ", _("OK"));
- die (STATE_OK, _("%s %s: %s\n"), p->name, _("is not accessible (ignoring)"), strerror(errno));
+ return false;
} else {
printf("DISK %s - ", _("CRITICAL"));
die (STATE_CRITICAL, _("%s %s: %s\n"), p->name, _("is not accessible"), strerror(errno));
}
}
+ return true;
}
@@ -1006,7 +1058,8 @@ get_stats (struct parameter_list *p, struct fs_usage *fsp) {
continue;
#endif
if (p_list->group && ! (strcmp(p_list->group, p->group))) {
- stat_path(p_list);
+ if (! stat_path(p_list))
+ continue;
get_fs_usage (p_list->best_match->me_mountdir, p_list->best_match->me_devname, &tmpfsp);
get_path_stats(p_list, &tmpfsp);
if (verbose >= 3)
From ca3d59cd6918c9e2739e783b721d4c1122640fd3 Mon Sep 17 00:00:00 2001
From: Kristian Schuster <116557017+KriSchu@users.noreply.github.com>
Date: Sun, 19 Feb 2023 23:00:21 +0100
Subject: [PATCH 6/9] check_disk: add new tests for new ignore-missing feature
---
plugins/t/check_disk.t | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)
diff --git a/plugins/t/check_disk.t b/plugins/t/check_disk.t
index a534fd4a5..275db70d8 100644
--- a/plugins/t/check_disk.t
+++ b/plugins/t/check_disk.t
@@ -23,7 +23,7 @@ my $mountpoint2_valid = getTestParameter( "NP_MOUNTPOINT2_VALID", "Path to anoth
if ($mountpoint_valid eq "" or $mountpoint2_valid eq "") {
plan skip_all => "Need 2 mountpoints to test";
} else {
- plan tests => 84;
+ plan tests => 86;
}
$result = NPTest->testCmd(
@@ -355,14 +355,24 @@ like( $result->output, qr/$mountpoint2_valid/,"ignore: output data does have $mo
# ignore-missing: exit okay, when fs is not accessible
$result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -p /bob");
cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for not existing filesystem /bob");
-like( $result->output, '/^DISK OK - /bob is not accessible .*$/', 'Output OK');
+like( $result->output, '/^DISK OK - No disks were found for provided parameters; ignored paths: /bob;.*$/', 'Output OK');
# ignore-missing: exit okay, when regex does not match
$result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -r /bob");
cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching");
-like( $result->output, '/^DISK OK: Regular expression did not match any path or disk.*$/', 'Output OK');
+like( $result->output, '/^DISK OK - No disks were found for provided parameters;.*$/', 'Output OK');
# ignore-missing: exit okay, when fs with exact match (-E) is not found
-$result = NPTest->testCmd( "./check_disk --ignore-missing -E -w 0% -c 0% -p /etc");
+$result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -E -p /etc");
cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay when exact match does not find fs");
-like( $result->output, '/^DISK OK: /etc not found.*$/', 'Output OK');
+like( $result->output, '/^DISK OK - No disks were found for provided parameters; ignored paths: /etc;.*$/', 'Output OK');
+
+# ignore-missing: exit okay, when checking one existing fs and one non-existing fs (regex)
+$result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -r '/bob' -r '^/$'");
+cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching");
+like( $result->output, '/^DISK OK - free space: / .*$/', 'Output OK');
+
+# ignore-missing: exit okay, when checking one existing fs and one non-existing fs (path)
+$result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -p '/bob' -p '/'");
+cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching");
+like( $result->output, '/^DISK OK - free space: / .*; ignored paths: /bob;.*$/', 'Output OK');
\ No newline at end of file
From a58293a0c288ee0e050c79715073da9fbdfc4c58 Mon Sep 17 00:00:00 2001
From: Kristian Schuster <116557017+KriSchu@users.noreply.github.com>
Date: Mon, 20 Feb 2023 01:27:23 +0100
Subject: [PATCH 7/9] check_disk: fix tests by setting correct test number and
escaping line end regex
---
plugins/t/check_disk.t | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/plugins/t/check_disk.t b/plugins/t/check_disk.t
index 275db70d8..73f1e3748 100644
--- a/plugins/t/check_disk.t
+++ b/plugins/t/check_disk.t
@@ -23,7 +23,7 @@ my $mountpoint2_valid = getTestParameter( "NP_MOUNTPOINT2_VALID", "Path to anoth
if ($mountpoint_valid eq "" or $mountpoint2_valid eq "") {
plan skip_all => "Need 2 mountpoints to test";
} else {
- plan tests => 86;
+ plan tests => 88;
}
$result = NPTest->testCmd(
@@ -126,7 +126,7 @@ my $free_mb_on_all = $free_mb_on_mp1 + $free_mb_on_mp2;
$result = NPTest->testCmd( "./check_disk -e -w 1 -c 1 -p $more_free" );
-is( $result->only_output, "DISK OK", "No print out of disks with -e for OKs");
+is( $result->only_output, "DISK OK - No disks were found for provided parameters;", "No print out of disks with -e for OKs");
$result = NPTest->testCmd( "./check_disk 100 100 $more_free" );
cmp_ok( $result->return_code, '==', 0, "Old syntax okay" );
@@ -368,9 +368,9 @@ cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay when exact m
like( $result->output, '/^DISK OK - No disks were found for provided parameters; ignored paths: /etc;.*$/', 'Output OK');
# ignore-missing: exit okay, when checking one existing fs and one non-existing fs (regex)
-$result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -r '/bob' -r '^/$'");
+$result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -r '/bob' -r '^/\$'");
cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching");
-like( $result->output, '/^DISK OK - free space: / .*$/', 'Output OK');
+like( $result->output, '/^DISK OK - free space: \/ .*$/', 'Output OK');
# ignore-missing: exit okay, when checking one existing fs and one non-existing fs (path)
$result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -p '/bob' -p '/'");
From e102b8a49e857a474db516455d2e871e6834ae34 Mon Sep 17 00:00:00 2001
From: Kristian Schuster <116557017+KriSchu@users.noreply.github.com>
Date: Mon, 20 Feb 2023 02:03:01 +0100
Subject: [PATCH 8/9] check_disk: fix ugly output with -e option and adapt
tests accordingly
---
plugins/check_disk.c | 10 +++++-----
plugins/t/check_disk.t | 8 ++++----
2 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index d32841d8e..c52d1df48 100644
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
@@ -186,8 +186,8 @@ main (int argc, char **argv)
char mountdir[32];
#endif
- preamble = strdup (" free space:");
- ignored_preamble = strdup (" ignored paths:");
+ preamble = strdup (" - free space:");
+ ignored_preamble = strdup (" - ignored paths:");
output = strdup ("");
ignored = strdup ("");
details = strdup ("");
@@ -455,12 +455,12 @@ main (int argc, char **argv)
if (verbose >= 2)
xasprintf (&output, "%s%s", output, details);
- if (strcmp(output, "") == 0) {
+ if (strcmp(output, "") == 0 && ! erronly) {
preamble = "";
- xasprintf (&output, " No disks were found for provided parameters;");
+ xasprintf (&output, " - No disks were found for provided parameters;");
}
- printf ("DISK %s -%s%s%s%s|%s\n", state_text (result), ((erronly && result==STATE_OK)) ? "" : preamble, output, (strcmp(ignored, "") == 0) ? "" : ignored_preamble, ignored, perf);
+ printf ("DISK %s%s%s%s%s|%s\n", state_text (result), ((erronly && result==STATE_OK)) ? "" : preamble, output, (strcmp(ignored, "") == 0) ? "" : ignored_preamble, ignored, perf);
return result;
}
diff --git a/plugins/t/check_disk.t b/plugins/t/check_disk.t
index 73f1e3748..c8f08f515 100644
--- a/plugins/t/check_disk.t
+++ b/plugins/t/check_disk.t
@@ -126,7 +126,7 @@ my $free_mb_on_all = $free_mb_on_mp1 + $free_mb_on_mp2;
$result = NPTest->testCmd( "./check_disk -e -w 1 -c 1 -p $more_free" );
-is( $result->only_output, "DISK OK - No disks were found for provided parameters;", "No print out of disks with -e for OKs");
+is( $result->only_output, "DISK OK", "No print out of disks with -e for OKs");
$result = NPTest->testCmd( "./check_disk 100 100 $more_free" );
cmp_ok( $result->return_code, '==', 0, "Old syntax okay" );
@@ -355,7 +355,7 @@ like( $result->output, qr/$mountpoint2_valid/,"ignore: output data does have $mo
# ignore-missing: exit okay, when fs is not accessible
$result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -p /bob");
cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for not existing filesystem /bob");
-like( $result->output, '/^DISK OK - No disks were found for provided parameters; ignored paths: /bob;.*$/', 'Output OK');
+like( $result->output, '/^DISK OK - No disks were found for provided parameters; - ignored paths: /bob;.*$/', 'Output OK');
# ignore-missing: exit okay, when regex does not match
$result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -r /bob");
@@ -365,7 +365,7 @@ like( $result->output, '/^DISK OK - No disks were found for provided parameters;
# ignore-missing: exit okay, when fs with exact match (-E) is not found
$result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -E -p /etc");
cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay when exact match does not find fs");
-like( $result->output, '/^DISK OK - No disks were found for provided parameters; ignored paths: /etc;.*$/', 'Output OK');
+like( $result->output, '/^DISK OK - No disks were found for provided parameters; - ignored paths: /etc;.*$/', 'Output OK');
# ignore-missing: exit okay, when checking one existing fs and one non-existing fs (regex)
$result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -r '/bob' -r '^/\$'");
@@ -375,4 +375,4 @@ like( $result->output, '/^DISK OK - free space: \/ .*$/', 'Output OK');
# ignore-missing: exit okay, when checking one existing fs and one non-existing fs (path)
$result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -p '/bob' -p '/'");
cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching");
-like( $result->output, '/^DISK OK - free space: / .*; ignored paths: /bob;.*$/', 'Output OK');
\ No newline at end of file
+like( $result->output, '/^DISK OK - free space: / .*; - ignored paths: /bob;.*$/', 'Output OK');
\ No newline at end of file
From 3e7da5f970d73df91fad32f4dce259d30cdbbd65 Mon Sep 17 00:00:00 2001
From: Kristian Schuster <116557017+KriSchu@users.noreply.github.com>
Date: Mon, 6 Mar 2023 14:03:10 +0100
Subject: [PATCH 9/9] check_disk: use cleaner code for ignore-missing option -
use datatype bool for new vars ignore_missing and path_ignored instead of int
- directly initialize preamble and ignored_preamble with their strings
---
plugins/check_disk.c | 34 ++++++++++++++++------------------
1 file changed, 16 insertions(+), 18 deletions(-)
diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index c52d1df48..bd84c8257 100644
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
@@ -141,7 +141,7 @@ int verbose = 0;
int erronly = FALSE;
int display_mntp = FALSE;
int exact_match = FALSE;
-int ignore_missing = FALSE;
+bool ignore_missing = false;
int freespace_ignore_reserved = FALSE;
int display_inodes_perfdata = FALSE;
char *warn_freespace_units = NULL;
@@ -157,7 +157,7 @@ char *crit_usedinodes_percent = NULL;
char *warn_freeinodes_percent = NULL;
char *crit_freeinodes_percent = NULL;
int path_selected = FALSE;
-int path_ignored = FALSE;
+bool path_ignored = false;
char *group = NULL;
struct stat *stat_buf;
struct name_list *seen = NULL;
@@ -173,8 +173,8 @@ main (int argc, char **argv)
char *details;
char *perf;
char *perf_ilabel;
- char *preamble;
- char *ignored_preamble;
+ char *preamble = " - free space:";
+ char *ignored_preamble = " - ignored paths:";
char *flag_header;
int temp_result;
@@ -186,8 +186,6 @@ main (int argc, char **argv)
char mountdir[32];
#endif
- preamble = strdup (" - free space:");
- ignored_preamble = strdup (" - ignored paths:");
output = strdup ("");
ignored = strdup ("");
details = strdup ("");
@@ -210,7 +208,7 @@ main (int argc, char **argv)
/* If a list of paths has not been selected, find entire
mount list and create list of paths
*/
- if (path_selected == FALSE && path_ignored == FALSE) {
+ if (path_selected == FALSE && path_ignored == false) {
for (me = mount_list; me; me = me->me_next) {
if (! (path = np_find_parameter(path_select_list, me->me_mountdir))) {
path = np_add_parameter(&path_select_list, me->me_mountdir);
@@ -221,7 +219,7 @@ main (int argc, char **argv)
}
}
- if (path_ignored == FALSE) {
+ if (path_ignored == false) {
np_set_best_match(path_select_list, mount_list, exact_match);
}
@@ -229,7 +227,7 @@ main (int argc, char **argv)
temp_list = path_select_list;
while (path_select_list) {
- if (! path_select_list->best_match && ignore_missing == 1) {
+ if (! path_select_list->best_match && ignore_missing == true) {
/* If the first element will be deleted, the temp_list must be updated with the new start address as well */
if (path_select_list == temp_list) {
temp_list = path_select_list->name_next;
@@ -249,7 +247,7 @@ main (int argc, char **argv)
path_select_list = temp_list;
- if (! path_select_list && ignore_missing == 1) {
+ if (! path_select_list && ignore_missing == true) {
result = STATE_OK;
if (verbose >= 2) {
printf ("None of the provided paths were found\n");
@@ -295,7 +293,7 @@ main (int argc, char **argv)
/* Skip remote filesystems if we're not interested in them */
if (me->me_remote && show_local_fs) {
if (stat_remote_fs) {
- if (!stat_path(path) && ignore_missing == 1) {
+ if (!stat_path(path) && ignore_missing == true) {
result = STATE_OK;
xasprintf (&ignored, "%s %s;", ignored, path->name);
}
@@ -319,7 +317,7 @@ main (int argc, char **argv)
}
if (!stat_path(path)) {
- if (ignore_missing == 1) {
+ if (ignore_missing == true) {
result = STATE_OK;
xasprintf (&ignored, "%s %s;", ignored, path->name);
}
@@ -682,8 +680,8 @@ process_arguments (int argc, char **argv)
if (! (se = np_find_parameter(path_select_list, optarg))) {
se = np_add_parameter(&path_select_list, optarg);
- if (stat(optarg, &stat_buf[0]) && ignore_missing == 1) {
- path_ignored = TRUE;
+ if (stat(optarg, &stat_buf[0]) && ignore_missing == true) {
+ path_ignored = true;
break;
}
}
@@ -775,7 +773,7 @@ process_arguments (int argc, char **argv)
break;
case IGNORE_MISSING:
- ignore_missing = 1;
+ ignore_missing = true;
break;
case 'A':
optarg = strdup(".*");
@@ -812,8 +810,8 @@ process_arguments (int argc, char **argv)
}
}
- if (!fnd && ignore_missing == 1) {
- path_ignored = TRUE;
+ if (!fnd && ignore_missing == true) {
+ path_ignored = true;
/* path_selected = TRUE;*/
break;
} else if (!fnd)
@@ -1031,7 +1029,7 @@ stat_path (struct parameter_list *p)
if (stat (p->name, &stat_buf[0])) {
if (verbose >= 3)
printf("stat failed on %s\n", p->name);
- if (ignore_missing == 1) {
+ if (ignore_missing == true) {
return false;
} else {
printf("DISK %s - ", _("CRITICAL"));

View file

@ -1,168 +0,0 @@
From 691376d3a16da06e34740593d9a1de0e00cbffb8 Mon Sep 17 00:00:00 2001
From: Christian Kujau <lists@nerdbynature.de>
Date: Mon, 20 Mar 2023 11:35:01 +0100
Subject: [PATCH 1/2] check_procs: Implement --exclude-process to exclude
specific processes.
Signed-off-by: Christian Kujau <lists@nerdbynature.de>
---
plugins/check_procs.c | 47 +++++++++++++++++++++++++++++++++++++++++--
1 file changed, 45 insertions(+), 2 deletions(-)
diff --git a/plugins/check_procs.c b/plugins/check_procs.c
index a025ee891..d672dd44e 100644
--- a/plugins/check_procs.c
+++ b/plugins/check_procs.c
@@ -70,6 +70,7 @@ int options = 0; /* bitmask of filter criteria to test against */
#define PCPU 256
#define ELAPSED 512
#define EREG_ARGS 1024
+#define EXCLUDE_PROGS 2048
#define KTHREAD_PARENT "kthreadd" /* the parent process of kernel threads:
ppid of procs are compared to pid of this proc*/
@@ -93,6 +94,9 @@ int rss;
float pcpu;
char *statopts;
char *prog;
+char *exclude_progs;
+char **exclude_progs_arr = NULL;
+char exclude_progs_counter = 0;
char *args;
char *input_filename = NULL;
regex_t re_args;
@@ -250,6 +254,25 @@ main (int argc, char **argv)
continue;
}
+ /* Ignore excluded processes by name */
+ if(options & EXCLUDE_PROGS) {
+ int found = 0;
+ int i = 0;
+
+ for(i=0; i < (exclude_progs_counter); i++) {
+ if(!strcmp(procprog, exclude_progs_arr[i])) {
+ found = 1;
+ }
+ }
+ if(found == 0) {
+ resultsum |= EXCLUDE_PROGS;
+ } else
+ {
+ if(verbose >= 3)
+ printf("excluding - by ignorelist\n");
+ }
+ }
+
/* filter kernel threads (childs of KTHREAD_PARENT)*/
/* TODO adapt for other OSes than GNU/Linux
sorry for not doing that, but I've no other OSes to test :-( */
@@ -409,6 +432,7 @@ process_arguments (int argc, char **argv)
{"input-file", required_argument, 0, CHAR_MAX+2},
{"no-kthreads", required_argument, 0, 'k'},
{"traditional-filter", no_argument, 0, 'T'},
+ {"exclude-process", required_argument, 0, 'X'},
{0, 0, 0, 0}
};
@@ -417,7 +441,7 @@ process_arguments (int argc, char **argv)
strcpy (argv[c], "-t");
while (1) {
- c = getopt_long (argc, argv, "Vvhkt:c:w:p:s:u:C:a:z:r:m:P:T",
+ c = getopt_long (argc, argv, "Vvhkt:c:w:p:s:u:C:a:z:r:m:P:T:X:",
longopts, &option);
if (c == -1 || c == EOF)
@@ -490,6 +514,23 @@ process_arguments (int argc, char **argv)
prog);
options |= PROG;
break;
+ case 'X':
+ if(exclude_progs)
+ break;
+ else
+ exclude_progs = optarg;
+ xasprintf (&fmt, _("%s%sexclude progs '%s'"), (fmt ? fmt : ""), (options ? ", " : ""),
+ exclude_progs);
+ char *p = strtok(exclude_progs, ",");
+
+ while(p){
+ exclude_progs_arr = realloc(exclude_progs_arr, sizeof(char*) * ++exclude_progs_counter);
+ exclude_progs_arr[exclude_progs_counter-1] = p;
+ p = strtok(NULL, ",");
+ }
+
+ options |= EXCLUDE_PROGS;
+ break;
case 'a': /* args (full path name with args) */
/* TODO: allow this to be passed in with --metric */
if (args)
@@ -745,6 +786,8 @@ print_help (void)
printf (" %s\n", _("Only scan for processes with args that contain the regex STRING."));
printf (" %s\n", "-C, --command=COMMAND");
printf (" %s\n", _("Only scan for exact matches of COMMAND (without path)."));
+ printf (" %s\n", "-X, --exclude-process");
+ printf (" %s\n", _("Exclude processes which match this comma seperated list"));
printf (" %s\n", "-k, --no-kthreads");
printf (" %s\n", _("Only scan for non kernel threads (works on Linux only)."));
@@ -786,5 +829,5 @@ print_usage (void)
printf ("%s\n", _("Usage:"));
printf ("%s -w <range> -c <range> [-m metric] [-s state] [-p ppid]\n", progname);
printf (" [-u user] [-r rss] [-z vsz] [-P %%cpu] [-a argument-array]\n");
- printf (" [-C command] [-k] [-t timeout] [-v]\n");
+ printf (" [-C command] [-X process_to_exclude] [-k] [-t timeout] [-v]\n");
}
From 7b7037280c36279ea51de07f9a4efea10bcfa24c Mon Sep 17 00:00:00 2001
From: Christian Kujau <lists@nerdbynature.de>
Date: Tue, 21 Mar 2023 11:26:03 +0100
Subject: [PATCH 2/2] check_procs: add a test for the newly added -X option.
$ make test
[...]
perl -I .. -I .. ../test.pl
No application (check_curl) found for test harness (check_curl.t)
No application (check_snmp) found for test harness (check_snmp.t)
./t/check_procs.t ...... ok
./tests/check_nt.t ..... ok
./tests/check_procs.t .. ok
All tests successful.
Files=4, Tests=73, 8 wallclock secs ( 0.05 usr 0.02 sys + 0.38 cusr
0.22 csys = 0.67 CPU)
Result: PASS
Signed-off-by: Christian Kujau <lists@nerdbynature.de>
---
plugins/tests/check_procs.t | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/plugins/tests/check_procs.t b/plugins/tests/check_procs.t
index 3af218f50..b3a0a3015 100755
--- a/plugins/tests/check_procs.t
+++ b/plugins/tests/check_procs.t
@@ -8,7 +8,7 @@ use Test::More;
use NPTest;
if (-x "./check_procs") {
- plan tests => 52;
+ plan tests => 54;
} else {
plan skip_all => "No check_procs compiled";
}
@@ -34,9 +34,13 @@ is( $result->return_code, 0, "Checking no threshold breeched" );
is( $result->output, "PROCS OK: 95 processes | procs=95;100;200;0;", "Output correct" );
$result = NPTest->testCmd( "$command -C launchd -c 5" );
-is( $result->return_code, 2, "Checking processes filtered by command name" );
+is( $result->return_code, 2, "Checking processes matched by command name" );
is( $result->output, "PROCS CRITICAL: 6 processes with command name 'launchd' | procs=6;;5;0;", "Output correct" );
+$result = NPTest->testCmd( "$command -X bash -c 5" );
+is( $result->return_code, 2, "Checking processes excluded by command name" );
+is( $result->output, "PROCS CRITICAL: 95 processes with exclude progs 'bash' | procs=95;;5;0;", "Output correct" );
+
SKIP: {
skip 'user with uid 501 required', 4 unless getpwuid(501);

View file

@ -1,31 +0,0 @@
From cf90f0de7b3c347a6860b50de6a610bd7132668c Mon Sep 17 00:00:00 2001
From: Andreas Baumann <mail@andreasbaumann.cc>
Date: Thu, 16 Mar 2023 16:21:46 +0100
Subject: [PATCH] check_curk: including netinet/in.h (for FreeBSD), fixed an
ambigous compare warning
---
plugins/check_curl.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/plugins/check_curl.c b/plugins/check_curl.c
index e5be1ad56..c51914a9a 100644
--- a/plugins/check_curl.c
+++ b/plugins/check_curl.c
@@ -55,6 +55,7 @@ const char *email = "devel@monitoring-plugins.org";
#include "uriparser/Uri.h"
#include <arpa/inet.h>
+#include <netinet/in.h>
#if defined(HAVE_SSL) && defined(USE_OPENSSL)
#include <openssl/opensslv.h>
@@ -541,7 +542,7 @@ check_http (void)
/* compose URL: use the address we want to connect to, set Host: header later */
snprintf (url, DEFAULT_BUFFER_SIZE, "%s://%s:%d%s",
use_ssl ? "https" : "http",
- use_ssl & host_name != NULL ? host_name : server_address,
+ ( use_ssl & ( host_name != NULL ) ) ? host_name : server_address,
server_port,
server_url
);

View file

@ -1,129 +0,0 @@
From ce85affd208cd8c873dd88c17b8d3d0540c8872e Mon Sep 17 00:00:00 2001
From: Patrick Uiterwijk <patrick@puiterwijk.org>
Date: Thu, 13 Dec 2018 18:24:53 +0100
Subject: [PATCH 1/5] check_smtp: Add option to prefix PROXY header
This enables checks of SMTP servers that expect the haproxy
PROXY protocol: -o smtpd_upstream_proxy_protocol=haproxy.
Backported from nagios-plugins:
https://github.com/nagios-plugins/nagios-plugins/commit/3246efe923b5482c5024c40e593ce942e628a3cb
---
plugins/check_smtp.c | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c
index eaa7eebab..addabfc66 100644
--- a/plugins/check_smtp.c
+++ b/plugins/check_smtp.c
@@ -52,6 +52,7 @@ int days_till_exp_warn, days_till_exp_crit;
enum {
SMTP_PORT = 25
};
+#define PROXY_PREFIX "PROXY TCP4 0.0.0.0 0.0.0.0 25 25\r\n"
#define SMTP_EXPECT "220"
#define SMTP_HELO "HELO "
#define SMTP_EHLO "EHLO "
@@ -102,6 +103,7 @@ double critical_time = 0;
int check_critical_time = FALSE;
int verbose = 0;
int use_ssl = FALSE;
+short use_proxy_prefix = FALSE;
short use_ehlo = FALSE;
short use_lhlo = FALSE;
short ssl_established = 0;
@@ -184,6 +186,13 @@ main (int argc, char **argv)
if (result == STATE_OK) { /* we connected */
+ /* If requested, send PROXY header */
+ if (use_proxy_prefix) {
+ if (verbose)
+ printf ("Sending header %s\n", PROXY_PREFIX);
+ send(sd, PROXY_PREFIX, strlen(PROXY_PREFIX), 0);
+ }
+
/* watch for the SMTP connection string and */
/* return a WARNING status if we couldn't read any data */
if (recvlines(buffer, MAX_INPUT_BUFFER) <= 0) {
@@ -478,6 +487,7 @@ process_arguments (int argc, char **argv)
{"starttls",no_argument,0,'S'},
{"certificate",required_argument,0,'D'},
{"ignore-quit-failure",no_argument,0,'q'},
+ {"proxy",no_argument,0,'r'},
{0, 0, 0, 0}
};
@@ -494,7 +504,7 @@ process_arguments (int argc, char **argv)
}
while (1) {
- c = getopt_long (argc, argv, "+hVv46Lt:p:f:e:c:w:H:C:R:SD:F:A:U:P:q",
+ c = getopt_long (argc, argv, "+hVv46Lrt:p:f:e:c:w:H:C:R:SD:F:A:U:P:q",
longopts, &option);
if (c == -1 || c == EOF)
@@ -621,6 +631,9 @@ process_arguments (int argc, char **argv)
use_ssl = TRUE;
use_ehlo = TRUE;
break;
+ case 'r':
+ use_proxy_prefix = TRUE;
+ break;
case 'L':
use_lhlo = TRUE;
break;
@@ -819,6 +832,8 @@ print_help (void)
printf (" %s\n", _("FROM-address to include in MAIL command, required by Exchange 2000")),
printf (" %s\n", "-F, --fqdn=STRING");
printf (" %s\n", _("FQDN used for HELO"));
+ printf (" %s\n", "-r, --proxy");
+ printf (" %s\n", _("Use PROXY protocol prefix for the connection."));
#ifdef HAVE_SSL
printf (" %s\n", "-D, --certificate=INTEGER[,INTEGER]");
printf (" %s\n", _("Minimum number of days a certificate has to be valid."));
From 6d5e81fcbadbef557cf3f61ce7fd6ef73e25683e Mon Sep 17 00:00:00 2001
From: Franz Schwartau <franz@electromail.org>
Date: Mon, 12 Jun 2023 15:55:32 +0200
Subject: [PATCH 2/5] check_smtp: add missing -r option in usage
---
plugins/check_smtp.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c
index addabfc66..a1debd25f 100644
--- a/plugins/check_smtp.c
+++ b/plugins/check_smtp.c
@@ -875,6 +875,6 @@ print_usage (void)
printf ("%s\n", _("Usage:"));
printf ("%s -H host [-p port] [-4|-6] [-e expect] [-C command] [-R response] [-f from addr]\n", progname);
printf ("[-A authtype -U authuser -P authpass] [-w warn] [-c crit] [-t timeout] [-q]\n");
- printf ("[-F fqdn] [-S] [-L] [-D warn days cert expire[,crit days cert expire]] [-v] \n");
+ printf ("[-F fqdn] [-S] [-L] [-D warn days cert expire[,crit days cert expire]] [-r] [-v] \n");
}
From d762fb137401491270c898febe07e34ba200e388 Mon Sep 17 00:00:00 2001
From: Franz Schwartau <franz@electromail.org>
Date: Mon, 12 Jun 2023 22:09:54 +0200
Subject: [PATCH 5/5] check_smtp: update year in copyright header
---
plugins/check_smtp.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c
index a1debd25f..70191ad92 100644
--- a/plugins/check_smtp.c
+++ b/plugins/check_smtp.c
@@ -3,7 +3,7 @@
* Monitoring check_smtp plugin
*
* License: GPL
-* Copyright (c) 2000-2007 Monitoring Plugins Development Team
+* Copyright (c) 2000-2023 Monitoring Plugins Development Team
*
* Description:
*

View file

@ -1,86 +0,0 @@
From 252272344ea63a164eabc1631e9b77450d2b1c4b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Arkadiusz=20Mi=C5=9Bkiewicz?= <arekm@maven.pl>
Date: Fri, 30 Aug 2019 11:30:10 +0200
Subject: [PATCH 1/2] Add support for SNI in check_smtp.
Add support for SSL/TLS hostname extension support (SNI) for check_smtp
plugin.
Backported from nagios-plugins:
https://github.com/nagios-plugins/nagios-plugins/commit/9f1628f4b5525335ce1d6e48e8ac8b07d0757f82
---
plugins/check_smtp.c | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c
index 70191ad92..c0ab838ac 100644
--- a/plugins/check_smtp.c
+++ b/plugins/check_smtp.c
@@ -103,6 +103,7 @@ double critical_time = 0;
int check_critical_time = FALSE;
int verbose = 0;
int use_ssl = FALSE;
+int use_sni = FALSE;
short use_proxy_prefix = FALSE;
short use_ehlo = FALSE;
short use_lhlo = FALSE;
@@ -234,7 +235,7 @@ main (int argc, char **argv)
smtp_quit();
return STATE_UNKNOWN;
}
- result = np_net_ssl_init(sd);
+ result = np_net_ssl_init_with_hostname(sd, (use_sni ? server_address : NULL));
if(result != STATE_OK) {
printf (_("CRITICAL - Cannot create SSL context.\n"));
close(sd);
@@ -463,6 +464,10 @@ process_arguments (int argc, char **argv)
int c;
char* temp;
+ enum {
+ SNI_OPTION
+ };
+
int option = 0;
static struct option longopts[] = {
{"hostname", required_argument, 0, 'H'},
@@ -485,6 +490,7 @@ process_arguments (int argc, char **argv)
{"help", no_argument, 0, 'h'},
{"lmtp", no_argument, 0, 'L'},
{"starttls",no_argument,0,'S'},
+ {"sni", no_argument, 0, SNI_OPTION},
{"certificate",required_argument,0,'D'},
{"ignore-quit-failure",no_argument,0,'q'},
{"proxy",no_argument,0,'r'},
@@ -631,6 +637,13 @@ process_arguments (int argc, char **argv)
use_ssl = TRUE;
use_ehlo = TRUE;
break;
+ case SNI_OPTION:
+#ifdef HAVE_SSL
+ use_sni = TRUE;
+#else
+ usage (_("SSL support not available - install OpenSSL and recompile"));
+#endif
+ break;
case 'r':
use_proxy_prefix = TRUE;
break;
@@ -839,6 +852,8 @@ print_help (void)
printf (" %s\n", _("Minimum number of days a certificate has to be valid."));
printf (" %s\n", "-S, --starttls");
printf (" %s\n", _("Use STARTTLS for the connection."));
+ printf (" %s\n", "--sni");
+ printf (" %s\n", _("Enable SSL/TLS hostname extension support (SNI)"));
#endif
printf (" %s\n", "-A, --authtype=STRING");
@@ -875,6 +890,6 @@ print_usage (void)
printf ("%s\n", _("Usage:"));
printf ("%s -H host [-p port] [-4|-6] [-e expect] [-C command] [-R response] [-f from addr]\n", progname);
printf ("[-A authtype -U authuser -P authpass] [-w warn] [-c crit] [-t timeout] [-q]\n");
- printf ("[-F fqdn] [-S] [-L] [-D warn days cert expire[,crit days cert expire]] [-r] [-v] \n");
+ printf ("[-F fqdn] [-S] [-L] [-D warn days cert expire[,crit days cert expire]] [-r] [--sni] [-v] \n");
}

22
debian/patches/series vendored
View file

@ -1,26 +1,4 @@
02_check_icmp_links
03_epn
# commited upstream
10_check_http_chunked_wo_actual_content
11_fallback_for_gnutls
12_check_curl_improvements
13_check_icmp_improvements
14_check_curl_fix_SSL_with_multiple_IPs
15_check_swap_remove_includes
16_check_snmp_disable_multiplier_when_unused
17_fix_exit_codes
18_check_mysql_fix_typo
19_check_nwstat_fix_typo
20_chech_nt_fix_encoding
21_check_pgsql_extra_output
22_check_disk_avoid_mount
23_check_mysql_fix_error_handling
24_check_disk_fix_SI_units
# feature patches
30_check_radius_radcli_1.3.1_support
31_check_mailq_separate_submission_queue
32_check_disk_add_ignore_missing
33_check_procs_exclude-process
34_check_curl_fix_compare_warning
36_check_smtp_adding_proxy_header
37_check_smtp_Adding_SNI