{
    "name"  : "检查策略路由配置",
    "problems" : {
        "conflict" : {
            "desc"      : "【问题】策略路由未正确配置",
            "advice"    : "【建议】${0}接口没有启动策略路由，请确认需要走策略路由的数据是否从这个接口流入，请在内网接口启用策略路由命令为ip policy route-map 策略路由名" 
        },
		"conflict1" : {
            "desc"      : "【问题】策略路由下一跳可能未正确配置",
            "advice"    : "【提示】策略路由不支持set next-hop规则，正确的配置为set ip next-hop，请检查是否需要配置${1}"

        },
		"conflict2" : {
            "desc"      : "【问题】策略路由下一跳可能未正确配置",
            "advice"    : "【提示】目前配置策略路由为低优先级路由，请检查是否需要配置${1}"

        },
		"conflict3" : {
            "desc"      : "【问题】策略路由下一跳可能未正确配置",
            "advice"    : "【建议】提示策略路由下一跳配置错误，正确的配置为set ip next hop ${1}" 
        },
		"conflict4" : {
            "desc"      : "【问题】策略路由set interface规则可能未正确配置",
            "advice"    : "【提示】策略路set interface规则接口仅支持点对点口，常见的如tunnel口、dialer口，普通以太网接口不支持set interface规则，请使用set ip next-hop规则替换" 
        },

		"conflict5" : {
            "desc"      : "【问题】策略路由匹配ACL未正确配置",
            "advice"    : "【建议】提示策略路由匹配ACL配置错误，正确的配置为match ip address " 
        },
		"conflict6" : {
            "desc"      : "【问题】策略路由关联的ACL未配置",
            "advice"    : "【建议】策略路由关联的ACL未配置" 
        },
		"conflict7" : {
            "desc"      : "【问题】策略路由关联的ACL配置可能不正确",
            "advice"    : "【建议】策略路由调用的ACL没有包含需要走策略路由的IP x.x.x.x.，请修订策略路由调用的ACL" 
        },
		"conflict8" : {
            "desc"      : "【问题】策略路由调用的ACL有deny规则匹配异常IP",
            "advice"    : "【建议】在策略路由调用的ACL中，如果在其中一个子图调用的ACL中显示的deny掉某些地址段，对应的数据流将会直接跳出route-map；进行普通路由的匹配；现${1}对应的网段已经被ACL 拒绝走策略路由，需要修改配置走策略路由的网段不要配置拒绝" 
        },
		"conflict9" : {
            "desc"      : "【问题】策略路由调用的ACL有deny规则匹配异常IP",
            "advice"    : "【建议】在策略路由调用的ACL中，在其中一个子图调用的ACL中deny掉${1}对应的网段，对应的数据流不会直接跳出route-map，而会跳出当前路由子图，进行下一个路由子图的匹配" 
        }

      } 
}

---------------------------code------------------------------- 
routeInterface = precondition('routeInterface')
nextStep1Ip = precondition('nextStep1Ip')
routeMap = precondition('routeMap')
#routeMap = 'rm'

cmd = 'show ip policy ' + routeMap + ' | include '+ routeInterface
response = cli(cmd)
results = response.split(/(\r?\n)+/)
print results.length
print results
if results.length < 4:
		add_problem("conflict",[routeInterface])
		return 'warn'
	end
	

	
nextStep1Ip = precondition('nextStep1Ip')
cmd = 'show route-map ' + routeMap + ' | include '+ nextStep1Ip
response1 = cli(cmd)
print response1
results1 = response1.split(/\r?\n/ig)
print results1
print results1.length
i=1
while i < ( results1.length -1 ) :
    resultsTemp = results1[i]
	resultsTemp = resultsTemp.trim()
	a = resultsTemp.match(/\bip\b.*\bdefault\b/) 
	b = resultsTemp.match(/\bnext\b.*\hop\b/) 
	c = resultsTemp
	d = resultsTemp.match(/\bip\b.*\bnext\b.*\hop\b/)
	print d
	print resultsTemp
	print "uuuuuuuuuuuuuuu"
	print c.length
		  if (d == null) && (a != null):
			add_problem("conflict1",[routeInterface,nextStep1Ip])
			return 'warn'
			end
			if (d == null) && (b != null):
			add_problem("conflict2",[routeInterface,nextStep1Ip])
			end 
			if (d == null) && (c.length) < 8 :
			add_problem("conflict3",[routeInterface,nextStep1Ip])
			return 'warn'
			end 
	i = i + 1
end	




cmd = 'show route-map ' + routeMap 
response2 = cli(cmd)
print response2
results2 = response2.split(/(\r?\n)+/)
print results2
print "hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh"
i = 1
arr = []
while i < results2.length:
    resultsTemp2 = results2[i]
	resultsTemp2 = resultsTemp2.trim()
	print resultsTemp2	
	a = resultsTemp2.match(/\binterface\b/) 	
	print a 
    if a != null :
		add_problem('conflict4')
		return 'warn'
	end
	i = i + 1
