예제 #1
0
def gen_alert_sqlserver_mirror(server_id, mirror_role):
    if g_alert != "1":
        return -1

    sql = """SELECT a.server_id,
									a.connect,
									a.create_time,
									a.host,
									a.port,
									b.send_mail,
									b.send_mail_to_list,
									b.send_sms,
									b.send_sms_to_list,
									b.send_wx,
									b.tags,
									'sqlserver' AS db_type
								FROM sqlserver_status a, db_cfg_sqlserver b
								WHERE a.server_id = b.id 
									and a.server_id = %s """ % (server_id)
    result = func.mysql_query(sql)
    if result <> 0:
        for line in result:
            server_id = line[0]
            connect = line[1]
            create_time = line[2]
            host = line[3]
            port = line[4]
            send_mail = line[5]
            send_mail_to_list = line[6]
            send_sms = line[7]
            send_sms_to_list = line[8]
            send_wx = line[9]
            tags = line[10]
            db_type = line[11]

            if send_mail_to_list is None or send_mail_to_list.strip() == '':
                send_mail_to_list = mail_to_list_common
            if send_sms_to_list is None or send_sms_to_list.strip() == '':
                send_sms_to_list = sms_to_list_common

            if mirror_role == 1:
                send_mail = func.update_send_mail_status(
                    server_id, db_type, 'mirroring_role', send_mail,
                    send_mail_max_count)
                send_sms = func.update_send_sms_status(server_id, db_type,
                                                       'mirroring_role',
                                                       send_sms,
                                                       send_sms_max_count)
                send_wx = func.update_send_wx_status(server_id, db_type,
                                                     'mirroring_role', send_wx)
                func.add_alert(server_id, tags, host, port, create_time,
                               db_type, 'mirroring_role', mirror_role,
                               'critical', 'Database role is NOT match!',
                               send_mail, send_mail_to_list, send_sms,
                               send_sms_to_list, send_wx)
                func.update_db_status('repl', 3, server_id, host, db_type,
                                      create_time, 'mirroring_role',
                                      mirror_role, 'critical')
            else:
                func.check_if_ok(server_id, tags, host, port, create_time,
                                 db_type, 'mirroring_role', mirror_role,
                                 'Database role is OK!', send_mail,
                                 send_mail_to_list, send_sms, send_sms_to_list,
                                 send_wx)
                func.update_db_status('repl', 1, server_id, host, db_type,
                                      create_time, 'mirroring_role',
                                      mirror_role, 'ok')
    else:
        pass
예제 #2
0
def gen_alert_sqlserver_status(server_id):
    if g_alert != "1":
        return -1

    sql = """SELECT a.server_id,
									a.connect,
									a.processes,
									a.processes_running,
									a.processes_waits,
									a.create_time,
									a.host,
									a.port,
									b.alarm_processes,
									b.alarm_processes_running,
									alarm_processes_waits,
									b.threshold_warning_processes,
									b.threshold_warning_processes_running,
									b.threshold_warning_processes_waits,
									b.threshold_critical_processes,
									threshold_critical_processes_running,
									threshold_critical_processes_waits,
									b.send_mail,
									b.send_mail_to_list,
									b.send_sms,
									b.send_sms_to_list,
									b.send_wx,
									b.tags,
									'sqlserver' AS db_type
								FROM sqlserver_status a, db_cfg_sqlserver b
								WHERE a.server_id = b.id 
									and a.server_id = %s """ % (server_id)
    result = func.mysql_query(sql)
    if result <> 0:
        for line in result:
            server_id = line[0]
            connect = line[1]
            processes = line[2]
            processes_running = line[3]
            processes_waits = line[4]
            create_time = line[5]
            host = line[6]
            port = line[7]
            alarm_processes = line[8]
            alarm_processes_running = line[9]
            alarm_processes_waits = line[10]
            threshold_warning_processes = line[11]
            threshold_warning_processes_running = line[12]
            threshold_warning_processes_waits = line[13]
            threshold_critical_processes = line[14]
            threshold_critical_processes_running = line[15]
            threshold_critical_processes_waits = line[16]
            send_mail = line[17]
            send_mail_to_list = line[18]
            send_sms = line[19]
            send_sms_to_list = line[20]
            send_wx = line[21]
            tags = line[22]
            db_type = line[23]

            if send_mail_to_list is None or send_mail_to_list.strip() == '':
                send_mail_to_list = mail_to_list_common
            if send_sms_to_list is None or send_sms_to_list.strip() == '':
                send_sms_to_list = sms_to_list_common
            if connect <> 1:
                send_mail = func.update_send_mail_status(
                    server_id, db_type, 'connect', send_mail,
                    send_mail_max_count)
                send_sms = func.update_send_sms_status(server_id, db_type,
                                                       'connect', send_sms,
                                                       send_sms_max_count)
                send_wx = func.update_send_wx_status(server_id, db_type,
                                                     'connect', send_wx)
                func.add_alert(server_id, tags, host, port, create_time,
                               db_type, 'connect', 'down', 'critical',
                               'sqlserver server down', send_mail,
                               send_mail_to_list, send_sms, send_sms_to_list,
                               send_wx)
                func.update_db_status('connect', '3', server_id, host, db_type,
                                      create_time, 'connect', 'down',
                                      'critical')
                func.update_db_status('sessions', '-1', server_id, host,
                                      db_type, '', '', '', '')
                func.update_db_status('actives', '-1', server_id, host,
                                      db_type, '', '', '', '')
                func.update_db_status('waits', '-1', server_id, host, db_type,
                                      '', '', '', '')
                func.update_db_status('repl', '-1', server_id, host, db_type,
                                      '', '', '', '')
                func.update_db_status('repl_delay', '-1', server_id, host,
                                      db_type, '', '', '', '')
            else:

                func.check_if_ok(server_id, tags, host, port, create_time,
                                 db_type, 'connect', 'up',
                                 'sqlserver server up', send_mail,
                                 send_mail_to_list, send_sms, send_sms_to_list,
                                 send_wx)
                func.update_db_status('connect', '1', server_id, host, db_type,
                                      create_time, 'connect', 'up', 'ok')
                if int(alarm_processes) == 1:
                    if int(processes) >= int(threshold_critical_processes):
                        #send_mail = func.update_send_mail_status(server_id,db_type,'processes',send_mail,send_mail_max_count)
                        #send_sms = func.update_send_sms_status(server_id,db_type,'processes',send_sms,send_sms_max_count)
                        #func.add_alert(server_id,tags,host,port,create_time,db_type,'processes',processes,'critical','too many processes',send_mail,send_mail_to_list,send_sms,send_sms_to_list,send_wx)
                        func.update_db_status('sessions', 3, server_id, host,
                                              db_type, create_time,
                                              'processes', processes,
                                              'critical')
                    elif int(processes) >= int(threshold_warning_processes):
                        #send_mail = func.update_send_mail_status(server_id,db_type,'processes',send_mail,send_mail_max_count)
                        #send_sms = func.update_send_sms_status(server_id,db_type,'processes',send_sms,send_sms_max_count)
                        #func.add_alert(server_id,tags,host,port,create_time,db_type,'processes',processes,'warning','too many processes',send_mail,send_mail_to_list,send_sms,send_sms_to_list,send_wx)
                        func.update_db_status('sessions', 2, server_id, host,
                                              db_type, create_time,
                                              'processes', processes,
                                              'warning')
                    else:
                        func.update_db_status('sessions', 1, server_id, host,
                                              db_type, create_time,
                                              'processes', processes, 'ok')
                        func.check_if_ok(server_id, tags, host, port,
                                         create_time, db_type, 'processes',
                                         processes, 'processes ok', send_mail,
                                         send_mail_to_list, send_sms,
                                         send_sms_to_list, send_wx)

                if int(alarm_processes_running) == 1:
                    if int(processes_running) >= int(
                            threshold_critical_processes_running):
                        #send_mail = func.update_send_mail_status(server_id,db_type,'processes_running',send_mail,send_mail_max_count)
                        #send_sms = func.update_send_sms_status(server_id,db_type,'processes_running',send_sms,send_sms_max_count)
                        #func.add_alert(server_id,tags,host,port,create_time,db_type,'processes_running',processes_running,'critical','too many processes running',send_mail,send_mail_to_list,send_sms,send_sms_to_list,send_wx)
                        func.update_db_status('actives', 3, server_id, host,
                                              db_type, create_time,
                                              'processes_running',
                                              processes_running, 'critical')
                    elif int(processes_running) >= int(
                            threshold_warning_processes_running):
                        #send_mail = func.update_send_mail_status(server_id,db_type,'processes_running',send_mail,send_mail_max_count)
                        #send_sms = func.update_send_sms_status(server_id,db_type,'processes_running',send_sms,send_sms_max_count)
                        #func.add_alert(server_id,tags,host,port,create_time,db_type,'processes_running',processes_running,'critical','too many processes running',send_mail,send_mail_to_list,send_sms,send_sms_to_list,send_wx)
                        func.update_db_status('actives', 2, server_id, host,
                                              db_type, create_time,
                                              'processes_running',
                                              processes_running, 'warning')
                    else:
                        func.update_db_status('actives', 1, server_id, host,
                                              db_type, create_time,
                                              'processes_running',
                                              processes_running, 'ok')
                        func.check_if_ok(server_id, tags, host, port,
                                         create_time, db_type,
                                         'processes_running',
                                         processes_running,
                                         'processes running ok', send_mail,
                                         send_mail_to_list, send_sms,
                                         send_sms_to_list, send_wx)

                if int(alarm_processes_waits) == 1:
                    if int(processes_waits) >= int(
                            threshold_critical_processes_waits):
                        #send_mail = func.update_send_mail_status(server_id,db_type,'processes_waits',send_mail,send_mail_max_count)
                        #send_sms = func.update_send_sms_status(server_id,db_type,'processes_waits',send_sms,send_sms_max_count)
                        #func.add_alert(server_id,tags,host,port,create_time,db_type,'processes_waits',processes_waits,'critical','too many processes waits',send_mail,send_mail_to_list,send_sms,send_sms_to_list,send_wx)
                        func.update_db_status('waits', 3, server_id, host,
                                              db_type, create_time,
                                              'processes_waits',
                                              processes_waits, 'critical')
                    elif int(processes_waits) >= int(
                            threshold_warning_processes_waits):
                        #send_mail = func.update_send_mail_status(server_id,db_type,'processes_waits',send_mail,send_mail_max_count)
                        #send_sms = func.update_send_sms_status(server_id,db_type,'processes_waits',send_sms,send_sms_max_count)
                        #func.add_alert(server_id,tags,host,port,create_time,db_type,'processes_waits',processes_waits,'warning','too many processes waits',send_mail,send_mail_to_list,send_sms,send_sms_to_list,send_wx)
                        func.update_db_status('waits', 2, server_id, host,
                                              db_type, create_time,
                                              'processes_waits',
                                              processes_waits, 'warning')
                    else:
                        func.update_db_status('waits', 1, server_id, host,
                                              db_type, create_time,
                                              'processes_waits',
                                              processes_waits, 'ok')
                        func.check_if_ok(server_id, tags, host, port,
                                         create_time, db_type,
                                         'processes_waits', processes_waits,
                                         'processes waits ok', send_mail,
                                         send_mail_to_list, send_sms,
                                         send_sms_to_list, send_wx)

    else:
        pass
