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

update snmp synology; added snmp performance data

parent 092c1561
No related branches found
No related tags found
No related merge requests found
#!/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]
#
# 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
#
# ----------------------------------------------------------------------
# 2020-08-11 <axel.hahn@iml.unibe.ch> initial version
# ======================================================================
. `dirname $0`/inc_pluginfunctions
# --- basic vars
ABOUT="SNMP performance data v0.2"
SNMPCOMMUNITY="public"
SNMPVERSION="2c"
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
usage()
{
cat <<EOH
$ABOUT
University of Bern * Institute of Medical Education
GNU GPL 3.0
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 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]
usage
fi
prflist=( $(_cfg_dataitem 4) )
oidlist=( $(_cfg_dataitem 5) )
unitlist=( $(_cfg_dataitem 6) )
# --- SNPGET 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
for index in ${!oidlist[*]}
do
label="${prflist[$index]}"
value=$(_get ${oidlist[$index]})
unit="${unitlist[$index]}"
# handle counter data
if [ "$(_iscounter ${oidlist[$index]})" = "true" ]; then
value2=`ph.perfdeltaspeed "snmp-data-${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
ph.perfadd "${label}" "${value}"
done
# --- output
ph.status "SNMP performance data :: $info $out"
ph.exit
\ No newline at end of file
# IML Checks for Icinga / Nagios
[Home](readme.md)
---
## check SNMP data
### Introduction
**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).
### Syntax
``$ check_snmp_data -h HOSTNAME [-C COOMMUNITYSTRING] -v -m METHOD``
#### Parameters
Starting the script without parameters shows a help.
```
SNMP performance data v1.0
University of Bern * Institute of Medical Education
GNU GPL 3.0
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 public
-v verbose output
-m method what to show
method is one of ...
cpu CPU usage
load System load
netio Network IO (experimental)
synotemp Synology NAS temperature
EXAMPLE:
./check_snmp_data -h 192.168.100.12 -v -m cpu
```
### Examples
#### Get values
``./check_snmp_data -h 192.168.100.12 -v -m cpu``
Shows the current cpu usage of host *192.168.100.12*.
The output is something like that:
```
OK: SNMP performance data :: CPU usage
cpu-user 0 %
cpu-system 0 %
cpu-idle 99 %
|cpu-user=0;;;0; cpu-system=0;;;0; cpu-idle=99;;;0;
```
The 3 lines with values starting from line 2 are written with *-v* option only.
The performance data (last line) always will be sent.
#### Get counter data
``./check_snmp_data -h 192.168.100.12 -v -m netio``
If there is a check with counter data using *-v* option you see the counter value and the delta speed. It is calculated by
```
[current_counter] - [last_counter]
delta_speed = ----------------------------------
time_since_last_check_in_sec
```
The output looks like that:
```
OK: SNMP performance data :: Network IO (experimental)
in total: 2669086814 delta: 1 per sec
out total: 2212665608 delta: 0 per sec
|in=1;;;0; out=0;;;0;
```
### Configuration
check_snmp_data is a Bash script. If you open / view it you see a DATA section as comment lines on the top.
It starts with a short description:
```
# SYNTAX:
# label --> DATA:[method]:label:[text]
# n x data --> DATA:[method]:data:[perf-label]:[oid]:[optional unit]
```
... followed by the configuration data of the checks.
```
#
# 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:%
```
To fetch configuration data the text in $0 is grepped by ``^#\ DATA:``.
There is a single line with **label** to define a short description of the check.
There can be severeal lines with **data** to define the values to get. Each data line must have a uniq label within the same check.
......@@ -243,7 +243,7 @@ do
if [ ${idiskStatus} != "1" ] ; then
ph.setStatus "critical"
healthString="$healthString, problem with ${diskID[$i]} (model:${diskModel[$i]}) status:${diskStatus[$i]} temperature:${diskTemp[$i]} C "
healthString="$healthString, problem with ${diskID[$i]} (model:${diskModel[$i]}) status:${diskStatus[$i]} temperature:${diskTemp[$i]} °C"
fi
_wd "${diskID[$i]} (model:${diskModel[$i]}) status: ${diskStatus[$i]} ($idiskStatus) temperature: ${diskTemp[$i]} °C"
......
......@@ -17,41 +17,39 @@ We use Icinga graphite module to show performance data. The templates are locate
## Scripts
There is one include script used by all checks:
[inc_pluginfunctions](inc_pluginfunctions.md)
## Checks
check_apache_requests
check_backup_one
check_ceph_diskfree
check_ceph_osd
check_ceph_status
check_clientbackup
check_couchdb-lb
check_cpu
check_cronstatus
check_disk-io
check_dns_responsetime
[check_eol](check_eol.md)
check_haproxy_health
check_haproxy_status
check_memory
check_netio
check_netstat
check_opencpu
check_packages2install
check_proc_mem
check_proc_ressources
check_proc_zombie
check_reboot_required
check_sensuplugins
check_smartstatus
check_snmp_syno.sh
check_snmp_synology
check_ssl
check_systemdservices
check_timesync
check_uptime
inc_pluginfunctions
inc_pluginfunctions.md
paramtest
\ No newline at end of file
* check_apache_requests
* check_backup_one
* check_ceph_diskfree
* check_ceph_osd
* check_ceph_status
* check_clientbackup
* check_couchdb-lb
* check_cpu
* check_cronstatus
* check_disk-io
* check_dns_responsetime
* [check_eol](check_eol.md)
* check_haproxy_health
* check_haproxy_status
* check_memory
* check_netio
* check_netstat
* check_opencpu
* check_packages2install
* check_proc_mem
* check_proc_ressources
* check_proc_zombie
* check_reboot_required
* check_sensuplugins
* check_smartstatus
* [check_snmp_data](check_snmp_data.md)
* check_snmp_synology
* check_ssl
* check_systemdservices
* check_timesync
* check_uptime
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment