aio_elin 1.1.4 → 1.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3093074e8e06bcab921686e962bef6673c402294a56f33787dd60a0ca4c5c17b
4
- data.tar.gz: 57f76f51557109d3997415e5c9e8fb31a5c1214919bc578275c218bded6f3a49
3
+ metadata.gz: 90dd9b073ff592969c306ad69c4555f3fbf52725618eb324a2e4b68ccade5af8
4
+ data.tar.gz: a2627434d305620d41d2fac80fa716f1ba97765f32c87fd47bc81e5bd303e911
5
5
  SHA512:
6
- metadata.gz: 00d4aea9f3765dbf13999417a2dc1ba095e7017c48b4b070bd82471cf735f42c06877d18b057ec97b7c5fc48405de6a57a663bc9f1fe0a2ebefcb8f473c7c7e3
7
- data.tar.gz: 4d417b9f884ba2e2dfc6172e04a381a177dcb7c437c252ff9e37e6f72a3db8ee332d3684eb13ae29b835eea367c0b4329098419872c973fe0dcedbe464b3a3fd
6
+ metadata.gz: df3db93e38705d96dd46f04675b7ffee2aa1707841f39db1db22f0c19aa9ccf1a7cf5f6bec57fcafc23f961c9d79145b738078c2e9afe234eb533e7ff54f3de2
7
+ data.tar.gz: 0e0b530a253d1b737dc7597e94f4d3760d7332afc52d746eab5de08432ab916e905ca4f68df51ec770512ee6f86c05380d07e8148c5f7c263d44d0b87a6bb083
@@ -2,112 +2,123 @@
2
2
  # 这个模块用于转换不同设备间的命令
3
3
  #
4
4
  module Aio::Device
5
- module CmdSwitch
5
+ module CmdSwitch
6
6
 
7
- include Aio::Module
8
-
9
- class << self
10
- def version(klass)
11
- case klass
12
- when Cisco, Maipu
13
- "show version"
14
- when H3C
15
- "display version"
16
- end
17
- end
7
+ include Aio::Module
18
8
 
19
- def cpu(klass)
20
- case klass
21
- when Cisco
22
- "show process cpu"
23
- when H3C
24
- "display cpu-usage"
25
- when Maipu
26
- "show cpu"
27
- end
28
- end
9
+ class << self
10
+ def version(klass)
11
+ case klass
12
+ when Cisco, Maipu
13
+ "show version"
14
+ when H3C
15
+ "display version"
16
+ end
17
+ end
29
18
 
30
- def memory(klass)
31
- case klass
32
- when Cisco
33
- "show process memory"
34
- when H3C
35
- "display memory"
36
- when Maipu
37
- "show memory"
38
- end
39
- end
19
+ def configuration(klass)
20
+ case klass
21
+ when Cisco, Maipu
22
+ 'show run'
23
+ when H3C, Huawei
24
+ 'display current'
25
+ end
26
+ end
40
27
 
41
- def inventory(klass)
42
- case klass
43
- when Cisco
44
- "show inventory"
45
- when H3C
46
- "display device manuinfo"
47
- end
48
- end
28
+ def cpu(klass)
29
+ case klass
30
+ when Cisco
31
+ "show process cpu"
32
+ when H3C
33
+ "display cpu-usage"
34
+ when Maipu
35
+ "show cpu"
36
+ end
37
+ end
49
38
 
50
- def clock(klass)
51
- case klass
52
- when Cisco, Maipu
53
- "show clock"
54
- when H3C
55
- "display clock"
56
- end
57
- end
39
+ def memory(klass)
40
+ case klass
41
+ when Cisco
42
+ "show process memory"
43
+ when H3C
44
+ "display memory"
45
+ when Maipu
46
+ "show memory"
47
+ end
48
+ end
58
49
 
59
- def environment(klass)
60
- case klass
61
- when Cisco, Maipu
62
- "show environment"
63
- end
64
- end
50
+ def inventory(klass)
51
+ case klass
52
+ when Cisco
53
+ "show inventory"
54
+ when H3C
55
+ "display device manuinfo"
56
+ when Maipu
57
+ "show system module brief"
58
+ end
59
+ end
65
60
 
