{
    "name"  : "检测运营商线路是否正常",
    "problems" : {
        "nextHopError" : {
            "desc"      : "【问题】下一跳地址不一致",
            "advice"    : "【建议】请检查设备端下一跳地址是否配置正确"
        },
        "noMac" : {
            "desc"      : "【问题】设备无法学习到下一跳MAC地址",
            "advice"    : "【建议】请检查线路是否接错或运营商线路是否已开通"
        },
        "pingError" : {
            "desc"      : "【问题】设备无法ping通下一跳或公网",
            "advice"    : "【建议】请尝试电脑或其他设备出口直连运营商线路是否能正常上网，若无法上网请联系运营商检测线路是否有策略限制，例如会话数限制，绑定MAC，禁ping等；若可以正常上网，请确认PC端学习的下一跳mac与设备端学习的mac是否一致、尝试修订设备外网接口mac地址与可以上网的mac一致测试是否可以上网、尝试修订设备外网接口mtu值测试是否能够正常上网"
        }
    }
}

---------------------------code-------------------------------
wanIntf = precondition('wanIntf')
nextHop = precondition('nextHop')
#wanIntf = 'GigabitEthernet 0/4'
#nextHop = '192.168.25.1'

if wanIntf == '' || nextHop == '' :
    add_reason('需要配置外网接口、下一跳地址才能进行检测')
    return 'skip'
end

cmd = 'show run int ' + wanIntf
reg = /[\r\n]+\s*nexthop\s+([\d\.]+)/
response = cli(cmd)
result = response.match(reg)
if !result :
    add_problem('nextHopError')
    return 'warn'
else :
    nextHopConf = result[1]
    if nextHop != nextHopConf :
        add_problem('nextHopError')
        return 'warn'
    end
end

cmd = 'show arp | in ' + nextHop
response = cli(cmd)
reg = response.match(/Internet/ig)
if reg == null:
    add_problem('noMac')
    return 'warn'
end

cmd = 'ping ' + nextHop
responseNextHop = cli(cmd)
dataNextHop = formatPing(responseNextHop)
if dataNextHop.successRate == 0 :
    responseAny = cli('ping 114.114.114.114')
    dataAny = formatPing(responseAny)
    if dataAny.successRate == 0 :
        add_problem('pingError')
        return 'warn'
    end
end

return 'success'
