{
    "name"  : "检测流控策略是否配置正常",
    "problems" : {
        "error" : {
            "desc"      : "【问题】流控限速通道承诺带宽太小",
            "advice"    : "【建议】请适当调整通道带宽大小"
        }
    }
}

---------------------------code-------------------------------
wanIntf = precondition('wanIntf')

if wanIntf == '' :
    add_reason('需要配置外网接口才能进行检测')
    return 'skip'
end

reg = /flow\-policy\s(.+)/i
cmd = 'show run int ' + wanIntf
response = cli(cmd)
result = response.match(reg)
if !result :
    add_reason('端口未配置流控策略')
    return 'skip'
else :
    flow_policy = result[1]
    cmd = 'show flow-control ' + flow_policy + ' auto-pir'
    response = cli(cmd)
    response = response.split(/Outbound/)
    foreach item in response :
        reg = /root\s{2,}.+?\s{2,}[\d]+\s{2,}[\d]+\s{2,}([\d]+)/i
        result = item.match(reg)
        if !result :
            return 'skip'
        else :
            root = result[1]
            halfRoot = root / 2
        end

        reg = /key\s{2,}.+?\s{2,}[\d]+\s{2,}[\d]+\s{2,}([\d]+)/i
        result = item.match(reg)
        if !result :
            return 'skip'
        else :
            key = result[1]
            if key < 500 || key < halfRoot :
                add_problem('error')
                return 'warn'
            end
        end
        
        reg = /normal\s{2,}.+?\s{2,}[\d]+\s{2,}[\d]+\s{2,}([\d]+)/i
        result = item.match(reg)
        if !result :
            return 'skip'
        else :
            normal = result[1]
            if normal < 500 || normal < halfRoot :
                add_problem('error')
                return 'warn'
            end
        end

        reg = /unkey\s{2,}.+?\s{2,}[\d]+\s{2,}[\d]+\s{2,}([\d]+)/i
        result = item.match(reg)
        if !result :
            return 'skip'
        else :
            unkey = result[1]
            if unkey < 500 || unkey < halfRoot :
                add_problem('error')
                return 'warn'
            end
        end
    end
end

return 'success'