Check SNMP data

Script: check_snmp_data

check_snmp_data is a plugin for fetching performance data with a set of given OIDs.

It can handle current values (i.e. load / cpu usage / disc usage) and counter values (i.e. network io).

Requirements

  • snmpget
  • snmpwalk

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.

______________________________________________________________________

CHECK_SNMP_DATA 
v0.8

(c) Institute for Medical Education - University of Bern
Licence: GNU GPL 3
______________________________________________________________________

SNMP performance data of Synology storages.

USAGE:
    check_snmp_data [options] -h SNMPTARGET

PARAMETERS:
    -a STRING
        authentication params for snmpwalk/ snmpget to connect to target; 
        default: \"-v2c -c public\" (Snmpv2 with community string \"public\")
    -h SNMPTARGET
        as fqdn or ip address; default: localhost
    -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

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_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.

SNMP authentication configuration

In a configuration file you can put the authentication parameters for snmpget and snmpwalk.

By default it reads /etc/icinga2/snmp.cfg - but you can use -f FILENAME to override it.

sudo cat /etc/icinga2/snmp.cfg 
#
# snmp-connections
# SYNTAX: [hostname]:[params]
#
DEFAULT:-v 2c -c public
server-01.example.com:-v 3 -l authnoPriv -a SHA -u imlmonitor -A password-for-server-01
server-02.example.com:-v 3 -l authnoPriv -a SHA -u imlmonitor -A password-for-server-02