Example #1
0
def email_alarm_title(otype, name, ip, server, Reason, status, lasterr,
                      error_start_time, oid):
    '''
    @ 格式化报警主题,内容
    '''
    monitorTime = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())

    content = "告警类型: " + str(status) + " \n\n"
    content1 = "告警名称: " + str(name) + " \n"
    content2 = "告警IP: " + str(ip) + " \n"
    content3 = "告警服务: " + str(server) + " \n"
    content4 = "检查时间:" + str(monitorTime) + " \n\n"
    content5 = "故障信息: \n " + str(Reason) + " \n"
    content6 = "上次故障信息: \n " + str(lasterr) + " \n"
    content7 = ""

    #清除故障首次发生时间
    if status == 'RECOVERY':
        error_time = Caltime(error_start_time, monitorTime)
        sql = 'update uxin_alarm set error_start_time="" where id=%s' % (oid)
        content7 = "故障持续时间: " + str(error_time) + " "
        cmdtosql.update(sql)

    if otype == 'progress':
        topTemp = "OMS监控:" + str(name) + "  IP:" + str(ip) + " 服务:" + str(
            Reason) + " 状态:" + str(status) + ""
    else:
        topTemp = "OMS监控:" + str(name) + "  IP:" + str(ip) + " 服务:" + str(
            server) + " 状态:" + str(status) + ""

    if status == 'PROBLEM':
        if otype == 'progress':
            topTemp = "OMS监控:" + str(name) + "  IP:" + str(ip) + " 服务:" + str(
                Reason) + " 状态:" + str(status) + ""
        else:
            topTemp = "OMS监控:" + str(name) + "  IP:" + str(ip) + " 服务:" + str(
                server) + " 状态:" + str(status) + ""
        subject = "【故障】" + "【监控源" + str(
            config.monitor_point) + "】" + str(topTemp) + " " + monitorTime
        template = content + content1 + content2 + content3 + content4 + content5
    elif status == 'DOWN':
        subject = "【宕机】" + "【监控源" + str(
            config.monitor_point) + "】" + str(topTemp) + " " + monitorTime
        template = content + content1 + content2 + content3 + content4 + content5
    elif status == 'RECOVERY':
        if otype == 'progress':
            topTemp = "OMS监控:" + str(name) + "  IP:" + str(ip) + " 服务:" + str(
                lasterr) + " 状态:" + str(status) + ""
        else:
            topTemp = "OMS监控:" + str(name) + "  IP:" + str(ip) + " 服务:" + str(
                server) + " 状态:" + str(status) + ""
        subject = "【恢复】" + "【监控源" + str(config.monitor_point) + "】" + str(
            topTemp) + " " + monitorTime + " " + content7
        template = content + content1 + content2 + content3 + content4 + content6 + content7

    log_info(str(subject + template))

    return subject, template
Example #2
0
def update_fail_count(item,fail_count):

    id=item[0]
    host=item[2]
    check_type=item[1]
    port=item[4]
    check_name=item[3]

    if fail_count != '0':
        #fail_count 清零
        sql='update uxin_alarm set fail_count="0" where id=%s' %(id)
        cmdtosql.update(sql)

        log_info("IP地址: " + str(host) + " 类型:" + str(check_type) + "  报警名:" + str(check_name) + "  检测对象:" + str(port) + " 恢复")
Example #3
0
def update_table(item,reason):

	id=item[0]
	host=item[2]
	check_type=item[1]
	port=item[4]
	check_name=item[3]

	#更新fail_count字段+1
	sql='update uxin_alarm set fail_count=fail_count + 1 where id="%s"' %(id)
	cmdtosql.update(sql)

	#更新上次失败原因
	sql='update uxin_alarm set last_result="%s" where id=%s' %(reason,id)
	cmdtosql.update(sql)

        #更新首次失败的时间
	monitorTime = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
	if item[21] == 'NULL' or item[21] == ''  or item[21] is None:
	    sql1='update uxin_alarm set error_start_time="%s" where id=%s' %(item[11],item[0])
	    cmdtosql.update(sql1)

	#更新日志

	log_info("IP地址: " + str(host) + " 类型:" + str(check_type) + "  报警名:" + str(check_name) + "  检测对象:" + str(port) + " 失败内容:" +str(reason))
Example #4
0
def monitor_item_updateTime(itemlist):
    '''
    @Monitor 更新项目上次下次监控时间
    '''
    itemlist = list(itemlist)
    lastTime = monitor_item_lastTime()
    nextTime = monitor_item_nextTime(itemlist)
    
    sql = "update uxin_alarm set next_time='"+nextTime+"',last_time='"+lastTime+"',lock_status='' where id="+str(itemlist[0])


#        sql1 = "update uxin_alarm set last_time='"+lastTime+"' where id="+str(itemlist[0])
#        sql_lock = "update uxin_alarm set lock_status='' where id="+str(itemlist[0])
#   log_debug("更新上次:"+str(sql))
    try:
        time.sleep(1)
        log_debug("monitor_item_update_lastTime()执行sql语句:"+str(sql))
#                cmdtosql.update(sql1)
        cmdtosql.update(sql)
#                cmdtosql.update(sql_lock)
    except Exception as e:
        log_error("monitor_item_update_lastTime():"+str(e))