Module: Aio::Device::Methods
- Extended by:
- Ui::Verbose
- Defined in:
- lib/aio/core/device/methods.rb
Class Method Summary collapse
- .clock ⇒ Object
-
.configuration? ⇒ Boolean
否是有config命令.
-
.configuration_interfaces ⇒ Object
单独查看接口配置.
-
.cpu_percent ⇒ Object
CPU 利用率百分比.
- .get_manager_ip ⇒ Object
-
.inventory ⇒ Object
板卡序列号信息 返回数组: [:pid, :sn, :description].
-
.ios_version ⇒ Object
IOS 版本.
- .klass ⇒ Object
- .klass=(klass) ⇒ Object
-
.memory_percent ⇒ Object
Memory 利用率百分比.
-
.soft_image ⇒ Object
IOS 特性集.
-
.uptime ⇒ Object
运行时间.
-
.warning_env? ⇒ Boolean
判断温度是否有警告.
-
.warning_fan? ⇒ Boolean
判断风扇是否有警告.
-
.warning_interface? ⇒ Boolean
只判断最关键的三个信息.
-
.warning_power? ⇒ Boolean
判断电源是否有警告.
Methods included from Ui::Verbose
clear_line, print_error, print_good, progress_bar
Class Method Details
.clock ⇒ Object
153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/aio/core/device/methods.rb', line 153 def clock cmd = CmdSwitch.clock(klass) pool = ["time", "zone", "week", "year", "month", "day"] res = [] pool.each do |key| res << klass.cmds_useful[cmd][:clock][key.to_sym] end return res rescue Exception puts_error return ["", "", "", "", "", ""] end |
.configuration? ⇒ Boolean
否是有config命令
26 27 28 29 |
# File 'lib/aio/core/device/methods.rb', line 26 def configuration? cmd = CmdSwitch.configuration(klass) klass.cmds_useful[cmd].nil? ? false : true end |
.configuration_interfaces ⇒ Object
单独查看接口配置
20 21 22 23 |
# File 'lib/aio/core/device/methods.rb', line 20 def configuration_interfaces cmd = CmdSwitch.configuration(klass) return klass.cmds_useful[cmd][:iface_config] end |
.cpu_percent ⇒ Object
CPU 利用率百分比
33 34 35 36 37 38 39 40 |
# File 'lib/aio/core/device/methods.rb', line 33 def cpu_percent cmd = CmdSwitch.cpu(klass) return klass.cmds_useful[cmd][:cpu][:minutes_5] if kind_of?(Cisco, H3C) return klass.cmds_useful[cmd][:cpu][:used_percent] if klass.kind_of? Maipu rescue Exception puts_error return "" end |
.get_manager_ip ⇒ Object
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/aio/core/device/methods.rb', line 166 def get_manager_ip return klass.manager_ip unless klass.manager_ip.nil? cmd = [] cmd[0] = CmdSwitch.interface(klass) cmd[1] = CmdSwitch.interface_brief(klass) total = [] manager = "" return unless kind_of?(Cisco, H3C, Maipu) # 如果是 show interfaces if klass.has_cmd?(cmd[0]) total = klass.cmds_useful[cmd[0]][:interface] total.each_value do |info| if (info[:iface_id] == (klass.interface[:loopback] + "0")) and info[:state] =~ /(?i)up/ manager = info[:addr] end end # 如果是 show ip interface brief elsif klass.has_cmd?(cmd[1]) total = klass.cmds_useful[cmd[1]][:interface_brief] total.each_value do |info| # 如果有环回口,那么就直接输出 if (info[:interface_id].downcase == klass.interface[:loopback].downcase + "0") and (info[:status] =~ /(?i)up/) manager = info[:ip] end end end return manager rescue Exception puts_error return "" end |
.inventory ⇒ Object
板卡序列号信息返回数组: [:pid, :sn, :description]
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 150 151 |
# File 'lib/aio/core/device/methods.rb', line 121 def inventory cmd = CmdSwitch.inventory(klass) if kind_of?(Cisco, H3C) keys = klass.cmds_useful[cmd][:inventory].keys res = [] keys.each do |sn| res << klass.cmds_useful[cmd][:inventory][sn.to_sym] end return res elsif kind_of?(Maipu) md = klass.cmds_useful[cmd][:module] res = [] md.each_value do |v| res << { name: v[:module], # 这里反着来 pid: v[:name], sn: v[:sn], description: '' } end return res else return [{:name => "", :pid => "", :sn => "", :description => ""}] end rescue Exception puts_error return [{:name => "", :pid => "", :sn => "", :description => ""}] end |
.ios_version ⇒ Object
IOS 版本
54 55 56 57 58 59 60 |
# File 'lib/aio/core/device/methods.rb', line 54 def ios_version cmd = CmdSwitch.version(klass) return klass.cmds_useful[cmd][:software][:version] if kind_of?(Cisco, H3C, Maipu) rescue Exception puts_error return "" end |
.klass ⇒ Object
15 16 17 |
# File 'lib/aio/core/device/methods.rb', line 15 def klass @@klass end |
.klass=(klass) ⇒ Object
11 12 13 |
# File 'lib/aio/core/device/methods.rb', line 11 def klass=(klass) @@klass = klass end |
.memory_percent ⇒ Object
Memory 利用率百分比
43 44 45 46 47 48 49 50 51 |
# File 'lib/aio/core/device/methods.rb', line 43 def memory_percent cmd = CmdSwitch.memory(klass) return klass.cmds_useful[cmd][:memory][:used_rate] if klass.kind_of? H3C return klass.cmds_useful[cmd][:memory][:proc_ratio] if klass.kind_of? Cisco return klass.cmds_useful[cmd][:memory][:used_percent] if klass.kind_of? Maipu rescue Exception puts_error return "" end |
.soft_image ⇒ Object
IOS 特性集
63 64 65 66 67 68 69 70 71 |
# File 'lib/aio/core/device/methods.rb', line 63 def soft_image cmd = CmdSwitch.version(klass) return klass.cmds_useful[cmd][:software][:soft_image] if kind_of?(Cisco, Maipu) # H3C 不是在version中查看 rescue Exception puts_error return "" end |
.uptime ⇒ Object
运行时间
74 75 76 77 78 79 80 |
# File 'lib/aio/core/device/methods.rb', line 74 def uptime cmd = CmdSwitch.version(klass) return klass.cmds_useful[cmd][:software][:uptime] if kind_of?(Cisco, H3C, Maipu) rescue Exception puts_error return "" end |
.warning_env? ⇒ Boolean
判断温度是否有警告
83 84 85 86 87 88 89 90 |
# File 'lib/aio/core/device/methods.rb', line 83 def warning_env? if klass.kind_of? Maipu return (klass.include_warning?(:mainboard_temperature) and klass.include_warning?(:cpu_temperature)) end return klass.include_warning?(:cpu_status) if klass.kind_of? Cisco rescue Exception puts_error end |
.warning_fan? ⇒ Boolean
判断风扇是否有警告
101 102 103 104 105 |
# File 'lib/aio/core/device/methods.rb', line 101 def warning_fan? return klass.include_warning?(:fan_status) if kind_of?(Cisco, H3C, Maipu) rescue Exception puts_error end |
.warning_interface? ⇒ Boolean
只判断最关键的三个信息
108 109 110 111 112 113 114 115 116 117 |
# File 'lib/aio/core/device/methods.rb', line 108 def warning_interface? if kind_of?(Cisco, Maipu, H3C) tmp = klass.include_warning?(:input_errors) tmp = tmp or klass.include_warning(:crc) tmp = tmp or klass.include_warning(:output_errors) return tmp end rescue Exception puts_error end |