#!/bin/sh # ---------------------------------------------------------------------- # Variables # ---------------------------------------------------------------------- SNMPAUTH= SNMPCONFIG=/etc/icinga2/snmp.cfg SNMPCOMMUNITY="public" SNMPVERSION="2c" SNMPWALK=$(which snmpwalk) SNMPGET=$(which snmpget) SNMPTIMEOUT=3 SNMPTARGET="127.0.0.1" # ---------------------------------------------------------------------- # FUNCTIONS # ---------------------------------------------------------------------- # read config data for authentication; it sets the variable SNMPAUTH # that can be used for snmpwalk / snmpget # # no params # # used global vars: # - SNMPVERSION + SNMPCOMMUNITY to set the default # - SNMPCONFIG - filename of the config to read # - SNMPTARGET - SNMPTARGET (ip or fqdn) of target to connect # read_config(){ SNMPAUTH="-v $SNMPVERSION -c $SNMPCOMMUNITY" if [ -r "$SNMPCONFIG" ]; then if grep "^${SNMPTARGET}:" "$SNMPCONFIG" >/dev/null; then SNMPAUTH="$( grep "^${SNMPTARGET}:" "$SNMPCONFIG" | cut -f 2- -d ':' )" else SNMPAUTH="$( grep "^DEFAULT:" "$SNMPCONFIG" | cut -f 2- -d ':' )" fi else ph.setStatus "unknown" echo "ERROR: unable to read config file [$SNMPCONFIG]." ph.exit fi } # ----------------------------------------------------------------------