最近针对各服务模块日志进行梳理,然后整理相关的日志,针对每个日志文件未有输出则告警,以确认服务运行是否正常~~
#!/usr/bin/perl
use strict;
use POSIX qw( strftime);
my $DATE = strftime("%Y-%m-%d", localtime(time));
my $DIR_PATH = "/home/coremail/logs/api";
opendir DIR, ${DIR_PATH} or die "Can not open \"$DIR_PATH\": $!\n";
my @FILELIST = readdir DIR;
foreach my $file (@FILELIST){
if($file =~ /$DATE/ && $file =~ /rmi_api|wmsvr|pop3svr|nginxaccess|mtasvr|deliveragent|scequerysvr|udsvr|mssvr|mdsvr/){
Service_Log_Check($file);
}
}
sub Service_Log_Check{
my $INPUT_FILE = shift;
my $path = "/home/coremail/logs/api";
my $file = "$path/$INPUT_FILE";
my $now = time;
my $time = strftime("%Y-%m-%d %H:%M:%S", localtime(time));
my $interval = 300;
my $mtime = (stat($file))[9];
my $ctime = (stat($file))[10];
my $lasttime = $now - $mtime;
if ($lasttime >= $interval) {
Mail_Notify_Error($time,$INPUT_FILE);
}
}
sub Mail_Notify_Error{
my @ARGCHECK = @_;
my $SERVERIP = `grep IPADDR /etc/sysconfig/network-scripts/ifcfg-bond0`;
if($SERVERIP =~ /IPADDR=(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/){
$SERVERIP = $1;
}
my $string = "$ARGCHECK[0] $SERVERIP $ARGCHECK[1]";
print "$string\n";
my $SMTPIP = "smtp.api.localdomain";
my $RECD = "13509609521\@139.com";
my $SEND = "13509609521\@139.com";
my $SUBJECT = "日志输出检查告警邮件";
my $SENDMAIL = "/home/coremail/bin/bsmtp -f $SEND -h $SMTPIP -s $SUBJECT $RECD";
system("echo $string | $SENDMAIL");
}
阅读(1824) | 评论(0) | 转发(0) |