66
- def power(klass)
67
- case klass
68
- when Cisco
69
- "show environment"
70
- when H3C
71
- "display power"
72
- when Maipu
73
- "show system power"
74
- end
75
- end
61
+ def clock(klass)
62
+ case klass
63
+ when Cisco, Maipu
64
+ "show clock"
65
+ when H3C
66
+ "display clock"
67
+ end
68
+ end
76
69
 
77
- def fan(klass)
78
- case klass
79
- when Cisco
80
- "show environment"
81
- when H3C
82
- "display fan"
83
- when Maipu
84
- "show system fan"
85
- end
86
- end
70
+ def environment(klass)
71
+ case klass
72
+ when Cisco, Maipu
73
+ "show environment"
74
+ end
75
+ end
87
76
 
88
- def interface(klass)
89
- case klass
90
- when Cisco, Maipu
91
- "show interfaces"
92
- when H3C, Huawei
93
- "display interface"
94
- end
95
- end
77
+ def power(klass)
78
+ case klass
79
+ when Cisco
80
+ "show environment"
81
+ when H3C
82
+ "display power"
83
+ when Maipu
84
+ "show system power"
85
+ end
86
+ end
96
87
 
97
- def interface_brief(klass)
98
- case klass
99
- when Cisco
100
- # if klass.platform == FW
101
- # "show interface ip brief"
102
- "show ip interface brief"
103
- when H3C
104
- "display ip interface brief"
105
- when Maipu
106
- "show ip interface brief"
107
- end
108
- end
109
-
88
+ def fan(klass)
89
+ case klass
90
+ when Cisco
91
+ "show environment"
92
+ when H3C
93
+ "display fan"
94
+ when Maipu
95
+ "show system fan"
96
+ end
97
+ end
110
98
 
111
- end # class self
112
- end
99
+ def interface(klass)
100
+ case klass
101
+ when Cisco, Maipu
102
+ "show interfaces"
103
+ when H3C, Huawei
104
+ "display interface"
105
+ end
106
+ end
107
+
108
+ def interface_brief(klass)
109
+ case klass
110
+ when Cisco
111
+ # if klass.platform == FW
112
+ # "show interface ip brief"
113
+ "show ip interface brief"
114
+ when H3C
115
+ "display ip interface brief"
116
+ when Maipu
117
+ "show ip interface brief"
118
+ end
119
+ end
120
+
121
+
122
+ end # class self
123
+ end
113
124
  end
@@ -16,6 +16,19 @@ module Aio::Device
16
16
  @@klass
17
17
  end
18
18
 
19
+ # 单独查看接口配置
20
+ def configuration_interfaces
21
+ cmd = CmdSwitch.configuration(klass)
22
+ return klass.cmds_useful[cmd][:iface_config]
23
+ end
24
+
25
+ # 否是有config命令
26
+ def configuration?
27
+ cmd = CmdSwitch.configuration(klass)
28
+ klass.cmds_useful[cmd].nil? ? false : true
29
+ end
30
+
31
+
19
32
  # CPU 利用率百分比
20
33
  def cpu_percent
21
34
  cmd = CmdSwitch.cpu(klass)
@@ -114,6 +127,20 @@ module Aio::Device
114
127
  res << klass.cmds_useful[cmd][:inventory][sn.to_sym]
115
128
  end
116
129
  return res
130
+
131
+ elsif kind_of?(Maipu)
132
+ md = klass.cmds_useful[cmd][:module]
133
+ res = []
134
+ md.each_value do |v|
135
+ res << {
136
+ name: v[:module], # 这里反着来
137
+ pid: v[:name],
138
+ sn: v[:sn],
139
+ description: ''
140
+ }
141
+ end
142
+ return res
143
+
117
144
  else
118
145
  return [{:name => "", :pid => "", :sn => "", :description => ""}]
119
146
  end
@@ -244,6 +244,8 @@ module Aio::Device
244
244
  end
245
245
  end
246
246
 
247
+ alias :name :device_name
248
+
247
249
  private
248
250
 
249
251
  def changeto_cisco
@@ -155,6 +155,16 @@ module Aio::Module
155
155
  Aio::Base::Toolkit::Regexp.blank
156
156
  end
157
157
 
