Cisco Unified Communication Monitoring mit Icinga, #2

Nachdem zuvor auf dem Cisco Unified Communication Manager die Services im Icinga eingerichtet wurden, fehlen jetzt noch die Cisco IP-Phones.
Wie schön ist es doch, wenn wir wissen, dass die Services alle laufen, aber die Telefone in den Seilen hängen und keiner bekommt es mit.

Also, wieder ein neues Bash-Script geschrieben (diesmal auch mit SNMP V3 laugh )

/usr/lib/nagios/plugins/check_cucm_phonestat.sh

#!/bin/bash
#
# check_snmp_cisco_uc
# Description : Check phone status on cisco uc (Callmanager)
# Version : 0.1
# Author : Georg Gren
# Licence : GPLv2

# Commands
CMD_BASENAME="/usr/bin/basename"
CMD_SNMPGET="/usr/bin/snmpget"
CMD_SNMPWALK="/usr/bin/snmpwalk"
CMD_GREP="/bin/grep"
CMD_AWK="/usr/bin/awk"
CMD_EXPR="/usr/bin/expr"


# Script name
SCRIPTNAME=`$CMD_BASENAME $0`

# Version
VERSION="0.1"

# Plugin return codes
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3

#Service-states from cisco MIB
PHONESTATE_1="unknown"
PHONESTATE_2="registered"
PHONESTATE_3="unregistered"
PHONESTATE_4="rejected"
PHONESTATE_5="pariallyregistered"

PHONESUM=0

# Default OID
OID_PHONESTAT="1.3.6.1.4.1.9.9.156.1.2.1.1.7"

# Default variables
DESCRIPTION="Unknown"
STATE=$STATE_UNKNOWN

# Default options
COMMUNITY="public"
HOSTNAME="127.0.0.1"

# Option processing
print_usage() {
	echo "Usage: check_cucm_phonestat.sh -H hostname [-S|-v|-c|-a|-A|-l|-u|-x|-X|-W|-C|-h|-V]"
}

print_version() {
	echo $SCRIPTNAME version $VERSION
	echo ""
	echo "The nagios plugins come with ABSOLUTELY NO WARRANTY."
	echo "You may redistribute copies of the plugins under the terms of the GNU General Public License v2."
}

print_help() {
	print_version
	echo ""
	print_usage
	echo ""
        echo "  $SCRIPTNAME -H Hostname / -address"
        echo "  $SCRIPTNAME -S Phone-State        set Filter: 0=summery all states, 1=unknown, 2=registered, 3=unregistered, 4=rejected, 5=partiallyregistered"
        echo "  $SCRIPTNAME -v SNMP VERSION       specifies SNMP version to use (1|2c|3)"
        echo "  $SCRIPTNAME -c COMMUNITY          set the community string"
        echo "  $SCRIPTNAME -a PROTOCOL           set authentication protocol (MD5|SHA)"
        echo "  $SCRIPTNAME -A PASSPHRASE         set authentication protocol pass phrase"
        echo "  $SCRIPTNAME -l LEVEL              set security level (noAuthNoPriv|authNoPriv|authPriv)"
        echo "  $SCRIPTNAME -u USER-NAME          set security name (e.g. alice)"
        echo "  $SCRIPTNAME -x PROTOCOL           set privacy protocol (DES|AES)"
        echo "  $SCRIPTNAME -X PASSPHRASE         set privacy protocol pass phrase"
        echo "  $SCRIPTNAME -W WARN               set number for warn-level"
        echo "  $SCRIPTNAME -C CRITICAL           set number for critical-level"
        echo "  $SCRIPTNAME -h Help"
        echo "  $SCRIPTNAME -V Version"
	echo ""
	echo "REQUIRED PARAMETERS: -H Hostname, -S Phone-State, -v 1|2c|3, -W WARN, -C CRITICAL" 
	echo ""
	echo "This plugin uses the 'snmpget' command and 'snmpwalk' command included with the NET-SNMP package."
}

