Class: MicroboshHacker::HealthMonitorConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/microbosh_hacker/health_monitor_config.rb

Constant Summary collapse

REQUIRED_OPTS =
%i{ email_recipients from host port domain}
OPTIONAL_OPTS =
%i{ auth user password interval}
AVAILABLE_OPTS =
REQUIRED_OPTS+ OPTIONAL_OPTS

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_path, opts = {}) ⇒ HealthMonitorConfig

Returns a new instance of HealthMonitorConfig.



10
11
12
13
14
15
16
17
18
# File 'lib/microbosh_hacker/health_monitor_config.rb', line 10

def initialize(config_path, opts = {})
  @config_path=config_path
  @opts=opts

  raise "Missing options: #{(REQUIRED_OPTS - @opts.keys).join(', ')}" unless (REQUIRED_OPTS - @opts.keys).empty?
  opts.each_pair do |k, v|
    raise "Nil or empty option: #{k}" if v.nil? || v.to_s.empty?
  end
end

Instance Attribute Details

#config_pathObject (readonly)

Returns the value of attribute config_path.



4
5
6
# File 'lib/microbosh_hacker/health_monitor_config.rb', line 4

def config_path
  @config_path
end

#optsObject (readonly)

Returns the value of attribute opts.



4
5
6
# File 'lib/microbosh_hacker/health_monitor_config.rb', line 4

def opts
  @opts
end

Instance Method Details

#to_yamlObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/microbosh_hacker/health_monitor_config.rb', line 20

def to_yaml
  config = ::YAML.load_file(config_path)
  config['plugins'].unshift(
    {
      'name' => 'email',
      'events' => [ 'alert' ],
      'options' => {
        'recipients' => opts[:email_recipients],
        'smtp' => {
          'from' => opts[:from],
          'host' => opts[:host],
          'port' => opts[:port],
          'domain' => opts[:domain]
        }
      }
    }
  )

    # auth: 'plain
    # user: user
    # password: pass123
    # interval:1
  config.to_yaml
end