예제 #1
0
#coding=utf-8

import sys
import checkDB
import datetime,time
from util import message

phoneNumList = ['18669706675','13041230875', '17090440001', '18611184461', '13120061529', '18610715750', '18500080769', '15645102187', '15645102218', '18646292523', '13051421899', '17090021518', '17090082917']
#role_name = 'checkDB'

if __name__== "__main__":
	while True:
		url = sys.path[0] + '/log/'
		str = url + 'checkDB_' + datetime.datetime.now().strftime('%Y-%m-%d') + '.log'
		resultlist = checkDB.checkDB()
		if len(resultlist) == 0:
			with open(r'%s'%str,'a') as db_log:          
				print >> db_log,('%s 数据库连接ok'%(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')))
			#message.message_send(['%s 数据库连接ok'%(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))],phoneNumList)
			time.sleep(300)
		else:
			message.message_send(resultlist,phoneNumList)
			for rest in resultlist:
				#print '入日志数据'
				with open(r'%s'%str,'a') as db_log:          
					print >> db_log,('%s'%(rest))
			time.sleep(300)
예제 #2
0
def dealBusiness(dbconn, cursor):
    sqlErr = ""
    errdict = {}
    arm_itvs = dealSql.getArmItv(cursor)
    if type(arm_itvs) is str:
        return arm_itvs
    if len(arm_itvs) == 0:
        return ""
    itvdict = {}
    arm_itv_ids = ""  ############################
    for arm_itv in arm_itvs:
        itvdict[arm_itv[0]] = arm_itv[1]
        if len(arm_itv_ids) == 0:
            arm_itv_ids = str(arm_itv[0])
        else:
            arm_itv_ids = arm_itv_ids + "," + str(arm_itv[0])
    confId_rsts = dealSql.getArmConfId(cursor, arm_itv_ids)
    if type(confId_rsts) is str:
        return confId_rsts
    if len(confId_rsts) == 0:
        return ""

    log_ids = ""
    errMsgDict = {}
    # errMsgDict = {arm_type:[[role,msg,log_id]]}
    for confId_rst in confId_rsts:
        # confId_rst = mod_idvalue,mod_type,flag,arm_itv_id

        if str(confId_rst[1]) == "1":
            # 告警模块查询
            arm_msgs = dealSql.getArmMsgByMod(cursor, confId_rst[0], itvdict[confId_rst[3]])
        else:
            arm_msgs = dealSql.getArmMsgByConfId(cursor, confId_rst[0], itvdict[confId_rst[3]])
        # msgs = err_msg,role_name,arm_log_id
        if type(arm_msgs) is str:
            sqlErr = sqlErr + "【" + arm_msgs + "】"
            continue
        if len(arm_msgs) == 0:
            continue
        if str(confId_rst[2]) == "2":
            if len(log_ids) == 0:
                log_ids = str(confId_rst[2])
            else:
                log_ids = log_ids + "," + str(confId_rst[2])
        else:
            for arm_msg in arm_msgs:
                if errMsgDict.has_key(arm_msg[1]):
                    errMsgDict[arm_msg[1]].append([arm_msg[0], arm_msg[2]])
                else:
                    errMsgDict[arm_msg[1]] = [[arm_msg[0], arm_msg[2]]]
    if len(log_ids) == 0:
        pass
    else:
        isErr = dealSql.updateArmLog(cursor, log_ids, "3")
        if type(isErr) is str:
            sqlErr = sqlErr + "【" + isErr + "】"
    # errMsgDict = {role:[[msg,log_id]]}
    for role in errMsgDict.keys():
        phonelist = dealSql.getphoneNumList(cursor, role)
        if type(phonelist) is str:
            sqlErr = sqlErr + "【" + phonelist + "】"
            continue
        if len(phonelist) == 0:
            continue
        log_send_ids = message.message_send(errMsgDict[role], phonelist)
        if len(log_send_ids) == 0:
            sqlErr = sqlErr + "【告警短信发送失败,请查看短信告警日志" + logurl + "】"
            continue
        isErr = dealSql.updateArmLog(cursor, log_send_ids, "2")
        if type(isErr) is str:
            sqlErr = sqlErr + "【" + isErr + "】"
    is_err = connectDb.sqlcommit(dbconn)
    if type(is_err) is str:
        sqlErr = sqlErr + "【更新告警日志状态数据," + is_err + "】"
    return sqlErr