Module: WarCorrespondent

Defined in:
lib/warcorrespondent.rb,
lib/warcorrespondent/uplink.rb,
lib/warcorrespondent/logging.rb,
lib/warcorrespondent/reporter.rb,
lib/warcorrespondent/installer.rb,
lib/warcorrespondent/reporters/cpu.rb,
lib/warcorrespondent/reporters/net.rb,
lib/warcorrespondent/reporters/users.rb,
lib/warcorrespondent/reporters/memory.rb,
lib/warcorrespondent/reporters/loadavg.rb

Defined Under Namespace

Modules: Installer, Logging, Reporters Classes: Reporter, Uplink, WLogger

Class Method Summary collapse

Class Method Details

.config_base_directoryObject



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

def self.config_base_directory
  [ '/etc/warcorrespondent', '~/.warcorrespondent'].each do |f|
    if File.exists?(File.expand_path(f))
      return File.expand_path(f)
    end
  end
  nil
end

.config_fileObject



19
20
21
# File 'lib/warcorrespondent.rb', line 19

def self.config_file
  config_base_directory+"/warcorrespondent.yml" if config_base_directory
end

.log_fileObject



27
28
29
# File 'lib/warcorrespondent.rb', line 27

def self.log_file
  '/var/log/warcorrespondent'
end

.register_reporter(reporter) ⇒ Object



69
70
71
72
# File 'lib/warcorrespondent.rb', line 69

def self.register_reporter(reporter)
  @@reporters ||= []
  @@reporters << reporter
end

.reporters_directoryObject



23
24
25
# File 'lib/warcorrespondent.rb', line 23

def self.reporters_directory
  config_base_directory+"/reporters" if config_base_directory
end

.runObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/warcorrespondent.rb', line 52

def self.run
  Logging::logger.info{'warcorrespondent starting up'}
  setup
  Logging::logger.debug "config loaded..."
  Thread.new do 
    @@uplink.run
  end
  @@reporters.each do |reporter|
    Thread.new do
      reporter.run
    end
  end
  loop do
    sleep 1
  end
end

.setupObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/warcorrespondent.rb', line 31

def self.setup
  @@reporters ||= []
  @@uplink = Uplink.new
  begin
    @@config = YAML.load_file(config_file)
    @@uplink.url = @@config['url']
    @@uplink.secret = @@config['secret']
  rescue
    Logging::logger.fatal "Could not load config file #{config_file}. Bailing out."
    exit
  end
  Dir.glob("#{reporters_directory}/*.rb").each do |i| 
    begin
      Logging::logger.info "including #{i}"
      require i 
    rescue
      Logging::logger.fatal "Parse error in #{i}. Bailing out."
    end
  end
end

.update(message) ⇒ Object



74
75
76
# File 'lib/warcorrespondent.rb', line 74

def self.update(message)
  @@uplink.add(message)
end