Code

Fix for regex input of '|', being output causing problems with Nagios' parsing of
authorTon Voon <ton.voon@opsera.com>
Fri, 21 Jan 2011 13:14:33 +0000 (13:14 +0000)
committerTon Voon <ton.voon@opsera.com>
Fri, 21 Jan 2011 13:14:33 +0000 (13:14 +0000)
performance data. Now replaced with ','

NEWS
plugins/check_procs.c
plugins/tests/check_procs.t

diff --git a/NEWS b/NEWS
index aca62181292df4abd20dd0f40fe59828309275b4..540e0cfa83642a7256463777ed29c41f17c98d42 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -11,6 +11,7 @@ This file documents the major additions and syntax changes between releases.
        check_disk_smb now handles NT_STATUS_ACCESS_DENIED properly (Debian #601696) 
        Make check_snmp work more like v1.4.14 with regard to using special values (Timeticks, STRING) as numeric thresholds
        Fix check_ldap overriding the port when --ssl was specified after -p
        check_disk_smb now handles NT_STATUS_ACCESS_DENIED properly (Debian #601696) 
        Make check_snmp work more like v1.4.14 with regard to using special values (Timeticks, STRING) as numeric thresholds
        Fix check_ldap overriding the port when --ssl was specified after -p
+       Fix check_procs where regex input of '|' would get displayed in output - now replaced with ','
 
 1.4.15 27th July 2010
        ENHANCEMENTS
 
 1.4.15 27th July 2010
        ENHANCEMENTS
index 2151fb386facd262f57604870a2fd54e3fe62240..d875a618f3eb259644928f39b4299a650467aa13 100644 (file)
@@ -318,6 +318,8 @@ process_arguments (int argc, char **argv)
        int err;
        int cflags = REG_NOSUB | REG_EXTENDED;
        char errbuf[MAX_INPUT_BUFFER];
        int err;
        int cflags = REG_NOSUB | REG_EXTENDED;
        char errbuf[MAX_INPUT_BUFFER];
+       char *temp_string;
+       int i=0;
        static struct option longopts[] = {
                {"warning", required_argument, 0, 'w'},
                {"critical", required_argument, 0, 'c'},
        static struct option longopts[] = {
                {"warning", required_argument, 0, 'w'},
                {"critical", required_argument, 0, 'c'},
@@ -450,7 +452,14 @@ process_arguments (int argc, char **argv)
                                regerror (err, &re_args, errbuf, MAX_INPUT_BUFFER);
                                die (STATE_UNKNOWN, "PROCS %s: %s - %s\n", _("UNKNOWN"), _("Could not compile regular expression"), errbuf);
                        }
                                regerror (err, &re_args, errbuf, MAX_INPUT_BUFFER);
                                die (STATE_UNKNOWN, "PROCS %s: %s - %s\n", _("UNKNOWN"), _("Could not compile regular expression"), errbuf);
                        }
-                       asprintf (&fmt, "%s%sregex args '%s'", (fmt ? fmt : ""), (options ? ", " : ""), optarg);
+                       /* Strip off any | within the regex optarg */
+                       temp_string = strdup(optarg);
+                       while(temp_string[i]!='\0'){
+                               if(temp_string[i]=='|')
+                                       temp_string[i]=',';
+                               i++;
+                       }
+                       asprintf (&fmt, "%s%sregex args '%s'", (fmt ? fmt : ""), (options ? ", " : ""), temp_string);
                        options |= EREG_ARGS;
                        break;
                case 'r':                                       /* RSS */
                        options |= EREG_ARGS;
                        break;
                case 'r':                                       /* RSS */
index 1d0c034e5b0d157306e05814c2517db63e9beeab..d71c83a274016e9d752ed8c1d6169cc83f5bee38 100644 (file)
@@ -8,7 +8,7 @@ use Test::More;
 use NPTest;
 
 if (-x "./check_procs") {
 use NPTest;
 
 if (-x "./check_procs") {
-       plan tests => 48;
+       plan tests => 50;
 } else {
        plan skip_all => "No check_procs compiled";
 }
 } else {
        plan skip_all => "No check_procs compiled";
 }
@@ -113,3 +113,7 @@ $result = NPTest->testCmd( "$command --metric=RSS -c 70000 -v" );
 is( $result->return_code, 2, "Checking against RSS > 70MB" );
 is( $result->output, 'RSS CRITICAL: 5 crit, 0 warn out of 95 processes [WindowServer, SystemUIServer, Safari, Mail, Safari]', "Output correct" );
 
 is( $result->return_code, 2, "Checking against RSS > 70MB" );
 is( $result->output, 'RSS CRITICAL: 5 crit, 0 warn out of 95 processes [WindowServer, SystemUIServer, Safari, Mail, Safari]', "Output correct" );
 
+$result = NPTest->testCmd( "$command --ereg-argument-array='(nosuchname|nosuch2name)'" );
+is( $result->return_code, 0, "Checking no pipe symbol in output" );
+is( $result->output, "PROCS OK: 0 processes with regex args '(nosuchname,nosuch2name)'", "Output correct" );
+