158
+ def reg_separator
159
+ if self.kind_of?(Cisco)
160
+ return /^!$/
161
+ elsif self.kind_of?(H3C)
162
+ return /^[#]$/
163
+ else
164
+ reg_blank
165
+ end
166
+ end
167
+
158
168
  end
159
169
  end
160
170
 
data/lib/aio/ui.rb CHANGED
@@ -114,6 +114,9 @@ module Aio::Ui
114
114
  device_manager.warning_summarize_tidy
115
115
  end # 判断没有没 input 尾部
116
116
 
117
+ # NOTE Debug 输出方法处
118
+ #device_manager["PF_YYB_MP2900_1"].inventory
119
+
117
120
  print_good "正在加载输出模块 #{banner.output_style}"
118
121
  output_klass = module_manager.get_module_klass_by_name(banner.output_style)
119
122
 
@@ -0,0 +1,40 @@
1
+ #coding=utf-8
2
+
3
+ require "aio/core"
4
+
5
+ class Aio::Module::Cmd::Cisco::ShowRun < Aio::Module::Cmd::Cisco
6
+ include Aio::Module
7
+
8
+ def initialize
9
+ super({
10
+ :cmd_full => "show run",
11
+ :cmd_short => "sh run",
12
+ :author => "Elin",
13
+ :description => "This is Cisco Command# show run",
14
+ :key_stand => true,
15
+ :platform => "all"
16
+ })
17
+ end
18
+
19
+ #
20
+ # 此模块暂时只支持将show run中的接口信息提取出来,不做任何处理
21
+ #
22
+ def parse
23
+ context = self.context.dup
24
+ iface_config = {}
25
+ useful[:iface_config] = iface_config
26
+
27
+ # NOTE 删除
28
+ context.readline_match_block(/Building configuration/) do |block|
29
+ key_stand_cisco
30
+ end
31
+
32
+ context.readline_range_loop(/interface (Fast|Gigabit)Ethernet/, reg_separator) do |cont|
33
+ iface_name = cont.shift.split(' ')[1]
34
+ iface_cont = cont.join("\n")
35
+
36
+ iface_config[iface_name] = iface_cont
37
+ end
38
+ end
39
+ end
40
+
@@ -0,0 +1,40 @@
1
+ #coding=utf-8
2
+
3
+ require "aio/core"
4
+
5
+ class Aio::Module::Cmd::H3C::DisplayCurrent < Aio::Module::Cmd::H3C
6
+ include Aio::Module
7
+
8
+ def initialize
9
+ super({
10
+ :cmd_full => "display current",
11
+ :cmd_short => "dis cu",
12
+ :author => "Elin",
13
+ :description => "This is H3C Command# display current",
14
+ :ranking => Ranking_1,
15
+ :key_stand => true,
16
+ :platform => "all"
17
+ })
18
+ end
19
+
20
+ #
21
+ # 此模块暂时只支持将dis cur中的接口信息提取出来,不做任何处理
22
+ #
23
+ def parse
24
+ context = self.context.dup
25
+ iface_config = {}
26
+ useful[:iface_config] = iface_config
27
+
28
+ # NOTE 删除
29
+ context.readline_match_block(/^sysname/) do |cont|
30
+ key_stand_h3c
31
+ end
32
+
33
+ context.readline_range_loop(/interface (Fast|Gigabit)Ethernet/, reg_separator) do |cont|
34
+ iface_name = cont.shift.split(' ')[1]
35
+ iface_cont = cont.join("\n")
36
+
37
+ iface_config[iface_name] = iface_cont
38
+ end
39
+ end
40
+ end
@@ -14,7 +14,7 @@ class Aio::Module::Cmd::Maipu::ShowSystemFan < Aio::Module::Cmd::Maipu
14
14
  :ranking => Ranking_1,
15
15
  :platform => "all",
16
16
  :benchmark => {
17
- :fan_status => ["==", "NORMAL"],
17
+ :fan_status => ["==", "NORMAL", 'Normal'],
18
18
  :fan_alarm => ["<", 1]
19
19
  }
20
20
  })
