{
    "name"  : "WEB认证相关配置是否正确",
    "precondition" : ["gateway_ip"],
    "problems" : {
        "no_redirect" : {
            "desc"      : "【问题】未配置重定向地址",
            "advice"    : [
                "【建议】配置重定向地址",
                "配置示例： ",
                "Ruijie#config",
                "Ruijie(config)#http redirect 重定向地址",
                "Ruijie(config)#end",
                "Ruijie#write"
            ]
        },
        "no_homepage" : {
            "desc"      : "【问题】未配置认证页面",
            "advice"    : [
                "【建议】配置认证页面",
                "配置示例：",
                "Ruijie#config",
                "Ruijie(config)#http redirect homepage 重定向主页",
                "Ruijie(config)#end",
                "Ruijie#write"
            ]
        },
        "no_arp" : {
            "desc"      : "【问题】未配置网关ARP直通",
            "advice"    : [
                "【建议】重新插紧网线或者更换网线",
                "配置示例：",
                "Ruijie#config",
                "Ruijie(config)#http redirect direct-site IP地址 arp(IP地址为网关地址)",
                "Ruijie(config)#end",
                "Ruijie#write"
            ]
        },
        "link_exp" : {
            "desc"      : "【问题】设备与认证服务器之间链路问题",
            "advice"    : "【建议】排查设备与认证服务器直连的链路问题或者确认认证服务器无异常" 
        }
    }
}

---------------------------code-------------------------------
res = cli('show http redirect')

isProblemFound = false

#server ip是否为0.0.0.0
ipAdr = res.match(/server:\s*(.*)$/im)
if ipAdr != null:
    ipAdr = ipAdr[1]
    if ipAdr == '0.0.0.0' :
        isProblemFound = true
        add_problem("no_redirect")
    end
end

#是否有设置homepage
if res.match(/homepage:\s*\n/i) != null :
    isProblemFound = true
    add_problem("no_homepage")
end

if isProblemFound == true:
    return 'warn'
end

#是否有arp
gatewayIp = precondition('gateway_ip')
if gatewayIp != null && gatewayIp != '':
    cmd = 'show run | include http redirect direct-site ' + gatewayIp
    res = cli(cmd)
    if res.search(/arp/) == -1 :
        isProblemFound = true
        add_problem("no_arp")
    end
end

#server ip 是否ping得通
if ipAdr != null :
    cmd = 'ping ' + ipAdr
    res = cli(cmd)
    if res.search('!') == -1 :
        isProblemFound = true
        add_problem("link_exp")
    end
end


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