예제 #3
0
def gen_alert_oracle_diskgroup(server_id):
    if g_alert != "1":
        return -1
        
    sql = """SELECT a.server_id,
										a.diskgroup_name,
										a.total_mb,
										a.free_mb,
										CONVERT(a.used_rate, DECIMAL(5,2)) as used_rate,
										a.create_time,
										b.HOST,
										b.PORT,
										b.alarm_asm_space,
										b.threshold_warning_asm_space,
										b.threshold_critical_asm_space,
										b.send_mail,
										b.send_mail_to_list,
										b.send_sms,
										b.send_sms_to_list,
										b.send_wx,
										b.tags,
										'oracle' AS db_type
						FROM oracle_diskgroup a, db_cfg_oracle b
						WHERE a.server_id = b.id
							and a.server_id = %s
							and CONVERT(a.used_rate, DECIMAL(5,2)) >= b.threshold_warning_asm_space
						ORDER BY used_rate """ %(server_id)
    result=func.mysql_query(sql)
    if result <> 0:
        for line in result:
            #print "diskgroup_name: %s" %(line[1])
            server_id=line[0]
            diskgroup_name=line[1]
            total_mb=line[2]
            free_mb=line[3]
            used_rate=line[4]
            create_time=line[5]
            host=line[6]
            port=line[7]
            alarm_asm_space=line[8]
            threshold_warning_asm_space=line[9]
            threshold_critical_asm_space=line[10]
            send_mail=line[11]
            send_mail_to_list=line[12]
            send_sms=line[13]
            send_sms_to_list=line[14]
            send_wx=line[15]
            tags=line[16]
            db_type=line[17]
            
            if send_mail_to_list is None or  send_mail_to_list.strip()=='':
                send_mail_to_list = mail_to_list_common
            if send_sms_to_list is None or  send_sms_to_list.strip()=='':
                send_sms_to_list = sms_to_list_common
                
            if int(alarm_asm_space)==1:
                if int(used_rate) >= int(threshold_critical_asm_space):
                    send_mail = func.update_send_mail_status(server_id,db_type,'diskgroup(%s)' %(diskgroup_name),send_mail,send_mail_max_count)
                    send_sms  = func.update_send_sms_status(server_id,db_type,'diskgroup(%s)' %(diskgroup_name),send_sms,send_sms_max_count)
                    send_wx  = func.update_send_wx_status(server_id,db_type,'diskgroup(%s)' %(diskgroup_name),send_wx)
                    func.add_alert(server_id,tags,host,port,create_time,db_type,'diskgroup(%s)' %(diskgroup_name),used_rate,'critical','diskgroup %s usage reach %s' %(diskgroup_name,used_rate),send_mail,send_mail_to_list,send_sms,send_sms_to_list,send_wx)
                    func.update_db_status('diskgroup',3,server_id, host, db_type,create_time,'diskgroup(%s)' %(diskgroup_name),used_rate,'critical')
                elif int(used_rate) >= int(threshold_warning_asm_space):
                    send_mail = func.update_send_mail_status(server_id,db_type,'diskgroup(%s)' %(diskgroup_name),send_mail,send_mail_max_count)
                    send_sms  = func.update_send_sms_status(server_id,db_type,'diskgroup(%s)' %(diskgroup_name),send_sms,send_sms_max_count)
                    send_wx  = func.update_send_wx_status(server_id,db_type,'diskgroup(%s)' %(diskgroup_name),send_wx)
                    func.add_alert(server_id,tags,host,port,create_time,db_type,'diskgroup(%s)' %(diskgroup_name),used_rate,'warning','diskgroup %s usage reach %s' %(diskgroup_name,used_rate),send_mail,send_mail_to_list,send_sms,send_sms_to_list,send_wx)
                    func.update_db_status('diskgroup',2,server_id, host, db_type,create_time,'diskgroup(%s)' %(diskgroup_name),used_rate,'warning')
                else:
                    func.check_if_ok(server_id,tags,host,port,create_time,db_type,'diskgroup(%s)' %(diskgroup_name),used_rate,'tablespace %s usage ok' %(diskgroup_name),send_mail,send_mail_to_list,send_sms,send_sms_to_list,send_wx)
                    func.update_db_status('diskgroup',1,server_id, host, db_type,create_time,'diskgroup','max(%s:%s)' %(diskgroup_name,used_rate),'ok')
    else:
       pass
