#!/bin/bash # $Header: $ # vim:nu:ai:sw=4:ts=4: # # Nagios check script to check whether a given interface has a given IP address # Created by Wolfram Schlich # Distributed under the terms of the GNU General Public License v3 # # External dependencies: # - ip # - egrep # ## ## nagios state specific exit codes ## declare -i state_ok=0 declare -i state_warning=1 declare -i state_critical=2 declare -i state_unknown=3 declare -i state_dependent=4 ## ## functions ## function usage() { echo echo "Usage: ${0##*/} " echo } function checkargs() { if [[ -z "${iface}" || -z "${ipaddr}" ]]; then usage exit ${state_unknown} fi } ## ## main() ## if [[ ! -x "$(type -p ip 2>/dev/null)" ]]; then echo "ERROR: 'ip' not executable" exit ${state_unknown} fi if [[ ! -x "$(type -p egrep 2>/dev/null)" ]]; then echo "ERROR: 'egrep' not executable" exit ${state_unknown} fi iface="${1}"; shift ipaddr="${1}"; shift checkargs if ! ip link show dev ${iface} >&/dev/null; then echo "CRITICAL - interface '${iface}' does NOT EXIST!" exit ${state_critical} elif ! ip link show dev ${iface} 2>/dev/null | egrep "[[:space:]]${iface}:.*(,|<)UP(,|>)" >&/dev/null; then echo "CRITICAL - interface '${iface}' is DOWN!" exit ${state_critical} elif ! ip addr show dev ${iface} 2>/dev/null | egrep "inet6?[[:space:]]${ipaddr}[[:space:]]" >&/dev/null; then echo "CRITICAL - interface '${iface}' does not have IP address '${ipaddr}' configured!" exit ${state_critical} else echo "OK - interface '${iface}' has IP address '${ipaddr}' configured properly" exit ${state_ok} fi ## should never reach this echo "ERROR - there's an error in the matrix!" exit ${state_unknown}