Saturday, August 18, 2018

python program to check ocssd.log for error/issue/node eviction etc in last 48 hours

# python program to check ocssd.log for error/issue/node eviction etc

#!/usr/bin/env python

import io
import datetime
import traceback

DayList=['Sun','Mon','Tue','Wed','Thu','Fri','Sat']
KeyWordList=['ORA-','Error','CRS-1013','Polling','Diskpingout']
# KeyWordList=['ORA-','Error','Starting ORACLE instance','Shutting down instance']
OutputList=[]

# customize to check last 48 hours in this case
SkipOldEventHours=48

# name and location of ocssd file . it has changed in 12c
AlertLogFile=r'/ora01/grid/11.2.0.4/grid/log/`hostname`/cssd/ocssd.log'

SkipOldEventDateTimeDelta=datetime.timedelta(hours=SkipOldEventHours)
EventDate=datetime.datetime(1, 1, 1, 0, 0)

try:
    with io.open(AlertLogFile,mode='r') as f:
        for line in f:
                for w in KeyWordList:
                    if w in line:
                        OutputList.append([EventDate,line.rstrip('\n')])
except:
    print(traceback.format_exc())

for o in OutputList:
    # use o[0].strftime('%a %b %d %H:%M:%S %Y') to get original Oracle style Format
    print('[%s] %s' % (o[0],o[1]))

# the end