
{
    "name"  : "是否端口配置限速导致",
    "precondition" : ["name"],
    "problems" : {
        "port_limit" : {
            "desc"      : "【问题】端口${0}配置了限速功能，现场可能因流量超过该阀值，导致业务丢包正常。",
            "advice"    : "【建议】请确认是否需要删除端口限速，或者修订其它限速值。若点击自动下发则自动删除限速命令。"
        }
    }
}

---------------------------code-------------------------------
intf = precondition('name')
restore_cmd = []
reback_cmd = []
intf_cmd = format('show run interface %s',intf)
intf_limit = cli(intf_cmd)
reg = /rate-limit/
r = intf_limit.match(reg)
if r != null:
    change_title('检测出端口配置了限速')
	
    restore_cmd.push('config')
    cmd_intf = 'interface '+intf
    restore_cmd.push(cmd_intf)
    restore_cmd.push('no rate-limit input')
    restore_cmd.push('no rate-limit output')
    restore_cmd.push('end')
    restore_cmd.push('write')
	
	input_cmd = getCmd('in',intf_limit)
	output_cmd = getCmd('out',intf_limit)
	reback_cmd.push('config')
    cmd_intf = 'interface '+intf
	reback_cmd.push(cmd_intf)
	reback_cmd.push(input_cmd)
	reback_cmd.push(output_cmd)
	reback_cmd.push('end')
	reback_cmd.push('write')
	
    add_problem('port_limit',[intf],restore_cmd,reback_cmd)
    return 'warn'        
end

change_title('检测端口未配置限速')
return 'success'

def getCmd(type,str):
	cmd = ""
	reg_input = /(rate-limit input \d+ \d+)/
	reg_output = /(rate-limit output \d+ \d+)/
	if type =='in':
		r = str.match(reg_input)
		if r != null:
			cmd = r[1]
		end
	else:
		r = str.match(reg_output)
		if r != null:
			cmd = r[1]
		end
	end
	return cmd
end

