#coding=utf-8 require "aio/core" class Aio::Module::Cmd::Cisco::ShowIpRouteSummary < Aio::Module::Cmd::Cisco include Aio::Module def initialize super({ :cmd_full => "show ip route summary", :cmd_short => "sh ip rou sum", :author => "Elin", :description => "This is Cisco Command# show ip route summary", :platform => "all", :benchmark => {} }) end def parse cont = self.context.dup summary = {} useful[:route_summary] = summary cont.readline_match_block(/Route Source Networks Subnets Replicates Overhead/) cont.readline_match_block(/connected (?\d+) (?\d+) (?\d+)/) do |block| summary_conn = {} summary[:connected] = summary_conn block.update(summary_conn, :networks) block.update(summary_conn, :subnets) block.update(summary_conn, :replicates) end cont.readline_match_block(/static (?\d+) (?\d+) (?\d+)/) do |block| summary_static = {} summary[:static] = summary_static block.update(summary_static, :networks) block.update(summary_static, :subnets) block.update(summary_static, :replicates) end # 有的多一个Replicates,整个数值有可能是5,也有可能是4 # 但是后面的 Replicates Overhead Memory 不做考虑,直接忽略 cont.readline_match_block_loop(/(?[^\d\s]+) (?\d+) (?\d+) (?\d+) (?\d+) .*/, reg_blank) do |block| proto = block[:proto] proto_id = block[:proto_id] summary_proto = {} summary["#{proto}_#{proto_id}".to_sym] = summary_proto block.update(summary_proto, :proto, proto) block.update(summary_proto, :proto_id) block.update(summary_proto, :networks) block.update(summary_proto, :subnets) block.update(summary_proto, :replicates) end end end