#!/usr/bin/env python
#coding=utf8
import io
import datetime
import time
import traceback
import linecache
import sys
import time
import os
def checkalerterrror(alertfilename):
daylist=['Sun','Mon','Tue','Wed','Thu','Fri','Sat']
keywordlist=['ORA-','Error','Starting ORACLE instance','Shutting down
instance','.trc','fail','WARNING','Warning']
alertlogfileconfig =
os.getcwd()+os.path.sep+'config.'+alertfilename.split('/')[-1]+'.ini'
eventdate=datetime.datetime(1, 1, 1, 0, 0)
startline = 0
try:
with open(alertlogfileconfig,'r') as f:
startline = int(f.read())
except:
print(traceback.format_exc())
try:
'''
count = -1
for count,line in enumerate(open(alertfilename,'rU')):
pass
count += 1
'''
countnums = os.popen('wc -l ' + alertfilename).readline()
count = int(countnums.split()[0])
with open(alertlogfileconfig,'w') as f:
f.write(str(count))
if startline > count :
print('Attention ,the startline is ' + str(startline) +' , the
endline is ' + str(count) + ' ,so reset the startline to 0')
startline = 0
print()
lines = linecache.getlines(alertfilename)[startline:count]
for line in lines :
if len(line) > 3 and line[0:3] in daylist:
eventdate = datetime.datetime.strptime(line.rstrip('\n'), '%a %b
%d %H:%M:%S %Y')
elif len(line) > 3 :
for w in keywordlist:
if w in line:
评论