如何使用paramiko监控Oracle alert日志
小编给大家分享一下如何使用paramiko监控Oracle alert日志,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!
环境设置
Linux系统为 Centos 6.8
Python环境为 Python 3.6
连接Unix类服务器模块: paramiko
使用的命令我们使用grep命令来判断alert日志中是否有ORA Error及Checkpoint报警
监控alert日志程序如下程序使用paramiko连接linux/Unix服务器后查看alert日志查看报警关键字,当发现错误时输入结果
我们可以for循环批量监控并发送结果到指定的邮箱,这部分就让大家自己写了,可参照我以前的文章
这样即可做到自动化监控了,可大幅减少DBA日常的工作
自动化监控多个Oracle表空间
使用Python发送邮件
程序名称为:checkoraclelog.py
#!/usr/bin/python#coding=utf8importparamikodeforaclelog(ssh,path):alert_log=[]command='grep-E\'ORA-|Checkpoint|Error\''+pathstdin,stdout,stderr=ssh.exec_command(command)err=stderr.readlines()iflen(err)!=0:print(err)returnFalseelse:stdout_content=stdout.readlines()iflen(stdout_content)!=0:result='\n'.join(stdout_content)result='Oralcelogon'+hostname+'haveerrors\n'+'Thelogpathis'+path+'\n'+resultalert_log.append(result)returnalert_logelse: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()ifalert_log:ifalert_log!='noerror':foriinalert_log:print(i)else:print('ThereisnoORA-erroron'+hostname)exceptExceptionase:print(hostname+''+str(e))验证结果
正常情况下如果有ORA等错误会输出结果
以上是“如何使用paramiko监控Oracle alert日志”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。