Class: AxeConfig

Inherits:
Hash
  • Object
show all
Defined in:
lib/myaxes/axeconfig.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ AxeConfig

Returns a new instance of AxeConfig.



7
8
9
10
11
# File 'lib/myaxes/axeconfig.rb', line 7

def initialize(options)
  @config = Hash.new
  @options = options
  @targets = Hash.new
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



5
6
7
# File 'lib/myaxes/axeconfig.rb', line 5

def config
  @config
end

#targetsObject (readonly)

Returns the value of attribute targets.



5
6
7
# File 'lib/myaxes/axeconfig.rb', line 5

def targets
  @targets
end

Instance Method Details

#read(config) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/myaxes/axeconfig.rb', line 13

def read(config)
  user = @options['user']
  ip = @options['ip']
  #password = @options['password']
  group = @options['group']

  puts "Configfile (#{config}) not found" unless File.readable?(config)

  begin
    @config = YAML.load_file(config)
  rescue Exception => errmsg
    puts "Configfile format error: #{errmsg}"
  end

  @config['Targets'].each_key do |target|
    if @config['Targets'][target]['query'].include? group
      @config['Targets'][target]['query'][group].each do |query|
        query.to_s.gsub!('{ip}', ip).gsub!('{user}', user)
      end
      @targets["#{@config['Targets'][target]['hostname']}"] = @config['Targets'][target]['query'][group]
    end
  end

  self.config
end