Class: Aio::Module::Cmd::Cisco::ShowInterfaces
- Inherits:
-
Aio::Module::Cmd::Cisco
- Object
- Aio::Module::Cmd
- Aio::Module::Cmd::Cisco
- Aio::Module::Cmd::Cisco::ShowInterfaces
- Includes:
- Aio::Module
- Defined in:
- lib/modules/cmd/cisco/show_interfaces.rb
Constant Summary collapse
- Reg_Ethernet =
/Ethernet[^\.]+/
- Reg_Loopback =
/Loopback/
- Reg_SubIface =
/Ethernet.*[\.]/
Instance Attribute Summary
Attributes inherited from Aio::Module::Cmd
#cmd_info, #context, #device_info, #ext_info, #useful, #warning_klass
Instance Method Summary collapse
-
#iface_stat(context, iface) ⇒ Object
接口的计数.
-
#initialize ⇒ ShowInterfaces
constructor
A new instance of ShowInterfaces.
- #parse ⇒ Object
- #parse_asa(context) ⇒ Object
- #parse_eth(context) ⇒ Object
- #parse_subiface(context) ⇒ Object
- #switch_iface(context) ⇒ Object
Methods inherited from Aio::Module::Cmd
#author, #benchmark, #clear_useful, #cmd_full, #cmd_short, #description, #division, #key_stand, #license, #platform, #ranking, #set_defaults, #type
Methods included from Ui::Verbose
#clear_line, #print_error, #print_good, #progress_bar
Constructor Details
#initialize ⇒ ShowInterfaces
Returns a new instance of ShowInterfaces.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/modules/cmd/cisco/show_interfaces.rb', line 8 def initialize super({ :cmd_full => "show interfaces", :cmd_short => "sh int", :author => "Elin", :description => "This is Cisco Command# show interfaces", :ranking => Ranking_1, :platform => "all", :benchmark => { :input_queue_drops => ["<=", 10], :total_output_drops => ["<=", 10], :output_queue_drops => ["<=", 10], :runts => ["<=", 10], :giants => ["<=", 10], :throttles => ["<=", 10], :input_errors => ["<=", 10], :crc => ["<=", 1000], :frame => ["<=", 10], :overrun => ["<=", 10], :ignored => ["<=", 10], :output_errors => ["<=", 10], :collisions => ["<=", 10], :iface_resets => ["<=", 10], } }) end |
Instance Method Details
#iface_stat(context, iface) ⇒ Object
接口的计数
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/modules/cmd/cisco/show_interfaces.rb', line 121 def iface_stat(context, iface) #只有当:state 为UP的才会进行下面的操作 if iface[:state] =~ /up/ context.readline_match_block(/Input queue: \d+\/\d+\/(?<input_queue_drops>\d+)\/\d+ \(size\/max\/drops\/flushes\); Total output drops: (?<total_output_drops>\d+)/) do |block| block.warning_ordinary(iface, :input_queue_drops, self) block.warning_ordinary(iface, :total_output_drops, self) end context.readline_match_block(/Output queue: \d+\/\d+\/(?<output_queue_drops>\d+) \(size\/max total\/drops\)/) do |block| block.warning_ordinary(iface, :output_queue_drops, self) end context.readline_match_block(/(?<runts>\d+) runts, (?<giants>\d+) giants, (?<throttles>\d+) throttles/) do |block| block.warning_ordinary(iface, :runts, self) block.warning_ordinary(iface, :giants, self) block.warning_ordinary(iface, :throttles, self) end context.readline_match_block(/(?<input_errors>\d+) input errors, (?<crc>\d+) CRC, (?<frame>\d+) frame, (?<overrun>\d+) overrun, (?<ignored>\d+) ignored/) do |block| block.warning_serious(iface, :input_errors, self) block.warning_serious(iface, :crc, self) block.warning_ordinary(iface, :frame, self) block.warning_ordinary(iface, :overrun, self) block.warning_ordinary(iface, :ignored, self) end context.readline_match_block(/(?<output_errors>\d+) output errors, (?<collisions>\d+) collisions, (?<iface_resets>\d+) interface resets/) do |block| block.warning_serious(iface, :output_errors, self) block.warning_ordinary(iface, :collisions, self) block.warning_ordinary(iface, :iface_resets, self) end end end |
#parse ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/modules/cmd/cisco/show_interfaces.rb', line 39 def parse cont = self.context.dup useful[:interface] = {} cont.readline_range_loop(/, line protocol/, /, line protocol/, {:before => true}) do |cont_layer| case device_template when Template_3 # 当是ASA的时候 parse_asa(cont_layer) else switch_iface(cont_layer) end end end |
#parse_asa(context) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/modules/cmd/cisco/show_interfaces.rb', line 64 def parse_asa(context) iface = {} iface_id = nil context.readline_match_block(/Interface (?<iface_id>.*) "(?<side>.*)", is (?<state>.*), line protocol is (?<proto_state>.*)/) do |block| iface_id = block[:iface_id].strip useful[:interface][iface_id] = iface block.update(iface, :iface_id) block.update(iface, :side) block.update(iface, :state) block.update(iface, :proto_state) end return if iface.empty? context.readline_match_block(/MAC address (?<mac>[^,]*)/) do |block| block.update(iface, :mac) end context.readline_match_block(/IP address (?<addr>.*), subnet mask (?<mask>.*)/) do |block| block.update(iface, :addr) block.update(iface, :mask, Aio::Base::Toolkit::IPAddr.mask_dotted_to_i(block[:mask]).to_s) end iface_stat(context, iface) end |
#parse_eth(context) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/modules/cmd/cisco/show_interfaces.rb', line 88 def parse_eth(context) iface = {} iface_id = nil context.readline_match_block(/(?<iface_id>.*) is (?<state>.*), line protocol is (?<proto_state>.*)/) do |block| iface_id = block[:iface_id].strip useful[:interface][iface_id] = iface block.update(iface, :iface_id) block.update(iface, :state) block.update(iface, :proto_state) end context.readline_match_block(/Hardware .* address is (?<mac>[^\s]*) /) do |block| block.update(iface, :mac) end context.readline_match_block(/Description: (?<description>.*)/) do |block| block.update(iface, :description) end context.readline_match_block(/Internet address is (?<addr>[^\/]+)\/(?<mask>\d+)/) do |block| block.update(iface, :addr) block.update(iface, :mask) end context.readline_match_block(/Encapsulation (?<encapsulation>[^\s]*)/) do |block| block.update(iface, :encapsulation) end context.readline_match_block(/(?<duplex>.*[Dd]uplex), (?<speed>.*), /) do |block| block.update(iface, :duplex) block.update(iface, :speed) end iface_stat(context, iface) end |
#parse_subiface(context) ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/modules/cmd/cisco/show_interfaces.rb', line 151 def parse_subiface(context) iface = {} iface_id = nil context.readline_match_block(/(?<iface_id>.*) is (?<state>.*), line protocol is (?<proto_state>.*)/) do |block| iface_id = block[:iface_id] useful[:interface][iface_id] = iface update(iface, :iface_id) update(iface, :state) update(iface, :proto_state) end context.readline_match_block(/Hardware .* address is (?<mac>.*) /) do |block| update(iface, :mac) end context.readline_match_block(/Description: (?<description>.*)/) do |block| update(iface, :description) end context.readline_match_block(/Internet address is (?<addr>.*)/) do |block| update(iface, :addr) end context.readline_match_block(/Encapsulation (?<encapsulation>.*) Virtual LAN, Vlan ID (?<vlan_id>.*)/) do |block| update(iface, :encapsulation) update(iface, :vlan_id) end end |
#switch_iface(context) ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/modules/cmd/cisco/show_interfaces.rb', line 53 def switch_iface(context) case context[0] when Reg_Ethernet parse_eth(context) when Reg_Loopback parse_eth(context) when Reg_SubIface parse_subiface(context) end end |