[pkg-nagios-changes] [Git][nagios-team/monitoring-plugins][master] 4 commits: Adding d/p/27_check_snmp_add_multiplier
Jan Wagner (@waja)
gitlab at salsa.debian.org
Fri Jan 20 11:48:01 GMT 2023
Jan Wagner pushed to branch master at Debian Nagios Maintainer Group / monitoring-plugins
Commits:
e99bd7b1 by Jan Wagner at 2023-01-20T11:41:24+00:00
Adding d/p/27_check_snmp_add_multiplier
- - - - -
73742e9c by Jan Wagner at 2023-01-20T11:42:26+00:00
Adding d/p/28_check_snmp_fix_regex_matches from upstream
- - - - -
4f70a9dd by Jan Wagner at 2023-01-20T11:44:45+00:00
Adding d/p/29_check_log_polish from upstream
- - - - -
4f7eea1c by Jan Wagner at 2023-01-20T11:47:15+00:00
Adding d/p/30_check_disk_clarify_usage_possibilites from upstream
- - - - -
5 changed files:
- + debian/patches/27_check_snmp_add_multiplier
- + debian/patches/28_check_snmp_fix_regex_matches
- + debian/patches/29_check_log_polish
- + debian/patches/30_check_disk_clarify_usage_possibilites
- debian/patches/series
Changes:
=====================================
debian/patches/27_check_snmp_add_multiplier
=====================================
@@ -0,0 +1,372 @@
+From 403cbe5d8bd073277f188bdb729ad3333855ab39 Mon Sep 17 00:00:00 2001
+From: Wolfgang Nieder <wnd at gmx.net>
+Date: Sat, 7 Jul 2018 09:12:44 +0200
+Subject: [PATCH 1/3] add 'multiplier' to modify current value
+
+---
+ plugins/check_snmp.c | 84 +++++++++++++++++++++++++++-----------
+ plugins/tests/check_snmp.t | 12 ++++--
+ 2 files changed, 70 insertions(+), 26 deletions(-)
+
+diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c
+index 2601ccd89..d407609f5 100644
+--- a/plugins/check_snmp.c
++++ b/plugins/check_snmp.c
+@@ -1,31 +1,31 @@
+ /*****************************************************************************
+-*
++*
+ * Monitoring check_snmp plugin
+-*
++*
+ * License: GPL
+ * Copyright (c) 1999-2007 Monitoring Plugins Development Team
+-*
++*
+ * Description:
+-*
++*
+ * This file contains the check_snmp plugin
+-*
++*
+ * Check status of remote machines and obtain system information via SNMP
+-*
+-*
++*
++*
+ * 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/>.
+-*
+-*
++*
++*
+ *****************************************************************************/
+
+ const char *progname = "check_snmp";
+@@ -90,6 +90,7 @@ char *thisarg (char *str);
+ char *nextarg (char *str);
+ void print_usage (void);
+ void print_help (void);
++char *multiply (char *str);
+
+ #include "regex.h"
+ char regex_expect[MAX_INPUT_BUFFER] = "";
+@@ -154,6 +155,8 @@ double *previous_value;
+ size_t previous_size = OID_COUNT_STEP;
+ int perf_labels = 1;
+ char* ip_version = "";
++double multiplier = 1.0;
++char *fmtstr = "";
+
+ static char *fix_snmp_range(char *th)
+ {
+@@ -316,7 +319,7 @@ main (int argc, char **argv)
+ for (i = 0; i < numcontext; i++) {
+ command_line[10 + i] = contextargs[i];
+ }
+-
++
+ for (i = 0; i < numauthpriv; i++) {
+ command_line[10 + numcontext + i] = authpriv[i];
+ }
+@@ -330,7 +333,7 @@ main (int argc, char **argv)
+
+ for (i = 0; i < numoids; i++) {
+ command_line[10 + numcontext + numauthpriv + 1 + i] = oids[i];
+- xasprintf(&cl_hidden_auth, "%s %s", cl_hidden_auth, oids[i]);
++ xasprintf(&cl_hidden_auth, "%s %s", cl_hidden_auth, oids[i]);
+ }
+
+ command_line[10 + numcontext + numauthpriv + 1 + numoids] = NULL;
+@@ -398,15 +401,15 @@ main (int argc, char **argv)
+ is_counter=0;
+ /* We strip out the datatype indicator for PHBs */
+ if (strstr (response, "Gauge: ")) {
+- show = strstr (response, "Gauge: ") + 7;
+- }
++ show = multiply (strstr (response, "Gauge: ") + 7);
++ }
+ else if (strstr (response, "Gauge32: ")) {
+- show = strstr (response, "Gauge32: ") + 9;
+- }
++ show = multiply (strstr (response, "Gauge32: ") + 9);
++ }
+ else if (strstr (response, "Counter32: ")) {
+ show = strstr (response, "Counter32: ") + 11;
+ is_counter=1;
+- if(!calculate_rate)
++ if(!calculate_rate)
+ strcpy(type, "c");
+ }
+ else if (strstr (response, "Counter64: ")) {
+@@ -416,7 +419,10 @@ main (int argc, char **argv)
+ strcpy(type, "c");
+ }
+ else if (strstr (response, "INTEGER: ")) {
+- show = strstr (response, "INTEGER: ") + 9;
++ show = multiply (strstr (response, "INTEGER: ") + 9);
++ if (fmtstr != "") {
++ conv = fmtstr;
++ }
+ }
+ else if (strstr (response, "OID: ")) {
+ show = strstr (response, "OID: ") + 5;
+@@ -616,7 +622,7 @@ main (int argc, char **argv)
+ state_string=malloc(string_length);
+ if(state_string==NULL)
+ die(STATE_UNKNOWN, _("Cannot malloc"));
+-
++
+ current_length=0;
+ for(i=0; i<total_oids; i++) {
+ xasprintf(&temp_string,"%.0f",response_value[i]);
+@@ -638,7 +644,7 @@ main (int argc, char **argv)
+ state_string[--current_length]='\0';
+ if (verbose > 2)
+ printf("State string=%s\n",state_string);
+-
++
+ /* This is not strictly the same as time now, but any subtle variations will cancel out */
+ np_state_write_string(current_time, state_string );
+ if(previous_state==NULL) {
+@@ -698,6 +704,8 @@ process_arguments (int argc, char **argv)
+ {"perf-oids", no_argument, 0, 'O'},
+ {"ipv4", no_argument, 0, '4'},
+ {"ipv6", no_argument, 0, '6'},
++ {"multiplier", required_argument, 0, 'M'},
++ {"fmtstr", required_argument, 0, 'f'},
+ {0, 0, 0, 0}
+ };
+
+@@ -715,7 +723,7 @@ process_arguments (int argc, char **argv)
+ }
+
+ while (1) {
+- c = getopt_long (argc, argv, "nhvVO46t:c:w:H:C:o:e:E:d:D:s:t:R:r:l:u:p:m:P:N:L:U:a:x:A:X:z:",
++ c = getopt_long (argc, argv, "nhvVO46t:c:w:H:C:o:e:E:d:D:s:t:R:r:l:u:p:m:P:N:L:U:a:x:A:X:M:f:z:",
+ longopts, &option);
+
+ if (c == -1 || c == EOF)
+@@ -953,6 +961,16 @@ process_arguments (int argc, char **argv)
+ if(verbose>2)
+ printf("IPv6 detected! Will pass \"udp6:\" to snmpget.\n");
+ break;
++ case 'M':
++ if ( strspn( optarg, "0123456789.," ) == strlen( optarg ) ) {
++ multiplier=strtod(optarg,NULL);
++ }
++ break;
++ case 'f':
++ if (multiplier != 1.0) {
++ fmtstr=optarg;
++ }
++ break;
+ }
+ }
+
+@@ -1022,7 +1040,7 @@ validate_arguments ()
+ contextargs[0] = strdup ("-n");
+ contextargs[1] = strdup (context);
+ }
+-
++
+ if (seclevel == NULL)
+ xasprintf(&seclevel, "noAuthNoPriv");
+
+@@ -1143,6 +1161,21 @@ nextarg (char *str)
+
+
+
++/* multiply result (values 0 < n < 1 work as divider) */
++char *
++multiply (char *str)
++{
++ double val = strtod (str, NULL);
++ val *= multiplier;
++ if (val == (int)val) {
++ sprintf(str, "%.0f", val);
++ } else {
++ sprintf(str, "%f", val);
++ }
++ return str;
++}
++
++
+ void
+ print_help (void)
+ {
+@@ -1235,6 +1268,10 @@ print_help (void)
+ printf (" %s\n", _("Units label(s) for output data (e.g., 'sec.')."));
+ printf (" %s\n", "-D, --output-delimiter=STRING");
+ printf (" %s\n", _("Separates output on multiple OID requests"));
++ printf (" %s\n", "-M, --multiplier=FLOAT");
++ printf (" %s\n", _("Multiplies current value, 0 < n < 1 works as divider, defaults to 1"));
++ printf (" %s\n", "-f, --fmtstr=STRING");
++ printf (" %s\n", _("C-style format string for float values (see option -M)"));
+
+ printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);
+ printf (" %s\n", _("NOTE the final timeout value is calculated using this formula: timeout_interval * retries + 5"));
+@@ -1287,4 +1324,5 @@ print_usage (void)
+ printf ("[-l label] [-u units] [-p port-number] [-d delimiter] [-D output-delimiter]\n");
+ printf ("[-m miblist] [-P snmp version] [-N context] [-L seclevel] [-U secname]\n");
+ printf ("[-a authproto] [-A authpasswd] [-x privproto] [-X privpasswd] [-4|6]\n");
++ printf ("[-M multiplier [-f format]]\n");
+ }
+diff --git a/plugins/tests/check_snmp.t b/plugins/tests/check_snmp.t
+index 0a77fa8ad..e9cc02135 100755
+--- a/plugins/tests/check_snmp.t
++++ b/plugins/tests/check_snmp.t
+@@ -9,7 +9,7 @@ use NPTest;
+ use FindBin qw($Bin);
+ use POSIX qw/strftime/;
+
+-my $tests = 73;
++my $tests = 75;
+ # Check that all dependent modules are available
+ eval {
+ require NetSNMP::OID;
+@@ -57,9 +57,9 @@ if ($pid) {
+ exec("snmpd -c tests/conf/snmpd.conf -C -f -r udp:$port_snmp");
+ }
+
+-END {
++END {
+ foreach my $pid (@pids) {
+- if ($pid) { print "Killing $pid\n"; kill "INT", $pid }
++ if ($pid) { print "Killing $pid\n"; kill "INT", $pid }
+ }
+ };
+
+@@ -268,3 +268,9 @@ like($res->output, '/SNMP WARNING - \d+ \*-4\* | iso.3.6.1.4.1.8072.3.2.67.10=\d
+ $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10,.1.3.6.1.4.1.8072.3.2.67.17 -w 1,2 -c 1" );
+ is($res->return_code, 2, "Multiple OIDs with some thresholds" );
+ like($res->output, '/SNMP CRITICAL - \*\d+\* \*-4\* | iso.3.6.1.4.1.8072.3.2.67.10=\d+c;1;2 iso.3.6.1.4.1.8072.3.2.67.17=-4;;/', "Multiple OIDs with thresholds output" );
++
++$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.2.1.25.2.2.0 -M .125 ");
++is($res->return_code, 0, "Multiply OK" );
++
++$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.2.1.25.2.2.0 --multiplier=.0009765625 -f '%.3f' ");
++is($res->return_code, 0, "Multiply format OK" );
+
+From fdde61e978c4251b67ce4db42e4f5797c087cbec Mon Sep 17 00:00:00 2001
+From: Robert Bohne <robert.bohne at redhat.com>
+Date: Fri, 11 Nov 2022 11:10:44 +0100
+Subject: [PATCH 2/3] Improve tests for check_snmp & multiply option
+
+---
+ plugins/tests/check_snmp.t | 20 +++++++++++++++-----
+ plugins/tests/check_snmp_agent.pl | 8 ++++----
+ 2 files changed, 19 insertions(+), 9 deletions(-)
+
+diff --git a/plugins/tests/check_snmp.t b/plugins/tests/check_snmp.t
+index e9cc02135..bb5b8db66 100755
+--- a/plugins/tests/check_snmp.t
++++ b/plugins/tests/check_snmp.t
+@@ -9,7 +9,7 @@ use NPTest;
+ use FindBin qw($Bin);
+ use POSIX qw/strftime/;
+
+-my $tests = 75;
++my $tests = 81;
+ # Check that all dependent modules are available
+ eval {
+ require NetSNMP::OID;
+@@ -269,8 +269,18 @@ $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1
+ is($res->return_code, 2, "Multiple OIDs with some thresholds" );
+ like($res->output, '/SNMP CRITICAL - \*\d+\* \*-4\* | iso.3.6.1.4.1.8072.3.2.67.10=\d+c;1;2 iso.3.6.1.4.1.8072.3.2.67.17=-4;;/', "Multiple OIDs with thresholds output" );
+
+-$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.2.1.25.2.2.0 -M .125 ");
+-is($res->return_code, 0, "Multiply OK" );
++$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.19");
++is($res->return_code, 0, "Test plain .1.3.6.1.4.1.8072.3.2.67.6 RC" );
++is($res->output,'SNMP OK - 42 | iso.3.6.1.4.1.8072.3.2.67.19=42 ', "Test plain value of .1.3.6.1.4.1.8072.3.2.67.1" );
+
+-$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.2.1.25.2.2.0 --multiplier=.0009765625 -f '%.3f' ");
+-is($res->return_code, 0, "Multiply format OK" );
++$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.19 -M .1");
++is($res->return_code, 0, "Test multiply RC" );
++is($res->output,'SNMP OK - 4.200000 | iso.3.6.1.4.1.8072.3.2.67.19=4.200000 ' , "Test multiply .1 output" );
++
++$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.19 --multiplier=.1 -f '%.2f' ");
++is($res->return_code, 0, "Test multiply RC + format" );
++is($res->output, 'SNMP OK - 4.200000 | iso.3.6.1.4.1.8072.3.2.67.19=4.200000 ', "Test multiply .1 output + format" );
++
++$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.19 --multiplier=.1 -f '%.2f' -w 1");
++is($res->return_code, 1, "Test multiply RC + format + thresholds" );
++is($res->output, 'SNMP WARNING - *4.20* | iso.3.6.1.4.1.8072.3.2.67.19=4.20;1 ', "Test multiply .1 output + format + thresholds" );
+diff --git a/plugins/tests/check_snmp_agent.pl b/plugins/tests/check_snmp_agent.pl
+index 0e41d575d..38912e98b 100644
+--- a/plugins/tests/check_snmp_agent.pl
++++ b/plugins/tests/check_snmp_agent.pl
+@@ -32,11 +32,11 @@
+ because we\'re not done yet!';
+
+ # Next are arrays of indexes (Type, initial value and increments)
+-# 0..16 <---- please update comment when adding/removing fields
+-my @fields = (ASN_OCTET_STR, ASN_OCTET_STR, ASN_OCTET_STR, ASN_OCTET_STR, ASN_OCTET_STR, ASN_UNSIGNED, ASN_UNSIGNED, ASN_COUNTER, ASN_COUNTER64, ASN_UNSIGNED, ASN_COUNTER, ASN_OCTET_STR, ASN_OCTET_STR, ASN_OCTET_STR, ASN_OCTET_STR, ASN_OCTET_STR, ASN_INTEGER, ASN_OCTET_STR, ASN_OCTET_STR );
+-my @values = ($multiline, $multilin2, $multilin3, $multilin4, $multilin5, 4294965296, 1000, 4294965296, uint64("18446744073709351616"), int(rand(2**32)), 64000, "stringtests", "3.5", "87.4startswithnumberbutshouldbestring", '555"I said"', 'CUSTOM CHECK OK: foo is 12345', -2, '-4', '-6.6' );
++# 0..19 <---- please update comment when adding/removing fields
++my @fields = (ASN_OCTET_STR, ASN_OCTET_STR, ASN_OCTET_STR, ASN_OCTET_STR, ASN_OCTET_STR, ASN_UNSIGNED, ASN_UNSIGNED, ASN_COUNTER, ASN_COUNTER64, ASN_UNSIGNED, ASN_COUNTER, ASN_OCTET_STR, ASN_OCTET_STR, ASN_OCTET_STR, ASN_OCTET_STR, ASN_OCTET_STR, ASN_INTEGER, ASN_OCTET_STR, ASN_OCTET_STR, ASN_INTEGER );
++my @values = ($multiline, $multilin2, $multilin3, $multilin4, $multilin5, 4294965296, 1000, 4294965296, uint64("18446744073709351616"), int(rand(2**32)), 64000, "stringtests", "3.5", "87.4startswithnumberbutshouldbestring", '555"I said"', 'CUSTOM CHECK OK: foo is 12345', -2, '-4', '-6.6', 42 );
+ # undef increments are randomized
+-my @incrts = (undef, undef, undef, undef, undef, 1000, -500, 1000, 100000, undef, 666, undef, undef, undef, undef, undef, -1, undef, undef );
++my @incrts = (undef, undef, undef, undef, undef, 1000, -500, 1000, 100000, undef, 666, undef, undef, undef, undef, undef, -1, undef, undef, 0 );
+
+ # Number of elements in our OID
+ my $oidelts;
+
+From 84dddab6fe6315bbe4ad5197b9a4b56ebc89e007 Mon Sep 17 00:00:00 2001
+From: Sven Nierlein <sven at nierlein.de>
+Date: Thu, 22 Dec 2022 12:02:52 +0100
+Subject: [PATCH 3/3] check_snmp: always apply format when applying multiplier
+
+---
+ plugins/check_snmp.c | 6 +++++-
+ plugins/tests/check_snmp.t | 2 +-
+ 2 files changed, 6 insertions(+), 2 deletions(-)
+
+diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c
+index d407609f5..56bad8800 100644
+--- a/plugins/check_snmp.c
++++ b/plugins/check_snmp.c
+@@ -1167,10 +1167,14 @@ multiply (char *str)
+ {
+ double val = strtod (str, NULL);
+ val *= multiplier;
++ char *conv = "%f";
++ if (fmtstr != "") {
++ conv = fmtstr;
++ }
+ if (val == (int)val) {
+ sprintf(str, "%.0f", val);
+ } else {
+- sprintf(str, "%f", val);
++ sprintf(str, conv, val);
+ }
+ return str;
+ }
+diff --git a/plugins/tests/check_snmp.t b/plugins/tests/check_snmp.t
+index bb5b8db66..bc03ec604 100755
+--- a/plugins/tests/check_snmp.t
++++ b/plugins/tests/check_snmp.t
+@@ -279,7 +279,7 @@ is($res->output,'SNMP OK - 4.200000 | iso.3.6.1.4.1.8072.3.2.67.19=4.200000 ' ,
+
+ $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.19 --multiplier=.1 -f '%.2f' ");
+ is($res->return_code, 0, "Test multiply RC + format" );
+-is($res->output, 'SNMP OK - 4.200000 | iso.3.6.1.4.1.8072.3.2.67.19=4.200000 ', "Test multiply .1 output + format" );
++is($res->output, 'SNMP OK - 4.20 | iso.3.6.1.4.1.8072.3.2.67.19=4.20 ', "Test multiply .1 output + format" );
+
+ $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.19 --multiplier=.1 -f '%.2f' -w 1");
+ is($res->return_code, 1, "Test multiply RC + format + thresholds" );
=====================================
debian/patches/28_check_snmp_fix_regex_matches
=====================================
@@ -0,0 +1,78 @@
+From 12d1b0cbab5469e230ea5b69b5f1fc411836de21 Mon Sep 17 00:00:00 2001
+From: Sven Nierlein <sven at nierlein.de>
+Date: Thu, 19 Jan 2023 23:29:01 +0100
+Subject: [PATCH] fix check_snmp regex matches
+
+the multiplier function always tried to extract a number, even if the result
+is a string because of using a mib.
+
+before:
+```
+./check_snmp -H hostname -P2c -c public -o IF-MIB::ifAdminStatus.11466 -vvv -r 0
+/usr/bin/snmpget -Le -t 10 -r 5 -m ALL -v 2c [context] [authpriv] 10.0.13.11:161 IF-MIB::ifAdminStatus.11466
+IF-MIB::ifAdminStatus.11466 = INTEGER: up(1)
+Processing oid 1 (line 1)
+ oidname: IF-MIB::ifAdminStatus.11466
+ response: = INTEGER: up(1)
+SNMP OK - 0 | IF-MIB::ifAdminStatus.11466=0;;
+```
+
+the regexp 0 matches, even if the actual result is "up(1)".
+
+after this patch:
+```
+./check_snmp -H hostname -P2c -c public -o IF-MIB::ifAdminStatus.11466 -vvv -r 0
+/usr/bin/snmpget -Le -t 10 -r 5 -m ALL -v 2c [context] [authpriv] 10.0.13.11:161 IF-MIB::ifAdminStatus.11466
+IF-MIB::ifAdminStatus.11466 = INTEGER: up(1)
+Processing oid 1 (line 1)
+ oidname: IF-MIB::ifAdminStatus.11466
+ response: = INTEGER: up(1)
+SNMP CRITICAL - *up(1)* |
+```
+---
+ plugins/check_snmp.c | 23 +++++++++++++++++++++--
+ 1 file changed, 21 insertions(+), 2 deletions(-)
+
+diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c
+index 56bad8800..d3968a27d 100644
+--- a/plugins/check_snmp.c
++++ b/plugins/check_snmp.c
+@@ -1165,17 +1165,36 @@ nextarg (char *str)
+ char *
+ multiply (char *str)
+ {
+- double val = strtod (str, NULL);
+- val *= multiplier;
++ char *endptr;
++ double val;
+ char *conv = "%f";
++
++ if(verbose>2)
++ printf(" multiply input: %s\n", 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;
++ }
++
++ if(verbose>2)
++ printf(" multiply extracted double: %f\n", val);
++ val *= multiplier;
+ if (fmtstr != "") {
+ conv = fmtstr;
+ }
+ if (val == (int)val) {
+ sprintf(str, "%.0f", val);
+ } else {
++ if(verbose>2)
++ printf(" multiply using format: %s\n", conv);
+ sprintf(str, conv, val);
+ }
++ if(verbose>2)
++ printf(" multiply result: %s\n", str);
+ return str;
+ }
+
=====================================
debian/patches/29_check_log_polish
=====================================
@@ -0,0 +1,319 @@
+From 6408677bb1cefd03364965bf0e09a6dd450154d9 Mon Sep 17 00:00:00 2001
+From: lgmu <80966566+lgmu at users.noreply.github.com>
+Date: Thu, 19 Jan 2023 11:33:25 +0100
+Subject: [PATCH 1/3] Added --exclude, cleanup args, fix -a count bug
+
+Added --exclude to exclude patterns
+Cleaned up duplicated code in the args
+Fixed a bug when using --all because the count always returned "1" even when nothing matched
+
+entry=$($GREP "$query" "$tempdiff")
+count=$(echo "$entry" | wc -l)
+
+Example:
+
+$ touch testfile
+$ TEST123=$(grep 'test' testfile)
+$ echo "$TEST123" | wc -l
+1
+---
+ plugins-scripts/check_log.sh | 91 ++++++++++++------------------------
+ 1 file changed, 31 insertions(+), 60 deletions(-)
+
+diff --git a/plugins-scripts/check_log.sh b/plugins-scripts/check_log.sh
+index fdb574168..1ea70b562 100755
+--- a/plugins-scripts/check_log.sh
++++ b/plugins-scripts/check_log.sh
+@@ -18,7 +18,7 @@
+ # On the first run of the plugin, it will return an OK state with a message
+ # of "Log check data initialized". On successive runs, it will return an OK
+ # state if *no* pattern matches have been found in the *difference* between the
+-# log file and the older copy of the log file. If the plugin detects any
++# log file and the older copy of the log file. If the plugin detects any
+ # pattern matches in the log diff, it will return a CRITICAL state and print
+ # out a message is the following format: "(x) last_match", where "x" is the
+ # total number of pattern matches found in the file and "last_match" is the
+@@ -76,6 +76,7 @@ print_usage() {
+ echo ""
+ echo "Other parameters:"
+ echo " -a|--all : Print all matching lines"
++ echo " --exclude: Exclude a pattern (-p or -e also applies here when used)"
+ echo " -p|--perl-regex : Use perl style regular expressions in the query"
+ echo " -e|--extended-regex : Use extended style regular expressions in the query (not necessary for GNU grep)"
+ }
+@@ -99,82 +100,46 @@ if [ $# -lt 1 ]; then
+ fi
+
+ # Grab the command line arguments
+-
+-#logfile=$1
+-#oldlog=$2
+-#query=$3
+ exitstatus=$STATE_WARNING #default
+ while test -n "$1"; do
+ case "$1" in
+- --help)
+- print_help
+- exit "$STATE_OK"
+- ;;
+- -h)
++ -h | --help)
+ print_help
+ exit "$STATE_OK"
+ ;;
+- --version)
+- print_revision "$PROGNAME" "$REVISION"
+- exit "$STATE_OK"
+- ;;
+- -V)
++ -V | --version)
+ print_revision "$PROGNAME" "$REVISION"
+ exit "$STATE_OK"
+ ;;
+- --filename)
++ -F | --filename)
+ logfile=$2
+ shift 2
+ ;;
+- -F)
+- logfile=$2
+- shift 2
+- ;;
+- --oldlog)
++ -O | --oldlog)
+ oldlog=$2
+ shift 2
+ ;;
+- -O)
+- oldlog=$2
+- shift 2
+- ;;
+- --query)
+- query=$2
+- shift 2
+- ;;
+- -q)
++ -q | --query)
+ query=$2
+ shift 2
+ ;;
+- -x)
+- exitstatus=$2
++ --exclude)
++ exclude=$2
+ shift 2
+ ;;
+- --exitstatus)
++ -x | --exitstatus)
+ exitstatus=$2
+ shift 2
+ ;;
+- --extended-regex)
++ -e | --extended-regex)
+ ERE=1
+ shift
+ ;;
+- -e)
+- ERE=1
+- shift
+- ;;
+- --perl-regex)
+- PRE=1
+- shift
+- ;;
+- -p)
++ -p | --perl-regex)
+ PRE=1
+ shift
+ ;;
+- --all)
+- ALL=1
+- shift
+- ;;
+- -a)
++ -a | --all)
+ ALL=1
+ shift
+ ;;
+@@ -213,8 +178,8 @@ elif [ ! -r "$logfile" ] ; then
+ fi
+ # If no oldlog was given this can not work properly, abort then
+ if [ -z "$oldlog" ]; then
+- echo "Oldlog parameter is needed"
+- exit $STATE_UNKNOWN
++ echo "Oldlog parameter is needed"
++ exit $STATE_UNKNOWN
+ fi
+
+ # If the old log file doesn't exist, this must be the first time
+@@ -245,18 +210,24 @@ diff "$logfile" "$oldlog" | grep -v "^>" > "$tempdiff"
+
+
+ if [ $ALL ]; then
+- # Get the last matching entry in the diff file
+- entry=$($GREP "$query" "$tempdiff")
+-
+- # Count the number of matching log entries we have
+- count=$(echo "$entry" | wc -l)
++ # Get all matching entries in the diff file
++ if [ -n "$exclude" ]; then
++ entry=$($GREP "$query" "$tempdiff" | $GREP -v "$exclude")
++ count=$($GREP "$query" "$tempdiff" | $GREP -vc "$exclude")
++ else
++ entry=$($GREP "$query" "$tempdiff")
++ count=$($GREP -c "$query" "$tempdiff")
++ fi
+
+ else
+- # Count the number of matching log entries we have
+- count=$($GREP -c "$query" "$tempdiff")
+-
+- # Get the last matching entry in the diff file
+- entry=$($GREP "$query" "$tempdiff" | tail -1)
++ # Get the last matching entry in the diff file
++ if [ -n "$exclude" ]; then
++ entry=$($GREP "$query" "$tempdiff" | $GREP -v "$exclude" | tail -1)
++ count=$($GREP "$query" "$tempdiff" | $GREP -vc "$exclude")
++ else
++ entry=$($GREP "$query" "$tempdiff" | tail -1)
++ count=$($GREP -c "$query" "$tempdiff")
++ fi
+ fi
+
+ rm -f "$tempdiff"
+
+From 8eaf03494fc401da4d3db79105586907b41525ed Mon Sep 17 00:00:00 2001
+From: lgmu <80966566+lgmu at users.noreply.github.com>
+Date: Thu, 19 Jan 2023 11:37:45 +0100
+Subject: [PATCH 2/3] Fix indents
+
+---
+ plugins-scripts/check_log.sh | 8 ++++----
+ 1 file changed, 4 insertions(+), 4 deletions(-)
+
+diff --git a/plugins-scripts/check_log.sh b/plugins-scripts/check_log.sh
+index 1ea70b562..c623a8d6b 100755
+--- a/plugins-scripts/check_log.sh
++++ b/plugins-scripts/check_log.sh
+@@ -153,18 +153,18 @@ done
+
+ # Parameter sanity check
+ if [ $ERE ] && [ $PRE ] ; then
+- echo "Can not use extended and perl regex at the same time"
+- exit "$STATE_UNKNOWN"
++ echo "Can not use extended and perl regex at the same time"
++ exit "$STATE_UNKNOWN"
+ fi
+
+ GREP="grep"
+
+ if [ $ERE ]; then
+- GREP="grep -E"
++ GREP="grep -E"
+ fi
+
+ if [ $PRE ]; then
+- GREP="grep -P"
++ GREP="grep -P"
+ fi
+
+ # If the source log file doesn't exist, exit
+
+From 5b2d1c5bf38dfffe1c980d9425d60a96b99513cc Mon Sep 17 00:00:00 2001
+From: lorenzg <lorenz.gruenwald at consol.de>
+Date: Fri, 20 Jan 2023 08:52:38 +0100
+Subject: [PATCH 3/3] add tests for check_log
+
+---
+ plugins-scripts/t/check_log.t | 82 +++++++++++++++++++++++++++++++++++
+ 1 file changed, 82 insertions(+)
+ create mode 100644 plugins-scripts/t/check_log.t
+
+diff --git a/plugins-scripts/t/check_log.t b/plugins-scripts/t/check_log.t
+new file mode 100644
+index 000000000..b66e0fd88
+--- /dev/null
++++ b/plugins-scripts/t/check_log.t
+@@ -0,0 +1,82 @@
++#!/usr/bin/perl -w -I ..
++#
++# check_log tests
++#
++#
++
++use strict;
++use Test::More;
++use NPTest;
++
++my $tests = 18;
++plan tests => $tests;
++
++my $firstTimeOutput ='/^Log check data initialized/';
++my $okOutput = '/^Log check ok - 0 pattern matches found/';
++my $criticalOutput = '/^\(\d+\) < /';
++my $multilineOutput = '/\(3\) <.*\n.*\n.*$/';
++my $unknownOutput = '/^Usage: /';
++my $unknownArgOutput = '/^Unknown argument: /';
++my $bothRegexOutput = '/^Can not use extended and perl regex/';
++
++my $result;
++my $temp_file = "/tmp/check_log.tmp";
++my $oldlog = "/tmp/oldlog.tmp";
++
++open(FH, '>', $temp_file) or die $!;
++close(FH);
++
++$result = NPTest->testCmd("./check_log");
++cmp_ok( $result->return_code, '==', 3, "Missing parameters" );
++like ( $result->output, $unknownOutput, "Output for unknown correct" );
++
++$result = NPTest->testCmd("./check_log -f");
++cmp_ok( $result->return_code, '==', 3, "Wrong parameters" );
++like ( $result->output, $unknownArgOutput, "Output for unknown correct" );
++
++$result = NPTest->testCmd("./check_log -F ".$temp_file." -O ".$oldlog." -q 'Simple match' -e -p");
++cmp_ok( $result->return_code, '==', 3, "Both regex parameters" );
++like ( $result->output, $bothRegexOutput, "Output for unknown correct" );
++
++$result = NPTest->testCmd("./check_log -F ".$temp_file." -O ".$oldlog." -q 'Simple match'");
++cmp_ok( $result->return_code, '==', 0, "First time executing" );
++like ( $result->output, $firstTimeOutput, "Output for first time executing correct" );
++
++open(FH, '>>', $temp_file) or die $!;
++print FH "This is some text, that should not match\n";
++close(FH);
++
++$result = NPTest->testCmd("./check_log -F ".$temp_file." -O ".$oldlog." -q 'No match'");
++cmp_ok( $result->return_code, '==', 0, "No match" );
++like ( $result->output, $okOutput, "Output for no match correct" );
++
++open(FH, '>>', $temp_file) or die $!;
++print FH "This text should match\n";
++close(FH);
++
++$result = NPTest->testCmd("./check_log -F ".$temp_file." -O ".$oldlog." -q 'should match'");
++cmp_ok( $result->return_code, '==', 2, "Pattern match" );
++like ( $result->output, $criticalOutput, "Output for match correct" );
++
++open(FH, '>>', $temp_file) or die $!;
++print FH "This text should not match, because it is excluded\n";
++close(FH);
++
++$result = NPTest->testCmd("./check_log -F ".$temp_file." -O ".$oldlog." -q 'match' --exclude 'because'");
++cmp_ok( $result->return_code, '==', 0, "Exclude a pattern" );
++like ( $result->output, $okOutput, "Output for no match correct" );
++
++open(FH, '>>', $temp_file) or die $!;
++print FH "Trying\nwith\nmultiline\nignore me\n";
++close(FH);
++
++$result = NPTest->testCmd("./check_log -F ".$temp_file." -O ".$oldlog." -q 'Trying\\|with\\|multiline\\|ignore' --exclude 'me' --all");
++cmp_ok( $result->return_code, '==', 2, "Multiline pattern match with --all" );
++like ( $result->output, $multilineOutput, "Output for multiline match correct" );
++
++$result = NPTest->testCmd("./check_log -F ".$temp_file." -O ".$oldlog." -q 'match' -a");
++cmp_ok( $result->return_code, '==', 0, "Non matching --all" );
++like ( $result->output, $okOutput, "Output for no match correct" );
++
++unlink($oldlog);
++unlink($temp_file);
=====================================
debian/patches/30_check_disk_clarify_usage_possibilites
=====================================
@@ -0,0 +1,20 @@
+From 4fa72f14e814ca94e8ee75b444011bd553870ebe Mon Sep 17 00:00:00 2001
+From: RincewindsHat <12514511+RincewindsHat at users.noreply.github.com>
+Date: Sat, 29 Jan 2022 15:50:03 +0100
+Subject: [PATCH 1/4] Clarify usage possibilites of check_disk
+
+---
+ plugins/check_disk.c | 5 ++++-
+ 1 file changed, 4 insertions(+), 1 deletion(-)
+
+--- a/plugins/check_disk.c
++++ b/plugins/check_disk.c
+@@ -951,7 +951,7 @@
+ print_usage (void)
+ {
+ printf ("%s\n", _("Usage:"));
+- printf (" %s -w limit -c limit [-W limit] [-K limit] {-p path | -x device}\n", progname);
++ printf (" %s {-w absolute_limit |-w percentage_limit% | -W inode_percentage_limit } {-c absolute_limit|-c percentage_limit% | -K inode_percentage_limit } {-p path | -x device}\n", progname);
+ printf ("[-C] [-E] [-e] [-f] [-g group ] [-k] [-l] [-M] [-m] [-R path ] [-r path ]\n");
+ printf ("[-t timeout] [-u unit] [-v] [-X type] [-N type]\n");
+ }
=====================================
debian/patches/series
=====================================
@@ -15,3 +15,7 @@
24_check_apt_usage
25_spell_fixes
26_check_mailq_fix_nullmailer_regex
+27_check_snmp_add_multiplier
+28_check_snmp_fix_regex_matches
+29_check_log_polish
+30_check_disk_clarify_usage_possibilites
View it on GitLab: https://salsa.debian.org/nagios-team/monitoring-plugins/-/compare/ff160b6fe15b47eeb4b71815c5ef59b10590dddf...4f7eea1cd1c18a43c763d3ca50a911c0c5c3691b
--
View it on GitLab: https://salsa.debian.org/nagios-team/monitoring-plugins/-/compare/ff160b6fe15b47eeb4b71815c5ef59b10590dddf...4f7eea1cd1c18a43c763d3ca50a911c0c5c3691b
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-nagios-changes/attachments/20230120/a1b227a4/attachment-0001.htm>
More information about the pkg-nagios-changes
mailing list