{
    "name"  : "检测端口错帧",
    "problems" : {
        "frame_check" : {
            "desc"      : "【问题】端口${0}存在大量错包且数值在增加，该问题会导致接入业务大量丢包等。",
            "advice"    : "【建议】检测端口物理链路质量，重新拔插或更换，更换完毕后通过show interface counters errors检测仍有错误报文。"
        }
    }
}
---------------------------code-------------------------------
intf_countErr = cli('show interfaces counters errors')
intf_countErrList = intf_countErr.split("\r\n")
reg = /([^ ]+)\s+\d+\s+(\d+)\s+(\d+)\s+(\d+)/
result = "pass"
port = ""
tag = 0
stepResult = 'PASS'
foreach data in intf_countErrList:
    if data.match(/CRC-Align-Err\s+Align-Err\s+FCS-Err/):
        tag = 1
    end
    if tag == 1:
        r = data.match(reg)
        if r != null:
            intf = r[1]
            crcErr = r[2]
            aliErr = r[3]
            fcsErr = r[4]
            if crcErr >= 1000 || aliErr >= 1000 || fcsErr >= 1000:
                stepResult='FAIL'
                sleep(5000)
                if errAdd(intf,crcErr,aliErr,fcsErr):
                    result = "fail"
                    port = port + intf + "、"
                end
            end
        end
    end
end

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

if result == "fail":
    change_title('检测端口存在错帧并持续增加')
    add_problem('frame_check',[port])
    return 'warn'
end

if result == 'pass' :
    return 'skip'

return 'success'

def errAdd(intf,crcErr,aliErr,fcsErr):
    cmd = format('show interface %s counters errors',intf)
    intf_countErr_new = cli(cmd)
    r1 = intf_countErr_new.match(reg)
    if r1 != null:
        if r1[2] > crcErr || r1[3] > aliErr || r1[4] > fcsErr:
            return 1
        end
    end
    return 0
end