{
    "name"  : "检查开启流控之后上网卡",
    "problems" : {
        "noTConError" : {
            "desc"      : "【问题】用户在指定接口并没有开启流控。",
            "advice"    : "【建议】用户是否选错了接口。"
        },
		"noBroError" : {
            "desc"      : "【问题】在实际场景中拨号口的上行带宽不可能大于4M。",
            "advice"    : "【建议】在实际场景中拨号口的上行带宽不可能大于4M，请与运营商确认。"
        },
		"BroNoConError" : {
            "desc"      : "【问题】接口配置的带宽与流控配置的根通道的带宽不一致。",
            "advice"    : "【建议】检查流控的根通道的带宽值是否准确。"
        },
		"noRelError" : {
            "desc"      : "【问题】流控根通道配置的带宽可能大于实际物理带宽。",
            "advice"    : "【建议】接口配置的带宽可能大于运营商实际带宽，请向运营商核实，或关闭流控之后用测速软件测试带宽。"
        },
		"PoNoConError" : {
            "desc"      : "【问题】带宽利用率紧张。",
            "advice"    : "【建议】调小unkey通道的承诺带宽或者每用户带宽。"
        },
		"noRegError" : {
            "desc"      : "【问题】设备出现no buffer，整机性能不足。",
            "advice"    : "【建议】关闭耗性能功能模块，例如流控，流量审计，应用识别等。"
        },
		"inAttackError" : {
            "desc"      : "【问题】内网可能存在伪造报文攻击。",
            "advice"    : "【建议】请查看内网是否存在伪造源IP攻击。"
        }
    }
}
---------------------------code-------------------------------
keyChangeBand= precondition('keyChangeBand')
if keyChangeBand == 'none':
    add_reason('无需检测是否上网慢')
	return 'skip'
end

max = 0
num = 0
commend = "show interface "+keyChangeBand
res = cli(commend)
print res
index = res.match(/Index\(dec\):\d+/ig)
index1 = index[0]
index2 = index1.match(/\d+/)
index3 = index2[0]
print index3
BW = res.match(/BW\s+\d+/ig)
BW1 = BW[0]
BW2 = BW1.match(/\d+/)
BW3 = BW2[0]		
print BW3
res = cli("show flow-control-policy group")
print res
groupName = res.split(/tpl\w+/ig)
bandwidth = res.split(/tpl\w+/ig)
ifx = res.split(/tpl\w+/ig)
print res
resAr = res.match(/\S+\s+\d+\s+[1-9]\d*\s+\d+\s+\d+/ig)
print resAr
if resAr == null :
	print 'warn'
	add_problem("noTConError")
	return 'warn'
end
while num < resAr.length :
	resAr1 = resAr[num] 
	ifx1 = resAr1.split(/\s+/)
	print ifx1
	ifx[num]= ifx1[2]
	groupName[num] = ifx1[0] 
	print "^^^^^^^"+groupName[num]
	bandwidth[num] = ifx1[4]
	num = num +1
end
print groupName
print bandwidth
print ifx
resAr = res.match(keyChangeBand)
print resAr
if resAr == null :
	print 'warn'
	add_problem("noTConError")
	return 'warn'
end
if resAr != null :
	while num < groupName.length :
		nam = groupName[num]
		if nam == keyChangeBand :
			ifxf =ifx[num]
			if ifxf == 0 :
				print 'warn'
				add_problem("noTConError")
				return 'warn'
			end	
			ban1 =bandwidth[num]
			if BW3 != ban1 :
				print 'warn'
				add_problem("BroNoConError")
				return 'warn'
				end	
			end		
		num = num +1
	end
end	
num = 0
while num < groupName.length :
	isDi = groupName[num]
	ban = bandwidth[num]
	if isDi.match(/di/ig) != null &&  ban>40000 :
		print 'warn'
		add_problem("noBroError")
		return 'warn'
	end	
	num = num +1
end
commend = "show flow-control "+keyChangeBand+" auto"
res = cli(commend)
resArr = res.match(/Max-perc\s+\d+\S+\s+Full-cnt\s+\d+/ig)
print resArr
if resArr != null :
	max = resArr[0]
	max1=max.match(/\d+/ig)
	max = max1[0]
	ful = max1[1]
	print "max"+max
	print "ful"+ ful 
	if max < 70 && max > 0:
		print 'warn'
		add_problem("noRelError")
		return 'warn'
	end	
	if max >100 && ful>100 :
		print 'warn'
		add_problem("PoNoConError")
		return 'warn'
	end		
end
res = cli("show logging")
print res
resArr = res.match(/The number of no buffer of interface/ig)
print resArr
if resArr != null :
	print 'warn'
	add_problem("noRegError")
	return 'warn'
end	
res = cli("show flow-control param")
resArr = res.match(/max-limit:\s+\d+/ig)
print resArr
if resArr != null :
	res = resArr[0]
	resArr = res.match(/\d+/ig)
	limi = resArr[0]
	if limi == max :
		print 'warn'
		add_problem("inAttackError")
		return 'warn'
	end	
end	

print 'success'
return 'success'