@@ -0,0 +1,69 @@
1
+ #coding=utf-8
2
+
3
+ require "aio/core"
4
+
5
+ class Aio::Module::Cmd::Maipu::ShowSystemModuleBrief < Aio::Module::Cmd::Maipu
6
+ include Aio::Module
7
+
8
+ def initialize
9
+ super({
10
+ :cmd_full => "show system module brief",
11
+ :cmd_short => "sh sys mod b",
12
+ :author => "Elin",
13
+ :description => "This is Maipu Command# show system module brief",
14
+ :ranking => Ranking_1,
15
+ :platform => "all",
16
+ :benchmark => {}
17
+ })
18
+ end
19
+
20
+ def parse
21
+ cont = self.context.dup
22
+ useful[:module] = {}
23
+ all_module = useful[:module]
24
+
25
+ cont.readline_match_block(/-------------------/) {|b|b}
26
+ cont.readline_match_block_loop(/.*/, reg_blank) do |block|
27
+ bl = block[0].to_s
28
+ arr = bl.split(' ')
29
+ # 当是7个的时候,说明是
30
+ # Mpu 0 online Start Ok SM3120-28TC(V1) ******************
31
+ if arr.size == 7
32
+ md = arr.shift + " " + arr.shift
33
+ online = arr.shift
34
+ status = arr.shift + " " + arr.shift
35
+ name = arr.shift
36
+ sn = arr.shift
37
+
38
+ one_module = {}
39
+ all_module[md] = one_module
40
+
41
+ block.update(one_module, :module, md)
42
+ block.update(one_module, :online, online)
43
+ block.update(one_module, :status, status)
44
+ block.update(one_module, :name, name)
45
+ block.update(one_module, :sn, sn)
46
+
47
+ # Power 1 online Normal /
48
+ elsif
49
+ md = arr.shift + " " + arr.shift
50
+ online = arr.shift
51
+ status = arr.shift
52
+ name = arr.shift
53
+ sn = arr.shift unless arr.empty?
54
+ sn ||= '/'
55
+
56
+ one_module = {}
57
+ all_module[md] = one_module
58
+
59
+ block.update(one_module, :module, md)
60
+ block.update(one_module, :online, online)
61
+ block.update(one_module, :status, status)
62
+ block.update(one_module, :name, name)
63
+ block.update(one_module, :sn, sn)
64
+ end
65
+
66
+ end
67
+ end
68
+ end
69
+
@@ -0,0 +1,219 @@
1
+ #coding=utf-8
2
+
3
+ require "aio/core"
4
+
5
+ class Aio::Module::OutputStyle::Citic < Aio::Module::OutputStyle
6
+
7
+ include Aio::Ui::Verbose
8
+ include Aio::Device
9
+
10
+ def initialize
11
+ super({
12
+ :author => "Elin",
13
+ :description => "此模块用于中信银行接口查询",
14
+ :file_suffix => "txt",
15
+ })
16
+
17
+ @report = {}
18
+ end
19
+
20
+ def generate
21
+ file = File.new(output_file, "w+")
22
+
23
+ device_manager.devices.each_key do |device_name|
24
+ device_klass = device_manager[device_name]
25
+
26
+ # 当不是需要的设备类型时
27
+ unless device_klass.kind_of?(Cisco) or device_klass.kind_of?(H3C)
28
+ print_error "#{device_name} 不在检查设备类型内"
29
+ next
30
+ end
31
+
32
+ # 当没有信息的时候,跳过
33
+ unless device_klass.configuration?
34
+ print_error "#{device_name} 没有配置信息"
35
+ next
36
+ end
37
+
38
+ device_klass.configuration_interfaces.each_pair do |iface, cont|
39
+ config = cont.split("\n")
40
+
41
+ # 当接口是关闭的,那么跳过
42
+ if config.include?('shutdown')
43
+ next
44
+
45
+ # 当接口是三层接口,那么跳过
46
+ elsif config.to_s.match(/ip address/)
47
+ next
48
+
49
+ # 当接口是access
50
+ elsif config.to_s.match(/port access/)
51
+ check_access(device_klass, iface, config)
52
+
53
+ # 当接口是trunk
54
+ elsif config.to_s.match(/port mode|link-type trunk/)
55
+ check_trunk(device_klass, iface, config)
56
+
57
+ # 如有既不是access 也不是 trunk 则报错
58
+ else
59
+ report_error(device_name, iface, '未做配置')
60
+ end
61
+
62
+ end
63
+ end
64
+
65
+ file.write(puts_report)
66
+ end
67
+
68
+ def report_error(device_name, iface, msg)
69
+ @report[device_name] ||= []
70
+ @report[device_name] << [iface, msg]
71
+ end
72
+
73
+ # 检查access接口配置是否齐全
74
+ def check_access(device_klass, iface, config)
75
+ ck = false
76
+
77
+ # 当是思科
78
+ =begin
79
+
80
+ switchport access vlan
81
+ switchport mode access
82
+ switchport port-security
83
+ switchport port-security mac-address
84
+
85
+ 或者
86
+
87
+ switchport access vlan
88
+ switchport mode access
89
+ authentication port-control auto
90
+ authentication violation protect
91
+ dot1x pae authenticator
92
+
93
+ 或者
94
+
95
+ switchport access vlan
96
+ switchport mode access
97
+ dot1x mac-auth-bypass
98
+ dot1x pae authenticator
99
+ dot1x port-control auto
100
+
101
+ =end
102
+ if device_klass.kind_of? Cisco
103
+ point = 0b000000000
104
+ # switchport port-security mac-address 只能出现一次
105
+ mac_first = true
106
+
107
+ config.each do |c|
108
+ case c
109
+ when /^switchport access vlan/ # 1
110
+ point += 0b000000001
111
+ when /^switchport mode access$/ # 2
112
+ point += 0b000000010
113
+ when /^switchport port-security$/ # 3
114
+ point += 0b000000100
115
+ when /^switchport port-security mac-address/ # 4
116
+ point += 0b000001000 if mac_first
117
+ mac_first = false
118
+ when /^authentication port-control auto$/ # 5
119
+ point += 0b000010000
120
+ when /^authentication violation protect$/ # 6
121
+ point += 0b000100000
122
+ when /^dot1x pae authenticator$/ # 7
123
+ point += 0b001000000
124
+ when /^dot1x mac-auth-bypass$/ # 8
125
+ point += 0b010000000
126
+ when /^dot1x port-control auto$/ # 9
127
+ point += 0b100000000
128
+ end
129
+ end
130
+
131
+ if point == 0b000001111 or point == 0b001110011 or point == 0b111000011 or point == 0b001010011
132
+ ck = true
133
+ end
134
+
135
+ # 当是H3C的时候
136
+ =begin
137
+
138
+ port link-mode bridge
139
+ port access vlan
140
+ stp edged-port
141
+ mac-address max-mac-count 0
142
+ undo mac-address max-mac-count enable-forwarding
143
+ mac-address static
144
+
145
+ =end
146
+ elsif device_klass.kind_of? H3C
147
+ point = 0b000000
148
+ config.each do |c|
149
+ case c
150
+ when /^port link-mode bridge$/
151
+ point += 0b000001
152
+ when /^port access vlan$/
153
+ point += 0b000010
154
+ when /^stp edged-port$/
155
+ point += 0b000100
156
+ when /^mac-address max-mac-count 0$/
157
+ point += 0b001000
158
+ when /^undo mac-address max-mac-count enable-forwarding$/
159
+ point += 0b010000
160
+ when /^mac-address static$/
161
+ point += 0b100000
162
+ end
163
+ end
164
+
165
+ if point == 0b0011111 or point == 0b1100011
166
+ ck = true
167
+ end
168
+ end
169
+
170
+ report_error(device_klass.name, iface, 'access 接口配置不完全') unless ck
171
+ return ck
172
+ end
173
+
174
+ # 检查trunk接口配置是否齐全
175
+ def check_trunk(device_klass, iface, config)
176
+ ck = false
177
+
178
+ if device_klass.kind_of? Cisco
179
+ ck = true if config.include?('switchport mode trunk')
180
+
181
+ elsif device_klass.kind_of? H3C
182
+ ck = true if config.include?('port link-type trunk')
183
+
184
+ else
185
+ return false
186
+ end
187
+
188
+ report_error(device_klass.name, iface, 'trunk 接口配置不完全') unless ck
189
+ return ck
190
+ end
191
+
192
+ def puts_report
193
+ arr = []
194
+
195
+ @report.each_pair do |device_name, e|
196
+ tb = init_table(device_name)
197
+ e.each { |row| tb << row }
198
+ arr << tb
199
+ end
200
+
201
+ arr.join("\n")
202
+ end
203
+
204
+ def init_table(header)
205
+ col = ['接口', '错误配置信息']
206
+
207
+ table = Aio::Base::Toolkit::Table.new(
208
+ 'Header' => header,
209
+ 'Columns' => col,
210
+ 'Indent' => 4,
211
+ 'HeaderIndent' => 2
212
+ )
213
+
214
+ table.sort_index = -1
215
+ table
216
+ end
217
+ end
218
+
219
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aio_elin
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.4
4
+ version: 1.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-20 00:00:00.000000000 Z
11
+ date: 2019-03-21 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: 网络设备巡检工具
14
14
  email: 365433079@qq.com
