Skip to content
Snippets Groups Projects
Commit 1c9289ae authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

fix empty value in performance data; shell fixes

parent 054db9e3
No related branches found
No related tags found
1 merge request!51Fix SNMP netio
...@@ -38,15 +38,19 @@ ...@@ -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 # 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-11 <axel.hahn@iml.unibe.ch> initial version
# 2020-08-13 <axel.hahn@iml.unibe.ch> add host in label for counter data # 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.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 # --- basic vars
ABOUT="SNMP performance data v0.4" self_APPNAME=$( basename $0 | tr [:lower:] [:upper:] )
self_APPVERSION=0.6
SNMPCOMMUNITY="public" SNMPCOMMUNITY="public"
SNMPVERSION="2c" SNMPVERSION="2c"
SNMPWALK=$(which snmpwalk) SNMPWALK=$(which snmpwalk)
...@@ -125,14 +129,18 @@ _iscounter(){ ...@@ -125,14 +129,18 @@ _iscounter(){
#--------------------------------------------------- #---------------------------------------------------
# --- show usage # --- show usage
usage() function showHelp(){
{ cat <<EOH
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 SNMP performance data of Synology storages.
GNU GPL 3.0
USAGE: USAGE:
./check_snmp_data -h hostname [-C communitystring] -m method ./check_snmp_data -h hostname [-C communitystring] -m method
...@@ -146,11 +154,11 @@ PARAMETERS: ...@@ -146,11 +154,11 @@ PARAMETERS:
EOH EOH
# --- dynamic: add current methods # --- dynamic: add current methods
_cfg_getMethods | while read line _cfg_getMethods | while read -r line
do do
METHOD=`echo $line | cut -f 1 -d ":"` METHOD=$(echo "$line" | cut -f 1 -d ":")
descr=$(_cfg_getlabel) descr=$(_cfg_getlabel)
printf " %-10s %-50s\n" $METHOD "$descr" printf " %-10s %-50s\n" "$METHOD" "$descr"
done done
# --- finish usage # --- finish usage
...@@ -199,8 +207,8 @@ fi ...@@ -199,8 +207,8 @@ fi
# --- read metadata of the selected METHOD # --- read metadata of the selected METHOD
info=$(_cfg_getlabel) info=$(_cfg_getlabel)
if [ -z "$info" ]; then if [ -z "$info" ]; then
echo ERROR: unknown METHOD [$METHOD] echo "ERROR: unknown METHOD [$METHOD]"
usage showHelp
fi fi
prflist=( $(_cfg_dataitem 4) ) prflist=( $(_cfg_dataitem 4) )
...@@ -210,14 +218,14 @@ looplist=( $(_cfg_dataitem 7) ) ...@@ -210,14 +218,14 @@ looplist=( $(_cfg_dataitem 7) )
# --- check for looplist # --- check for looplist
if [ -n "$looplist" ]; then 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 tmpPrflist=()
declare -a tmpOidlist=() declare -a tmpOidlist=()
declare -a tmpUnitlist=() declare -a tmpUnitlist=()
for i in `seq 1 $nb`; for i in $(seq 1 $nb);
do do
for j in `seq 1 ${#looplist[@]}` for j in $(seq 1 ${#looplist[@]})
do do
tmpPrflist+=("${prflist[$(($j-1))]}.$(($i-1))") tmpPrflist+=("${prflist[$(($j-1))]}.$(($i-1))")
tmpOidlist+=("${looplist[$(($j-1))]}.$(($i-1))") tmpOidlist+=("${looplist[$(($j-1))]}.$(($i-1))")
...@@ -230,7 +238,7 @@ if [ -n "$looplist" ]; then ...@@ -230,7 +238,7 @@ if [ -n "$looplist" ]; then
fi fi
# --- SNMPGET to all wanted oids # --- 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 if [ $? -ne 0 ] ; then
$SNMPGET -One -t 10 -v $SNMPVERSION -c $SNMPCOMMUNITY $HOSTNAME ${oidlist[*]} $SNMPGET -One -t 10 -v $SNMPVERSION -c $SNMPCOMMUNITY $HOSTNAME ${oidlist[*]}
...@@ -239,6 +247,8 @@ fi ...@@ -239,6 +247,8 @@ fi
# --- performance data # --- performance data
typeset -i value
for index in ${!oidlist[*]} for index in ${!oidlist[*]}
do do
label="${prflist[$index]}" label="${prflist[$index]}"
...@@ -251,7 +261,7 @@ do ...@@ -251,7 +261,7 @@ do
else else
# handle counter data # handle counter data
if [ "$(_iscounter ${oidlist[$index]})" = "true" ]; then 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 )" _wd "$( printf '%-14s total: %-14s delta: %6s %s per sec' $label $value $value2 $unit )"
value=$value2 value=$value2
else else
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment