Class: Aio::Module::InputStyle::XinhuaNat
- Inherits:
-
Aio::Module::InputStyle
- Object
- Aio::Module::InputStyle
- Aio::Module::InputStyle::XinhuaNat
- Includes:
- Aio::Module
- Defined in:
- lib/modules/input/style/xinhua_nat.rb
Constant Summary collapse
- Xinhua_Routing =
/^------------------------------------------------------------$/
Instance Attribute Summary
Attributes inherited from Aio::Module::InputStyle
#ext_info, #input_file, #input_info
Instance Method Summary collapse
-
#initialize ⇒ XinhuaNat
constructor
A new instance of XinhuaNat.
- #parse ⇒ Object
- #split(array, pattern) ⇒ Object
Methods inherited from Aio::Module::InputStyle
#author, #check_file, #description, #file_suffix, #file_suffix?, #license, #pass_file, #pass_file?, #platform, #set_defaults, #type
Constructor Details
#initialize ⇒ XinhuaNat
Returns a new instance of XinhuaNat.
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/modules/input/style/xinhua_nat.rb', line 10 def initialize super({ :author => "Elin", :description => "这个模块专门针对中行网络标准化管理NAT软件", :platform => "ausware", :file_suffix => Regexp.new('\.diag$'), :pass_file => [ Regexp.new('RoutingTable.*'), Regexp.new('路由状态'), ] }) end |
Instance Method Details
#parse ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/modules/input/style/xinhua_nat.rb', line 23 def parse # dir 为 Pathname 类 dir = self.input_file # 分析第一层: 文件夹名称包含设备名称+管理IP ::Dir.foreach(dir) do |device_layer| if device_layer.downcase == "." or device_layer.downcase == ".." next end tmp = [] device_layer.reverse.split('_', 2).each do |res| tmp << res.reverse end manager_ip = tmp[0] device_name = tmp[1] # 分析第二层:文件后缀为.diag,此外还有个HSRP文件夹,但是可有一次搞定 Find.find(File.join(dir, device_layer)) do |context_layer| # 如果文件后缀名不是.diag则跳过 if ! self.file_suffix?(context_layer) next end # 检查是否是需要略过的文件 if self.pass_file?(context_layer) next end fo = File.open(context_layer, "r+", :encoding => "utf-8") context = fo.each_line.to_a # 分割输出,在路由状态中会有这种情况 split(context, Xinhua_Routing).each do |cont| cmd = cont.shift.strip yield device_name, cmd, cont, manager_ip end end end end |
#split(array, pattern) ⇒ Object
67 68 69 |
# File 'lib/modules/input/style/xinhua_nat.rb', line 67 def split(array, pattern) Aio::Base::Toolkit::Array.split(array, pattern) end |