|
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import commands,time,os
t=time.strftime('%Y%m%d',time.localtime(time.time()))
t1=time.strftime('%Y-%m-%d',time.localtime(time.time()))
Time=t1.split('-')[0]+ t1.split('-')[1]+t1.split('-')[2]
day=t1.split('-')[2]
h=time.localtime()[3]
apache_log_file = "/log/logs/apache/%s/error_%s.log"%(Time,Time)
apache_vhost_abr6_file = "/log/logs/vhosts/hiwork_thor_v10/abr6/%s/error_%s.log"%(Time,Time)
apache_vhost_keepmesp_file = "/log/logs/vhosts/hiwork_thor_v10/keepmesp/%s/error_%s.log"%(Time,Time)
apache_vhost_loveizhifu_file = "/log/logs/vhosts/hiwork_thor_v10/loveizhifu/%s/error_%s.log"%(Time,Time)
def check_apache(apache_log_file):
try:
L=len(apache_log_file.split('/'))
if os.path.exists(r'%s'%apache_log_file):
status,result = commands.getstatusoutput("""cat %s |grep -ni "error" | grep "%s %s:" """ %(apache_log_file,day,h))
if result.count('error') !=0:
count=result.count('error')
if L == 6:
ProjectName = apache_log_file.split('/')[3]
print ProjectName
s1,r1 = commands.getstatusoutput("""/usr/bin/python SendMail.py "有%s处错误 项目名:%s \n%s" """%(count,ProjectName,result))
else:
ProjectName = apache_log_file.split('/')[5]
s2,r2 = commands.getstatusoutput("""/usr/bin/python SendMail.py "有%s处错误 项目名:%s \n%s" """%(count,ProjectName,result))
else:
print "没有错误文件"
except Exception, e:
s2,r2 = commands.getstatusoutput("""/usr/bin/python SendMail.py "脚本出错%s %s %s " """%(sys.argv[0],e.args[0],e.args[1]))
try:
check_apache(apache_log_file)
check_apache(apache_vhost_abr6_file)
check_apache(apache_vhost_keepmesp_file)
check_apache(apache_vhost_loveizhifu_file)
except Exception,e:
s3,r3 = commands.getstatusoutput("""/usr/bin/python SendMail.py "%s脚本出错 %s" """%(sys.argv[0],e))
|
|
|