diff --git a/.gitignore b/.gitignore index b3322408e4f59d645cceadfe07eac5887d7331c2..ec00e31fbe6c87cbaa30be4619a98c493798761a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ check_smart.pl paramtest check_snmp_syno.sh check-cpu.sh +static/* \ No newline at end of file diff --git a/check_snmp_data b/check_snmp_data index 954613f550dbf9fc8e3a81a5f49de944cb9a6b5f..7609dfb0f93d7f606de8df9fd8d14f1f701061de 100755 --- a/check_snmp_data +++ b/check_snmp_data @@ -38,15 +38,19 @@ # DATA:disc:data:disc-space:1.3.6.1.4.1.6574.3.1.1.2::1.3.6.1.4.1.6574.3.1.1.5 # # ---------------------------------------------------------------------- -# 2020-08-11 <axel.hahn@iml.unibe.ch> initial version -# 2020-08-13 <axel.hahn@iml.unibe.ch> add host in label for counter data -# 2022-10-21 v0.4 <axel.hahn@unibe.ch> remove grep: warning: stray \ before white space +# 2020-08-11 <axel.hahn@iml.unibe.ch> initial version +# 2020-08-13 <axel.hahn@iml.unibe.ch> add host in label for counter data +# 2022-10-21 v0.4 <axel.hahn@unibe.ch> remove grep: warning: stray \ before white space +# 2022-10-21 v0.5 <andrea.gottsponer@unibe.ch> remove grep: warning: stray \ before white space +# 2022-10-25 v0.6 <axel.hahn@unibe.ch> fix empty value in performance data; shell fixes # ====================================================================== -. `dirname $0`/inc_pluginfunctions +. $(dirname $0)/inc_pluginfunctions # --- basic vars -ABOUT="SNMP performance data v0.4" +self_APPNAME=$( basename $0 | tr [:lower:] [:upper:] ) +self_APPVERSION=0.6 + SNMPCOMMUNITY="public" SNMPVERSION="2c" SNMPWALK=$(which snmpwalk) @@ -125,14 +129,18 @@ _iscounter(){ #--------------------------------------------------- # --- show usage -usage() -{ - cat <<EOH +function showHelp(){ +cat <<EOH +______________________________________________________________________ + +$self_APPNAME +v$self_APPVERSION -$ABOUT +(c) Institute for Medical Education - University of Bern +Licence: GNU GPL 3 +______________________________________________________________________ -University of Bern * Institute of Medical Education -GNU GPL 3.0 +SNMP performance data of Synology storages. USAGE: ./check_snmp_data -h hostname [-C communitystring] -m method @@ -146,11 +154,11 @@ PARAMETERS: EOH # --- dynamic: add current methods - _cfg_getMethods | while read line + _cfg_getMethods | while read -r line do - METHOD=`echo $line | cut -f 1 -d ":"` + METHOD=$(echo "$line" | cut -f 1 -d ":") descr=$(_cfg_getlabel) - printf " %-10s %-50s\n" $METHOD "$descr" + printf " %-10s %-50s\n" "$METHOD" "$descr" done # --- finish usage @@ -199,8 +207,8 @@ fi # --- read metadata of the selected METHOD info=$(_cfg_getlabel) if [ -z "$info" ]; then - echo ERROR: unknown METHOD [$METHOD] - usage + echo "ERROR: unknown METHOD [$METHOD]" + showHelp fi prflist=( $(_cfg_dataitem 4) ) @@ -210,14 +218,14 @@ looplist=( $(_cfg_dataitem 7) ) # --- check for looplist if [ -n "$looplist" ]; then - nb=`$SNMPWALK -OQne -t 10 -v $SNMPVERSION -c $SNMPCOMMUNITY $HOSTNAME ${oidlist[*]} 2> /dev/null | wc -l` + nb=$($SNMPWALK -OQne -t 10 -v $SNMPVERSION -c $SNMPCOMMUNITY $HOSTNAME ${oidlist[*]} 2> /dev/null | wc -l) declare -a tmpPrflist=() declare -a tmpOidlist=() declare -a tmpUnitlist=() - for i in `seq 1 $nb`; + for i in $(seq 1 $nb); do - for j in `seq 1 ${#looplist[@]}` + for j in $(seq 1 ${#looplist[@]}) do tmpPrflist+=("${prflist[$(($j-1))]}.$(($i-1))") tmpOidlist+=("${looplist[$(($j-1))]}.$(($i-1))") @@ -230,7 +238,7 @@ if [ -n "$looplist" ]; then fi # --- SNMPGET to all wanted oids -SYNO=`$SNMPGET -One -t 10 -v $SNMPVERSION -c $SNMPCOMMUNITY $HOSTNAME ${oidlist[*]} 2> /dev/null` +SYNO=$($SNMPGET -One -t 10 -v $SNMPVERSION -c $SNMPCOMMUNITY $HOSTNAME ${oidlist[*]} 2> /dev/null) if [ $? -ne 0 ] ; then $SNMPGET -One -t 10 -v $SNMPVERSION -c $SNMPCOMMUNITY $HOSTNAME ${oidlist[*]} @@ -239,6 +247,8 @@ fi # --- performance data +typeset -i value + for index in ${!oidlist[*]} do label="${prflist[$index]}" @@ -251,7 +261,7 @@ do else # handle counter data if [ "$(_iscounter ${oidlist[$index]})" = "true" ]; then - value2=`ph.perfdeltaspeed "snmp-data-${HOSTNAME}-${method}-${label}" $value` + value2=$(ph.perfdeltaspeed "snmp-data-${HOSTNAME}-${method}-${label}" $value) _wd "$( printf '%-14s total: %-14s delta: %6s %s per sec' $label $value $value2 $unit )" value=$value2 else diff --git a/docs/20_Checks/check_snmp_data.md b/docs/20_Checks/check_snmp_data.md index 57a512316b01229410746eb6f91f85675940a5f1..8a182e40d101aab25694354d94eebbe11bbf7e82 100644 --- a/docs/20_Checks/check_snmp_data.md +++ b/docs/20_Checks/check_snmp_data.md @@ -4,22 +4,23 @@ **check_snmp_data** is a plugin for fetching performance data with a set of given OIDs. -It can handle current values (i.e. load or cpu usage) and counter values (i.e. network io). +It can handle current values (i.e. load / cpu usage / disc usage) and counter values (i.e. network io). ## Syntax -``$ check_snmp_data -h HOSTNAME [-C COOMMUNITYSTRING] -v -m METHOD`` - -### Parameters - -Starting the script without parameters shows a help. +Start the script without parameter to get the help. ```txt +______________________________________________________________________ + +CHECK_SNMP_DATA +v0.6 -SNMP performance data v1.0 +(c) Institute for Medical Education - University of Bern +Licence: GNU GPL 3 +______________________________________________________________________ -University of Bern * Institute of Medical Education -GNU GPL 3.0 +SNMP performance data of Synology storages. USAGE: ./check_snmp_data -h hostname [-C communitystring] -m method @@ -34,6 +35,7 @@ PARAMETERS: load System load netio Network IO (experimental) synotemp Synology NAS temperature + disc Disc usage EXAMPLE: ./check_snmp_data -h 192.168.100.12 -v -m cpu