Zabbix monitors whether rsync can pull logs normally through shell script

Background: The
    company synchronizes overseas server logs to local analysis through rsync scripts. Due to network quality problems, it often fails to be pulled. In order to be processed in time, it is necessary to monitor whether the logs can be pulled and processed normally
    . Trigger alarm when the log size within hours is less than 5M or 10M

# CAT . / Usr / local / zabbix_agents_3 2.0 / cripts / platform_log. SH  

# / bin /! Bash 
# 
# Get the current hour numbers 0 - 23 format, and the former five hours 
# statistical size of the combined log within five hours, If both are less than 5M, an alarm is triggered: it may be that no logs have been pulled, or the problem may be merged 
# Get hours 0 ~ 24 
current_hour = ` date +% H` 
last_hour =` date +% H -d ' -1 hours ' ` 
two_hours_ago =` date +% H -d ' -2 hours ' ` 
three_hours_ago =` date +% H -d '-3 hours'`
four_hours_ago=`date +%H -d '-4 hours'`
five_hours_ago=`date +%H -d '-5 hours'`


oneday=$(date -d "today" +"%y%m-%d")
YEAR_MONTH=`date -d "${a} hour" +"%Y-%m"`

MONTH_NUM=${YEAR_MONTH: -2}
oneday_num=${oneday:2:2}
if [ $MONTH_NUM != $oneday_num ];then
    local YEAR_MONTH=`date -d "1 month ago" +%Y-%m`
fi


# /opt_log/platform_logs/downloader/all/2020-04/dl-v2-2004-1305.txt
function downloader_logs
{
    sum=0
    for day_hour in $current_hour $last_hour $two_hours_ago $three_hours_ago $four_hours_ago $five_hours_ago;do
     #计算日志的大小,单位为字节,转换为M
size_num=`du -b /opt_log/platform_logs/downloader/all/${YEAR_MONTH}/dl-v2-${oneday}${day_hour}.txt|awk '{print $1}'` size_m=`expr $((size_num/1024/1024))` #echo ${day_hour}_/opt_log/platform_logs/downloader/all/${YEAR_MONTH}/dl-v2-${oneday}${day_hour}.txt--${size_m}; if [ $size_m -lt 5 ];then sum=$((sum+1)) fi done echo $sum } # /opt_log/platform_logs/datacollection/all/2020-04/co-2004-1715.tx function datacollection_logs { sum=0 for day_hour in $current_hour $last_hour $two_hours_ago $three_hours_ago $four_hours_ago $five_hours_ago;do size_num=`du -b /opt_log/platform_logs/datacollection/all/${YEAR_MONTH}/co-${oneday}${day_hour}.txt|awk '{print $1}'` size_m=`expr $((size_num/1024/1024))` #echo ${day_hour}_/opt_log/platform_logs/datacollection/all/${YEAR_MONTH}/co-${oneday}${day_hour}.txt--${size_m}; if [ $size_m -lt 10 ];then sum=$((sum+1)) fi done echo $sum } # $1 # 具体的监控项 UserParameter=platform.logs[*],/usr/local/zabbix_agents_3.2.0/scripts/platform_log.sh $1

 

Guess you like

Origin www.cnblogs.com/reblue520/p/12721455.html