Class: DogEventer::NagiosCheck

Inherits:
EventEmitter show all
Defined in:
lib/dogeventer/event_emitter.rb

Instance Attribute Summary collapse

Attributes inherited from EventEmitter

#events

Instance Method Summary collapse

Methods inherited from EventEmitter

#wait

Constructor Details

#initialize(check_name, host, start_time) ⇒ NagiosCheck

Returns a new instance of NagiosCheck.



13
14
15
16
17
18
# File 'lib/dogeventer/event_emitter.rb', line 13

def initialize(check_name, host, start_time)
  @check_name = check_name
  @host = host
  @start_time = start_time
  @events = []
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



11
12
13
# File 'lib/dogeventer/event_emitter.rb', line 11

def host
  @host
end

Instance Method Details

#alert_type(state) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/dogeventer/event_emitter.rb', line 32

def alert_type(state)
  {
    :critical => :error,
    :ok       => :success,
    :warning  => :warning,
    :warn     => :warn
  }[state]
end

#critical(date = nil) ⇒ Object



61
62
63
# File 'lib/dogeventer/event_emitter.rb', line 61

def critical(date=nil)
  to_event :critical
end

#date_happened(date = nil) ⇒ Object



41
42
43
# File 'lib/dogeventer/event_emitter.rb', line 41

def date_happened(date=nil)
  (date || @start_time).to_i
end

#event_objectObject



24
25
26
# File 'lib/dogeventer/event_emitter.rb', line 24

def event_object()
  @check_name
end

#event_typeObject



28
29
30
# File 'lib/dogeventer/event_emitter.rb', line 28

def event_type()
  "monitoring.alert"
end

#msg_title(alert_state) ⇒ Object



20
21
22
# File 'lib/dogeventer/event_emitter.rb', line 20

def msg_title(alert_state)
  "#{@check_name} is #{alert_state.to_s} on #{@host}"
end

#ok(date = nil) ⇒ Object



69
70
71
# File 'lib/dogeventer/event_emitter.rb', line 69

def ok(date=nil)
  to_event :ok
end

#source_type_nameObject



45
46
47
# File 'lib/dogeventer/event_emitter.rb', line 45

def source_type_name()
  "Nagios"
end

#to_event(alert_state, date = nil) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/dogeventer/event_emitter.rb', line 49

def to_event(alert_state, date=nil)
  @events << {
    :event_object  => event_object,
    :event_type    => event_type,
    :alert_type    => alert_type(alert_state),
    :date_happened => date_happened(date),
    :msg_title     => msg_title(alert_state),
    :source_type_name => source_type_name,
    :host          => host
  }
end

#warning(date = nil) ⇒ Object



65
66
67
# File 'lib/dogeventer/event_emitter.rb', line 65

def warning(date=nil)
  to_event :warning
end