{
    "name"  : "安全隧道未启动/启动失败",
    "problems" : {
        "dnsDelegate1" : {
            "desc"      : "【问题】红色预警：SSLVPN服务未开启或开启失败",
            "advice"    : "【建议】请开启SSLVPN服务或参照SSLVPN服务无法启动。"
        },
		"dnsDelegate2" : {
            "desc"      : "【问题】请先登录SSLVPN",
            "advice"    : "【建议】无"
        },
		"dnsDelegate3" : {
            "desc"      : "【问题】无",
            "advice"    : "【建议】为用户分配安全隧道资源"
        },
		"dnsDelegate4" : {
            "desc"      : "【问题】无",
            "advice"    : "【建议】如果登录终端是webclient，提示请使用IE登录或桌面客户端登录，收集客户端日志文件确认是否完成安装，确认流表前业务是限制建流，与运营商确认是否UDP流量限制了。"
        },
		"dnsDelegate5" : {
            "desc"      : "【问题】无",
            "advice"    : "【建议】show efmp counter关注丢包情况。"
        },
		"dnsDelegate6" : {
            "desc"      : "【问题】发生过4xx返回页面",
            "advice"    : "【建议】请尝试重新安装SSLVPN客户端。"
        },
		"dnsDelegate7" : {
            "desc"      : "【问题】用户未尝试获取程序启动参数。",
            "advice"    : "【建议】建议使用IE类浏览器或桌面客户端登录。"
        },
		"dnsDelegate8" : {
            "desc"      : "【问题】用户未尝试获取安全隧道启动参数。",
            "advice"    : "【建议】收集客户端日志文件确认是否完成安装；确认流表前业务是限制建流；与运营商确认是否UDP流量限制了"
        },
		"dnsDelegate9" : {
            "desc"      : "【问题】存在用户无安全隧道接入权限",
            "advice"    : "【建议】排查用户的SSLVPN资源授权配置是否有问题"
        },
		"dnsDelegateA" : {
            "desc"      : "【问题】未收到安全隧道连接请求；",
            "advice"    : "【建议】收集客户端日志文件确认是否完成安装；确认流表前业务是限制建流；与运营商确认是否UDP流量限制了或桌面客户端登录，收集客户端日志文件确认是否完成安装，确认流表前业务是限制建流，与运营商确认是否UDP流量限制了。"
        },
		"dnsDelegateC" : {
            "desc"      : "【问题】存在用户因服务器配置出错导致安全隧道失败",
            "advice"    : "【建议】添加新的客户端网段或检测地址池绑定策略。"
        },
		"dnsDelegateD" : {
            "desc"      : "【问题】存在用户因服务器发生内部错误导致安全隧道失败",
            "advice"    : "【建议】show sslvpn log收集服务器日志；如果不断累加则需要重启SSLVPN服务。"
        },
		"dnsDelegateE" : {
            "desc"      : "【问题】存在用户因客户程序异常导致安全隧道失败",
            "advice"    : "【建议】收集客户端日志了解真正的致命原因，重新登录或卸载重装可能可以解决问题。"
        },
		"dnsDelegateF" : {
            "desc"      : "【问题】存在用户因网络丢包导致安全隧道失败",
            "advice"    : "【建议】收集客户端日志了解真正的致命原因；用户重新登录或切换网络重新登录；如果仍然不行则需要抓包分析。"
		},
		"dnsDelegateG" : {
            "desc"      : "【问题】无",
            "advice"    : "【建议】联系锐捷支持，并提供show sslvpn log type user level warning可以进一步区分是握手超时还是握手失败。debug sslvpn iptun-usr error可得到具体的出错位置。"
        }
    }
}
---------------------------code-------------------------------
Result = "success"
def judgeLevelResult(res, cmd, problem, error) :
	reg = cmd + "\\W+\\d+"
	reg1 = newRegExp(reg, "ig")
    resTmp = res.match(reg1)
	print resTmp
	resTmp1 = resTmp[0]
	print resTmp1
	result = resTmp1.match(/\d+/)
	result = result[0]
	if error == "is0" :
		if result == 0:
			add_problem(problem)
			Result = "warn"
		end
	else:
		if result != 0:
			add_problem(problem)
			Result = "warn"
		end
	end
end

userName = precondition('userName')
publicIp = precondition('publicIp')
print userName
print publicIp
res = cli("show sslvpn gateway")
print res
if res.match("Web access service: on") == null || res.match("Secure app service: on") == null || res.match("IP tunnel service: on") == null:
	add_problem("dnsDelegate1")
    return "warn"
end

cmd = "show sslvpn resource-group by-name " + userName
res = cli(cmd)
print res
if res.indexOf("Session status: running-syned") != -1:
    return "success"
end

cmd = "show sslvpn resource-group by-user-name" + userName
res = cli(cmd)
print res
resTmp = res.split(/\r\n?/)
if resTmp.length < 2:
	add_problem("dnsDelegate2")
    return "warn"
end

res = cli("show sslvpn resource-group by-name")
print res
if res.indexOf("Iptunnel Enable: TRUE") == -1:
	add_problem("dnsDelegate3")
    return "warn"
end

cmd = "show ip fpm flows filter 17 " + publicIp + " 32 0.0.0.0 32"
res = cli(cmd)
resTmp = res.split(/\r\n?/)
print res
if resTmp.length < 2:
	add_problem("dnsDelegate4")
    return "warn"
end

cmd = "show sslvpn iptunnel session summary | include " + publicIp
res1 = cli(cmd)
print res1
res1Tmp = res1.split(/\r\n/)
if res1Tmp.length < 2:
	add_problem("dnsDelegate5")
    return "warn"
end

res = cli("show sslvpn statistics all detail")
print res

judgeLevelResult(res, "SSLVPN 4XX page", "dnsDelegate6", "")
judgeLevelResult(res, "SSLVPN Get GUI action", "dnsDelegate7", "is0")
judgeLevelResult(res, "SSLVPN Get IPTunnel action", "dnsDelegate8", "is0")
judgeLevelResult(res, "User Login without iptunnel", "dnsDelegate9", "")
judgeLevelResult(res, "IPTunnel Request", "dnsDelegateA", "is")
judgeLevelResult(res, "IPTunnel Connect ok", "dnsDelegateA", "is0")
judgeLevelResult(res, "IPTunnel Config error", "dnsDelegateC", "")
judgeLevelResult(res, "IPTunnel Server error", "dnsDelegateD", "")
judgeLevelResult(res, "IPTunnel Client error", "dnsDelegateE", "")
judgeLevelResult(res, "IPTunnel Client Ctrl error", "dnsDelegateF", "")
judgeLevelResult(res, "IPTunnel DTLS failed", "dnsDelegateG", "is0")

return Result
