Nagios check juniper virtual chassis

From Initech Technical Wiki
Revision as of 03:18, 14 April 2017 by Timprice (talk | contribs) (Created page with "<code> #!/bin/bash SAVEIFS=$IFS IFS=$(/bin/echo -en "\n\b") function USAGE { echo echo "####################################################################" echo "# File n...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

  1. !/bin/bash

SAVEIFS=$IFS IFS=$(/bin/echo -en "\n\b")

function USAGE { echo echo "####################################################################" echo "# File name : nagios_check_juniper_virtual_chassis" echo "# Created by : Tim Price - Initech Consulting ( for any questions contact me on tim@initech.nz )" echo "# Created date : 14/04/2017" echo "# Version : 1.0" echo "# Information : Check Juniper EX series switch virtual chassis members are all present and running" echo "# : the same junos version" echo "# Usage : $0 -H host -C community -c vc-count" echo "####################################################################" echo }

while getopts ":H:C:c:" opt; do

 case $opt in

H) HOST="$OPTARG" ;; C) SNMP_COMMUNITY="$OPTARG" ;; c) VC_COUNT="$OPTARG" ;;

   	\?) USAGE
   	;;
 esac

done

if [ "$HOST" == "" ] || [ "$SNMP_COMMUNITY" == "" ] || [ "$VC_COUNT" == "" ]; then USAGE exit 0 fi TOTAL_VERSIONS=0 TOTAL_SWITCHES=0 for LINE in `snmpwalk -On -v2c -c $SNMP_COMMUNITY $HOST 1.3.6.1.4.1.2636.3.40.1.4.1.1.1.5 | awk '{print $4}' | uniq -c`; do NUMBER=`echo $LINE | awk '{print $1}'` TOTAL_SWITCHES=$(($TOTAL_SWITCHES + $NUMBER)) TOTAL_VERSIONS=$(($TOTAL_VERSIONS + 1)) done

if [ $TOTAL_VERSIONS -gt 1 ]; then echo "CRITICAL - Virtual chassis contains switches with $TOTAL_VERSIONS different junos versions" IFS=$SAVEIFS exit 2 fi

if [ $TOTAL_SWITCHES -ne $VC_COUNT ]; then echo "CRITICAL - Only $TOTAL_SWITCHES virtual chassis switch member(s) present, $VC_COUNT are expected" IFS=$SAVEIFS exit 2 fi

echo "OK - $VC_COUNT virtual chassis switch member(s) present, all running the same junos version" IFS=$SAVEIFS exit 0