# Check Parameters
check_param()
{
if [ "$HOSTNAME" == "" ] || [ "$SNMPVERSION" == "" ] || [ "$PHONESTAT" == "" ] || [ "$WARNLEVEL" == "" ] || [ "$CRITLEVEL" == "" ]
then
	echo "Error - Missing parameters - hostname = $HOSTNAME : snmp-version = $SNMPVERSION : phone-state = $PHONESTAT : warn-level = $WARNLEVEL : critical-level = $CRITLEVEL"
	echo "$USAGE"
	exit $STATE_UNKNOWN
fi

if [ $PHONESTAT -gt 5 ]
then
        echo "Error - Value is out of range: phone-state = $PHONESTAT!"
        echo "$USAGE"
        exit $STATE_UNKNOWN
fi

case $SNMPVERSION in
		1 | 2c)
			if [ "$COMMUNITY" == "" ]
			then
				echo "Error - Missing parameters - community = $COMMUNITY"
				echo "$USAGE"
				exit $STATE_UNKNOWN
			fi
			WALKPARAM="-v $SNMPVERSION -c $COMMUNITY -H $HOSTNAME";;
		3) 
			case $LEVEL in
				"noAuthNoPriv")
					if [ "$LEVEL" == "" ] || [ "$SNMPUSER" == "" ]
					then
						echo "Error - Missing parameters - snmp-version = $SNMPVERSION : user = $SNMPUSER"
						echo "$USAGE"
						exit $STATE_UNKNOWN
					fi
					WALKPARAM="-v $SNMPVERSION -l $LEVEL -u $SNMPUSER $HOSTNAME";;

                                "authNoPriv")
                                        if [ "$LEVEL" == "" ] || [ "$SNMPUSER" == "" ] || [ "$AUTHPROT" == "" ] || [ "$AUTHPASS" == "" ]
                                        then
                                                echo "Error - Missing parameters - snmp-version = $SNMPVERSION : user = $SNMPUSER : authprotocol = $AUTHPROT : authpassword = $AUTHPASS"
                                                echo "$USAGE"
                                                exit $STATE_UNKNOWN
                                        fi
                                        WALKPARAM="-v $SNMPVERSION -l $LEVEL -u $SNMPUSER -a $AUTHPROT -A $AUTHPASS $HOSTNAME";;

                                "authPriv")
                                        if [ "$LEVEL" == "" ] || [ "$SNMPUSER" == "" ] || [ "$AUTHPROT" == "" ] || [ "$AUTHPASS" == ""  || [ "$PRIVPROT" == "" ] || [ "$PRIVPASS" == "" ]]
                                        then
                                                echo "Error - Missing parameters - snmp-version = $SNMPVERSION : user = $SNMPUSER : authprotocol = $AUTHPROT : authpassword = $AUTHPASS : privacypassword = $PRIVPROT : privacypassword = $PRIVPASS"
                                                echo "$USAGE"
                                                exit $STATE_UNKNOWN
                                        fi
                                        WALKPARAM="-v $SNMPVERSION -l $LEVEL -u $SNMPUSER -a $AUTHPROT -A $AUTHPASS -x $PRIVPROT -X PRIVPASS $HOSTNAME";;

			esac

esac
}

check_state()
{
#check + count =$PHONESTAT
for i in "${PHONESSTATS[@]}"
        do
        if [ $i == $PHONESTAT ]
                then
                ((PHONESUM++))
        fi
done

eval PHONESTATE=\$PHONESTATE_${PHONESTAT}

if [ $PHONESUM -ge $CRITLEVEL ]; then
        DESCRIPTION="CRITICAL: $PHONESUM phones are: $PHONESTATE"
        STATE=$STATE_CRITICAL
elif [ $PHONESUM -ge $WARNLEVEL ]; then
        DESCRIPTION="WARNING: $PHONESUM phones are: $PHONESTATE"
        STATE=$STATE_WARNING
elif [ $PHONESUM -lt $WARNLEVEL ]; then
        DESCRIPTION="OK: $PHONESUM phones are: $PHONESTATE"
        STATE=$STATE_OK
else
        DESCRIPTION="$PHONESUM phones are: $PHONESTATE"
        STATE=$STATE_UNKNOWN
fi
}

check_state_all()
{
PHONESUM_1=0
PHONESUM_2=0
PHONESUM_3=0
PHONESUM_4=0
PHONESUM_5=0

#check + count =$PHONESTAT
for i in "${PHONESSTATS[@]}"
        do
	case $i in
                1)
                ((PHONESUM_1++));;
                2)
                ((PHONESUM_2++));;
                3)
                ((PHONESUM_3++));;
                4)
                ((PHONESUM_4++));;
                5)
                ((PHONESUM_5++));;

        esac
done
PHONESUM=$PHONESUM_1 + $PHONESUM_3 + $PHONESUM_4 + $PHONESUM_5

#eval PHONESTATE=\$PHONESTATE_${PHONESTAT}

