From 23436a18516e66469aeb4d81329d62ee4bfa7a51 Mon Sep 17 00:00:00 2001 From: Klaus Ethgen Date: Wed, 28 Oct 2015 00:38:47 +0100 Subject: Fixing the stuff that is broken on btrfs (Closes #1357) diff --git a/plugins/check_disk.c b/plugins/check_disk.c index 874a0ee..b338684 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c @@ -1038,10 +1038,7 @@ get_stats (struct parameter_list *p, struct fs_usage *fsp) { void get_path_stats (struct parameter_list *p, struct fs_usage *fsp) { - /* 2007-12-08 - Workaround for Gnulib reporting insanely high available - * space on BSD (the actual value should be negative but fsp->fsu_bavail - * is unsigned) */ - p->available = fsp->fsu_bavail > fsp->fsu_bfree ? 0 : fsp->fsu_bavail; + p->available = fsp->fsu_bavail; p->available_to_root = fsp->fsu_bfree; p->used = fsp->fsu_blocks - fsp->fsu_bfree; if (freespace_ignore_reserved) { -- cgit v0.10-9-g596f From 439b93049ddcfa28d7d3b8dd8085770c613aabc3 Mon Sep 17 00:00:00 2001 From: Jan Wagner Date: Fri, 6 Jan 2017 16:54:29 +0100 Subject: Fixing shellcheck SC2006 diff --git a/plugins-scripts/check_log.sh b/plugins-scripts/check_log.sh index d28c8d0..4599268 100755 --- a/plugins-scripts/check_log.sh +++ b/plugins-scripts/check_log.sh @@ -60,8 +60,8 @@ PATH="@TRUSTED_PATH@" export PATH -PROGNAME=`basename $0` -PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'` +PROGNAME=$(basename $0) +PROGPATH=$(echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,') REVISION="@NP_VERSION@" . $PROGPATH/utils.sh @@ -180,9 +180,9 @@ fi # The temporary file that the script should use while # processing the log file. if [ -x /bin/mktemp ]; then - tempdiff=`/bin/mktemp /tmp/check_log.XXXXXXXXXX` + tempdiff=$(/bin/mktemp /tmp/check_log.XXXXXXXXXX) else - tempdiff=`/bin/date '+%H%M%S'` + tempdiff=$(/bin/date '+%H%M%S') tempdiff="/tmp/check_log.${tempdiff}" touch $tempdiff chmod 600 $tempdiff @@ -191,10 +191,10 @@ fi diff $logfile $oldlog | grep -v "^>" > $tempdiff # Count the number of matching log entries we have -count=`grep -c "$query" $tempdiff` +count=$(grep -c "$query" $tempdiff) # Get the last matching entry in the diff file -lastentry=`grep "$query" $tempdiff | tail -1` +lastentry=$(grep "$query" $tempdiff | tail -1) rm -f $tempdiff cat $logfile > $oldlog diff --git a/plugins-scripts/check_oracle.sh b/plugins-scripts/check_oracle.sh index 96078ac..d4d3aae 100755 --- a/plugins-scripts/check_oracle.sh +++ b/plugins-scripts/check_oracle.sh @@ -8,8 +8,8 @@ PATH="@TRUSTED_PATH@" export PATH -PROGNAME=`basename $0` -PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'` +PROGNAME=$(basename $0) +PROGPATH=$(echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,') REVISION="@NP_VERSION@" . $PROGPATH/utils.sh @@ -135,8 +135,8 @@ export ORACLE_HOME PATH LD_LIBRARY_PATH case "$cmd" in --tns) - tnschk=` tnsping $2` - tnschk2=` echo $tnschk | grep -c OK` + tnschk=$(tnsping $2) + tnschk2=$(echo $tnschk | grep -c OK) if [ ${tnschk2} -eq 1 ] ; then tnschk3=${tnschk##*(}; tnschk3=${tnschk3%)*} echo "OK - reply time ${tnschk3} from $2" @@ -165,7 +165,7 @@ case "$cmd" in }' ;; --db) - pmonchk=`ps -ef | grep -v grep | grep -E -c "(asm|ora)_pmon_${2}$"` + pmonchk=$(ps -ef | grep -v grep | grep -E -c "(asm|ora)_pmon_${2}$") if [ ${pmonchk} -ge 1 ] ; then echo "${2} OK - ${pmonchk} PMON process(es) running" exit $STATE_OK @@ -181,25 +181,25 @@ case "$cmd" in fi ;; --login) - loginchk=`sqlplus dummy/user@$2 < /dev/null` - loginchk2=` echo $loginchk | grep -c ORA-01017` + loginchk=$(sqlplus dummy/user@$2 < /dev/null) + loginchk2=$(echo $loginchk | grep -c ORA-01017) if [ ${loginchk2} -eq 1 ] ; then echo "OK - dummy login connected" exit $STATE_OK else - loginchk3=` echo "$loginchk" | grep "ORA-" | head -1` + loginchk3=$(echo "$loginchk" | grep "ORA-" | head -1) echo "CRITICAL - $loginchk3" exit $STATE_CRITICAL fi ;; --connect) - connectchk=`sqlplus $2 < /dev/null` - connectchk2=` echo $connectchk | grep -c ORA-` + connectchk=$(sqlplus $2 < /dev/null) + connectchk2=$(echo $connectchk | grep -c ORA-) if [ ${connectchk2} -eq 0 ] ; then echo "OK - login successful" exit $STATE_OK else - connectchk3=` echo "$connectchk" | grep "ORA-" | head -1` + connectchk3=$(echo "$connectchk" | grep "ORA-" | head -1) echo "CRITICAL - $connectchk3" exit $STATE_CRITICAL fi @@ -219,29 +219,29 @@ and dbg.name='db block gets' and cg.name='consistent gets'; EOF` - if [ -n "`echo $result | grep ORA-`" ] ; then - error=` echo "$result" | grep "ORA-" | head -1` - echo "CRITICAL - $error" - exit $STATE_CRITICAL + if [ -n "$(echo $result | grep ORA-)" ] ; then + error=$(echo "$result" | grep "ORA-" | head -1) + echo "CRITICAL - $error" + exit $STATE_CRITICAL fi - buf_hr=`echo "$result" | awk '/^[0-9\. \t]+$/ {print int($1)}'` - buf_hrx=`echo "$result" | awk '/^[0-9\. \t]+$/ {print $1}'` + buf_hr=$(echo "$result" | awk '/^[0-9\. \t]+$/ {print int($1)}') + buf_hrx=$(echo "$result" | awk '/^[0-9\. \t]+$/ {print $1}') result=`sqlplus -s ${3}/${4}@${2} << EOF set pagesize 0 set numf '9999999.99' select sum(lc.pins)/(sum(lc.pins)+sum(lc.reloads))*100 from v\\$librarycache lc; EOF` - - if [ -n "`echo $result | grep ORA-`" ] ; then - error=` echo "$result" | grep "ORA-" | head -1` - echo "CRITICAL - $error" - exit $STATE_CRITICAL + + if [ -n "$(echo $result | grep ORA-)" ] ; then + error=$(echo "$result" | grep "ORA-" | head -1) + echo "CRITICAL - $error" + exit $STATE_CRITICAL fi - lib_hr=`echo "$result" | awk '/^[0-9\. \t]+$/ {print int($1)}'` - lib_hrx=`echo "$result" | awk '/^[0-9\. \t]+$/ {print $1}'` + lib_hr=$(echo "$result" | awk '/^[0-9\. \t]+$/ {print int($1)}') + lib_hrx=$(echo "$result" | awk '/^[0-9\. \t]+$/ {print $1}') if [ $buf_hr -le ${5} -o $lib_hr -le ${5} ] ; then echo "${2} CRITICAL - Cache Hit Rates: $lib_hrx% Lib -- $buf_hrx% Buff|lib=$lib_hrx%;${6};${5};0;100 buffer=$buf_hrx%;${6};${5};0;100" @@ -273,16 +273,16 @@ from dba_free_space group by tablespace_name) B ON a.tablespace_name=b.tablespace_name WHERE a.tablespace_name='${5}'; EOF` - if [ -n "`echo $result | grep ORA-`" ] ; then - error=` echo "$result" | grep "ORA-" | head -1` - echo "CRITICAL - $error" - exit $STATE_CRITICAL + if [ -n "$(echo $result | grep ORA-)" ] ; then + error=$(echo "$result" | grep "ORA-" | head -1) + echo "CRITICAL - $error" + exit $STATE_CRITICAL fi - ts_free=`echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print int($1)}'` - ts_total=`echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print int($2)}'` - ts_pct=`echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print int($3)}'` - ts_pctx=`echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print $3}'` + ts_free=$(echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print int($1)}') + ts_total=$(echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print int($2)}') + ts_pct=$(echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print int($3)}') + ts_pctx=$(echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print $3}') if [ "$ts_free" -eq 0 -a "$ts_total" -eq 0 -a "$ts_pct" -eq 0 ] ; then echo "No data returned by Oracle - tablespace $5 not found?" exit $STATE_UNKNOWN diff --git a/plugins-scripts/check_sensors.sh b/plugins-scripts/check_sensors.sh index f742830..5348b17 100755 --- a/plugins-scripts/check_sensors.sh +++ b/plugins-scripts/check_sensors.sh @@ -2,8 +2,8 @@ PATH="@TRUSTED_PATH@" export PATH -PROGNAME=`basename $0` -PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'` +PROGNAME=$(basename $0) +PROGPATH=$(echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,') REVISION="@NP_VERSION@" . $PROGPATH/utils.sh @@ -41,7 +41,7 @@ case "$1" in exit $STATE_OK ;; *) - sensordata=`sensors 2>&1` + sensordata=$(sensors 2>&1) status=$? if test ${status} -eq 127; then text="SENSORS UNKNOWN - command not found (did you install lmsensors?)" -- cgit v0.10-9-g596f From 5f3232f00d07dac166b48acd6d0c92ec1ff64901 Mon Sep 17 00:00:00 2001 From: Jan Wagner Date: Fri, 6 Jan 2017 17:43:22 +0100 Subject: Fixing shellcheck SC2086 diff --git a/plugins-scripts/check_log.sh b/plugins-scripts/check_log.sh index 4599268..8f76b1b 100755 --- a/plugins-scripts/check_log.sh +++ b/plugins-scripts/check_log.sh @@ -60,11 +60,11 @@ PATH="@TRUSTED_PATH@" export PATH -PROGNAME=$(basename $0) -PROGPATH=$(echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,') +PROGNAME=$(basename "$0") +PROGPATH=$(echo "$0" | sed -e 's,[\\/][^\\/][^\\/]*$,,') REVISION="@NP_VERSION@" -. $PROGPATH/utils.sh +. "$PROGPATH"/utils.sh print_usage() { echo "Usage: $PROGNAME -F logfile -O oldlog -q query" @@ -73,7 +73,7 @@ print_usage() { } print_help() { - print_revision $PROGNAME $REVISION + print_revision "$PROGNAME" "$REVISION" echo "" print_usage echo "" @@ -87,7 +87,7 @@ print_help() { if [ $# -lt 1 ]; then print_usage - exit $STATE_UNKNOWN + exit "$STATE_UNKNOWN" fi # Grab the command line arguments @@ -100,19 +100,19 @@ while test -n "$1"; do case "$1" in --help) print_help - exit $STATE_OK + exit "$STATE_OK" ;; -h) print_help - exit $STATE_OK + exit "$STATE_OK" ;; --version) - print_revision $PROGNAME $REVISION - exit $STATE_OK + print_revision "$PROGNAME" "$REVISION" + exit "$STATE_OK" ;; -V) - print_revision $PROGNAME $REVISION - exit $STATE_OK + print_revision "$PROGNAME" "$REVISION" + exit "$STATE_OK" ;; --filename) logfile=$2 @@ -149,7 +149,7 @@ while test -n "$1"; do *) echo "Unknown argument: $1" print_usage - exit $STATE_UNKNOWN + exit "$STATE_UNKNOWN" ;; esac shift @@ -157,22 +157,22 @@ done # If the source log file doesn't exist, exit -if [ ! -e $logfile ]; then +if [ ! -e "$logfile" ]; then echo "Log check error: Log file $logfile does not exist!" - exit $STATE_UNKNOWN -elif [ ! -r $logfile ] ; then + exit "$STATE_UNKNOWN" +elif [ ! -r "$logfile" ] ; then echo "Log check error: Log file $logfile is not readable!" - exit $STATE_UNKNOWN + exit "$STATE_UNKNOWN" fi # If the old log file doesn't exist, this must be the first time # we're running this test, so copy the original log file over to # the old diff file and exit -if [ ! -e $oldlog ]; then - cat $logfile > $oldlog +if [ ! -e "$oldlog" ]; then + cat "$logfile" > "$oldlog" echo "Log check data initialized..." - exit $STATE_OK + exit "$STATE_OK" fi # The old log file exists, so compare it to the original log now @@ -184,20 +184,20 @@ if [ -x /bin/mktemp ]; then else tempdiff=$(/bin/date '+%H%M%S') tempdiff="/tmp/check_log.${tempdiff}" - touch $tempdiff - chmod 600 $tempdiff + touch "$tempdiff" + chmod 600 "$tempdiff" fi -diff $logfile $oldlog | grep -v "^>" > $tempdiff +diff "$logfile" "$oldlog" | grep -v "^>" > "$tempdiff" # Count the number of matching log entries we have -count=$(grep -c "$query" $tempdiff) +count=$(grep -c "$query" "$tempdiff") # Get the last matching entry in the diff file -lastentry=$(grep "$query" $tempdiff | tail -1) +lastentry=$(grep "$query" "$tempdiff" | tail -1) -rm -f $tempdiff -cat $logfile > $oldlog +rm -f "$tempdiff" +cat "$logfile" > "$oldlog" if [ "$count" = "0" ]; then # no matches, exit with no error echo "Log check ok - 0 pattern matches found" @@ -207,4 +207,4 @@ else # Print total matche count and the last entry we found exitstatus=$STATE_CRITICAL fi -exit $exitstatus +exit "$exitstatus" diff --git a/plugins-scripts/check_oracle.sh b/plugins-scripts/check_oracle.sh index d4d3aae..0e751f3 100755 --- a/plugins-scripts/check_oracle.sh +++ b/plugins-scripts/check_oracle.sh @@ -8,11 +8,11 @@ PATH="@TRUSTED_PATH@" export PATH -PROGNAME=$(basename $0) -PROGPATH=$(echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,') +PROGNAME=$(basename "$0") +PROGPATH=$(echo "$0" | sed -e 's,[\\/][^\\/][^\\/]*$,,') REVISION="@NP_VERSION@" -. $PROGPATH/utils.sh +. "$PROGPATH"/utils.sh print_usage() { @@ -29,7 +29,7 @@ print_usage() { } print_help() { - print_revision $PROGNAME $REVISION + print_revision "$PROGNAME" "$REVISION" echo "" print_usage echo "" @@ -87,47 +87,47 @@ esac case "$cmd" in --help) print_help - exit $STATE_OK + exit "$STATE_OK" ;; -h) print_help - exit $STATE_OK + exit "$STATE_OK" ;; --version) - print_revision $PROGNAME $REVISION - exit $STATE_OK + print_revision "$PROGNAME" "$REVISION" + exit "$STATE_OK" ;; -V) - print_revision $PROGNAME $REVISION - exit $STATE_OK + print_revision "$PROGNAME" "$REVISION" + exit "$STATE_OK" ;; esac # Hunt down a reasonable ORACLE_HOME if [ -z "$ORACLE_HOME" ] ; then - # Adjust to taste - for oratab in /var/opt/oracle/oratab /etc/oratab - do - [ ! -f $oratab ] && continue - ORACLE_HOME=`IFS=: - while read SID ORACLE_HOME junk; - do - if [ "$SID" = "$2" -o "$SID" = "*" ] ; then - echo $ORACLE_HOME; - exit; - fi; - done < $oratab` - [ -n "$ORACLE_HOME" ] && break - done + # Adjust to taste + for oratab in /var/opt/oracle/oratab /etc/oratab + do + [ ! -f $oratab ] && continue + ORACLE_HOME=`IFS=: + while read SID ORACLE_HOME junk; + do + if [ "$SID" = "$2" -o "$SID" = "*" ] ; then + echo "$ORACLE_HOME"; + exit; + fi; + done < $oratab` + [ -n "$ORACLE_HOME" ] && break + done fi # Last resort -[ -z "$ORACLE_HOME" -a -d $PROGPATH/oracle ] && ORACLE_HOME=$PROGPATH/oracle +[ -z "$ORACLE_HOME" -a -d "$PROGPATH"/oracle ] && ORACLE_HOME=$PROGPATH/oracle if [ "$cmd" != "--db" ]; then - if [ -z "$ORACLE_HOME" -o ! -d "$ORACLE_HOME" ] ; then - echo "Cannot determine ORACLE_HOME for sid $2" - exit $STATE_UNKNOWN - fi + if [ -z "$ORACLE_HOME" -o ! -d "$ORACLE_HOME" ] ; then + echo "Cannot determine ORACLE_HOME for sid $2" + exit "$STATE_UNKNOWN" + fi fi PATH=$PATH:$ORACLE_HOME/bin LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib @@ -135,81 +135,81 @@ export ORACLE_HOME PATH LD_LIBRARY_PATH case "$cmd" in --tns) - tnschk=$(tnsping $2) - tnschk2=$(echo $tnschk | grep -c OK) - if [ ${tnschk2} -eq 1 ] ; then - tnschk3=${tnschk##*(}; tnschk3=${tnschk3%)*} - echo "OK - reply time ${tnschk3} from $2" - exit $STATE_OK + tnschk=$(tnsping "$2") + tnschk2=$(echo "$tnschk" | grep -c OK) + if [ "${tnschk2}" -eq 1 ] ; then + tnschk3=${tnschk##*(}; tnschk3=${tnschk3%)*} + echo "OK - reply time ${tnschk3} from $2" + exit "$STATE_OK" else - echo "No TNS Listener on $2" - exit $STATE_CRITICAL + echo "No TNS Listener on $2" + exit "$STATE_CRITICAL" fi ;; --oranames) - namesctl status $2 | awk ' + namesctl status "$2" | awk ' /Server has been running for:/ { - msg = "OK: Up" - for (i = 6; i <= NF; i++) { - msg = msg " " $i - } - status = '$STATE_OK' + msg = "OK: Up" + for (i = 6; i <= NF; i++) { + msg = msg " " $i + } + status = '"$STATE_OK"' } /error/ { - msg = "CRITICAL: " $0 - status = '$STATE_CRITICAL' + msg = "CRITICAL: " $0 + status = '"$STATE_CRITICAL"' } END { - print msg - exit status + print msg + exit status }' ;; --db) pmonchk=$(ps -ef | grep -v grep | grep -E -c "(asm|ora)_pmon_${2}$") - if [ ${pmonchk} -ge 1 ] ; then - echo "${2} OK - ${pmonchk} PMON process(es) running" - exit $STATE_OK + if [ "${pmonchk}" -ge 1 ] ; then + echo "${2} OK - ${pmonchk} PMON process(es) running" + exit "$STATE_OK" #if [ -f $ORACLE_HOME/dbs/sga*${2}* ] ; then - #if [ ${pmonchk} -eq 1 ] ; then + #if [ ${pmonchk} -eq 1 ] ; then #utime=`ls -la $ORACLE_HOME/dbs/sga*$2* | cut -c 43-55` - #echo "${2} OK - running since ${utime}" - #exit $STATE_OK - #fi + #echo "${2} OK - running since ${utime}" + #exit $STATE_OK + #fi else - echo "${2} Database is DOWN" - exit $STATE_CRITICAL + echo "${2} Database is DOWN" + exit "$STATE_CRITICAL" fi ;; --login) - loginchk=$(sqlplus dummy/user@$2 < /dev/null) - loginchk2=$(echo $loginchk | grep -c ORA-01017) - if [ ${loginchk2} -eq 1 ] ; then - echo "OK - dummy login connected" - exit $STATE_OK + loginchk=$(sqlplus dummy/user@"$2" < /dev/null) + loginchk2=$(echo "$loginchk" | grep -c ORA-01017) + if [ "${loginchk2}" -eq 1 ] ; then + echo "OK - dummy login connected" + exit "$STATE_OK" else - loginchk3=$(echo "$loginchk" | grep "ORA-" | head -1) - echo "CRITICAL - $loginchk3" - exit $STATE_CRITICAL + loginchk3=$(echo "$loginchk" | grep "ORA-" | head -1) + echo "CRITICAL - $loginchk3" + exit "$STATE_CRITICAL" fi ;; --connect) - connectchk=$(sqlplus $2 < /dev/null) - connectchk2=$(echo $connectchk | grep -c ORA-) - if [ ${connectchk2} -eq 0 ] ; then - echo "OK - login successful" - exit $STATE_OK + connectchk=$(sqlplus "$2" < /dev/null) + connectchk2=$(echo "$connectchk" | grep -c ORA-) + if [ "${connectchk2}" -eq 0 ] ; then + echo "OK - login successful" + exit "$STATE_OK" else - connectchk3=$(echo "$connectchk" | grep "ORA-" | head -1) - echo "CRITICAL - $connectchk3" - exit $STATE_CRITICAL + connectchk3=$(echo "$connectchk" | grep "ORA-" | head -1) + echo "CRITICAL - $connectchk3" + exit "$STATE_CRITICAL" fi ;; --cache) - if [ ${5} -gt ${6} ] ; then - echo "UNKNOWN - Warning level is less then Crit" - exit $STATE_UNKNOWN + if [ "${5}" -gt "${6}" ] ; then + echo "UNKNOWN - Warning level is less then Crit" + exit "$STATE_UNKNOWN" fi - result=`sqlplus -s ${3}/${4}@${2} << EOF + result=`sqlplus -s "${3}"/"${4}"@"${2}" << EOF set pagesize 0 set numf '9999999.99' select (1-(pr.value/(dbg.value+cg.value)))*100 @@ -219,48 +219,48 @@ and dbg.name='db block gets' and cg.name='consistent gets'; EOF` - if [ -n "$(echo $result | grep ORA-)" ] ; then + if [ -n "$(echo "$result" | grep ORA-)" ] ; then error=$(echo "$result" | grep "ORA-" | head -1) echo "CRITICAL - $error" - exit $STATE_CRITICAL + exit "$STATE_CRITICAL" fi buf_hr=$(echo "$result" | awk '/^[0-9\. \t]+$/ {print int($1)}') buf_hrx=$(echo "$result" | awk '/^[0-9\. \t]+$/ {print $1}') - result=`sqlplus -s ${3}/${4}@${2} << EOF + result=`sqlplus -s "${3}"/"${4}"@"${2}" << EOF set pagesize 0 set numf '9999999.99' select sum(lc.pins)/(sum(lc.pins)+sum(lc.reloads))*100 from v\\$librarycache lc; EOF` - if [ -n "$(echo $result | grep ORA-)" ] ; then + if [ -n "$(echo "$result" | grep ORA-)" ] ; then error=$(echo "$result" | grep "ORA-" | head -1) echo "CRITICAL - $error" - exit $STATE_CRITICAL + exit "$STATE_CRITICAL" fi lib_hr=$(echo "$result" | awk '/^[0-9\. \t]+$/ {print int($1)}') lib_hrx=$(echo "$result" | awk '/^[0-9\. \t]+$/ {print $1}') - if [ $buf_hr -le ${5} -o $lib_hr -le ${5} ] ; then - echo "${2} CRITICAL - Cache Hit Rates: $lib_hrx% Lib -- $buf_hrx% Buff|lib=$lib_hrx%;${6};${5};0;100 buffer=$buf_hrx%;${6};${5};0;100" - exit $STATE_CRITICAL + if [ "$buf_hr" -le "${5}" -o "$lib_hr" -le "${5}" ] ; then + echo "${2} CRITICAL - Cache Hit Rates: $lib_hrx% Lib -- $buf_hrx% Buff|lib=$lib_hrx%;${6};${5};0;100 buffer=$buf_hrx%;${6};${5};0;100" + exit "$STATE_CRITICAL" fi - if [ $buf_hr -le ${6} -o $lib_hr -le ${6} ] ; then - echo "${2} WARNING - Cache Hit Rates: $lib_hrx% Lib -- $buf_hrx% Buff|lib=$lib_hrx%;${6};${5};0;100 buffer=$buf_hrx%;${6};${5};0;100" - exit $STATE_WARNING + if [ "$buf_hr" -le "${6}" -o "$lib_hr" -le "${6}" ] ; then + echo "${2} WARNING - Cache Hit Rates: $lib_hrx% Lib -- $buf_hrx% Buff|lib=$lib_hrx%;${6};${5};0;100 buffer=$buf_hrx%;${6};${5};0;100" + exit "$STATE_WARNING" fi echo "${2} OK - Cache Hit Rates: $lib_hrx% Lib -- $buf_hrx% Buff|lib=$lib_hrx%;${6};${5};0;100 buffer=$buf_hrx%;${6};${5};0;100" - exit $STATE_OK + exit "$STATE_OK" ;; --tablespace) - if [ ${6} -lt ${7} ] ; then - echo "UNKNOWN - Warning level is more then Crit" - exit $STATE_UNKNOWN + if [ "${6}" -lt "${7}" ] ; then + echo "UNKNOWN - Warning level is more then Crit" + exit "$STATE_UNKNOWN" fi - result=`sqlplus -s ${3}/${4}@${2} << EOF + result=`sqlplus -s "${3}"/"${4}"@"${2}" << EOF set pagesize 0 set numf '9999999.99' select NVL(b.free,0.0),a.total,100 - trunc(NVL(b.free,0.0)/a.total * 1000) / 10 prc @@ -273,10 +273,10 @@ from dba_free_space group by tablespace_name) B ON a.tablespace_name=b.tablespace_name WHERE a.tablespace_name='${5}'; EOF` - if [ -n "$(echo $result | grep ORA-)" ] ; then + if [ -n "$(echo "$result" | grep ORA-)" ] ; then error=$(echo "$result" | grep "ORA-" | head -1) echo "CRITICAL - $error" - exit $STATE_CRITICAL + exit "$STATE_CRITICAL" fi ts_free=$(echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print int($1)}') @@ -285,20 +285,20 @@ EOF` ts_pctx=$(echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print $3}') if [ "$ts_free" -eq 0 -a "$ts_total" -eq 0 -a "$ts_pct" -eq 0 ] ; then echo "No data returned by Oracle - tablespace $5 not found?" - exit $STATE_UNKNOWN + exit "$STATE_UNKNOWN" fi - if [ "$ts_pct" -ge ${6} ] ; then - echo "${2} : ${5} CRITICAL - $ts_pctx% used [ $ts_free / $ts_total MB available ]|${5}=$ts_pctx%;${7};${6};0;100" - exit $STATE_CRITICAL + if [ "$ts_pct" -ge "${6}" ] ; then + echo "${2} : ${5} CRITICAL - $ts_pctx% used [ $ts_free / $ts_total MB available ]|${5}=$ts_pctx%;${7};${6};0;100" + exit "$STATE_CRITICAL" fi - if [ "$ts_pct" -ge ${7} ] ; then - echo "${2} : ${5} WARNING - $ts_pctx% used [ $ts_free / $ts_total MB available ]|${5}=$ts_pctx%;${7};${6};0;100" - exit $STATE_WARNING + if [ "$ts_pct" -ge "${7}" ] ; then + echo "${2} : ${5} WARNING - $ts_pctx% used [ $ts_free / $ts_total MB available ]|${5}=$ts_pctx%;${7};${6};0;100" + exit "$STATE_WARNING" fi echo "${2} : ${5} OK - $ts_pctx% used [ $ts_free / $ts_total MB available ]|${5}=$ts_pctx%;${7};${6};0;100" - exit $STATE_OK + exit "$STATE_OK" ;; *) print_usage - exit $STATE_UNKNOWN + exit "$STATE_UNKNOWN" esac diff --git a/plugins-scripts/check_sensors.sh b/plugins-scripts/check_sensors.sh index 5348b17..9a6cf5d 100755 --- a/plugins-scripts/check_sensors.sh +++ b/plugins-scripts/check_sensors.sh @@ -2,43 +2,43 @@ PATH="@TRUSTED_PATH@" export PATH -PROGNAME=$(basename $0) -PROGPATH=$(echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,') +PROGNAME=$(basename "$0") +PROGPATH=$(echo "$0" | sed -e 's,[\\/][^\\/][^\\/]*$,,') REVISION="@NP_VERSION@" -. $PROGPATH/utils.sh +. "$PROGPATH"/utils.sh print_usage() { echo "Usage: $PROGNAME" [--ignore-fault] } print_help() { - print_revision $PROGNAME $REVISION + print_revision "$PROGNAME" "$REVISION" echo "" print_usage echo "" echo "This plugin checks hardware status using the lm_sensors package." echo "" support - exit $STATE_OK + exit "$STATE_OK" } case "$1" in --help) print_help - exit $STATE_OK + exit "$STATE_OK" ;; -h) print_help - exit $STATE_OK + exit "$STATE_OK" ;; --version) - print_revision $PROGNAME $REVISION - exit $STATE_OK + print_revision "$PROGNAME" "$REVISION" + exit "$STATE_OK" ;; -V) - print_revision $PROGNAME $REVISION - exit $STATE_OK + print_revision "$PROGNAME" "$REVISION" + exit "$STATE_OK" ;; *) sensordata=$(sensors 2>&1) @@ -49,10 +49,10 @@ case "$1" in elif test ${status} -ne 0; then text="WARNING - sensors returned state $status" exit=$STATE_WARNING - elif echo ${sensordata} | egrep ALARM > /dev/null; then + elif echo "${sensordata}" | egrep ALARM > /dev/null; then text="SENSOR CRITICAL - Sensor alarm detected!" exit=$STATE_CRITICAL - elif echo ${sensordata} | egrep FAULT > /dev/null \ + elif echo "${sensordata}" | egrep FAULT > /dev/null \ && test "$1" != "-i" -a "$1" != "--ignore-fault"; then text="SENSOR UNKNOWN - Sensor reported fault" exit=$STATE_UNKNOWN @@ -63,8 +63,8 @@ case "$1" in echo "$text" if test "$1" = "-v" -o "$1" = "--verbose"; then - echo ${sensordata} + echo "${sensordata}" fi - exit $exit + exit "$exit" ;; esac -- cgit v0.10-9-g596f From 1204d7fe56c9f35af6500f5ddbae733a622fb63d Mon Sep 17 00:00:00 2001 From: Jan Wagner Date: Fri, 6 Jan 2017 17:56:03 +0100 Subject: Fixing shellcheck SC2009 This requires pgrep from the procps package. diff --git a/plugins-scripts/check_oracle.sh b/plugins-scripts/check_oracle.sh index 0e751f3..70a3fef 100755 --- a/plugins-scripts/check_oracle.sh +++ b/plugins-scripts/check_oracle.sh @@ -165,7 +165,7 @@ case "$cmd" in }' ;; --db) - pmonchk=$(ps -ef | grep -v grep | grep -E -c "(asm|ora)_pmon_${2}$") + pmonchk=$(pgrep -f "(asm|ora)_pmon_${2}$") if [ "${pmonchk}" -ge 1 ] ; then echo "${2} OK - ${pmonchk} PMON process(es) running" exit "$STATE_OK" -- cgit v0.10-9-g596f From 5c473c8612a55cc71689bf4ba468a464bf9da197 Mon Sep 17 00:00:00 2001 From: Jan Wagner Date: Fri, 6 Jan 2017 18:02:36 +0100 Subject: Fixing shellcheck SC2143 diff --git a/plugins-scripts/check_oracle.sh b/plugins-scripts/check_oracle.sh index 70a3fef..9b9540a 100755 --- a/plugins-scripts/check_oracle.sh +++ b/plugins-scripts/check_oracle.sh @@ -219,7 +219,7 @@ and dbg.name='db block gets' and cg.name='consistent gets'; EOF` - if [ -n "$(echo "$result" | grep ORA-)" ] ; then + if echo "$result" | grep -q 'ORA-' ; then error=$(echo "$result" | grep "ORA-" | head -1) echo "CRITICAL - $error" exit "$STATE_CRITICAL" @@ -234,7 +234,7 @@ select sum(lc.pins)/(sum(lc.pins)+sum(lc.reloads))*100 from v\\$librarycache lc; EOF` - if [ -n "$(echo "$result" | grep ORA-)" ] ; then + if echo "$result" | grep -q 'ORA-' ; then error=$(echo "$result" | grep "ORA-" | head -1) echo "CRITICAL - $error" exit "$STATE_CRITICAL" @@ -273,7 +273,7 @@ from dba_free_space group by tablespace_name) B ON a.tablespace_name=b.tablespace_name WHERE a.tablespace_name='${5}'; EOF` - if [ -n "$(echo "$result" | grep ORA-)" ] ; then + if echo "$result" | grep -q 'ORA-' ; then error=$(echo "$result" | grep "ORA-" | head -1) echo "CRITICAL - $error" exit "$STATE_CRITICAL" -- cgit v0.10-9-g596f From 9d8e973b93f261cbb52f5cb944f2e074c348290d Mon Sep 17 00:00:00 2001 From: Jan Wagner Date: Fri, 6 Jan 2017 18:14:55 +0100 Subject: Fixing shellcheck SC2162 diff --git a/plugins-scripts/check_oracle.sh b/plugins-scripts/check_oracle.sh index 9b9540a..bfd9e8f 100755 --- a/plugins-scripts/check_oracle.sh +++ b/plugins-scripts/check_oracle.sh @@ -110,7 +110,7 @@ if [ -z "$ORACLE_HOME" ] ; then do [ ! -f $oratab ] && continue ORACLE_HOME=`IFS=: - while read SID ORACLE_HOME junk; + while read -r SID ORACLE_HOME junk; do if [ "$SID" = "$2" -o "$SID" = "*" ] ; then echo "$ORACLE_HOME"; -- cgit v0.10-9-g596f From 8294af907bd8482a86df749f562b7ec09e3faeed Mon Sep 17 00:00:00 2001 From: Jan Wagner Date: Fri, 6 Jan 2017 18:39:51 +0100 Subject: Fixing shellcheck SC2166 diff --git a/plugins-scripts/check_oracle.sh b/plugins-scripts/check_oracle.sh index bfd9e8f..b14ec50 100755 --- a/plugins-scripts/check_oracle.sh +++ b/plugins-scripts/check_oracle.sh @@ -112,7 +112,7 @@ if [ -z "$ORACLE_HOME" ] ; then ORACLE_HOME=`IFS=: while read -r SID ORACLE_HOME junk; do - if [ "$SID" = "$2" -o "$SID" = "*" ] ; then + if [ "$SID" = "$2" ] || [ "$SID" = "*" ] ; then echo "$ORACLE_HOME"; exit; fi; @@ -121,10 +121,10 @@ if [ -z "$ORACLE_HOME" ] ; then done fi # Last resort -[ -z "$ORACLE_HOME" -a -d "$PROGPATH"/oracle ] && ORACLE_HOME=$PROGPATH/oracle +[ -z "$ORACLE_HOME" ] && [ -d "$PROGPATH"/oracle ] && ORACLE_HOME=$PROGPATH/oracle if [ "$cmd" != "--db" ]; then - if [ -z "$ORACLE_HOME" -o ! -d "$ORACLE_HOME" ] ; then + if [ -z "$ORACLE_HOME" ] || [ ! -d "$ORACLE_HOME" ] ; then echo "Cannot determine ORACLE_HOME for sid $2" exit "$STATE_UNKNOWN" fi @@ -243,11 +243,11 @@ EOF` lib_hr=$(echo "$result" | awk '/^[0-9\. \t]+$/ {print int($1)}') lib_hrx=$(echo "$result" | awk '/^[0-9\. \t]+$/ {print $1}') - if [ "$buf_hr" -le "${5}" -o "$lib_hr" -le "${5}" ] ; then + if [ "$buf_hr" -le "${5}" ] || [ "$lib_hr" -le "${5}" ] ; then echo "${2} CRITICAL - Cache Hit Rates: $lib_hrx% Lib -- $buf_hrx% Buff|lib=$lib_hrx%;${6};${5};0;100 buffer=$buf_hrx%;${6};${5};0;100" exit "$STATE_CRITICAL" fi - if [ "$buf_hr" -le "${6}" -o "$lib_hr" -le "${6}" ] ; then + if [ "$buf_hr" -le "${6}" ] || [ "$lib_hr" -le "${6}" ] ; then echo "${2} WARNING - Cache Hit Rates: $lib_hrx% Lib -- $buf_hrx% Buff|lib=$lib_hrx%;${6};${5};0;100 buffer=$buf_hrx%;${6};${5};0;100" exit "$STATE_WARNING" fi @@ -283,7 +283,7 @@ EOF` ts_total=$(echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print int($2)}') ts_pct=$(echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print int($3)}') ts_pctx=$(echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print $3}') - if [ "$ts_free" -eq 0 -a "$ts_total" -eq 0 -a "$ts_pct" -eq 0 ] ; then + if [ "$ts_free" -eq 0 ] && [ "$ts_total" -eq 0 ] && [ "$ts_pct" -eq 0 ] ; then echo "No data returned by Oracle - tablespace $5 not found?" exit "$STATE_UNKNOWN" fi -- cgit v0.10-9-g596f From c85281d25bb4b0fc12a45b2732620f51a10344be Mon Sep 17 00:00:00 2001 From: Gerhard Lausser Date: Tue, 7 Feb 2017 14:15:47 +0100 Subject: check_snmp: put the "c" (to mark a counter) after the perfdata value diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index da9638c..b5abac1 100644 --- a/plugins/check_snmp.c +++ b/plugins/check_snmp.c @@ -576,6 +576,9 @@ main (int argc, char **argv) len = sizeof(perfstr)-strlen(perfstr)-1; strncat(perfstr, show, len>ptr-show ? ptr-show : len); + if (type) + strncat(perfstr, type, sizeof(perfstr)-strlen(perfstr)-1); + if (warning_thresholds) { strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1); strncat(perfstr, warning_thresholds, sizeof(perfstr)-strlen(perfstr)-1); @@ -588,8 +591,6 @@ main (int argc, char **argv) strncat(perfstr, critical_thresholds, sizeof(perfstr)-strlen(perfstr)-1); } - if (type) - strncat(perfstr, type, sizeof(perfstr)-strlen(perfstr)-1); strncat(perfstr, " ", sizeof(perfstr)-strlen(perfstr)-1); } } -- cgit v0.10-9-g596f From 6246b8f1830e8a375bc656deafd28aab715b4fd9 Mon Sep 17 00:00:00 2001 From: Lee Clemens Date: Tue, 16 May 2017 11:23:43 -0400 Subject: Add mailq -C option for config dir or config file New variable, mailq_args, is appended for postfix mta mailq commands Fixes #1489 diff --git a/plugins-scripts/check_mailq.pl b/plugins-scripts/check_mailq.pl index 32f498d..9ef292e 100755 --- a/plugins-scripts/check_mailq.pl +++ b/plugins-scripts/check_mailq.pl @@ -28,9 +28,9 @@ use POSIX; use strict; use Getopt::Long; -use vars qw($opt_V $opt_h $opt_v $verbose $PROGNAME $opt_w $opt_c $opt_t $opt_s - $opt_M $mailq $status $state $msg $msg_q $msg_p $opt_W $opt_C $mailq @lines - %srcdomains %dstdomains); +use vars qw($opt_V $opt_h $opt_v $verbose $PROGNAME $opt_w $opt_c $opt_t $opt_s $opt_d + $opt_M $mailq $status $state $msg $msg_q $msg_p $opt_W $opt_C $mailq $mailq_args + @lines %srcdomains %dstdomains); use FindBin; use lib "$FindBin::Bin"; use utils qw(%ERRORS &print_revision &support &usage ); @@ -48,6 +48,8 @@ $PROGNAME = "check_mailq"; $mailq = 'sendmail'; # default $msg_q = 0 ; $msg_p = 0 ; +# If appended, must start with a space +$mailq_args = '' ; $state = $ERRORS{'UNKNOWN'}; Getopt::Long::Configure('bundling'); @@ -68,6 +70,10 @@ if ($opt_s) { $sudo = ""; } +if ($opt_d) { + $mailq_args = $mailq_args . ' -C ' . $opt_d; +} + $SIG{'ALRM'} = sub { print ("ERROR: timed out waiting for $utils::PATH_TO_MAILQ \n"); exit $ERRORS{"WARNING"}; @@ -309,8 +315,8 @@ elsif ( $mailq eq "postfix" ) { ## open mailq if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) { - if (! open (MAILQ, "$sudo $utils::PATH_TO_MAILQ | " ) ) { - print "ERROR: could not open $utils::PATH_TO_MAILQ \n"; + if (! open (MAILQ, "$sudo $utils::PATH_TO_MAILQ$mailq_args | " ) ) { + print "ERROR: could not open $utils::PATH_TO_MAILQ$mailq_args \n"; exit $ERRORS{'UNKNOWN'}; } }elsif( defined $utils::PATH_TO_MAILQ){ @@ -330,7 +336,7 @@ elsif ( $mailq eq "postfix" ) { close MAILQ; if ( $? ) { - print "CRITICAL: Error code ".($?>>8)." returned from $utils::PATH_TO_MAILQ",$/; + print "CRITICAL: Error code ".($?>>8)." returned from $utils::PATH_TO_MAILQ$mailq_args",$/; exit $ERRORS{CRITICAL}; } @@ -343,7 +349,7 @@ elsif ( $mailq eq "postfix" ) { }elsif ($lines[0]=~/Mail queue is empty/) { $msg_q = 0; }else{ - print "Couldn't match $utils::PATH_TO_MAILQ output\n"; + print "Couldn't match $utils::PATH_TO_MAILQ$mailq_args output\n"; exit $ERRORS{'UNKNOWN'}; } @@ -568,7 +574,8 @@ sub process_arguments(){ "w=i" => \$opt_w, "warning=i" => \$opt_w, # warning if above this number "c=i" => \$opt_c, "critical=i" => \$opt_c, # critical if above this number "t=i" => \$opt_t, "timeout=i" => \$opt_t, - "s" => \$opt_s, "sudo" => \$opt_s + "s" => \$opt_s, "sudo" => \$opt_s, + "d:s" => \$opt_d, "configdir:s" => \$opt_d ); if ($opt_V) { @@ -649,7 +656,7 @@ sub process_arguments(){ } sub print_usage () { - print "Usage: $PROGNAME -w -c [-W ] [-C ] [-M ] [-t ] [-s] [-v]\n"; + print "Usage: $PROGNAME -w -c [-W ] [-C ] [-M ] [-t ] [-s] [-d ] [-v]\n"; } sub print_help () { @@ -667,6 +674,7 @@ sub print_help () { print "-t (--timeout) = Plugin timeout in seconds (default = $utils::TIMEOUT)\n"; print "-M (--mailserver) = [ sendmail | qmail | postfix | exim | nullmailer ] (default = autodetect)\n"; print "-s (--sudo) = Use sudo to call the mailq command\n"; + print "-d (--configdir) = Config file or directory\n"; print "-h (--help)\n"; print "-V (--version)\n"; print "-v (--verbose) = debugging output\n"; -- cgit v0.10-9-g596f From 541322969e27b07566c55448d749bc64ab7ae5c0 Mon Sep 17 00:00:00 2001 From: Stephane Lapie Date: Wed, 7 Jun 2017 15:12:53 +0900 Subject: Fix regexp for nullmailer "mailq" output As it currently is, the regular expression does not match mailq command output on a Debian Jessie setup. Three erroneous behaviors fixed : - Meaningful lines do not end with the "bytes" word - There might be one or more space before the byte count, not 2 - Time match was completely broken, it only accounted for 0-29 minutes and 0-29 seconds. diff --git a/plugins-scripts/check_mailq.pl b/plugins-scripts/check_mailq.pl index 32f498d..1fc15ff 100755 --- a/plugins-scripts/check_mailq.pl +++ b/plugins-scripts/check_mailq.pl @@ -533,7 +533,7 @@ elsif ( $mailq eq "nullmailer" ) { while () { #2006-06-22 16:00:00 282 bytes - if (/^[1-9][0-9]*-[01][0-9]-[0-3][0-9]\s[0-2][0-9]\:[0-2][0-9]\:[0-2][0-9]\s{2}[0-9]+\sbytes$/) { + if (/^[1-9][0-9]*-[01][0-9]-[0-3][0-9]\s[0-2][0-9]\:[0-5][0-9]\:[0-5][0-9]\s+[0-9]+\sbytes/) { $msg_q++ ; } } -- cgit v0.10-9-g596f From 09a2210c477932c8df40ff820414b3a9bbec10fb Mon Sep 17 00:00:00 2001 From: Rasp8e Date: Tue, 17 Oct 2017 15:19:43 +0200 Subject: Adding Proxy-Authorization and extra headers in the case of connection through PROXY to HTTPS diff --git a/plugins/check_http.c b/plugins/check_http.c index 86a36c2..2e393eb 100644 --- a/plugins/check_http.c +++ b/plugins/check_http.c @@ -916,6 +916,21 @@ check_http (void) if (verbose) printf ("Entering CONNECT tunnel mode with proxy %s:%d to dst %s:%d\n", server_address, server_port, host_name, HTTPS_PORT); asprintf (&buf, "%s %s:%d HTTP/1.1\r\n%s\r\n", http_method, host_name, HTTPS_PORT, user_agent); + if (strlen(proxy_auth)) { + base64_encode_alloc (proxy_auth, strlen (proxy_auth), &auth); + xasprintf (&buf, "%sProxy-Authorization: Basic %s\r\n", buf, auth); + } + /* optionally send any other header tag */ + if (http_opt_headers_count) { + for (i = 0; i < http_opt_headers_count ; i++) { + if (force_host_header != http_opt_headers[i]) { + xasprintf (&buf, "%s%s\r\n", buf, http_opt_headers[i]); + } + } + /* This cannot be free'd here because a redirection will then try to access this and segfault */ + /* Covered in a testcase in tests/check_http.t */ + /* free(http_opt_headers); */ + } asprintf (&buf, "%sProxy-Connection: keep-alive\r\n", buf); asprintf (&buf, "%sHost: %s\r\n", buf, host_name); /* we finished our request, send empty line with CRLF */ -- cgit v0.10-9-g596f From 22c00bbe47d2bed5e77ad1d494502c4697a86abb Mon Sep 17 00:00:00 2001 From: Stefan Bethke Date: Wed, 10 Oct 2018 00:40:07 +0200 Subject: Docs check_http: make -C obvious You need to read the docs carefully to realize that check_http has two modes of operation: the regular HTTP checks, and a TLS certificate check. Only one of these can be run in a single invocation. Fixes #1553 diff --git a/plugins/check_http.c b/plugins/check_http.c index 86a36c2..d540bf7 100644 --- a/plugins/check_http.c +++ b/plugins/check_http.c @@ -1532,6 +1532,10 @@ print_help (void) print_usage (); +#ifdef HAVE_SSL + printf (_("In the first form, make an HTTP request.")); + printf (_("In the second form, connect to the server and check the TLS certificate.")); +#endif printf (_("NOTE: One or both of -H and -I must be specified")); printf ("\n"); @@ -1688,6 +1692,8 @@ print_usage (void) printf (" [-b proxy_auth] [-f ]\n"); printf (" [-e ] [-d string] [-s string] [-l] [-r | -R ]\n"); printf (" [-P string] [-m :] [-4|-6] [-N] [-M ]\n"); - printf (" [-A string] [-k string] [-S ] [--sni] [-C [,]]\n"); + printf (" [-A string] [-k string] [-S ] [--sni]\n"); printf (" [-T ] [-j method]\n"); + printf (" %s -H | -I -C [,]\n",progname); + printf (" [-p ] [-t ] [-4|-6] [--sni]\n"); } -- cgit v0.10-9-g596f From 0a58acc7052d4962d8fe68aeb6919b59dfdef1cf Mon Sep 17 00:00:00 2001 From: Tomas Mozes Date: Wed, 5 Dec 2018 12:50:53 +0100 Subject: plugins: check_http: Increase regexp limit diff --git a/plugins/check_http.c b/plugins/check_http.c index 856e1e9..a25f1ec 100644 --- a/plugins/check_http.c +++ b/plugins/check_http.c @@ -72,7 +72,7 @@ int maximum_age = -1; enum { REGS = 2, - MAX_RE_SIZE = 256 + MAX_RE_SIZE = 1024 }; #include "regex.h" regex_t preg; -- cgit v0.10-9-g596f From b8b87b55d61aceff03107b0335347257f429e9ad Mon Sep 17 00:00:00 2001 From: ghciv6 Date: Tue, 15 Sep 2020 21:36:27 +0200 Subject: - fix for issue #1562 1st compare then free up resources diff --git a/plugins/check_mysql_query.c b/plugins/check_mysql_query.c index 49a14dd..ac2fb15 100644 --- a/plugins/check_mysql_query.c +++ b/plugins/check_mysql_query.c @@ -136,18 +136,18 @@ main (int argc, char **argv) die (STATE_CRITICAL, "QUERY %s: Fetch row error - %s\n", _("CRITICAL"), error); } - /* free the result */ - mysql_free_result (res); - - /* close the connection */ - mysql_close (&mysql); - if (! is_numeric(row[0])) { die (STATE_CRITICAL, "QUERY %s: %s - '%s'\n", _("CRITICAL"), _("Is not a numeric"), row[0]); } value = strtod(row[0], NULL); + /* free the result */ + mysql_free_result (res); + + /* close the connection */ + mysql_close (&mysql); + if (verbose >= 3) printf("mysql result: %f\n", value); -- cgit v0.10-9-g596f From 1039822de848daf4f367d914634d782e3316026a Mon Sep 17 00:00:00 2001 From: Prathamesh Bhanuse <72161308+Prathu121@users.noreply.github.com> Date: Fri, 2 Oct 2020 01:48:46 +0530 Subject: Update README diff --git a/README b/README index beb7769..71b4d37 100644 --- a/README +++ b/README @@ -10,7 +10,7 @@ Monitoring Plugins * For information on detailed changes that have been made or plugins that have been added, read the `ChangeLog` file. -* Some plugins require that you have additional programs and/or +* Some plugins require that you have additional programs or libraries installed on your system before they can be used. Plugins that are dependent on other programs/libraries that are missing are usually not compiled. Read the `REQUIREMENTS` file for more information. @@ -19,7 +19,7 @@ Monitoring Plugins the basic guidelines for development will provide detailed help when invoked with the `-h` or `--help` options. -You can check for the latest plugins at: +You can check the latest plugins at: * -- cgit v0.10-9-g596f From ad99755033f33a301abc1815d746644067bc297a Mon Sep 17 00:00:00 2001 From: Rolf Eike Beer Date: Mon, 2 Nov 2020 20:05:56 +0100 Subject: check_dns: split multiple IP addresses passed in one -a argument diff --git a/plugins/check_dns.c b/plugins/check_dns.c index b90f50e..0f2e654 100644 --- a/plugins/check_dns.c +++ b/plugins/check_dns.c @@ -473,9 +473,23 @@ process_arguments (int argc, char **argv) case 'a': /* expected address */ if (strlen (optarg) >= ADDRESS_LENGTH) die (STATE_UNKNOWN, _("Input buffer overflow\n")); - expected_address = (char **)realloc(expected_address, (expected_address_cnt+1) * sizeof(char**)); - expected_address[expected_address_cnt] = strdup(optarg); - expected_address_cnt++; + if (strchr(optarg, ',') != NULL) { + char *comma = strchr(optarg, ','); + while (comma != NULL) { + expected_address = (char **)realloc(expected_address, (expected_address_cnt+1) * sizeof(char**)); + expected_address[expected_address_cnt] = strndup(optarg, comma - optarg); + expected_address_cnt++; + optarg = comma + 1; + comma = strchr(optarg, ','); + } + expected_address = (char **)realloc(expected_address, (expected_address_cnt+1) * sizeof(char**)); + expected_address[expected_address_cnt] = strdup(optarg); + expected_address_cnt++; + } else { + expected_address = (char **)realloc(expected_address, (expected_address_cnt+1) * sizeof(char**)); + expected_address[expected_address_cnt] = strdup(optarg); + expected_address_cnt++; + } break; case 'A': /* expect authority */ expect_authority = TRUE; -- cgit v0.10-9-g596f From aa79ab278ffc9bf3d41207d97bdfb04be35b5c74 Mon Sep 17 00:00:00 2001 From: Sven Nierlein Date: Tue, 8 Dec 2020 16:24:10 +0100 Subject: check_mailq: restore accidentially removed options with https://github.com/monitoring-plugins/monitoring-plugins/issues/381 -W and -C have been removed. It would have been sufficient to only remove the long options. Restoring short options.. - fixes https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=954961 diff --git a/plugins-scripts/check_mailq.pl b/plugins-scripts/check_mailq.pl index 32f498d..aac1310 100755 --- a/plugins-scripts/check_mailq.pl +++ b/plugins-scripts/check_mailq.pl @@ -568,7 +568,9 @@ sub process_arguments(){ "w=i" => \$opt_w, "warning=i" => \$opt_w, # warning if above this number "c=i" => \$opt_c, "critical=i" => \$opt_c, # critical if above this number "t=i" => \$opt_t, "timeout=i" => \$opt_t, - "s" => \$opt_s, "sudo" => \$opt_s + "s" => \$opt_s, "sudo" => \$opt_s, + "W=i" => \$opt_W, # warning if above this number + "C=i" => \$opt_C, # critical if above this number ); if ($opt_V) { @@ -662,8 +664,8 @@ sub print_help () { print " Feedback/patches to support non-sendmail mailqueue welcome\n\n"; print "-w (--warning) = Min. number of messages in queue to generate warning\n"; print "-c (--critical) = Min. number of messages in queue to generate critical alert ( w < c )\n"; - print "-W (--Warning) = Min. number of messages for same domain in queue to generate warning\n"; - print "-C (--Critical) = Min. number of messages for same domain in queue to generate critical alert ( W < C )\n"; + print "-W = Min. number of messages for same domain in queue to generate warning\n"; + print "-C = Min. number of messages for same domain in queue to generate critical alert ( W < C )\n"; print "-t (--timeout) = Plugin timeout in seconds (default = $utils::TIMEOUT)\n"; print "-M (--mailserver) = [ sendmail | qmail | postfix | exim | nullmailer ] (default = autodetect)\n"; print "-s (--sudo) = Use sudo to call the mailq command\n"; -- cgit v0.10-9-g596f From 233251f43ba8404f3fd6fc3524ac06e6924985fb Mon Sep 17 00:00:00 2001 From: Jan Wagner Date: Wed, 9 Dec 2020 14:10:53 +0100 Subject: Updating version number diff --git a/NP-VERSION-GEN b/NP-VERSION-GEN index cf78d69..dd74d0c 100755 --- a/NP-VERSION-GEN +++ b/NP-VERSION-GEN @@ -6,7 +6,7 @@ SRC_ROOT=`dirname $0` NPVF=NP-VERSION-FILE -DEF_VER=2.2.git +DEF_VER=2.3 LF=' ' diff --git a/configure.ac b/configure.ac index 4aebc2a..562efcd 100644 --- a/configure.ac +++ b/configure.ac @@ -1,6 +1,6 @@ dnl Process this file with autoconf to produce a configure script. AC_PREREQ(2.59) -AC_INIT(monitoring-plugins,2.2) +AC_INIT(monitoring-plugins,2.3) AC_CONFIG_SRCDIR(NPTest.pm) AC_CONFIG_FILES([gl/Makefile]) AC_CONFIG_AUX_DIR(build-aux) -- cgit v0.10-9-g596f From 5789a76bbce7dbe3793058b13419b701822d4b8b Mon Sep 17 00:00:00 2001 From: Jan Wagner Date: Wed, 9 Dec 2020 15:32:23 +0100 Subject: Updating contributors diff --git a/THANKS.in b/THANKS.in index 9bb4382..7d1d1ff 100644 --- a/THANKS.in +++ b/THANKS.in @@ -357,3 +357,27 @@ Thomas Kurschel Yannick Charton Nicolai Søborg Rolf Eike Beer +Bernd Arnold +Andreas Baumann +Tobias Wolf +Lars Michelsen +Vincent Danjean +Kostyantyn Hushchyn +Christian Tacke +Alexander A. Klimov +Vadim Zhukov +Bernard Spil +Christian Schmidt +Guido Falsi +Harald Koch +Iustin Pop +Jacob Hansen +Jean-François Rameau +Karol Babioch +Lucas Bussey +Marc Sánchez +Markus Frosch +Michael Kraus +Patrick Rauscher +Prathamesh Bhanuse +Valentin Vidic -- cgit v0.10-9-g596f From d9c87f84b4075c0efeb46c2f984b2170a00b8c89 Mon Sep 17 00:00:00 2001 From: Jan Wagner Date: Wed, 9 Dec 2020 15:33:18 +0100 Subject: Draft NEWS diff --git a/NEWS b/NEWS index 0848705..f9f2da6 100644 --- a/NEWS +++ b/NEWS @@ -1,17 +1,51 @@ This file documents the major additions and syntax changes between releases. -2.3 [...] +2.3 10th December 2020 ENHANCEMENTS check_dns: allow 'expected address' (-a) to be specified in CIDR notation (IPv4 only). check_dns: allow for IPv6 RDNS + check_dns: Accept CIDR check_dns: allow unsorted addresses check_dns: allow forcing complete match of all addresses check_apt: add --only-critical switch check_apt: add -l/--list option to print packages + check_file_age: add range checking + check_file_age: enable to test for maximum file size + check_apt: adding packages-warning option + check_load: Adding top consuming processes option + check_http: Adding Proxy-Authorization and extra headers + check_snmp: make calcualtion of timeout value in help output more clear + check_uptime: new plugin for checking uptime to see how long the system is running + check_curl: check_http replacement based on libcurl + check_http: Allow user to specify HTTP method after proxy CONNECT + check_http: Add new flag --show-body/-B to print body + check_cluster: Added data argument validation + check_icmp: Add IPv6 support + check_icmp: Automatically detect IP protocol + check_icmp: emit error if multiple protocol version + check_disk: add support to display inodes usage in perfdata + check_hpjd: Added -D option to disable warning on 'out of paper' + check_http: support the --show-body/-B flag when --expect is used + check_mysql: allow mariadbclient to be used + check_tcp: add --sni + check_dns: detect unreachable dns service in nslookup output FIXES Fix regression where check_dhcp was rereading response in a tight loop + check_dns: fix error detection on sles nslookup + check_disk_smb: fix timeout issue + check_swap: repaired "-n" behaviour + check_icmp: Correctly set address_family on lookup + check_icmp: Do not overwrite -4,-6 on lookup + check_smtp: initializes n before it is used + check_dns: fix typo in parameter description + check_by_ssh: fix child process leak on timeouts + check_mysql: Allow sockets to be specified to -H + check_procs: improve command examples for 'at least' processes + check_swap: repaired "-n" behaviour + check_disk: include -P switch in help + check_mailq: restore accidentially removed options 2.2 29th November 2016 ENHANCEMENTS -- cgit v0.10-9-g596f From bcedcee206b489d9fc2fb5ae49f934c1b44ee1d0 Mon Sep 17 00:00:00 2001 From: Jan Wagner Date: Wed, 9 Dec 2020 22:35:02 +0100 Subject: New version number for git diff --git a/NP-VERSION-GEN b/NP-VERSION-GEN index dd74d0c..c353b1d 100755 --- a/NP-VERSION-GEN +++ b/NP-VERSION-GEN @@ -6,7 +6,7 @@ SRC_ROOT=`dirname $0` NPVF=NP-VERSION-FILE -DEF_VER=2.3 +DEF_VER=2.3git LF=' ' diff --git a/configure.ac b/configure.ac index 562efcd..7c17dcd 100644 --- a/configure.ac +++ b/configure.ac @@ -1,6 +1,6 @@ dnl Process this file with autoconf to produce a configure script. AC_PREREQ(2.59) -AC_INIT(monitoring-plugins,2.3) +AC_INIT(monitoring-plugins,2.3git) AC_CONFIG_SRCDIR(NPTest.pm) AC_CONFIG_FILES([gl/Makefile]) AC_CONFIG_AUX_DIR(build-aux) -- cgit v0.10-9-g596f From b42294b1ebcb7d4661596d487894114a893dff17 Mon Sep 17 00:00:00 2001 From: Jan Wagner Date: Wed, 9 Dec 2020 22:52:08 +0100 Subject: New version in NEWS diff --git a/NEWS b/NEWS index f9f2da6..4061c03 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,10 @@ This file documents the major additions and syntax changes between releases. +2.4 [...] + ENHANCEMENTS + + FIXES + 2.3 10th December 2020 ENHANCEMENTS check_dns: allow 'expected address' (-a) to be specified in CIDR notation -- cgit v0.10-9-g596f From 7fdbea06c7d7f82359d04903be1bdb0eea5a9e89 Mon Sep 17 00:00:00 2001 From: Jan Wagner Date: Wed, 9 Dec 2020 22:54:38 +0100 Subject: Prepare the release docu for 2024 when we release 2.4 diff --git a/doc/RELEASING.md b/doc/RELEASING.md index 1f9db07..bcd2c5a 100644 --- a/doc/RELEASING.md +++ b/doc/RELEASING.md @@ -11,14 +11,14 @@ Before you start - Check Travis CI status. - Update local Git repository to the current `master` tip. For a - maintenance release (e.g., version 2.2.2), update to the current - `maint-2.2` tip, instead. + maintenance release (e.g., version 2.3.2), update to the current + `maint-2.3` tip, instead. Prepare and commit files ------------------------ - Update `configure.ac` and `NP-VERSION-GEN` with new version. -- Update `NEWS` from `git log --reverse v2.2.1..` output, and specify +- Update `NEWS` from `git log --reverse v2.3.1..` output, and specify the release version/date. - Update `AUTHORS` if there are new team members. - Update `THANKS.in` using `tools/update-thanks`. @@ -29,27 +29,27 @@ Prepare and commit files Create annotated tag -------------------- - git tag -a -m 'Monitoring Plugins 2.3' v2.3 + git tag -a -m 'Monitoring Plugins 2.4' v2.4 Push the code and tag to GitHub ------------------------------- git push monitoring-plugins master - git push monitoring-plugins v2.3 + git push monitoring-plugins v2.4 Create new maintenance branch ----------------------------- _Only necessary when creating a feature release._ - git checkout -b maint-2.3 v2.3 - git push -u monitoring-plugins maint-2.3 + git checkout -b maint-2.4 v2.4 + git push -u monitoring-plugins maint-2.4 Checkout new version -------------------- rm -rf /tmp/plugins - git archive --prefix=tmp/plugins/ v2.3 | (cd /; tar -xf -) + git archive --prefix=tmp/plugins/ v2.4 | (cd /; tar -xf -) Build the tarball ----------------- @@ -62,26 +62,26 @@ Build the tarball Upload tarball to web site -------------------------- - scp monitoring-plugins-2.3.tar.gz \ + scp monitoring-plugins-2.4.tar.gz \ plugins@orwell.monitoring-plugins.org:web/download/ Generate SHA1 checksum file on web site --------------------------------------- ssh plugins@orwell.monitoring-plugins.org \ - '(cd web/download; $HOME/bin/create-checksum monitoring-plugins-2.3.tar.gz)' + '(cd web/download; $HOME/bin/create-checksum monitoring-plugins-2.4.tar.gz)' Announce new release -------------------- - In the site.git repository: - - Create `web/input/news/release-2-3.md`. + - Create `web/input/news/release-2-4.md`. - Update the `plugins_release` version in `web/macros.py`. - Commit and push the result: - git add web/input/news/release-2-3.md - git commit web/input/news/release-2-3.md web/macros.py + git add web/input/news/release-2-4.md + git commit web/input/news/release-2-4.md web/macros.py git push origin master - Post an announcement on (at least) the following mailing lists: @@ -93,6 +93,6 @@ Announce new release If you want to mention the number of contributors in the announcement: - git shortlog -s v2.2.1..v2.3 | wc -l + git shortlog -s v2.3.1..v2.4 | wc -l -- cgit v0.10-9-g596f From dbdd0f972af15db15a4e556bd6b2ccf149f59266 Mon Sep 17 00:00:00 2001 From: Tim Gates Date: Sat, 19 Dec 2020 17:14:23 +1100 Subject: docs: fix simple typo, conspicuosly -> conspicuously There is a small typo in plugins-root/check_icmp.c. Should read `conspicuously` rather than `conspicuosly`. diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index e45fdf6..31eb4c6 100644 --- a/plugins-root/check_icmp.c +++ b/plugins-root/check_icmp.c @@ -1134,7 +1134,7 @@ finish(int sig) while(host) { if(!host->icmp_recv) { /* rta 0 is ofcourse not entirely correct, but will still show up - * conspicuosly as missing entries in perfparse and cacti */ + * conspicuously as missing entries in perfparse and cacti */ pl = 100; rta = 0; status = STATE_CRITICAL; -- cgit v0.10-9-g596f From 8eaccee190734a12763a51aaa8a46f324f6742ec Mon Sep 17 00:00:00 2001 From: Wolfgang Karall-Ahlborn Date: Sun, 3 Jan 2021 11:27:44 +0100 Subject: check_procs -- exchange needle and haystack in strstr() for proper state match diff --git a/plugins/check_procs.c b/plugins/check_procs.c index f7917c3..0de6be9 100644 --- a/plugins/check_procs.c +++ b/plugins/check_procs.c @@ -265,7 +265,7 @@ main (int argc, char **argv) } } - if ((options & STAT) && (strstr (statopts, procstat))) + if ((options & STAT) && (strstr (procstat, statopts))) resultsum |= STAT; if ((options & ARGS) && procargs && (strstr (procargs, args) != NULL)) resultsum |= ARGS; -- cgit v0.10-9-g596f From 9076ea36f70dbd643de4102a88dbd2f18847af16 Mon Sep 17 00:00:00 2001 From: Wolfgang Karall-Ahlborn Date: Sun, 3 Jan 2021 12:18:31 +0100 Subject: check_procs -- update test data too diff --git a/plugins/tests/check_procs.t b/plugins/tests/check_procs.t index 54d43d9..6d71015 100755 --- a/plugins/tests/check_procs.t +++ b/plugins/tests/check_procs.t @@ -83,7 +83,7 @@ is( $result->output, 'PROCS OK: 3 processes with RSS >= 100000 | procs=3;;;0;', $result = NPTest->testCmd( "$command -s S" ); is( $result->return_code, 0, "Checking filter for sleeping processes" ); -like( $result->output, '/^PROCS OK: 44 processes with STATE = S/', "Output correct" ); +like( $result->output, '/^PROCS OK: 88 processes with STATE = S/', "Output correct" ); $result = NPTest->testCmd( "$command -s Z" ); is( $result->return_code, 0, "Checking filter for zombies" ); -- cgit v0.10-9-g596f From ede8defad4f44478f69e148022b542a694498087 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Tue, 19 Jan 2021 18:32:27 +0100 Subject: check_curl: fixed help, usage and errors for TLS 1.3 diff --git a/plugins/check_curl.c b/plugins/check_curl.c index 2d69b31..ef77918 100644 --- a/plugins/check_curl.c +++ b/plugins/check_curl.c @@ -1354,7 +1354,7 @@ process_arguments (int argc, char **argv) ssl_version = CURL_SSLVERSION_DEFAULT; #endif /* LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 52, 0) */ else - usage4 (_("Invalid option - Valid SSL/TLS versions: 2, 3, 1, 1.1, 1.2 (with optional '+' suffix)")); + usage4 (_("Invalid option - Valid SSL/TLS versions: 2, 3, 1, 1.1, 1.2, 1.3 (with optional '+' suffix)")); } #if LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 54, 0) if (got_plus) { @@ -1659,7 +1659,7 @@ print_help (void) printf (" %s\n", "-S, --ssl=VERSION[+]"); printf (" %s\n", _("Connect via SSL. Port defaults to 443. VERSION is optional, and prevents")); printf (" %s\n", _("auto-negotiation (2 = SSLv2, 3 = SSLv3, 1 = TLSv1, 1.1 = TLSv1.1,")); - printf (" %s\n", _("1.2 = TLSv1.2). With a '+' suffix, newer versions are also accepted.")); + printf (" %s\n", _("1.2 = TLSv1.2, 1.3 = TLSv1.3). With a '+' suffix, newer versions are also accepted.")); printf (" %s\n", _("Note: SSLv2 and SSLv3 are deprecated and are usually disabled in libcurl")); printf (" %s\n", "--sni"); printf (" %s\n", _("Enable SSL/TLS hostname extension support (SNI)")); -- cgit v0.10-9-g596f From d9a5d1faf0400b9da47dee516c035da1a93dc12c Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Tue, 19 Jan 2021 18:35:41 +0100 Subject: check_curl: fixed a potential buffer overflow in url buffer diff --git a/plugins/check_curl.c b/plugins/check_curl.c index ef77918..a3f63f1 100644 --- a/plugins/check_curl.c +++ b/plugins/check_curl.c @@ -1041,7 +1041,7 @@ redir (curlhelp_write_curlbuf* header_buf) const UriPathSegmentA* p = uri.pathHead; for (; p; p = p->next) { strncat (new_url, "/", DEFAULT_BUFFER_SIZE); - strncat (new_url, uri_string (p->text, buf, DEFAULT_BUFFER_SIZE), DEFAULT_BUFFER_SIZE); + strncat (new_url, uri_string (p->text, buf, DEFAULT_BUFFER_SIZE), DEFAULT_BUFFER_SIZE-1); } } -- cgit v0.10-9-g596f From dae075e65a38c65352d04f8c8fdfa21e2056d01c Mon Sep 17 00:00:00 2001 From: Florian Lohoff Date: Mon, 15 Feb 2021 15:34:07 +0100 Subject: Using snprintf which honors the buffers size and guarantees null termination. (Closes: #1601) As strcpy may overflow the resulting buffer: flo@p5:~$ /tmp/f/usr/lib/nagios/plugins/check_pgsql -d "$(seq 1 10000)" *** buffer overflow detected ***: terminated Aborted I would propose to change the code rather like this, using snprintf which honors the buffers size and guarantees null termination. diff --git a/plugins/check_pgsql.c b/plugins/check_pgsql.c index 11ce691..b8fc5f1 100644 --- a/plugins/check_pgsql.c +++ b/plugins/check_pgsql.c @@ -347,7 +347,7 @@ process_arguments (int argc, char **argv) if (!is_pg_dbname (optarg)) /* checks length and valid chars */ usage2 (_("Database name is not valid"), optarg); else /* we know length, and know optarg is terminated, so us strcpy */ - strcpy (dbName, optarg); + snprintf(dbName, NAMEDATALEN, "%s", optarg); break; case 'l': /* login name */ if (!is_pg_logname (optarg)) -- cgit v0.10-9-g596f From 0f926a3566fb6f3333f3a24e47e2ad204fd0fba4 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Mon, 8 Mar 2021 19:46:43 +0100 Subject: check_curl: added string_statuscode function for printing HTTP/1.1 and HTTP/2 correctly diff --git a/plugins/check_curl.c b/plugins/check_curl.c index a3f63f1..8f274c2 100644 --- a/plugins/check_curl.c +++ b/plugins/check_curl.c @@ -296,6 +296,28 @@ CURLcode sslctxfun(CURL *curl, SSL_CTX *sslctx, void *parm) #endif /* USE_OPENSSL */ #endif /* HAVE_SSL */ +/* returns a string "HTTP/1.x" or "HTTP/2" */ +static char *string_statuscode (int major, int minor) +{ + static char buf[10]; + + switch (major) { + case 1: + snprintf (buf, sizeof (buf), "HTTP/%d.%d", major, minor); + break; + case 2: + case 3: + snprintf (buf, sizeof (buf), "HTTP/%d", major); + break; + default: + /* assuming here HTTP/N with N>=4 */ + snprintf (buf, sizeof (buf), "HTTP/%d", major); + break; + } + + return buf; +} + /* Checks if the server 'reply' is one of the expected 'statuscodes' */ static int expected_statuscode (const char *reply, const char *statuscodes) @@ -746,7 +768,8 @@ GOT_FIRST_CERT: if (curlhelp_parse_statusline (header_buf.buf, &status_line) < 0) { snprintf (msg, DEFAULT_BUFFER_SIZE, "Unparsable status line in %.3g seconds response time|%s\n", total_time, perfstring); - die (STATE_CRITICAL, "HTTP CRITICAL HTTP/1.x %ld unknown - %s", code, msg); + /* 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); } /* get result code from cURL */ @@ -823,8 +846,8 @@ GOT_FIRST_CERT: /* check status codes, set exit status accordingly */ if( status_line.http_code != code ) { - die (STATE_CRITICAL, _("HTTP CRITICAL HTTP/%d.%d %d %s - different HTTP codes (cUrl has %ld)\n"), - status_line.http_major, status_line.http_minor, + die (STATE_CRITICAL, _("HTTP CRITICAL %s %d %s - different HTTP codes (cUrl has %ld)\n"), + string_statuscode (status_line.http_major, status_line.http_minor), status_line.http_code, status_line.msg, code); } @@ -895,8 +918,8 @@ GOT_FIRST_CERT: 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: HTTP/%d.%d %d %s%s%s - %d bytes in %.3f second response time %s|%s\n", - state_text(result), status_line.http_major, status_line.http_minor, + die (result, "HTTP %s: %s %d %s%s%s - %d bytes in %.3f second response time %s|%s\n", + state_text(result), string_statuscode (status_line.http_major, status_line.http_minor), status_line.http_code, status_line.msg, strlen(msg) > 0 ? " - " : "", msg, page_len, total_time, -- cgit v0.10-9-g596f From 5cfc93d995cfd5cc7d1a469f3c1276c4884da2a2 Mon Sep 17 00:00:00 2001 From: Sven Nierlein Date: Thu, 11 Mar 2021 13:33:16 +0100 Subject: fix check_curl crash if http header contains leading spaces check_curl crashes when a (broken) http server returns invalid http header with leading spaces or double colons. This PR adds a fix and a test case for this. Signed-off-by: Sven Nierlein diff --git a/plugins/check_curl.c b/plugins/check_curl.c index 2d69b31..ef96218 100644 --- a/plugins/check_curl.c +++ b/plugins/check_curl.c @@ -2037,7 +2037,7 @@ get_header_value (const struct phr_header* headers, const size_t nof_headers, co { int i; for( i = 0; i < nof_headers; i++ ) { - if( strncasecmp( header, headers[i].name, max( headers[i].name_len, 4 ) ) == 0 ) { + if(headers[i].name != NULL && strncasecmp( header, headers[i].name, max( headers[i].name_len, 4 ) ) == 0 ) { return strndup( headers[i].value, headers[i].value_len ); } } diff --git a/plugins/tests/check_curl.t b/plugins/tests/check_curl.t index 1afbe4b..0caad23 100755 --- a/plugins/tests/check_curl.t +++ b/plugins/tests/check_curl.t @@ -21,7 +21,7 @@ use FindBin qw($Bin); $ENV{'LC_TIME'} = "C"; -my $common_tests = 70; +my $common_tests = 72; my $ssl_only_tests = 8; # Check that all dependent modules are available eval "use HTTP::Daemon 6.01;"; @@ -188,6 +188,12 @@ sub run_server { $c->send_basic_header; $c->send_header('foo'); $c->send_crlf; + } elsif ($r->url->path eq "/header_broken_check") { + $c->send_basic_header; + $c->send_header('foo'); + print $c "Test1:: broken\n"; + print $c " Test2: leading whitespace\n"; + $c->send_crlf; } elsif ($r->url->path eq "/virtual_port") { # return sent Host header $c->send_basic_header; @@ -247,7 +253,7 @@ my $cmd; # advanced checks with virtual hostname and virtual port SKIP: { skip "libcurl version is smaller than $required_version", 6 unless $use_advanced_checks; - + # http without virtual port $cmd = "./$plugin -H $virtual_host -I 127.0.0.1 -p $port_http -u /virtual_port -r ^$virtual_host:$port_http\$"; $result = NPTest->testCmd( $cmd ); @@ -259,7 +265,7 @@ SKIP: { $result = NPTest->testCmd( $cmd ); is( $result->return_code, 0, $cmd); like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output ); - + # http with virtual port (80) $cmd = "./$plugin -H $virtual_host:80 -I 127.0.0.1 -p $port_http -u /virtual_port -r ^$virtual_host\$"; $result = NPTest->testCmd( $cmd ); @@ -321,6 +327,10 @@ sub run_common_tests { is( $result->return_code, 2, "Missing header string check"); like( $result->output, qr%^HTTP CRITICAL: HTTP/1\.1 200 OK - header 'bar' not found on 'https?://127\.0\.0\.1:\d+/header_check'%, "Shows search string and location"); + $result = NPTest->testCmd( "$command -u /header_broken_check" ); + is( $result->return_code, 0, "header_check search for string"); + like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - 138 bytes in [\d\.]+ second/', "Output correct" ); + my $cmd; $cmd = "$command -u /slow"; $result = NPTest->testCmd( $cmd ); -- cgit v0.10-9-g596f From 2482950e267a752b37d696c10ea091dc62d6d8a7 Mon Sep 17 00:00:00 2001 From: Barak Shohat Date: Tue, 6 Apr 2021 16:35:20 +0300 Subject: Updated check_curl.c to display a specific human-readable error message where possible diff --git a/plugins/check_curl.c b/plugins/check_curl.c index 8f274c2..8cb2ff4 100644 --- a/plugins/check_curl.c +++ b/plugins/check_curl.c @@ -313,8 +313,8 @@ static char *string_statuscode (int major, int minor) /* assuming here HTTP/N with N>=4 */ snprintf (buf, sizeof (buf), "HTTP/%d", major); break; - } - + } + return buf; } @@ -662,7 +662,7 @@ check_http (void) /* Curl errors, result in critical Nagios state */ if (res != CURLE_OK) { snprintf (msg, DEFAULT_BUFFER_SIZE, _("Invalid HTTP response received from host on port %d: cURL returned %d - %s"), - server_port, res, curl_easy_strerror(res)); + server_port, res, errbuf[0] ? errbuf : curl_easy_strerror(res)); die (STATE_CRITICAL, "HTTP CRITICAL - %s\n", msg); } diff --git a/plugins/t/check_curl.t b/plugins/t/check_curl.t index 4bff538..cc65f03 100644 --- a/plugins/t/check_curl.t +++ b/plugins/t/check_curl.t @@ -46,7 +46,7 @@ $res = NPTest->testCmd( ); cmp_ok( $res->return_code, '==', 2, "Webserver $host_nonresponsive not responding" ); # was CRITICAL only, but both check_curl and check_http print HTTP CRITICAL (puzzle?!) -cmp_ok( $res->output, 'eq', "HTTP CRITICAL - Invalid HTTP response received from host on port 80: cURL returned 28 - Timeout was reached", "Output OK"); +like( $res->output, "/HTTP CRITICAL - Invalid HTTP response received from host on port 80: cURL returned 28 - Connection timed out after/", "Output OK"); $res = NPTest->testCmd( "./$plugin $hostname_invalid -wt 1 -ct 2" @@ -56,7 +56,7 @@ cmp_ok( $res->return_code, '==', 2, "Webserver $hostname_invalid not valid" ); # On Debian, it is Name or service not known, on Darwin, it is No address associated with nodename # Is also possible to get a socket timeout if DNS is not responding fast enough # cURL gives us consistent strings from it's own 'lib/strerror.c' -like( $res->output, "/cURL returned 6 - Couldn't resolve host name/", "Output OK"); +like( $res->output, "/cURL returned 6 - Could not resolve host:/", "Output OK"); # host header checks $res = NPTest->testCmd("./$plugin -v -H $host_tcp_http"); -- cgit v0.10-9-g596f From 6993c216955a54845d98dc568534613334c0b545 Mon Sep 17 00:00:00 2001 From: Barak Shohat Date: Wed, 7 Apr 2021 12:34:46 +0300 Subject: Add an option to check_curl to verify the peer certificate & host using the system CA's diff --git a/plugins/check_curl.c b/plugins/check_curl.c index 8f274c2..19f80b7 100644 --- a/plugins/check_curl.c +++ b/plugins/check_curl.c @@ -195,6 +195,7 @@ 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; #if defined(HAVE_SSL) && defined(USE_OPENSSL) X509 *cert = NULL; @@ -489,9 +490,11 @@ check_http (void) if (client_privkey) handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_SSLKEY, client_privkey), "CURLOPT_SSLKEY"); if (ca_cert) { + handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_CAINFO, ca_cert), "CURLOPT_CAINFO"); + } + if (ca_cert || verify_peer_and_host) { /* per default if we have a CA verify both the peer and the * hostname in the certificate, can be switched off later */ - handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_CAINFO, ca_cert), "CURLOPT_CAINFO"); handle_curl_option_return_code (curl_easy_setopt( curl, CURLOPT_SSL_VERIFYPEER, 1), "CURLOPT_SSL_VERIFYPEER"); handle_curl_option_return_code (curl_easy_setopt( curl, CURLOPT_SSL_VERIFYHOST, 2), "CURLOPT_SSL_VERIFYHOST"); } else { @@ -1159,6 +1162,7 @@ process_arguments (int argc, char **argv) {"client-cert", required_argument, 0, 'J'}, {"private-key", required_argument, 0, 'K'}, {"ca-cert", required_argument, 0, CA_CERT_OPTION}, + {"verify-cert", no_argument, 0, 'D'}, {"useragent", required_argument, 0, 'A'}, {"header", required_argument, 0, 'k'}, {"no-body", no_argument, 0, 'N'}, @@ -1193,7 +1197,7 @@ process_arguments (int argc, char **argv) server_url = strdup(DEFAULT_SERVER_URL); while (1) { - c = getopt_long (argc, argv, "Vvh46t:c:w:A:k:H:P:j:T:I:a:b:d:e:p:s:R:r:u:f:C:J:K:nlLS::m:M:NE", longopts, &option); + c = getopt_long (argc, argv, "Vvh46t:c:w:A:k:H:P:j:T:I:a:b:d:e:p:s:R:r:u:f:C:J:K:DnlLS::m:M:NE", longopts, &option); if (c == -1 || c == EOF || c == 1) break; @@ -1333,6 +1337,11 @@ process_arguments (int argc, char **argv) ca_cert = optarg; goto enable_ssl; #endif +#ifdef LIBCURL_FEATURE_SSL + case 'D': /* verify peer certificate & host */ + verify_peer_and_host = TRUE; + goto enable_ssl; +#endif case 'S': /* use SSL */ #ifdef LIBCURL_FEATURE_SSL enable_ssl: @@ -1703,6 +1712,8 @@ print_help (void) printf (" %s\n", _("matching the client certificate")); printf (" %s\n", "--ca-cert=FILE"); printf (" %s\n", _("CA certificate file to verify peer against")); + printf (" %s\n", "-D, --verify-cert"); + printf (" %s\n", _("Verify the peer's SSL certificate and hostname")); #endif printf (" %s\n", "-e, --expect=STRING"); @@ -1836,7 +1847,7 @@ print_usage (void) { printf ("%s\n", _("Usage:")); printf (" %s -H | -I [-u ] [-p ]\n",progname); - printf (" [-J ] [-K ] [--ca-cert ]\n"); + printf (" [-J ] [-K ] [--ca-cert ] [-D]\n"); printf (" [-w ] [-c ] [-t ] [-L] [-E] [-a auth]\n"); printf (" [-b proxy_auth] [-f ]\n"); printf (" [-e ] [-d string] [-s string] [-l] [-r | -R ]\n"); diff --git a/plugins/t/check_curl.t b/plugins/t/check_curl.t index 4bff538..55577ad 100644 --- a/plugins/t/check_curl.t +++ b/plugins/t/check_curl.t @@ -9,7 +9,7 @@ use Test::More; use POSIX qw/mktime strftime/; use NPTest; -plan tests => 57; +plan tests => 58; my $successOutput = '/OK.*HTTP.*second/'; @@ -94,6 +94,9 @@ SKIP: { $res = NPTest->testCmd("./$plugin -v -H $host_tls_http:443 -S -p 443"); like( $res->output, '/^Host: '.$host_tls_http.'\s*$/ms', "Host Header OK" ); + + $res = NPTest->testCmd("./$plugin -v -H $host_tls_http -D -p 443"); + like( $res->output, '/(^Host: '.$host_tls_http.'\s*$)|(cURL returned 60)/ms', "Host Header OK" ); }; SKIP: { -- cgit v0.10-9-g596f From f90aec83cb20263401ab620d07e4914355d9681d Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Thu, 8 Apr 2021 14:07:20 +0200 Subject: check_curl: Increase regexp limit (to 1024 as in check_http) diff --git a/plugins/check_curl.c b/plugins/check_curl.c index 8125ee8..f900f16 100644 --- a/plugins/check_curl.c +++ b/plugins/check_curl.c @@ -117,7 +117,7 @@ typedef enum curlhelp_ssl_library { enum { REGS = 2, - MAX_RE_SIZE = 256 + MAX_RE_SIZE = 1024 }; #include "regex.h" regex_t preg; -- cgit v0.10-9-g596f From a6acea7941a2a5519ab49d13b5adf946a50b5ea5 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Thu, 8 Apr 2021 14:15:54 +0200 Subject: check_curl: make -C obvious (from check_http) diff --git a/plugins/check_curl.c b/plugins/check_curl.c index f900f16..892300a 100644 --- a/plugins/check_curl.c +++ b/plugins/check_curl.c @@ -1852,9 +1852,11 @@ print_usage (void) printf (" [-b proxy_auth] [-f ]\n"); printf (" [-e ] [-d string] [-s string] [-l] [-r | -R ]\n"); printf (" [-P string] [-m :] [-4|-6] [-N] [-M ]\n"); - printf (" [-A string] [-k string] [-S ] [--sni] [-C [,]]\n"); + printf (" [-A string] [-k string] [-S ] [--sni]\n"); printf (" [-T ] [-j method]\n"); printf (" [--http-version=]\n"); + printf (" %s -H | -I -C [,]\n",progname); + printf (" [-p ] [-t ] [-4|-6] [--sni]\n"); printf ("\n"); printf ("%s\n", _("WARNING: check_curl is experimental. Please use")); printf ("%s\n\n", _("check_http if you need a stable version.")); -- cgit v0.10-9-g596f From 1debd29b573f4d81eeba4d7f78f797c348b231ce Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Thu, 8 Apr 2021 15:14:53 +0200 Subject: check_curl: make -C obvious (from check_http, part 2) diff --git a/plugins/check_curl.c b/plugins/check_curl.c index 892300a..8fc97f4 100644 --- a/plugins/check_curl.c +++ b/plugins/check_curl.c @@ -1858,6 +1858,10 @@ print_usage (void) printf (" %s -H | -I -C [,]\n",progname); printf (" [-p ] [-t ] [-4|-6] [--sni]\n"); printf ("\n"); +#ifdef LIBCURL_FEATURE_SSL + printf ("%s\n", _("In the first form, make an HTTP request.")); + printf ("%s\n\n", _("In the second form, connect to the server and check the TLS certificate.")); +#endif printf ("%s\n", _("WARNING: check_curl is experimental. Please use")); printf ("%s\n\n", _("check_http if you need a stable version.")); } -- cgit v0.10-9-g596f From cd358cd08a6ddceece836788078ec96b5f8eb0c5 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Thu, 8 Apr 2021 20:39:48 +0200 Subject: check_curl: backported --show-body/-B to print body (from check_http) diff --git a/plugins/check_curl.c b/plugins/check_curl.c index 8fc97f4..99833f6 100644 --- a/plugins/check_curl.c +++ b/plugins/check_curl.c @@ -145,6 +145,7 @@ thresholds *thlds; char user_agent[DEFAULT_BUFFER_SIZE]; int verbose = 0; int show_extended_perfdata = FALSE; +int show_body = FALSE; int min_page_len = 0; int max_page_len = 0; int redir_depth = 0; @@ -792,7 +793,9 @@ GOT_FIRST_CERT: snprintf(msg, DEFAULT_BUFFER_SIZE, _("Invalid HTTP response received from host: %s\n"), status_line.first_line); else snprintf(msg, DEFAULT_BUFFER_SIZE, _("Invalid HTTP response received from host on port %d: %s\n"), server_port, status_line.first_line); - die (STATE_CRITICAL, "HTTP CRITICAL - %s", msg); + die (STATE_CRITICAL, "HTTP CRITICAL - %s%s%s", msg, + show_body ? "\n" : "", + show_body ? body_buf.buf : ""); } if( server_expect_yn ) { @@ -921,13 +924,15 @@ GOT_FIRST_CERT: 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", + 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), status_line.http_code, status_line.msg, strlen(msg) > 0 ? " - " : "", msg, page_len, total_time, (display_html ? "" : ""), - perfstring); + perfstring, + (show_body ? body_buf.buf : ""), + (show_body ? "\n" : "") ); /* proper cleanup after die? */ curlhelp_free_statusline(&status_line); @@ -1173,6 +1178,7 @@ process_arguments (int argc, char **argv) {"use-ipv4", no_argument, 0, '4'}, {"use-ipv6", no_argument, 0, '6'}, {"extended-perfdata", no_argument, 0, 'E'}, + {"show-body", no_argument, 0, 'B'}, {"http-version", required_argument, 0, HTTP_VERSION_OPTION}, {0, 0, 0, 0} }; @@ -1197,7 +1203,7 @@ process_arguments (int argc, char **argv) server_url = strdup(DEFAULT_SERVER_URL); while (1) { - c = getopt_long (argc, argv, "Vvh46t:c:w:A:k:H:P:j:T:I:a:b:d:e:p:s:R:r:u:f:C:J:K:DnlLS::m:M:NE", longopts, &option); + c = getopt_long (argc, argv, "Vvh46t:c:w:A:k:H:P:j:T:I:a:b:d:e:p:s:R:r:u:f:C:J:K:DnlLS::m:M:NEB", longopts, &option); if (c == -1 || c == EOF || c == 1) break; @@ -1545,6 +1551,9 @@ process_arguments (int argc, char **argv) case 'E': /* show extended perfdata */ show_extended_perfdata = TRUE; break; + case 'B': /* print body content after status line */ + show_body = TRUE; + break; case HTTP_VERSION_OPTION: curl_http_version = CURL_HTTP_VERSION_NONE; if (strcmp (optarg, "1.0") == 0) { @@ -1757,6 +1766,8 @@ print_help (void) printf (" %s\n", _("Any other tags to be sent in http header. Use multiple times for additional headers")); printf (" %s\n", "-E, --extended-perfdata"); printf (" %s\n", _("Print additional performance data")); + printf (" %s\n", "-B, --show-body"); + printf (" %s\n", _("Print body content below status line")); printf (" %s\n", "-L, --link"); printf (" %s\n", _("Wrap output in HTML link (obsoleted by urlize)")); printf (" %s\n", "-f, --onredirect="); -- cgit v0.10-9-g596f From f0ac7fcc7c40fab04c00fbbc8c091e89e77b0f74 Mon Sep 17 00:00:00 2001 From: Barak Shohat Date: Mon, 12 Apr 2021 19:06:27 +0300 Subject: check_curl: Fix bug where headers beginning with HTTP_ cause the status line parsing to fail. diff --git a/plugins/check_curl.c b/plugins/check_curl.c index 99833f6..3e0a6f9 100644 --- a/plugins/check_curl.c +++ b/plugins/check_curl.c @@ -1995,7 +1995,7 @@ curlhelp_parse_statusline (const char *buf, curlhelp_statusline *status_line) char *first_line_buf; /* find last start of a new header */ - start = strrstr2 (buf, "\r\nHTTP"); + start = strrstr2 (buf, "\r\nHTTP/"); if (start != NULL) { start += 2; buf = start; -- cgit v0.10-9-g596f From a4308b19135bdadf339163f7e127c628d987a0fc Mon Sep 17 00:00:00 2001 From: PhiBo Date: Wed, 28 Apr 2021 15:11:23 +0200 Subject: Add CodeQL checks Add initial github actions to perform CodeQL securtiy checks diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml new file mode 100644 index 0000000..9de367e --- /dev/null +++ b/.github/workflows/codeql-analysis.yml @@ -0,0 +1,71 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL" + +on: + push: + branches: [ master ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ master ] + schedule: + - cron: '15 18 * * 0' + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: [ 'cpp' ] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] + # Learn more: + # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v1 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + # queries: ./path/to/local/query, your-org/your-repo/queries@main + + - name: Install packages + run: | + sudo apt-get install -y --no-install-recommends m4 gettext automake autoconf make build-essential + sudo apt-get install -y --no-install-recommends perl autotools-dev libdbi-dev libldap2-dev libpq-dev \ + libmysqlclient-dev libradcli-dev libkrb5-dev libdbi0-dev \ + libdbd-sqlite3 libssl-dev libcurl4-openssl-dev liburiparser-dev + + - name: Configure build + run: | + ./tools/setup + ./configure --enable-libtap + + - name: Build + run: | + make + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v1 -- cgit v0.10-9-g596f From 444a3579b2168eda949943a060bddff9ec95fd99 Mon Sep 17 00:00:00 2001 From: Sven Nierlein Date: Mon, 12 Apr 2021 17:21:47 +0200 Subject: fix fping test in case of dns errors, fping returns an unknown and thats ok. diff --git a/plugins/t/check_fping.t b/plugins/t/check_fping.t index 342b0a7..03a6110 100644 --- a/plugins/t/check_fping.t +++ b/plugins/t/check_fping.t @@ -12,9 +12,6 @@ use vars qw($tests); BEGIN {$tests = 4; plan tests => $tests} -my $successOutput = '/^FPING OK - /'; -my $failureOutput = '/^FPING CRITICAL - /'; - my $host_responsive = getTestParameter("NP_HOST_RESPONSIVE", "The hostname of system responsive to network requests", "localhost"); my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", "The hostname of system not responsive to network requests", "10.0.0.1"); my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", "An invalid (not known to DNS) hostname", "nosuchhost"); @@ -29,9 +26,9 @@ if( ! -x "./check_fping") { elsif ( $> != 0 && (!$fping || ! -u $fping)) { $t += skipMsg( "./check_fping", $tests ); } else { - $t += checkCmd( "./check_fping $host_responsive", 0, $successOutput ); - $t += checkCmd( "./check_fping $host_nonresponsive", [ 1, 2 ] ); - $t += checkCmd( "./check_fping $hostname_invalid", [ 1, 2 ] ); + $t += checkCmd( "./check_fping $host_responsive", 0, '/^FPING OK - /' ); + $t += checkCmd( "./check_fping $host_nonresponsive", 2, '/^FPING CRITICAL - /' ); + $t += checkCmd( "./check_fping $hostname_invalid", 3, '/^FPING UNKNOWN - /' ); } exit(0) if defined($Test::Harness::VERSION); -- cgit v0.10-9-g596f From fc71e3f9304ed51f3fd7ca544f38a30a590c8ba5 Mon Sep 17 00:00:00 2001 From: Sven Nierlein Date: Tue, 13 Apr 2021 09:15:12 +0200 Subject: migrate travis ci to github actions diff --git a/.github/NPTest.cache b/.github/NPTest.cache new file mode 100644 index 0000000..232305a --- /dev/null +++ b/.github/NPTest.cache @@ -0,0 +1,54 @@ +{ + 'NP_ALLOW_SUDO' => 'yes', + 'NP_DNS_SERVER' => '8.8.8.8', + 'NP_GOOD_NTP_SERVICE' => '', + 'NP_HOST_DHCP_RESPONSIVE' => '', + 'NP_HOST_HPJD_PORT_INVALID' => '161', + 'NP_HOST_HPJD_PORT_VALID' => '', + 'NP_HOSTNAME_INVALID_CIDR' => '130.133.8.39/30', + 'NP_HOSTNAME_INVALID' => 'nosuchhost', + 'NP_HOSTNAME_VALID_CIDR' => '130.133.8.41/30', + 'NP_HOSTNAME_VALID_IP' => '130.133.8.40', + 'NP_HOSTNAME_VALID' => 'monitoring-plugins.org', + 'NP_HOSTNAME_VALID_REVERSE' => 'orwell.monitoring-plugins.org.', + 'NP_HOST_NONRESPONSIVE' => '192.168.1.2', + 'NP_HOST_RESPONSIVE' => 'localhost', + 'NP_HOST_SMB' => '', + 'NP_HOST_SNMP' => '', + 'NP_HOST_TCP_FTP' => '', + 'NP_HOST_TCP_HPJD' => '', + 'NP_HOST_TCP_HTTP2' => 'test.monitoring-plugins.org', + 'NP_HOST_TCP_HTTP' => 'localhost', + 'NP_HOST_TCP_IMAP' => 'imap.web.de', + 'NP_HOST_TCP_JABBER' => 'jabber.org', + 'NP_HOST_TCP_LDAP' => 'localhost', + 'NP_HOST_TCP_POP' => 'pop.web.de', + 'NP_HOST_TCP_PROXY' => 'localhost', + 'NP_HOST_TCP_SMTP' => 'localhost', + 'NP_HOST_TCP_SMTP_NOTLS' => '', + 'NP_HOST_TCP_SMTP_TLS' => '', + 'NP_HOST_TLS_CERT' => 'localhost', + 'NP_HOST_TLS_HTTP' => 'localhost', + 'NP_HOST_UDP_TIME' => 'none', + 'NP_INTERNET_ACCESS' => 'yes', + 'NP_LDAP_BASE_DN' => 'dc=nodomain', + 'NP_MOUNTPOINT2_VALID' => '/media/ramdisk1', + 'NP_MOUNTPOINT_VALID' => '/', + 'NP_MYSQL_LOGIN_DETAILS' => '-u root -d test', + 'NP_MYSQL_SERVER' => 'localhost', + 'NP_MYSQL_SOCKET' => '/var/run/mysqld/mysqld.sock', + 'NP_MYSQL_WITH_SLAVE' => '', + 'NP_MYSQL_WITH_SLAVE_LOGIN' => '', + 'NP_NO_NTP_SERVICE' => 'localhost', + 'NP_PORT_TCP_PROXY' => '3128', + 'NP_SMB_SHARE' => '', + 'NP_SMB_SHARE_DENY' => '', + 'NP_SMB_SHARE_SPC' => '', + 'NP_SMB_VALID_USER' => '', + 'NP_SMB_VALID_USER_PASS' => '', + 'NP_SNMP_COMMUNITY' => '', + 'NP_SNMP_USER' => '', + 'NP_SSH_CONFIGFILE' => '~/.ssh/config', + 'NP_SSH_HOST' => 'localhost', + 'NP_SSH_IDENTITY' => '~/.ssh/id_rsa' +} diff --git a/.github/prepare_debian.sh b/.github/prepare_debian.sh new file mode 100755 index 0000000..4005320 --- /dev/null +++ b/.github/prepare_debian.sh @@ -0,0 +1,99 @@ +#!/bin/bash + +set -x +set -e + +export DEBIAN_FRONTEND=noninteractive + +apt-get update +apt-get -y install software-properties-common +if [ $(lsb_release -is) = "Debian" ]; then + apt-add-repository non-free + apt-get update +fi +apt-get -y install perl autotools-dev libdbi-dev libldap2-dev libpq-dev libradcli-dev libnet-snmp-perl procps +apt-get -y install libdbi0-dev libdbd-sqlite3 libssl-dev dnsutils snmp-mibs-downloader libsnmp-perl snmpd +apt-get -y install fping snmp netcat smbclient vsftpd apache2 ssl-cert postfix libhttp-daemon-ssl-perl +apt-get -y install libdbd-sybase-perl libnet-dns-perl +apt-get -y install slapd ldap-utils +apt-get -y install gcc make autoconf automake gettext +apt-get -y install faketime +apt-get -y install libmonitoring-plugin-perl +apt-get -y install libcurl4-openssl-dev +apt-get -y install liburiparser-dev +apt-get -y install squid +apt-get -y install openssh-server +apt-get -y install mariadb-server mariadb-client libmariadb-dev +apt-get -y install cron iputils-ping +apt-get -y install iproute2 + +# remove ipv6 interface from hosts +if [ $(ip addr show | grep "inet6 ::1" | wc -l) -eq "0" ]; then + sed '/^::1/d' /etc/hosts > /tmp/hosts + cp -f /tmp/hosts /etc/hosts +fi + +ip addr show + +cat /etc/hosts + + +# apache +a2enmod ssl +a2ensite default-ssl +make-ssl-cert generate-default-snakeoil --force-overwrite +service apache2 start + +# squid +cp tools/squid.conf /etc/squid/squid.conf +service squid start + +# mariadb +service mariadb start +mysql -e "create database IF NOT EXISTS test;" -uroot + +# ldap +sed -e 's/cn=admin,dc=nodomain/'$(/usr/sbin/slapcat|grep ^dn:|awk '{print $2}')'/' -i .github/NPTest.cache +service slapd start + +# sshd +ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa +cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys +service ssh start +sleep 1 +ssh-keyscan localhost >> ~/.ssh/known_hosts +touch ~/.ssh/config + +# start one login session, required for check_users +( ssh -n -tt root@localhost "top" < /dev/null >/dev/null 2>&1 & ) +sleep 1 +who +ssh root@localhost "top -b -n 1" + +# snmpd +for DIR in /usr/share/snmp/mibs /usr/share/mibs; do + rm -f $DIR/ietf/SNMPv2-PDU \ + $DIR/ietf/IPSEC-SPD-MIB \ + $DIR/ietf/IPATM-IPMC-MIB \ + $DIR/iana/IANA-IPPM-METRICS-REGISTRY-MIB +done +mkdir -p /var/lib/snmp/mib_indexes +sed -e 's/^agentaddress.*/agentaddress 127.0.0.1/' -i /etc/snmp/snmpd.conf +service snmpd start + +# start cron, will be used by check_nagios +cron + +# start postfix +service postfix start + +# start ftpd +service vsftpd start + +# hostname +sed "/NP_HOST_TLS_CERT/s/.*/'NP_HOST_TLS_CERT' => '$(hostname)',/" -i /src/.github/NPTest.cache + +# create some test files to lower inodes +for i in $(seq 10); do + touch /media/ramdisk2/test.$1 +done diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..4c3497d --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,77 @@ +name: Test + +on: + push: + branches: + - '*' + pull_request: + +jobs: +# macos: +# name: Running tests on ${{ matrix.os }} +# strategy: +# fail-fast: false +# matrix: +# os: +# - macos-10.15 +# runs-on: ${{ matrix.os }} +# steps: +# +# - name: Git clone repository +# uses: actions/checkout@v2 +# #- name: Setup tmate session, see https://github.com/marketplace/actions/debugging-with-tmate +# # uses: mxschmitt/action-tmate@v3 +# - name: Prepare machine +# run: | +# brew install automake +# - name: Run the tests +# run: | +# tools/setup \ +# && ./configure --enable-libtap \ +# && make \ +# && make test + + linux: + runs-on: ubuntu-latest + name: Running tests on ${{ matrix.distro }} + strategy: + fail-fast: false + matrix: + distro: + #- 'debian:10' + - 'debian:testing' + #- 'ubuntu:20.10' + #- 'centos:7' + #- 'centos:8' + include: + #- distro: 'debian:10' + # prepare: .github/prepare_debian.sh + - distro: 'debian:testing' + prepare: .github/prepare_debian.sh + #- distro: 'ubuntu:20.10' + # prepare: .github/prepare_debian.sh + #- distro: 'centos:7' + # prepare: .github/prepare_centos.sh + #- distro: 'centos:8' + # prepare: .github/prepare_centos.sh + steps: + - name: Git clone repository + uses: actions/checkout@v2 + #- name: Setup tmate session, see https://github.com/marketplace/actions/debugging-with-tmate + # uses: mxschmitt/action-tmate@v3 + - name: Run the tests on ${{ matrix.distro }} + run: | + docker volume create --driver local --opt type=tmpfs --opt device=tmpfs --opt o=size=100m,uid=1000 tmp-vol + docker run \ + -e NPTEST_ACCEPTDEFAULT=1 \ + -e NPTEST_CACHE="/src/.github/NPTest.cache" \ + -w /src -v ${PWD}:/src \ + --tmpfs /media/ramdisk1 \ + --mount source=tmp-vol,destination=/src,target=/media/ramdisk2 \ + ${{ matrix.distro }} \ + /bin/sh -c '${{ matrix.prepare }} && \ + tools/setup && \ + ./configure --enable-libtap && \ + make && \ + make test' + docker volume rm tmp-vol diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 3d9fe64..0000000 --- a/.travis.yml +++ /dev/null @@ -1,98 +0,0 @@ -sudo: required -dist: xenial -language: c - -env: - global: - # This is the encrypted COVERITY_SCAN_TOKEN, created via the "travis - # encrypt" command using the project repository's public key. - - secure: "ggJ9c/VfKcwtrwz/My+ne4My7D8g3qi3vz5Hh+yLiri0+oIXCy313ZD6ssIEY/5beQZEOnuHhBgBJd/Y3clSQNc2M9fRNc+wxOkIO992lgnY0MZJN3y9MLfpqUbTClhU9Fst0qXQqGpI6UI8yz1tj7yKi7DPrycJLRrjMpyTfyo=" - -matrix: - include: - - compiler: "gcc" - os: linux - env: - - PLATFORM=linux BITS=64 HOST=x86_64 - addons: - coverity_scan: - project: - name: "monitoring-plugins/monitoring-plugins" - description: "Monitoring Plugins" - notification_email: team@monitoring-plugins.org - build_command_prepend: tools/setup && ./configure - build_command: make - branch_pattern: coverity.* - - compiler: "clang" - os: linux - env: - - PLATFORM=linux BITS=64 HOST=x86_64 - -before_install: - # Trusty related fixed - # multiverse is no on trusty activated (https://github.com/travis-ci/travis-ci/issues/4979) - - sudo apt-get install -qq --no-install-recommends software-properties-common - - sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu/ trusty multiverse" && sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu/ trusty-updates multiverse" - # /etc/hosts has IPv6 hosts (https://github.com/travis-ci/travis-ci/issues/4978) - - sudo [ $(ip addr show | grep "inet6 ::1" | wc -l) -eq "0" ] || sudo sed -i '/^::1/d' /etc/hosts - # Trusty has running ntpd on localhost, but we don't like that for our tests - - "sudo killall -9 ntpd ||:" - # Trusty has no swap, lets create some - - sudo fallocate -l 20M /swapfile; sudo chmod 600 /swapfile; sudo mkswap /swapfile; sudo swapon /swapfile - - sudo apt-get update -qq - - sudo apt-get purge -qq gawk - -install: - - sudo apt-get install -qq --no-install-recommends perl autotools-dev libdbi-dev libldap2-dev libpq-dev libmysqlclient-dev libradcli-dev libkrb5-dev libnet-snmp-perl procps - - sudo apt-get install -qq --no-install-recommends libdbi0-dev libdbd-sqlite3 libssl-dev dnsutils snmp-mibs-downloader libsnmp-perl snmpd - - sudo apt-get install -qq --no-install-recommends fping snmp netcat smbclient fping pure-ftpd apache2 ssl-cert postfix libhttp-daemon-ssl-perl - - sudo apt-get install -qq --no-install-recommends libdbd-sybase-perl libnet-dns-perl - - sudo apt-get install -qq --no-install-recommends slapd ldap-utils - - sudo apt-get install -qq --no-install-recommends autoconf automake - - sudo apt-get install -qq --no-install-recommends faketime - - sudo apt-get install -qq --no-install-recommends libmonitoring-plugin-perl - - sudo apt-get install -qq --no-install-recommends libcurl4-openssl-dev - - sudo apt-get install -qq --no-install-recommends liburiparser-dev - - sudo apt-get install -qq --no-install-recommends squid - # Trusty related dependencies (not yet provided) - - test "$(dpkg -l | grep -E "mysql-(client|server)-[0-9].[0-9]" | grep -c ^ii)" -gt 0 || sudo apt-get install -qq --no-install-recommends mariadb-client mariadb-server - # enable ssl apache - - sudo a2enmod ssl - - sudo a2ensite default-ssl - - sudo make-ssl-cert generate-default-snakeoil --force-overwrite - - sudo service apache2 reload - - sudo cp tools/squid.conf /etc/squid/squid.conf - - sudo service squid reload - - sudo service mysql restart - -before_script: - # ensure we have a test database in place for tests - - mysql -e "create database IF NOT EXISTS test;" -uroot - # Detect LDAP configuration (seems volatile on trusty env) - - sed -e 's/cn=admin,dc=nodomain/'$(sudo /usr/sbin/slapcat|grep ^dn:|grep cn=|awk '{print $2}')'/' -i plugins/t/NPTest.cache.travis - - tools/setup - - ./configure --enable-libtap - - make - - export NPTEST_ACCEPTDEFAULT=1 - - export NPTEST_CACHE="$(pwd)/plugins/t/NPTest.cache.travis" - - ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa - - cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys - - ssh-keyscan localhost >> ~/.ssh/known_hosts - - touch ~/.ssh/config - - sudo rm -f /usr/share/mibs/ietf/SNMPv2-PDU /usr/share/mibs/ietf/IPSEC-SPD-MIB /usr/share/mibs/ietf/IPATM-IPMC-MIB /usr/share/mibs/iana/IANA-IPPM-METRICS-REGISTRY-MIB - - sudo mkdir -p /var/lib/snmp/mib_indexes - - sudo mkdir /media/ramdisk && sudo chmod 777 /media/ramdisk && sudo mount -t tmpfs -o size=20% none /media/ramdisk - - sed "/NP_HOST_TLS_CERT/s/.*/'NP_HOST_TLS_CERT' => '$(hostname)',/" -i $NPTEST_CACHE - -script: - - if [ "$COVERITY_SCAN_BRANCH" != 1 ]; then make test; fi - -notifications: - irc: - channels: - - "chat.freenode.net#Monitoring-Plugins" - on_success: change - on_failure: always - skip_join: true - email: - # - team@monitoring-plugins.org diff --git a/plugins/t/NPTest.cache.travis b/plugins/t/NPTest.cache.travis deleted file mode 100644 index 9b9f805..0000000 --- a/plugins/t/NPTest.cache.travis +++ /dev/null @@ -1,54 +0,0 @@ -{ - 'NP_ALLOW_SUDO' => 'yes', - 'NP_DNS_SERVER' => '8.8.8.8', - 'NP_GOOD_NTP_SERVICE' => '', - 'NP_HOST_DHCP_RESPONSIVE' => '', - 'NP_HOST_HPJD_PORT_INVALID' => '161', - 'NP_HOST_HPJD_PORT_VALID' => '', - 'NP_HOSTNAME_INVALID_CIDR' => '130.133.8.39/30', - 'NP_HOSTNAME_INVALID' => 'nosuchhost', - 'NP_HOSTNAME_VALID_CIDR' => '130.133.8.41/30', - 'NP_HOSTNAME_VALID_IP' => '130.133.8.40', - 'NP_HOSTNAME_VALID' => 'monitoring-plugins.org', - 'NP_HOSTNAME_VALID_REVERSE' => 'orwell.monitoring-plugins.org.', - 'NP_HOST_NONRESPONSIVE' => '10.0.0.1', - 'NP_HOST_RESPONSIVE' => 'localhost', - 'NP_HOST_SMB' => '', - 'NP_HOST_SNMP' => '', - 'NP_HOST_TCP_FTP' => '', - 'NP_HOST_TCP_HPJD' => '', - 'NP_HOST_TCP_HTTP2' => 'test.monitoring-plugins.org', - 'NP_HOST_TCP_HTTP' => 'localhost', - 'NP_HOST_TCP_IMAP' => 'imap.web.de', - 'NP_HOST_TCP_JABBER' => 'jabber.org', - 'NP_HOST_TCP_LDAP' => 'localhost', - 'NP_HOST_TCP_POP' => 'pop.web.de', - 'NP_HOST_TCP_PROXY' => 'localhost', - 'NP_HOST_TCP_SMTP' => 'localhost', - 'NP_HOST_TCP_SMTP_NOTLS' => '', - 'NP_HOST_TCP_SMTP_TLS' => '', - 'NP_HOST_TLS_CERT' => 'localhost, - 'NP_HOST_TLS_HTTP' => 'localhost', - 'NP_HOST_UDP_TIME' => 'none', - 'NP_INTERNET_ACCESS' => 'yes', - 'NP_LDAP_BASE_DN' => 'cn=admin,dc=nodomain', - 'NP_MOUNTPOINT2_VALID' => '/media/ramdisk', - 'NP_MOUNTPOINT_VALID' => '/', - 'NP_MYSQL_LOGIN_DETAILS' => '-u root -d test', - 'NP_MYSQL_SERVER' => 'localhost', - 'NP_MYSQL_SOCKET' => '/var/run/mysqld/mysqld.sock', - 'NP_MYSQL_WITH_SLAVE' => '', - 'NP_MYSQL_WITH_SLAVE_LOGIN' => '', - 'NP_NO_NTP_SERVICE' => 'localhost', - 'NP_PORT_TCP_PROXY' => '3128', - 'NP_SMB_SHARE' => '', - 'NP_SMB_SHARE_DENY' => '', - 'NP_SMB_SHARE_SPC' => '', - 'NP_SMB_VALID_USER' => '', - 'NP_SMB_VALID_USER_PASS' => '', - 'NP_SNMP_COMMUNITY' => '', - 'NP_SNMP_USER' => '', - 'NP_SSH_CONFIGFILE' => '~/.ssh/config', - 'NP_SSH_HOST' => 'localhost', - 'NP_SSH_IDENTITY' => '~/.ssh/id_rsa' -} -- cgit v0.10-9-g596f From 40e171b7cdb2262398728aa9b84e747a856d9c1f Mon Sep 17 00:00:00 2001 From: Jacob Hansen Date: Fri, 30 Apr 2021 09:38:19 +0200 Subject: Attempt to fix check_users Signed-off-by: Jacob Hansen diff --git a/.github/prepare_debian.sh b/.github/prepare_debian.sh index 4005320..3693acc 100755 --- a/.github/prepare_debian.sh +++ b/.github/prepare_debian.sh @@ -65,10 +65,12 @@ ssh-keyscan localhost >> ~/.ssh/known_hosts touch ~/.ssh/config # start one login session, required for check_users -( ssh -n -tt root@localhost "top" < /dev/null >/dev/null 2>&1 & ) -sleep 1 -who -ssh root@localhost "top -b -n 1" +#( ssh -n -tt root@localhost "top" < /dev/null >/dev/null 2>&1 & ) +ssh -tt localhost /dev/null 2>/dev/null & +disown %1 +#sleep 1 +#who +#ssh root@localhost "top -b -n 1" # snmpd for DIR in /usr/share/snmp/mibs /usr/share/mibs; do -- cgit v0.10-9-g596f From 5ab03a70950cecf5fe4ab52a3c4f9b0f6ac98939 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aksel=20Sj=C3=B6gren?= Date: Wed, 28 Apr 2021 15:48:20 +0200 Subject: Fix conditional tests for check_http, check_curl Set correct number of tests in skip- blocks to avoid the error "Bad plan. You planned 50 tests but ran 55" when run with/without /usr/bin/faketime and NP_INTERNET_ACCESS=yes/no. diff --git a/plugins/t/check_curl.t b/plugins/t/check_curl.t index a4f1dfb..4f4124b 100644 --- a/plugins/t/check_curl.t +++ b/plugins/t/check_curl.t @@ -84,7 +84,7 @@ like( $res->output, '/^Host: testhost:8001\s*$/ms', "Host Header OK" ); like( $res->output, '/CURLOPT_URL: http:\/\/'.$host_tcp_http.':80\//ms', "Url OK" ); SKIP: { - skip "No internet access", 3 if $internet_access eq "no"; + skip "No internet access", 4 if $internet_access eq "no"; $res = NPTest->testCmd("./$plugin -v -H $host_tls_http -S"); like( $res->output, '/^Host: '.$host_tls_http.'\s*$/ms', "Host Header OK" ); @@ -120,7 +120,7 @@ SKIP: { cmp_ok( $res->return_code, "==", 0, "And also when not found"); } SKIP: { - skip "No internet access", 16 if $internet_access eq "no"; + skip "No internet access", 28 if $internet_access eq "no"; $res = NPTest->testCmd( "./$plugin --ssl $host_tls_http" diff --git a/plugins/t/check_http.t b/plugins/t/check_http.t index e92681e..c137f7b 100644 --- a/plugins/t/check_http.t +++ b/plugins/t/check_http.t @@ -103,7 +103,7 @@ SKIP: { cmp_ok( $res->return_code, "==", 0, "And also when not found"); } SKIP: { - skip "No internet access", 16 if $internet_access eq "no"; + skip "No internet access", 23 if $internet_access eq "no"; $res = NPTest->testCmd( "./$plugin --ssl $host_tls_http" @@ -135,7 +135,7 @@ SKIP: { # run some certificate checks with faketime SKIP: { - skip "No faketime binary found", 12 if !$faketime; + skip "No faketime binary found", 7 if !$faketime; $res = NPTest->testCmd("LC_TIME=C TZ=UTC ./$plugin -C 1 $host_tls_http"); like($res->output, qr/OK - Certificate '$host_tls_cert' will expire on/, "Catch cert output"); is( $res->return_code, 0, "Catch cert output exit code" ); -- cgit v0.10-9-g596f From e712d5a6ef194845e815f0471589262bcb1cced4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aksel=20Sj=C3=B6gren?= Date: Thu, 29 Apr 2021 15:04:19 +0200 Subject: Add test-debug for plugins-root Fixes "No rule to make target 'test-debug'" when running "make test-debug" in root dir. diff --git a/plugins-root/Makefile.am b/plugins-root/Makefile.am index a1ebb6d..7cd2675 100644 --- a/plugins-root/Makefile.am +++ b/plugins-root/Makefile.am @@ -37,6 +37,9 @@ TESTS = @PLUGIN_TEST@ test: perl -I $(top_builddir) -I $(top_srcdir) ../test.pl +test-debug: + NPTEST_DEBUG=1 HARNESS_VERBOSE=1 perl -I $(top_builddir) -I $(top_srcdir) ../test.pl + setuid_root_mode = ug=rx,u+s # /* Author Coreutils team - see ACKNOWLEDGEMENTS */ -- cgit v0.10-9-g596f From 39c162e594ec962eb338332624d3ac7474227a2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aksel=20Sj=C3=B6gren?= Date: Thu, 29 Apr 2021 15:58:50 +0200 Subject: Fix check_dhcp tests * try to use "/usr/sbin/ip" before "ifconfig" since the latter is obsolete on Linux to figure out interface to listen for DHCP messages. But keeping ifconfig method just in case. Without this, tests fail on boxes without ifconfig AND the correct interface named ethX. * amend possible failure responses, as check_dhcp might get a DHCPOFFER, but from an unexpected address - which happens if the box running tests are on a network with a DHCP server. diff --git a/plugins-root/t/check_dhcp.t b/plugins-root/t/check_dhcp.t index 222f454..ce62773 100644 --- a/plugins-root/t/check_dhcp.t +++ b/plugins-root/t/check_dhcp.t @@ -19,7 +19,7 @@ if ($allow_sudo eq "yes" or $> == 0) { my $sudo = $> == 0 ? '' : 'sudo'; my $successOutput = '/OK: Received \d+ DHCPOFFER\(s\), \d+ of 1 requested servers responded, max lease time = \d+ sec\./'; -my $failureOutput = '/CRITICAL: No DHCPOFFERs were received/'; +my $failureOutput = '/CRITICAL: (No DHCPOFFERs were received|Received \d+ DHCPOFFER\(s\), 0 of 1 requested servers responded, max lease time = \d+ sec\.)/'; my $invalidOutput = '/Invalid hostname/'; my $host_responsive = getTestParameter( "NP_HOST_DHCP_RESPONSIVE", @@ -36,7 +36,12 @@ my $hostname_invalid = getTestParameter( "NP_HOSTNAME_INVALID", # try to determince interface my $interface = ''; -if(`ifconfig -a 2>/dev/null` =~ m/^(e\w*\d+)/mx and $1 ne 'eth0') { + +# find interface used for default route +if (-x '/usr/sbin/ip' and `/usr/sbin/ip route get 1.1.1.1 2>/dev/null` =~ m/\sdev\s(\S+)/) { + $interface = "-i $1"; +} +elsif (`ifconfig -a 2>/dev/null` =~ m/^(e\w*\d+)/mx and $1 ne 'eth0') { $interface = ' -i '.$1; } -- cgit v0.10-9-g596f From de9f85c916db4515bd81f2a000d7fb57f8e0f46a Mon Sep 17 00:00:00 2001 From: Jacob Hansen Date: Fri, 30 Apr 2021 12:33:52 +0200 Subject: Use openssl generated cert The SSL certificate generate using make-ssl-cert seems to not work well with a our plugins. Causing a "CN could not be found" error to be shown. Using an OpenSSL generated certifiticate, seems to work better. Signed-off-by: Jacob Hansen diff --git a/.github/prepare_debian.sh b/.github/prepare_debian.sh index 3693acc..a74f346 100755 --- a/.github/prepare_debian.sh +++ b/.github/prepare_debian.sh @@ -41,8 +41,12 @@ cat /etc/hosts # apache a2enmod ssl a2ensite default-ssl -make-ssl-cert generate-default-snakeoil --force-overwrite -service apache2 start +# replace snakeoil certs with openssl generated ones as the make-ssl-cert ones +# seems to cause problems with our plugins +rm /etc/ssl/certs/ssl-cert-snakeoil.pem +rm /etc/ssl/private/ssl-cert-snakeoil.key +openssl req -nodes -newkey rsa:2048 -x509 -sha256 -days 365 -nodes -keyout /etc/ssl/private/ssl-cert-snakeoil.key -out /etc/ssl/certs/ssl-cert-snakeoil.pem -subj "/C=GB/ST=London/L=London/O=Global Security/OU=IT Department/CN=$(hostname)" +service apache2 restart # squid cp tools/squid.conf /etc/squid/squid.conf -- cgit v0.10-9-g596f From ae2fe683e3a5e2254473777b0249efe66f24d26c Mon Sep 17 00:00:00 2001 From: Jacob Hansen Date: Tue, 18 May 2021 15:19:43 +0200 Subject: check_curl.t: Adjust test to use -f curl It appears that `-f follow` doesn't work correctly in `check_curl` at the moment. Test adjusted to use `-f curl` instead. Issue for the above created: https://github.com/monitoring-plugins/monitoring-plugins/issues/1685 Signed-off-by: Jacob Hansen diff --git a/plugins/t/check_curl.t b/plugins/t/check_curl.t index 4f4124b..45ee533 100644 --- a/plugins/t/check_curl.t +++ b/plugins/t/check_curl.t @@ -193,8 +193,7 @@ SKIP: { ); cmp_ok( $res->return_code, "==", 0, "Can read https for www.e-paycobalt.com (uses AES certificate)" ); - - $res = NPTest->testCmd( "./$plugin -H www.mozilla.com -u /firefox -f follow" ); + $res = NPTest->testCmd( "./$plugin -H www.mozilla.com -u /firefox -f curl" ); is( $res->return_code, 0, "Redirection based on location is okay"); $res = NPTest->testCmd( "./$plugin -H www.mozilla.com --extended-perfdata" ); -- cgit v0.10-9-g596f From 227369bb3bec2a44ebece952a9085bfb032a7a0e Mon Sep 17 00:00:00 2001 From: Jacob Hansen Date: Wed, 19 May 2021 13:12:29 +0200 Subject: Disable IPv6 in tests Docker doesn't seem to have a working IPv6 stack by default. For now disable IPv6 tests. Signed-off-by: Jacob Hansen diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4c3497d..06cc441 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -71,7 +71,7 @@ jobs: ${{ matrix.distro }} \ /bin/sh -c '${{ matrix.prepare }} && \ tools/setup && \ - ./configure --enable-libtap && \ + ./configure --enable-libtap --with-ipv6=no && \ make && \ make test' docker volume rm tmp-vol -- cgit v0.10-9-g596f From 0bbcb60f02d6f78561f684adb0294870a3522e4f Mon Sep 17 00:00:00 2001 From: Jacob Hansen Date: Wed, 19 May 2021 13:13:47 +0200 Subject: Refactor check_fping * Set correct amount of tests based on conditionals. * When running the test as non-root, we would previously check is the setuid bit is set. This doesn't seem to be needed, so just check if the binary is executable for the user running the test. * Use cmp_ok to check if tests succeeds rather than couting. Signed-off-by: Jacob Hansen diff --git a/plugins/t/check_fping.t b/plugins/t/check_fping.t index 03a6110..67b357b 100644 --- a/plugins/t/check_fping.t +++ b/plugins/t/check_fping.t @@ -5,31 +5,30 @@ # use strict; -use Test; +use Test::More; use NPTest; -use vars qw($tests); - -BEGIN {$tests = 4; plan tests => $tests} - my $host_responsive = getTestParameter("NP_HOST_RESPONSIVE", "The hostname of system responsive to network requests", "localhost"); my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", "The hostname of system not responsive to network requests", "10.0.0.1"); my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", "An invalid (not known to DNS) hostname", "nosuchhost"); -my $t; +my $res; my $fping = qx(which fping 2> /dev/null); chomp($fping); if( ! -x "./check_fping") { - $t += skipMissingCmd( "./check_fping", $tests ); + plan skip_all => "check_fping not found, skipping tests"; } -elsif ( $> != 0 && (!$fping || ! -u $fping)) { - $t += skipMsg( "./check_fping", $tests ); +elsif ( !$fping || !-x $fping ) { + plan skip_all => "fping not found or cannot be executed, skipping tests"; } else { - $t += checkCmd( "./check_fping $host_responsive", 0, '/^FPING OK - /' ); - $t += checkCmd( "./check_fping $host_nonresponsive", 2, '/^FPING CRITICAL - /' ); - $t += checkCmd( "./check_fping $hostname_invalid", 3, '/^FPING UNKNOWN - /' ); -} + plan tests => 3; + $res = NPTest->testCmd( "./check_fping $host_responsive" ); + cmp_ok( $res->return_code, '==', 0, "Responsive host returns OK"); -exit(0) if defined($Test::Harness::VERSION); -exit($tests - $t); + $res = NPTest->testCmd( "./check_fping $host_nonresponsive" ); + cmp_ok( $res->return_code, '==', 2, "Non-Responsive host returns Critical"); + + $res = NPTest->testCmd( "./check_fping $hostname_invalid" ); + cmp_ok( $res->return_code, '==', 3, "Invalid host returns Unknown"); +} -- cgit v0.10-9-g596f From 226469f970568340d27d90499199823b67b9e3dc Mon Sep 17 00:00:00 2001 From: Jacob Hansen Date: Wed, 19 May 2021 13:59:52 +0200 Subject: Prune container and volumes Rather than manully removing the tmpfs volume. Signed-off-by: Jacob Hansen diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 06cc441..3e46795 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -74,4 +74,5 @@ jobs: ./configure --enable-libtap --with-ipv6=no && \ make && \ make test' - docker volume rm tmp-vol + docker container prune -f + docker volume prune -f -- cgit v0.10-9-g596f From 6344d29143bfd80d511e6c2d4bd39b9f58e03f14 Mon Sep 17 00:00:00 2001 From: Sven Nierlein Date: Thu, 20 May 2021 17:49:46 +0200 Subject: remove useless comments Signed-off-by: Sven Nierlein diff --git a/.github/prepare_debian.sh b/.github/prepare_debian.sh index a74f346..c68b9f5 100755 --- a/.github/prepare_debian.sh +++ b/.github/prepare_debian.sh @@ -69,12 +69,8 @@ ssh-keyscan localhost >> ~/.ssh/known_hosts touch ~/.ssh/config # start one login session, required for check_users -#( ssh -n -tt root@localhost "top" < /dev/null >/dev/null 2>&1 & ) ssh -tt localhost /dev/null 2>/dev/null & disown %1 -#sleep 1 -#who -#ssh root@localhost "top -b -n 1" # snmpd for DIR in /usr/share/snmp/mibs /usr/share/mibs; do diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3e46795..512d28e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,29 +8,7 @@ on: jobs: # macos: -# name: Running tests on ${{ matrix.os }} -# strategy: -# fail-fast: false -# matrix: -# os: -# - macos-10.15 -# runs-on: ${{ matrix.os }} -# steps: -# -# - name: Git clone repository -# uses: actions/checkout@v2 -# #- name: Setup tmate session, see https://github.com/marketplace/actions/debugging-with-tmate -# # uses: mxschmitt/action-tmate@v3 -# - name: Prepare machine -# run: | -# brew install automake -# - name: Run the tests -# run: | -# tools/setup \ -# && ./configure --enable-libtap \ -# && make \ -# && make test - +# ... linux: runs-on: ubuntu-latest name: Running tests on ${{ matrix.distro }} @@ -38,22 +16,12 @@ jobs: fail-fast: false matrix: distro: - #- 'debian:10' - 'debian:testing' - #- 'ubuntu:20.10' - #- 'centos:7' - #- 'centos:8' + #... include: - #- distro: 'debian:10' - # prepare: .github/prepare_debian.sh - distro: 'debian:testing' prepare: .github/prepare_debian.sh - #- distro: 'ubuntu:20.10' - # prepare: .github/prepare_debian.sh - #- distro: 'centos:7' - # prepare: .github/prepare_centos.sh - #- distro: 'centos:8' - # prepare: .github/prepare_centos.sh + #... steps: - name: Git clone repository uses: actions/checkout@v2 -- cgit v0.10-9-g596f From eb75d847ae31a86768b06926bc2323f7c16f07b9 Mon Sep 17 00:00:00 2001 From: Sven Nierlein Date: Thu, 20 May 2021 18:04:49 +0200 Subject: tests: increase startup sleep github action might fail from to time otherwise diff --git a/plugins/tests/check_curl.t b/plugins/tests/check_curl.t index 0caad23..29cb03f 100755 --- a/plugins/tests/check_curl.t +++ b/plugins/tests/check_curl.t @@ -126,8 +126,6 @@ if ($pid) { exit; } } - # give our webservers some time to startup - sleep(1); } else { # Child #print "child\n"; @@ -140,6 +138,9 @@ if ($pid) { exit; } +# give our webservers some time to startup +sleep(3); + # Run the same server on http and https sub run_server { my $d = shift; diff --git a/plugins/tests/check_http.t b/plugins/tests/check_http.t index 2f051fa..0f56950 100755 --- a/plugins/tests/check_http.t +++ b/plugins/tests/check_http.t @@ -102,8 +102,6 @@ if ($pid) { exit; } } - # give our webservers some time to startup - sleep(1); } else { # Child #print "child\n"; @@ -116,6 +114,9 @@ if ($pid) { exit; } +# give our webservers some time to startup +sleep(3); + # Run the same server on http and https sub run_server { my $d = shift; -- cgit v0.10-9-g596f From b428cc17f75682465e6f1e59b32fdec02b87ceac Mon Sep 17 00:00:00 2001 From: Sven Nierlein Date: Thu, 20 May 2021 20:57:59 +0200 Subject: tests: ignore sigpipes in https test daemon check_http closes the connection after checking the certificate with -C. This leads to sigpipe errors when the ssl daemon wants to send a response and the daemon quits which makes the subsequent tests fail. diff --git a/plugins/tests/check_http.t b/plugins/tests/check_http.t index 0f56950..188f5e7 100755 --- a/plugins/tests/check_http.t +++ b/plugins/tests/check_http.t @@ -91,6 +91,8 @@ if ($pid) { exit; } } else { + # closing the connection after -C cert checks make the daemon exit with a sigpipe otherwise + local $SIG{'PIPE'} = 'IGNORE'; my $d = HTTP::Daemon::SSL->new( LocalPort => $port_https, LocalAddr => "127.0.0.1", @@ -415,22 +417,24 @@ sub run_common_tests { # stickyport - on full urlS port is set back to 80 otherwise $cmd = "$command -f stickyport -u /redir_external -t 5 -s redirected"; + alarm(2); eval { local $SIG{ALRM} = sub { die "alarm\n" }; - alarm(2); $result = NPTest->testCmd( $cmd ); - alarm(0); }; + }; isnt( $@, "alarm\n", $cmd ); + alarm(0); is( $result->return_code, 0, $cmd ); # Let's hope there won't be any web server on :80 returning "redirected"! $cmd = "$command -f sticky -u /redir_external -t 5 -s redirected"; + alarm(2); eval { local $SIG{ALRM} = sub { die "alarm\n" }; - alarm(2); $result = NPTest->testCmd( $cmd ); - alarm(0); }; + }; isnt( $@, "alarm\n", $cmd ); + alarm(0); isnt( $result->return_code, 0, $cmd ); # Test an external address - timeout -- cgit v0.10-9-g596f From 63cb7ecfcf8d5b6c9f2be704eee7fa7cd9216f88 Mon Sep 17 00:00:00 2001 From: Barak Shohat Date: Mon, 24 May 2021 13:42:43 +0300 Subject: check_curl.c: bugfix: verify certificates option should not force SSL to be used diff --git a/plugins/check_curl.c b/plugins/check_curl.c index 3e0a6f9..d29db0a 100644 --- a/plugins/check_curl.c +++ b/plugins/check_curl.c @@ -1346,7 +1346,7 @@ process_arguments (int argc, char **argv) #ifdef LIBCURL_FEATURE_SSL case 'D': /* verify peer certificate & host */ verify_peer_and_host = TRUE; - goto enable_ssl; + break; #endif case 'S': /* use SSL */ #ifdef LIBCURL_FEATURE_SSL diff --git a/plugins/t/check_curl.t b/plugins/t/check_curl.t index 45ee533..ada6a04 100644 --- a/plugins/t/check_curl.t +++ b/plugins/t/check_curl.t @@ -95,7 +95,7 @@ SKIP: { $res = NPTest->testCmd("./$plugin -v -H $host_tls_http:443 -S -p 443"); like( $res->output, '/^Host: '.$host_tls_http.'\s*$/ms', "Host Header OK" ); - $res = NPTest->testCmd("./$plugin -v -H $host_tls_http -D -p 443"); + $res = NPTest->testCmd("./$plugin -v -H $host_tls_http -D -S -p 443"); like( $res->output, '/(^Host: '.$host_tls_http.'\s*$)|(cURL returned 60)/ms', "Host Header OK" ); }; -- cgit v0.10-9-g596f From beb609ffcf8c24c133f59829e0d3d82102661b82 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Thu, 27 May 2021 15:32:08 +0200 Subject: check_curl: - added verbose output in verify_callback - pin refcounting for certs (avoid subject extraction error when checking certs in is_openssl_callback mode) diff --git a/plugins/check_curl.c b/plugins/check_curl.c index 3e0a6f9..59e398b 100644 --- a/plugins/check_curl.c +++ b/plugins/check_curl.c @@ -285,6 +285,18 @@ int verify_callback(int preverify_ok, X509_STORE_CTX *x509_ctx) * TODO: is the last certificate always the server certificate? */ cert = X509_STORE_CTX_get_current_cert(x509_ctx); + X509_up_ref(cert); + if (verbose>=2) { + puts("* SSL verify callback with certificate:"); + X509_NAME *subject, *issuer; + printf("* issuer:\n"); + issuer = X509_get_issuer_name( cert ); + X509_NAME_print_ex_fp(stdout, issuer, 5, XN_FLAG_MULTILINE); + printf("* curl verify_callback:\n* subject:\n"); + subject = X509_get_subject_name( cert ); + X509_NAME_print_ex_fp(stdout, subject, 5, XN_FLAG_MULTILINE); + puts(""); + } return 1; } -- cgit v0.10-9-g596f From 20e9451fadb452636bc4b395fcb6aaf93a477c23 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Thu, 24 Jun 2021 11:02:28 +0200 Subject: added option --enable-automatic-decompression diff --git a/plugins/check_curl.c b/plugins/check_curl.c index 59e398b..d4442f5 100644 --- a/plugins/check_curl.c +++ b/plugins/check_curl.c @@ -206,6 +206,7 @@ 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; int process_arguments (int, char**); void handle_curl_option_return_code (CURLcode res, const char* option); @@ -383,6 +384,13 @@ check_http (void) /* print everything on stdout like check_http would do */ handle_curl_option_return_code (curl_easy_setopt(curl, CURLOPT_STDERR, stdout), "CURLOPT_STDERR"); + if (automatic_decompression) +#if LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 21, 6) + handle_curl_option_return_code (curl_easy_setopt(curl, CURLOPT_ACCEPT_ENCODING, ""), "CURLOPT_ACCEPT_ENCODING"); +#else + handle_curl_option_return_code (curl_easy_setopt(curl, CURLOPT_ENCODING, ""), "CURLOPT_ENCODING"); +#endif /* LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 21, 6) */ + /* 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"); @@ -1149,7 +1157,8 @@ process_arguments (int argc, char **argv) INVERT_REGEX = CHAR_MAX + 1, SNI_OPTION, CA_CERT_OPTION, - HTTP_VERSION_OPTION + HTTP_VERSION_OPTION, + AUTOMATIC_DECOMPRESSION }; int option = 0; @@ -1192,6 +1201,7 @@ process_arguments (int argc, char **argv) {"extended-perfdata", no_argument, 0, 'E'}, {"show-body", no_argument, 0, 'B'}, {"http-version", required_argument, 0, HTTP_VERSION_OPTION}, + {"enable-automatic-decompression", no_argument, 0, AUTOMATIC_DECOMPRESSION}, {0, 0, 0, 0} }; @@ -1583,6 +1593,9 @@ process_arguments (int argc, char **argv) exit (STATE_WARNING); } break; + case AUTOMATIC_DECOMPRESSION: + automatic_decompression = TRUE; + break; case '?': /* print short usage statement if args not parsable */ usage5 (); @@ -1793,6 +1806,8 @@ print_help (void) printf (" %s\n", "--http-version=VERSION"); printf (" %s\n", _("Connect via specific HTTP protocol.")); 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 ("\n"); printf (UT_WARN_CRIT); -- cgit v0.10-9-g596f From a1af8be9781ccdf36087a9e42fa18cfd468f1401 Mon Sep 17 00:00:00 2001 From: Daniel Uhlmann Date: Thu, 24 Jun 2021 11:37:14 +0200 Subject: changed 'STATE_CRITICAL' to 'STATE_WARNING' for infinite loop diff --git a/plugins/check_http.c b/plugins/check_http.c index 0b71266..34fb4f0 100644 --- a/plugins/check_http.c +++ b/plugins/check_http.c @@ -1453,8 +1453,8 @@ redir (char *pos, char *status_line) !strncmp(server_address, addr, MAX_IPV4_HOSTLENGTH) && (host_name && !strncmp(host_name, addr, MAX_IPV4_HOSTLENGTH)) && !strcmp(server_url, url)) - die (STATE_WARNING, - _("HTTP WARNING - redirection creates an infinite loop - %s://%s:%d%s%s\n"), + die (STATE_CRITICAL, + _("HTTP CRITICAL - redirection creates an infinite loop - %s://%s:%d%s%s\n"), type, addr, i, url, (display_html ? "" : "")); strcpy (server_type, type); -- cgit v0.10-9-g596f From 0b6838ffcaf372df419059771dd42f1bd69644c0 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Thu, 24 Jun 2021 17:08:20 +0000 Subject: fix for missing X509_up_ref on old systems with only OpenSSL 1.0 diff --git a/plugins/check_curl.c b/plugins/check_curl.c index d4442f5..daf64b0 100644 --- a/plugins/check_curl.c +++ b/plugins/check_curl.c @@ -55,6 +55,10 @@ const char *email = "devel@monitoring-plugins.org"; #include +#if defined(HAVE_SSL) && defined(USE_OPENSSL) +#include +#endif + #define MAKE_LIBCURL_VERSION(major, minor, patch) ((major)*0x10000 + (minor)*0x100 + (patch)) #define DEFAULT_BUFFER_SIZE 2048 @@ -286,7 +290,9 @@ int verify_callback(int preverify_ok, X509_STORE_CTX *x509_ctx) * TODO: is the last certificate always the server certificate? */ cert = X509_STORE_CTX_get_current_cert(x509_ctx); +#if OPENSSL_VERSION_NUMBER >= 0x10100000L X509_up_ref(cert); +#endif if (verbose>=2) { puts("* SSL verify callback with certificate:"); X509_NAME *subject, *issuer; -- cgit v0.10-9-g596f From 6e5ee70d07c0a8515acdc3ad52716285a4b7f77b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20K=C3=A4stle?= Date: Fri, 25 Jun 2021 12:12:48 +0200 Subject: Let ssh decide if a host is valid, enables usage of ssh .config file diff --git a/plugins/check_by_ssh.c b/plugins/check_by_ssh.c index 13d8bc3..485bf3b 100644 --- a/plugins/check_by_ssh.c +++ b/plugins/check_by_ssh.c @@ -230,7 +230,6 @@ process_arguments (int argc, char **argv) timeout_interval = atoi (optarg); break; case 'H': /* host */ - host_or_die(optarg); hostname = optarg; break; case 'p': /* port number */ @@ -329,7 +328,6 @@ process_arguments (int argc, char **argv) if (c <= argc) { die (STATE_UNKNOWN, _("%s: You must provide a host name\n"), progname); } - host_or_die(argv[c]); hostname = argv[c++]; } -- cgit v0.10-9-g596f From 3abcf83af41af9e56382b8e93a48d8d3ce1f18e8 Mon Sep 17 00:00:00 2001 From: rincewind Date: Fri, 2 Jul 2021 10:37:35 +0200 Subject: Remove modified note, since this is a git repository diff --git a/plugins-scripts/check_log.sh b/plugins-scripts/check_log.sh index d28c8d0..4330235 100755 --- a/plugins-scripts/check_log.sh +++ b/plugins-scripts/check_log.sh @@ -1,8 +1,7 @@ #!/bin/sh # # Log file pattern detector plugin for monitoring -# Written by Ethan Galstad (nagios@nagios.org) -# Last Modified: 07-31-1999 +# Written originally by Ethan Galstad (nagios@nagios.org) # # Usage: ./check_log # -- cgit v0.10-9-g596f From 14e1d7f6af409c28dab4732357a2b355a1ada85a Mon Sep 17 00:00:00 2001 From: rincewind Date: Fri, 2 Jul 2021 17:39:47 +0200 Subject: Apply shellcheck diff --git a/plugins-scripts/check_log.sh b/plugins-scripts/check_log.sh index 4330235..8a79704 100755 --- a/plugins-scripts/check_log.sh +++ b/plugins-scripts/check_log.sh @@ -59,11 +59,11 @@ PATH="@TRUSTED_PATH@" export PATH -PROGNAME=`basename $0` -PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'` +PROGNAME=$(basename "$0") +PROGPATH=$(echo "$0" | sed -e 's,[\\/][^\\/][^\\/]*$,,') REVISION="@NP_VERSION@" -. $PROGPATH/utils.sh +. "$PROGPATH"/utils.sh print_usage() { echo "Usage: $PROGNAME -F logfile -O oldlog -q query" @@ -72,7 +72,7 @@ print_usage() { } print_help() { - print_revision $PROGNAME $REVISION + print_revision "$PROGNAME" $REVISION echo "" print_usage echo "" @@ -86,7 +86,7 @@ print_help() { if [ $# -lt 1 ]; then print_usage - exit $STATE_UNKNOWN + exit "$STATE_UNKNOWN" fi # Grab the command line arguments @@ -99,19 +99,19 @@ while test -n "$1"; do case "$1" in --help) print_help - exit $STATE_OK + exit "$STATE_OK" ;; -h) print_help - exit $STATE_OK + exit "$STATE_OK" ;; --version) - print_revision $PROGNAME $REVISION - exit $STATE_OK + print_revision "$PROGNAME" $REVISION + exit "$STATE_OK" ;; -V) - print_revision $PROGNAME $REVISION - exit $STATE_OK + print_revision "$PROGNAME" $REVISION + exit "$STATE_OK" ;; --filename) logfile=$2 @@ -148,7 +148,7 @@ while test -n "$1"; do *) echo "Unknown argument: $1" print_usage - exit $STATE_UNKNOWN + exit "$STATE_UNKNOWN" ;; esac shift @@ -156,22 +156,22 @@ done # If the source log file doesn't exist, exit -if [ ! -e $logfile ]; then +if [ ! -e "$logfile" ]; then echo "Log check error: Log file $logfile does not exist!" - exit $STATE_UNKNOWN -elif [ ! -r $logfile ] ; then + exit "$STATE_UNKNOWN" +elif [ ! -r "$logfile" ] ; then echo "Log check error: Log file $logfile is not readable!" - exit $STATE_UNKNOWN + exit "$STATE_UNKNOWN" fi # If the old log file doesn't exist, this must be the first time # we're running this test, so copy the original log file over to # the old diff file and exit -if [ ! -e $oldlog ]; then - cat $logfile > $oldlog +if [ ! -e "$oldlog" ]; then + cat "$logfile" > "$oldlog" echo "Log check data initialized..." - exit $STATE_OK + exit "$STATE_OK" fi # The old log file exists, so compare it to the original log now @@ -179,24 +179,24 @@ fi # The temporary file that the script should use while # processing the log file. if [ -x /bin/mktemp ]; then - tempdiff=`/bin/mktemp /tmp/check_log.XXXXXXXXXX` + tempdiff=$(/bin/mktemp /tmp/check_log.XXXXXXXXXX) else - tempdiff=`/bin/date '+%H%M%S'` + tempdiff=$(/bin/date '+%H%M%S') tempdiff="/tmp/check_log.${tempdiff}" - touch $tempdiff - chmod 600 $tempdiff + touch "$tempdiff" + chmod 600 "$tempdiff" fi -diff $logfile $oldlog | grep -v "^>" > $tempdiff +diff "$logfile" "$oldlog" | grep -v "^>" > "$tempdiff" # Count the number of matching log entries we have -count=`grep -c "$query" $tempdiff` +count=$(grep -c "$query" "$tempdiff") # Get the last matching entry in the diff file -lastentry=`grep "$query" $tempdiff | tail -1` +lastentry=$(grep "$query" "$tempdiff" | tail -1) -rm -f $tempdiff -cat $logfile > $oldlog +rm -f "$tempdiff" +cat "$logfile" > "$oldlog" if [ "$count" = "0" ]; then # no matches, exit with no error echo "Log check ok - 0 pattern matches found" @@ -206,4 +206,4 @@ else # Print total matche count and the last entry we found exitstatus=$STATE_CRITICAL fi -exit $exitstatus +exit "$exitstatus" -- cgit v0.10-9-g596f From c2aa1a5fa2dd96c7186704901d33721a63b9cd03 Mon Sep 17 00:00:00 2001 From: rincewind Date: Fri, 2 Jul 2021 18:01:47 +0200 Subject: Add extended and perl regex diff --git a/plugins-scripts/check_log.sh b/plugins-scripts/check_log.sh index 8a79704..6e9fbca 100755 --- a/plugins-scripts/check_log.sh +++ b/plugins-scripts/check_log.sh @@ -145,6 +145,22 @@ while test -n "$1"; do exitstatus=$2 shift ;; + --extended-regex) + ERE=1 + shift + ;; + -e) + ERE=1 + shift + ;; + --perl-regex) + PRE=1 + shift + ;; + -p) + PRE=1 + shift + ;; *) echo "Unknown argument: $1" print_usage @@ -154,6 +170,20 @@ while test -n "$1"; do shift done +# Parameter sanity check +if [ $ERE ] && [ $PRE ] ; then + echo "Can not use extended and perl regex at the same time" + exit "$STATE_UNKNOWN" +fi + +if [ $ERE ]; then + GREP="grep -E" +fi + +if [ $PRE ]; then + GREP="grep -P" +fi + # If the source log file doesn't exist, exit if [ ! -e "$logfile" ]; then @@ -190,10 +220,10 @@ fi diff "$logfile" "$oldlog" | grep -v "^>" > "$tempdiff" # Count the number of matching log entries we have -count=$(grep -c "$query" "$tempdiff") +count=$($GREP -c "$query" "$tempdiff") # Get the last matching entry in the diff file -lastentry=$(grep "$query" "$tempdiff" | tail -1) +lastentry=$($GREP "$query" "$tempdiff" | tail -1) rm -f "$tempdiff" cat "$logfile" > "$oldlog" -- cgit v0.10-9-g596f From 53b77dee91f780b4d78839f881c642189b829e3c Mon Sep 17 00:00:00 2001 From: rincewind Date: Fri, 2 Jul 2021 18:38:12 +0200 Subject: Add -a option to print all matching lines and -p and -e options for perl and extended RE diff --git a/plugins-scripts/check_log.sh b/plugins-scripts/check_log.sh index 6e9fbca..8af07b5 100755 --- a/plugins-scripts/check_log.sh +++ b/plugins-scripts/check_log.sh @@ -69,6 +69,11 @@ print_usage() { echo "Usage: $PROGNAME -F logfile -O oldlog -q query" echo "Usage: $PROGNAME --help" echo "Usage: $PROGNAME --version" + echo "" + echo "Other parameters:" + echo " -a|--all : Print all matching lines" + 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)" } print_help() { @@ -115,35 +120,35 @@ while test -n "$1"; do ;; --filename) logfile=$2 - shift + shift 2 ;; -F) logfile=$2 - shift + shift 2 ;; --oldlog) oldlog=$2 - shift + shift 2 ;; -O) oldlog=$2 - shift + shift 2 ;; --query) query=$2 - shift + shift 2 ;; -q) query=$2 - shift + shift 2 ;; -x) exitstatus=$2 - shift + shift 2 ;; --exitstatus) exitstatus=$2 - shift + shift 2 ;; --extended-regex) ERE=1 @@ -161,13 +166,20 @@ while test -n "$1"; do PRE=1 shift ;; + --all) + ALL=1 + shift + ;; + -a) + ALL=1 + shift + ;; *) echo "Unknown argument: $1" print_usage exit "$STATE_UNKNOWN" ;; esac - shift done # Parameter sanity check @@ -176,6 +188,8 @@ if [ $ERE ] && [ $PRE ] ; then exit "$STATE_UNKNOWN" fi +GREP="grep" + if [ $ERE ]; then GREP="grep -E" fi @@ -219,11 +233,20 @@ fi diff "$logfile" "$oldlog" | grep -v "^>" > "$tempdiff" -# Count the number of matching log entries we have -count=$($GREP -c "$query" "$tempdiff") +if [ $ALL ]; then + # Get the last matching entry in the diff file + entry=$($GREP "$query" "$tempdiff") -# Get the last matching entry in the diff file -lastentry=$($GREP "$query" "$tempdiff" | tail -1) + # Count the number of matching log entries we have + count=$(echo "$entry" | wc -l) + +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) +fi rm -f "$tempdiff" cat "$logfile" > "$oldlog" @@ -232,7 +255,7 @@ if [ "$count" = "0" ]; then # no matches, exit with no error echo "Log check ok - 0 pattern matches found" exitstatus=$STATE_OK else # Print total matche count and the last entry we found - echo "($count) $lastentry" + echo "($count) $entry" exitstatus=$STATE_CRITICAL fi -- cgit v0.10-9-g596f From 6e696643a5701ddd18945593743286b35b5944cb Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Sun, 4 Jul 2021 18:43:42 +0200 Subject: check_curl: changed to STATE_CRITICAL for infinite loops (-ffollow) diff --git a/plugins/check_curl.c b/plugins/check_curl.c index daf64b0..ba08c36 100644 --- a/plugins/check_curl.c +++ b/plugins/check_curl.c @@ -1106,8 +1106,8 @@ redir (curlhelp_write_curlbuf* header_buf) !strncmp(server_address, new_host, MAX_IPV4_HOSTLENGTH) && (host_name && !strncmp(host_name, new_host, MAX_IPV4_HOSTLENGTH)) && !strcmp(server_url, new_url)) - die (STATE_WARNING, - _("HTTP WARNING - redirection creates an infinite loop - %s://%s:%d%s%s\n"), + die (STATE_CRITICAL, + _("HTTP CRITICAL - redirection creates an infinite loop - %s://%s:%d%s%s\n"), use_ssl ? "https" : "http", new_host, new_port, new_url, (display_html ? "" : "")); /* set new values for redirected request */ -- cgit v0.10-9-g596f From 10db89344adc7dad1d1ec4ac00e4fadc6b79fa72 Mon Sep 17 00:00:00 2001 From: rincewind Date: Mon, 5 Jul 2021 09:56:19 +0200 Subject: Add quoting for the remaining variables diff --git a/plugins-scripts/check_log.sh b/plugins-scripts/check_log.sh index 8af07b5..382bd72 100755 --- a/plugins-scripts/check_log.sh +++ b/plugins-scripts/check_log.sh @@ -77,7 +77,7 @@ print_usage() { } print_help() { - print_revision "$PROGNAME" $REVISION + print_revision "$PROGNAME" "$REVISION" echo "" print_usage echo "" @@ -111,11 +111,11 @@ while test -n "$1"; do exit "$STATE_OK" ;; --version) - print_revision "$PROGNAME" $REVISION + print_revision "$PROGNAME" "$REVISION" exit "$STATE_OK" ;; -V) - print_revision "$PROGNAME" $REVISION + print_revision "$PROGNAME" "$REVISION" exit "$STATE_OK" ;; --filename) -- cgit v0.10-9-g596f From 1fb635d8691180b312537a4540feb6f947986e86 Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Thu, 22 Jul 2021 13:33:14 +0100 Subject: Re-attach a comment to where it actually belongs diff --git a/plugins-scripts/check_ifoperstatus.pl b/plugins-scripts/check_ifoperstatus.pl index 9ede163..c190ce9 100755 --- a/plugins-scripts/check_ifoperstatus.pl +++ b/plugins-scripts/check_ifoperstatus.pl @@ -124,10 +124,10 @@ if (!defined($session)) { ## map ifdescr to ifindex - should look at being able to cache this value if (defined $ifdescr || defined $iftype) { - # escape "/" in ifdescr - very common in the Cisco world if (defined $iftype) { $status=fetch_ifindex($snmpIfType, $iftype); } else { + # escape "/" in ifdescr - very common in the Cisco world $ifdescr =~ s/\//\\\//g; $status=fetch_ifindex($snmpIfDescr, $ifdescr); # if using on device with large number of interfaces # recommend use of SNMP v2 (get-bulk) -- cgit v0.10-9-g596f From 3f5c54c7830b0529030bb08e2c333497e70b6eb1 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Sun, 25 Jul 2021 18:39:07 +0200 Subject: check_curl: fixed DNS caching for SSL hostnames (avoid CURLOPT_RESOLVE entry errors) diff --git a/plugins/check_curl.c b/plugins/check_curl.c index ba08c36..2c91a27 100644 --- a/plugins/check_curl.c +++ b/plugins/check_curl.c @@ -59,6 +59,8 @@ const char *email = "devel@monitoring-plugins.org"; #include #endif +#include + #define MAKE_LIBCURL_VERSION(major, minor, patch) ((major)*0x10000 + (minor)*0x100 + (patch)) #define DEFAULT_BUFFER_SIZE 2048 @@ -370,12 +372,55 @@ handle_curl_option_return_code (CURLcode res, const char* option) } int +lookup_host (const char *host, char *buf, size_t buflen) +{ + struct addrinfo hints, *res, *result; + int errcode; + void *ptr; + + memset (&hints, 0, sizeof (hints)); + hints.ai_family = address_family; + hints.ai_socktype = SOCK_STREAM; + hints.ai_flags |= AI_CANONNAME; + + errcode = getaddrinfo (host, NULL, &hints, &result); + if (errcode != 0) + return errcode; + + 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; + } + 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); + res = res->ai_next; + } + + freeaddrinfo(result); + + return 0; +} + +int check_http (void) { int result = STATE_OK; int page_len = 0; int i; char *force_host_header = NULL; + struct curl_slist *host = NULL; + char addrstr[100]; + char dnscache[DEFAULT_BUFFER_SIZE]; /* initialize curl */ if (curl_global_init (CURL_GLOBAL_DEFAULT) != CURLE_OK) @@ -418,9 +463,12 @@ 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) { - struct curl_slist *host = NULL; - char dnscache[DEFAULT_BUFFER_SIZE]; - snprintf (dnscache, DEFAULT_BUFFER_SIZE, "%s:%d:%s", host_name, server_port, server_address); + if ( (res=lookup_host (server_address, addrstr, 100)) != 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); + } + snprintf (dnscache, DEFAULT_BUFFER_SIZE, "%s:%d:%s", host_name, server_port, addrstr); host = curl_slist_append(NULL, dnscache); curl_easy_setopt(curl, CURLOPT_RESOLVE, host); if (verbose>=1) -- cgit v0.10-9-g596f From de5503063e4ea455a7a0a57afcc467a2041c859f Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Sun, 25 Jul 2021 18:49:06 +0200 Subject: check_curl: fixed a potential buffer overflow in retir/uri_string diff --git a/plugins/check_curl.c b/plugins/check_curl.c index 2c91a27..5990b95 100644 --- a/plugins/check_curl.c +++ b/plugins/check_curl.c @@ -1033,8 +1033,8 @@ char* uri_string (const UriTextRangeA range, char* buf, size_t buflen) { if (!range.first) return "(null)"; - strncpy (buf, range.first, max (buflen, range.afterLast - range.first)); - buf[max (buflen, range.afterLast - range.first)] = '\0'; + strncpy (buf, range.first, max (buflen-1, range.afterLast - range.first)); + buf[max (buflen-1, range.afterLast - range.first)] = '\0'; buf[range.afterLast - range.first] = '\0'; return buf; } -- cgit v0.10-9-g596f From f29ba217d7521efda868551eab2866067615e49a Mon Sep 17 00:00:00 2001 From: rincewind Date: Wed, 1 Sep 2021 10:48:32 +0200 Subject: Use netcat-openbsd for debian explicitely diff --git a/.github/prepare_debian.sh b/.github/prepare_debian.sh index c68b9f5..4021c10 100755 --- a/.github/prepare_debian.sh +++ b/.github/prepare_debian.sh @@ -13,7 +13,7 @@ if [ $(lsb_release -is) = "Debian" ]; then fi apt-get -y install perl autotools-dev libdbi-dev libldap2-dev libpq-dev libradcli-dev libnet-snmp-perl procps apt-get -y install libdbi0-dev libdbd-sqlite3 libssl-dev dnsutils snmp-mibs-downloader libsnmp-perl snmpd -apt-get -y install fping snmp netcat smbclient vsftpd apache2 ssl-cert postfix libhttp-daemon-ssl-perl +apt-get -y install fping snmp netcat-openbsd smbclient vsftpd apache2 ssl-cert postfix libhttp-daemon-ssl-perl apt-get -y install libdbd-sybase-perl libnet-dns-perl apt-get -y install slapd ldap-utils apt-get -y install gcc make autoconf automake gettext -- cgit v0.10-9-g596f From 70f55ca9db87f639856e0548a57081c886e09d14 Mon Sep 17 00:00:00 2001 From: Jonny007-MKD Date: Sun, 23 Feb 2020 15:02:43 +0100 Subject: check_dns: add --expect-nxdomain diff --git a/NEWS b/NEWS index 4061c03..3790e8a 100644 --- a/NEWS +++ b/NEWS @@ -13,6 +13,7 @@ This file documents the major additions and syntax changes between releases. check_dns: Accept CIDR check_dns: allow unsorted addresses check_dns: allow forcing complete match of all addresses + check_dns: option to expect NXDOMAIN check_apt: add --only-critical switch check_apt: add -l/--list option to print packages check_file_age: add range checking diff --git a/plugins/check_dns.c b/plugins/check_dns.c index 0f2e654..0c10f09 100644 --- a/plugins/check_dns.c +++ b/plugins/check_dns.c @@ -41,7 +41,7 @@ const char *email = "devel@monitoring-plugins.org"; int process_arguments (int, char **); int validate_arguments (void); -int error_scan (char *); +int error_scan (char *, int*); int ip_match_cidr(const char *, const char *); unsigned long ip2long(const char *); void print_help (void); @@ -54,6 +54,7 @@ char ptr_server[ADDRESS_LENGTH] = ""; int verbose = FALSE; char **expected_address = NULL; int expected_address_cnt = 0; +int expect_nxdomain = FALSE; int expect_authority = FALSE; int all_match = FALSE; @@ -87,6 +88,7 @@ main (int argc, char **argv) int parse_address = FALSE; /* This flag scans for Address: but only after Name: */ output chld_out, chld_err; size_t i; + int is_nxdomain = FALSE; setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); @@ -186,7 +188,7 @@ main (int argc, char **argv) } - result = error_scan (chld_out.line[i]); + result = error_scan (chld_out.line[i], &is_nxdomain); if (result != STATE_OK) { msg = strchr (chld_out.line[i], ':'); if(msg) msg++; @@ -199,8 +201,8 @@ main (int argc, char **argv) if (verbose) puts(chld_err.line[i]); - if (error_scan (chld_err.line[i]) != STATE_OK) { - result = max_state (result, error_scan (chld_err.line[i])); + if (error_scan (chld_err.line[i], &is_nxdomain) != STATE_OK) { + result = max_state (result, error_scan (chld_err.line[i], &is_nxdomain)); msg = strchr(input_buffer, ':'); if(msg) msg++; @@ -209,6 +211,10 @@ main (int argc, char **argv) } } + if (is_nxdomain && !expect_nxdomain) { + die (STATE_CRITICAL, _("Domain '%s' was not found by the server\n"), query_address); + } + if (addresses) { int i,slen; char *adrp; @@ -260,6 +266,16 @@ main (int argc, char **argv) } } + if (expect_nxdomain) { + if (!is_nxdomain) { + result = STATE_CRITICAL; + xasprintf(&msg, _("Domain '%s' was found by the server: '%s'\n"), query_address, address); + } else { + if (address == NULL) free(address); + address = "NXDOMAIN"; + } + } + /* check if authoritative */ if (result == STATE_OK && expect_authority && non_authoritative) { result = STATE_CRITICAL; @@ -339,9 +355,15 @@ ip2long(const char* src) { } int -error_scan (char *input_buffer) +error_scan (char *input_buffer, int* is_nxdomain) { + const int nxdomain = strstr (input_buffer, "Non-existent") || + strstr (input_buffer, "** server can't find") || + strstr (input_buffer, "** Can't find") || + strstr (input_buffer, "NXDOMAIN"); + if (nxdomain) *is_nxdomain = TRUE; + /* the DNS lookup timed out */ if (strstr (input_buffer, _("Note: nslookup is deprecated and may be removed from future releases.")) || strstr (input_buffer, _("Consider using the `dig' or `host' programs instead. Run nslookup with")) || @@ -360,7 +382,7 @@ error_scan (char *input_buffer) /* Connection was refused */ else if (strstr (input_buffer, "Connection refused") || - strstr (input_buffer, "Couldn't find server") || + strstr (input_buffer, "Couldn't find server") || strstr (input_buffer, "Refused") || (strstr (input_buffer, "** server can't find") && strstr (input_buffer, ": REFUSED"))) @@ -374,13 +396,6 @@ error_scan (char *input_buffer) else if (strstr (input_buffer, "No information")) die (STATE_CRITICAL, _("No information returned by DNS server at %s\n"), dns_server); - /* Host or domain name does not exist */ - else if (strstr (input_buffer, "Non-existent") || - strstr (input_buffer, "** server can't find") || - strstr (input_buffer, "** Can't find") || - strstr (input_buffer,"NXDOMAIN")) - die (STATE_CRITICAL, _("Domain %s was not found by the server\n"), query_address); - /* Network is unreachable */ else if (strstr (input_buffer, "Network is unreachable")) die (STATE_CRITICAL, _("Network is unreachable\n")); @@ -417,6 +432,7 @@ process_arguments (int argc, char **argv) {"server", required_argument, 0, 's'}, {"reverse-server", required_argument, 0, 'r'}, {"expected-address", required_argument, 0, 'a'}, + {"expect-nxdomain", no_argument, 0, 'n'}, {"expect-authority", no_argument, 0, 'A'}, {"all", no_argument, 0, 'L'}, {"warning", required_argument, 0, 'w'}, @@ -432,7 +448,7 @@ process_arguments (int argc, char **argv) strcpy (argv[c], "-t"); while (1) { - c = getopt_long (argc, argv, "hVvALt:H:s:r:a:w:c:", long_opts, &opt_index); + c = getopt_long (argc, argv, "hVvALnt:H:s:r:a:w:c:", long_opts, &opt_index); if (c == -1 || c == EOF) break; @@ -491,6 +507,9 @@ process_arguments (int argc, char **argv) expected_address_cnt++; } break; + case 'n': /* expect NXDOMAIN */ + expect_nxdomain = TRUE; + break; case 'A': /* expect authority */ expect_authority = TRUE; break; @@ -532,8 +551,15 @@ process_arguments (int argc, char **argv) int validate_arguments () { - if (query_address[0] == 0) + if (query_address[0] == 0) { + printf ("missing --host argument\n"); + return ERROR; + } + + if (expected_address_cnt > 0 && expect_nxdomain) { + printf ("--expected-address and --expect-nxdomain cannot be combined\n"); return ERROR; + } return OK; } @@ -566,6 +592,9 @@ print_help (void) printf (" %s\n", _("Optional IP-ADDRESS/CIDR you expect the DNS server to return. HOST must end")); printf (" %s\n", _("with a dot (.). This option can be repeated multiple times (Returns OK if any")); printf (" %s\n", _("value matches).")); + printf (" -n, --expect-nxdomain\n"); + printf (" %s\n", _("Expect the DNS server to return NXDOMAIN (i.e. the domain was not found)")); + printf (" %s\n", _("Cannot be used together with -a")); printf (" -A, --expect-authority\n"); printf (" %s\n", _("Optionally expect the DNS server to be authoritative for the lookup")); printf (" -w, --warning=seconds\n"); @@ -586,5 +615,5 @@ void print_usage (void) { printf ("%s\n", _("Usage:")); - printf ("%s -H host [-s server] [-a expected-address] [-A] [-t timeout] [-w warn] [-c crit] [-L]\n", progname); + printf ("%s -H host [-s server] [-a expected-address] [-n] [-A] [-t timeout] [-w warn] [-c crit] [-L]\n", progname); } diff --git a/plugins/t/check_dns.t b/plugins/t/check_dns.t index cdfbe60..1e7d534 100644 --- a/plugins/t/check_dns.t +++ b/plugins/t/check_dns.t @@ -10,7 +10,7 @@ use NPTest; plan skip_all => "check_dns not compiled" unless (-x "check_dns"); -plan tests => 19; +plan tests => 23; my $successOutput = '/DNS OK: [\.0-9]+ seconds? response time/'; @@ -58,7 +58,7 @@ my $dns_server = getTestParameter( my $host_nonresponsive = getTestParameter( "NP_HOST_NONRESPONSIVE", "The hostname of system not responsive to network requests", - "10.0.0.1", + "192.0.2.0", ); my $res; @@ -105,3 +105,11 @@ cmp_ok( $res->return_code, '==', 0, "Got expected address"); $res = NPTest->testCmd("./check_dns -H $hostname_valid -a $hostname_invalid_cidr -t 5"); cmp_ok( $res->return_code, '==', 2, "Got wrong address"); like ( $res->output, "/^DNS CRITICAL.*expected '$hostname_invalid_cidr' but got '$hostname_valid_ip'".'$/', "Output OK"); + +$res = NPTest->testCmd("./check_dns -H $hostname_valid -n"); +cmp_ok( $res->return_code, '==', 2, "Found $hostname_valid"); +like ( $res->output, "/^DNS CRITICAL.*Domain '$hostname_valid' was found by the server:/", "Output OK"); + +$res = NPTest->testCmd("./check_dns -H $hostname_invalid -n"); +cmp_ok( $res->return_code, '==', 0, "Did not find $hostname_invalid"); +like ( $res->output, $successOutput, "Output OK" ); -- cgit v0.10-9-g596f From 2056c5853175e6ad0e041ff3776e10d9e612b521 Mon Sep 17 00:00:00 2001 From: Jonny007-MKD Date: Sun, 23 Feb 2020 15:05:42 +0100 Subject: check_dns: Fix memory leak diff --git a/plugins/check_dns.c b/plugins/check_dns.c index 0c10f09..2f944f9 100644 --- a/plugins/check_dns.c +++ b/plugins/check_dns.c @@ -271,7 +271,7 @@ main (int argc, char **argv) result = STATE_CRITICAL; xasprintf(&msg, _("Domain '%s' was found by the server: '%s'\n"), query_address, address); } else { - if (address == NULL) free(address); + if (address != NULL) free(address); address = "NXDOMAIN"; } } -- cgit v0.10-9-g596f From cfc43a327526d838db5ec81f5594df4a14319786 Mon Sep 17 00:00:00 2001 From: Jonny007-MKD Date: Mon, 24 May 2021 20:40:02 +0200 Subject: Improvements suggested by tobiaswiese diff --git a/plugins/check_dns.c b/plugins/check_dns.c index 2f944f9..9de6caf 100644 --- a/plugins/check_dns.c +++ b/plugins/check_dns.c @@ -41,7 +41,7 @@ const char *email = "devel@monitoring-plugins.org"; int process_arguments (int, char **); int validate_arguments (void); -int error_scan (char *, int*); +int error_scan (char *, int *); int ip_match_cidr(const char *, const char *); unsigned long ip2long(const char *); void print_help (void); @@ -355,7 +355,7 @@ ip2long(const char* src) { } int -error_scan (char *input_buffer, int* is_nxdomain) +error_scan (char *input_buffer, int *is_nxdomain) { const int nxdomain = strstr (input_buffer, "Non-existent") || diff --git a/plugins/t/check_dns.t b/plugins/t/check_dns.t index 1e7d534..afb2062 100644 --- a/plugins/t/check_dns.t +++ b/plugins/t/check_dns.t @@ -58,7 +58,7 @@ my $dns_server = getTestParameter( my $host_nonresponsive = getTestParameter( "NP_HOST_NONRESPONSIVE", "The hostname of system not responsive to network requests", - "192.0.2.0", + "10.0.0.1", ); my $res; -- cgit v0.10-9-g596f From 66e245375992c3942dbd5761f8b991e52bf5f9ab Mon Sep 17 00:00:00 2001 From: rincewind Date: Sat, 25 Sep 2021 23:24:34 +0200 Subject: Introduce new perfdata functions and stuff for using (u)int64_t diff --git a/plugins/utils.c b/plugins/utils.c index 348ec02..011f715 100644 --- a/plugins/utils.c +++ b/plugins/utils.c @@ -27,6 +27,8 @@ #include "utils_base.h" #include #include +#include +#include #include @@ -239,6 +241,46 @@ is_intnonneg (char *number) return FALSE; } +/* + * Checks whether the number in the string _number_ can be put inside a int64_t + * On success the number will be written to the _target_ address, if _target_ is not set + * to NULL. + */ +bool is_int64(char *number, int64_t *target) { + errno = 0; + uint64_t tmp = strtoll(number, NULL, 10); + if (errno != 0) { + return false; + } + if (tmp < INT64_MIN || tmp > INT64_MAX) { + return false; + } + if (target != NULL) { + *target = tmp; + } + return true; +} + +/* + * Checks whether the number in the string _number_ can be put inside a uint64_t + * On success the number will be written to the _target_ address, if _target_ is not set + * to NULL. + */ +bool is_uint64(char *number, uint64_t *target) { + errno = 0; + uint64_t tmp = strtoll(number, NULL, 10); + if (errno != 0) { + return false; + } + if (tmp < 0 || tmp > UINT64_MAX) { + return false; + } + if (target != NULL) { + *target = tmp; + } + return true; +} + int is_intpercent (char *number) { @@ -556,6 +598,84 @@ char *perfdata (const char *label, } +char *perfdata_uint64 (const char *label, + uint64_t val, + const char *uom, + int warnp, + uint64_t warn, + int critp, + uint64_t crit, + int minp, + uint64_t minv, + int maxp, + uint64_t maxv) +{ + char *data = NULL; + + if (strpbrk (label, "'= ")) + xasprintf (&data, "'%s'=%ld%s;", label, val, uom); + else + xasprintf (&data, "%s=%ld%s;", label, val, uom); + + if (warnp) + xasprintf (&data, "%s%ld;", data, warn); + else + xasprintf (&data, "%s;", data); + + if (critp) + xasprintf (&data, "%s%ld;", data, crit); + else + xasprintf (&data, "%s;", data); + + if (minp) + xasprintf (&data, "%s%ld", data, minv); + + if (maxp) + xasprintf (&data, "%s;%ld", data, maxv); + + return data; +} + + +char *perfdata_int64 (const char *label, + int64_t val, + const char *uom, + int warnp, + int64_t warn, + int critp, + int64_t crit, + int minp, + int64_t minv, + int maxp, + int64_t maxv) +{ + char *data = NULL; + + if (strpbrk (label, "'= ")) + xasprintf (&data, "'%s'=%ld%s;", label, val, uom); + else + xasprintf (&data, "%s=%ld%s;", label, val, uom); + + if (warnp) + xasprintf (&data, "%s%ld;", data, warn); + else + xasprintf (&data, "%s;", data); + + if (critp) + xasprintf (&data, "%s%ld;", data, crit); + else + xasprintf (&data, "%s;", data); + + if (minp) + xasprintf (&data, "%s%ld", data, minv); + + if (maxp) + xasprintf (&data, "%s;%ld", data, maxv); + + return data; +} + + char *fperfdata (const char *label, double val, const char *uom, diff --git a/plugins/utils.h b/plugins/utils.h index 33a2054..91a9c3f 100644 --- a/plugins/utils.h +++ b/plugins/utils.h @@ -16,6 +16,9 @@ suite of plugins. */ /* now some functions etc are being defined in ../lib/utils_base.c */ #include "utils_base.h" + +#include + #ifdef NP_EXTRA_OPTS /* Include extra-opts functions if compiled in */ #include "extra_opts.h" @@ -38,6 +41,7 @@ int is_intpos (char *); int is_intneg (char *); int is_intnonneg (char *); int is_intpercent (char *); +bool is_uint64(char *number, uint64_t *target); int is_numeric (char *); int is_positive (char *); @@ -88,6 +92,12 @@ void usage_va(const char *fmt, ...) __attribute__((noreturn)); char *perfdata (const char *, long int, const char *, int, long int, int, long int, int, long int, int, long int); +char *perfdata_uint64 (const char *, uint64_t , const char *, int, uint64_t, + int, uint64_t, int, uint64_t, int, uint64_t); + +char *perfdata_int64 (const char *, int64_t, const char *, int, int64_t, + int, int64_t, int, int64_t, int, int64_t); + char *fperfdata (const char *, double, const char *, int, double, int, double, int, double, int, double); -- cgit v0.10-9-g596f From 4621427ba8cbfab4815e65d35a728ad51ad8c391 Mon Sep 17 00:00:00 2001 From: rincewind Date: Sat, 25 Sep 2021 23:24:45 +0200 Subject: check_swap: Fix perfdata und thresholds for big values and simplify code The original problem was https://github.com/monitoring-plugins/monitoring-plugins/pull/1705 where the performance data output of check_swap did not conform to the parser logic of a monitoring system (which decided to go for "correct" SI or IEC units. The PR was accompanied by a change to byte values in the performance data which broke the _perfdata_ helper function which could not handle values of this size. The fix for this, was to use _fperfdata_ which could, but would use float values. I didn't like that (since all values here are discreet) and this is my proposal for a fix for the problem. It introduces some helper functions which do now explicitely work with (u)int64_t, including a special version of the _perfdata_ helper. In the process of introducing this to check_swap, I stumbled over several sections of the check_swap code which I found problematic. Therefore I tried to simplify the code and make it more readable and less redundant. I am kinda sorry about this, but sincerely hope my changes can be helpful. diff --git a/plugins/check_swap.c b/plugins/check_swap.c index 0ff0c77..25bcb3d 100644 --- a/plugins/check_swap.c +++ b/plugins/check_swap.c @@ -34,6 +34,10 @@ const char *email = "devel@monitoring-plugins.org"; #include "common.h" #include "popen.h" #include "utils.h" +#include +#include +#include +#include #ifdef HAVE_DECL_SWAPCTL # ifdef HAVE_SYS_PARAM_H @@ -51,26 +55,30 @@ const char *email = "devel@monitoring-plugins.org"; # define SWAP_CONVERSION 1 #endif -int check_swap (int usp, float free_swap_mb, float total_swap_mb); +typedef struct { + bool is_percentage; + uint64_t value; +} threshold_t; + +int check_swap (float free_swap_mb, float total_swap_mb); int process_arguments (int argc, char **argv); int validate_arguments (void); void print_usage (void); void print_help (void); -int warn_percent = 0; -int crit_percent = 0; -float warn_size_bytes = 0; -float crit_size_bytes = 0; +threshold_t warn; +threshold_t crit; int verbose; -int allswaps; +bool allswaps; int no_swap_state = STATE_CRITICAL; int main (int argc, char **argv) { - int percent_used, percent; - float total_swap_mb = 0, used_swap_mb = 0, free_swap_mb = 0; - float dsktotal_mb = 0, dskused_mb = 0, dskfree_mb = 0, tmp_mb = 0; + unsigned int percent_used, percent; + uint64_t total_swap_mb = 0, used_swap_mb = 0, free_swap_mb = 0; + uint64_t dsktotal_mb = 0, dskused_mb = 0, dskfree_mb = 0; + uint64_t tmp_KB = 0; int result = STATE_UNKNOWN; char input_buffer[MAX_INPUT_BUFFER]; #ifdef HAVE_PROC_MEMINFO @@ -116,10 +124,15 @@ main (int argc, char **argv) } fp = fopen (PROC_MEMINFO, "r"); while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, fp)) { - if (sscanf (input_buffer, "%*[S]%*[w]%*[a]%*[p]%*[:] %f %f %f", &dsktotal_mb, &dskused_mb, &dskfree_mb) == 3) { - dsktotal_mb = dsktotal_mb / 1048576; /* Apply conversion */ - dskused_mb = dskused_mb / 1048576; - dskfree_mb = dskfree_mb / 1048576; + /* + * The following sscanf call looks for a line looking like: "Swap: 123 123 123" + * On which kind of system this format exists, I can not say, but I wanted to + * document this for people who are not adapt with sscanf anymore, like me + */ + if (sscanf (input_buffer, "%*[S]%*[w]%*[a]%*[p]%*[:] %lu %lu %lu", &dsktotal_mb, &dskused_mb, &dskfree_mb) == 3) { + dsktotal_mb = dsktotal_mb / (1024 * 1024); /* Apply conversion */ + dskused_mb = dskused_mb / (1024 * 1024); + dskfree_mb = dskfree_mb / (1024 * 1024); total_swap_mb += dsktotal_mb; used_swap_mb += dskused_mb; free_swap_mb += dskfree_mb; @@ -128,21 +141,25 @@ main (int argc, char **argv) percent=100.0; else percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb)); - result = max_state (result, check_swap (percent, dskfree_mb, dsktotal_mb)); + result = max_state (result, check_swap (dskfree_mb, dsktotal_mb)); if (verbose) xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent); } } - else if (sscanf (input_buffer, "%*[S]%*[w]%*[a]%*[p]%[TotalFre]%*[:] %f %*[k]%*[B]", str, &tmp_mb)) { + /* + * The following sscanf call looks for lines looking like: "SwapTotal: 123" and "SwapFree: 123" + * This format exists at least on Debian Linux with a 5.* kernel + */ + else if (sscanf (input_buffer, "%*[S]%*[w]%*[a]%*[p]%[TotalFre]%*[:] %lu %*[k]%*[B]", str, &tmp_KB)) { if (verbose >= 3) { - printf("Got %s with %f\n", str, tmp_mb); + printf("Got %s with %lu\n", str, tmp_KB); } /* I think this part is always in Kb, so convert to mb */ if (strcmp ("Total", str) == 0) { - dsktotal_mb = tmp_mb / 1024; + dsktotal_mb = tmp_KB / 1024; } else if (strcmp ("Free", str) == 0) { - dskfree_mb = tmp_mb / 1024; + dskfree_mb = tmp_KB / 1024; } } } @@ -227,7 +244,7 @@ main (int argc, char **argv) free_swap_mb += dskfree_mb; if (allswaps) { percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb)); - result = max_state (result, check_swap (percent, dskfree_mb, dsktotal_mb)); + result = max_state (result, check_swap (dskfree_mb, dsktotal_mb)); if (verbose) xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent); } @@ -289,7 +306,7 @@ main (int argc, char **argv) if(allswaps && dsktotal_mb > 0){ percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb)); - result = max_state (result, check_swap (percent, dskfree_mb, dsktotal_mb)); + result = max_state (result, check_swap (dskfree_mb, dsktotal_mb)); if (verbose) { xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent); } @@ -328,7 +345,7 @@ main (int argc, char **argv) if(allswaps && dsktotal_mb > 0){ percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb)); - result = max_state (result, check_swap (percent, dskfree_mb, dsktotal_mb)); + result = max_state (result, check_swap(dskfree_mb, dsktotal_mb)); if (verbose) { xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent); } @@ -355,14 +372,19 @@ main (int argc, char **argv) status = "- Swap is either disabled, not present, or of zero size. "; } - result = max_state (result, check_swap (percent_used, free_swap_mb, total_swap_mb)); - printf (_("SWAP %s - %d%% free (%d MB out of %d MB) %s|"), + result = max_state (result, check_swap(free_swap_mb, total_swap_mb)); + printf (_("SWAP %s - %d%% free (%dMB out of %dMB) %s|"), state_text (result), (100 - percent_used), (int) free_swap_mb, (int) total_swap_mb, status); - puts (perfdata ("swap", (long) free_swap_mb, "MB", - TRUE, (long) max (warn_size_bytes/(1024 * 1024), warn_percent/100.0*total_swap_mb), - TRUE, (long) max (crit_size_bytes/(1024 * 1024), crit_percent/100.0*total_swap_mb), + uint64_t warn_print = warn.value; + if (warn.is_percentage) warn_print = warn.value * (total_swap_mb *1024 *1024/100); + uint64_t crit_print = crit.value; + if (crit.is_percentage) crit_print = crit.value * (total_swap_mb *1024 *1024/100); + + puts (perfdata_uint64 ("swap", free_swap_mb *1024 *1024, "B", + TRUE, warn_print, + TRUE, crit_print, TRUE, 0, TRUE, (long) total_swap_mb)); @@ -370,26 +392,37 @@ main (int argc, char **argv) } - int -check_swap (int usp, float free_swap_mb, float total_swap_mb) +check_swap(float free_swap_mb, float total_swap_mb) { if (!total_swap_mb) return no_swap_state; - int result = STATE_UNKNOWN; - float free_swap = free_swap_mb * (1024 * 1024); /* Convert back to bytes as warn and crit specified in bytes */ - if (usp >= 0 && crit_percent != 0 && usp >= (100.0 - crit_percent)) - result = STATE_CRITICAL; - else if (crit_size_bytes > 0 && free_swap <= crit_size_bytes) - result = STATE_CRITICAL; - else if (usp >= 0 && warn_percent != 0 && usp >= (100.0 - warn_percent)) - result = STATE_WARNING; - else if (warn_size_bytes > 0 && free_swap <= warn_size_bytes) - result = STATE_WARNING; - else if (usp >= 0.0) - result = STATE_OK; - return result; + uint64_t free_swap = free_swap_mb * (1024 * 1024); /* Convert back to bytes as warn and crit specified in bytes */ + + if (!crit.is_percentage && crit.value <= free_swap) return STATE_CRITICAL; + if (!warn.is_percentage && warn.value <= free_swap) return STATE_WARNING; + + + uint64_t usage_percentage = ((total_swap_mb - free_swap_mb) / total_swap_mb) * 100; + + if (crit.is_percentage && + usage_percentage >= 0 && + crit.value != 0 && + usage_percentage >= (100 - crit.value)) + { + return STATE_CRITICAL; + } + + if (warn.is_percentage && + usage_percentage >= 0 && + warn.value != 0 && + usage_percentage >= (100 - warn.value)) + { + return STATE_WARNING; + } + + return STATE_OK; } @@ -422,42 +455,67 @@ process_arguments (int argc, char **argv) break; switch (c) { - case 'w': /* warning size threshold */ - if (is_intnonneg (optarg)) { - warn_size_bytes = (float) atoi (optarg); - break; - } - else if (strstr (optarg, ",") && - strstr (optarg, "%") && - sscanf (optarg, "%f,%d%%", &warn_size_bytes, &warn_percent) == 2) { - warn_size_bytes = floorf(warn_size_bytes); - break; - } - else if (strstr (optarg, "%") && - sscanf (optarg, "%d%%", &warn_percent) == 1) { - break; - } - else { - usage4 (_("Warning threshold must be integer or percentage!")); - } - case 'c': /* critical size threshold */ - if (is_intnonneg (optarg)) { - crit_size_bytes = (float) atoi (optarg); - break; - } - else if (strstr (optarg, ",") && - strstr (optarg, "%") && - sscanf (optarg, "%f,%d%%", &crit_size_bytes, &crit_percent) == 2) { - crit_size_bytes = floorf(crit_size_bytes); - break; - } - else if (strstr (optarg, "%") && - sscanf (optarg, "%d%%", &crit_percent) == 1) { - break; - } - else { - usage4 (_("Critical threshold must be integer or percentage!")); + case 'w': /* warning size threshold */ + { + /* + * We expect either a positive integer value without a unit, which means + * the unit is Bytes or a positive integer value and a percentage sign (%), + * which means the value must be with 0 and 100 and is relative to the total swap + */ + size_t length; + length = strlen(optarg); + + if (optarg[length - 1] == '%') { + // It's percentage! + warn.is_percentage = true; + optarg[length - 1] = '\0'; + if (is_uint64(optarg, &warn.value)) { + if (warn.value > 100) { + usage4 (_("Warning threshold percentage must be <= 100!")); + } else { + break; + } + } + } else { + // It's Bytes + warn.is_percentage = false; + if (is_uint64(optarg, &warn.value)) { + break; + } else { + usage4 (_("Warning threshold be positive integer or percentage!")); + } + } } + case 'c': /* critical size threshold */ + { + /* + * We expect either a positive integer value without a unit, which means + * the unit is Bytes or a positive integer value and a percentage sign (%), + * which means the value must be with 0 and 100 and is relative to the total swap + */ + size_t length; + length = strlen(optarg); + + if (optarg[length - 1] == '%') { + // It's percentage! + crit.is_percentage = true; + optarg[length - 1] = '\0'; + if (is_uint64(optarg, &crit.value)) { + if (crit.value> 100) { + usage4 (_("Critical threshold percentage must be <= 100!")); + } else { + break; + } + } + } else { + crit.is_percentage = false; + if (is_uint64(optarg, &crit.value)) { + break; + } else { + usage4 (_("Critical threshold be positive integer or percentage!")); + } + } + } case 'a': /* all swap */ allswaps = TRUE; break; @@ -482,23 +540,6 @@ process_arguments (int argc, char **argv) c = optind; if (c == argc) return validate_arguments (); - if (warn_percent == 0 && is_intnonneg (argv[c])) - warn_percent = atoi (argv[c++]); - - if (c == argc) - return validate_arguments (); - if (crit_percent == 0 && is_intnonneg (argv[c])) - crit_percent = atoi (argv[c++]); - - if (c == argc) - return validate_arguments (); - if (warn_size_bytes == 0 && is_intnonneg (argv[c])) - warn_size_bytes = (float) atoi (argv[c++]); - - if (c == argc) - return validate_arguments (); - if (crit_size_bytes == 0 && is_intnonneg (argv[c])) - crit_size_bytes = (float) atoi (argv[c++]); return validate_arguments (); } @@ -508,17 +549,12 @@ process_arguments (int argc, char **argv) int validate_arguments (void) { - if (warn_percent == 0 && crit_percent == 0 && warn_size_bytes == 0 - && crit_size_bytes == 0) { + if (warn.value == 0 && crit.value == 0) { return ERROR; } - else if (warn_percent < crit_percent) { - usage4 - (_("Warning percentage should be more than critical percentage")); - } - else if (warn_size_bytes < crit_size_bytes) { + else if (warn.value < crit.value) { usage4 - (_("Warning free space should be more than critical free space")); + (_("Warning should be more than critical")); } return OK; } @@ -564,7 +600,6 @@ print_help (void) } - void print_usage (void) { -- cgit v0.10-9-g596f From 280ae58ed8e340f8096cf37f60c84f99d6723537 Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Sun, 26 Sep 2021 00:34:44 +0200 Subject: Remove spaces from tests diff --git a/plugins/t/check_swap.t b/plugins/t/check_swap.t index e44adc9..de9e0f0 100644 --- a/plugins/t/check_swap.t +++ b/plugins/t/check_swap.t @@ -8,9 +8,9 @@ use strict; use Test::More tests => 8; use NPTest; -my $successOutput = '/^SWAP OK - [0-9]+\% free \([0-9]+ MB out of [0-9]+ MB\)/'; -my $failureOutput = '/^SWAP CRITICAL - [0-9]+\% free \([0-9]+ MB out of [0-9]+ MB\)/'; -my $warnOutput = '/^SWAP WARNING - [0-9]+\% free \([0-9]+ MB out of [0-9]+ MB\)/'; +my $successOutput = '/^SWAP OK - [0-9]+\% free \([0-9]+MB out of [0-9]+MB\)/'; +my $failureOutput = '/^SWAP CRITICAL - [0-9]+\% free \([0-9]+MB out of [0-9]+MB\)/'; +my $warnOutput = '/^SWAP WARNING - [0-9]+\% free \([0-9]+MB out of [0-9]+MB\)/'; my $result; -- cgit v0.10-9-g596f From f55ea7632f4284a0b8858361270337bd9fde9a60 Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Sun, 26 Sep 2021 01:34:45 +0200 Subject: Fix comparing logic diff --git a/plugins/check_swap.c b/plugins/check_swap.c index 25bcb3d..6dec9b2 100644 --- a/plugins/check_swap.c +++ b/plugins/check_swap.c @@ -400,8 +400,8 @@ check_swap(float free_swap_mb, float total_swap_mb) uint64_t free_swap = free_swap_mb * (1024 * 1024); /* Convert back to bytes as warn and crit specified in bytes */ - if (!crit.is_percentage && crit.value <= free_swap) return STATE_CRITICAL; - if (!warn.is_percentage && warn.value <= free_swap) return STATE_WARNING; + if (!crit.is_percentage && crit.value >= free_swap) return STATE_CRITICAL; + if (!warn.is_percentage && warn.value >= free_swap) return STATE_WARNING; uint64_t usage_percentage = ((total_swap_mb - free_swap_mb) / total_swap_mb) * 100; -- cgit v0.10-9-g596f From d2f2da175eda5a06291a974d971968a1241d7935 Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Sat, 2 Oct 2021 12:47:50 +0200 Subject: Change all to comments to old comment style diff --git a/plugins/check_swap.c b/plugins/check_swap.c index 6dec9b2..4d124a3 100644 --- a/plugins/check_swap.c +++ b/plugins/check_swap.c @@ -466,7 +466,7 @@ process_arguments (int argc, char **argv) length = strlen(optarg); if (optarg[length - 1] == '%') { - // It's percentage! + /* It's percentage */ warn.is_percentage = true; optarg[length - 1] = '\0'; if (is_uint64(optarg, &warn.value)) { @@ -477,7 +477,7 @@ process_arguments (int argc, char **argv) } } } else { - // It's Bytes + /* It's Bytes */ warn.is_percentage = false; if (is_uint64(optarg, &warn.value)) { break; @@ -497,7 +497,7 @@ process_arguments (int argc, char **argv) length = strlen(optarg); if (optarg[length - 1] == '%') { - // It's percentage! + /* It's percentage */ crit.is_percentage = true; optarg[length - 1] = '\0'; if (is_uint64(optarg, &crit.value)) { @@ -508,6 +508,7 @@ process_arguments (int argc, char **argv) } } } else { + /* It's Bytes */ crit.is_percentage = false; if (is_uint64(optarg, &crit.value)) { break; -- cgit v0.10-9-g596f From 46c5327e348540ab04dc37d42f6d1c5408179fa6 Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Sat, 2 Oct 2021 23:37:12 +0200 Subject: Revert to poor man's logic diff --git a/plugins/check_swap.c b/plugins/check_swap.c index 4d124a3..685c2cc 100644 --- a/plugins/check_swap.c +++ b/plugins/check_swap.c @@ -37,7 +37,6 @@ const char *email = "devel@monitoring-plugins.org"; #include #include #include -#include #ifdef HAVE_DECL_SWAPCTL # ifdef HAVE_SYS_PARAM_H @@ -56,7 +55,7 @@ const char *email = "devel@monitoring-plugins.org"; #endif typedef struct { - bool is_percentage; + int is_percentage; uint64_t value; } threshold_t; @@ -69,7 +68,7 @@ void print_help (void); threshold_t warn; threshold_t crit; int verbose; -bool allswaps; +int allswaps; int no_swap_state = STATE_CRITICAL; int @@ -467,7 +466,7 @@ process_arguments (int argc, char **argv) if (optarg[length - 1] == '%') { /* It's percentage */ - warn.is_percentage = true; + warn.is_percentage = 1; optarg[length - 1] = '\0'; if (is_uint64(optarg, &warn.value)) { if (warn.value > 100) { @@ -478,7 +477,7 @@ process_arguments (int argc, char **argv) } } else { /* It's Bytes */ - warn.is_percentage = false; + warn.is_percentage = 0; if (is_uint64(optarg, &warn.value)) { break; } else { @@ -498,7 +497,7 @@ process_arguments (int argc, char **argv) if (optarg[length - 1] == '%') { /* It's percentage */ - crit.is_percentage = true; + crit.is_percentage = 1; optarg[length - 1] = '\0'; if (is_uint64(optarg, &crit.value)) { if (crit.value> 100) { @@ -509,7 +508,7 @@ process_arguments (int argc, char **argv) } } else { /* It's Bytes */ - crit.is_percentage = false; + crit.is_percentage = 0; if (is_uint64(optarg, &crit.value)) { break; } else { diff --git a/plugins/utils.c b/plugins/utils.c index 011f715..f7f8952 100644 --- a/plugins/utils.c +++ b/plugins/utils.c @@ -246,19 +246,19 @@ is_intnonneg (char *number) * On success the number will be written to the _target_ address, if _target_ is not set * to NULL. */ -bool is_int64(char *number, int64_t *target) { +int is_int64(char *number, int64_t *target) { errno = 0; uint64_t tmp = strtoll(number, NULL, 10); if (errno != 0) { - return false; + return 0; } if (tmp < INT64_MIN || tmp > INT64_MAX) { - return false; + return 0; } if (target != NULL) { *target = tmp; } - return true; + return 1; } /* @@ -266,19 +266,19 @@ bool is_int64(char *number, int64_t *target) { * On success the number will be written to the _target_ address, if _target_ is not set * to NULL. */ -bool is_uint64(char *number, uint64_t *target) { +int is_uint64(char *number, uint64_t *target) { errno = 0; uint64_t tmp = strtoll(number, NULL, 10); if (errno != 0) { - return false; + return 0; } if (tmp < 0 || tmp > UINT64_MAX) { - return false; + return 0; } if (target != NULL) { *target = tmp; } - return true; + return 1; } int diff --git a/plugins/utils.h b/plugins/utils.h index 91a9c3f..5b54da3 100644 --- a/plugins/utils.h +++ b/plugins/utils.h @@ -17,8 +17,6 @@ suite of plugins. */ #include "utils_base.h" -#include - #ifdef NP_EXTRA_OPTS /* Include extra-opts functions if compiled in */ #include "extra_opts.h" @@ -41,7 +39,8 @@ int is_intpos (char *); int is_intneg (char *); int is_intnonneg (char *); int is_intpercent (char *); -bool is_uint64(char *number, uint64_t *target); +int is_uint64(char *number, uint64_t *target); +int is_int64(char *number, int64_t *target); int is_numeric (char *); int is_positive (char *); -- cgit v0.10-9-g596f From ead405515fb4bf84ce18d2fe3f621058f09a8aa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20K=C3=A4stle?= Date: Mon, 18 Oct 2021 10:41:44 +0200 Subject: Restrict the nickname length of the test user for check_ircd check_ircd was using the string `ircd` plus the PID as a nickname for connecting to a IRC network by default. This caused errors, when the PID was too high and the network restricted the length of the nickname to 9 characters. This patch "fixes" this by just cutting it of, if it gets too big. diff --git a/plugins-scripts/check_ircd.pl b/plugins-scripts/check_ircd.pl index 22d21c2..e7ab80c 100755 --- a/plugins-scripts/check_ircd.pl +++ b/plugins-scripts/check_ircd.pl @@ -69,7 +69,7 @@ $ENV{'ENV'}=''; # -----------------------------------------------------------------[ Global ]-- $PROGNAME = "check_ircd"; -my $NICK="ircd$$"; +my $NICK="ircd" . $$ % 10000; my $USER_INFO="monitor localhost localhost : "; # -------------------------------------------------------------[ connection ]-- -- cgit v0.10-9-g596f From 03028d23b6c59bcb4000bc70209593afd798dfe3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20K=C3=A4stle?= Date: Mon, 18 Oct 2021 13:16:10 +0200 Subject: Add comment to make the purpose of the nickname fix more obvious diff --git a/plugins-scripts/check_ircd.pl b/plugins-scripts/check_ircd.pl index e7ab80c..d869ae7 100755 --- a/plugins-scripts/check_ircd.pl +++ b/plugins-scripts/check_ircd.pl @@ -69,6 +69,8 @@ $ENV{'ENV'}=''; # -----------------------------------------------------------------[ Global ]-- $PROGNAME = "check_ircd"; +# nickname shouldn't be longer than 9 chars, this might happen with large PIDs +# To prevent this, we cut of the part over 10000 my $NICK="ircd" . $$ % 10000; my $USER_INFO="monitor localhost localhost : "; -- cgit v0.10-9-g596f From a96161c824f7f97830f4aa4daa166013961d55f1 Mon Sep 17 00:00:00 2001 From: Sven Nierlein Date: Mon, 25 Oct 2021 14:55:50 +0200 Subject: actions: map utmp from host to container this fixes the check_users not having any logged in user to check. diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 512d28e..0f93930 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -35,6 +35,7 @@ jobs: -e NPTEST_CACHE="/src/.github/NPTest.cache" \ -w /src -v ${PWD}:/src \ --tmpfs /media/ramdisk1 \ + -v /var/run/utmp:/var/run/utmp \ --mount source=tmp-vol,destination=/src,target=/media/ramdisk2 \ ${{ matrix.distro }} \ /bin/sh -c '${{ matrix.prepare }} && \ -- cgit v0.10-9-g596f From a08215368e5f9dc0164fcce9f5591c5310fdeb8c Mon Sep 17 00:00:00 2001 From: Harald Jenny Date: Mon, 5 Jul 2021 10:29:09 +0200 Subject: Create check_load.c just a cosmetic fix so the load plugin display a LOAD prefix before check results diff --git a/plugins/check_load.c b/plugins/check_load.c index bf7b94b..0e4de54 100644 --- a/plugins/check_load.c +++ b/plugins/check_load.c @@ -209,7 +209,7 @@ main (int argc, char **argv) else if(la[i] > wload[i]) result = STATE_WARNING; } - printf("%s - %s|", state_text(result), status_line); + printf("LOAD %s - %s|", state_text(result), status_line); for(i = 0; i < 3; i++) printf("load%d=%.3f;%.3f;%.3f;0; ", nums[i], la[i], wload[i], cload[i]); -- cgit v0.10-9-g596f From e79ada81a696e3c826b383e3ff7cbc8f91bf46a4 Mon Sep 17 00:00:00 2001 From: Harald Jenny Date: Mon, 5 Jul 2021 10:30:39 +0200 Subject: Update check_load.t adjust tests for new plugin output diff --git a/plugins/t/check_load.t b/plugins/t/check_load.t index 55f6f75..60837ef 100644 --- a/plugins/t/check_load.t +++ b/plugins/t/check_load.t @@ -11,8 +11,8 @@ use NPTest; my $res; my $loadValue = "[0-9]+\.?[0-9]+"; -my $successOutput = "/^OK - load average: $loadValue, $loadValue, $loadValue/"; -my $failureOutput = "/^CRITICAL - load average: $loadValue, $loadValue, $loadValue/"; +my $successOutput = "/^LOAD OK - load average: $loadValue, $loadValue, $loadValue/"; +my $failureOutput = "/^LOAD CRITICAL - load average: $loadValue, $loadValue, $loadValue/"; plan tests => 11; -- cgit v0.10-9-g596f From 078c69d2ddf6b7dd2dfef5ca0f3013a723ec0268 Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Mon, 25 Oct 2021 17:34:13 +0200 Subject: Recognice IEC binary units and format accordingly to base2 (always) diff --git a/plugins/check_disk.c b/plugins/check_disk.c index a273519..0786228 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c @@ -574,21 +574,24 @@ process_arguments (int argc, char **argv) case 'u': if (units) free(units); - if (! strcmp (optarg, "bytes")) { + if (! strcasecmp (optarg, "bytes")) { mult = (uintmax_t)1; units = strdup ("B"); - } else if (! strcmp (optarg, "kB")) { + } else if ( (! strcmp (optarg, "kB")) || (!strcmp(optarg, "KiB")) ) { mult = (uintmax_t)1024; - units = strdup ("kB"); - } else if (! strcmp (optarg, "MB")) { + units = strdup ("kiB"); + } else if ( (! strcmp (optarg, "MB")) || (!strcmp(optarg, "MiB")) ) { mult = (uintmax_t)1024 * 1024; - units = strdup ("MB"); - } else if (! strcmp (optarg, "GB")) { + units = strdup ("MiB"); + } else if ( (! strcmp (optarg, "GB")) || (!strcmp(optarg, "GiB")) ) { mult = (uintmax_t)1024 * 1024 * 1024; - units = strdup ("GB"); - } else if (! strcmp (optarg, "TB")) { + units = strdup ("GiB"); + } else if ( (! strcmp (optarg, "TB")) || (!strcmp(optarg, "TiB")) ) { mult = (uintmax_t)1024 * 1024 * 1024 * 1024; - units = strdup ("TB"); + units = strdup ("TiB"); + } else if ( (! strcmp (optarg, "PB")) || (!strcmp(optarg, "PiB")) ) { + mult = (uintmax_t)1024 * 1024 * 1024 * 1024 * 1024; + units = strdup ("PiB"); } else { die (STATE_UNKNOWN, _("unit type %s not known\n"), optarg); } @@ -599,13 +602,13 @@ process_arguments (int argc, char **argv) mult = 1024; if (units) free(units); - units = strdup ("kB"); + units = strdup ("kiB"); break; case 'm': /* display mountpoint */ mult = 1024 * 1024; if (units) free(units); - units = strdup ("MB"); + units = strdup ("MiB"); break; case 'L': stat_remote_fs = 1; @@ -812,7 +815,7 @@ process_arguments (int argc, char **argv) } if (units == NULL) { - units = strdup ("MB"); + units = strdup ("MiB"); mult = (uintmax_t)1024 * 1024; } -- cgit v0.10-9-g596f From 8f2cfd1c805f68a21e221f9ea629800be1c88af8 Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Mon, 25 Oct 2021 17:35:29 +0200 Subject: Reformat a little bit for easier reading diff --git a/plugins/check_disk.c b/plugins/check_disk.c index 0786228..00afcad 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c @@ -288,8 +288,17 @@ main (int argc, char **argv) get_stats (path, &fsp); if (verbose >= 3) { - printf ("For %s, used_pct=%g free_pct=%g used_units=%g free_units=%g total_units=%g used_inodes_pct=%g free_inodes_pct=%g fsp.fsu_blocksize=%llu mult=%llu\n", - me->me_mountdir, path->dused_pct, path->dfree_pct, path->dused_units, path->dfree_units, path->dtotal_units, path->dused_inodes_percent, path->dfree_inodes_percent, fsp.fsu_blocksize, mult); + printf ("For %s, used_pct=%g free_pct=%g used_units=%llu free_units=%llu total_units=%llu used_inodes_pct=%g free_inodes_pct=%g fsp.fsu_blocksize=%llu mult=%llu\n", + me->me_mountdir, + path->dused_pct, + path->dfree_pct, + path->dused_units, + path->dfree_units, + path->dtotal_units, + path->dused_inodes_percent, + path->dfree_inodes_percent, + fsp.fsu_blocksize, + mult); } /* Threshold comparisons */ @@ -344,12 +353,13 @@ main (int argc, char **argv) /* Nb: *_high_tide are unset when == UINT_MAX */ xasprintf (&perf, "%s %s", perf, - perfdata ((!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir, - path->dused_units, units, - (warning_high_tide != UINT_MAX ? TRUE : FALSE), warning_high_tide, - (critical_high_tide != UINT_MAX ? TRUE : FALSE), critical_high_tide, - TRUE, 0, - TRUE, path->dtotal_units)); + perfdata_uint64 ( + (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir, + path->dused_units * mult, "B", + (warning_high_tide == UINT64_MAX ? FALSE : TRUE), warning_high_tide * mult, + (critical_high_tide == UINT64_MAX ? FALSE : TRUE), critical_high_tide * mult, + TRUE, 0, + TRUE, path->dtotal_units * mult)); if (display_inodes_perfdata) { /* *_high_tide must be reinitialized at each run */ @@ -366,12 +376,12 @@ main (int argc, char **argv) xasprintf (&perf_ilabel, "%s (inodes)", (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir); /* Nb: *_high_tide are unset when == UINT_MAX */ xasprintf (&perf, "%s %s", perf, - perfdata (perf_ilabel, - path->inodes_used, "", - (warning_high_tide != UINT_MAX ? TRUE : FALSE), warning_high_tide, - (critical_high_tide != UINT_MAX ? TRUE : FALSE), critical_high_tide, - TRUE, 0, - TRUE, path->inodes_total)); + perfdata_uint64 (perf_ilabel, + path->inodes_used, "", + (warning_high_tide != UINT64_MAX ? TRUE : FALSE), warning_high_tide, + (critical_high_tide != UINT64_MAX ? TRUE : FALSE), critical_high_tide, + TRUE, 0, + TRUE, path->inodes_total)); } if (disk_result==STATE_OK && erronly && !verbose) @@ -1055,8 +1065,14 @@ get_stats (struct parameter_list *p, struct fs_usage *fsp) { } if (verbose >= 3) printf("Group %s now has: used_units=%g free_units=%g total_units=%g fsu_blocksize=%llu mult=%llu\n", - p->group, tmpfsp.fsu_bavail, tmpfsp.fsu_blocksize, p->best_match->me_mountdir, p->dused_units, - p->dfree_units, p->dtotal_units, mult); + p->group, + tmpfsp.fsu_bavail, + tmpfsp.fsu_blocksize, + p->best_match->me_mountdir, + p->dused_units, + p->dfree_units, + p->dtotal_units, + mult); } /* modify devname and mountdir for output */ p->best_match->me_mountdir = p->best_match->me_devname = p->group; -- cgit v0.10-9-g596f From 50fc9b73a2127c8ed1944b8e3fd5f0f7b64ca8ec Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Mon, 25 Oct 2021 17:36:58 +0200 Subject: Switch to uint64_t diff --git a/lib/utils_disk.h b/lib/utils_disk.h index 999270c..bf52e4c 100644 --- a/lib/utils_disk.h +++ b/lib/utils_disk.h @@ -27,7 +27,7 @@ struct parameter_list uintmax_t total, available, available_to_root, used, inodes_free, inodes_free_to_root, inodes_used, inodes_total; double dfree_pct, dused_pct; - double dused_units, dfree_units, dtotal_units; + uint64_t dused_units, dfree_units, dtotal_units; double dused_inodes_percent, dfree_inodes_percent; }; diff --git a/plugins/check_disk.c b/plugins/check_disk.c index 00afcad..ecde4e5 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c @@ -172,8 +172,6 @@ main (int argc, char **argv) char *preamble; char *flag_header; double inode_space_pct; - double warning_high_tide; - double critical_high_tide; int temp_result; struct mount_entry *me; @@ -335,23 +333,23 @@ main (int argc, char **argv) */ /* *_high_tide must be reinitialized at each run */ - warning_high_tide = UINT_MAX; - critical_high_tide = UINT_MAX; + uint64_t warning_high_tide = UINT64_MAX; + uint64_t critical_high_tide = UINT64_MAX; if (path->freespace_units->warning != NULL) { warning_high_tide = path->dtotal_units - path->freespace_units->warning->end; } if (path->freespace_percent->warning != NULL) { - warning_high_tide = abs( min( (double) warning_high_tide, (double) (1.0 - path->freespace_percent->warning->end/100)*path->dtotal_units )); + warning_high_tide = llabs( min( (double) warning_high_tide, (1.0 - path->freespace_percent->warning->end / 100 * path->dtotal_units) )); } if (path->freespace_units->critical != NULL) { critical_high_tide = path->dtotal_units - path->freespace_units->critical->end; } if (path->freespace_percent->critical != NULL) { - critical_high_tide = abs( min( (double) critical_high_tide, (double) (1.0 - path->freespace_percent->critical->end/100)*path->dtotal_units )); + critical_high_tide = llabs( min( (double) critical_high_tide, (double) (1.0 - path->freespace_percent->critical->end/100)*path->dtotal_units )); } - /* Nb: *_high_tide are unset when == UINT_MAX */ + /* Nb: *_high_tide are unset when == UINT64_MAX */ xasprintf (&perf, "%s %s", perf, perfdata_uint64 ( (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir, @@ -363,18 +361,18 @@ main (int argc, char **argv) if (display_inodes_perfdata) { /* *_high_tide must be reinitialized at each run */ - warning_high_tide = UINT_MAX; - critical_high_tide = UINT_MAX; + warning_high_tide = UINT64_MAX; + critical_high_tide = UINT64_MAX; if (path->freeinodes_percent->warning != NULL) { - warning_high_tide = abs( min( (double) warning_high_tide, (double) (1.0 - path->freeinodes_percent->warning->end/100)*path->inodes_total )); + warning_high_tide = llabs( min( (double) warning_high_tide, (double) (1.0 - path->freeinodes_percent->warning->end/100)*path->inodes_total )); } if (path->freeinodes_percent->critical != NULL) { - critical_high_tide = abs( min( (double) critical_high_tide, (double) (1.0 - path->freeinodes_percent->critical->end/100)*path->inodes_total )); + critical_high_tide = llabs( min( (double) critical_high_tide, (double) (1.0 - path->freeinodes_percent->critical->end/100)*path->inodes_total )); } xasprintf (&perf_ilabel, "%s (inodes)", (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir); - /* Nb: *_high_tide are unset when == UINT_MAX */ + /* Nb: *_high_tide are unset when == UINT64_MAX */ xasprintf (&perf, "%s %s", perf, perfdata_uint64 (perf_ilabel, path->inodes_used, "", @@ -392,7 +390,7 @@ main (int argc, char **argv) } else { xasprintf(&flag_header, ""); } - xasprintf (&output, "%s%s %s %.0f %s (%.0f%%", + xasprintf (&output, "%s%s %s %llu%s (%.0f%%", output, flag_header, (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir, path->dfree_units, -- cgit v0.10-9-g596f From d3af7a353e75dadf283c58ad49cfe2dc81a4c9ce Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Mon, 25 Oct 2021 17:42:00 +0200 Subject: Remove useless lines and fix some formatting diff --git a/plugins/utils.c b/plugins/utils.c index f7f8952..ff0e55d 100644 --- a/plugins/utils.c +++ b/plugins/utils.c @@ -601,12 +601,16 @@ char *perfdata (const char *label, char *perfdata_uint64 (const char *label, uint64_t val, const char *uom, + int warnp, uint64_t warn, + int critp, uint64_t crit, + int minp, uint64_t minv, + int maxp, uint64_t maxv) { @@ -618,20 +622,16 @@ char *perfdata_uint64 (const char *label, xasprintf (&data, "%s=%ld%s;", label, val, uom); if (warnp) - xasprintf (&data, "%s%ld;", data, warn); - else - xasprintf (&data, "%s;", data); + xasprintf (&data, "%s%lu;", data, warn); if (critp) - xasprintf (&data, "%s%ld;", data, crit); - else - xasprintf (&data, "%s;", data); + xasprintf (&data, "%s%lu;", data, crit); if (minp) - xasprintf (&data, "%s%ld", data, minv); + xasprintf (&data, "%s%lu", data, minv); if (maxp) - xasprintf (&data, "%s;%ld", data, maxv); + xasprintf (&data, "%s;%lu", data, maxv); return data; } @@ -658,13 +658,9 @@ char *perfdata_int64 (const char *label, if (warnp) xasprintf (&data, "%s%ld;", data, warn); - else - xasprintf (&data, "%s;", data); if (critp) xasprintf (&data, "%s%ld;", data, crit); - else - xasprintf (&data, "%s;", data); if (minp) xasprintf (&data, "%s%ld", data, minv); -- cgit v0.10-9-g596f From 726a29a3ac4b155536099b8cae2bd517d56fb5f8 Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Tue, 26 Oct 2021 12:50:14 +0200 Subject: Fix some tests diff --git a/plugins/t/check_disk.t b/plugins/t/check_disk.t index fdd8769..ec527e7 100644 --- a/plugins/t/check_disk.t +++ b/plugins/t/check_disk.t @@ -88,8 +88,9 @@ $result = NPTest->testCmd( ); $_ = $result->perf_output; my ($warn_absth_data, $crit_absth_data, $total_absth_data) = (m/=.[^;]*;(\d+);(\d+);\d+;(\d+)/); -is ($warn_absth_data, $total_absth_data - 20, "Wrong warning in perf data using absolute thresholds"); -is ($crit_absth_data, $total_absth_data - 10, "Wrong critical in perf data using absolute thresholds"); +# default unit is MiB, but perfdata is always bytes +is ($warn_absth_data, $total_absth_data - (20 * (2 ** 20)), "Wrong warning in perf data using absolute thresholds"); +is ($crit_absth_data, $total_absth_data - (10 * (2 ** 20)), "Wrong critical in perf data using absolute thresholds"); # Then check percent thresholds. $result = NPTest->testCmd( @@ -119,7 +120,7 @@ like ( $result->only_output, qr/$more_free/, "Have disk name in text"); $result = NPTest->testCmd( "./check_disk -w 1 -c 1 -p $more_free -p $less_free" ); cmp_ok( $result->return_code, '==', 0, "At least 1 MB available on $more_free and $less_free"); $_ = $result->output; -my ($free_mb_on_mp1, $free_mb_on_mp2) = (m/(\d+) MB .* (\d+) MB /g); +my ($free_mb_on_mp1, $free_mb_on_mp2) = (m/(\d+)MiB .* (\d+)MiB /g); my $free_mb_on_all = $free_mb_on_mp1 + $free_mb_on_mp2; -- cgit v0.10-9-g596f From 1c0882def0d9ce4ed5b2d443884138622e6d839b Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Tue, 26 Oct 2021 13:05:57 +0200 Subject: hopefully fix warning high tide with percentage diff --git a/plugins/check_disk.c b/plugins/check_disk.c index ecde4e5..1778b61 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c @@ -340,7 +340,7 @@ main (int argc, char **argv) warning_high_tide = path->dtotal_units - path->freespace_units->warning->end; } if (path->freespace_percent->warning != NULL) { - warning_high_tide = llabs( min( (double) warning_high_tide, (1.0 - path->freespace_percent->warning->end / 100 * path->dtotal_units) )); + warning_high_tide = llabs( min( (double) warning_high_tide, (double) (1.0 - path->freespace_percent->warning->end/100)* path->dtotal_units )); } if (path->freespace_units->critical != NULL) { critical_high_tide = path->dtotal_units - path->freespace_units->critical->end; -- cgit v0.10-9-g596f From 6e0586c8e35c3990631f73d8cdb89b70751994c3 Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Tue, 26 Oct 2021 16:53:01 +0200 Subject: Reform some arithmetical operations for more clarity diff --git a/plugins/check_disk.c b/plugins/check_disk.c index 1778b61..71eab53 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c @@ -334,19 +334,21 @@ main (int argc, char **argv) /* *_high_tide must be reinitialized at each run */ uint64_t warning_high_tide = UINT64_MAX; - uint64_t critical_high_tide = UINT64_MAX; if (path->freespace_units->warning != NULL) { - warning_high_tide = path->dtotal_units - path->freespace_units->warning->end; + warning_high_tide = (path->dtotal_units - path->freespace_units->warning->end) * mult; } if (path->freespace_percent->warning != NULL) { - warning_high_tide = llabs( min( (double) warning_high_tide, (double) (1.0 - path->freespace_percent->warning->end/100)* path->dtotal_units )); + warning_high_tide = min( warning_high_tide, (uint64_t)((1.0 - path->freespace_percent->warning->end/100) * (path->dtotal_units * mult)) ); } + + uint64_t critical_high_tide = UINT64_MAX; + if (path->freespace_units->critical != NULL) { - critical_high_tide = path->dtotal_units - path->freespace_units->critical->end; + critical_high_tide = (path->dtotal_units - path->freespace_units->critical->end) * mult; } if (path->freespace_percent->critical != NULL) { - critical_high_tide = llabs( min( (double) critical_high_tide, (double) (1.0 - path->freespace_percent->critical->end/100)*path->dtotal_units )); + critical_high_tide = min( critical_high_tide, (uint64_t)((1.0 - path->freespace_percent->critical->end/100) * (path->dtotal_units * mult)) ); } /* Nb: *_high_tide are unset when == UINT64_MAX */ @@ -354,8 +356,8 @@ main (int argc, char **argv) perfdata_uint64 ( (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir, path->dused_units * mult, "B", - (warning_high_tide == UINT64_MAX ? FALSE : TRUE), warning_high_tide * mult, - (critical_high_tide == UINT64_MAX ? FALSE : TRUE), critical_high_tide * mult, + (warning_high_tide == UINT64_MAX ? FALSE : TRUE), warning_high_tide, + (critical_high_tide == UINT64_MAX ? FALSE : TRUE), critical_high_tide, TRUE, 0, TRUE, path->dtotal_units * mult)); -- cgit v0.10-9-g596f From 73ed8109e5ba1c61f8ba435fd4324318d0751f18 Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Tue, 26 Oct 2021 20:47:28 +0200 Subject: Re-add separation semicolons for perfdata, which I deleted diff --git a/plugins/utils.c b/plugins/utils.c index ff0e55d..c0dce25 100644 --- a/plugins/utils.c +++ b/plugins/utils.c @@ -617,18 +617,22 @@ char *perfdata_uint64 (const char *label, char *data = NULL; if (strpbrk (label, "'= ")) - xasprintf (&data, "'%s'=%ld%s;", label, val, uom); + xasprintf (&data, "'%s'=%ld%s", label, val, uom); else - xasprintf (&data, "%s=%ld%s;", label, val, uom); + xasprintf (&data, "%s=%ld%s", label, val, uom); + xasprintf (&data, "%s;", data); if (warnp) - xasprintf (&data, "%s%lu;", data, warn); + xasprintf (&data, "%s%lu", data, warn); + xasprintf (&data, "%s;", data); if (critp) - xasprintf (&data, "%s%lu;", data, crit); + xasprintf (&data, "%s%lu", data, crit); + xasprintf (&data, "%s;", data); if (minp) xasprintf (&data, "%s%lu", data, minv); + xasprintf (&data, "%s;", data); if (maxp) xasprintf (&data, "%s;%lu", data, maxv); @@ -652,18 +656,22 @@ char *perfdata_int64 (const char *label, char *data = NULL; if (strpbrk (label, "'= ")) - xasprintf (&data, "'%s'=%ld%s;", label, val, uom); + xasprintf (&data, "'%s'=%ld%s", label, val, uom); else - xasprintf (&data, "%s=%ld%s;", label, val, uom); + xasprintf (&data, "%s=%ld%s", label, val, uom); + xasprintf (&data, "%s;", data); if (warnp) - xasprintf (&data, "%s%ld;", data, warn); + xasprintf (&data, "%s%ld", data, warn); + xasprintf (&data, "%s;", data); if (critp) - xasprintf (&data, "%s%ld;", data, crit); + xasprintf (&data, "%s%ld", data, crit); + xasprintf (&data, "%s;", data); if (minp) xasprintf (&data, "%s%ld", data, minv); + xasprintf (&data, "%s;", data); if (maxp) xasprintf (&data, "%s;%ld", data, maxv); -- cgit v0.10-9-g596f From 4c8ab67dd31c526d1c73653319ba537cec3000a5 Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Tue, 26 Oct 2021 21:09:55 +0200 Subject: Fix my own errors for real this time and add some comments, so I wont do them again diff --git a/plugins/utils.c b/plugins/utils.c index c0dce25..ebdae2e 100644 --- a/plugins/utils.c +++ b/plugins/utils.c @@ -601,41 +601,39 @@ char *perfdata (const char *label, char *perfdata_uint64 (const char *label, uint64_t val, const char *uom, - - int warnp, + int warnp, /* Warning present */ uint64_t warn, - - int critp, + int critp, /* Critical present */ uint64_t crit, - - int minp, + int minp, /* Minimum present */ uint64_t minv, - - int maxp, + int maxp, /* Maximum present */ uint64_t maxv) { char *data = NULL; if (strpbrk (label, "'= ")) - xasprintf (&data, "'%s'=%ld%s", label, val, uom); + xasprintf (&data, "'%s'=%ld%s;", label, val, uom); else - xasprintf (&data, "%s=%ld%s", label, val, uom); - xasprintf (&data, "%s;", data); + xasprintf (&data, "%s=%ld%s;", label, val, uom); if (warnp) - xasprintf (&data, "%s%lu", data, warn); - xasprintf (&data, "%s;", data); + xasprintf (&data, "%s%lu;", data, warn); + else + xasprintf (&data, "%s;", data); if (critp) - xasprintf (&data, "%s%lu", data, crit); - xasprintf (&data, "%s;", data); + xasprintf (&data, "%s%lu;", data, crit); + else + xasprintf (&data, "%s;", data); if (minp) - xasprintf (&data, "%s%lu", data, minv); - xasprintf (&data, "%s;", data); + xasprintf (&data, "%s%lu;", data, minv); + else + xasprintf (&data, "%s;", data); if (maxp) - xasprintf (&data, "%s;%lu", data, maxv); + xasprintf (&data, "%s%lu", data, maxv); return data; } @@ -644,37 +642,39 @@ char *perfdata_uint64 (const char *label, char *perfdata_int64 (const char *label, int64_t val, const char *uom, - int warnp, + int warnp, /* Warning present */ int64_t warn, - int critp, + int critp, /* Critical present */ int64_t crit, - int minp, + int minp, /* Minimum present */ int64_t minv, - int maxp, + int maxp, /* Maximum present */ int64_t maxv) { char *data = NULL; if (strpbrk (label, "'= ")) - xasprintf (&data, "'%s'=%ld%s", label, val, uom); + xasprintf (&data, "'%s'=%ld%s;", label, val, uom); else - xasprintf (&data, "%s=%ld%s", label, val, uom); - xasprintf (&data, "%s;", data); + xasprintf (&data, "%s=%ld%s;", label, val, uom); if (warnp) - xasprintf (&data, "%s%ld", data, warn); - xasprintf (&data, "%s;", data); + xasprintf (&data, "%s%ld;", data, warn); + else + xasprintf (&data, "%s;", data); if (critp) - xasprintf (&data, "%s%ld", data, crit); - xasprintf (&data, "%s;", data); + xasprintf (&data, "%s%ld;", data, crit); + else + xasprintf (&data, "%s;", data); if (minp) - xasprintf (&data, "%s%ld", data, minv); - xasprintf (&data, "%s;", data); + xasprintf (&data, "%s%ld;", data, minv); + else + xasprintf (&data, "%s;", data); if (maxp) - xasprintf (&data, "%s;%ld", data, maxv); + xasprintf (&data, "%s%ld", data, maxv); return data; } -- cgit v0.10-9-g596f From 5974b0481c280d8de9c52ff2d7b99fcf4be99b5d Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Wed, 27 Oct 2021 12:44:21 +0200 Subject: Remove whitespace at the end of lines diff --git a/plugins/check_disk.c b/plugins/check_disk.c index 71eab53..cc6dbb7 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c @@ -1,29 +1,29 @@ /***************************************************************************** -* +* * Monitoring check_disk plugin -* +* * License: GPL * Copyright (c) 1999-2008 Monitoring Plugins Development Team -* +* * Description: -* +* * This file contains the check_disk plugin -* -* +* +* * 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 . -* -* +* +* *****************************************************************************/ const char *progname = "check_disk"; @@ -253,7 +253,7 @@ main (int argc, char **argv) /* Remove filesystems already seen */ if (np_seen_name(seen, me->me_mountdir)) { continue; - } + } np_add_name(&seen, me->me_mountdir); if (path->group == NULL) { @@ -1039,20 +1039,20 @@ get_stats (struct parameter_list *p, struct fs_usage *fsp) { if (p_list->group && ! (strcmp(p_list->group, p->group))) { stat_path(p_list); get_fs_usage (p_list->best_match->me_mountdir, p_list->best_match->me_devname, &tmpfsp); - get_path_stats(p_list, &tmpfsp); + get_path_stats(p_list, &tmpfsp); if (verbose >= 3) printf("Group %s: adding %llu blocks sized %llu, (%s) used_units=%g free_units=%g total_units=%g fsu_blocksize=%llu mult=%llu\n", p_list->group, tmpfsp.fsu_bavail, tmpfsp.fsu_blocksize, p_list->best_match->me_mountdir, p_list->dused_units, p_list->dfree_units, p_list->dtotal_units, mult); - /* prevent counting the first FS of a group twice since its parameter_list entry + /* prevent counting the first FS of a group twice since its parameter_list entry * is used to carry the information of all file systems of the entire group */ if (! first) { p->total += p_list->total; p->available += p_list->available; p->available_to_root += p_list->available_to_root; p->used += p_list->used; - + p->dused_units += p_list->dused_units; p->dfree_units += p_list->dfree_units; p->dtotal_units += p_list->dtotal_units; @@ -1063,7 +1063,7 @@ get_stats (struct parameter_list *p, struct fs_usage *fsp) { } first = 0; } - if (verbose >= 3) + if (verbose >= 3) printf("Group %s now has: used_units=%g free_units=%g total_units=%g fsu_blocksize=%llu mult=%llu\n", p->group, tmpfsp.fsu_bavail, @@ -1082,7 +1082,7 @@ get_stats (struct parameter_list *p, struct fs_usage *fsp) { p->dfree_pct = 100 - p->dused_pct; p->dused_inodes_percent = calculate_percent(p->inodes_total - p->inodes_free, p->inodes_total); p->dfree_inodes_percent = 100 - p->dused_inodes_percent; - + } void @@ -1097,7 +1097,7 @@ get_path_stats (struct parameter_list *p, struct fs_usage *fsp) { /* default behaviour : take all the blocks into account */ p->total = fsp->fsu_blocks; } - + p->dused_units = p->used*fsp->fsu_blocksize/mult; p->dfree_units = p->available*fsp->fsu_blocksize/mult; p->dtotal_units = p->total*fsp->fsu_blocksize/mult; -- cgit v0.10-9-g596f From 884327ee21b25be3ce1b5627bb40339e14545256 Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Wed, 27 Oct 2021 12:47:08 +0200 Subject: Replace tabs with spaces and do some formatting diff --git a/plugins/check_disk.c b/plugins/check_disk.c index cc6dbb7..c526d05 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c @@ -46,7 +46,7 @@ const char *email = "devel@monitoring-plugins.org"; #include #include "fsusage.h" #include "mountlist.h" -#include "intprops.h" /* necessary for TYPE_MAXIMUM */ +#include "intprops.h" /* necessary for TYPE_MAXIMUM */ #if HAVE_LIMITS_H # include #endif @@ -243,10 +243,10 @@ main (int argc, char **argv) #ifdef __CYGWIN__ if (strncmp(path->name, "/cygdrive/", 10) != 0 || strlen(path->name) > 11) - continue; + continue; snprintf(mountdir, sizeof(mountdir), "%s:\\", me->me_mountdir + 10); if (GetDriveType(mountdir) != DRIVE_FIXED) - me->me_remote = 1; + me->me_remote = 1; #endif /* Filters */ @@ -287,16 +287,16 @@ main (int argc, char **argv) if (verbose >= 3) { printf ("For %s, used_pct=%g free_pct=%g used_units=%llu free_units=%llu total_units=%llu used_inodes_pct=%g free_inodes_pct=%g fsp.fsu_blocksize=%llu mult=%llu\n", - me->me_mountdir, - path->dused_pct, - path->dfree_pct, - path->dused_units, - path->dfree_units, - path->dtotal_units, - path->dused_inodes_percent, - path->dfree_inodes_percent, - fsp.fsu_blocksize, - mult); + me->me_mountdir, + path->dused_pct, + path->dfree_pct, + path->dused_units, + path->dfree_units, + path->dtotal_units, + path->dused_inodes_percent, + path->dfree_inodes_percent, + fsp.fsu_blocksize, + mult); } /* Threshold comparisons */ @@ -333,7 +333,7 @@ main (int argc, char **argv) */ /* *_high_tide must be reinitialized at each run */ - uint64_t warning_high_tide = UINT64_MAX; + uint64_t warning_high_tide = UINT64_MAX; if (path->freespace_units->warning != NULL) { warning_high_tide = (path->dtotal_units - path->freespace_units->warning->end) * mult; @@ -342,7 +342,7 @@ main (int argc, char **argv) warning_high_tide = min( warning_high_tide, (uint64_t)((1.0 - path->freespace_percent->warning->end/100) * (path->dtotal_units * mult)) ); } - uint64_t critical_high_tide = UINT64_MAX; + uint64_t critical_high_tide = UINT64_MAX; if (path->freespace_units->critical != NULL) { critical_high_tide = (path->dtotal_units - path->freespace_units->critical->end) * mult; @@ -353,13 +353,13 @@ main (int argc, char **argv) /* Nb: *_high_tide are unset when == UINT64_MAX */ xasprintf (&perf, "%s %s", perf, - perfdata_uint64 ( - (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir, - path->dused_units * mult, "B", - (warning_high_tide == UINT64_MAX ? FALSE : TRUE), warning_high_tide, - (critical_high_tide == UINT64_MAX ? FALSE : TRUE), critical_high_tide, - TRUE, 0, - TRUE, path->dtotal_units * mult)); + perfdata_uint64 ( + (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir, + path->dused_units * mult, "B", + (warning_high_tide == UINT64_MAX ? FALSE : TRUE), warning_high_tide, + (critical_high_tide == UINT64_MAX ? FALSE : TRUE), critical_high_tide, + TRUE, 0, + TRUE, path->dtotal_units * mult)); if (display_inodes_perfdata) { /* *_high_tide must be reinitialized at each run */ @@ -376,37 +376,36 @@ main (int argc, char **argv) xasprintf (&perf_ilabel, "%s (inodes)", (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir); /* Nb: *_high_tide are unset when == UINT64_MAX */ xasprintf (&perf, "%s %s", perf, - perfdata_uint64 (perf_ilabel, - path->inodes_used, "", - (warning_high_tide != UINT64_MAX ? TRUE : FALSE), warning_high_tide, - (critical_high_tide != UINT64_MAX ? TRUE : FALSE), critical_high_tide, - TRUE, 0, - TRUE, path->inodes_total)); + perfdata_uint64 (perf_ilabel, + path->inodes_used, "", + (warning_high_tide != UINT64_MAX ? TRUE : FALSE), warning_high_tide, + (critical_high_tide != UINT64_MAX ? TRUE : FALSE), critical_high_tide, + TRUE, 0, + TRUE, path->inodes_total)); } if (disk_result==STATE_OK && erronly && !verbose) continue; - if(disk_result && verbose >= 1) { - xasprintf(&flag_header, " %s [", state_text (disk_result)); - } else { - xasprintf(&flag_header, ""); - } - xasprintf (&output, "%s%s %s %llu%s (%.0f%%", - output, flag_header, - (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir, - path->dfree_units, - units, - path->dfree_pct); - if (path->dused_inodes_percent < 0) { - xasprintf(&output, "%s inode=-)%s;", output, (disk_result ? "]" : "")); - } else { - xasprintf(&output, "%s inode=%.0f%%)%s;", output, path->dfree_inodes_percent, ((disk_result && verbose >= 1) ? "]" : "")); - } + if(disk_result && verbose >= 1) { + xasprintf(&flag_header, " %s [", state_text (disk_result)); + } else { + xasprintf(&flag_header, ""); + } + xasprintf (&output, "%s%s %s %llu%s (%.0f%%", + output, flag_header, + (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir, + path->dfree_units, + units, + path->dfree_pct); + if (path->dused_inodes_percent < 0) { + xasprintf(&output, "%s inode=-)%s;", output, (disk_result ? "]" : "")); + } else { + xasprintf(&output, "%s inode=%.0f%%)%s;", output, path->dfree_inodes_percent, ((disk_result && verbose >= 1) ? "]" : "")); + } free(flag_header); /* TODO: Need to do a similar debug line - xasprintf (&details, _("%s\n\ -%.0f of %.0f %s (%.0f%% inode=%.0f%%) free on %s (type %s mounted on %s) warn:%lu crit:%lu warn%%:%.0f%% crit%%:%.0f%%"), + xasprintf (&details, _("%s\n\%.0f of %.0f %s (%.0f%% inode=%.0f%%) free on %s (type %s mounted on %s) warn:%lu crit:%lu warn%%:%.0f%% crit%%:%.0f%%"), details, dfree_units, dtotal_units, units, dfree_pct, inode_space_pct, me->me_devname, me->me_type, me->me_mountdir, (unsigned long)w_df, (unsigned long)c_df, w_dfp, c_dfp); @@ -567,14 +566,14 @@ process_arguments (int argc, char **argv) } break; - case 'W': /* warning inode threshold */ + case 'W': /* warning inode threshold */ if (*optarg == '@') { warn_freeinodes_percent = optarg; } else { xasprintf(&warn_freeinodes_percent, "@%s", optarg); } break; - case 'K': /* critical inode threshold */ + case 'K': /* critical inode threshold */ if (*optarg == '@') { crit_freeinodes_percent = optarg; } else { @@ -1066,19 +1065,19 @@ get_stats (struct parameter_list *p, struct fs_usage *fsp) { if (verbose >= 3) printf("Group %s now has: used_units=%g free_units=%g total_units=%g fsu_blocksize=%llu mult=%llu\n", p->group, - tmpfsp.fsu_bavail, - tmpfsp.fsu_blocksize, - p->best_match->me_mountdir, - p->dused_units, + tmpfsp.fsu_bavail, + tmpfsp.fsu_blocksize, + p->best_match->me_mountdir, + p->dused_units, p->dfree_units, - p->dtotal_units, - mult); + p->dtotal_units, + mult); } /* modify devname and mountdir for output */ p->best_match->me_mountdir = p->best_match->me_devname = p->group; } /* finally calculate percentages for either plain FS or summed up group */ - p->dused_pct = calculate_percent( p->used, p->used + p->available ); /* used + available can never be > uintmax */ + p->dused_pct = calculate_percent( p->used, p->used + p->available ); /* used + available can never be > uintmax */ p->dfree_pct = 100 - p->dused_pct; p->dused_inodes_percent = calculate_percent(p->inodes_total - p->inodes_free, p->inodes_total); p->dfree_inodes_percent = 100 - p->dused_inodes_percent; -- cgit v0.10-9-g596f From 0bd45c200b64de1918ad4546e09083c529ea39a3 Mon Sep 17 00:00:00 2001 From: Geert Hendrickx Date: Thu, 28 Oct 2021 23:08:02 +0200 Subject: check_smtp: add -L flag to support LMTP (LHLO instead of HELO/EHLO). diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c index d37c57c..c1e92df 100644 --- a/plugins/check_smtp.c +++ b/plugins/check_smtp.c @@ -55,6 +55,7 @@ enum { #define SMTP_EXPECT "220" #define SMTP_HELO "HELO " #define SMTP_EHLO "EHLO " +#define SMTP_LHLO "LHLO " #define SMTP_QUIT "QUIT\r\n" #define SMTP_STARTTLS "STARTTLS\r\n" #define SMTP_AUTH_LOGIN "AUTH LOGIN\r\n" @@ -102,6 +103,7 @@ int check_critical_time = FALSE; int verbose = 0; int use_ssl = FALSE; short use_ehlo = FALSE; +short use_lhlo = FALSE; short ssl_established = 0; char *localhostname = NULL; int sd; @@ -152,7 +154,9 @@ main (int argc, char **argv) return STATE_CRITICAL; } } - if(use_ehlo) + if(use_lhlo) + xasprintf (&helocmd, "%s%s%s", SMTP_LHLO, localhostname, "\r\n"); + else if(use_ehlo) xasprintf (&helocmd, "%s%s%s", SMTP_EHLO, localhostname, "\r\n"); else xasprintf (&helocmd, "%s%s%s", SMTP_HELO, localhostname, "\r\n"); @@ -197,7 +201,7 @@ main (int argc, char **argv) if (recvlines(buffer, MAX_INPUT_BUFFER) <= 0) { printf (_("recv() failed\n")); return STATE_WARNING; - } else if(use_ehlo){ + } else if(use_ehlo || use_lhlo){ if(strstr(buffer, "250 STARTTLS") != NULL || strstr(buffer, "250-STARTTLS") != NULL){ supports_tls=TRUE; @@ -470,6 +474,7 @@ process_arguments (int argc, char **argv) {"use-ipv4", no_argument, 0, '4'}, {"use-ipv6", no_argument, 0, '6'}, {"help", no_argument, 0, 'h'}, + {"lmtp", no_argument, 0, 'L'}, {"starttls",no_argument,0,'S'}, {"certificate",required_argument,0,'D'}, {"ignore-quit-failure",no_argument,0,'q'}, @@ -489,7 +494,7 @@ process_arguments (int argc, char **argv) } while (1) { - c = getopt_long (argc, argv, "+hVv46t:p:f:e:c:w:H:C:R:SD:F:A:U:P:q", + c = getopt_long (argc, argv, "+hVv46Lt:p:f:e:c:w:H:C:R:SD:F:A:U:P:q", longopts, &option); if (c == -1 || c == EOF) @@ -616,6 +621,9 @@ process_arguments (int argc, char **argv) use_ssl = TRUE; use_ehlo = TRUE; break; + case 'L': + use_lhlo = TRUE; + break; case '4': address_family = AF_INET; break; @@ -824,6 +832,8 @@ print_help (void) printf (" %s\n", _("SMTP AUTH username")); printf (" %s\n", "-P, --authpass=STRING"); printf (" %s\n", _("SMTP AUTH password")); + printf (" %s\n", "-L, --lmtp"); + printf (" %s\n", _("Send LHLO instead of HELO/EHLO")); printf (" %s\n", "-q, --ignore-quit-failure"); printf (" %s\n", _("Ignore failure when sending QUIT command to server")); @@ -850,6 +860,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] [-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]] [-v] \n"); } -- cgit v0.10-9-g596f From 1738d14c0cae83a24927f34e11a673c7e29baa04 Mon Sep 17 00:00:00 2001 From: Sven Nierlein Date: Mon, 25 Oct 2021 10:15:40 +0200 Subject: check_procs: remove trailing whitespace diff --git a/plugins/check_procs.c b/plugins/check_procs.c index f7917c3..bae429d 100644 --- a/plugins/check_procs.c +++ b/plugins/check_procs.c @@ -1,34 +1,34 @@ /***************************************************************************** -* +* * Monitoring check_procs plugin -* +* * License: GPL * Copyright (c) 2000-2008 Monitoring Plugins Development Team -* +* * Description: -* +* * This file contains the check_procs plugin -* +* * Checks all processes and generates WARNING or CRITICAL states if the * specified metric is outside the required threshold ranges. The metric * defaults to number of processes. Search filters can be applied to limit * the processes to check. -* -* +* +* * 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 . -* -* +* +* *****************************************************************************/ const char *progname = "check_procs"; @@ -50,7 +50,7 @@ const char *email = "devel@monitoring-plugins.org"; int process_arguments (int, char **); int validate_arguments (void); -int convert_to_seconds (char *); +int convert_to_seconds (char *); void print_help (void); void print_usage (void); @@ -230,9 +230,9 @@ main (int argc, char **argv) procseconds = convert_to_seconds(procetime); if (verbose >= 3) - printf ("proc#=%d uid=%d vsz=%d rss=%d pid=%d ppid=%d pcpu=%.2f stat=%s etime=%s prog=%s args=%s\n", + printf ("proc#=%d uid=%d vsz=%d rss=%d pid=%d ppid=%d pcpu=%.2f stat=%s etime=%s prog=%s args=%s\n", procs, procuid, procvsz, procrss, - procpid, procppid, procpcpu, procstat, + procpid, procppid, procpcpu, procstat, procetime, procprog, procargs); /* Ignore self */ @@ -292,9 +292,9 @@ main (int argc, char **argv) procs++; if (verbose >= 2) { - printf ("Matched: uid=%d vsz=%d rss=%d pid=%d ppid=%d pcpu=%.2f stat=%s etime=%s prog=%s args=%s\n", + printf ("Matched: uid=%d vsz=%d rss=%d pid=%d ppid=%d pcpu=%.2f stat=%s etime=%s prog=%s args=%s\n", procuid, procvsz, procrss, - procpid, procppid, procpcpu, procstat, + procpid, procppid, procpcpu, procstat, procetime, procprog, procargs); } @@ -320,7 +320,7 @@ main (int argc, char **argv) result = max_state (result, i); } } - } + } /* This should not happen */ else if (verbose) { printf(_("Not parseable: %s"), input_buffer); @@ -332,7 +332,7 @@ main (int argc, char **argv) return STATE_UNKNOWN; } - if ( result == STATE_UNKNOWN ) + if ( result == STATE_UNKNOWN ) result = STATE_OK; /* Needed if procs found, but none match filter */ @@ -352,9 +352,9 @@ main (int argc, char **argv) if (metric != METRIC_PROCS) { printf (_("%d crit, %d warn out of "), crit, warn); } - } + } printf (ngettext ("%d process", "%d processes", (unsigned long) procs), procs); - + if (strcmp(fmt,"") != 0) { printf (_(" with %s"), fmt); } @@ -440,7 +440,7 @@ process_arguments (int argc, char **argv) break; case 'c': /* critical threshold */ critical_range = optarg; - break; + break; case 'w': /* warning threshold */ warning_range = optarg; break; @@ -542,11 +542,11 @@ process_arguments (int argc, char **argv) if ( strcmp(optarg, "PROCS") == 0) { metric = METRIC_PROCS; break; - } + } else if ( strcmp(optarg, "VSZ") == 0) { metric = METRIC_VSZ; break; - } + } else if ( strcmp(optarg, "RSS") == 0 ) { metric = METRIC_RSS; break; @@ -559,7 +559,7 @@ process_arguments (int argc, char **argv) metric = METRIC_ELAPSED; break; } - + usage4 (_("Metric must be one of PROCS, VSZ, RSS, CPU, ELAPSED!")); case 'k': /* linux kernel thread filter */ kthread_filter = 1; @@ -642,7 +642,7 @@ convert_to_seconds(char *etime) { seconds = 0; for (ptr = etime; *ptr != '\0'; ptr++) { - + if (*ptr == '-') { hyphcnt++; continue; -- cgit v0.10-9-g596f From 282ccd4a8bbaa5d99c7c0cf6eba963ee3c0bff3a Mon Sep 17 00:00:00 2001 From: Sven Nierlein Date: Mon, 25 Oct 2021 17:28:17 +0200 Subject: check_procs: improve ps args autodetection one of the first ps commands in the configure.ac is `axwo 'stat comm vsz rss user uid pid ppid args'` which works on most modern linux systems (checked debian 10/11 and centos 7/8). But this test misses the etime argument. Therefore `check_procs --metric=ELAPSED` does not work. To fix this, we simply do the same test including etime before that one. Signed-off-by: Sven Nierlein diff --git a/configure.ac b/configure.ac index 7c17dcd..dfc37b5 100644 --- a/configure.ac +++ b/configure.ac @@ -783,6 +783,16 @@ dnl ac_cv_ps_format=["%*s %d %d %d %d %*d %*d %d %d%*[ 0123456789abcdef]%[OSRZT dnl ac_cv_ps_cols=8 dnl AC_MSG_RESULT([$ac_cv_ps_command]) +dnl This one is the exact same test as the next one but includes etime +elif ps axwo 'stat comm vsz rss user uid pid ppid etime args' 2>/dev/null | \ + egrep -i ["^ *STAT +[UCOMAND]+ +VSZ +RSS +USER +UID +PID +PPID +ELAPSED +COMMAND"] > /dev/null +then + ac_cv_ps_varlist="[procstat,&procuid,&procpid,&procppid,&procvsz,&procrss,&procpcpu,procetime,procprog,&pos]" + ac_cv_ps_command="$PATH_TO_PS axwo 'stat uid pid ppid vsz rss pcpu etime comm args'" + ac_cv_ps_format="%s %d %d %d %d %d %f %s %s %n" + ac_cv_ps_cols=10 + AC_MSG_RESULT([$ac_cv_ps_command]) + dnl Some gnu/linux systems (debian for one) don't like -axwo and need axwo. dnl so test for this first... elif ps axwo 'stat comm vsz rss user uid pid ppid args' 2>/dev/null | \ diff --git a/plugins/tests/check_procs.t b/plugins/tests/check_procs.t index 54d43d9..7f612e8 100755 --- a/plugins/tests/check_procs.t +++ b/plugins/tests/check_procs.t @@ -69,9 +69,13 @@ SKIP: { like( $result->output, '/^PROCS OK: 0 processes with UID = -2 \(nobody\), args \'UsB\'/', "Output correct" ); }; -$result = NPTest->testCmd( "$command --ereg-argument-array='mdworker.*501'" ); -is( $result->return_code, 0, "Checking regexp search of arguments" ); -is( $result->output, "PROCS OK: 1 process with regex args 'mdworker.*501' | procs=1;;;0;", "Output correct" ); +SKIP: { + skip 'check_procs is compiled with etime format support', 2 if `$command -vvv` =~ m/etime/mx; + + $result = NPTest->testCmd( "$command --ereg-argument-array='mdworker.*501'" ); + is( $result->return_code, 0, "Checking regexp search of arguments" ); + is( $result->output, "PROCS OK: 1 process with regex args 'mdworker.*501' | procs=1;;;0;", "Output correct" ); +} $result = NPTest->testCmd( "$command --vsz 1000000" ); is( $result->return_code, 0, "Checking filter by VSZ" ); @@ -129,4 +133,3 @@ is( $result->output, 'RSS CRITICAL: 5 crit, 0 warn out of 95 processes [WindowSe $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)' | procs=0;;;0;", "Output correct" ); - -- cgit v0.10-9-g596f From 1fda28f12424be232ac88399e72e95c2bc2d5421 Mon Sep 17 00:00:00 2001 From: Sven Nierlein Date: Tue, 26 Oct 2021 11:16:38 +0200 Subject: remove unused test file Signed-off-by: Sven Nierlein diff --git a/plugins/tests/var/ps_axwo.debian b/plugins/tests/var/ps_axwo.debian deleted file mode 100644 index 37a2d35..0000000 --- a/plugins/tests/var/ps_axwo.debian +++ /dev/null @@ -1,84 +0,0 @@ -STAT UID PID PPID VSZ RSS %CPU COMMAND COMMAND -S 0 1 0 1504 428 0.0 init init [2] -SN 0 2 1 0 0 0.0 ksoftirqd/0 [ksoftirqd/0] -S< 0 3 1 0 0 0.0 events/0 [events/0] -S< 0 4 3 0 0 0.0 khelper [khelper] -S< 0 5 3 0 0 0.0 kacpid [kacpid] -S< 0 38 3 0 0 0.0 kblockd/0 [kblockd/0] -S 0 48 3 0 0 0.0 pdflush [pdflush] -S< 0 51 3 0 0 0.0 aio/0 [aio/0] -S 0 50 1 0 0 0.0 kswapd0 [kswapd0] -S 0 193 1 0 0 0.0 kseriod [kseriod] -S 0 214 1 0 0 0.0 scsi_eh_0 [scsi_eh_0] -S 0 221 1 0 0 0.0 khubd [khubd] -S 0 299 1 0 0 0.3 kjournald [kjournald] -S 0 1148 1 0 0 0.0 pciehpd_event [pciehpd_event] -S 0 1168 1 0 0 0.0 shpchpd_event [shpchpd_event] -Ss 1 1795 1 1612 276 0.0 portmap /sbin/portmap -Ss 0 2200 1 1652 568 0.0 vmware-guestd /usr/sbin/vmware-guestd --background /var/run/vmware-guestd.pid -Ss 0 2209 1 2240 532 0.0 inetd /usr/sbin/inetd -Ss 0 2319 1 3468 792 0.0 sshd /usr/sbin/sshd -Ss 0 2323 1 2468 676 0.0 rpc.statd /sbin/rpc.statd -Ss 1 2332 1 1684 488 0.0 atd /usr/sbin/atd -Ss 0 2335 1 1764 636 0.0 cron /usr/sbin/cron -Ss+ 0 2350 1 1500 348 0.0 getty /sbin/getty 38400 tty1 -Ss+ 0 2351 1 1500 348 0.0 getty /sbin/getty 38400 tty2 -Ss+ 0 2352 1 1500 348 0.0 getty /sbin/getty 38400 tty3 -Ss+ 0 2353 1 1500 348 0.0 getty /sbin/getty 38400 tty4 -Ss+ 0 2354 1 1500 348 0.0 getty /sbin/getty 38400 tty5 -Ss+ 0 2355 1 1500 348 0.0 getty /sbin/getty 38400 tty6 -S 0 6907 1 2308 892 0.0 mysqld_safe /bin/sh /usr/bin/mysqld_safe -S 103 6944 6907 123220 27724 0.0 mysqld /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-file=/var/run/mysqld/mysqld.pid --skip-locking --port=3306 --socket=/var/run/mysqld/mysqld.sock -S 0 6945 6907 1488 420 0.0 logger logger -p daemon.err -t mysqld_safe -i -t mysqld -S 1001 17778 1 6436 1588 0.0 snmpd /usr/sbin/snmpd -u nagios -Lsd -Lf /dev/null -p/var/run/snmpd.pid -Ss 0 17789 1 9496 5556 0.0 snmptrapd /usr/sbin/snmptrapd -t -m ALL -M /usr/share/snmp/mibs:/usr/local/monitoring/snmp/load -p /var/run/snmptrapd.pid -Ss 0 847 2319 14452 1752 0.0 sshd sshd: tonvoon [priv] -S 1000 857 847 14616 1832 0.0 sshd sshd: tonvoon@pts/3 -Ss 1000 860 857 2984 1620 0.0 bash -bash -S 0 868 860 2588 1428 0.0 bash -su -S+ 1001 877 868 2652 1568 0.0 bash -su -S 0 6086 3 0 0 0.0 pdflush [pdflush] -Ss 0 17832 2319 14452 1752 0.0 sshd sshd: tonvoon [priv] -S 1000 18155 17832 14620 1840 0.0 sshd sshd: tonvoon@pts/0 -Ss 1000 18156 18155 2984 1620 0.0 bash -bash -S 0 18518 18156 2588 1428 0.0 bash -su -S 1001 18955 18518 2672 1600 0.0 bash -su -Ss 0 21683 2319 14452 1756 0.0 sshd sshd: tonvoon [priv] -S 1000 21742 21683 14620 1896 0.0 sshd sshd: tonvoon@pts/1 -Ss 1000 21743 21742 2984 1620 0.0 bash -bash -S 0 21748 21743 2592 1432 0.0 bash -su -S 1001 21757 21748 2620 1540 0.0 bash -su -Ss 0 2334 2319 14452 1756 0.0 sshd sshd: tonvoon [priv] -S 1000 2343 2334 14620 1840 0.0 sshd sshd: tonvoon@pts/2 -Ss 1000 2344 2343 2984 1620 0.0 bash -bash -S 0 2349 2344 2592 1432 0.0 bash -su -S+ 1001 2364 2349 2620 1520 0.0 bash -su -T 1001 2454 2364 2096 1032 0.0 vi vi configure.in.rej -S+ 1001 8500 21757 69604 52576 0.0 opsview_web_ser /usr/bin/perl -w ./script/opsview_web_server.pl -f -d -Ss 0 7609 2319 14452 1756 0.0 sshd sshd: tonvoon [priv] -S 1000 7617 7609 14460 1828 0.0 sshd sshd: tonvoon@pts/4 -Ss 1000 7618 7617 2984 1620 0.0 bash -bash -S 0 7623 7618 2592 1432 0.0 bash -su -S+ 1001 7632 7623 2620 1528 0.0 bash -su -Ss 1001 12678 1 20784 17728 0.0 opsviewd opsviewd -Ss 0 832 1 14512 6360 0.0 apache2 /usr/sbin/apache2 -k start -DSSL -S 33 842 832 14648 6596 0.0 apache2 /usr/sbin/apache2 -k start -DSSL -S 33 843 832 14512 6504 0.0 apache2 /usr/sbin/apache2 -k start -DSSL -S 33 844 832 14512 6476 0.0 apache2 /usr/sbin/apache2 -k start -DSSL -S 33 845 832 14512 6476 0.0 apache2 /usr/sbin/apache2 -k start -DSSL -S 33 846 832 14512 6476 0.0 apache2 /usr/sbin/apache2 -k start -DSSL -Ss 7 4081 1 2464 884 0.0 lpd /usr/sbin/lpd -s -S 33 26484 832 14512 6476 0.0 apache2 /usr/sbin/apache2 -k start -DSSL -Ss 1001 22324 1 20252 1612 0.1 nagios ../../bin/nagios -d /usr/local/nagios/etc/nagios.cfg -Ss 0 23336 2319 14452 1756 0.0 sshd sshd: tonvoon [priv] -S 1000 23339 23336 14620 1840 0.0 sshd sshd: tonvoon@pts/5 -Ss 1000 23340 23339 2996 1636 0.0 bash -bash -S 0 23367 23340 3020 1628 0.0 bash bash -S 1001 23370 23367 3064 1748 0.0 bash bash -Ss 1001 23783 1 3220 764 0.0 ndo2db /usr/local/nagios/bin/ndo2db -c /usr/local/nagios/etc/ndo2db.cfg -Ss 1001 23784 1 6428 4948 0.0 import_ndologsd import_ndologsd -S+ 1001 9803 18955 4132 1936 0.0 ssh ssh altinity@cube02.lei.altinity -S 1001 22505 22324 20256 1616 0.0 nagios ../../bin/nagios -d /usr/local/nagios/etc/nagios.cfg -S 1001 22506 22505 1676 608 0.0 check_ping /usr/local/libexec/check_ping -H 192.168.10.23 -w 3000.0,80% -c 5000.0,100% -p 1 -S 1001 22507 22506 1660 492 0.0 ping /bin/ping -n -U -w 10 -c 1 192.168.10.23 -R+ 1001 22508 23370 2308 680 0.0 ps ps axwo stat uid pid ppid vsz rss pcpu comm args -- cgit v0.10-9-g596f From c3abdb9267567ac9b40ef4a8f3b585c7ab87bac6 Mon Sep 17 00:00:00 2001 From: Sven Nierlein Date: Tue, 26 Oct 2021 13:34:02 +0200 Subject: check_procs: add test for elapsed time diff --git a/plugins/tests/check_procs.t b/plugins/tests/check_procs.t index 7f612e8..fcea404 100755 --- a/plugins/tests/check_procs.t +++ b/plugins/tests/check_procs.t @@ -8,13 +8,14 @@ use Test::More; use NPTest; if (-x "./check_procs") { - plan tests => 50; + plan tests => 52; } else { plan skip_all => "No check_procs compiled"; } my $result; -my $command = "./check_procs --input-file=tests/var/ps-axwo.darwin"; +my $command = "./check_procs --input-file=tests/var/ps-axwo.darwin"; +my $cmd_etime = "./check_procs --input-file=tests/var/ps-axwo.debian"; $result = NPTest->testCmd( "$command" ); is( $result->return_code, 0, "Run with no options" ); @@ -77,6 +78,14 @@ SKIP: { is( $result->output, "PROCS OK: 1 process with regex args 'mdworker.*501' | procs=1;;;0;", "Output correct" ); } +SKIP: { + skip 'check_procs is compiled without etime format support', 2 if `$cmd_etime -vvv` !~ m/etime/mx; + + $result = NPTest->testCmd( "$cmd_etime -m ELAPSED -C apache2 -w 1000 -c 2000" ); + is( $result->return_code, 2, "Checking elapsed time threshold" ); + is( $result->output, "ELAPSED CRITICAL: 10 crit, 0 warn out of 10 processes with command name 'apache2' | procs=10;;;0; procs_warn=0;;;0; procs_crit=10;;;0;", "Output correct" ); +} + $result = NPTest->testCmd( "$command --vsz 1000000" ); is( $result->return_code, 0, "Checking filter by VSZ" ); is( $result->output, 'PROCS OK: 24 processes with VSZ >= 1000000 | procs=24;;;0;', "Output correct" ); diff --git a/plugins/tests/var/ps-axwo.debian b/plugins/tests/var/ps-axwo.debian new file mode 100644 index 0000000..5889e9a --- /dev/null +++ b/plugins/tests/var/ps-axwo.debian @@ -0,0 +1,219 @@ +STAT UID PID PPID VSZ RSS %CPU ELAPSED COMMAND COMMAND +Ss 0 1 0 167244 7144 0.1 26-03:07:26 systemd /lib/systemd/systemd --system --deserialize 17 +S 0 2 0 0 0 0.0 26-03:07:26 kthreadd [kthreadd] +I< 0 3 2 0 0 0.0 26-03:07:26 rcu_gp [rcu_gp] +I< 0 4 2 0 0 0.0 26-03:07:26 rcu_par_gp [rcu_par_gp] +I< 0 6 2 0 0 0.0 26-03:07:26 kworker/0:0H-ev [kworker/0:0H-events_highpri] +I< 0 9 2 0 0 0.0 26-03:07:26 mm_percpu_wq [mm_percpu_wq] +S 0 10 2 0 0 0.0 26-03:07:26 rcu_tasks_rude_ [rcu_tasks_rude_] +S 0 11 2 0 0 0.0 26-03:07:26 rcu_tasks_trace [rcu_tasks_trace] +S 0 12 2 0 0 0.0 26-03:07:26 ksoftirqd/0 [ksoftirqd/0] +I 0 13 2 0 0 0.0 26-03:07:26 rcu_sched [rcu_sched] +S 0 14 2 0 0 0.0 26-03:07:26 migration/0 [migration/0] +S 0 15 2 0 0 0.0 26-03:07:26 cpuhp/0 [cpuhp/0] +S 0 16 2 0 0 0.0 26-03:07:26 cpuhp/1 [cpuhp/1] +S 0 17 2 0 0 0.0 26-03:07:26 migration/1 [migration/1] +S 0 18 2 0 0 0.0 26-03:07:26 ksoftirqd/1 [ksoftirqd/1] +I< 0 20 2 0 0 0.0 26-03:07:26 kworker/1:0H-ev [kworker/1:0H-events_highpri] +S 0 21 2 0 0 0.0 26-03:07:26 cpuhp/2 [cpuhp/2] +S 0 22 2 0 0 0.0 26-03:07:26 migration/2 [migration/2] +S 0 23 2 0 0 0.0 26-03:07:26 ksoftirqd/2 [ksoftirqd/2] +I< 0 25 2 0 0 0.0 26-03:07:26 kworker/2:0H-ev [kworker/2:0H-events_highpri] +S 0 26 2 0 0 0.0 26-03:07:26 cpuhp/3 [cpuhp/3] +S 0 27 2 0 0 0.0 26-03:07:26 migration/3 [migration/3] +S 0 28 2 0 0 0.0 26-03:07:26 ksoftirqd/3 [ksoftirqd/3] +I< 0 30 2 0 0 0.0 26-03:07:26 kworker/3:0H-ev [kworker/3:0H-events_highpri] +S 0 35 2 0 0 0.0 26-03:07:26 kdevtmpfs [kdevtmpfs] +I< 0 36 2 0 0 0.0 26-03:07:26 netns [netns] +S 0 37 2 0 0 0.0 26-03:07:26 kauditd [kauditd] +S 0 38 2 0 0 0.0 26-03:07:26 khungtaskd [khungtaskd] +S 0 39 2 0 0 0.0 26-03:07:26 oom_reaper [oom_reaper] +I< 0 40 2 0 0 0.0 26-03:07:26 writeback [writeback] +S 0 41 2 0 0 0.0 26-03:07:26 kcompactd0 [kcompactd0] +SN 0 42 2 0 0 0.0 26-03:07:26 ksmd [ksmd] +SN 0 43 2 0 0 0.0 26-03:07:26 khugepaged [khugepaged] +I< 0 62 2 0 0 0.0 26-03:07:26 kintegrityd [kintegrityd] +I< 0 63 2 0 0 0.0 26-03:07:26 kblockd [kblockd] +I< 0 64 2 0 0 0.0 26-03:07:26 blkcg_punt_bio [blkcg_punt_bio] +I< 0 65 2 0 0 0.0 26-03:07:26 edac-poller [edac-poller] +I< 0 66 2 0 0 0.0 26-03:07:26 devfreq_wq [devfreq_wq] +I< 0 67 2 0 0 0.0 26-03:07:26 kworker/2:1H-ev [kworker/2:1H-events_highpri] +S 0 70 2 0 0 0.3 26-03:07:25 kswapd0 [kswapd0] +I< 0 71 2 0 0 0.0 26-03:07:25 kthrotld [kthrotld] +I< 0 72 2 0 0 0.0 26-03:07:25 acpi_thermal_pm [acpi_thermal_pm] +I< 0 74 2 0 0 0.0 26-03:07:25 ipv6_addrconf [ipv6_addrconf] +I< 0 80 2 0 0 0.0 26-03:07:25 kworker/3:1H-ev [kworker/3:1H-events_highpri] +I< 0 84 2 0 0 0.0 26-03:07:25 kstrp [kstrp] +I< 0 87 2 0 0 0.0 26-03:07:25 zswap-shrink [zswap-shrink] +I< 0 110 2 0 0 0.0 26-03:07:25 kworker/0:1H-ev [kworker/0:1H-events_highpri] +I< 0 141 2 0 0 0.0 26-03:07:25 ata_sff [ata_sff] +S 0 143 2 0 0 0.0 26-03:07:25 scsi_eh_0 [scsi_eh_0] +I< 0 144 2 0 0 0.0 26-03:07:25 scsi_tmf_0 [scsi_tmf_0] +S 0 145 2 0 0 0.0 26-03:07:25 scsi_eh_1 [scsi_eh_1] +I< 0 146 2 0 0 0.0 26-03:07:25 scsi_tmf_1 [scsi_tmf_1] +S 0 147 2 0 0 0.0 26-03:07:25 scsi_eh_2 [scsi_eh_2] +I< 0 148 2 0 0 0.0 26-03:07:25 scsi_tmf_2 [scsi_tmf_2] +S 0 149 2 0 0 0.0 26-03:07:25 scsi_eh_3 [scsi_eh_3] +I< 0 150 2 0 0 0.0 26-03:07:25 scsi_tmf_3 [scsi_tmf_3] +S 0 151 2 0 0 0.0 26-03:07:25 scsi_eh_4 [scsi_eh_4] +I< 0 152 2 0 0 0.0 26-03:07:25 scsi_tmf_4 [scsi_tmf_4] +S 0 153 2 0 0 0.0 26-03:07:25 scsi_eh_5 [scsi_eh_5] +I< 0 154 2 0 0 0.0 26-03:07:25 scsi_tmf_5 [scsi_tmf_5] +S 0 158 2 0 0 0.0 26-03:07:25 card0-crtc0 [card0-crtc0] +S 0 159 2 0 0 0.0 26-03:07:25 card0-crtc1 [card0-crtc1] +S 0 160 2 0 0 0.0 26-03:07:25 card0-crtc2 [card0-crtc2] +I< 0 162 2 0 0 0.0 26-03:07:25 kworker/1:1H-ev [kworker/1:1H-events_highpri] +S 0 163 2 0 0 0.0 26-03:07:25 scsi_eh_6 [scsi_eh_6] +I< 0 164 2 0 0 0.0 26-03:07:25 scsi_tmf_6 [scsi_tmf_6] +S 0 165 2 0 0 0.0 26-03:07:25 usb-storage [usb-storage] +I< 0 167 2 0 0 0.0 26-03:07:25 uas [uas] +I< 0 176 2 0 0 0.0 26-03:07:25 kdmflush [kdmflush] +I< 0 177 2 0 0 0.0 26-03:07:25 kdmflush [kdmflush] +S 0 202 2 0 0 0.0 26-03:07:24 scsi_eh_7 [scsi_eh_7] +I< 0 203 2 0 0 0.0 26-03:07:24 scsi_tmf_7 [scsi_tmf_7] +S 0 204 2 0 0 0.0 26-03:07:24 usb-storage [usb-storage] +I< 0 232 2 0 0 0.0 26-03:07:23 btrfs-worker [btrfs-worker] +I< 0 233 2 0 0 0.0 26-03:07:23 btrfs-worker-hi [btrfs-worker-hi] +I< 0 234 2 0 0 0.0 26-03:07:23 btrfs-delalloc [btrfs-delalloc] +I< 0 235 2 0 0 0.0 26-03:07:23 btrfs-flush_del [btrfs-flush_del] +I< 0 236 2 0 0 0.0 26-03:07:23 btrfs-cache [btrfs-cache] +I< 0 237 2 0 0 0.0 26-03:07:23 btrfs-fixup [btrfs-fixup] +I< 0 238 2 0 0 0.0 26-03:07:23 btrfs-endio [btrfs-endio] +I< 0 239 2 0 0 0.0 26-03:07:23 btrfs-endio-met [btrfs-endio-met] +I< 0 240 2 0 0 0.0 26-03:07:23 btrfs-endio-met [btrfs-endio-met] +I< 0 241 2 0 0 0.0 26-03:07:23 btrfs-endio-rai [btrfs-endio-rai] +I< 0 242 2 0 0 0.0 26-03:07:23 btrfs-rmw [btrfs-rmw] +I< 0 243 2 0 0 0.0 26-03:07:23 btrfs-endio-wri [btrfs-endio-wri] +I< 0 244 2 0 0 0.0 26-03:07:23 btrfs-freespace [btrfs-freespace] +I< 0 245 2 0 0 0.0 26-03:07:23 btrfs-delayed-m [btrfs-delayed-m] +I< 0 246 2 0 0 0.0 26-03:07:23 btrfs-readahead [btrfs-readahead] +I< 0 247 2 0 0 0.0 26-03:07:23 btrfs-qgroup-re [btrfs-qgroup-re] +S 0 248 2 0 0 0.0 26-03:07:23 btrfs-cleaner [btrfs-cleaner] +S 0 249 2 0 0 0.2 26-03:07:23 btrfs-transacti [btrfs-transacti] +I< 0 317 2 0 0 0.0 26-03:07:22 rpciod [rpciod] +I< 0 322 2 0 0 0.0 26-03:07:22 xprtiod [xprtiod] +S 0 381 2 0 0 0.0 26-03:07:22 irq/133-mei_me [irq/133-mei_me] +S 0 422 2 0 0 0.0 26-03:07:22 watchdogd [watchdogd] +I< 0 523 2 0 0 0.0 26-03:07:22 led_workqueue [led_workqueue] +I< 0 583 2 0 0 0.0 26-03:07:22 cryptd [cryptd] +I< 0 590 2 0 0 0.0 26-03:07:22 ext4-rsv-conver [ext4-rsv-conver] +Ss 104 693 1 12324 4292 0.5 26-03:07:21 dbus-daemon /usr/bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation --syslog-only +Ss 0 731 1 575120 1368 0.0 26-03:07:21 systemd-logind /lib/systemd/systemd-logind +Ssl 0 1111 1 121248 732 0.0 26-03:07:18 unattended-upgr /usr/bin/python3 /usr/share/unattended-upgrades/unattended-upgrade-shutdown --wait-for-signal +S 0 1141 2 0 0 0.0 26-03:07:18 lockd [lockd] +I< 0 1459 2 0 0 0.0 26-03:07:16 nfsiod [nfsiod] +S 0 1621 2 0 0 0.0 26-03:07:15 NFSv4 callback [NFSv4 callback] +Ssl 0 1771 1 1548340 676 0.0 26-03:07:13 libvirtd /usr/sbin/libvirtd +I< 0 24315 2 0 0 0.0 26-02:49:02 cifsiod [cifsiod] +I< 0 24316 2 0 0 0.0 26-02:49:02 smb3decryptd [smb3decryptd] +I< 0 24317 2 0 0 0.0 26-02:49:02 cifsfileinfoput [cifsfileinfoput] +I< 0 24318 2 0 0 0.0 26-02:49:02 cifsoplockd [cifsoplockd] +I< 0 24319 2 0 0 0.0 26-02:49:02 cifs-dfscache [cifs-dfscache] +S 0 24322 2 0 0 0.0 26-02:49:02 cifsd [cifsd] +I< 0 24413 2 0 0 0.0 26-02:48:57 btrfs-worker [btrfs-worker] +I< 0 24414 2 0 0 0.0 26-02:48:57 btrfs-worker-hi [btrfs-worker-hi] +I< 0 24415 2 0 0 0.0 26-02:48:57 btrfs-delalloc [btrfs-delalloc] +I< 0 24416 2 0 0 0.0 26-02:48:57 btrfs-flush_del [btrfs-flush_del] +I< 0 24418 2 0 0 0.0 26-02:48:57 btrfs-cache [btrfs-cache] +I< 0 24419 2 0 0 0.0 26-02:48:57 btrfs-fixup [btrfs-fixup] +I< 0 24420 2 0 0 0.0 26-02:48:57 btrfs-endio [btrfs-endio] +I< 0 24421 2 0 0 0.0 26-02:48:57 btrfs-endio-met [btrfs-endio-met] +I< 0 24422 2 0 0 0.0 26-02:48:57 btrfs-endio-met [btrfs-endio-met] +I< 0 24423 2 0 0 0.0 26-02:48:57 btrfs-endio-rai [btrfs-endio-rai] +I< 0 24424 2 0 0 0.0 26-02:48:57 btrfs-rmw [btrfs-rmw] +I< 0 24425 2 0 0 0.0 26-02:48:57 btrfs-endio-wri [btrfs-endio-wri] +I< 0 24426 2 0 0 0.0 26-02:48:57 btrfs-freespace [btrfs-freespace] +I< 0 24427 2 0 0 0.0 26-02:48:57 btrfs-delayed-m [btrfs-delayed-m] +I< 0 24428 2 0 0 0.0 26-02:48:57 btrfs-readahead [btrfs-readahead] +I< 0 24429 2 0 0 0.0 26-02:48:57 btrfs-qgroup-re [btrfs-qgroup-re] +S 0 24450 2 0 0 0.0 26-02:48:53 btrfs-cleaner [btrfs-cleaner] +S 0 24451 2 0 0 0.0 26-02:48:53 btrfs-transacti [btrfs-transacti] +I< 0 747708 2 0 0 0.0 16-21:06:20 xfsalloc [xfsalloc] +I< 0 747709 2 0 0 0.0 16-21:06:20 xfs_mru_cache [xfs_mru_cache] +S 0 747713 2 0 0 0.0 16-21:06:20 jfsIO [jfsIO] +S 0 747714 2 0 0 0.0 16-21:06:20 jfsCommit [jfsCommit] +S 0 747715 2 0 0 0.0 16-21:06:20 jfsCommit [jfsCommit] +S 0 747716 2 0 0 0.0 16-21:06:20 jfsCommit [jfsCommit] +S 0 747717 2 0 0 0.0 16-21:06:20 jfsCommit [jfsCommit] +S 0 747718 2 0 0 0.0 16-21:06:20 jfsSync [jfsSync] +Ss 0 1071687 1 105976 28304 0.0 3-03:12:31 systemd-journal /lib/systemd/systemd-journald +Ss 0 1934146 1 25672 4704 0.0 11:19:31 cupsd /usr/sbin/cupsd -l +Ssl 0 1934148 1 182868 8540 0.0 11:19:31 cups-browsed /usr/sbin/cups-browsed +S 13 1934155 3392655 5752 88 0.0 11:19:31 pinger (pinger) +S< 33 1934166 3393034 57996 5460 0.0 11:19:31 apache2 /usr/sbin/apache2 -k start +S< 33 1934167 3393034 216944 13892 0.0 11:19:30 apache2 /usr/sbin/apache2 -k start +S< 33 1934168 3393034 216944 13756 0.0 11:19:30 apache2 /usr/sbin/apache2 -k start +S< 33 1934169 3393034 216936 13732 0.0 11:19:30 apache2 /usr/sbin/apache2 -k start +S< 33 1934170 3393034 216944 13888 0.0 11:19:30 apache2 /usr/sbin/apache2 -k start +S< 33 1934172 3393034 216944 15388 0.0 11:19:30 apache2 /usr/sbin/apache2 -k start +S< 33 1934701 3393034 216936 13736 0.0 11:19:29 apache2 /usr/sbin/apache2 -k start +S< 33 1935056 3393034 216920 13724 0.0 11:19:28 apache2 /usr/sbin/apache2 -k start +S 7 1936834 1934146 16652 832 0.0 11:18:12 dbus /usr/lib/cups/notifier/dbus dbus:// +S< 33 1955909 3393034 216928 13792 0.0 11:00:25 apache2 /usr/sbin/apache2 -k start +I< 0 2531464 2 0 0 0.0 06:35:47 kworker/u9:0-i9 [kworker/u9:0-i915_flip] +I 0 2570506 2 0 0 0.0 06:27:41 kworker/1:0-cgr [kworker/1:0-cgroup_destroy] +I 0 2596195 2 0 0 0.0 06:21:52 kworker/1:1-eve [kworker/1:1-events] +I 0 2785341 2 0 0 0.0 03:34:16 kworker/u8:8-bt [kworker/u8:8-btrfs-endio-write] +I 0 2785520 2 0 0 0.0 03:33:50 kworker/3:0-eve [kworker/3:0-events] +I 0 2798669 2 0 0 0.0 03:21:09 kworker/u8:5-bt [kworker/u8:5-btrfs-endio-write] +Ss 0 2803015 1 5616 3108 0.0 03:17:54 cron /usr/sbin/cron -f +I 0 2845483 2 0 0 0.0 02:38:11 kworker/0:3-eve [kworker/0:3-events] +I 0 2939490 2 0 0 0.1 01:10:32 kworker/0:0-eve [kworker/0:0-events] +I 0 2939754 2 0 0 0.0 01:10:26 kworker/u8:1-i9 [kworker/u8:1-i915] +I 0 2942040 2 0 0 0.0 01:08:02 kworker/u8:7-bt [kworker/u8:7-btrfs-endio-meta] +S 117 2954268 3392551 40044 5772 0.0 56:37 pickup pickup -l -t unix -u -c +I 0 2965195 2 0 0 0.0 46:00 kworker/u8:0-bt [kworker/u8:0-btrfs-worker] +I 0 2977972 2 0 0 0.0 33:54 kworker/u8:2-bt [kworker/u8:2-btrfs-endio-write] +I 0 2985488 2 0 0 0.0 27:02 kworker/u8:3-bl [kworker/u8:3-blkcg_punt_bio] +I 0 2987519 2 0 0 1.0 25:15 kworker/2:1-eve [kworker/2:1-events] +I 0 2987601 2 0 0 0.0 25:03 kworker/u8:9-i9 [kworker/u8:9-i915] +I< 0 2995218 2 0 0 0.0 18:41 kworker/u9:2-xp [kworker/u9:2-xprtiod] +I 0 2997170 2 0 0 0.0 16:41 kworker/3:1-rcu [kworker/3:1-rcu_gp] +I 0 3001264 2 0 0 0.0 13:01 kworker/u8:4-bt [kworker/u8:4-btrfs-endio-write] +I 0 3004697 2 0 0 0.7 09:41 kworker/2:0-eve [kworker/2:0-events] +I 0 3010619 2 0 0 1.0 04:29 kworker/2:2-eve [kworker/2:2-events] +I 0 3014612 2 0 0 0.0 00:41 kworker/3:2-eve [kworker/3:2-events] +S 0 3015082 2803015 6716 3028 0.0 00:30 cron /usr/sbin/CRON -f +I 0 3015382 2 0 0 0.0 00:00 kworker/u8:6-bt [kworker/u8:6-btrfs-endio-meta] +Ss 1 3392068 1 5592 504 0.0 15-02:34:39 atd /usr/sbin/atd -f +Ssl 0 3392072 1 235796 1740 0.0 15-02:34:39 accounts-daemon /usr/libexec/accounts-daemon +Ssl 106 3392076 1 315708 6128 0.0 15-02:34:39 colord /usr/libexec/colord +Ss 0 3392083 1 8120 720 0.0 15-02:34:39 haveged /usr/sbin/haveged --Foreground --verbose=1 +Ss 0 3392090 1 5168 132 0.0 15-02:34:39 blkmapd /usr/sbin/blkmapd +SNsl 111 3392094 1 155648 440 0.0 15-02:34:39 rtkit-daemon /usr/libexec/rtkit-daemon +Ssl 0 3392097 1 290168 1352 0.0 15-02:34:39 packagekitd /usr/libexec/packagekitd +Ss 128 3392100 1 7960 448 0.0 15-02:34:39 rpcbind /sbin/rpcbind -f -w +Ss 0 3392114 1 13432 616 0.0 15-02:34:39 systemd-machine /lib/systemd/systemd-machined +Ss 0 3392118 1 13316 848 0.0 15-02:34:39 sshd sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups +Ssl 0 3392124 1 244072 2456 0.0 15-02:34:39 upowerd /usr/libexec/upowerd +Ssl 0 3392138 1 1634748 10684 0.0 15-02:34:39 containerd /usr/bin/containerd +Ssl 0 3392139 1 222768 1784 0.0 15-02:34:39 rsyslogd /usr/sbin/rsyslogd -n -iNONE +Ss 13 3392140 1 3344 152 0.0 15-02:34:39 polipo /usr/bin/polipo -c /etc/polipo/config pidFile=/var/run/polipo/polipo.pid daemonise=true +Ssl 119 3392156 1 76472 1688 0.0 15-02:34:39 ntpd /usr/sbin/ntpd -p /var/run/ntpd.pid -g -u 119:126 +Ss 120 3392168 1 4656 276 0.0 15-02:34:39 rpc.statd /sbin/rpc.statd --no-notify +Ss 0 3392171 1 5072 432 0.0 15-02:34:39 rpc.mountd /usr/sbin/rpc.mountd --manage-gids +Ss 0 3392176 1 5008 288 0.0 15-02:34:39 rpc.idmapd /usr/sbin/rpc.idmapd +Ss 105 3392184 1 15544 6816 3.5 15-02:34:39 avahi-daemon avahi-daemon: running [tsui.local] +Ss 0 3392186 1 25288 3860 0.0 15-02:34:39 systemd-udevd /lib/systemd/systemd-udevd +S 105 3392190 3392184 8788 52 0.0 15-02:34:39 avahi-daemon avahi-daemon: chroot helper +Ssl 0 3392197 1 396120 4188 0.0 15-02:34:39 udisksd /usr/libexec/udisks2/udisksd +Ssl 0 3392214 1 237504 6632 0.0 15-02:34:39 polkitd /usr/libexec/polkitd --no-debug +Ss 0 3392284 1 9684 560 0.0 15-02:34:38 xinetd /usr/sbin/xinetd -pidfile /run/xinetd.pid -stayalive -inetd_compat -inetd_ipv6 +Ssl 0 3392285 1 314840 1352 0.0 15-02:34:38 ModemManager /usr/sbin/ModemManager +Ss 0 3392317 1 2352 140 0.0 15-02:34:38 acpid /usr/sbin/acpid +S 0 3392400 2 0 0 0.0 15-02:34:38 nfsd [nfsd] +S 0 3392401 2 0 0 0.0 15-02:34:38 nfsd [nfsd] +S 0 3392402 2 0 0 0.0 15-02:34:38 nfsd [nfsd] +S 0 3392403 2 0 0 0.0 15-02:34:38 nfsd [nfsd] +S 0 3392404 2 0 0 0.0 15-02:34:38 nfsd [nfsd] +S 0 3392405 2 0 0 0.0 15-02:34:38 nfsd [nfsd] +S 0 3392407 2 0 0 0.0 15-02:34:38 nfsd [nfsd] +S 0 3392410 2 0 0 0.0 15-02:34:38 nfsd [nfsd] +Ss 0 3392551 1 40092 1304 0.0 15-02:34:37 master /usr/lib/postfix/sbin/master -w +S 117 3392553 3392551 40156 568 0.0 15-02:34:37 qmgr qmgr -l -t unix -u +Ss 0 3392650 1 63652 4 0.0 15-02:34:36 squid /usr/sbin/squid --foreground -sYC +Ssl 116 3392652 1 1675196 93848 0.0 15-02:34:36 mariadbd /usr/sbin/mariadbd +S 13 3392655 3392650 81776 21232 0.0 15-02:34:36 squid (squid-1) --kid squid-1 --foreground -sYC +S 13 3392657 3392655 5572 68 0.0 15-02:34:36 log_file_daemon (logfile-daemon) /var/log/squid/access.log +S Date: Mon, 15 Nov 2021 14:29:51 +0100 Subject: check_icmp: Fix pkt perfdata in check_host mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add missing "warn" threshold field in "pkt" perfdata output. Perfdata should be interpreted as; 'label'=value[UOM];[warn];[crit];[min];[max] With one field missing, the hardcoded min value '0' ended up in the "crit" field, making applications interpreting the perfdata thining that critical threshold is always exceeded. Signed-off-by: Aksel Sjögren diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index 31eb4c6..519b93c 100644 --- a/plugins-root/check_icmp.c +++ b/plugins-root/check_icmp.c @@ -921,7 +921,7 @@ wait_for_reply(int sock, u_int t) /* if we're in hostcheck mode, exit with limited printouts */ if(mode == MODE_HOSTCHECK) { printf("OK - %s responds to ICMP. Packet %u, rta %0.3fms|" - "pkt=%u;;0;%u rta=%0.3f;%0.3f;%0.3f;;\n", + "pkt=%u;;;0;%u rta=%0.3f;%0.3f;%0.3f;;\n", host->name, icmp_recv, (float)tdiff / 1000, icmp_recv, packets, (float)tdiff / 1000, (float)warn.rta / 1000, (float)crit.rta / 1000); -- cgit v0.10-9-g596f From 024d268386353133af1a9ff5c0b5879397c19b1c Mon Sep 17 00:00:00 2001 From: Sven Nierlein Date: Wed, 17 Nov 2021 11:58:41 +0100 Subject: check_snmp: fix performance thresholds when using multiple oids when using check_snmp with multiple oids it simply printed the unparsed content from -w/-c into the thresholds for each oid. So each oid contained the hole -w from all oids. ./check_snmp ... -o iso.3.6.1.2.1.25.1.3.0,iso.3.6.1.2.1.25.1.5.0 -w '1,2' -c '3,4' before: SNMP ... | HOST-RESOURCES-MIB::hrSystemInitialLoadDevice.0=393216;1,2;3,4 HOST-RESOURCES-MIB::hrSystemNumUsers.0=24;1,2;3,4 after: SNMP ... | HOST-RESOURCES-MIB::hrSystemInitialLoadDevice.0=393216;1;3 HOST-RESOURCES-MIB::hrSystemNumUsers.0=24;2;4 This also applies to fixed thresholds since check_snmp translates negative infinities from: '~:-1' to '@-1:~' diff --git a/lib/utils_base.c b/lib/utils_base.c index fd7058d..08fa215 100644 --- a/lib/utils_base.c +++ b/lib/utils_base.c @@ -128,6 +128,7 @@ range temp_range->end = 0; temp_range->end_infinity = TRUE; temp_range->alert_on = OUTSIDE; + temp_range->text = strdup(str); if (str[0] == '@') { temp_range->alert_on = INSIDE; @@ -706,4 +707,3 @@ void np_state_write_string(time_t data_time, char *data_string) { np_free(temp_file); } - diff --git a/lib/utils_base.h b/lib/utils_base.h index d7e7dff..9482f23 100644 --- a/lib/utils_base.h +++ b/lib/utils_base.h @@ -23,6 +23,7 @@ typedef struct range_struct { double end; int end_infinity; int alert_on; /* OUTSIDE (default) or INSIDE */ + char* text; /* original unparsed text input */ } range; typedef struct thresholds_struct { diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index afc568b..58d46b1 100644 --- a/plugins/check_snmp.c +++ b/plugins/check_snmp.c @@ -468,6 +468,9 @@ main (int argc, char **argv) /* Process this block for numeric comparisons */ /* Make some special values,like Timeticks numeric only if a threshold is defined */ if (thlds[i]->warning || thlds[i]->critical || calculate_rate) { + if (verbose > 2) { + print_thresholds(" thresholds", thlds[i]); + } ptr = strpbrk (show, "-0123456789"); if (ptr == NULL) die (STATE_UNKNOWN,_("No valid data returned (%s)\n"), show); @@ -581,14 +584,16 @@ main (int argc, char **argv) if (warning_thresholds) { strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1); - strncat(perfstr, warning_thresholds, sizeof(perfstr)-strlen(perfstr)-1); + if(thlds[i]->warning && thlds[i]->warning->text) + strncat(perfstr, thlds[i]->warning->text, sizeof(perfstr)-strlen(perfstr)-1); } if (critical_thresholds) { if (!warning_thresholds) strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1); strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1); - strncat(perfstr, critical_thresholds, sizeof(perfstr)-strlen(perfstr)-1); + if(thlds[i]->critical && thlds[i]->critical->text) + strncat(perfstr, thlds[i]->critical->text, sizeof(perfstr)-strlen(perfstr)-1); } strncat(perfstr, " ", sizeof(perfstr)-strlen(perfstr)-1); diff --git a/plugins/tests/check_snmp.t b/plugins/tests/check_snmp.t index 85d6bf5..0a77fa8 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 = 67; +my $tests = 73; # Check that all dependent modules are available eval { require NetSNMP::OID; @@ -251,9 +251,20 @@ is($res->output, 'SNMP CRITICAL - *-4* | iso.3.6.1.4.1.8072.3.2.67.17=-4;-2:;-3: $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.18 -c '~:-6.5'" ); is($res->return_code, 0, "Negative float OK" ); -is($res->output, 'SNMP OK - -6.6 | iso.3.6.1.4.1.8072.3.2.67.18=-6.6;;~:-6.5 ', "Negative float OK output" ); +is($res->output, 'SNMP OK - -6.6 | iso.3.6.1.4.1.8072.3.2.67.18=-6.6;;@-6.5:~ ', "Negative float OK 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.18 -w '~:-6.65' -c '~:-6.55'" ); is($res->return_code, 1, "Negative float WARNING" ); -is($res->output, 'SNMP WARNING - *-6.6* | iso.3.6.1.4.1.8072.3.2.67.18=-6.6;~:-6.65;~:-6.55 ', "Negative float WARNING output" ); +is($res->output, 'SNMP WARNING - *-6.6* | iso.3.6.1.4.1.8072.3.2.67.18=-6.6;@-6.65:~;@-6.55:~ ', "Negative float WARNING 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.10,.1.3.6.1.4.1.8072.3.2.67.17 -w '1:100000,-10:20' -c '2:200000,-20:30'" ); +is($res->return_code, 0, "Multiple OIDs with thresholds" ); +like($res->output, '/SNMP OK - \d+ -4 | iso.3.6.1.4.1.8072.3.2.67.10=\d+c;1:100000;2:200000 iso.3.6.1.4.1.8072.3.2.67.17=-4;-10:20;-20:30/', "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.4.1.8072.3.2.67.10,.1.3.6.1.4.1.8072.3.2.67.17 -w '1:100000,-1:2' -c '2:200000,-20:30'" ); +is($res->return_code, 1, "Multiple OIDs with thresholds" ); +like($res->output, '/SNMP WARNING - \d+ \*-4\* | iso.3.6.1.4.1.8072.3.2.67.10=\d+c;1:100000;2:200000 iso.3.6.1.4.1.8072.3.2.67.17=-4;-10:20;-20:30/', "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.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" ); -- cgit v0.10-9-g596f From 27d96dcf23c44c74d0a2be7ea94f47798e37030a Mon Sep 17 00:00:00 2001 From: rincewind Date: Fri, 9 Jul 2021 16:07:23 +0200 Subject: Do not show RTA if no connection was possible diff --git a/plugins/check_ping.c b/plugins/check_ping.c index 423ecbe..7d58b10 100644 --- a/plugins/check_ping.c +++ b/plugins/check_ping.c @@ -37,6 +37,8 @@ const char *email = "devel@monitoring-plugins.org"; #include "popen.h" #include "utils.h" +#include + #define WARN_DUPLICATES "DUPLICATES FOUND! " #define UNKNOWN_TRIP_TIME -1.0 /* -1 seconds */ @@ -163,10 +165,14 @@ main (int argc, char **argv) printf (""); /* Print performance data */ - printf("|%s", fperfdata ("rta", (double) rta, "ms", - wrta>0?TRUE:FALSE, wrta, - crta>0?TRUE:FALSE, crta, - TRUE, 0, FALSE, 0)); + if (pl != 100) { + printf("|%s", fperfdata ("rta", (double) rta, "ms", + wrta>0?TRUE:FALSE, wrta, + crta>0?TRUE:FALSE, crta, + TRUE, 0, FALSE, 0)); + } else { + printf("|"); + } printf(" %s\n", perfdata ("pl", (long) pl, "%", wpl>0?TRUE:FALSE, wpl, cpl>0?TRUE:FALSE, cpl, -- cgit v0.10-9-g596f From 0214ec1918abf589f15b70948ddba641a9729ce3 Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Wed, 17 Nov 2021 14:09:11 +0100 Subject: Show RTA as unknown if it can not be determined diff --git a/plugins/check_ping.c b/plugins/check_ping.c index 7d58b10..6aa43ed 100644 --- a/plugins/check_ping.c +++ b/plugins/check_ping.c @@ -171,7 +171,7 @@ main (int argc, char **argv) crta>0?TRUE:FALSE, crta, TRUE, 0, FALSE, 0)); } else { - printf("|"); + printf("| rta=U;;;;;"); } printf(" %s\n", perfdata ("pl", (long) pl, "%", wpl>0?TRUE:FALSE, wpl, -- cgit v0.10-9-g596f From 1c53c4f541db3afdc3a2975121b69064d53f7ef3 Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Wed, 17 Nov 2021 15:45:17 +0100 Subject: homogenize perfdata function and fix small bug with missing semicolon diff --git a/plugins/utils.c b/plugins/utils.c index ebdae2e..17dd581 100644 --- a/plugins/utils.c +++ b/plugins/utils.c @@ -589,10 +589,12 @@ char *perfdata (const char *label, xasprintf (&data, "%s;", data); if (minp) - xasprintf (&data, "%s%ld", data, minv); + xasprintf (&data, "%s%ld;", data, minv); + else + xasprintf (&data, "%s;", data); if (maxp) - xasprintf (&data, "%s;%ld", data, maxv); + xasprintf (&data, "%s%ld", data, maxv); return data; } -- cgit v0.10-9-g596f From e030c2d17c10446bda840d66f6753b9bf573d715 Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Wed, 17 Nov 2021 15:45:49 +0100 Subject: Add thresholds even if value is missing diff --git a/plugins/check_ping.c b/plugins/check_ping.c index 6aa43ed..ba7af37 100644 --- a/plugins/check_ping.c +++ b/plugins/check_ping.c @@ -171,7 +171,7 @@ main (int argc, char **argv) crta>0?TRUE:FALSE, crta, TRUE, 0, FALSE, 0)); } else { - printf("| rta=U;;;;;"); + printf("| rta=U;%f;%f;;", wrta, crta); } printf(" %s\n", perfdata ("pl", (long) pl, "%", wpl>0?TRUE:FALSE, wpl, -- cgit v0.10-9-g596f From ee3449dee7578f1b0508b9ceb0c14a0d72a67646 Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Fri, 19 Nov 2021 00:34:44 +0100 Subject: Small fix to threshold validation and style (indentation) fixes diff --git a/plugins/check_swap.c b/plugins/check_swap.c index 685c2cc..7f71bf7 100644 --- a/plugins/check_swap.c +++ b/plugins/check_swap.c @@ -552,9 +552,12 @@ validate_arguments (void) if (warn.value == 0 && crit.value == 0) { return ERROR; } - else if (warn.value < crit.value) { - usage4 - (_("Warning should be more than critical")); + else if ((warn.is_percentage == crit.is_percentage) && (warn.value < crit.value)) { + /* This is NOT triggered if warn and crit are different units, e.g warn is percentage + * and crit is absolut. We cannot determine the condition at this point since we + * dont know the value of total swap yet + */ + usage4(_("Warning should be more than critical")); } return OK; } @@ -570,7 +573,7 @@ print_help (void) printf ("%s\n", _("Check swap space on local machine.")); - printf ("\n\n"); + printf ("\n\n"); print_usage (); @@ -578,23 +581,23 @@ print_help (void) printf (UT_EXTRA_OPTS); printf (" %s\n", "-w, --warning=INTEGER"); - printf (" %s\n", _("Exit with WARNING status if less than INTEGER bytes of swap space are free")); - printf (" %s\n", "-w, --warning=PERCENT%%"); - printf (" %s\n", _("Exit with WARNING status if less than PERCENT of swap space is free")); - printf (" %s\n", "-c, --critical=INTEGER"); - printf (" %s\n", _("Exit with CRITICAL status if less than INTEGER bytes of swap space are free")); - printf (" %s\n", "-c, --critical=PERCENT%%"); - printf (" %s\n", _("Exit with CRITICAL status if less than PERCENT of swap space is free")); - printf (" %s\n", "-a, --allswaps"); - printf (" %s\n", _("Conduct comparisons for all swap partitions, one by one")); - printf (" %s\n", "-n, --no-swap="); - printf (" %s %s\n", _("Resulting state when there is no swap regardless of thresholds. Default:"), state_text(no_swap_state)); + printf (" %s\n", _("Exit with WARNING status if less than INTEGER bytes of swap space are free")); + printf (" %s\n", "-w, --warning=PERCENT%"); + printf (" %s\n", _("Exit with WARNING status if less than PERCENT of swap space is free")); + printf (" %s\n", "-c, --critical=INTEGER"); + printf (" %s\n", _("Exit with CRITICAL status if less than INTEGER bytes of swap space are free")); + printf (" %s\n", "-c, --critical=PERCENT%"); + printf (" %s\n", _("Exit with CRITICAL status if less than PERCENT of swap space is free")); + printf (" %s\n", "-a, --allswaps"); + printf (" %s\n", _("Conduct comparisons for all swap partitions, one by one")); + printf (" %s\n", "-n, --no-swap="); + printf (" %s %s\n", _("Resulting state when there is no swap regardless of thresholds. Default:"), state_text(no_swap_state)); printf (UT_VERBOSE); printf ("\n"); - printf ("%s\n", _("Notes:")); - printf (" %s\n", _("Both INTEGER and PERCENT thresholds can be specified, they are all checked.")); - printf (" %s\n", _("On AIX, if -a is specified, uses lsps -a, otherwise uses lsps -s.")); + printf ("%s\n", _("Notes:")); + printf (" %s\n", _("Both INTEGER and PERCENT thresholds can be specified, they are all checked.")); + printf (" %s\n", _("On AIX, if -a is specified, uses lsps -a, otherwise uses lsps -s.")); printf (UT_SUPPORT); } @@ -604,6 +607,6 @@ void print_usage (void) { printf ("%s\n", _("Usage:")); - printf (" %s [-av] -w %% -c %%\n",progname); - printf (" -w -c [-n ]\n"); + printf (" %s [-av] -w %% -c %%\n",progname); + printf (" -w -c [-n ]\n"); } -- cgit v0.10-9-g596f From a1fe4df6a3a146b50c4fd700acdf8baf848874aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20K=C3=A4stle?= Date: Mon, 19 Apr 2021 11:51:30 +0200 Subject: Fixed option description authpassword -> authpasswd + whitespaces diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index 58d46b1..88422b1 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 . -* -* +* +* *****************************************************************************/ const char *progname = "check_snmp"; @@ -315,7 +315,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]; } @@ -329,7 +329,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,14 +398,14 @@ main (int argc, char **argv) /* We strip out the datatype indicator for PHBs */ if (strstr (response, "Gauge: ")) { show = strstr (response, "Gauge: ") + 7; - } + } else if (strstr (response, "Gauge32: ")) { show = 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: ")) { @@ -607,7 +607,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 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) { @@ -1006,7 +1006,7 @@ validate_arguments () contextargs[0] = strdup ("-n"); contextargs[1] = strdup (context); } - + if (seclevel == NULL) xasprintf(&seclevel, "noAuthNoPriv"); @@ -1166,7 +1166,7 @@ print_help (void) printf ("(%s \"%s\")\n", _("default is") ,DEFAULT_COMMUNITY); printf (" %s\n", "-U, --secname=USERNAME"); printf (" %s\n", _("SNMPv3 username")); - printf (" %s\n", "-A, --authpassword=PASSWORD"); + printf (" %s\n", "-A, --authpasswd=PASSWORD"); printf (" %s\n", _("SNMPv3 authentication password")); printf (" %s\n", "-X, --privpasswd=PASSWORD"); printf (" %s\n", _("SNMPv3 privacy password")); -- cgit v0.10-9-g596f From cf9dccbec22e15a475cd6d5b160f503a04348a0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20K=C3=A4stle?= Date: Mon, 19 Apr 2021 12:22:16 +0200 Subject: Revert "Fixed option description authpassword -> authpasswd + whitespaces" This reverts commit b27e639725f680411aaa78dd9aa59cfff84ad0c5. diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index 88422b1..58d46b1 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 . -* -* +* +* *****************************************************************************/ const char *progname = "check_snmp"; @@ -315,7 +315,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]; } @@ -329,7 +329,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,14 +398,14 @@ main (int argc, char **argv) /* We strip out the datatype indicator for PHBs */ if (strstr (response, "Gauge: ")) { show = strstr (response, "Gauge: ") + 7; - } + } else if (strstr (response, "Gauge32: ")) { show = 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: ")) { @@ -607,7 +607,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 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) { @@ -1006,7 +1006,7 @@ validate_arguments () contextargs[0] = strdup ("-n"); contextargs[1] = strdup (context); } - + if (seclevel == NULL) xasprintf(&seclevel, "noAuthNoPriv"); @@ -1166,7 +1166,7 @@ print_help (void) printf ("(%s \"%s\")\n", _("default is") ,DEFAULT_COMMUNITY); printf (" %s\n", "-U, --secname=USERNAME"); printf (" %s\n", _("SNMPv3 username")); - printf (" %s\n", "-A, --authpasswd=PASSWORD"); + printf (" %s\n", "-A, --authpassword=PASSWORD"); printf (" %s\n", _("SNMPv3 authentication password")); printf (" %s\n", "-X, --privpasswd=PASSWORD"); printf (" %s\n", _("SNMPv3 privacy password")); -- cgit v0.10-9-g596f From c46447af659e96d78c2f02e1295e887a4d12cd36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20K=C3=A4stle?= Date: Mon, 19 Apr 2021 12:23:42 +0200 Subject: Fix option description authpassword -> authpasswd diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index 58d46b1..abe54cf 100644 --- a/plugins/check_snmp.c +++ b/plugins/check_snmp.c @@ -1166,7 +1166,7 @@ print_help (void) printf ("(%s \"%s\")\n", _("default is") ,DEFAULT_COMMUNITY); printf (" %s\n", "-U, --secname=USERNAME"); printf (" %s\n", _("SNMPv3 username")); - printf (" %s\n", "-A, --authpassword=PASSWORD"); + printf (" %s\n", "-A, --authpasswd=PASSWORD"); printf (" %s\n", _("SNMPv3 authentication password")); printf (" %s\n", "-X, --privpasswd=PASSWORD"); printf (" %s\n", _("SNMPv3 privacy password")); -- cgit v0.10-9-g596f From f961b7f7bd5d10328bf152cbc015271180165f0f Mon Sep 17 00:00:00 2001 From: Linda Guo Date: Fri, 19 Nov 2021 13:25:09 +1100 Subject: Allows check_ldap to get password from env variable It's not secure to provide LDAP password through command line option because other users on the same host can see the password in 'ps' command output. This change allows check_ldap to get password from environment variable. diff --git a/plugins/check_ldap.c b/plugins/check_ldap.c index bc7bd44..845a4f5 100644 --- a/plugins/check_ldap.c +++ b/plugins/check_ldap.c @@ -432,6 +432,9 @@ validate_arguments () set_thresholds(&entries_thresholds, warn_entries, crit_entries); } + if (ld_passwd==NULL) + ld_passwd = getenv("LDAP_PASSWORD"); + return OK; } @@ -465,7 +468,7 @@ print_help (void) printf (" %s\n", "-D [--bind]"); printf (" %s\n", _("ldap bind DN (if required)")); printf (" %s\n", "-P [--pass]"); - printf (" %s\n", _("ldap password (if required)")); + printf (" %s\n", _("ldap password (if required, or set the password through environment variable 'LDAP_PASSWORD')")); printf (" %s\n", "-T [--starttls]"); printf (" %s\n", _("use starttls mechanism introduced in protocol version 3")); printf (" %s\n", "-S [--ssl]"); -- cgit v0.10-9-g596f From f291934f2cd7124e62deb6de5fca98d2506d3c45 Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Sun, 21 Nov 2021 02:43:01 +0100 Subject: Update Url to qstat diff --git a/plugins/check_game.c b/plugins/check_game.c index 709dae1..a534b69 100644 --- a/plugins/check_game.c +++ b/plugins/check_game.c @@ -318,7 +318,7 @@ print_help (void) printf ("%s\n", _("Notes:")); printf (" %s\n", _("This plugin uses the 'qstat' command, the popular game server status query tool.")); printf (" %s\n", _("If you don't have the package installed, you will need to download it from")); - printf (" %s\n", _("http://www.activesw.com/people/steve/qstat.html before you can use this plugin.")); + printf (" %s\n", _("https://github.com/multiplay/qstat before you can use this plugin.")); printf (UT_SUPPORT); } -- cgit v0.10-9-g596f From 09bfb1b482f428b1c11f68b5be7d134ba5e3b457 Mon Sep 17 00:00:00 2001 From: PhiBo Date: Wed, 24 Nov 2021 11:23:47 +0100 Subject: Fix possible overflow in check_ups (Fixes: #1030) diff --git a/plugins/check_ups.c b/plugins/check_ups.c index e9e56a5..0de37a2 100644 --- a/plugins/check_ups.c +++ b/plugins/check_ups.c @@ -402,7 +402,10 @@ get_ups_variable (const char *varname, char *buf, size_t buflen) /* create the command string to send to the UPS daemon */ /* Add LOGOUT to avoid read failure logs */ - sprintf (send_buffer, "GET VAR %s %s\nLOGOUT\n", ups_name, varname); + if (snprintf (send_buffer, sizeof(send_buffer), "GET VAR %s %s\nLOGOUT\n", ups_name, varname) >= sizeof(send_buffer)) { + printf("%s\n", _("UPS name to long for buffer")); + return ERROR; + } /* send the command to the daemon and get a response back */ if (process_tcp_request -- cgit v0.10-9-g596f From e2f24a5af3fe407035c8c57f539148f2d694973b Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Wed, 24 Nov 2021 14:25:42 +0100 Subject: Fix CodeQL checks diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index 519b93c..bcf6c5f 100644 --- a/plugins-root/check_icmp.c +++ b/plugins-root/check_icmp.c @@ -502,7 +502,7 @@ main(int argc, char **argv) icmp_data_size = size; icmp_pkt_size = size + ICMP_MINLEN; } else - usage_va("ICMP data length must be between: %d and %d", + usage_va("ICMP data length must be between: %ul and %ul", sizeof(struct icmp) + sizeof(struct icmp_ping_data), MAX_PING_DATA - 1); break; @@ -1293,7 +1293,7 @@ add_target_ip(char *arg, struct sockaddr_storage *in) if(!host) { char straddr[INET6_ADDRSTRLEN]; parse_address((struct sockaddr_storage*)&in, straddr, sizeof(straddr)); - crash("add_target_ip(%s, %s): malloc(%d) failed", + crash("add_target_ip(%s, %s): malloc(%ul) failed", arg, straddr, sizeof(struct rta_host)); } memset(host, 0, sizeof(struct rta_host)); diff --git a/plugins/check_disk.c b/plugins/check_disk.c index c526d05..f032378 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c @@ -1040,9 +1040,15 @@ get_stats (struct parameter_list *p, struct fs_usage *fsp) { 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) - printf("Group %s: adding %llu blocks sized %llu, (%s) used_units=%g free_units=%g total_units=%g fsu_blocksize=%llu mult=%llu\n", - p_list->group, tmpfsp.fsu_bavail, tmpfsp.fsu_blocksize, p_list->best_match->me_mountdir, p_list->dused_units, p_list->dfree_units, - p_list->dtotal_units, mult); + printf("Group %s: adding %llu blocks sized %llu, (%s) used_units=%g free_units=%g total_units=%g mult=%llu\n", + p_list->group, + tmpfsp.fsu_blocks, + tmpfsp.fsu_blocksize, + p_list->best_match->me_mountdir, + p_list->dused_units, + p_list->dfree_units, + p_list->dtotal_units, + mult); /* prevent counting the first FS of a group twice since its parameter_list entry * is used to carry the information of all file systems of the entire group */ @@ -1065,12 +1071,10 @@ get_stats (struct parameter_list *p, struct fs_usage *fsp) { if (verbose >= 3) printf("Group %s now has: used_units=%g free_units=%g total_units=%g fsu_blocksize=%llu mult=%llu\n", p->group, - tmpfsp.fsu_bavail, - tmpfsp.fsu_blocksize, - p->best_match->me_mountdir, p->dused_units, p->dfree_units, p->dtotal_units, + tmpfsp.fsu_blocksize, mult); } /* modify devname and mountdir for output */ diff --git a/plugins/check_hpjd.c b/plugins/check_hpjd.c index 6546556..d3d72d7 100644 --- a/plugins/check_hpjd.c +++ b/plugins/check_hpjd.c @@ -121,7 +121,7 @@ main (int argc, char **argv) HPJD_GD_DOOR_OPEN, HPJD_GD_PAPER_OUTPUT, HPJD_GD_STATUS_DISPLAY); /* get the command to run */ - sprintf (command_line, "%s -OQa -m : -v 1 -c %s %s:%hd %s", PATH_TO_SNMPGET, community, + sprintf (command_line, "%s -OQa -m : -v 1 -c %s %s:%s %s", PATH_TO_SNMPGET, community, address, port, query_string); /* run the command */ diff --git a/plugins/check_swap.c b/plugins/check_swap.c index 7f71bf7..00bdcdd 100644 --- a/plugins/check_swap.c +++ b/plugins/check_swap.c @@ -142,7 +142,7 @@ main (int argc, char **argv) percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb)); result = max_state (result, check_swap (dskfree_mb, dsktotal_mb)); if (verbose) - xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent); + xasprintf (&status, "%s [%ul (%d%%)]", status, dskfree_mb, 100 - percent); } } /* -- cgit v0.10-9-g596f From 40d4e8a057a77e357c26d701c5fd304b51787b93 Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Wed, 24 Nov 2021 15:38:18 +0100 Subject: check_hpjd: Fixing port option diff --git a/plugins/check_hpjd.c b/plugins/check_hpjd.c index d3d72d7..c4b4417 100644 --- a/plugins/check_hpjd.c +++ b/plugins/check_hpjd.c @@ -66,7 +66,7 @@ void print_usage (void); char *community = NULL; char *address = NULL; -char *port = NULL; +unsigned int port = 0; int check_paper_out = 1; int @@ -121,8 +121,12 @@ main (int argc, char **argv) HPJD_GD_DOOR_OPEN, HPJD_GD_PAPER_OUTPUT, HPJD_GD_STATUS_DISPLAY); /* get the command to run */ - sprintf (command_line, "%s -OQa -m : -v 1 -c %s %s:%s %s", PATH_TO_SNMPGET, community, - address, port, query_string); + sprintf (command_line, "%s -OQa -m : -v 1 -c %s %s:%u %s", + PATH_TO_SNMPGET, + community, + address, + port, + query_string); /* run the command */ child_process = spopen (command_line); @@ -380,11 +384,8 @@ process_arguments (int argc, char **argv) community = strdup (DEFAULT_COMMUNITY); } - if (port == NULL) { - if (argv[c] != NULL ) - port = argv[c]; - else - port = atoi (DEFAULT_PORT); + if (port == 0) { + port = atoi(DEFAULT_PORT); } return validate_arguments (); -- cgit v0.10-9-g596f From d28bab4dbdf5b5be37b70164dd4a6d55e0ca9380 Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Wed, 24 Nov 2021 19:02:17 +0100 Subject: More wrong printf formatting diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index bcf6c5f..01ae174 100644 --- a/plugins-root/check_icmp.c +++ b/plugins-root/check_icmp.c @@ -502,7 +502,7 @@ main(int argc, char **argv) icmp_data_size = size; icmp_pkt_size = size + ICMP_MINLEN; } else - usage_va("ICMP data length must be between: %ul and %ul", + usage_va("ICMP data length must be between: %lu and %lu", sizeof(struct icmp) + sizeof(struct icmp_ping_data), MAX_PING_DATA - 1); break; @@ -1293,7 +1293,7 @@ add_target_ip(char *arg, struct sockaddr_storage *in) if(!host) { char straddr[INET6_ADDRSTRLEN]; parse_address((struct sockaddr_storage*)&in, straddr, sizeof(straddr)); - crash("add_target_ip(%s, %s): malloc(%ul) failed", + crash("add_target_ip(%s, %s): malloc(%lu) failed", arg, straddr, sizeof(struct rta_host)); } memset(host, 0, sizeof(struct rta_host)); diff --git a/plugins/check_disk.c b/plugins/check_disk.c index f032378..54befca 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c @@ -1040,7 +1040,7 @@ get_stats (struct parameter_list *p, struct fs_usage *fsp) { 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) - printf("Group %s: adding %llu blocks sized %llu, (%s) used_units=%g free_units=%g total_units=%g mult=%llu\n", + printf("Group %s: adding %llu blocks sized %llu, (%s) used_units=%lu free_units=%llu total_units=%llu mult=%llu\n", p_list->group, tmpfsp.fsu_blocks, tmpfsp.fsu_blocksize, @@ -1069,7 +1069,7 @@ get_stats (struct parameter_list *p, struct fs_usage *fsp) { first = 0; } if (verbose >= 3) - printf("Group %s now has: used_units=%g free_units=%g total_units=%g fsu_blocksize=%llu mult=%llu\n", + printf("Group %s now has: used_units=%llu free_units=%llu total_units=%llu fsu_blocksize=%llu mult=%llu\n", p->group, p->dused_units, p->dfree_units, diff --git a/plugins/check_swap.c b/plugins/check_swap.c index 00bdcdd..7da26cf 100644 --- a/plugins/check_swap.c +++ b/plugins/check_swap.c @@ -142,7 +142,7 @@ main (int argc, char **argv) percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb)); result = max_state (result, check_swap (dskfree_mb, dsktotal_mb)); if (verbose) - xasprintf (&status, "%s [%ul (%d%%)]", status, dskfree_mb, 100 - percent); + xasprintf (&status, "%s [%lu (%d%%)]", status, dskfree_mb, 100 - percent); } } /* -- cgit v0.10-9-g596f From 5e2c3992204466d621e521695c4250f1d5480e77 Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Mon, 29 Nov 2021 17:27:57 +0100 Subject: Make size parameter a little bit more intelligible diff --git a/plugins-scripts/check_file_age.pl b/plugins-scripts/check_file_age.pl index 01b854a..26281dd 100755 --- a/plugins-scripts/check_file_age.pl +++ b/plugins-scripts/check_file_age.pl @@ -147,7 +147,7 @@ sub print_help () { print "\n"; print " -i | --ignore-missing : return OK if the file does not exist\n"; print " File must be no more than this many seconds old (default: warn 240 secs, crit 600)\n"; - print " File must be at least this many bytes long (default: crit 0 bytes)\n\n"; + print " File must be at least this many bytes long (default: file size is ignored (0 bytes))\n\n"; print " Both and can specify a range using the standard plugin syntax\n"; print " If any of the warning and critical arguments are in range syntax (not just bare numbers)\n"; print " then all warning and critical arguments will be interpreted as ranges.\n"; -- cgit v0.10-9-g596f From 8df8460c6cd5c926990fddc1659e0f4194848473 Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Thu, 2 Dec 2021 15:26:31 +0100 Subject: Fix syntax error resulting from merging diff --git a/plugins-scripts/check_mailq.pl b/plugins-scripts/check_mailq.pl index 4bc9487..3914f4a 100755 --- a/plugins-scripts/check_mailq.pl +++ b/plugins-scripts/check_mailq.pl @@ -575,7 +575,7 @@ sub process_arguments(){ "c=i" => \$opt_c, "critical=i" => \$opt_c, # critical if above this number "t=i" => \$opt_t, "timeout=i" => \$opt_t, "s" => \$opt_s, "sudo" => \$opt_s, - "d:s" => \$opt_d, "configdir:s" => \$opt_d + "d:s" => \$opt_d, "configdir:s" => \$opt_d, "W=i" => \$opt_W, # warning if above this number "C=i" => \$opt_C, # critical if above this number ); -- cgit v0.10-9-g596f From 5a81bd813ecae7c6492e4eac001331973d9594b3 Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Thu, 2 Dec 2021 17:10:57 +0100 Subject: Missing oldlog now aborts check_log diff --git a/plugins-scripts/check_log.sh b/plugins-scripts/check_log.sh index 6113123..d71f420 100755 --- a/plugins-scripts/check_log.sh +++ b/plugins-scripts/check_log.sh @@ -43,6 +43,10 @@ # check the same for pattern matches. This is necessary # because of the way the script operates. # +# 4. This plugin does NOT have an understanding of logrotation or similar +# mechanisms. Therefore bad timing could lead to missing events +# +# # Examples: # # Check for login failures in the syslog... @@ -207,6 +211,11 @@ elif [ ! -r "$logfile" ] ; then echo "Log check error: Log file $logfile is not readable!" exit "$STATE_UNKNOWN" fi +# If no oldlog was given this can not work properly, abort then +if [ ! -v oldlog ]; then + echo "Oldlog parameter is needed" + exit $STATE_UNKNOWN +fi # If the old log file doesn't exist, this must be the first time # we're running this test, so copy the original log file over to @@ -256,7 +265,7 @@ cat "$logfile" > "$oldlog" if [ "$count" = "0" ]; then # no matches, exit with no error echo "Log check ok - 0 pattern matches found" exitstatus=$STATE_OK -else # Print total matche count and the last entry we found +else # Print total match count and the last entry we found echo "($count) $entry" exitstatus=$STATE_CRITICAL fi -- cgit v0.10-9-g596f From c1bf69c3a6a52c714e27107219e402bbecd7c000 Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Mon, 20 Dec 2021 00:08:24 +0100 Subject: Apparently Dash is not Bash, so -v does not work diff --git a/plugins-scripts/check_log.sh b/plugins-scripts/check_log.sh index d71f420..fdb5741 100755 --- a/plugins-scripts/check_log.sh +++ b/plugins-scripts/check_log.sh @@ -212,7 +212,7 @@ elif [ ! -r "$logfile" ] ; then exit "$STATE_UNKNOWN" fi # If no oldlog was given this can not work properly, abort then -if [ ! -v oldlog ]; then +if [ -z "$oldlog" ]; then echo "Oldlog parameter is needed" exit $STATE_UNKNOWN fi -- cgit v0.10-9-g596f From 763b7ab0c491cdc47442010374454532bfbe41dc Mon Sep 17 00:00:00 2001 From: rincewind Date: Fri, 23 Apr 2021 16:07:37 +0200 Subject: check_sensors.sh: Make shellcheck happier diff --git a/plugins-scripts/check_sensors.sh b/plugins-scripts/check_sensors.sh index 9a6cf5d..ab4e726 100755 --- a/plugins-scripts/check_sensors.sh +++ b/plugins-scripts/check_sensors.sh @@ -46,7 +46,7 @@ case "$1" in if test ${status} -eq 127; then text="SENSORS UNKNOWN - command not found (did you install lmsensors?)" exit=$STATE_UNKNOWN - elif test ${status} -ne 0; then + elif test "${status}" -ne 0; then text="WARNING - sensors returned state $status" exit=$STATE_WARNING elif echo "${sensordata}" | egrep ALARM > /dev/null; then -- cgit v0.10-9-g596f