diff --git a/check_eol b/check_eol index 27c09078912fe16975543e68f95e99f552601bda..2a852a9236263b32237e27096827098a27494a16 100755 --- a/check_eol +++ b/check_eol @@ -47,12 +47,13 @@ # 2021-03-26 v1.2 <axel.hahn@iml.unibe.ch> test major version if minor version was not detected # 2021-11-02 v1.3 <axel.hahn@iml.unibe.ch> detect centos stream # 2022-02-28 v1.4 <axel.hahn@iml.unibe.ch> remove negative performance data +# 2022-08-29 v1.5 <axel.hahn@iml.unibe.ch> fix help; shell syntax updates # ====================================================================== -. `dirname $0`/inc_pluginfunctions +. "$( dirname $0 )/inc_pluginfunctions" eolcfg="${0}-data/*.cfg" -_version="1.3" +_version="1.5" # --- limits typeset -i iDaysWarn=365 @@ -89,7 +90,7 @@ function autodetect(){ # --- stop 2: find version number detectorPlugin="$0-versiondetect/detect-$myKey" if [ -x "$detectorPlugin" ]; then - myVersion=`. "$detectorPlugin"` + myVersion=$(. "$detectorPlugin") fi if [ -z "$myVersion" ]; then ph.abort "UNKNOWN: [$myKey] was not detected properly. It is unknown or output for version cannot be parsed." @@ -108,8 +109,8 @@ function getDaysLeft(){ local mydate=$1 echo $mydate | grep "[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]" >/dev/null if [ $? -eq 0 ]; then - typeset -i local tsend=`date --date="$mydate" +%s` - typeset -i local daysLeft=($tsend - `date +%s`)/60/60/24 + typeset -i local tsend=$(date --date="$mydate" +%s) + typeset -i local daysLeft=($tsend - $(date +%s))/60/60/24 echo $daysLeft fi } @@ -125,7 +126,7 @@ function findEolDate(){ 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` + line=$(grep "^$myKey:$myVerKey:" $eolcfg | sort -n | tail -1) test -z "$line" || bContinue=1 echo $myVerKey | grep "\." >/dev/null || bContinue=1 @@ -143,6 +144,7 @@ function findEolDate(){ # --- no param? show help if [ $# -lt 2 ]; then + _self=$( basename $0 ) cat <<EOH ______________________________________________________________________ @@ -154,15 +156,15 @@ ______________________________________________________________________ Check and of support of an OS or a product. The dates are defined in the files check_eol-*.cfg -For detailed information see `basename $0`.md +For detailed information see docs/20_Checks/check_eol.md USAGE - $ `basename $0` [-c CRITICAL] [-w WARING] PRODUCT VERSION + $ $_self [-c CRITICAL] [-w WARING] PRODUCT VERSION PARAMETERS PRODUCT set a product; known product keys are listed below -`grep "^[a-zA-Z]" $eolcfg | cut -f 2 -d ":" | sort -un | sed "s#^# #g"` +$( grep "^[a-zA-Z]" $eolcfg | cut -f 2 -d ":" | sort -u | sed "s#^# #g" ) VERSION set a version. Autodetection: @@ -175,10 +177,10 @@ OPTIONS -w set warning limit; default $iDaysWarn EXAMPLES - `basename $0` php 7.4 - `basename $0` -w 100 -c 30 php 7.4 - `basename $0` os detect - `basename $0` php detect + $_self php 8.1 + $_self -w 100 -c 30 php 8.1 + $_self os detect + $_self php detect EOH @@ -228,18 +230,18 @@ if [ -z "$eol" ]; then 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 "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 ":"` + myEolVer=$(echo $eol | cut -f 3 -d ":") + myEolEnd=$(echo $eol | cut -f 4 -d ":") + myComment=$(echo $eol | cut -f 5 -d ":") - myDaysLeft=`getDaysLeft $myEolEnd` + myDaysLeft=$(getDaysLeft $myEolEnd) # --- verify days left with limits ph.setStatus "ok" if [ $myDaysLeft -lt $iDaysWarn ]; then @@ -251,7 +253,7 @@ else 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" + 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 ":" diff --git a/docs/20_Checks/check_eol.md b/docs/20_Checks/check_eol.md new file mode 100644 index 0000000000000000000000000000000000000000..9c2173683357f7d7a970ad87bedae7d9035d0d6b --- /dev/null +++ b/docs/20_Checks/check_eol.md @@ -0,0 +1,174 @@ +## check EOL + +### Introduction + +**check_eol** is a plugin for Icinga/ Nagios. It detects the end of life of an OS or a product. + +You get a status "ok", "warning" or "critical" based on the limits. + +The status is "unknown" if a product or the eol date was not detected. + +It is customizable / extendable to detect other products that are not included in the delivered basic config. + +### Syntax + +```txt +./check_eol +______________________________________________________________________ + +CHECK EOL :: v1.5 + +(c) Institute for Medical Education - University of Bern +Licence: GNU GPL 3 +______________________________________________________________________ + +Check and of support of an OS or a product. +The dates are defined in the files check_eol-*.cfg +For detailed information see docs/20_Checks/check_eol.md + +USAGE + $ check_eol [-c CRITICAL] [-w WARING] PRODUCT VERSION + +PARAMETERS + PRODUCT set a product; known product keys are listed below + + centos + debian + mariadb + mysql + node + php + postgres + ruby + ubuntu + + VERSION set a version. + Autodetection: + There is a special handling vor version "detect". + You can set "os" as product to detect the (linux) distribution. + See examples below. + +OPTIONS + -c set critical limit; default 90 + -w set warning limit; default 365 + +EXAMPLES + check_eol php 8.1 + check_eol -w 100 -c 30 php 8.1 + check_eol os detect + check_eol php detect + +``` + +#### Parameters + +PRODUCT set a product; known product keys are listed below +VERSION set a version. + + Autodetection: + There is a special handling vor version "detect". + You can set "os" as product to detect the (linux) distribution. + See examples below. + +#### Options + + -c set critical limit; default 90 + -w set warning limit; default 365 + +### Examples + +``check_eol php 7.4`` + Show end of life for given php version 7.4 + +``check_eol -w 100 -c 30 php 7.4`` + Add custom critical and warning limits + +``check_eol os detect`` + Show end of life for current linux os. The distribution and the major version will be detected. + +``check_eol php detect`` + Show the end of life for the detected php version + +### Extend/ customize + +The check is build to be customizable. You can add + +* add your own end of life dates +* write a version detection for other products + +The related files are in 2 subdirectories with check_eol prefix: + +``` +> ls -1 check_eol-data/ check_eol-versiondetect/ +check_eol-data/: +databases.cfg +os.cfg +program-languages.cfg + +check_eol-versiondetect/: +autodetect-mysqlany* +autodetect-os* +detect-mariadb* +detect-mysql* +detect-node* +detect-php* +detect-postgres* +detect-ruby* +``` + +#### End of life dates + +The dates are defined in the files *check_eol-*.cfg*. +Those contain lines with parsed information that must start at the begin of line: + +* ``[Key]:[version]:[Date as YYYY-MM-DD]:[COMMENT]`` + * Key: name of the product in lowercase, i.e. "php", "centos" + * Version: version number, i.e. a major version i.e. "12" for Node or "7.4" for PHP + * Date as YYYY-MM-DD + * Comment: this is optional +* ``[Key]:METADATA for a product (can be multiline)`` + * This type is completely optional. You can use it to show general (version indepenendent) product infos. It will be shown as additional text for each version of a product + +Al other lines, like empty lines, lines starting with special characters are ignored. I use the hash to mark comments. + +Snippet: + + # -------------------------------------------- + centos:The CentOS Project + centos:website https://www.centos.org/ + # -------------------------------------------- + + centos:6:2020-11-30 + centos:7:2024-06-30 + centos:8:2029-05-31 + +Example output: + + $ check_eol centos 7 + OK [centos 7] ends on 2024-06-30 ... 1586 days left + + The CentOS Project + website https://www.centos.org/ + + Limit Info: warn below 365 days; critical below 90 days + +#### Files + +* check_eol-data/os.cfg - contains eol dates for debian, centos, ubuntu +* check_eol-data/check_eol-databases.cfg - Mariadb, PostgreSql +* check_eol-data/check_eol-program-languages.cfg - Php, NodeJS + +You can add your custom products and dates - it just must match *check_eol-*.cfg*. You should use a custom file name that does not conflict with delivered files. + +Suggestion: *check_eol-data/custom-[my category].cfg* + +#### Version detection + +If you use ``check_eol [product] [version]`` with an already known version in your monitoring check then the search for an eol date is done directly in the *cfg files (see above). + +If you wan to let detect the version use the keyword *detect* next to a product i.e. ``check_eol php detect``. +What happens is is uses a detection for the version number. Therefor it calls a script named *check_eol-versiondetect/detect-[PRODUCT]* - in our example for php ist is *check_eol-versiondetect/detect-php*. + +The scripts *check_eol-versiondetect/detect-[PRODUCT]* must return just a major version - or major and minor version without any other text. + +You can add your own scripts for other non existing products. The only rule is: it must output the version only. Your [PRODUCT] and the returned version will be scanned in *check_eol-*.cfg* to perform the eol check. diff --git a/docs/config.json b/docs/config.json index 6b291ff32f0459c84d495a5b57703ae3774a70c5..ba82dcfb17750957f69ada1a8f3b1daac5358c1e 100644 --- a/docs/config.json +++ b/docs/config.json @@ -3,7 +3,7 @@ "author": "Axel Hahn", "tagline": "Icinga checks written in Bash", "ignore": { - "files": ["20_Checks/zz_template_check_.md"], + "files": ["zz_template_check_.md"], "folders": ["99_Not_Ready"] }, "html": {