Nagios check junos psu count

From Initech Technical Wiki
Jump to: navigation, search
#!/bin/bash
#
#   File name	 : check_junos_psu_count
#
#   Created by	 : Tim Price - Initech Consulting Limit (tim@initech.co.nz)
#   Created date : 20-09-2017
#   Version	 : 1.0
#
#   Information  : Check the number of power supplies installed in a juniper device or chassis cluster
#
####################################################################

## SNMP hostname
## SNMP C
## SNMP V

SNMP_HOST=${1}
SNMP_COMM=${2}
PSU_COUNT=${3}

## Error if no ARG is given

if [[ $# -eq 0 ]]
then
	echo "UNKNOWN - No ARG = hostname (1), SNMP COMM (2), PSU COUNT (3) is given"
        exit 3
else
	PSUS_INSTALLED=$(snmpwalk -v2c -c ${SNMP_COMM} ${SNMP_HOST} .1.3.6.1.4.1.2636.3.1.13.1.6.2 | grep " 2$" | wc -l)
	
	## Check if Power supplies installed matches expected number

	if [[ ${PSU_COUNT} -gt ${PSUS_INSTALLED} ]]; then
		echo "CRITICAL - Only ${PSUS_INSTALLED} power supplies installed, ${PSU_COUNT} expected"
		exit 2

	elif [[ ${PSU_COUNT} -lt ${PSUS_INSTALLED} ]]; then
		echo "WARNING - ${PSUS_INSTALLED} power supplies installed, only ${PSU_COUNT} expected"
                exit 1
	else
		echo "OK - ${PSUS_INSTALLED} power supplies installed and operating"
		exit 0
	fi
fi