小编给大家分享一下如何使用paramiko监控oracle alert日志,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!环境设置
小编给大家分享一下如何使用paramiko监控oracle alert日志,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!
环境设置
连接Unix类服务器模块: paramiko
我们使用grep命令来判断alert日志中是否有ORA Error及Checkpoint报警
如下程序使用paramiko连接linux/Unix服务器后查看alert日志查看报警关键字,当发现错误时输入结果
我们可以for循环批量监控并发送结果到指定的邮箱,这部分就让大家自己写了,可参照我以前的文章
这样即可做到自动化监控了,可大幅减少DBA日常的工作
自动化监控多个Oracle表空间
使用Python发送邮件
程序名称为:checkoraclelog.py
#!/usr/bin/python
#coding=utf8
import paramiko
def oraclelog(ssh,path):
alert_log=[]
command='grep -E \'ORA-|Checkpoint|Error\' '+path
stdin,stdout,stderr=ssh.exec_command(command)
err=stderr.readlines()
if len(err) != 0:
print (err)
return False else:
stdout_content=stdout.readlines()
if len(stdout_content)!=0:
result='\n'.join(stdout_content)
result= 'Oralce log on '+hostname+ ' have errors\n'+'The log path is '+path+'\n'+result
alert_log.append(result)
return alert_log else:
return 'noerror'if __name__ == '__main__':
hostname='10.60.14.60'
username='root'
passWord='password'
try:
#使用SSHClient方法定义ssh变量
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
#连接目标服务器
ssh.connect(hostname=hostname,port=22,username=username,password=password)
path='/oracle/NP1/saptrace/background/alert_NP1.log'
alert_log=oraclelog(ssh,path)
ssh.close()
if alert_log: if alert_log !='noerror': for i in alert_log:
print (i) else:
print ('There is no ORA- error on '+hostname)
except Exception as e:
print (hostname+' '+str(e))
正常情况下如果有ORA等错误会输出结果
以上是“如何使用paramiko监控Oracle alert日志”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注编程网数据库频道!
--结束END--
本文标题: 如何使用paramiko监控Oracle alert日志
本文链接: https://www.lsjlt.com/news/64163.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-16
2024-05-16
2024-05-16
2024-05-15
2024-05-15
2024-05-15
2024-05-15
2024-05-15
2024-05-15
2024-05-15
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0