{
    "name"  : "检测多出口环境下NAT映射与路由策略是否匹配",
    "problems" : {
        "error" : {
            "desc"      : "【问题】多出口环境下静态映射后未配置策略路由",
            "advice"    : "【建议】请针对该静态映射的IP配置策略路由"
        }
    }
}

---------------------------code-------------------------------
ipCheck = precondition('ipCheck')

response = cli('show sys-mode')
reg = /WAN:\s([^\r\n]+)/i
result = response.match(reg)
result = result[1]
reg = /([a-zA-Z]+\s[\d\/\.]+)/g
wanArr = result.match(reg)

upWanArr = []
response = cli('show ip in brief')
foreach wan in wanArr :
    reg = format('%s\\s{2,}.+?\\s{2,}.+?\\s{2,}(?:up|UP)',wan)
    result = response.match(reg)
    if result != null :
        upWanArr.push(wan)
    end
end

if upWanArr.length > 1 :
    response = cli('show sys-mode')
    reg = /LAN:\s([^\r\n]+)/i
    result = response.match(reg)
    result = result[1]
    reg = /([a-zA-Z]+\s[\d\/\.]+)/g
    lanArr = result.match(reg)
    upLanArr = []
    response = cli('show ip in brief')
    foreach lan in lanArr :
        reg = format('%s\\s{2,}([\\d\\.]+)\\/([\\d]+)\\s{2,}.+?\\s{2,}(?:up|UP)',lan)
        result = response.match(reg)
        if result != null :
            ip = result[1]
            mask = result[2]
            if isSameIpseg(ip, ipCheck, mask) == true :
                upLanArr.push(lan)
            end
        end
    end
    
    response = cli('show ru | in ip nat')
    reg = format('%s',ipCheck)
    reg = newRegExp(reg)
    if reg.test(response) == true && upLanArr.length > 0:
        cmd = 'show run int ' + upLanArr[0]
        response = cli(cmd)
        reg = /route\-map/i
        if reg.test(response) == false :
            add_problem('error')
            return 'warn'
        end
    end
end

return 'success'


