#!/bin/bash # check_snmp_firecluster for nagios # 2016-04-22 - Rich Johnson #--------------------------------------------------- # this plugin checks the following: # - if cluster is enabled # - member role is master or backup master # - member system health index # - member hardware health index # - member monitor port index # - member weight average index SNMPWALK=$(which snmpwalk) SNMPGET=$(which snmpget) SNMPTimeout="10" SNMPVersion="3" SNMPCommunity="public" hostname="" #OID declarations OID_wgClusterEnabled=".1.3.6.1.4.1.3097.6.6.1.0" OID_wgFirstMemberId=".1.3.6.1.4.1.3097.6.6.2.0" OID_wgFirstMemberRole=".1.3.6.1.4.1.3097.6.6.3.0" OID_wgFirstMemberSystemHealth=".1.3.6.1.4.1.3097.6.6.4.0" OID_wgFirstMemberHardwareHealth=".1.3.6.1.4.1.3097.6.6.5.0" OID_wgFirstMemberMonitorPortHealth=".1.3.6.1.4.1.3097.6.6.6.0" OID_wgFirstMemberWeightAvg=".1.3.6.1.4.1.3097.6.6.7.0" OID_wgSecondMemberId=".1.3.6.1.4.1.3097.6.6.8.0" OID_wgSecondMemberRole=".1.3.6.1.4.1.3097.6.6.9.0" OID_wgSecondMemberSystemHealth=".1.3.6.1.4.1.3097.6.6.10.0" OID_wgSecondMemberHardwareHealth=".1.3.6.1.4.1.3097.6.6.11.0" OID_wgSecondMemberMonitorPortHealth=".1.3.6.1.4.1.3097.6.6.12.0" OID_wgSecondMemberWeightAvg=".1.3.6.1.4.1.3097.6.6.13.0" usage() { echo "usage: ./check_snmp_firecluster -h [hostname] [options]" echo "options:" echo " -h [IPv4 Address] IP address of cluster management address" echo " -u [snmp username] Required if using SNMPv3" echo " -a [none|MD5|SHA] Authentication - Required if using SNMPv3" echo " -A [password] Required if using SNMPv3 & not using '-a none'" echo " -x [None|DES] Privacy - Required if using SNMPv3" echo " -a [password] Required if using SNMPv2 & not using '-x none'" echo " -c [community name] required if using SNMPv1 or 2" echo "" echo "examples:" echo "" echo " - SNMPv1/2c" echo " ./check_snmp_firecluster -h 10.0.0.1 -c public" echo " - SNMPv3" echo " ./check_snmp_firecluster -h 192.168.0.1 -u username -a sha -A myauthpass -x des -X myprivpass" exit 3 } if [ "$1" == "--help" ]; then usage; exit 0 fi while getopts h:u:a:A:x:X:c: OPTNAME; do case "$OPTNAME" in h) hostname="$OPTARG";; u) SNMPUser="$OPTARG";; a) SNMPAuth="$OPTARG";; A) SNMPAuthPassword="$OPTARG";; x) SNMPPriv="$OPTARG";; X) SNMPPrivPassword="$OPTARG";; c) SNMPVersion="1" SNMPCommunity="$OPTARG";; *) usage;; esac done # Define the SNMP arguments depending on version if [ "$hostname" = "" ] || ([ "$SNMPVersion" = "3" ] && [ "$SNMPUser" = "" ]) ; then usage else if [ "$SNMPVersion" = "1" ] ; then SNMPArgs="-t $SNMPTimeout -v 1 -c $SNMPCommunity" else # if using authentication and privacy SNMPArgs="-t $SNMPTimeout -v 3 -l authPriv -u $SNMPUser -a $SNMPAuth -A $SNMPAuthPassword -x $SNMPPriv -X $SNMPPrivPassword" # if using authentication, but no privacy (WHY!?!) if [ "$SNMPPriv" = "none" ]; then SNMPArgs="-t $SNMPTimeout -v 3 -l AuthNoPriv -u $SNMPUser -a $SNMPAuth -A $SNMPAuthPassword" fi # if using no authentication protocol and no privacy (WHY!?!) if ([ "$SNMPAuth" = "none" ] && [ "$SNMPPriv" = "none" ]); then SNMPArgs="-t $SNMPTimeout -v 3 -l noAuthNoPriv -u $SNMPUser" fi fi fi # Check that firecluster is enabled variable="$(snmpget $SNMPArgs $hostname $OID_wgClusterEnabled | grep "INTEGER: 1")" if [[ $? -eq 0 ]]; then clusterEnabled="yes" else echo "CRITICAL: Firecluster not enabled, or syntax error." exit 2 fi # Firecluster is enabled if [[ $clusterEnabled == "yes" ]]; then # Check member1 health m1id=$(snmpget $SNMPArgs $hostname $OID_wgFirstMemberId | cut -f2 -d'"') m1sh=$(snmpget $SNMPArgs $hostname $OID_wgFirstMemberSystemHealth | cut -f4 -d':' | xargs) m1hh=$(snmpget $SNMPArgs $hostname $OID_wgFirstMemberHardwareHealth | cut -f4 -d':' | xargs) m1ph=$(snmpget $SNMPArgs $hostname $OID_wgFirstMemberMonitorPortHealth | cut -f4 -d':' | xargs) m1wa=$(snmpget $SNMPArgs $hostname $OID_wgFirstMemberWeightAvg | cut -f4 -d':' | xargs) m1ro=$(snmpget $SNMPArgs $hostname $OID_wgFirstMemberRole | cut -f4 -d':' | xargs) if [ $m1ro = "0" ]; then m1ro="Disabled"; fi if [ $m1ro = "1" ]; then m1ro="Worker"; fi if [ $m1ro = "2" ]; then m1ro="Backup"; fi if [ $m1ro = "3" ]; then m1ro="Master"; fi if [ $m1ro = "4" ]; then m1ro="Idle"; fi if [ $m1ro = "5" ]; then m1ro="Standby"; fi # Check member2 health m2id=$(snmpget $SNMPArgs $hostname $OID_wgSecondMemberId | cut -f2 -d'"') m2sh=$(snmpget $SNMPArgs $hostname $OID_wgSecondMemberSystemHealth | cut -f4 -d':' | xargs) m2hh=$(snmpget $SNMPArgs $hostname $OID_wgSecondMemberHardwareHealth | cut -f4 -d':' | xargs) m2ph=$(snmpget $SNMPArgs $hostname $OID_wgSecondMemberMonitorPortHealth | cut -f4 -d':' | xargs) m2wa=$(snmpget $SNMPArgs $hostname $OID_wgSecondMemberWeightAvg | cut -f4 -d':' | xargs) m2ro=$(snmpget $SNMPArgs $hostname $OID_wgSecondMemberRole | cut -f4 -d':' | xargs) if [ $m2ro = "0" ]; then m2ro="Disabled"; fi if [ $m2ro = "1" ]; then m2ro="Worker"; fi if [ $m2ro = "2" ]; then m2ro="Backup"; fi if [ $m2ro = "3" ]; then m2ro="Master"; fi if [ $m2ro = "4" ]; then m2ro="Idle"; fi if [ $m2ro = "5" ]; then m2ro="Standby"; fi # Return 0 - OK if [ "$m1wa" = "100" ] && [ "$m2wa" = "100" ] && ([ "$m1ro" = "Master" ] || [ "$m1ro" = "Backup" ]) && ([ "$m2ro" = "Master" ] || [ "$m2ro" = "Backup" ]) ; then echo "OK: $m1ro:$m1id,SystemHealth:$m1sh,HardwareHealth:$m1hh,PortHealth:$m1ph,WeightedAvg:$m1wa ; $m2ro:$m2id,SystemHealth:$m2sh,HardwareHealth:$m2hh,PortHealth:$m2ph,WeightedAvg:$m2wa" exit 0 fi # Return 1 - Warning if ([ "$m1wa" -ne "100" ] || [ "$m2wa" -ne "100" ]) && ([ "$m1ro" = "Master" ] || [ "$m1ro" = "Backup" ]) && ([ "$m2ro" = "Master" ] || [ "$m2ro" = "Backup" ]) ; then echo "WARNING: $m1ro:$m1id,SystemHealth:$m1sh,HardwareHealth:$m1hh,PortHealth:$m1ph,WeightedAvg:$m1wa ; $m2ro:$m2id,SystemHealth:$m2sh,HardwareHealth:$m2hh,PortHealth:$m2ph,WeightedAvg:$m2wa" exit 1 fi # Return 2 - Critical if ([ "$m1ro" != "Master" ] || [ "$m1ro" != "Backup" ]) && ([ "$m2ro" != "Master" ] || [ "$m2ro" != "Backup" ]) ; then echo "CRITICAL: $m1id:$m1ro ; $m2id:$m2ro - Both members must be Master or Backup!" exit 2 fi echo "Something went wrong." exit 3 fi