File check_spool_page of Package monitoring-plugins-spool_page

#!/bin/sh
#
#
#	Script to check Spool and page file usage on z/VM
#
#
#
#	Check for the command we can use
#
VMCP_COMMAND=vmcp
[ -f /sbin/hcp ] && VMCP_COMMAND=/sbin/HCP
[ -f /sbin/vmcp ] && VMCP_COMMAND=/sbin/vmcp
#
#	The complete result looks like
#
# s390zhi126:~ # vmcp query alloc spool
#                 EXTENT     EXTENT  TOTAL  PAGES   HIGH    %
# VOLID  RDEV      START        END  PAGES IN USE   PAGE USED
# ------ ---- ---------- ---------- ------ ------ ------ ----
# 540SPL 9028          1      10016  1761K 357279  1593K  19%
#                                   ------ ------        ----
# SUMMARY                            1761K 357279         19%
# USABLE                             1761K 357279         19%
# s390zhi126:~ # vmcp query alloc page
#                 EXTENT     EXTENT  TOTAL  PAGES   HIGH    %
# VOLID  RDEV      START        END  PAGES IN USE   PAGE USED
# ------ ---- ---------- ---------- ------ ------ ------ ----
# 540PAG 9029          1      10016  1761K      2    212   1%
#                                   ------ ------        ----
# SUMMARY                            1761K      2          1%
# USABLE                             1761K      2          1%
# 
#
convert_number()
{
erg=`expr $1 : "\([0-9]*\)K"`
if [ $? -eq 1 ]
then
	echo $1
	return
fi
expr $erg \* 1024
}
#
#
#
check_alloc()
{
type=$1
erg=`${VMCP_COMMAND} query alloc $type | grep SUMMARY`
[ $? -ge 1 ] && exit 2
set -- $erg
configvalue=`convert_number $2`
usevalue=`convert_number $3`
percentvalue=`expr $4 : "\([0-9]*\)%"`
echo "$type allocated $configvalue used $usevalue Percent $percentvalue |$type=$configvalue;$usevalue;$percentvalue"
[ $percentvalue -gt $criticalpercetage ] && exit 1
exit 0 
}
#
#	MAIN
#
[ $# -lt 3 ] && exit 2

if [ "$1" = "-c" ]
then
	criticalpercetage=$2
else
	exit 2
fi
[ ! "$3" = page -a ! "$3" = spool ] && exit 2 
check_alloc $3

#
#	If we are here something bad has happened
#
echo "UNKNOWN: something bad has happened"
exit 3