diff --git a/check_eol b/check_eol index 94cf0adfa2d8c9442a7868bc310162e6b77aa49d..8f2e13fecf95d7b9e7e9934b1e7097bffd74fdaf 100755 --- a/check_eol +++ b/check_eol @@ -44,6 +44,7 @@ # ---------------------------------------------------------------------- # 2020-02-21 v1.0 <axel.hahn@iml.unibe.ch> # 2020-03-05 v1.1 <axel.hahn@iml.unibe.ch> switch to ph.* helper functions +# 2021-03-26 v1.2 <axel.hahn@iml.unibe.ch> test major version if minor version was not detected # ====================================================================== . `dirname $0`/inc_pluginfunctions @@ -128,52 +129,26 @@ function getDaysLeft(){ fi } -# detect product in *cfg files and find its EOL + +# detect product in *cfg files and find its line with EOL information # global string myKey name of product # global string myVersion its version function findEolDate(){ - line=`grep "^$myKey:$myVersion:" $eolcfg | sort -n | tail -1` - if [ ! -z "$line" ]; then - - myEolEnd=`echo $line | cut -f 4 -d ":"` - myComment=`echo $line | cut -f 5 -d ":"` - myDaysLeft=`getDaysLeft $myEolEnd` - # --- verify days left with limits - ph.setStatus "ok" - if [ $myDaysLeft -lt $iDaysWarn ]; then - ph.setStatus "warning" - if [ $myDaysLeft -lt $iDaysCritical ]; then - ph.setStatus "critical" - fi - fi - if [ $myDaysLeft -ge 0 ]; then - ph.status "[$myKey $myVersion] ends on $myEolEnd ... $myDaysLeft days left $myComment" - else - echo "[$myKey $myVersion] ended on $myEolEnd ... `echo $myDaysLeft | sed 's#\-##'` days EXPIRED ALREADY !!! $myComment" - fi - echo - grep "^$myKey:" $eolcfg | grep -v ":$myKey:[0-9]" | cut -f 3- -d ":" - echo - echo "Limit Info: warn below $iDaysWarn days; critical below $iDaysCritical days" - ph.perfadd "$myKey-v$myVersion" "${myDaysLeft}" $iDaysWarn $iDaysCritical 0 - else - ph.setStatus "unknown" - echo "UNKNOWN. Sorry, [$myKey $myVersion] was not found in $eolcfg." - echo - grep "^$myKey:" $eolcfg >/dev/null - if [ $? -eq 0 ]; then - echo "HINT: the product [$myKey] is known ... but not the version [$myVersion] ... or its date is invalid i.e. 30th of feb or not YYYY-MM-DD" - echo - grep "^$myKey:" $eolcfg | grep -v ":$myKey:[0-9]" | cut -f 3- -d ":" - echo - echo "Maybe an admin can add the version in `grep -l "^$myKey:" $eolcfg`" - echo "Existing/ known versions are:" - grep "^$myKey:[0-9]" $eolcfg | cut -f 3 -d ":" | sort -un - else - echo "The product key [$myKey] was not detected in any version." - fi - fi + local myVerKey="$myVersion." + local line='' + local bContinue=0 + while [ $bContinue = 0 ]; do + myVerKey=$( echo $myVerKey | rev | cut -f 2- -d "." | rev ) + line=`grep "^$myKey:$myVerKey:" $eolcfg | sort -n | tail -1` + + test -z "$line" || bContinue=1 + echo $myVerKey | grep "\." >/dev/null || bContinue=1 + + done + + echo $line + } # ---------------------------------------------------------------------- @@ -255,7 +230,51 @@ fi myKey=$1 myVersion=$2 test $myVersion = "detect" && autodetect $myKey -findEolDate "$myKey" "$myVersion" +eol=$( findEolDate "$myKey" "$myVersion" ) + +if [ -z "$eol" ]; then + ph.setStatus "unknown" + echo "UNKNOWN. Sorry, [$myKey $myVersion] was not found in $eolcfg." + echo + grep "^$myKey:" $eolcfg >/dev/null + if [ $? -eq 0 ]; then + echo "HINT: the product [$myKey] is known ... but not the version [$myVersion] ... or its date is invalid i.e. 30th of feb or not YYYY-MM-DD" + echo + grep "^$myKey:" $eolcfg | grep -v ":$myKey:[0-9]" | cut -f 3- -d ":" + echo + echo "Maybe an admin can add the version in `grep -l "^$myKey:" $eolcfg`" + echo "Existing/ known versions are:" + grep "^$myKey:[0-9]" $eolcfg | cut -f 3 -d ":" | sort -un + else + echo "The product key [$myKey] was not detected in any version." + fi +else + myEolVer=`echo $eol | cut -f 3 -d ":"` + myEolEnd=`echo $eol | cut -f 4 -d ":"` + myComment=`echo $eol | cut -f 5 -d ":"` + + myDaysLeft=`getDaysLeft $myEolEnd` + # --- verify days left with limits + ph.setStatus "ok" + if [ $myDaysLeft -lt $iDaysWarn ]; then + ph.setStatus "warning" + if [ $myDaysLeft -lt $iDaysCritical ]; then + ph.setStatus "critical" + fi + fi + if [ $myDaysLeft -ge 0 ]; then + ph.status "[$myKey $myEolVer] ends on $myEolEnd ... $myDaysLeft days left $myComment" + else + echo "[$myKey $myEolVer] ended on $myEolEnd ... `echo $myDaysLeft | sed 's#\-##'` days EXPIRED ALREADY !!! $myComment" + fi + echo + grep "^$myKey:" $eolcfg | grep -v ":$myKey:[0-9]" | cut -f 3- -d ":" + echo + echo "Limit Info: warn below $iDaysWarn days; critical below $iDaysCritical days" + ph.perfadd "$myKey-v$myEolVer" "${myDaysLeft}" $iDaysWarn $iDaysCritical 0 + + +fi # --- bye ph.exit diff --git a/check_eol-versiondetect/detect-postgres b/check_eol-versiondetect/detect-postgres index 6b12ee1c5a8c295e2b564a8218060fa31d5f909a..ae1d34fd48bedd240f8f608c8d052d62b6a2ea76 100755 --- a/check_eol-versiondetect/detect-postgres +++ b/check_eol-versiondetect/detect-postgres @@ -5,11 +5,26 @@ # detect version of PostgreSQL # # ---------------------------------------------------------------------------- -# 2020-02-25 v1.0 <axel.hahn@iml.unibe.ch> +# 2020-02-25 v1.0 <axel.hahn@iml.unibe.ch> initial version +# 2021-03-26 v1.1 <axel.hahn@iml.unibe.ch> add locations if postgres is not in PATH # ---------------------------------------------------------------------------- +# +# WORKAROUND: add additional locations in $PATH +# +otherlocations="/usr/pgsql-10/bin/ /some/other/postgres/location/bin/" + +POSTGRES=$( which postgres 2>/dev/null ) +test -z "$POSTGRES" && + for mypath in ${otherlocations} + do + test -x "$mypath/postgres" && POSTGRES="$mypath/postgres" + done + + +# # ----- example output # postgres --version # postgres (PostgreSQL) 9.2.24 -postgres --version | cut -f 3 -d " " | cut -f 1,2 -d '.' +$POSTGRES --version | cut -f 3 -d " " | cut -f 1,2 -d '.'