Class: Remon::Check

Inherits:
Object
  • Object
show all
Includes:
Logger
Defined in:
lib/remon/check.rb

Direct Known Subclasses

ProcCheck

Constant Summary collapse

WARNING =
"warning".freeze
CRITICAL =
"critical".freeze
OK =
"ok".freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logger

logger, #logger

Constructor Details

#initialize(*args, **kwargs, &block) ⇒ Check

Returns a new instance of Check.



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

def initialize(*args, **kwargs, &block)
  @tags = kwargs[:tags] || []
  @ttl = kwargs[:ttl] || 10
  @host = kwargs[:host] || Remon.host

  opts = kwargs[:opts] || {}
  verfiy_opts(opts)
  default_opts = self.class.get_opts
  @opts = default_opts.merge opts

  @mutex = Mutex.new
  return if not respond_to? :init

  # propagate only those kwargs which are defined in "init" method definition
  filtered_kwargs = filtered_kwargs(kwargs)

  #workaround a bug in ruby for methods that take 0 args
  if filtered_kwargs.empty?
    init(*args, &block) if respond_to? :init
  else
    init(*args, **filtered_kwargs, &block) if respond_to? :init
  end
end

Instance Attribute Details

#mutexObject (readonly)

Returns the value of attribute mutex.



25
26
27
# File 'lib/remon/check.rb', line 25

def mutex
  @mutex
end

#optsObject (readonly) Also known as: o

Returns the value of attribute opts.



25
26
27
# File 'lib/remon/check.rb', line 25

def opts
  @opts
end

Class Method Details

.get_optsObject



17
18
19
# File 'lib/remon/check.rb', line 17

def self.get_opts
  @opts ||= {}
end

.nameObject



5
6
7
# File 'lib/remon/check.rb', line 5

def self.name
  @name || "undefined"
end

.name=(name) ⇒ Object



9
10
11
# File 'lib/remon/check.rb', line 9

def self.name=(name)
  @name = name
end

.opts(h) ⇒ Object



13
14
15
# File 'lib/remon/check.rb', line 13

def self.opts(h)
  @opts = h
end

Instance Method Details

#check_nameObject



61
62
63
# File 'lib/remon/check.rb', line 61

def check_name
  self.class.name
end

#runObject



53
54
55
# File 'lib/remon/check.rb', line 53

def run
  raise NotImplementedError.new "run method not implemented"
end

#run_mutexObject



57
58
59
# File 'lib/remon/check.rb', line 57

def run_mutex
  synchronize { run }
end

#to_sObject



65
66
67
# File 'lib/remon/check.rb', line 65

def to_s
  "<check:#{check_name}>"
end