Select Git revision
check_disk-io
-
Hahn Axel (hahn) authoredHahn Axel (hahn) authored
check_snmp_data 7.34 KiB
#!/usr/bin/env bash
# ======================================================================
#
# NAGIOS / ICINGA CHECK :: check_snmp_data
# this plugin checks snmp performance data
#
# DOCS:
# - Synology - see docs:
# https://global.download.synology.com/download/Document/Software/DeveloperGuide/Firmware/DSM/All/enu/Synology_DiskStation_MIB_Guide.pdf
#
# - IODs uc davis http://oidref.com/1.3.6.1.4.1.2021
#
# ----------------------------------------------------------------------
#
# SYNTAX:
# label --> DATA:[method]:label:[text]
# n x data --> DATA:[method]:data:[perf-label]:[oid]:[optional unit]:[loop oid]
#
# DATA:cpu:label:CPU usage
# DATA:cpu:data:cpu-user:1.3.6.1.4.1.2021.11.9.0:%
# DATA:cpu:data:cpu-system:1.3.6.1.4.1.2021.11.10.0:%
# DATA:cpu:data:cpu-idle:1.3.6.1.4.1.2021.11.11.0:%
#
# DATA:load:label:System load
# DATA:load:data:load1:1.3.6.1.4.1.2021.10.1.5.1:
# DATA:load:data:load5:1.3.6.1.4.1.2021.10.1.5.2:
# DATA:load:data:load15:1.3.6.1.4.1.2021.10.1.5.3:
#
# DATA:netio:label:Network IO (experimental)
# DATA:netio:data:in:1.3.6.1.2.1.4.3.0:
# DATA:netio:data:out:1.3.6.1.2.1.4.10.0:
#
# DATA:synotemp:label:Synology NAS temperature
# DATA:synotemp:data:temp:1.3.6.1.4.1.6574.1.2.0:°C
#
# DATA:disc:label:Disc usage
# DATA:disc:data:disc-free:1.3.6.1.4.1.6574.3.1.1.2::1.3.6.1.4.1.6574.3.1.1.4
# 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
# 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
# --- basic vars
self_APPNAME=$( basename $0 | tr [:lower:] [:upper:] )
self_APPVERSION=0.6
SNMPCOMMUNITY="public"
SNMPVERSION="2c"
SNMPWALK=$(which snmpwalk)
SNMPGET=$(which snmpget)
HOSTNAME="127.0.0.1"
METHOD=""
# --- OID declarations
# OID_syno="1.3.6.1.4.1.6574"
# OID_ucdavis="1.3.6.1.4.1.2021" # University of California, Davis - private UCD SNMP MIB extensions
# --- output variables
SYNO=""
out=""
#---------------------------------------------------
# FUNCTIONS
#---------------------------------------------------
# --- write verbose text
_wd()
{
if [ "$verbose" = "yes" ] ; then
out="${out}$*
" ; fi
}
#---------------------------------------------------
# --- get config entries in the DATA comment lines
# get line(s) for config
# param string one of label|data
_cfg_reader(){
grep "^# DATA:$METHOD:$1:" $0
}
_cfg_getlabel(){
_cfg_reader "label" | cut -f 4- -d ":"
}
_cfg_dataitem(){
_cfg_reader "data" | cut -f $1 -d ":" | while read item
do
echo -n "$item "
done
}
# get a list existing methods
_cfg_getMethods(){
grep "^# DATA:.*:label:" $0 | cut -f 2 -d ":"
}
#---------------------------------------------------
# --- get a value from SNMP output data
# global string $SYNO output of snmpget
# param string mib string
_getresult(){
echo "$SYNO" | grep "${1} " | cut -d "=" -f2 | cut -f 2- -d " "
}
# --- get a value from SNMP output data
# param string mib string
_get(){
_getresult $1 | cut -d ":" -f2 | cut -f 2- -d " "
}
# is given oid a counter?
# function resturns "true" or "false"
_iscounter(){
_getresult $1 | cut -d ":" -f1 | grep -i "Counter" >/dev/null
if [ $? -eq 0 ]; then
echo "true"
else
echo "false"
fi
}
#---------------------------------------------------
# --- show usage
function showHelp(){
cat <<EOH
______________________________________________________________________
$self_APPNAME
v$self_APPVERSION
(c) Institute for Medical Education - University of Bern
Licence: GNU GPL 3
______________________________________________________________________
SNMP performance data of Synology storages.
USAGE:
./check_snmp_data -h hostname [-C communitystring] -m method
PARAMETERS:
-h hostname as fqdn or ip address
-C communitystr optional: community string for snmp; default is $SNMPCOMMUNITY
-v verbose output
-m method what to show
method is one of ...
EOH
# --- dynamic: add current methods
_cfg_getMethods | while read -r line
do
METHOD=$(echo "$line" | cut -f 1 -d ":")
descr=$(_cfg_getlabel)
printf " %-10s %-50s\n" "$METHOD" "$descr"
done
# --- finish usage
cat <<EOH2
EXAMPLE:
./check_snmp_data -h 192.168.100.12 -v -m cpu
EOH2
ph.abort ""
}
#---------------------------------------------------
# MAIN
#---------------------------------------------------
while getopts h:m:v OPTNAME; do
case "$OPTNAME" in
h)
HOSTNAME="$OPTARG"
option_found=1
;;
C)
SNMPCOMMUNITY="$OPTARG"
;;
m)
METHOD="$OPTARG"
;;
v)
verbose="yes"
_wd ""
;;
*)
usage
;;
esac
done
if [ "$option_found" = "0" ] || [ "$HOSTNAME" = "" ] ; then
usage
# remark: script aborts ...
fi
# --- read metadata of the selected METHOD
info=$(_cfg_getlabel)
if [ -z "$info" ]; then
echo "ERROR: unknown METHOD [$METHOD]"
showHelp
fi
prflist=( $(_cfg_dataitem 4) )
oidlist=( $(_cfg_dataitem 5) )
unitlist=( $(_cfg_dataitem 6) )
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)
declare -a tmpPrflist=()
declare -a tmpOidlist=()
declare -a tmpUnitlist=()
for i in $(seq 1 $nb);
do
for j in $(seq 1 ${#looplist[@]})
do
tmpPrflist+=("${prflist[$(($j-1))]}.$(($i-1))")
tmpOidlist+=("${looplist[$(($j-1))]}.$(($i-1))")
tmpUnitlist+=("${unitlist[$(($j-1))]}")
done
done
prflist=( "${tmpPrflist[@]}" )
oidlist=( "${tmpOidlist[@]}" )
unitlist=( "${tmpUnitlist[@]}" )
fi
# --- SNMPGET to all wanted oids
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[*]}
ph.abort "Problem with SNMP request"
fi
# --- performance data
typeset -i value
for index in ${!oidlist[*]}
do
label="${prflist[$index]}"
value=$(_get ${oidlist[$index]})
unit="${unitlist[$index]}"
# handle loop data
if [ -n "$looplist" ]; then
_wd "$( printf '%-14s %s %s' $label $value $unit )"
else
# handle counter data
if [ "$(_iscounter ${oidlist[$index]})" = "true" ]; then
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
_wd "$( printf '%-14s %s %s' $label $value $unit )"
fi
fi
ph.perfadd "${label}" "${value}"
done
# --- output
ph.status "SNMP performance data :: $info $out"
ph.exit