#!/bin/bash ################################################################################################################ # $Id: check_centrify,v 1.23 2016/04/06 16:49:27 root Exp root $ ################################################################################################################ # Version History ################################################################################################################ # 2016-04-07 cwl Added a patch from Bill Carlson to allow users to provide command line args # 2013-08-27 cwl Fixed bug in the script where mode is reported as OK if centrify is unavailable # 2013-07-09 cwl PID for adclient is now from /var/run/adclient.pid this fixes a bug on Solaris hosts which # run zones returning multiple process ID's for the adclient process when centrify is run on the # host and one or more ldom # 2013-07-08 cwl Ported script to Solaris, also changed formating, and re-ordered script. # 2013-07-04 cwl Script now reports if both mem and cpu and warning/critical if both are over thresholds # the script also checks the current version against the allowed version/s and returns warning # if invalid # 2013-06-17 cwl script now reports DC # 2013-06-07 cwl Mode now checks for down and disconnected # 2013-06-06 cwl Tuned critical/warning values # 2013-06-03 cwl Added the collection of perf data # 2013-05-30 cwl Changed order of the script as adclient process isn't running in down mode # Also changed warning/critical messages to include what part is in warning/critical # 2013-05-28 cwl Created ################################################################################################################ # User defined variables below ################################################################################################################ CPU_WARNING=10 # This variable sets the warning value for CPU CPU_CRITICAL=15 # This variable sets the critical value for CPU MEM_WARNING=10 # This variable sets the warning value for MEM MEM_CRITICAL=15 # This variable sets the critical value for MEM ALLOWED_VERSIONS="5.3.0-213" # This variable sets the allowed version seperated by spaces ################################################################################################################ # Check OS and set tools ################################################################################################################ if [ `uname` == "SunOS" ] then AWK=/usr/xpg4/bin/awk TAIL=/usr/xpg4/bin/tail else AWK=`which awk` TAIL=`which tail` fi ################################################################################################################ # Global Variables (not user editable) ################################################################################################################ UTILS="`dirname $0`/utils.sh" . $UTILS SCRIPT_NAME=`basename $0` #Sets the script name variable to the name of the script WARN_CPU=0 # Variable used to hold if CPU is above warning value WARN_MEM=0 # Variable used to hold if MEM is above warning value CRIT_CPU=0 # Variable used to hold if CPU is above critical value CRIT_MEM=0 # Variable used to hold if MEM is above critical value MODE=`/usr/bin/adinfo -m` # Holds current mode of the adclient program ################################################################################################################ # Functions ################################################################################################################ function usage() { # This fuction displays the usage information echo "This script will check the following: " echo " * If Centrify is connected to a zone if not give a critical warning." echo " * Check how much memory the adclient process is using and give alerts for warning/critical values" echo " * Check how much CPU the adclient process is using and give alerts for warning/critical values" echo " * Confirm the installed Centrify version is in the allowed versions and give a warning if not" echo "Usage: ${SCRIPT_NAME} If no options are given then defaults are used" echo "Usage: ${SCRIPT_NAME} -c -C -m -M -a " echo "Example: ${SCRIPT_NAME} -c 15 -C 20 -m 10 -M 20 -a 5.3.0-213" } ################################################################################################################ # Main program ################################################################################################################ while getopts "c:C:m:M:a:" opt ; do case $opt in c) CPU_WARNING=$OPTARG ;; C) CPU_CRITICAL=$OPTARG ;; m) MEM_WARNING=$OPTARG ;; M) MEM_CRITICAL=$OPTARG ;; a) ALLOWED_VERSIONS="$OPTARG" ;; *) usage exit 1 ;; esac done if [ ! "$MODE" == "connected" ] then RESULT="CENTRIFY DOWN CRITICAL: Mode=${MODE} Zone=${ZONE} Version=$VERSION" exitstatus=$STATE_CRITICAL echo $RESULT exit $exitstatus fi # Only check the process ID if Centrify isn't down ZONE=`/usr/bin/adinfo -z|${AWK} 'BEGIN { FS = "/" };{print $NF}'` # Holds current zone VERSION=`/usr/bin/adinfo -v | ${AWK} '{print $3}'|sed '$s/.$//'` # Holds currently installed version DC=`/usr/bin/adinfo -r` # Holds current DC information #PID=`ps -ef|grep adclient|grep -v grep|${AWK} '{print $2}'` # Holds PID of adclient process PID=`cat /var/run/adclient.pid` PREF_SITE=`/usr/bin/adinfo -s` # Check the PID of adclient is valid if [ ! -z $PID ] then PROCESS=`ps -ef|grep $PID|grep -v grep|grep adclient` # PID is set, check it relates to adclient process if [ -z "$PROCESS" ] then # The PID value in adclient.pid isn't valid RESULT="Invalid PID in /var/run/adclient.pid" exitstatus=$STATE_UNKNOWN echo $RESULT exit $exitstatus fi else # The PID variable isn't set exit with unknown RESULT="Can't work out PID of Centrify process" exitstatus=$STATE_UNKNOWN echo $RESULT exit $exitstatus fi # Get CPU and MEM information if [ `uname` == "SunOS" ] then CPU=`ps -eo pid,pcpu,pmem|grep $PID|${AWK} '{print $2}'` MEM=`ps -eo pid,pcpu,pmem|grep $PID|${AWK} '{print $3}'` else CPU=`ps -p $PID u|${AWK} '{print $3}' |${TAIL} -n1` MEM=`ps -p $PID u|${AWK} '{print $4}' |${TAIL} -n1` fi # Check the version is in the allowed versions variable if [[ $ALLOWED_VERSIONS =~ $VERSION ]] then BAD_VERSION=0 else BAD_VERSION=1 fi # Perform some check to make sure there are no errors: CRIT_CPU=`echo "${CPU} ${CPU_CRITICAL}" | awk '{if ($1 > $2) print 1; else print 0}'` WARN_CPU=`echo "${CPU} ${CPU_WARNING}" | awk '{if ($1 > $2) print 1; else print 0}'` CRIT_MEM=`echo "${MEM} ${MEM_CRITICAL}" | awk '{if ($1 > $2) print 1; else print 0}'` WARN_MEM=`echo "${MEM} ${MEM_WARNING}" | awk '{if ($1 > $2) print 1; else print 0 }'` # Build up error message and exit status if [ "$CRIT_CPU" = "1" ] && [ "$CRIT_MEM" = "1" ] then RESULT="CENTRIFY CPU & MEMORY CRITICAL:" exitstatus=$STATE_CRITICAL elif [ "$CRIT_CPU" = "1" ] then RESULT="CENTRIFY CPU CRITICAL:" exitstatus=$STATE_CRITICAL elif [ "$CRIT_MEM" = "1" ] then RESULT="CENTRIFY MEM CRITICAL:" exitstatus=$STATE_CRITICAL elif [ "$WARN_CPU" = "1" ] && [ "$WARN_MEM" = "1" ] && [ "$BAD_VERSION" = "1" ] then RESULT="CENTRIFY MEM, CPU, VERSION WARNING:" exitstatus=$STATE_WARNING elif [ "$WARN_CPU" = "1" ] && [ "$WARN_MEM" = "1" ] then RESULT="CENTRIFY MEM & CPU WARNING:" exitstatus=$STATE_WARNING elif [ "$WARN_CPU" = "1" ] && [ "$BAD_VERSION" = "1" ] then RESULT="CENTRIFY CPU & VERSION WARNING:" exitstatus=$STATE_WARNING elif [ "$WARN_MEM" = "1" ] && [ "$BAD_VERSION" = "1" ] then RESULT="CENTRIFY MEM & VERSION WARNING:" exitstatus=$STATE_WARNING elif [ "$WARN_CPU" = "1" ] then RESULT="CENTRIFY CPU WARNING:" exitstatus=$STATE_WARNING elif [ "$WARN_MEM" = "1" ] then RESULT="CENTRIFY MEM WARNING:" exitstatus=$STATE_WARNING elif [ "$BAD_VERSION" = "1" ] then RESULT="CENTRIFY VERSION WARNING:" exitstatus=$STATE_WARNING else RESULT="CENTRIFY OK:" exitstatus=$STATE_OK fi # Exit with the result and exit status echo "$RESULT CPU=${CPU}% MEM=${MEM}% Mode=${MODE} Zone=${ZONE} DC=$DC Version=$VERSION| 'Centrify_CPU'=$CPU; 'Centrify_MEM'=$MEM;" exit $exitstatus #EOF