{
    "name"  : "是否为网线问题导致供电异常",
    "precondition" : ["name", "type"],
    "problems" : {
        "open" : {
            "desc"      : "【问题】检测到端口${0}上的网线线序C\\D线序为open，网线存在问题",
            "advice"    : "【建议】重新插紧网线或者更换网线"
        }
    }
}

---------------------------code-------------------------------
type = precondition('type')
print 'type!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
print type
if type != 'copper':
    add_reason('非电口类型的端口不需要进行该项诊断')
    return 'skip'
end

intf_name = precondition('name')

cli('configure')

cmd = 'interface ' + intf_name
cli(cmd)
res = cli('line-detect')
if res.search(/Invalid input | Unknown command./i) != -1 :
    res = cli('line-detect')
end
cli('end')

linePairExp = 'C-D'
reg = format("[\\r\\n]+(?:(?:([%s])[ ]+open[ ]+\\d+)|(cable-state:[ ]*open[ ]))", linePairExp)
reg = newRegExp(reg, 'ig')
matchStr = reg.exec(res)
if matchStr != null:
    add_problem('open',[intf_name])
    return 'warn'
end

return 'success'
