Fixed runtrap and added runtrap.debug

This commit is contained in:
Eric Renfro 2013-07-08 08:56:03 -04:00
parent 23a6bd21d5
commit db47e1d472
2 changed files with 17 additions and 7 deletions

23
runtrap
View file

@ -6,6 +6,11 @@ lockfile="/tmp/zabbix.trap.${state}.lock"
tempfile=$(mktemp /tmp/zabbix.trap.${state}.tmp.XXXXXXXXXX)
trapdir="$(dirname $(readlink -f $0))/trap.d/${state}"
errors=0
debug=false
if [[ "$0" == *".debug" ]]; then
debug=true
fi
if [[ ! -d "$trapdir" ]]; then
echo "ERROR: Trap directory doesn't exist: $trapdir "
@ -34,7 +39,7 @@ fi
echo 1 > ${lockfile}
for s in ${trapdir}/*
do
$s > ${tempfile} 2> /dev/null
$s >> ${tempfile} 2> /dev/null
if [ $? -ne 0 ]; then
errors=1
fi
@ -46,14 +51,18 @@ done
#echo "Errors: $errors"
#exit 0
zsend=$(zabbix_sender -c ${agentconf} -i ${tempfile})
if [ $? -ne 0 ]; then
echo "ERROR"
if $debug; then
cat ${tempfile}
else
if [[ $errors -gt 0 ]]; then
echo "WARN"
zsend=$(zabbix_sender -c ${agentconf} -i ${tempfile})
if [ $? -ne 0 ]; then
echo "ERROR"
else
echo "OK"
if [[ $errors -gt 0 ]]; then
echo "WARN"
else
echo "OK"
fi
fi
fi

1
runtrap.debug Symbolic link
View file

@ -0,0 +1 @@
runtrap