Mod aaa-12 modify remote format

RCA:
SOL:
修改人:zhangtao
检视人:
This commit is contained in:
zhangtaohz 2019-08-27 16:20:19 +08:00
parent 465b421c66
commit e939f5705b
2 changed files with 175 additions and 0 deletions

111
libs/files/log/deal_logfiles.sh Executable file
View File

@ -0,0 +1,111 @@
#!/bin/bash
# 本脚本功能:
# 1. 从logrotate配置文件中取出日志文件的路径所有日志文件均以logrotate配置文件中第一行指示的路径为前缀
# 2. 从log_sched配置文件中取出日志文件大小上限
# 3. 计算步骤1指示的日志文件的总大小检测日志总大小是否超出上限若超出则删除所有日志文件
function deal_logs ()
{
# logrotate配置文件路径
logrotate_log_file="/etc/logrotate.d/log-syslog"
#log_sched配置文件路径
log_sched_file="/etc/log-sched.conf"
# 日志文件前缀
prefix=
# 日志大小上限
size_max=0
echo "**********************************************************"
echo " logrotate_cfg: $logrotate_log_file"
echo " log_sched_cfg: $log_sched_file"
echo "**********************************************************"
echo ""
# logrotate配置文件判空
if [ ! -e $logrotate_log_file ] ; then
return
fi
# 从logrotate配置文件中第一行有效行中读取出日志文件前缀
while read line
do
if [ -z $line ] ; then
continue
fi
prefix=$line;
echo "**********************************************************"
echo " get log-file-prefix: $prefix"
echo "**********************************************************"
echo ""
break
done < $logrotate_log_file
if [ -z $prefix ] ; then
echo "get log file failed"
return
fi
# log_sched配置文件判空
if [ ! -e $log_sched_file ] ; then
return
fi
#从log_sched配置文件中读取出日志大小上限值
while read line
do
tmpkey="file.max_size="
if [[ $line = *$tmpkey* ]] ; then
if [[ $line = $tmpkey ]] ; then
echo "size_max is empty, do nothing and return"
return
fi
size_max=${line#$tmpkey}
echo "**********************************************************"
echo " get size_max: $size_max"
echo "**********************************************************"
echo ""
break
fi
done < $log_sched_file
if [ $size_max -eq 0 ] ; then
echo "size_max is 0, do nothing and return"
return
fi
#定期检查日志总大小是否超限
path=$prefix*
echo " get path: $path"
folder_size=$(wc -c $path|grep total |awk '{print $1}')
if [ -z $folder_size ] ; then
folder_size=0
fi
echo "cursize: $folder_size"
echo "maxsize: $size_max"
if [ $folder_size -gt $size_max ] ; then
echo "flush folder $path"
rm -rf $path
sync
fi
}
deal_logs $@

64
libs/files/log/rsyslog.conf Executable file
View File

@ -0,0 +1,64 @@
# /etc/rsyslog.conf Configuration file for rsyslog.
#
# For more information see
# /usr/share/doc/rsyslog-doc/html/rsyslog_conf.html
#
# Default logging rules can be found in /etc/rsyslog.d/50-default.conf
#################
#### MODULES ####
#################
module(load="imuxsock") # provides support for local system logging
#module(load="immark") # provides --MARK-- message capability
# provides UDP syslog reception
#module(load="imudp")
#input(type="imudp" port="514")
# provides TCP syslog reception
#module(load="imtcp")
#input(type="imtcp" port="514")
# provides kernel logging support and enable non-kernel klog messages
module(load="imklog" permitnonkernelfacility="on")
###########################
#### GLOBAL DIRECTIVES ####
###########################
#
# Use traditional timestamp format.
# To enable high precision timestamps, comment out the following line.
#
template(name="RFC3164fmt" type="string" string="<%PRI%>%timestamp:::date-rfc3164% %hostname% %syslogtag%%msg%\n")
template(name="RFC5424fmt" type="string" string="<%PRI%>%protocol-version% %timestamp:::date-rfc3339% %hostname% %app-name% %procid% %structured-data% %msgid%%msg%\n")
$ActionFileDefaultTemplate RFC5424fmt
# Filter duplicated messages
$RepeatedMsgReduction on
#
# Set the default permissions for all log files.
#
$FileOwner syslog
$FileGroup adm
$FileCreateMode 0640
$DirCreateMode 0755
$Umask 0022
$PrivDropToUser syslog
$PrivDropToGroup syslog
#
# Where to place spool and state files
#
$WorkDirectory /var/spool/rsyslog
#
# Include all config files in /etc/rsyslog.d/
#
$IncludeConfig /etc/rsyslog.d/*.conf