예제 #4
0
def gen_alert_mysql_replcation(server_id):
    if g_alert != "1":
        return -1

    sql = """SELECT a.server_id,
										a.slave_io_run,
										a.slave_sql_run,
										a.delay,
										a.create_time,
										b.host,
										b.port,
										b.alarm_repl_status,
										b.alarm_repl_delay,
										b.threshold_warning_repl_delay,
										b.threshold_critical_repl_delay,
										b.send_mail,
										b.send_mail_to_list,
										b.send_sms,
										b.send_sms_to_list,
										b.tags,
										'mysql' AS db_type
									FROM mysql_dr_s a, db_cfg_mysql b
									WHERE a.server_id = b.id
									and a.server_id = %s """ % (server_id)
    result = func.mysql_query(sql)
    if result <> 0:
        for line in result:
            server_id = line[0]
            slave_io_run = line[1]
            slave_sql_run = line[2]
            delay = line[3]
            create_time = line[4]
            host = line[5]
            port = line[6]
            alarm_repl_status = line[7]
            alarm_repl_delay = line[8]
            threshold_warning_repl_delay = line[9]
            threshold_critical_repl_delay = line[10]
            send_mail = line[11]
            send_mail_to_list = line[12]
            send_sms = line[13]
            send_sms_to_list = line[14]
            tags = line[15]
            db_type = line[16]

            if send_mail_to_list is None or send_mail_to_list.strip() == '':
                send_mail_to_list = mail_to_list_common
            if send_sms_to_list is None or send_sms_to_list.strip() == '':
                send_sms_to_list = sms_to_list_common

            if int(alarm_repl_status) == 1:
                if (slave_io_run == "Yes") and (slave_sql_run == "Yes"):
                    func.check_if_ok(
                        server_id, tags, host, port, create_time, db_type,
                        'replication',
                        'IO:' + slave_io_run + ',SQL:' + slave_sql_run,
                        'replication ok', send_mail, send_mail_to_list,
                        send_sms, send_sms_to_list)
                    func.update_db_status(
                        'repl', 1, server_id, host, db_type, create_time,
                        'replication',
                        'IO:' + slave_io_run + ',SQL:' + slave_sql_run, 'ok')
                    if int(alarm_repl_delay) == 1:
                        if int(delay) >= int(threshold_critical_repl_delay):
                            send_mail = func.update_send_mail_status(
                                server_id, db_type, 'repl_delay', send_mail,
                                send_mail_max_count)
                            send_sms = func.update_send_sms_status(
                                server_id, db_type, 'repl_delay', send_sms,
                                send_sms_max_count)
                            func.add_alert(server_id, tags, host, port,
                                           create_time, db_type, 'repl_delay',
                                           delay, 'critical',
                                           'replication has delay', send_mail,
                                           send_mail_to_list, send_sms,
                                           send_sms_to_list)
                            func.update_db_status('repl_delay', 3, server_id,
                                                  host, db_type, create_time,
                                                  'repl_delay', delay,
                                                  'critical')
                        elif int(delay) >= int(threshold_warning_repl_delay):
                            send_mail = func.update_send_mail_status(
                                server_id, db_type, 'repl_delay', send_mail,
                                send_mail_max_count)
                            send_sms = func.update_send_sms_status(
                                server_id, db_type, 'repl_delay', send_sms,
                                send_sms_max_count)
                            func.add_alert(server_id, tags, host, port,
                                           create_time, db_type, 'repl_delay',
                                           delay, 'warning',
                                           'replication has delay', send_mail,
                                           send_mail_to_list, send_sms,
                                           send_sms_to_list)
                            func.update_db_status('repl_delay', 2, server_id,
                                                  host, db_type, create_time,
                                                  'repl_delay', delay,
                                                  'warning')
                        else:
                            func.check_if_ok(server_id, tags, host, port,
                                             create_time, db_type,
                                             'repl_delay', delay,
                                             'replication delay ok', send_mail,
                                             send_mail_to_list, send_sms,
                                             send_sms_to_list)
                            func.update_db_status('repl_delay', 1, server_id,
                                                  host, db_type, create_time,
                                                  'repl_delay', delay, 'ok')
                else:
                    send_mail = func.update_send_mail_status(
                        server_id, db_type, 'replication', send_mail,
                        send_mail_max_count)
                    send_sms = func.update_send_sms_status(
                        server_id, db_type, 'replication', send_sms,
                        send_sms_max_count)
                    func.add_alert(
                        server_id, tags, host, port, create_time, db_type,
                        'replication',
                        'IO:' + slave_io_run + ',SQL:' + slave_sql_run,
                        'critical', 'replication stop', send_mail,
                        send_mail_to_list, send_sms, send_sms_to_list)
                    func.update_db_status(
                        'repl', 3, server_id, host, db_type, create_time,
                        'replication',
                        'IO:' + slave_io_run + ',SQL:' + slave_sql_run,
                        'critical')
                    func.update_db_status('repl_delay', '-1', server_id, host,
                                          db_type, '', '', '', '')
    else:
        pass
