#!/bin/sh
#
# Version 1.0 - Aout/2021
# by JTA

iostat=`which iostat 2>/dev/null`
bc=`which bc 2>/dev/null`


# Ensuring we have the needed tools:
( [ ! -f $iostat ] || [ ! -f $bc ] ) && \
	( echo "ERROR: You must have iostat and bc installed in order to run this plugin" && exit -1 )

# Getting parameters:
while getopts "d:w:c:h" OPT; do
	case $OPT in
		"d") disk=$OPTARG;;
		"w") warning=$OPTARG;;
		"c") critical=$OPTARG;;
		"h") help;;
	esac
done

# Adjusting the three warn and crit levels:
crit_tps=`echo $critical | cut -d, -f1`
crit_read=`echo $critical | cut -d, -f2`
crit_written=`echo $critical | cut -d, -f3`

warn_tps=`echo $warning | cut -d, -f1`
warn_read=`echo $warning | cut -d, -f2`
warn_written=`echo $warning | cut -d, -f3`


# Checking parameters:
[ ! -b "/dev/$disk" ] && echo "ERROR: Device incorrectly specified" && help

# Doing the actual check:
average=`$iostat $disk -xk | grep $disk`
echo "**** average = $average"
readsec=`echo $average | awk '{print $2}'`
writesec=`echo $average | awk '{print $8}'`
util=`echo $average | awk '{print $21}'`


echo ""
echo "readsec=$readsec writesec=$writesec util=$util "
exit $status
