def sansw_judge(total_RT, total_DB, sansw_IP, sansw_Alias):
    strTimeNow = s.time_now_to_show()
    if (total_DB != None) and (total_RT != None):
        intErrorIncrease = total_RT - total_DB
        intWarninglevel = s.is_Warning(intErrorIncrease, tuplThresholdTotal)
        if intWarninglevel:
            msg = warning_message_sansw(intWarninglevel)
            db.insert_warning(strTimeNow, sansw_IP, 'switch', intWarninglevel,
                              msg, 0)
            se.send_warnmail(
                [[strTimeNow, sansw_IP, sansw_Alias, intWarninglevel, msg]])
def sansw_rt_info_to_show():
    """
    @note: SANSW要展示的即时内容(status)
    """
    switch_total = sw.get_info_for_DB()[1]
    lst_sansw_to_show = []
    if switch_total:
        for sansw_alias in switch_total.keys():
            ip = switch_total[sansw_alias]["IP"]
            PE_sum = switch_total[sansw_alias]["PE_Sum"]
            if PE_sum == None:
                PE_sum = []
            PE_total = switch_total[sansw_alias]["PE_Total"]
            warning_level = s.is_Warning(PE_total, tuplThresholdTotal)
            PE_sum.insert(0, ip)
            PE_sum.append(PE_total)
            PE_sum.insert(0, sansw_alias)
            PE_sum.append(warning_level)
            lst_sansw_to_show.append(PE_sum)
        return lst_sansw_to_show
def sansw_info_to_show():
    """
    @note: 获取数据库SANSW要展示的内容(时间,status)
    """
    lst_switch = db.switch_last_info()
    lst_sansw_to_show = []
    if lst_switch:
        strTime = lst_switch.time.strftime('%Y-%m-%d %H:%M:%S')
        switch_total = lst_switch.sum_total
        for sansw_alias in switch_total.keys():
            ip = switch_total[sansw_alias]["IP"]
            PE_sum = switch_total[sansw_alias]["PE_Sum"]
            if PE_sum == None:
                PE_sum = ['--', '--', '--', '--', '--']
            PE_total = switch_total[sansw_alias]["PE_Total"]
            if PE_total == None:
                PE_total = '--'
            warning_level = s.is_Warning(PE_total, tuplThresholdTotal)
            PE_sum.insert(0, ip)
            PE_sum.append(PE_total)
            PE_sum.insert(0, sansw_alias)
            PE_sum.append(warning_level)
            lst_sansw_to_show.append(PE_sum)
        return strTime, lst_sansw_to_show
Exemple #4
0
 def sum_total_and_warning(self):
     lstSumTotal = list(self.sum_and_total())
     intTotal = lstSumTotal[1]
     intWarningLevel = s.is_Warning(intTotal, tuplThresholdTotal)
     lstSumTotalWarning = lstSumTotal.append(intWarningLevel)
     return lstSumTotalWarning
def test_is_Warning():
    assert sun.is_Warning(500, 200) == True
    assert sun.is_Warning(500, 2000) == None
    assert sun.is_Warning(100, [200, 2000]) == 0
    assert sun.is_Warning(600, [200, 2000]) == 1
    assert sun.is_Warning(3000, [200, 2000]) == 2