Finished runtrap and added states for live and daily operations

This commit is contained in:
Eric Renfro 2013-07-02 10:23:20 -04:00
parent 187a8ede45
commit 70bafc99f2
3 changed files with 25 additions and 16 deletions

41
runtrap
View file

@ -1,25 +1,29 @@
#!/bin/bash #!/bin/bash
lockfile="/tmp/zabbix.trap.lock" state=${1:-live}
tempfile=$(mktemp /tmp/zabbix.trap.tmp.XXXXXXXXXX) lockfile="/tmp/zabbix.trap.${state}.lock"
trapdir="$(dirname $(readlink -f $0))/trap.d" tempfile=$(mktemp /tmp/zabbix.trap.${state}.tmp.XXXXXXXXXX)
trapdir="$(dirname $(readlink -f $0))/trap.d/${state}"
errors=0 errors=0
if [[ ! -d "$trapdir" ]]; then
echo "ERROR: Trap directory doesn't exist: $trapdir "
exit 5
fi
if [[ -r "${lockfile}" ]]; then if [[ -r "${lockfile}" ]]; then
if [[ $(pgrep -f $(readlink -f $0) | wc -l) -gt 0 ]]; then if [[ $(pgrep -f $(readlink -f $0) | wc -l) -gt 0 ]]; then
runs=$(head -n1 ${lockfile}) runs=$(head -n1 ${lockfile})
if [[ $runs -ge 3 ]]; then if [[ $runs -ge 3 ]]; then
echo "need to kill prior poll" for s in ${trapdir}/${state}/*
for s in ${trapdir}/*
do do
echo "Kill: $s " echo "Kill: $s "
pkill -9 -f $s pkill -9 -f $s
done done
rm -f /tmp/zabbix.trap.lock rm -f /tmp/zabbix.trap.${state}.lock
rm -f /tmp/zabbix.trap.tmp.* rm -f /tmp/zabbix.trap.${state}.tmp.*
pkill -9 -f $(readlink -f $0) pkill -9 -f $(readlink -f $0)
else else
#let "runs++"
echo "$[ ++runs ]" > ${lockfile} echo "$[ ++runs ]" > ${lockfile}
exit 0 exit 0
fi fi
@ -27,7 +31,7 @@ if [[ -r "${lockfile}" ]]; then
fi fi
echo 1 > ${lockfile} echo 1 > ${lockfile}
for s in ${trapdir}/* for s in ${trapdir}/${state}/*
do do
$s > ${tempfile} 2> /dev/null $s > ${tempfile} 2> /dev/null
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
@ -35,18 +39,23 @@ do
fi fi
done done
cat ${tempfile} #cat ${tempfile}
rm -f ${tempfile} #rm -f ${tempfile}
echo #echo
echo "Errors: $errors" #echo "Errors: $errors"
exit 0 #exit 0
zsend=$(zabbix_sender -c /etc/zabbix/zabbix_agentd.conf -i ${tempfile}) zsend=$(zabbix_sender -c /etc/zabbix/zabbix_agentd.conf -i ${tempfile})
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "2" echo "ERROR"
else else
echo "${errors}" if [[ $errors -gt 0 ]]; then
echo "WARN"
else
echo "OK"
fi
fi fi
rm -f ${tempfile} rm -f ${tempfile}
rm -f /tmp/zabbix.trap.${state}.lock

View file

View file