- 论坛徽章:
- 3
|
#!/bin/bash
message_file="/usr/local/zabbix/scripts/message/type/message.txt"
message_type_file="/usr/local/zabbix/scripts/message/type/message_type_file.txt"
now_time=`date +"%Y%m%d%H"`
new_judge_time=`date +"%M"`
old_judge_time=`date -d"-1 min" +"%M"`
if [ ! -e $message_file ];then
touch $message_file
if [ ! -e $message_type_file ];then
touch $message_type_file
fi
fi
message_type () {
message=`redis-cli absrmmct:type {now_time} > ${message_file}`
message_type=`sed -n 'p;n' ${message_file} > ${message_type_file}`
echo '{'
echo ' "data":['
total=`cat ${message_type_file} | wc -l`
cc=1
while read line
do
if [ $total -ne $cc ];then
echo -n " "
echo \{
echo -n " "
echo \"\{\#MESSAGE_TYPE\}\"\:\"$line\"\}\,
else
echo -n " "
echo \{
echo -n " "
echo \"\{\#MESSAGE_TYPE\}\"\:\"$line\"\}\]\}
fi
((cc++))
done < ${message_type_file}
}
message_type_num () {
sleep 4
num_new_file="/usr/local/zabbix/scripts/message/type/${1}_num_${new_judge_time}.txt"
num_old_file="/usr/local/zabbix/scripts/message/type/${1}_num_${old_judge_time}.txt"
if [ ! -e ${num_new_file} ];then
touch $num_new_file
fi
num=`grep -A 1 $1 ${message_file} | sed -n "2p"`
if [ -z ${num} ];then
echo "0"
else
if [ ${new_judge_time} -eq "00" ] && [ ! -e ${num_old_file} ] || [ ! -e ${num_old_file} ];then
echo ${num} > $num_new_file
echo ${num}
else
echo ${num} > $num_new_file
count_one=`cat ${num_new_file}`
count_two=`cat ${num_old_file}`
count_result=`expr $count_one - $count_two`
echo ${count_result}
fi
fi
} |
|