예제 #5
0
def gen_alert_oracle_status(server_id):
    if g_alert != "1":
        return -1
        
    sql = """SELECT a.server_id,
										a.connect,
										a.session_total,
										a.session_actives,
										a.session_waits,
										CONVERT(a.flashback_space_used, DECIMAL(10,2)) as flashback_space_used,
										a.database_role,
										a.dg_stats,
										a.dg_delay,
										a.startup_time,
										a.create_time,
										b.HOST,
										b.PORT,
										b.alarm_session_total,
										b.alarm_session_actives,
										b.alarm_session_waits,
									  b.alarm_fb_space,
										b.threshold_warning_session_total,
										b.threshold_critical_session_total,
										b.threshold_warning_session_actives,
										b.threshold_critical_session_actives,
										b.threshold_warning_session_waits,
										b.threshold_critical_session_waits,
										b.threshold_warning_fb_space,
										b.threshold_critical_fb_space,
										b.send_mail,
										b.send_mail_to_list,
										b.send_sms,
										b.send_sms_to_list,
										b.send_wx,
										b.tags,
										'oracle' AS db_type
									FROM oracle_status a, db_cfg_oracle b
									WHERE a.server_id = b.id
									  and a.server_id = %s """ %(server_id)
    result=func.mysql_query(sql)
    if result <> 0:
        for line in result:
            server_id=line[0]
            connect=line[1]
            session_total=line[2]
            session_actives=line[3]
            session_waits=line[4]
            flashback_space_used=line[5]
            database_role=line[6]
            mrp_status=line[7]
            dg_delay=line[8]
            startup_time=line[9]
            create_time=line[10]
            host=line[11]
            port=line[12]
            alarm_session_total=line[13]
            alarm_session_actives=line[14]
            alarm_session_waits=line[15]
            alarm_fb_space=line[16]
            threshold_warning_session_total=line[17]
            threshold_critical_session_total=line[18]
            threshold_warning_session_actives=line[19]
            threshold_critical_session_actives=line[20]
            threshold_warning_session_waits=line[21]
            threshold_critical_session_waits=line[22]
            threshold_warning_fb_space=line[23]
            threshold_critical_fb_space=line[24]
            send_mail=line[25]
            send_mail_to_list=line[26]
            send_sms=line[27]
            send_sms_to_list=line[28]
            send_wx=line[29]
            tags=line[30]
            db_type=line[31]
        
            if send_mail_to_list is None or  send_mail_to_list.strip()=='':
                send_mail_to_list = mail_to_list_common
            if send_sms_to_list is None or  send_sms_to_list.strip()=='':
                send_sms_to_list = sms_to_list_common
                
            if connect <> 1:
                send_mail = func.update_send_mail_status(server_id,db_type,'connect',send_mail,send_mail_max_count)
                send_sms  = func.update_send_sms_status(server_id,db_type,'connect',send_sms,send_sms_max_count)
                send_wx  = func.update_send_wx_status(server_id,db_type,'connect',send_wx)
                func.add_alert(server_id,tags,host,port,create_time,db_type,'connect','down','critical','oracle server down',send_mail,send_mail_to_list,send_sms,send_sms_to_list,send_wx)
                func.update_db_status('connect','3',server_id, host, db_type,create_time,'connect','down','critical')
                func.update_db_status('sessions','-1',server_id, host, db_type,'','','','')
                func.update_db_status('actives','-1',server_id, host, db_type,'','','','')
                func.update_db_status('waits','-1',server_id, host, db_type,'','','','')
                func.update_db_status('repl','-1',server_id, host, db_type,'','','','')
                func.update_db_status('repl_delay','-1',server_id, host, db_type,'','','','')
                func.update_db_status('tablespace','-1',server_id, host, db_type,'','','','')
            else:
                func.check_if_ok(server_id,tags,host,port,create_time,db_type,'connect','up','oracle server up',send_mail,send_mail_to_list,send_sms,send_sms_to_list,send_wx)
                func.update_db_status('connect','1',server_id, host, db_type,create_time,'connect','up','ok')
                
                # 数据库从备库切换为primary时,需要更新repl和repl_delay
                if database_role=="PRIMARY":
                    func.update_db_status('repl','-1',server_id, host, db_type,'','','','')
                    func.update_db_status('repl_delay','-1',server_id, host, db_type,'','','','')
                

                # 数据库重启告警
                sql= "select startup_time from oracle_status_his s where s.server_id = %s and connect = 1 order by id desc limit 1;" %(server_id)
                last_startup=func.mysql_single_query(sql)
                if last_startup:
                    if last_startup != startup_time:
                        msg = "database on %s has been restarted" %(host)   
                        send_mail = func.update_send_mail_status(server_id,db_type,'db_restarted',send_mail,send_mail_max_count)
                        send_sms  = func.update_send_sms_status(server_id,db_type,'db_restarted',send_sms,send_sms_max_count) 
                        send_wx  = func.update_send_wx_status(server_id,db_type,'db_restarted',send_wx)                                            
                        func.add_alert(server_id,tags,host,port,create_time,db_type,'db_restarted',session_total,'warning',msg,send_mail,send_mail_to_list,send_sms,send_sms_to_list,send_wx)
                        
                        
                if int(alarm_session_total)==1:
                    if int(session_total) >= int(threshold_critical_session_total):
                        #send_mail = func.update_send_mail_status(server_id,db_type,'session_total',send_mail,send_mail_max_count)
                        #send_sms  = func.update_send_sms_status(server_id,db_type,'session_total',send_sms,send_sms_max_count)
                        #func.add_alert(server_id,tags,host,port,create_time,db_type,'session_total',session_total,'critical','too many sessions',send_mail,send_mail_to_list,send_sms,send_sms_to_list,send_wx)
                        func.update_db_status('sessions',3,server_id, host, db_type,create_time,'session_total',session_total,'critical')
                    elif int(session_total) >= int(threshold_warning_session_total):
                        #send_mail = func.update_send_mail_status(server_id,db_type,'session_total',send_mail,send_mail_max_count)
                        #send_sms  = func.update_send_sms_status(server_id,db_type,'session_total',send_sms,send_sms_max_count)
                        #func.add_alert(server_id,tags,host,port,create_time,db_type,'session_total',session_total,'warning','too many sessions',send_mail,send_mail_to_list,send_sms,send_sms_to_list,send_wx)
                        func.update_db_status('sessions',2,server_id, host, db_type,create_time,'session_total',session_total,'warning')
                    else:
                        func.check_if_ok(server_id,tags,host,port,create_time,db_type,'session_total',session_total,'sessions ok',send_mail,send_mail_to_list,send_sms,send_sms_to_list,send_wx)
                        func.update_db_status('sessions',1,server_id, host, db_type,create_time,'session_total',session_total,'ok')
        
                if int(alarm_session_actives)==1:
                    if int(session_actives) >= int(threshold_critical_session_actives):
                        #send_mail = func.update_send_mail_status(server_id,db_type,'session_actives',send_mail,send_mail_max_count)
                        #send_sms  = func.update_send_sms_status(server_id,db_type,'session_actives',send_sms,send_sms_max_count)
                        #func.add_alert(server_id,tags,host,port,create_time,db_type,'session_actives',session_actives,'critical','too many active sessions',send_mail,send_mail_to_list,send_sms,send_sms_to_list,send_wx)
                        func.update_db_status('actives',3,server_id, host, db_type,create_time,'session_actives',session_actives,'critical')
                    elif int(session_actives) >= int(threshold_warning_session_actives): 
                        #send_mail = func.update_send_mail_status(server_id,db_type,'session_actives',send_mail,send_mail_max_count)
                        #send_sms  = func.update_send_sms_status(server_id,db_type,'session_actives',send_sms,send_sms_max_count)
                        #func.add_alert(server_id,tags,host,port,create_time,db_type,'session_actives',session_actives,'warning','too many active sessions',send_mail,send_mail_to_list,send_sms,send_sms_to_list,send_wx)
                        func.update_db_status('actives',2,server_id, host, db_type,create_time,'session_actives',session_actives,'warning')
                    else:
                        func.check_if_ok(server_id,tags,host,port,create_time,db_type,'session_actives',session_actives,'active sessions ok',send_mail,send_mail_to_list,send_sms,send_sms_to_list,send_wx)
                        func.update_db_status('actives',1,server_id, host, db_type,create_time,'session_actives',session_actives,'ok')

                if int(alarm_session_waits)==1:
                    if int(session_waits) >= int(threshold_critical_session_waits):
                        #send_mail = func.update_send_mail_status(server_id,db_type,'session_waits',send_mail,send_mail_max_count)
                        #send_sms  = func.update_send_sms_status(server_id,db_type,'session_waits',send_sms,send_sms_max_count)
                        #func.add_alert(server_id,tags,host,port,create_time,db_type,'session_waits',session_waits,'critical','too many waits sessions',send_mail,send_mail_to_list,send_sms,send_sms_to_list,send_wx)
                        func.update_db_status('waits',3,server_id, host, db_type,create_time,'session_waits',session_waits,'critical')
                    elif int(session_waits) >= int(threshold_warning_session_waits):
                        #send_mail = func.update_send_mail_status(server_id,db_type,'session_waits',send_mail,send_mail_max_count)
                        #send_sms  = func.update_send_sms_status(server_id,db_type,'session_waits',send_sms,send_sms_max_count)
                        #func.add_alert(server_id,tags,host,port,create_time,db_type,'session_waits',session_waits,'warning','too many waits sessions',send_mail,send_mail_to_list,send_sms,send_sms_to_list,send_wx)
                        func.update_db_status('waits',2,server_id, host, db_type,create_time,'session_waits',session_waits,'warning')
                    else:                        
                        func.check_if_ok(server_id,tags,host,port,create_time,db_type,'session_waits',session_waits,'waits sessions ok',send_mail,send_mail_to_list,send_sms,send_sms_to_list,send_wx)
                        func.update_db_status('waits',1,server_id, host, db_type,create_time,'session_waits',session_waits,'ok')
	
                if int(alarm_fb_space)==1:
                    if int(flashback_space_used) >= int(threshold_critical_fb_space):
                        send_mail = func.update_send_mail_status(server_id,db_type,'flashback_space_used',send_mail,send_mail_max_count)
                        send_sms  = func.update_send_sms_status(server_id,db_type,'flashback_space_used',send_sms,send_sms_max_count)
                        send_wx  = func.update_send_wx_status(server_id,db_type,'flashback_space_used',send_wx)                              
                        func.add_alert(server_id,tags,host,port,create_time,db_type,'flashback_space_used',flashback_space_used,'critical','flashback space usage reach %s'%(flashback_space_used),send_mail,send_mail_to_list,send_sms,send_sms_to_list,send_wx)
                        func.update_db_status('flashback_space',3,server_id, host, db_type,create_time,'flashback_space_used',flashback_space_used,'critical')
                    elif int(flashback_space_used) >= int(threshold_warning_fb_space):
                        send_mail = func.update_send_mail_status(server_id,db_type,'flashback_space_used',send_mail,send_mail_max_count)
                        send_sms  = func.update_send_sms_status(server_id,db_type,'flashback_space_used',send_sms,send_sms_max_count)
                        send_wx  = func.update_send_wx_status(server_id,db_type,'flashback_space_used',send_wx)                              
                        func.add_alert(server_id,tags,host,port,create_time,db_type,'flashback_space_used',flashback_space_used,'warning','flashback space usage reach %s'%(flashback_space_used),send_mail,send_mail_to_list,send_sms,send_sms_to_list,send_wx)
                        func.update_db_status('flashback_space',2,server_id, host, db_type,create_time,'flashback_space_used',flashback_space_used,'warning')
                    else:                        
                        func.check_if_ok(server_id,tags,host,port,create_time,db_type,'flashback_space_used',flashback_space_used,'flashback space ok',send_mail,send_mail_to_list,send_sms,send_sms_to_list,send_wx)
                        func.update_db_status('flashback_space',1,server_id, host, db_type,create_time,'flashback_space_used',flashback_space_used,'ok')
                        
    else:
       pass