@@ -113,9 +113,11 @@ files:
113
113
  - lib/modules/cmd/cisco/show_memory.rb
114
114
  - lib/modules/cmd/cisco/show_process_cpu.rb
115
115
  - lib/modules/cmd/cisco/show_process_memory.rb
116
+ - lib/modules/cmd/cisco/show_run.rb
116
117
  - lib/modules/cmd/cisco/show_version.rb
117
118
  - lib/modules/cmd/h3c/display_clock.rb
118
119
  - lib/modules/cmd/h3c/display_cpu.rb
120
+ - lib/modules/cmd/h3c/display_current.rb
119
121
  - lib/modules/cmd/h3c/display_device_manuinfo.rb
120
122
  - lib/modules/cmd/h3c/display_fan.rb
121
123
  - lib/modules/cmd/h3c/display_interface.rb
@@ -135,6 +137,7 @@ files:
135
137
  - lib/modules/cmd/maipu/show_ip_route_statistic.rb
136
138
  - lib/modules/cmd/maipu/show_memory.rb
137
139
  - lib/modules/cmd/maipu/show_system_fan.rb
140
+ - lib/modules/cmd/maipu/show_system_module_brief.rb
138
141
  - lib/modules/cmd/maipu/show_system_power.rb
139
142
  - lib/modules/cmd/maipu/show_version.rb
