{
    "name"  : "dns代理静态路由",
    "precondition" : [],
    "problems" : {
        "dns" : {
            "desc"      : "【问题】当前dns代理的域名服务器需要配置静态路由",
            "advice"    : [
                "【建议】请配置ip route name_server1 255.255.255.255 nexthop"           
            ]
        }
    }
}

---------------------------code-------------------------------


isProblemFound = false

dnsProxyConfig = get_share_value('dnsProxyConfig')

# 通过这个得出Version为11.x 且发布日期小于2015年12月
isVer = false
res_ver = cli("show version detail")
res_time = res_ver
ver = res_ver.match(/System software version : EG_RGOS 11./img)
if ver != null:
    reg = /System software number  : (\S+)/im
    time = reg.exec(res_time)
    if time != null:
        time = time[1]
        # 小于2015年12月  12122015  
        if compareTime(time,'12002015') :
            isVer = true
        end
    end
end

wansDetail = get_share_value('wansDetail')

route_info = cli("show run | include ip route")

is_route_cfg_err = false
foreach wan in wansDetail:
    dns = wan.dns
    if wan.isUP && wan.ip && !wan.isDi && dns.length && wan.nexthop:
        wanIngf = wan.intf
        dns = wan.dns
        foreach data in dns:
            dnsIp = data.dnsIp
            str = "ip route " + dnsIp + "255.255.255.255 " + wan.nexthop
            is_match = route_info.match(str)
            if is_match == null:
                is_route_cfg_err = true
            end
        end
    end
end


if dnsProxyConfig.stateEnable && isVer && is_route_cfg_err:
    isProblemFound = true
    add_problem("dns")
end


if isProblemFound == true :
    return 'warn'
else:
    return 'success'
end
