#!/bin/ksh
#
# Nagios CPU Plugin
#
# Description: Check the cpu status
# Author     : Rakesh Narang
# Version    : 1.0
# 
#

prog=`basename $0`

if [ $# -lt 2 ]; then
echo "Usage: $0 <warning> <critical>"
exit 2
fi

# CPU threshold values
CPU_WARNING=$1 
CPU_CRITICAL=$2

if (( $CPU_CRITICAL >= $CPU_WARNING ))
then
        echo "Critical value must be less than the warning value"
        exit 5
fi

OUTPUT=`vmstat 1 5|egrep -v "Time|kthr"|awk '{print $22}'|tail -1`


if (( $OUTPUT <= $CPU_CRITICAL )) 
then

        echo "CRITICAL - CPU Utilisation is HIGH $OUTPUT% idle"
        exit 1

elif (( $OUTPUT <= $CPU_WARNING )) 
then

        echo "WARNING - CPU Utilisation is MED $OUTPUT% idle"
        exit 2

elif (( $CPU_WARNING < $OUTPUT ))
then
        echo "OK - CPU Utilisations is OK $OUTPUT% idle"
        exit 0
else
        echo "CPU STATUS UNKNOWN"
        exit 3
        
        
fi