Linux altar53.supremepanel53.com 4.18.0-553.8.1.lve.el8.x86_64 #1 SMP Thu Jul 4 16:24:39 UTC 2024 x86_64
/ lib64/ nagios/ plugins/ |
|
#!/bin/bash IOSTAT=/usr/bin/iostat STATE_OK=0 STATE_WARNING=1 STATE_CRITICAL=2 STATE_UNKNOWN=3 # Plugin parameters value if not define WARNING_THRESHOLD=${WARNING_THRESHOLD:="4"} CRITICAL_THRESHOLD=${CRITICAL_THRESHOLD:="5"} INTERVAL_SEC=${INTERVAL_SEC:="5"} NUM_REPORT=${NUM_REPORT:="2"} if [ ! -x $IOSTAT ]; then echo "UNKNOWN: iostat not found or is not executable by the nagios user." exit $STATE_UNKNOWN fi # CPU Steal Stats CPU_REPORT=`iostat -c $INTERVAL_SEC $NUM_REPORT | sed -e 's/,/./g' | tr -s ' ' ';' | sed '/^$/d' | tail -1` CPU_REPORT_SECTIONS=`echo ${CPU_REPORT} | grep ';' -o | wc -l` if [ ${CPU_REPORT_SECTIONS} -ge 6 ]; then CPU_STEAL=`echo $CPU_REPORT | cut -d ";" -f 6` NAGIOS_DATA=" steal=${CPU_STEAL}% | CpuSteal=${CPU_STEAL} ; $CRITICAL_THRESHOLD" fi # Functions plugin usage print_release() { echo "$RELEASE" } print_usage() { echo "" echo "$PROGNAME $RELEASE - CPU steal check script for Nagios" echo "" echo "Usage: check_cpu_steal -w -c (-i -n)" echo "" echo " -w Warning level in % for cpu steal" echo " -c Crical level in % for cpu steal" echo " -i Interval in seconds for iostat (default : 1)" echo " -n Number report for iostat (default : 3)" echo " -h Show this page" echo "" echo "Usage: $PROGNAME" echo "Usage: $PROGNAME --help" echo "" } print_help() { print_usage echo "" echo "This plugin will check cpu steal" echo "" exit 0 } # Parse parameters while [ $# -gt 0 ]; do case "$1" in -h | --help) print_help exit $STATE_OK ;; -v | --vversion) print_release exit $STATE_OK ;; -r | --resource) shift RESOURCE=$1 ;; -w | --warning) shift WARNING_THRESHOLD=$1 ;; -c | --critical) shift CRITICAL_THRESHOLD=$1 ;; -i | --interval) shift INTERVAL_SEC=$1 ;; -n | --number) shift NUM_REPORT=$1 ;; *) echo "Unknown argument: $1" print_usage exit $STATE_UNKNOWN ;; esac shift done # Resource check case $RESOURCE in steal) CPU="$CPU_STEAL" COMPARISON="less" ;; user) CPU="$CPU_USER" COMPARISON="greater" ;; system) CPU="$CPU_SYSTEM" COMPARISON="greater" ;; nice) CPU="$CPU_NICE" COMPARISON="greater" ;; iowait) CPU="$CPU_IOWAIT" COMPARISON="greater" ;; *) CPU="$CPU_IDLE" COMPARISON="less" ;; esac CPU_STEAL=`echo $CPU_REPORT | cut -d ";" -f 6` # Return if [ ${CPU_STEAL/.*} -ge $CRITICAL_THRESHOLD ]; then NAGIOS_STATE="CRITICAL" STATE=$STATE_CRITICAL elif [ ${CPU_STEAL/.*} -eq $WARNING_THRESHOLD ]; then NAGIOS_STATE="WARNING" STATE=$STATE_WARNING else NAGIOS_STATE="OK" STATE=$STATE_OK fi echo "CPU STEAL $NAGIOS_STATE ($CPU_STEAL/$CRITICAL_THRESHOLD) : ${NAGIOS_DATA}" exit $STATE