if [ $PHONESUM -ge $CRITLEVEL ]; then
        DESCRIPTION="Phones CRITICAL: $PHONESUM_2 $PHONESTATE_2, $PHONESUM_1 $PHONESTATE_1, $PHONESUM_3 $PHONESTATE_3, $PHONESUM_4 $PHONESTATE_4, $PHONESUM_5 $PHONESTATE_5"
        STATE=$STATE_CRITICAL
        #echo $DESCRIPTION
elif [ $PHONESUM -ge $WARNLEVEL ]; then
        DESCRIPTION="Phones WARNING: $PHONESUM_2 $PHONESTATE_2, $PHONESUM_1 $PHONESTATE_1, $PHONESUM_3 $PHONESTATE_3, $PHONESUM_4 $PHONESTATE_4, $PHONESUM_5 $PHONESTATE_5"
        STATE=$STATE_WARNING
        #echo $DESCRIPTION
elif [ $PHONESUM -lt $WARNLEVEL ]; then
        DESCRIPTION="Phones OK: $PHONESUM_2 $PHONESTATE_2, $PHONESUM_1 $PHONESTATE_1, $PHONESUM_3 $PHONESTATE_3, $PHONESUM_4 $PHONESTATE_4, $PHONESUM_5 $PHONESTATE_5"
        STATE=$STATE_OK
        #echo $DESCRIPTION
else
        DESCRIPTION="$PHONESUM_2 $PHONESTATE_2, $PHONESUM_1 $PHONESTATE_1, $PHONESUM_3 $PHONESTATE_3, $PHONESUM_4 $PHONESTATE_4, $PHONESUM_5 $PHONESTATE_5"
        STATE=$STATE_UNKNOWN
fi
}



############################################################
# Main Method
############################################################
main()
{
while getopts H:S:v:c:a:A:l:u:x:X:W:C:hV OPT
do
	case $OPT in
		H) HOSTNAME="$OPTARG" ;;
		S) PHONESTAT="$OPTARG" ;;
		v) SNMPVERSION="$OPTARG" ;;
		c) COMMUNITY="$OPTARG" ;;
		a) AUTHPROT="$OPTARG" ;;
		A) AUTHPASS="$OPTARG" ;;
		l) LEVEL="$OPTARG" ;;
		u) SNMPUSER="$OPTARG" ;;
		x) PRIVPROT="$OPTARG" ;;
		X) PRIVPASS="$OPTARG" ;;
		W) WARNLEVEL="$OPTARG" ;;
		C) CRITLEVEL="$OPTARG" ;;
		h)
			print_help
			exit $STATE_UNKNOWN
		;;
		V)
			print_version
			exit $STATE_UNKNOWN
		;;
		*) exit $STATE_UNKNOWN ;;

	esac
done

check_param

PHONESSTATS=($($CMD_SNMPWALK -t 2 -r 2 -Ovq $WALKPARAM $OID_PHONESTAT))

if [ $PHONESTAT == 0 ]; then
	check_state_all
else
	check_state
fi

echo $DESCRIPTION
exit $STATE
}

main $*

# Default exit
echo "Unknown - No result sent to nagios - End of script"
exit $STATE_UNKNOWN

Näheres zu den Parametern gibt der Aufruf /usr/lib/nagios/plugins/check_cucm_phonestat.sh -h her.

Mit dem Script kann man über den Parameter -S einstellen, welcher Phone-Status ausgegeben werden soll, oder halt auch alle zusammen cool. Somit kann man die 5 einzelnen Status auch einzeln mit unterschiedlichen Warning + Critical-Werten monitoren, oder nur die registrierten Phones , oder, oder, oder ...

Wie immer, nicht vergessen das Script ausführbar zu machen:

chmod +x ./check_cucm_phonestat.sh

Den Command-Eintrag hab ich ergänzt in
/etc/nagios-plugins/config/snmp_cucm.cfg

define command{
        command_name    check_snmp_phones
        command_line    $USER1$/check_cucm_phonestat.sh -H '$HOSTADDRESS$' -v 3 -l noAuthNoPriv -u verysecret -W 1 -C 2 -S $ARG1$
        }

Anschließend wird der Check selber noch eingerichtet.

define service {
        service_description             1_PHONES
        check_command                   check_snmp_phones! 0
        use                             generic-service
        host_name                       cucm12
        notification_interval           0 ; set > 0 if you want to be renotified
        }

Im Ergebnis haben wir eine schönen, neuen Check im Icinga:

Neuen Kommentar schreiben

Plain text

  • Keine HTML-Tags erlaubt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • HTML - Zeilenumbrüche und Absätze werden automatisch erzeugt.