zoukankan      html  css  js  c++  java
  • check datagurad scripts using python

    #!/usr/bin/python
    # -*- coding: utf-8 -*-
    import cx_Oracle  
    import string
    from email import encoders
    from email.header import Header
    from email.mime.text import MIMEText
    from email.utils import parseaddr, formataddr
    import smtplib
    import sys
    import getopt
    import re
    
    opts, args = getopt.getopt(sys.argv[1:], 'H:')
    
    p = re.compile(r"^((?:(2[0-4]d)|(25[0-5])|([01]?dd?)).){3}(?:(2[0-4]d)|(255[0-5])|([01]?dd?))$")
    ip = opts[0][1]
    flag = p.match(ip)
    if not flag:
        sys.exit()
    
    
    mail_host = 'smtp.qq.com'
    mail_user = '123123@qq.com'
    mail_pwd = '12312312'
    to_list = [ '123123@qq.com', '123123123@qq.com' ]
    
    
    conn = cx_Oracle.connect('read/read@%s/test' % ip)    
    cursor = conn.cursor ()  
    
    cursor.execute (''' select max(sequence#) from v$archived_log where dest_id=1 and thread#=%s ''' % '1')  
    #rows = cursor.fetchall()  
    rows = cursor.fetchone()  
    thread1Primary = rows[0]
    cursor.execute (''' select max(sequence#) from  v$log_history  where thread#=%s ''' % '1')  
    rows = cursor.fetchone()  
    thread1Standby = rows[0]
    
    cursor.execute (''' select max(sequence#) from v$archived_log where dest_id=1 and thread#=%s ''' % '2')  
    rows = cursor.fetchone()  
    thread2Primary = rows[0]
    cursor.execute (''' select max(sequence#) from  v$log_history  where thread#=%s ''' % '2')  
    rows = cursor.fetchone()  
    thread2Standby = rows[0]
    
    #    print (",").join(map(lambda x: str(x),row))
    cursor.close ()  
    conn.close ()  
    
    diffThread1 = thread1Primary - thread1Standby
    diffThread2 = thread2Primary - thread2Standby
    
    #msg = u'''
    #            DATAGUARD SYNC ERROR
    #              thread1Primary = %s 
    #              thread1Standby = %s
    #              thread2Primary = %s
    #              thread2Standby = %s
    #''' % (str(thread1Primary),str(thread1Standby),str(thread2Primary),str(thread2Standby))
    #
    #
    #print msg
    if diffThread1 != 0 or diffThread2 !=0:
        msg = u' DATAGUARD ERROR : thread1Primary = %s thread1Standby = %s thread2Primary = %s thread2Standby = %s ' % (str(thread1Primary),str(thread1Standby),str(thread2Primary),str(thread2Standby))
        sys.exit(2)
    else:
        msg = u' DATAGUARD OK : thread1Primary = %s thread1Standby = %s thread2Primary = %s thread2Standby = %s ' % (str(thread1Primary),str(thread1Standby),str(thread2Primary),str(thread2Standby))
        print msg
        
    
    #    send_email( msg, to_list, 'DATAGUARD SYNC ERROR')
  • 相关阅读:
    如何利用排班实现告警的灵活分派?
    OneAlert 携手 BearyChat(倍洽)快速构建 IT 运维 on-call 机制
    OneAPM大讲堂 | Metrics, Tracing 和 Logging 的关系
    OneAPM大讲堂 | Java 异常日志记录最佳实践
    从区块链的角度看企业协作
    为什么 APM 能提升 IT 团队工作质量?
    JavaScript中的私有成员[翻译]
    【工作分解法】IT人,你的工作“轻松”么?
    【数据分析】线性回归与逻辑回归(R语言实现)
    【数据分析】贝叶斯原理以及简单案例说明
  • 原文地址:https://www.cnblogs.com/zhaobin022/p/5057218.html
Copyright © 2011-2022 走看看