예제 #6
0
def gen_alert_oracle_tablespace(server_id):
    if g_alert != "1":
        return -1
        
    sql = """SELECT a.server_id,
										a.tablespace_name,
										a.total_size,
										a.used_size,
										CONVERT(a.max_rate, DECIMAL(6,2)) as max_rate,
										a.create_time,
										b. HOST,
										b. PORT,
										b.alarm_tablespace,
										b.threshold_warning_tablespace,
										b.threshold_critical_tablespace,
										b.filter_tbs,
										b.send_mail,
										b.send_mail_to_list,
										b.send_sms,
										b.send_sms_to_list,
										b.send_wx,
										b.tags,
										'oracle' AS db_type
						FROM oracle_tablespace a, db_cfg_oracle b
						WHERE a.server_id = b.id
							and a.server_id = %s
						ORDER BY max_rate """ %(server_id)
    result=func.mysql_query(sql)
    if result <> 0:
        for line in result:
            server_id=line[0]
            tablespace_name=line[1]
            total_size=line[2]
            used_size=line[3]
            max_rate=line[4]
            create_time=line[5]
            host=line[6]
            port=line[7]
            alarm_tablespace=line[8]
            threshold_warning_tablespace=line[9]
            threshold_critical_tablespace=line[10]
            filter_tbs=line[11]
            send_mail=line[12]
            send_mail_to_list=line[13]
            send_sms=line[14]
            send_sms_to_list=line[15]
            send_wx=line[16]
            tags=line[17]
            db_type=line[18]

            
            if send_mail_to_list is None or  send_mail_to_list.strip()=='':
                send_mail_to_list = mail_to_list_common
            if send_sms_to_list is None or  send_sms_to_list.strip()=='':
                send_sms_to_list = sms_to_list_common
            
            
            # 验证是否属于过滤表空间
            is_skip = 0
            if filter_tbs:
                list_tbs = filter_tbs.split(',');
                if list_tbs:
                    for i in range(len(list_tbs)):
                        if tablespace_name == list_tbs[i].upper():
                            is_skip = 1
                            break

            if int(alarm_tablespace)==1 and is_skip == 0:
                if int(max_rate) >= int(threshold_critical_tablespace):
                    send_mail = func.update_send_mail_status(server_id,db_type,'tablespace(%s)' %(tablespace_name),send_mail,send_mail_max_count)
                    send_sms  = func.update_send_sms_status(server_id,db_type,'tablespace(%s)' %(tablespace_name),send_sms,send_sms_max_count)
                    send_wx  = func.update_send_wx_status(server_id,db_type,'tablespace(%s)' %(tablespace_name),send_wx)
                    func.add_alert(server_id,tags,host,port,create_time,db_type,'tablespace(%s)' %(tablespace_name),max_rate,'critical','tablespace %s usage reach %s' %(tablespace_name,max_rate),send_mail,send_mail_to_list,send_sms,send_sms_to_list,send_wx)
                    func.update_db_status('tablespace',3,server_id, host, db_type,create_time,'tablespace(%s)' %(tablespace_name),max_rate,'critical')
                elif int(max_rate) >= int(threshold_warning_tablespace):
                    send_mail = func.update_send_mail_status(server_id,db_type,'tablespace(%s)' %(tablespace_name),send_mail,send_mail_max_count)
                    send_sms  = func.update_send_sms_status(server_id,db_type,'tablespace(%s)' %(tablespace_name),send_sms,send_sms_max_count)
                    send_wx  = func.update_send_wx_status(server_id,db_type,'tablespace(%s)' %(tablespace_name),send_wx)
                    func.add_alert(server_id,tags,host,port,create_time,db_type,'tablespace(%s)' %(tablespace_name),max_rate,'warning','tablespace %s usage reach %s' %(tablespace_name,max_rate),send_mail,send_mail_to_list,send_sms,send_sms_to_list,send_wx)
                    func.update_db_status('tablespace',2,server_id, host, db_type,create_time,'tablespace(%s)' %(tablespace_name),max_rate,'warning')
                else:
                    func.check_if_ok(server_id,tags,host,port,create_time,db_type,'tablespace(%s)' %(tablespace_name),max_rate,'tablespace %s usage ok' %(tablespace_name),send_mail,send_mail_to_list,send_sms,send_sms_to_list,send_wx)
                    func.update_db_status('tablespace',1,server_id, host, db_type,create_time,'tablespace','max(%s:%s)' %(tablespace_name,max_rate),'ok')
    else:
       pass
