{
    "name"  : "光口告警检测",
    "problems" : {
        "fiber_check" : {
            "desc"      : "【问题】检测到端口${0}存在告警，可能温度、电压、电流、光强度存在问题。",
            "advice"    : "【建议】建议更换告警光模块，否则会造成该端口状态异常或转发丢包。通过命令show interface 【问题端口】 transceiver alarm查看具体原因"
        }
    }
}
---------------------------code-------------------------------
intf_config = cli('show interfaces transceiver diagnosis')
intf_configList = intf_config.split("\r\n")
reg1 = /warning/
reg2 = /alarm/

strpResult="PASS"
intf_sta = cli('show interfaces status')
intf_staList = intf_sta.split("\r\n")
foreach data in intf_staList:
    if data.search("fiber")>=0:
        stepResult = "FAIL"
    end
end

if stepResult == "PASS":
    return 'skip'
end

result = "PASS"
port = ""
i = 0
foreach data in intf_configList:
    r1 = data.search(reg1)
    r2 = data.search(reg2)
    if r1 >= 0 || r2 >= 0:
        intf = get_intf(i,intf_configList)
        result = "FAIL"
		if port == '':
			port = intf
		else :
			port = port + "、" + intf
		end
    end
    i = i + 1
end


#0~========Interface GigabitEthernet 1/2/15========
#1~Interface GigabitEthernet 1/2/15 : the transceiver is absent!
#2~
#3~========Interface GigabitEthernet 1/2/16========
#4~Current diagnostic parameters[AP:Average Power]:
#5~Temp(Celsius)   Voltage(V)      Bias(mA)            RX power(dBm)       TX power(dBm)
#6~33(OK)          3.31(OK)        7.92(OK)            -40.00(alarm)[AP]   -2.42(OK)
#7~
#8~========Interface GigabitEthernet 1/2/17========
#9~Interface GigabitEthernet 1/2/17 : the transceiver is absent!




if result == "FAIL":
    change_title('检测光口是否存在告警')
    add_problem('fiber_check',[port])
    return 'warn'
end

change_title('检测光口未有告警')
return 'success'

def get_intf(line_num,strList):
    intf = ""
    reg_intf = /========Interface\s+(\w+Ethernet\s+[^ ]+)========/
    while line_num > 0:
        str_line = strList[line_num]
        r = str_line.match(reg_intf)
        if r != null:
            intf = r[1]
            return intf
			break
        end
        line_num = line_num - 1
    end
    return intf
end