end	


	
cmd = 'show route-map ' + routeMap+  ' | include ip address'
response3 = cli(cmd)
print response3
results3 = response3.split(/\r?\n/ig)
print results3
data = []
i = 1
j = 0
while i < results3.length:
    resultsTemp3 = results3[i]
	resultsTemp3 = resultsTemp3.trim()
	arr = resultsTemp3.split(/\s/)
	print arr 
	print arr.length
	while j < arr.length :
	m = arr [j]
	x = m.match(/\bacl\w\b/)
		if x !=null:
		data.push(x)
		print data 
		end 
	j=j+1
	end
	if data.length < 1:
	add_problem('conflict5')
	return 'warn'
	end 
	i = i + 2
end

			k = 0
			while k < data.length :
			print data
			datan = data [k]
			cmd ='show access-lists ' + datan
			response4 = cli(cmd)
			print response4
			print "555555666666666"
			results4 = response4.split(/\r?\n/ig)
						print results4.length
						print "wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww"
						if results4.length < 3 :
						add_problem("conflict6")
						return 'warn'
						end					
			k = k + 1
			end	
			
			
			k = 0
			while k < data.length :
				print data
				datan = data [k]
				print "777777777777777777777777777777777777777777777"
				cmd ='show access-lists ' + datan
				response4 = cli(cmd)
				print response4
				s = 0			
				a=response4.match(/\w*\.\w*\.\w*\.\w*\s\w*\.\w*\.\w*\.\w*/)
				aa = []
				if a != null :
				aa = response4.match(/\w*\.\w*\.\w*/)
				aa0=aa[0]
				print aa0
				cc=nextStep1Ip.match(/\w*\.\w*\.\w*/)
				cc0=cc[0]
				print cc0
				bb=response4.match(/\w*\.\w*\.\w*\.\w*/)
				bb0=bb[0]
				print bb0
					if (aa0 !=cc0)&&(bb0 !=cc0)  :
					add_problem('conflict7')
					return 'warn'
					end
				end 
				k = k + 1
			end		

			
			
			k = 0
			while k < data.length :
				datan = data [k]
				cmd ='show access-lists ' + datan + ' | include deny'
				response4 = cli(cmd)
				results4 = response4.split(/\r?\n/ig)
				print "88888888888888888888"
				print results4.length
				if results4.length < 3 :
				return 'success'
				end
			
				cmd ='show route-map ' + routeMap
				response4 = cli(cmd)
				print "mmmmmmmmmmmmmmmm"
				print response4 
				a = response4.match(/\bsequence\s2\b/)
				results4 = response4.split(/\r?\n/ig)
				print results4
				print results4.length
				print a 
				arrr = []
				if a != null :
				    i = 0
					while i < (results4.length -5):
					resultsTemp = results4[i]
					resultsTemp = resultsTemp.trim()			
					print resultsTemp 
					arrs = resultsTemp.match(/\bip\s\address\b\s*\w*\s*\w*/)
						if arrs != null :
						arrs0 = arrs[0]
						print arrs0 	
						arrs1 = arrs0.match(/\d+\s\d+/)
						arrs2 = arrs1[0]
						arrs3 = arrs2.match(/\d+/)
							arrr.push(arrs3)
						arrs4 = arrs2.match(/\s\d+/)
							arrr.push(arrs4)
						print arrr
						return arrr
						print "ggggggggggggggggggggggggggggggggggggggggggg"
						end 					
					i = i + 1
					end 
				else : 
				return 'success'
				end 
				k = k + 1
			end		

		
				i = 0	
				while i < arrr.length :
					cmd = 'show access-list ' +arrr[i] +' | include deny'
					response4 = cli(cmd)
					print response4
					s = 0			
					a=response4.match(/\w*\.\w*\.\w*\.\w*\s\w*\.\w*\.\w*\.\w*/)
					aa = []
					if a != null :
					aa = response4.match(/\w*\.\w*\.\w*/)
					aa0=aa[0]
					print aa0
					cc=nextStep1Ip.match(/\w*\.\w*\.\w*/)
					cc0=cc[0]
					print cc0
					bb=response4.match(/\w*\.\w*\.\w*\.\w*/)
					bb0=bb[0]
					print bb0
						if (aa0 ==cc0)||(bb0 ==cc0)  :
						add_problem('conflict9',[routeInterface,nextStep1Ip])
						return 'warn'
						end
					end 
				i = i + 2 
				end 	
				
				i = 1	
				while i < arrr.length :
					cmd = 'show access-list ' +arrr[i] +' | include deny'
					response4 = cli(cmd)
					print response4
					s = 0			
					a=response4.match(/\w*\.\w*\.\w*\.\w*\s\w*\.\w*\.\w*\.\w*/)
					aa = []
					if a != null :
					aa = response4.match(/\w*\.\w*\.\w*/)
					aa0=aa[0]
					print aa0
					cc=nextStep1Ip.match(/\w*\.\w*\.\w*/)
					cc0=cc[0]
					print cc0
					bb=response4.match(/\w*\.\w*\.\w*\.\w*/)
					bb0=bb[0]
					print bb0
						if (aa0 ==cc0)||(bb0 ==cc0)  :
						add_problem('conflict9',[routeInterface,nextStep1Ip])
						return 'warn'
						end
					end 
				i = i + 2 
				end 	
return 'success'