예제 #7
0
def gen_alert_oracle_dg(server_id):
    if g_alert != "1":
        return -1
     
    sql = """SELECT a.server_id,
										a.connect,
										a.database_role,
										a.dg_stats,
										a.dg_delay,
										a.create_time,
										b.HOST,
										b.PORT,
										b.send_mail,
										b.send_mail_to_list,
										b.send_sms,
										b.send_sms_to_list,
										b.send_wx,
										b.tags,
										'oracle' AS db_type
									FROM oracle_status a, db_cfg_oracle b
									WHERE a.server_id = b.id
									  and a.server_id = %s """ %(server_id)
    result=func.mysql_query(sql)
    if result <> 0:
        for line in result:
            server_id=line[0]
            connect=line[1]
            database_role=line[2]
            mrp_status=line[3]
            dg_delay=line[4]
            create_time=line[5]
            host=line[6]
            port=line[7]
            send_mail=line[8]
            send_mail_to_list=line[9]
            send_sms=line[10]
            send_sms_to_list=line[11]
            send_wx=line[12]
            tags=line[13]
            db_type=line[14]
        
            if send_mail_to_list is None or  send_mail_to_list.strip()=='':
                send_mail_to_list = mail_to_list_common
            if send_sms_to_list is None or  send_sms_to_list.strip()=='':
                send_sms_to_list = sms_to_list_common
                
            if connect <> 1:
                send_mail = func.update_send_mail_status(server_id,db_type,'connect',send_mail,send_mail_max_count)
                send_sms = func.update_send_sms_status(server_id,db_type,'connect',send_sms,send_sms_max_count) 
                send_wx  = func.update_send_wx_status(server_id,db_type,'connect',send_wx)
                func.add_alert(server_id,tags,host,port,create_time,db_type,'connect','down','critical','oracle server down',send_mail,send_mail_to_list,send_sms,send_sms_to_list,send_wx)
                func.update_db_status('connect','3',server_id, host, db_type,create_time,'connect','down','critical')
                func.update_db_status('sessions','-1',server_id, host, db_type,'','','','')
                func.update_db_status('actives','-1',server_id, host, db_type,'','','','')
                func.update_db_status('waits','-1',server_id, host, db_type,'','','','')
                func.update_db_status('repl','-1',server_id, host, db_type,'','','','')
                func.update_db_status('repl_delay','-1',server_id, host, db_type,'','','','')
                func.update_db_status('tablespace','-1',server_id, host, db_type,'','','','')
            else:
                func.check_if_ok(server_id,tags,host,port,create_time,db_type,'connect','up','oracle server up',send_mail,send_mail_to_list,send_sms,send_sms_to_list,send_wx)
                func.update_db_status('connect','1',server_id, host, db_type,create_time,'connect','up','ok')
                
                if database_role=="PHYSICAL STANDBY":
                    #print "dg_delay: %s" %(dg_delay)
                    if int(dg_delay) >= 1800:
                        if int(dg_delay) >= 3600*3:
                            send_mail = func.update_send_mail_status(server_id,db_type,'repl_delay',send_mail,send_mail_max_count)
                            send_sms  = func.update_send_sms_status(server_id,db_type,'repl_delay',send_sms,send_sms_max_count)
                            send_wx  = func.update_send_wx_status(server_id,db_type,'repl_delay',send_wx)
                            func.add_alert(server_id,tags,host,port,create_time,db_type,'repl_delay',dg_delay,'critical','replication delay more than 3 hours',send_mail,send_mail_to_list,send_sms,send_sms_to_list,send_wx)
                            func.update_db_status('repl_delay',3,server_id, host, db_type,create_time,'repl_delay',dg_delay,'critical')
                        elif int(dg_delay) >= 1800:
                            send_mail = func.update_send_mail_status(server_id,db_type,'repl_delay',send_mail,send_mail_max_count)
                            send_sms  = func.update_send_sms_status(server_id,db_type,'repl_delay',send_sms,send_sms_max_count)
                            send_wx  = func.update_send_wx_status(server_id,db_type,'repl_delay',send_wx)
                            func.add_alert(server_id,tags,host,port,create_time,db_type,'repl_delay',dg_delay,'warning','replication delay more than 30 minutes',send_mail,send_mail_to_list,send_sms,send_sms_to_list,send_wx)
                            func.update_db_status('repl_delay',3,server_id, host, db_type,create_time,'repl_delay',dg_delay,'warning')
                    else:    
                        func.check_if_ok(server_id,tags,host,port,create_time,db_type,'repl_delay',dg_delay,'replication delay ok',send_mail,send_mail_to_list,send_sms,send_sms_to_list,send_wx)
                        func.update_db_status('repl_delay',1,server_id, host, db_type,create_time,'repl_delay',dg_delay,'ok')
                        	
                        	   
                    if int(mrp_status) < 1:
                        send_mail = func.update_send_mail_status(server_id,db_type,'mrp_status',send_mail,send_mail_max_count)
                        send_sms  = func.update_send_sms_status(server_id,db_type,'mrp_status',send_sms,send_sms_max_count)
                        send_wx  = func.update_send_wx_status(server_id,db_type,'mrp_status',send_wx)
                        func.add_alert(server_id,tags,host,port,create_time,db_type,'mrp_status',mrp_status,'warning','MRP process is down',send_mail,send_mail_to_list,send_sms,send_sms_to_list,send_wx)
                        func.update_db_status('repl',2,server_id, host, db_type,create_time,'repl',mrp_status,'warning')
                    else:
                        func.check_if_ok(server_id,tags,host,port,create_time,db_type,'mrp_status',mrp_status,'MRP process is up',send_mail,send_mail_to_list,send_sms,send_sms_to_list,send_wx)
                        func.update_db_status('repl',1,server_id, host, db_type,create_time,'repl',mrp_status,'ok')
    else:
       pass
