{
    "name"  : "用户登录失败",
    "problems" : {
        "problems1" : {
            "desc"      : "【问题】红色预警：SSLVPN服务未开启或开启失败",
            "advice"    : "【建议】请开启SSLVPN服务或参照SSLVPN服务无法启动收集数据。"
        },
		 "problems2" : {
            "advice"    : "【建议】使用正确地址尝试再登录。"
        },
		 "problems3" : {
            "advice"    : "【建议】服务使用的证书可能不合法，请更换数字证书或重新生成数字证书."
        },
		"error" : {
			"desc"  	: "【问题】发生内部服务错误",
            "advice"    : "【建议】建议尝试重启SSLVPN服务或联系锐捷支持"
        },
		"tryerror" : {
			"desc"  	: "【问题】用户输入的地址可能有误或用户网络不可达",
            "advice"    : "【建议】建议检查输入地址是否正确、网络是否可达、确认是否设置了代理"
        },
		"Connect" : {
			"desc"  	: "【问题】用户输入的地址可能有误或用户网络不可达",
            "advice"    : "【建议】建议检查输入地址是否正确、网络是否可达、确认是否设置了代理"
        },
		"TLS_Failed" : {
			"desc"  	: "【问题】存在TLS握手失败",
            "advice"    : "【建议】建议检查浏览器的SSL设置"
        },
		"HTTP_request" : {
			"desc"  	: "【问题】用户输入的地址可能有误或用户网络不可达",
            "advice"    : "【建议】建议检查输入地址是否正确、网络是否可达、确认是否设置了代理"
        },
		"SSL_connect" : {
			"desc"  	: "【问题】存在因连单用户并发最大连接数受限导致握手失败",
            "advice"    : "【建议】建议关闭或调大单用户并发最大连接数"
        },
		"Server_error" : {
			"desc"  	: "【问题】发生内部服务错误",
            "advice"    : "【建议】建议尝试重启SSLVPN服务或联系锐捷支持"
        },
		"4xx_5xx" : {
			"desc"  	: "【问题】存在4xx与5xx返回页面"
        },
		"Login_request" : {
			"desc"  	: "【问题】用户输入的地址可能有误或用户网络不可达",
			"advice"    : "【建议】建议检查输入地址是否正确、网络是否可达、确认是否设置了代理"
        },
		"blacklist" : {
			"desc"  	: "【问题】存在因证书不合法导致的登录失败",
			"advice"    : "【建议】查看用户相关的日志确认原因；为用户重新重新生成证书或使用账号尝试登录"
        },
		"Account_Login" : {
			"desc"  	: "【问题】存在因禁止账号登录导致的登录失败",
			"advice"    : "【建议】查看用户相关的日志确认原因；允许账号登录"
        },
		"Cert_Login" : {
			"desc"  	: "【问题】存在因禁止文件数字证书登录导致的登录失败",
			"advice"    : "【建议】查看用户相关的日志确认原因；让用户使用账号尝试登录"
        },
		"USBKey_Login" : {
			"desc"  	: "【问题】存在因禁止USBKey登录导致的登录失败",
			"advice"    : "【建议】查看用户相关的日志确认原因；让用户使用账号尝试登录"
        },
		"License limit" : {
			"desc"  	: "【问题】存在并发授权数限制导致的登录失败",
			"advice"    : "【建议】查看用户相关的日志确认原因；申请并导入SSLVPN并发授权文件"
        },
		"Time_limit" : {
			"desc"  	: "【问题】存在因登录时间限制导致的登录失败",
			"advice"    : "【建议】查看用户相关的日志确认原因；调整登录IP策略"
        },
		"IP_limit" : {
			"desc"  	: "【问题】存在因登录时间限制导致的登录失败",
			"advice"    : "【建议】查看用户相关的日志确认原因；调整登录IP策略"
        },
		"IP_Locked" : {
			"desc"  	: "【问题】存在因登录IP被锁定导致的登录失败",
			"advice"    : "【建议】查看用户相关的日志确认原因；将被锁定的IP地址清除"
        },
		"Name_Locked" : {
			"desc"  	: "【问题】存在因用户名被锁定导致的登录失败",
			"advice"    : "【建议】查看用户相关的日志确认原因；将被锁定的用户名清除"
        },
		"AUTH" : {
			"desc"  	: "【问题】存在因认证错误导致的登录失败",
			"advice"    : "【建议】查看用户相关的日志确认原因"
        },
		"aaa_failed" : {
			"desc"  	: "【问题】存在因认证服务器繁忙导致的登录失败",
			"advice"    : "【建议】查看用户相关的日志确认原因；如果大量用户登录失败建议重启设备."
        },
		"request " : {
			"desc"  	: "【问题】存在因认证组件出错导致的登录失败",
			"advice"    : "【建议】查看用户相关的日志确认原因；如果大量用户登录失败建议重启设备"
        },
		"Timeout" : {
			"desc"  	: "【问题】存在因认证服务器连接超时导致的登录失败",
			"advice"    : "【建议】查看用户相关的日志确认原因；检查与认证服务器之间的网络情况."
        },
		"Unkown " : {
			"desc"  	: "【问题】存在因用户名被锁定导致的登录失败",
			"advice"    : "【建议】查看用户相关的日志确认原因；将被锁定的用户名清除"
        },
		"step7 " : {
			"advice"    : "【建议】未收到用户登录请求，可能是未配置端口映射、用户地址输错、用户PC开了代理、用户的上网线路被运营商抑制"
        }
    }
}
---------------------------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
ip_Addr = []
showHttp = []
showHttps = []
res = cli("show sslvpn gateway")
if res.match("Web access service: on") == null || res.match("Secure app service: on") == null || res.match("IP tunnel service: on") == null:
	add_problem("problems1")
    return "warn"
