From e1cabb81d0183e5631dd6bc9520647fcd41215c7 Mon Sep 17 00:00:00 2001 From: "Hahn Axel (hahn)" <axel.hahn@unibe.ch> Date: Wed, 12 Feb 2025 09:45:24 +0100 Subject: [PATCH 1/8] update index page for all checks --- docs/20_Checks/_index.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/20_Checks/_index.md b/docs/20_Checks/_index.md index 53a6c04..497dc25 100644 --- a/docs/20_Checks/_index.md +++ b/docs/20_Checks/_index.md @@ -8,16 +8,18 @@ * [check_ceph_status](check_ceph_status.md) * [check_clientbackup](check_clientbackup.md) * [check_couchdb](check_couchdb.md) -* check_couchdb-lb +* [check_conn](check_conn.md) * [check_cpu](check_cpu.md) * [check_cronstatus](check_cronstatus.md) * [check_disk-io](check_disk-io.md) * [check_dns_responsetime](check_dns_responsetime.md) * [check_docker_info](check_docker_info.md) +* [check_docker_io](check_docker_io.md) * [check_docker_stats](check_docker_stats.md) * [check_dockercontainer_top](check_dockercontainer_top.md) * [check_eol](check_eol.md) * [check_fs_errors](check_fs_errors.md) +* [check_file_age](check_file_age.md) * [check_fs_writable](check_fs_writable.md) * [check_gitlab_tokens](check_gitlab_tokens.md) * [check_haproxy_health](check_haproxy_health.md) -- GitLab From a4ba462ed472c046b3532fa2b684cdc906223f10 Mon Sep 17 00:00:00 2001 From: "Hahn Axel (hahn)" <axel.hahn@unibe.ch> Date: Wed, 12 Feb 2025 10:04:05 +0100 Subject: [PATCH 2/8] check_snmp_data: add IML header in help --- check_snmp_data | 20 +++++++------------- check_snmp_includes | 9 +++++++++ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/check_snmp_data b/check_snmp_data index 8a8aedc..212c4f0 100755 --- a/check_snmp_data +++ b/check_snmp_data @@ -70,6 +70,7 @@ # 2022-10-25 v0.6 <axel.hahn@unibe.ch> fix empty value in performance data; shell fixes # 2023-05-05 v0.7 <axel.hahn@unibe.ch> source shared func, support snmpv3; add synoio # 2023-05-16 v0.8 <axel.hahn@unibe.ch> add about for general infos and without perf data +# 2025-02-12 v1.0 <axel.hahn@unibe.ch> add IML header in help # ====================================================================== . $(dirname $0)/inc_pluginfunctions @@ -77,7 +78,7 @@ # --- basic vars self_APPNAME=$( basename $0 | tr [:lower:] [:upper:] ) -self_APPVERSION=0.8 +self_APPVERSION=1.0 METHOD="" @@ -160,18 +161,11 @@ function showHelp(){ do METHOD=$(echo "$line" | cut -f 2 -d ":") descr=$(_cfg_getlabel) - printf " %-10s %-50s\n" "$METHOD" "$descr" + printf " %-10s %-50s\n" "$METHOD" "$descr" done ) cat <<EOH -______________________________________________________________________ - -$self_APPNAME -v$self_APPVERSION - -(c) Institute for Medical Education - University of Bern -Licence: GNU GPL 3 -______________________________________________________________________ +$( ph.showImlHelpHeader ) SNMP performance data of Synology storages. @@ -187,10 +181,10 @@ PARAMETERS: -f FILE read authentication from config file default: "/etc/icinga2/snmp.cfg" - -m method what to show - method is one of ... + -m METHOD + what to show; METHOD is one of ... $_methods - -v verbose output + -v verbose output CONFIG FILE: The config file can be multiline and has the syntax diff --git a/check_snmp_includes b/check_snmp_includes index 27aab59..c16e0c0 100644 --- a/check_snmp_includes +++ b/check_snmp_includes @@ -1,4 +1,13 @@ #!/bin/sh +# ====================================================================== +# +# Include file for SNMP related checks +# Used by +# - check_snmp_data +# - check_snmp_printer +# - check_snmp_synology +# +# ====================================================================== # ---------------------------------------------------------------------- # Variables -- GitLab From 941035572fb9d470ca7fd132cc1e78a94716e3ef Mon Sep 17 00:00:00 2001 From: "Hahn Axel (hahn)" <axel.hahn@unibe.ch> Date: Wed, 12 Feb 2025 10:04:21 +0100 Subject: [PATCH 3/8] update docs for snmp_data --- docs/20_Checks/check_snmp_data.md | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/docs/20_Checks/check_snmp_data.md b/docs/20_Checks/check_snmp_data.md index e7e488e..8c3efa3 100644 --- a/docs/20_Checks/check_snmp_data.md +++ b/docs/20_Checks/check_snmp_data.md @@ -25,11 +25,13 @@ Start the script without parameter to get the help. ```txt ______________________________________________________________________ -CHECK_SNMP_DATA -v0.8 +CHECK_SNMP_DATA +v1.0 (c) Institute for Medical Education - University of Bern Licence: GNU GPL 3 + +https://os-docs.iml.unibe.ch/icinga-checks/Checks/check_snmp_data.html ______________________________________________________________________ SNMP performance data of Synology storages. @@ -46,17 +48,17 @@ PARAMETERS: -f FILE read authentication from config file default: "/etc/icinga2/snmp.cfg" - -m method what to show - method is one of ... - about About... general device infos - cpu CPU usage - load System load - mem Memory status - netio Network IO - synodisc Synology Disc usage - synotemp Synology NAS temperature - synoio Synology Space IO - -v verbose output + -m METHOD + what to show; METHOD is one of ... + about About... general device infos + cpu CPU usage + load System load + mem Memory status + netio Network IO + synodisc Synology Disc usage + synotemp Synology NAS temperature + synoio Synology Space IO + -v verbose output CONFIG FILE: The config file can be multiline and has the syntax @@ -69,7 +71,6 @@ CONFIG FILE: EXAMPLE: check_snmp_data -h 192.168.100.12 -v -m cpu - ``` ## Examples -- GitLab From 28d87af8b24ce01fd8692d844e34c48ddfda503d Mon Sep 17 00:00:00 2001 From: "Hahn Axel (hahn)" <axel.hahn@unibe.ch> Date: Wed, 12 Feb 2025 11:11:45 +0100 Subject: [PATCH 4/8] snmp_printer: add help and debug param --- check_snmp_printer | 125 +++++++++++++++++++++++++++++++++------------ 1 file changed, 92 insertions(+), 33 deletions(-) diff --git a/check_snmp_printer b/check_snmp_printer index 811b544..0d07fab 100755 --- a/check_snmp_printer +++ b/check_snmp_printer @@ -11,24 +11,11 @@ # /usr/lib64/nagios/plugins/check_snmp_printer_v2.0.1 # except "-c <script>" # -# TODO: IML like help -# -# USAGE -# check_snmp_printer -H <host|ip> --<what> -# check_snmp_printer -H <host|ip> -c <script> --<what> -# -# <host>|<ip> target to connect -# <what> what information will be shown -# --consum -# --messages -# --pagecount -# --trays -# <script> script to execute with full path -# # ------------------------------------------------------------ # 2021-03-22 <axel.hahn@iml.unibe.ch> v0.1 # 2023-09-18 <axel.hahn@iml.unibe.ch> v0.2 snmpv3 support # 2023-10-12 <axel.hahn@iml.unibe.ch> v0.3 parameter for custom script; detect debian +# 2025-02-12 <axel.hahn@unibe.ch> v1.0 add help and debug param # ============================================================ # ------------------------------------------------------------ @@ -38,6 +25,9 @@ . $( dirname $0 )/inc_pluginfunctions . $( dirname $0 )/check_snmp_includes +self_APPNAME=$( basename $0 | tr [:lower:] [:upper:] ) +self_APPVERSION=1.0 + debug=0 # check='/usr/lib64/nagios/plugins/check_snmp_printer' @@ -45,15 +35,80 @@ debug=0 nagiosDir='/usr/lib64/nagios/plugins' myscript="check_snmp_printer_v2.0.1" case "$( ph.getOS)" in - debian) - nagiosDir='/usr/lib/nagios/plugins' - ;; + debian) + nagiosDir='/usr/lib/nagios/plugins' + ;; esac +#--------------------------------------------------- +# --- show usage +function showHelp(){ + _self=$( basename $0 ) +cat <<EOH +$( ph.showImlHelpHeader ) + +This is a wrapper for the check_snmp_printer plugin. +Maybe you want to upgrade it from +<https://github.com/Tylan/check_snmp_printer/tree/master> + +The wrapper does + +- scan for snmp auth parameters of given host by check_snmp_includes +- adds snmp timeout +- executes check_snmp_printer with given other params + +USAGE: + $_self [-d] [-c SCRIPT] -H SNMPTARGET [other params] + +PARAMETERS: + + -d, --debug (as 1st param) + Debug mode: shows all generated params. + "-d" or "--debug" will be removed from params for + check_snmp_printer script + + -c SCRIPT + Set script to execute with full path + default: $nagiosDir/$myscript + + -H HOSTNAME + required: as fqdn or ip address; default: localhost + + All other params for check_snmp_printer, eg. + --consum + --messages + --pagecount + --trays + +CONFIG FILE: + The config file can be multiline and has the syntax + [SNMPTARGET[,target2]]:[auth parameters] + The auth parameters set the version and all needed values to connect. + Snmp v2 uses a community string. + Snmp v3 is highly recommended (you should disable Snmp v2) and needs + a user and password. + +EXAMPLE: + $_self -H 192.168.100.12 --consum + +EOH +} + # ------------------------------------------------------------ # MAIN # ------------------------------------------------------------ + +# show help +if [ "$#" -eq 0 ]; then + showHelp + exit 0 +fi +if [ "$1" = "--debug" ] || [ "$1" = "-d" ]; then + debug=1 + shift +fi + sParams="$*" # find host behind param -H @@ -64,29 +119,33 @@ check=$( echo $sParams | sed -Ee 's#.*\-c\ ([0-9a-z\.\-_/]*).*#\1#' ) test "$check" = "$sParams" && check="${nagiosDir}/${myscript}" test "$check" = "$sParams" || sParams=$( echo $sParams | sed -Ee 's#\-c\ ([0-9a-z\.\-_/]*)##' ) -# find SNMPTARGET in config +# find SNMPTARGET in config to add snmp auth parameters test -z "$SNMPAUTH" && read_config sParams+=" $SNMPAUTH" - +# find what to show ... it is more for debug message what=$( echo $sParams | sed -Ee 's#.*\-\-([a-z]*).*#\1#' ) case "$what" in - consum) - what="Consumables" - ;; - messages) - what="Messages of the printer" - ;; - pagecount) - what="Number of printed pages" - ;; - trays) - what="Status of trays for paper" - sParams="$sParams --nofeeder" - ;; + consum) + what="Consumables" + ;; + messages) + what="Messages of the printer" + ;; + pagecount) + what="Number of printed pages" + ;; + trays) + what="Status of trays for paper" + sParams="$sParams --nofeeder" + ;; + esac +# add our global snmp timeout +sParams+=" -t $SNMPTIMEOUT" + test "$debug" = "1" && ( echo "$what:"; echo calling $check $sParams ; echo ) -$check $sParams -t $SNMPTIMEOUT +$check $sParams # ------------------------------------------------------------ -- GitLab From 7f029b84398128df6a30b749ff6b9a91c6e7aea6 Mon Sep 17 00:00:00 2001 From: "Hahn Axel (hahn)" <axel.hahn@unibe.ch> Date: Wed, 12 Feb 2025 11:12:02 +0100 Subject: [PATCH 5/8] add markdown help for snmp_printer --- docs/20_Checks/check_snmp_printer.md | 100 +++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 docs/20_Checks/check_snmp_printer.md diff --git a/docs/20_Checks/check_snmp_printer.md b/docs/20_Checks/check_snmp_printer.md new file mode 100644 index 0000000..4f69e96 --- /dev/null +++ b/docs/20_Checks/check_snmp_printer.md @@ -0,0 +1,100 @@ +## Check SNMP printer + +Script: `check_snmp_printer` + +**check_snmp_printer** is a wrapper for Nagios plugin check_snmp_printer. Its main task is to fetch SNMP authentication parameters from a config file and then call the Nagios check. + +## Requirements + +* snmpget +* snmpwalk +* check_snmp_printer or an update of it eg. <https://github.com/Tylan/check_snmp_printer/tree/master> + +## Standalone installation + +From this repository ypu need next to this script: + +* `inc_pluginfunctions` shared function for all IML checks written in bash +* `check_snmp_includes` with a shared snmp config reader + +## Syntax + +Start the script without parameter to get the help. + +```txt +______________________________________________________________________ + +CHECK_SNMP_PRINTER +v1.0 + +(c) Institute for Medical Education - University of Bern +Licence: GNU GPL 3 + +https://os-docs.iml.unibe.ch/icinga-checks/Checks/check_snmp_printer.html +______________________________________________________________________ + +This is a wrapper for the check_snmp_printer plugin. +Maybe you want to upgrade it from +<https://github.com/Tylan/check_snmp_printer/tree/master> + +The wrapper does + +- scan for snmp auth parameters of given host by check_snmp_includes +- adds snmp timeout +- executes check_snmp_printer with given other params + +USAGE: + check_snmp_printer [-d] [-c SCRIPT] -H SNMPTARGET [other params] + +PARAMETERS: + + -d, --debug (as 1st param) + Debug mode: shows all generated params. + "-d" or "--debug" will be removed from params for + check_snmp_printer script + + -c SCRIPT + Set script to execute with full path + default: /usr/lib64/nagios/plugins/check_snmp_printer_v2.0.1 + + -H HOSTNAME + required: as fqdn or ip address; default: localhost + + All other params for check_snmp_printer, eg. + --consum + --messages + --pagecount + --trays + +CONFIG FILE: + The config file can be multiline and has the syntax + [SNMPTARGET[,target2]]:[auth parameters] + The auth parameters set the version and all needed values to connect. + Snmp v2 uses a community string. + Snmp v3 is highly recommended (you should disable Snmp v2) and needs + a user and password. + +EXAMPLE: + check_snmp_printer -H 192.168.100.12 --consum + +``` + +## Examples + +### Messages of the printer + +`./check_snmp_data -H 192.168.100.12 --messages` + +### Consumables + +`./check_snmp_data -H 192.168.100.12 --consum` + +### Number of pages printed + +`./check_snmp_data -H 192.168.100.12 --pagecount` + +### Status of trays for paper + +`./check_snmp_data -H 192.168.100.12 --trays` + +Remark: when using --trays the param `--nofeeder` will be inserted too. -- GitLab From d0b48f6419c0cea981ddc73ab4ac18f55f4b4153 Mon Sep 17 00:00:00 2001 From: "Hahn Axel (hahn)" <axel.hahn@unibe.ch> Date: Wed, 12 Feb 2025 11:12:50 +0100 Subject: [PATCH 6/8] link snmp_printer in index page --- docs/20_Checks/_index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/20_Checks/_index.md b/docs/20_Checks/_index.md index 497dc25..eab502c 100644 --- a/docs/20_Checks/_index.md +++ b/docs/20_Checks/_index.md @@ -45,7 +45,7 @@ * [check_requirements](check_requirements.md) * [check_smartstatus](check_smartstatus.md) * [check_snmp_data](check_snmp_data.md) -* check_snmp_printer +* [check_snmp_printer](check_snmp_printer.md) * check_snmp_switch * [check_snmp_synology](check_snmp_synology.md) * check_ssl -- GitLab From 7a3bdcea68bdf11488f05a1d73b275705c0c41ff Mon Sep 17 00:00:00 2001 From: "Hahn Axel (hahn)" <axel.hahn@unibe.ch> Date: Wed, 12 Feb 2025 11:18:29 +0100 Subject: [PATCH 7/8] snmp_synology update header in help with link to online help --- check_snmp_synology | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/check_snmp_synology b/check_snmp_synology index 9a572ff..8d2c01e 100755 --- a/check_snmp_synology +++ b/check_snmp_synology @@ -5,6 +5,7 @@ # 03.05.2023 v1.2 Axel Hahn: support Snmpv3 connections # 09.05.2023 v1.3 Axel Hahn: allow complete check or single check(s) # 12.05.2023 v1.4 Axel Hahn: no raid size check (DSM 5.x) +# 12.02.2025 v1.5 Axel Hahn: update header in help with link to online help # ---------------------------------------------------------------------- # this plugin check the health of your Synology NAS # - System status (Power, Fans) @@ -24,7 +25,7 @@ # --- basic vars self_APPNAME=$( basename $0 | tr [:lower:] [:upper:] ) -self_APPVERSION=1.4 +self_APPVERSION=1.5 SNMPOUTPUT= option_found=0 @@ -72,19 +73,10 @@ FLAG_UPDATE=1 FLAG_TEMPERATURE=1 _self=$( basename $0 ) -USAGE=" -______________________________________________________________________ - -$self_APPNAME -v$self_APPVERSION - -Based on script of Nicolas Ordonez. - -Institute for Medical Education - University of Bern -Licence: GNU GPL 3 -______________________________________________________________________ +USAGE="$( ph.showImlHelpHeader ) Check health of a Synology drive using SNMP. +Based on script of Nicolas Ordonez. SYNTAX: $_self [options] -h TARGET -- GitLab From 0fecb6def974d136168525de050ad754b879eaef Mon Sep 17 00:00:00 2001 From: "Hahn Axel (hahn)" <axel.hahn@unibe.ch> Date: Wed, 12 Feb 2025 11:18:48 +0100 Subject: [PATCH 8/8] update markdown help for snmp_synology --- docs/20_Checks/_index.md | 1 - docs/20_Checks/check_snmp_synology.md | 11 +++--- docs/fix_h1.sh | 54 +++++++++++++++++++++++++++ docs/fix_script.sh | 40 ++++++++++++++++++++ zz_test_help.sh | 48 ++++++++++++++++++++++++ 5 files changed, 148 insertions(+), 6 deletions(-) create mode 100755 docs/fix_h1.sh create mode 100755 docs/fix_script.sh create mode 100755 zz_test_help.sh diff --git a/docs/20_Checks/_index.md b/docs/20_Checks/_index.md index eab502c..869a346 100644 --- a/docs/20_Checks/_index.md +++ b/docs/20_Checks/_index.md @@ -46,7 +46,6 @@ * [check_smartstatus](check_smartstatus.md) * [check_snmp_data](check_snmp_data.md) * [check_snmp_printer](check_snmp_printer.md) -* check_snmp_switch * [check_snmp_synology](check_snmp_synology.md) * check_ssl * [check_ssl_certs](check_ssl_certs.md) diff --git a/docs/20_Checks/check_snmp_synology.md b/docs/20_Checks/check_snmp_synology.md index 24d722a..76d550d 100644 --- a/docs/20_Checks/check_snmp_synology.md +++ b/docs/20_Checks/check_snmp_synology.md @@ -23,16 +23,17 @@ Start the script without parameter to get the help. ```txt ______________________________________________________________________ -CHECK_SNMP_SYNOLOGY -v1.4 +CHECK_SNMP_SYNOLOGY +v1.5 -Based on script of Nicolas Ordonez. - -Institute for Medical Education - University of Bern +(c) Institute for Medical Education - University of Bern Licence: GNU GPL 3 + +https://os-docs.iml.unibe.ch/icinga-checks/Checks/check_snmp_synology.html ______________________________________________________________________ Check health of a Synology drive using SNMP. +Based on script of Nicolas Ordonez. SYNTAX: check_snmp_synology [options] -h TARGET diff --git a/docs/fix_h1.sh b/docs/fix_h1.sh new file mode 100755 index 0000000..ee2488b --- /dev/null +++ b/docs/fix_h1.sh @@ -0,0 +1,54 @@ +#!/bin/bash + +tmpfile=/tmp/tmp_myfile_$USER__$$ + +cd "$( dirname "$0" )" + +for f in *.md; do + if head "$f" | grep -q "^# "; then + echo + echo ">>>>> FIX $f" + echo + cp -p "$f" "$tmpfile" + + if grep -q "^## Introduction" "$f"; then + echo "Replace '## Introduction'" + sed -i -e "s/^## Introduction.*//" "$tmpfile" + head -1 "$f" | tail -1 | grep "." && sed -i -e '2,3d' "$tmpfile" + + # make 1st h1 smaller + sed -i -e "0,/^# /{s/^# /## /}" "$tmpfile" + + else + echo "Move Headers" + if grep "^###### " "$f"; then + echo "ABORT: H6 was found that cannot moved to smaller level." + exit 1 + fi + for header in "#####" "####" "###" "##" "#" + do + sed -i -e "s/^$header /#$header /g" "$tmpfile" + done + fi + diff -u --color "$f" "$tmpfile" + echo + read -p "Apply changes on '$f' [Y/n]? > " apply + if [ "$apply" = "" ] || [ "$apply" = "y" ]|| [ "$apply" = "Y" ]; then + echo "Applying ..." + mv "$tmpfile" "$f" + else + echo "Keeping current version." + rm "$tmpfile" + fi + sleep 1 + echo + echo + echo + echo + echo + echo + echo ---------------------------------------------------------------------- + else + echo "OK $f" + fi +done \ No newline at end of file diff --git a/docs/fix_script.sh b/docs/fix_script.sh new file mode 100755 index 0000000..f8def54 --- /dev/null +++ b/docs/fix_script.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +tmpfile=/tmp/tmp_myfile_$USER__$$ + +cd "$( dirname "$0" )" + +for f in check*.md; do + if ! head "$f" | grep -q "^Script: \`"; then + myscript="${f//.md/}" + echo + echo ">>>>> FIX $f" + echo + sed -n "1,2p" "$f" > "$tmpfile" + echo "Script: \`${myscript}\`" >> "$tmpfile" + echo >> "$tmpfile" + sed -n "3,\$p" "$f" >> "$tmpfile" + + if ! diff -u --color "$f" "$tmpfile"; then + echo + read -p "Apply changes on '$f' [Y/n]? > " apply + if [ "$apply" = "" ] || [ "$apply" = "y" ]|| [ "$apply" = "Y" ]; then + echo "Applying ..." + mv "$tmpfile" "$f" + else + echo "Keeping current version." + rm "$tmpfile" + fi + sleep 1 + echo + echo + echo + echo + echo + echo + echo ---------------------------------------------------------------------- + fi + else + echo "OK $f" + fi +done \ No newline at end of file diff --git a/zz_test_help.sh b/zz_test_help.sh new file mode 100755 index 0000000..0a92a96 --- /dev/null +++ b/zz_test_help.sh @@ -0,0 +1,48 @@ +#!/bin/bash +cd "$( dirname "$0" )" || exit +typeset -i iTotal + +typeset -i iErr +typeset -i iWarn + + +# ---------------------------------------------------------------------- +# FUNCTIONS +# ---------------------------------------------------------------------- + +function getChecks(){ + grep "inc_pluginfunctions" * 2>/dev/null | cut -f 1 -d ":" | grep -vE "^(zz_|inc)" +} + +# ---------------------------------------------------------------------- +# MAIN +# ---------------------------------------------------------------------- + +iTotal=$( getChecks | wc -l ) +echo +echo "CHECK IML CHECKS - $( date )" +echo +for check in $( getChecks ) +do + if ./$check -h 2>/dev/null| grep -q "https://os-docs.iml.unibe.ch"; then + # echo "✅ OK $check" + url=$( ./$check -h | grep "https://os-docs.iml.unibe.ch" ) + if curl -sI $url | grep -q "200 OK"; then + echo "✅ OK : $check" + else + echo "âš ï¸ WARN : $check - $url" + iWarn+=1 + fi + else + echo "⌠ERROR: $check" + iErr+=1 + # ./$check -h + fi +done + +echo +echo "---- Total : $iTotal" +echo " Errors : $iErr checks with wrong help" +echo " Warnings : $iWarn checks with wrong url" +echo +# ---------------------------------------------------------------------- -- GitLab