예제 #8
0
def gen_alert_os_status(os_ip):
    if g_alert != "1":
        return -1

    sql = """SELECT a.ip,
										a.hostname,
										a.connect,
										a.process,
										a.load_1,
										a.cpu_idle_time,
										a.mem_usage_rate,
										a.create_time,
										b.tags,
										b.alarm_os_process,
										b.alarm_os_load,
										b.alarm_os_cpu,
										b.alarm_os_memory,
										b.threshold_warning_os_process,
										b.threshold_critical_os_process,
										b.threshold_warning_os_load,
										b.threshold_critical_os_load,
										b.threshold_warning_os_cpu,
										b.threshold_critical_os_cpu,
										b.threshold_warning_os_memory,
										b.threshold_critical_os_memory,
										b.send_mail,
										b.send_mail_to_list,
										b.send_sms,
										b.send_sms_to_list
									FROM os_status a, db_cfg_os b
									WHERE a.ip = b.host
									  and a.ip = '%s' """ % (os_ip)
    result = func.mysql_query(sql)
    if result <> 0:
        for line in result:
            host = line[0]
            hostname = line[1]
            connect = line[2]
            process = line[3]
            load_1 = line[4]
            cpu_idle = line[5]
            memory_usage = line[6]
            create_time = line[7]
            tags = line[8]
            alarm_os_process = line[9]
            alarm_os_load = line[10]
            alarm_os_cpu = line[11]
            alarm_os_memory = line[12]
            threshold_warning_os_process = line[13]
            threshold_critical_os_process = line[14]
            threshold_warning_os_load = line[15]
            threshold_critical_os_load = line[16]
            threshold_warning_os_cpu = line[17]
            threshold_critical_os_cpu = line[18]
            threshold_warning_os_memory = line[19]
            threshold_critical_os_memory = line[20]
            send_mail = line[21]
            send_mail_to_list = line[22]
            send_sms = line[23]
            send_sms_to_list = line[24]

            server_id = 0
            tags = tags
            db_type = "os"
            port = ''

            if send_mail_to_list is None or send_mail_to_list.strip() == '':
                send_mail_to_list = mail_to_list_common
            if send_sms_to_list is None or send_sms_to_list.strip() == '':
                send_sms_to_list = sms_to_list_common

            if connect <> 1:
                send_mail = func.update_send_mail_status(
                    host, db_type, 'connect_server', send_mail,
                    send_mail_max_count)
                send_sms = func.update_send_sms_status(host, db_type,
                                                       'connect_server',
                                                       send_sms,
                                                       send_sms_max_count)
                func.add_alert(server_id, tags, host, port, create_time,
                               db_type, 'connect_server', 'down', 'critical',
                               'connect server fail', send_mail,
                               send_mail_to_list, send_sms, send_sms_to_list)
                func.update_db_status('connect', '3', server_id, host, db_type,
                                      create_time, 'connect_server', 'down',
                                      'critical')
                func.update_db_status('process', '-1', server_id, host,
                                      db_type, '', '', '', '')
                func.update_db_status('load_1', '-1', server_id, host, db_type,
                                      '', '', '', '')
                func.update_db_status('cpu', '-1', server_id, host, db_type,
                                      '', '', '', '')
                func.update_db_status('memory', '-1', server_id, host, db_type,
                                      '', '', '', '')
                func.update_db_status('network', '-1', server_id, host,
                                      db_type, '', '', '', '')
                func.update_db_status('disk', '-1', server_id, host, db_type,
                                      '', '', '', '')
            else:
                func.check_if_ok(server_id, tags, host, port, create_time,
                                 db_type, 'connect_server', 'up',
                                 'connect server success', send_mail,
                                 send_mail_to_list, send_sms, send_sms_to_list)
                func.update_db_status('connect', 1, server_id, host, db_type,
                                      create_time, 'connect_server', 'up',
                                      'ok')

                if int(alarm_os_process) == 1:
                    if int(process) >= int(threshold_critical_os_process):
                        #send_mail = func.update_send_mail_status(host,db_type,'process',send_mail,send_mail_max_count)
                        #send_sms = func.update_send_sms_status(host,db_type,'process',send_sms,send_sms_max_count)
                        #func.add_alert(server_id,tags,host,port,create_time,db_type,'process',process,'critical','too more process running',send_mail,send_mail_to_list,send_sms,send_sms_to_list)
                        func.update_db_status('process', 3, server_id, host,
                                              db_type, create_time, 'process',
                                              process, 'critical')
                    elif int(process) >= int(threshold_warning_os_process):
                        #send_mail = func.update_send_mail_status(host,db_type,'process',send_mail,send_mail_max_count)
                        #send_sms = func.update_send_sms_status(host,db_type,'process',send_sms,send_sms_max_count)
                        #func.add_alert(server_id,tags,host,port,create_time,db_type,'process',process,'warning','too more process running',send_mail,send_mail_to_list,send_sms,send_sms_to_list)
                        func.update_db_status('process', 2, server_id, host,
                                              db_type, create_time, 'process',
                                              process, 'warning')
                    else:
                        func.update_db_status('process', 1, server_id, host,
                                              db_type, create_time, 'process',
                                              process, 'ok')
                        func.check_if_ok(server_id, tags, host, port,
                                         create_time, db_type, 'process',
                                         process, 'process running ok',
                                         send_mail, send_mail_to_list,
                                         send_sms, send_sms_to_list)

                if int(alarm_os_load) == 1:
                    if int(load_1) == -1:
                        func.update_db_status('load_1', '-1', server_id, host,
                                              db_type, '', '', '', '')
                    elif int(load_1) >= int(threshold_critical_os_load):
                        #send_mail = func.update_send_mail_status(host,db_type,'load',send_mail,send_mail_max_count)
                        #send_sms = func.update_send_sms_status(host,db_type,'load',send_sms,send_sms_max_count)
                        #func.add_alert(server_id,tags,host,port,create_time,db_type,'load',load_1,'critical','too high load',send_mail,send_mail_to_list,send_sms,send_sms_to_list)
                        func.update_db_status('load_1', 3, server_id, host,
                                              db_type, create_time, 'load',
                                              load_1, 'critical')
                    elif int(load_1) >= int(threshold_warning_os_load):
                        #send_mail = func.update_send_mail_status(server_id,db_type,'load',send_mail,send_mail_max_count)
                        #send_sms = func.update_send_sms_status(host,db_type,'load',send_sms,send_sms_max_count)
                        #func.add_alert(server_id,tags,host,port,create_time,db_type,'load',load_1,'warning','too high load',send_mail,send_mail_to_list,send_sms,send_sms_to_list)
                        func.update_db_status('load_1', 2, server_id, host,
                                              db_type, create_time, 'load',
                                              load_1, 'warning')
                    else:
                        func.check_if_ok(server_id, tags, host, port,
                                         create_time, db_type, 'load', load_1,
                                         'load ok', send_mail,
                                         send_mail_to_list, send_sms,
                                         send_sms_to_list)
                        func.update_db_status('load_1', 1, server_id, host,
                                              db_type, create_time, 'load',
                                              load_1, 'ok')

                if int(alarm_os_cpu) == 1:
                    threshold_critical_os_cpu = int(100 -
                                                    threshold_critical_os_cpu)
                    threshold_warning_os_cpu = int(100 -
                                                   threshold_warning_os_cpu)
                    if int(cpu_idle) <= int(threshold_critical_os_cpu):
                        send_mail = func.update_send_mail_status(
                            host, db_type, 'cpu_idle', send_mail,
                            send_mail_max_count)
                        send_sms = func.update_send_sms_status(
                            host, db_type, 'cpu_idle', send_sms,
                            send_sms_max_count)
                        func.add_alert(server_id, tags, host, port,
                                       create_time, db_type, 'cpu_idle',
                                       str(cpu_idle) + '%', 'critical',
                                       'too little cpu idle', send_mail,
                                       send_mail_to_list, send_sms,
                                       send_sms_to_list)
                        func.update_db_status('cpu', 3, server_id, host,
                                              db_type, create_time, 'cpu_idle',
                                              str(cpu_idle) + '%', 'critical')
                    elif int(cpu_idle) <= int(threshold_warning_os_cpu):
                        send_mail = func.update_send_mail_status(
                            host, db_type, 'cpu_idle', send_mail,
                            send_mail_max_count)
                        send_sms = func.update_send_sms_status(
                            host, db_type, 'cpu_idle', send_sms,
                            send_sms_max_count)
                        func.add_alert(server_id, tags, host, port,
                                       create_time, db_type, 'cpu_idle',
                                       str(cpu_idle) + '%', 'warning',
                                       'too little cpu idle', send_mail,
                                       send_mail_to_list, send_sms,
                                       send_sms_to_list)
                        func.update_db_status('cpu', 2, server_id, host,
                                              db_type, create_time, 'cpu_idle',
                                              str(cpu_idle) + '%', 'warning')
                    else:
                        func.check_if_ok(server_id, tags, host, port,
                                         create_time, db_type, 'cpu_idle',
                                         str(cpu_idle) + '%', 'cpu idle ok',
                                         send_mail, send_mail_to_list,
                                         send_sms, send_sms_to_list)
                        func.update_db_status('cpu', 1, server_id, host,
                                              db_type, create_time, 'cpu_idle',
                                              str(cpu_idle) + '%', 'ok')

                if int(alarm_os_memory) == 1:
                    if memory_usage:
                        memory_usage_int = int(memory_usage.split('%')[0])
                    else:
                        memory_usage_int = 0
                    if int(memory_usage_int) >= int(
                            threshold_critical_os_memory):
                        #send_mail = func.update_send_mail_status(host,db_type,'memory',send_mail,send_mail_max_count)
                        #send_sms = func.update_send_sms_status(host,db_type,'memory',send_sms,send_sms_max_count)
                        #func.add_alert(server_id,tags,host,port,create_time,db_type,'memory',memory_usage,'critical','too more memory usage',send_mail,send_mail_to_list,send_sms,send_sms_to_list)
                        func.update_db_status('memory', 3, server_id, host,
                                              db_type, create_time, 'memory',
                                              memory_usage, 'critical')
                    elif int(memory_usage_int) >= int(
                            threshold_warning_os_memory):
                        #send_mail = func.update_send_mail_status(host,db_type,'memory',send_mail,send_mail_max_count)
                        #send_sms = func.update_send_sms_status(host,db_type,'memory',send_sms,send_sms_max_count)
                        #func.add_alert(server_id,tags,host,port,create_time,db_type,'memory',memory_usage,'warning','too more memory usage',send_mail,send_mail_to_list,send_sms,send_sms_to_list)
                        func.update_db_status('memory', 2, server_id, host,
                                              db_type, create_time, 'memory',
                                              memory_usage, 'warning')
                    else:
                        func.check_if_ok(server_id, tags, host, port,
                                         create_time, db_type, 'memory',
                                         memory_usage, 'memory usage ok',
                                         send_mail, send_mail_to_list,
                                         send_sms, send_sms_to_list)
                        func.update_db_status('memory', 1, server_id, host,
                                              db_type, create_time, 'memory',
                                              memory_usage, 'ok')

    else:
        pass
