Module: Nagios

Defined in:
lib/nagios.rb,
lib/generators/nagios/check_generator.rb,
lib/generators/nagios/check_em_generator.rb

Defined Under Namespace

Classes: Check, CheckEM, CheckEmGenerator, CheckGenerator, Runner, RunnerAsync

Constant Summary collapse

OK =
0
WARN =
1
CRIT =
2
OTHER =
3
CONCURRENCY_LEVEL =

for server

25
STATUS_NAMES =
{
  OK => 'OK',
  WARN => 'WARN',
  CRIT => 'CRIT',
  OTHER => 'OTHER'
}

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.project_initializer_loadedObject

Returns the value of attribute project_initializer_loaded.



33
34
35
# File 'lib/nagios.rb', line 33

def project_initializer_loaded
  @project_initializer_loaded
end

Class Method Details

.all_classesObject



99
100
101
102
103
104
105
106
107
108
109
# File 'lib/nagios.rb', line 99

def all_classes
  classes = []

  Nagios.constants.each do |const|
    kl = eval "Nagios::#{const}"
    anc = kl.ancestors rescue []
    classes << kl if anc.include?(Nagios::Check) && kl != Nagios::Check && kl != Nagios::CheckEM
  end

  classes
end

.concurrency_levelObject



35
36
37
# File 'lib/nagios.rb', line 35

def concurrency_level
  @concurrency_level
end

.concurrency_level=(cl) ⇒ Object



43
44
45
46
# File 'lib/nagios.rb', line 43

def concurrency_level=(cl)
  @concurrency_level = cl
  EM.threadpool_size = cl
end

.load_allObject



91
92
93
94
95
96
97
# File 'lib/nagios.rb', line 91

def load_all
  load_initializers

  Dir[root + "/**/*.rb"].each do |file|
    require file
  end
end

.load_initializersObject



76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/nagios.rb', line 76

def load_initializers
  mutex.lock

  unless project_initializer_loaded
    Dir[root + "/initializers/*.rb"].each do |file|
      require File.expand_path(file)
    end

    project_initializer_loaded = true
  end

ensure
  mutex.unlock
end

.loggerObject



27
28
29
30
31
# File 'lib/nagios.rb', line 27

def logger
  @logger ||= Logger.new(File.join(rails_root, "/log/nagios.log")).tap do |logger|
    logger.formatter = lambda { |s, d, p, m| "#{d.strftime("%d.%m.%Y %H:%M:%S")} #{m}\n" }
  end
end

.mutexObject



39
40
41
# File 'lib/nagios.rb', line 39

def mutex
  @mutex ||= Mutex.new
end

.rails_rootObject



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/nagios.rb', line 52

def rails_root
  @rails_root ||= begin
    if defined?(RAILS_ROOT)
      RAILS_ROOT
    elsif defined?(Rails)
      Rails.root
    elsif defined?(Application)
      Application.root
    end
  end
end

.rails_root=(rails_root) ⇒ Object



64
65
66
# File 'lib/nagios.rb', line 64

def rails_root=(rails_root)
  @rails_root = rails_root
end

.rootObject



68
69
70
# File 'lib/nagios.rb', line 68

def root
  @root ||= File.join(rails_root, %w{ app nagios })
end

.root=(root) ⇒ Object



72
73
74
# File 'lib/nagios.rb', line 72

def root=(root)
  @root = root
end

.status_name(status) ⇒ Object



48
49
50
# File 'lib/nagios.rb', line 48

def status_name(status)
  ":#{ STATUS_NAMES[status] || 'unknown' }"
end

.url(method) ⇒ Object



111
112
113
# File 'lib/nagios.rb', line 111

def url(method)
  "http://localhost:3000/nagios/check?method=#{method}"
end