Skip to content
Snippets Groups Projects
Select Git revision
  • a9e639180a7aa216911797adf9b5c980911a9bc3
  • master default protected
  • simple-task/7248-eol-check-add-node-22
  • 6877_check_iml_deployment
4 results

check_snmp_includes

Blame
  • check_snmp_includes 1.55 KiB
    #!/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
            SNMPAUTH="$( grep -v "^#" "$SNMPCONFIG" | grep ",*${SNMPTARGET}[,:]" | cut -f 2- -d ':' )"
            if [ -z "$SNMPAUTH" ]; then
                SNMPAUTH="$( grep "^DEFAULT:" "$SNMPCONFIG" | cut -f 2- -d ':' )"
                if [ -z "$SNMPAUTH" ]; then
                    ph.setStatus "unknown"
                    echo "ERROR: No authentication data were found for [${SNMPTARGET}] in config file [$SNMPCONFIG]."
                    ph.exit
                fi
            fi
        else
            ph.setStatus "unknown"
            echo "ERROR: unable to read config file [$SNMPCONFIG]."
            ph.exit
        fi
    }
    
    
    # ----------------------------------------------------------------------