Class: Monitoring::Client::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/monitoring/client/config.rb

Constant Summary collapse

DEFAULT_FILENAME =
"/usr/local/etc/monitoring-client.yml"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



18
19
20
21
22
# File 'lib/monitoring/client/config.rb', line 18

def initialize
  self.hostname = get_hostname
  self.hostgroup = nil
  load()
end

Instance Attribute Details

#hostgroupObject

Returns the value of attribute hostgroup.



16
17
18
# File 'lib/monitoring/client/config.rb', line 16

def hostgroup
  @hostgroup
end

#hostnameObject

Returns the value of attribute hostname.



16
17
18
# File 'lib/monitoring/client/config.rb', line 16

def hostname
  @hostname
end

Class Method Details

.globalObject



9
10
11
# File 'lib/monitoring/client/config.rb', line 9

def global
  @@global ||= Config.new
end

Instance Method Details

#get_hostnameObject



35
36
37
# File 'lib/monitoring/client/config.rb', line 35

def get_hostname
  %x(hostname).strip
end

#load(filename = DEFAULT_FILENAME) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/monitoring/client/config.rb', line 25

def load(filename = DEFAULT_FILENAME)
  c = YAML.load_file(filename)
  self.hostname = c[:hostname]
  self.hostgroup = c[:hostgroup]
  self
rescue Errno::ENOENT => e
  # Squelch missing file if default
  raise(e) unless filename == DEFAULT_FILENAME
end