oracle数据库警告,巡检Oracle数据库Alertlog日志警告信息

脚本工作过程很简单,就是每天自动切割Oracle数据库的alert日志到FTP服务器,然后该脚本自动搜索日志文件中是否错误信息等。

切割日志上传FTP的脚本没有添加,该部分很简单的。

1.[文件] odb_alert_log_xunjian.py ~ 3KB     下载(10)

#!/usr/bin/env python

#coding:gbk

"""

Author: Edward.Zhou ---

Purpose: Oracle数据库alert_sid.log日志信息巡检

Created: 2016/5/21

"""

import socket

import ftplib

import re

import os

import codecs

from datetime import date

#下载模块

def ftpget(host, ftpuser, ftppasswd, ftpfile):

ftpcnt = 0

ftpstat = []

errlogs = {}

try:

ftp = ftplib.FTP(host)

ftp.set_debuglevel(0)

except (socket.error, socket.gaierror):

ftpcnt = 1

err = "ERROR:Can't reach %s" % host

ftpstat.append(ftpcnt)

ftpstat.append(err)

return ftpstat

try:

ftp.login(user= ftpuser, passwd= ftppasswd)

except ftplib.error_perm:

ftpcnt = 1

err = "ERROR: cannot login,Please check user and password."

ftpstat.append(ftpcnt)

ftpstat.append(err)

ftp.quit()

return ftpstat

#print ftp.getwelcome()

try:

ftp.cwd("ORA_ALERT_LOG")

except ftplib.Error:

ftpcnt = 1

err = "FTP SERVER not change 'ORA_ALERT_LOG' directory."

ftpstat.append(ftpcnt)

ftpstat.append(err)

ftp.quit()

return ftpstat

if ftpfile in ftp.nlst():

path = "C:\\Windows\\Temp\\"+ftpfile

f = open(path, 'wb')

ftp.retrbinary("RETR " + ftpfile, f.write, 1024)

ftpcnt = 0

ftpstat.append(ftpcnt)

ftpstat.append(path)

ftp.quit()

return ftpstat

else:

ftpcnt = 1

err = "Need to download the file %s does not exist." % (ftpfile)

ftpstat.append(ftpcnt)

ftpstat.append(err)

ftp.quit()

return ftpstat

ftp.set_debuglevel(0)

ftp.close()

#ALERT_LOG日志查找告警信息

def logsearch(filename):

cnt = 0

logstat = []

lines = open(filename, "r").read().decode("utf-8")

rs = re.search(r'ORA-.*', lines)

if rs:

cnt = 1

errlog = rs.group()

logstat.append(cnt)

logstat.append(errlog)

else:

logstat.append(cnt)

return logstat

def main():

ftpfilelist = {

"yj-sop": "10.44.98.12alert_orcl.log",

"yj-cba": "10.44.98.101alert_orcl.log",

"yj-zhdb": "10.44.98.10alert_yjdb02.log",

"yj-vib": "10.44.80.18alert_orcl.log",

"ycomis": "10.44.98.20alert_orcl.log",

"yj-db": "10.44.98.92alert_orcl.log"

}

host = '192.168.223.1'

ftpuser = 'backup'

ftppasswd = 'backup'

print "日期:%s 星期:%s"%(date.today(),date.isoweekday(date.today()))

print

print "Oracle数据库Alert log日志警告信息巡检:"

for hostname in ftpfilelist:

logmsg = ftpget(host, ftpuser, ftppasswd, ftpfilelist[hostname])

if logmsg[0] == 1:

print "服务器:%s\t日志文件:%s\t状态:%s\t错误:%s" % (hostname, ftpfilelist[hostname], "异常", logmsg[1])

else:

errlogs = logsearch(logmsg[1])

os.remove(logmsg[1])

if errlogs[0] == 0:

print "服务器:%s\t日志文件:%s\t状态:%s" % (hostname, ftpfilelist[hostname], "正常")

else:

print "服务器:%s\t日志文件:%s\t状态:%s\t错误:%s" % (hostname, ftpfilelist[hostname], "异常", (errlogs[1]).encode("gbk"))

if __name__ == '__main__':

main()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值