예제 #9
0
def gen_alert_os_disk(os_ip):
    if g_alert != "1":
        return -1

    sql = """SELECT a.ip,
									a.mounted,
									a.used_rate,
									a.create_time,
									b.tags,
									b.alarm_os_disk,
									b.threshold_warning_os_disk,
									b.threshold_critical_os_disk,
									b.send_mail,
									b.send_mail_to_list,
									b.send_sms,
									b.send_sms_to_list
								FROM os_disk a, db_cfg_os b
								WHERE a.ip = b.host
								 AND a.ip = '%s' """ % (os_ip)
    result = func.mysql_query(sql)
    if result <> 0:
        for line in result:
            host = line[0]
            mounted = line[1]
            used_rate = line[2]
            create_time = line[3]
            tags = line[4]
            alarm_os_disk = line[5]
            threshold_warning_os_disk = line[6]
            threshold_critical_os_disk = line[7]
            send_mail = line[8]
            send_mail_to_list = line[9]
            send_sms = line[10]
            send_sms_to_list = line[11]

            server_id = 0
            tags = tags
            db_type = "os"
            port = ''

            used_rate_arr = used_rate.split("%")
            used_rate_int = int(used_rate_arr[0])

            if send_mail_to_list is None or send_mail_to_list.strip() == '':
                send_mail_to_list = mail_to_list_common
            if send_sms_to_list is None or send_sms_to_list.strip() == '':
                send_sms_to_list = sms_to_list_common

            if int(alarm_os_disk) == 1:
                #logger.info('disk_usage(%s)' %(mounted))
                if int(used_rate_int) >= int(threshold_critical_os_disk):
                    send_mail = func.update_send_mail_status(
                        host, db_type, 'disk_usage(%s)' % (mounted), send_mail,
                        send_mail_max_count)
                    send_sms = func.update_send_sms_status(
                        host, db_type, 'disk_usage(%s)' % (mounted), send_sms,
                        send_sms_max_count)
                    func.add_alert(
                        server_id, tags, host, port, create_time, db_type,
                        'disk_usage(%s)' % (mounted), used_rate, 'critical',
                        'disk %s usage reach %s' % (mounted, used_rate),
                        send_mail, send_mail_to_list, send_sms,
                        send_sms_to_list)
                    func.update_db_status('disk', 3, server_id, host, db_type,
                                          create_time,
                                          'disk_usage(%s)' % (mounted),
                                          used_rate, 'critical')
                elif int(used_rate_int) >= int(threshold_warning_os_disk):
                    send_mail = func.update_send_mail_status(
                        host, db_type, 'disk_usage(%s)' % (mounted), send_mail,
                        send_mail_max_count)
                    send_sms = func.update_send_sms_status(
                        host, db_type, 'disk_usage(%s)' % (mounted), send_sms,
                        send_sms_max_count)
                    func.add_alert(
                        server_id, tags, host, port, create_time, db_type,
                        'disk_usage(%s)' % (mounted), used_rate, 'warning',
                        'disk %s usage reach %s' % (mounted, used_rate),
                        send_mail, send_mail_to_list, send_sms,
                        send_sms_to_list)
                    func.update_db_status('disk', 2, server_id, host, db_type,
                                          create_time,
                                          'disk_usage(%s)' % (mounted),
                                          used_rate, 'warning')
                else:
                    func.check_if_ok(server_id, tags, host, port, create_time,
                                     db_type, 'disk_usage(%s)' % (mounted),
                                     used_rate, 'disk %s usage ok' % (mounted),
                                     send_mail, send_mail_to_list, send_sms,
                                     send_sms_to_list)
                    func.update_db_status('disk', 1, server_id, host, db_type,
                                          create_time, 'disk_usage',
                                          'max(%s:%s)' % (mounted, used_rate),
                                          'ok')
    else:
        pass