end
print res
reg = /Port:\s\d+/i
Port = res.match(reg)
Port = Port[0]
ipPort = Port.match(/[0-9]+/)
print ipPort
if res.match("Http port") != null:
	reg = /Http port:\s\d+/i
	Port = res.match(reg)
	Port = Port[0]
	Http_port = Port.match(/[0-9]+/)
 else:
	Http_port = ""
end
print Http_port

res = cli("show sys-mode")
resTmp = res.split(/\r\n?/)
print resTmp
i = 0
while i < resTmp.length:
	tmp = resTmp[i]
	if tmp.match("WAN:") != null:
		resTmp = tmp.split(/\W\s+/)
		break
	end
	i = i + 1
end
print resTmp

j = 1
while j < (resTmp.length - 1):
	tmp = resTmp[j]
	print tmp
	cmd = "show int " + tmp
	res = cli(cmd)
	num = res.match(/\d+\.\d+\.\d+\.\d+/g)
	print num
	if num != null:
		ip_Addr = ip_Addr.concat(num)
	end
	j = j + 1
end
print ip_Addr

if Port == 433:
	m = 0
	while m < ip_Addr.length:
		https = "https://" + ip_Addr[m]
		showHttps.push(https)
		m = m + 1
	end
else:
	m = 0
	while m < ip_Addr.length:
		https = "https://" + ip_Addr[m] + ":" + Port
		showHttps.push(https)
		m = m + 1
	end
end

if Http_port == 80 || Http_port == "":
	n = 0
	while n < ip_Addr.length:
		http = "http://" + ip_Addr[n]
		showHttp.push(http)
		n = n + 1
	end
else:
	n = 0
	while n < ip_Addr.length:
		http = "https://" + ip_Addr[n] + ":" + Http_port
		showHttp.push(http)
		n = n + 1
	end
end
add_problem("problems2")
print showHttps
print showHttp

res = cli("show sslvpn cert-manage gateway-cer")
print res
res = res.split(/\r\n?/)
s = 0
tim = []
while s < res.length:
	num = res[s]
	if num.match("Not After") != null :
		tim = num.split(/\s+/)
		break
	end
	s = s + 1
end

print tim
timeNow1 = getDate()
timeNow1 = timeNow1.toString()
timeNow = timeNow1.split(/\s+/)
print timeNow
if timeNow[3] > tim[tim.length - 2]:
	add_problem("problems3")
    return "warn"
else if timeNow[3] == tim[tim.length - 2]:
	print tim[tim.length - 5]
	if timeNow[1] > tim[tim.length - 5]:
		add_problem("problems3")
		return "warn"
	end
end

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

judgeLevelResult(res, "SSLVPN Event error", "error", "")

judgeLevelResult(res, "SSLVPN TLS try", "tryerror", "is0")
judgeLevelResult(res, "SSLVPN TLS Connect", "Connect", "is0")

judgeLevelResult(res, "SSLVPN TLS Connect", "TLS_Failed", "")
judgeLevelResult(res, "SSLVPN HTTP request", "HTTP_request", "is0")

judgeLevelResult(res, "SSLVPN HTTP SSL connect limit", "SSL_connect", "")
judgeLevelResult(res, "SSLVPN HTTP Server error", "Server_error", "")

judgeLevelResult(res, "SSLVPN 4XX page", "4xx_5xx", "")
judgeLevelResult(res, "SSLVPN 5XX page", "4xx_5xx", "")

judgeLevelResult(res, "SSLVPN Login request", "Login_request", "")
judgeLevelResult(res, "SSLVPN CN in blacklist", "blacklist", "")

judgeLevelResult(res, "SSLVPN Cert invalid", "blacklist", "")
judgeLevelResult(res, "SSLVPN Disable Account Login", "Account_Login", "")
judgeLevelResult(res, "SSLVPN Disable Cert Login", "Cert_Login", "")
judgeLevelResult(res, "SSLVPN Disable USBKey Login", "USBKey_Login", "")
judgeLevelResult(res, "SSLVPN License limit", "License_limit", "")
judgeLevelResult(res, "SSLVPN Login Time limit", "Time_limit", "")
judgeLevelResult(res, "SSLVPN Login IP limit", "IP_limit", "")
judgeLevelResult(res, "SSLVPN Login IP Locked", "IP_Locked", "")
judgeLevelResult(res, "SSLVPN Login Name Locked", "Name_Locked", "")
judgeLevelResult(res, "SSLVPN Login server error", "Name_Locked", "")
judgeLevelResult(res, "SSLVPN Incorrect credentials", "AUTH", "")
judgeLevelResult(res, "SSLVPN No Permission", "AUTH", "")
judgeLevelResult(res, "SSLVPN AUTH unknown", "AUTH", "")

res = cli("show sslvpn aaa-statics")
print res
judgeLevelResult(res, "AAA busying failed", "aaa_failed", "")
judgeLevelResult(res, "AAA request failed", "request_failed", "")
judgeLevelResult(res, "Timeout", "Timeout", "")
judgeLevelResult(res, "Unkown error", "Unkown", "")
judgeLevelResult(res, "sslvpn unresponse free", "Unkown", "")

cmd = "show sslvpn log wildcard " + userName 
res = cli(cmd)
print res
res = res.split(/\r\n?/)
if res.length < 2:
	add_problem("step7")
end

return Result