140
143
  - lib/modules/description/style/crc.rb
@@ -150,7 +153,7 @@ files:
150
153
  - lib/modules/input/style/console.rb
151
154
  - lib/modules/input/style/console.rb.bak
152
155
  - lib/modules/input/style/xinhua_nat.rb
153
- - lib/modules/output/style/boc_day.rb
156
+ - lib/modules/output/style/citic.rb
154
157
  - lib/modules/output/style/cmds.rb
155
158
  - lib/modules/output/style/compare_diff.rb
156
159
  - lib/modules/output/style/compare_json.rb
@@ -1,223 +0,0 @@
1
- #coding=utf-8
2
-
3
- require "aio/core"
4
-
5
- class Aio::Module::OutputStyle::BocDay < Aio::Module::OutputStyle
6
- include Aio::Ui::Verbose
7
-
8
- def initialize
9
- super({
10
- :author => "Elin",
11
- :description => "这个模块是中行每天日常早间巡检输出表格",
12
- :file_suffix => "txt",
13
- })
14
- end
15
-
16
- def generate
17
- file = File.new(output_file, "w+")
18
- $stdout = file
19
-
20
-
21
- tables = {}
22
- init(tables, "1#网省行地市骨干及地市下联")
23
- tables["1#网省行地市骨干及地市下联"][:row] = [
24
- ["地市联通7606", "A_HBWHC_WBN_DR"],
25
- ["地市电信7606", "A_HBWHA_WBN_DR"],
26
- ["地市电信H3C 8808", "A_HBWHA_MAN_DR"],
27
- ]
28
-
29
- init(tables, "2#网省行地市骨干及地市下联")
30
- tables["2#网省行地市骨干及地市下联"][:row] = [
31
- ["地市联通7606", "B_HBWHC_WBN_DR"],
32
- ["地市电信7606", "B_HBWHA_WBN_DR"],
33
- ["地市电信H3C 8808", "B_HBWHA_MAN_DR"],
34
- ]
35
-
36
- init(tables, "1#省行核心设备")
37
- tables["1#省行核心设备"][:row] = [
38
- ["核心-1", "A_HBWHA_COR_CS01"],
39
- ["核心-2", "A_HBWHA_COR_CS02"],
40
- ["楼层汇聚-1", "A_HBWHB_CAM_DS01"],
41
- ["楼层汇聚-2", "A_HBWHB_CAM_DS02"],
42
- ]
43
-
44
- init(tables, "2#省行核心设备")
45
- tables["2#省行核心设备"][:row] = [
46
- ["澳门路4507R-1", "B_HBWHA_CAM_DS01"],
47
- ["澳门路4507R-2", "B_HBWHA_CAM_DS02"],
48
- ["6506-1", "B_HBWHA_COR_CS01"],
49
- ["6506-2", "B_HBWHA_COR_CS02"],
50
- ["同城7206-联通", "B_HBWHC_WBN_DR"],
51
- ["同城7206-电信", "B_HBWHA_WBN_DR"],
52
- ]
53
-
54
- init(tables, "2#广电4507")
55
- tables["2#广电4507"][:row] = [
56
- ["广电4507-1", "B_HBWHB_CAM_DS01"],
57
- ["广电4507-2", "B_HBWHB_CAM_DS02"],
58
- ]
59
-
60
- init(tables, "1#网地市上联路由器")
61
- tables["1#网地市上联路由器"][:row] = [
62
- ["鄂州1", "A_HBEZA_WBN_AR01"],
63
- ["鄂州2", "A_HBEZA_WBN_AR02"],
64
- ["恩施1", "A_HBESA_WBN_AR01"],
65
- ["恩施2", "A_HBESA_WBN_AR02"],
66
- ["黄冈1", "A_HBHGA_WBN_AR01"],
67
- ["黄冈2", "A_HBHGA_WBN_AR02"],
68
- ["黄石1", "A_HBHSA_WBN_AR01"],
69
- ["黄石2", "A_HBHSA_WBN_AR02"],
70
- ["荆门1", "A_HBJMA_WBN_AR01"],
71
- ["荆门2", "A_HBJMA_WBN_AR02"],
72
- ["荆州1", "A_HBJZA_WBN_AR01"],
73
- ["荆州2", "A_HBJZA_WBN_AR02"],
74
- ["潜江1", "A_HBQJA_WBN_AR01"],
75
- ["潜江2", "A_HBQJA_WBN_AR02"],
76
- ["三峡1", "A_HBSXA_WBN_AR01"],
77
- ["三峡2", "A_HBSXA_WBN_AR02"],
78
- ["十堰1", "A_HBSYA_WBN_AR01"],
79
- ["十堰2", "A_HBSYA_WBN_AR02"],
80
- ["随州1", "A_HBSZA_WBN_AR01"],
81
- ["随州2", "A_HBSZA_WBN_AR02"],
82
- ["天门1", "A_HBTMA_WBN_AR01"],
83
- ["天门2", "A_HBTMA_WBN_AR02"],
84
- ["仙桃1", "A_HBXTA_WBN_AR01"],
85
- ["仙桃2", "A_HBXTA_WBN_AR02"],
86
- ["咸宁1", "A_HBXNA_WBN_AR01"],
87
- ["咸宁2", "A_HBXNA_WBN_AR02"],
88
- ["襄樊1", "A_HBXFA_WBN_AR01"],
89
- ["襄樊2", "A_HBXFA_WBN_AR02"],
90
- ["孝感1", "A_HBXGA_WBN_AR01"],
91
- ["孝感2", "A_HBXGA_WBN_AR02"],
92
- ]
93
-
94
- init(tables, "2#网地市上联路由器")
95
- tables["2#网地市上联路由器"][:row] = [
96
- ["鄂州1", "B_HBEZA_WBN_AR01"],
97
- ["鄂州2", "B_HBEZA_WBN_AR02"],
98
- ["恩施1", "B_HBESA_WBN_AR01"],
99
- ["恩施2", "B_HBESA_WBN_AR02"],
100
- ["黄冈1", "B_HBHGA_WBN_AR01"],
101
- ["黄冈2", "B_HBHGA_WBN_AR02"],
102
- ["黄石1", "B_HBHSA_WBN_AR01"],
103
- ["黄石2", "B_HBHSA_WBN_AR02"],
104
- ["荆门1", "B_HBJMA_WBN_AR01"],
105
- ["荆门2", "B_HBJMA_WBN_AR02"],
106
- ["荆州1", "B_HBJZA_WBN_AR01"],
107
- ["荆州2", "B_HBJZA_WBN_AR02"],
108
- ["潜江1", "B_HBQJA_WBN_AR01"],
109
- ["潜江2", "B_HBQJA_WBN_AR02"],
110
- ["三峡1", "B_HBSXA_WBN_AR01"],
111
- ["三峡2", "B_HBSXA_WBN_AR02"],
112
- ["十堰1", "B_HBSYA_WBN_AR01"],
113
- ["十堰2", "B_HBSYA_WBN_AR02"],
114
- ["随州1", "B_HBSZA_WBN_AR01"],
115
- ["随州2", "B_HBSZA_WBN_AR02"],
116
- ["天门1", "B_HBTMA_WBN_AR01"],
117
- ["天门2", "B_HBTMA_WBN_AR02"],
118
- ["仙桃1", "B_HBXTA_WBN_AR01"],
119
- ["仙桃2", "B_HBXTA_WBN_AR02"],
120
- ["咸宁1", "B_HBXNA_WBN_AR01"],
121
- ["咸宁2", "B_HBXNA_WBN_AR02"],
122
- ["襄樊1", "B_HBXFA_WBN_AR01"],
123
- ["襄樊2", "B_HBXFA_WBN_AR02"],
124
- ["孝感1", "B_HBXGA_WBN_AR01"],
125
- ["孝感2", "B_HBXGA_WBN_AR02"],
126
- ]
127
-
128
- tidy_tables(tables)
129
-
130
- res = %Q^
131
-
132
- #{tables["1#网省行地市骨干及地市下联"][:klass].to_s}
133
-
134
- #{tables["2#网省行地市骨干及地市下联"][:klass].to_s}
135
-
136
- #{tables["1#省行核心设备"][:klass].to_s}
137
-
138
- #{tables["2#省行核心设备"][:klass].to_s}
139
-
140
- #{tables["2#广电4507"][:klass].to_s}
141
-
142
- #{tables["1#网地市上联路由器"][:klass].to_s}
143
-
144
- #{tables["2#网地市上联路由器"][:klass].to_s}
145
-
146
- ^
147
- file.write(res)
148
- $stdout = STDOUT
149
-
150
- end
151
-
152
- def tidy_tables(tables)
153
- tables.each_pair do |desc, info|
154
- klass = info[:klass]
155
- info[:row].each do |row|
156
- device_name = row[1]
157
-
158
- # 当没有这个设备的时候,还是正常输出
159
- if device_manager[device_name].nil?
160
- row << ""
161
- row << ""
162
- row << ""
163
- next
164
- end
165
-
166
- output_warning(device_name)
167
-
168
- type = device_manager[device_name].device_info[:device_model]
169
- cpu = device_manager[device_name].cpu_percent + "%"
170
- mem = device_manager[device_name].memory_percent + "%"
171
-
172
- row << (type.nil? ? "" : type)
173
- row << (cpu.nil? ? "" : cpu)
174
- row << (mem.nil? ? "" : mem)
175
-
176
- klass << row
177
- end
178
- end
179
- end
180
-
181
- # 初始化tables
182
- def init(tables, name)
183
- tables[name] = {}
184
- tables[name][:row] = []
185
- tables[name][:klass] = table_main(name)
186
- end
187
-
188
- def table_main(header = "")
189
- col = ["设备用处", "设备名", "设备型号", "CPU(%)", "Memory(%)"]
190
- table = Aio::Base::Toolkit::Table.new(
191
- 'Header' => header,
192
- 'HeaderIndent' => 2,
193
- 'Columns' => col,
194
- #'CellPad' => 10,
195
- 'Indent' => 4)
196
- end
197
-
198
- def output_warning(device_name)
199
- dn = device_manager[device_name]
200
-
201
- if dn.has_warning?
202
- print_error device_name
203
-
204
- if dn.has_warning_serious?
205
- print_error " 严重的警告信息"
206
- dn.warning_info_serious.each_pair { |k, v| print_error " #{k} 出现的次数: #{v.size}" }
207
- end
208
-
209
- if dn.has_warning_ordinary?
210
- print_error " 普通的警告信息"
211
- dn.warning_info_ordinary.each_pair { |k, v| print_error " #{k} 出现的次数: #{v.size}" }
212
- end
213
-
214
- if dn.has_warning_compare?
215
- print_error " 对比的警告信息"
216
- dn.warning_info_compare.each_pair { |k, v| print_error " #{k} => "; pp v }
217
- end
218
-
219
- end
220
- end
221
-
222
- end
223
-