Class: DogEventer::PingdomCheck

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, url, start_time) ⇒ PingdomCheck

Returns a new instance of PingdomCheck.



77
78
79
80
81
82
# File 'lib/dogeventer/event_emitter.rb', line 77

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

Instance Attribute Details

#urlObject (readonly)

Returns the value of attribute url.



75
76
77
# File 'lib/dogeventer/event_emitter.rb', line 75

def url
  @url
end

Instance Method Details

#alert_type(state) ⇒ Object



96
97
98
99
100
101
# File 'lib/dogeventer/event_emitter.rb', line 96

def alert_type(state)
  {
    :down => :error,
    :up   => :success
  }[state]
end

#date_happened(date = nil) ⇒ Object



103
104
105
# File 'lib/dogeventer/event_emitter.rb', line 103

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

#down(date = nil) ⇒ Object



123
124
125
# File 'lib/dogeventer/event_emitter.rb', line 123

def down(date=nil)
  to_event :down
end

#event_objectObject



88
89
90
# File 'lib/dogeventer/event_emitter.rb', line 88

def event_object()
  @check_name
end

#event_typeObject



92
93
94
# File 'lib/dogeventer/event_emitter.rb', line 92

def event_type()
  "monitoring.alert"
end

#msg_title(alert_state) ⇒ Object



84
85
86
# File 'lib/dogeventer/event_emitter.rb', line 84

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

#source_type_nameObject



107
108
109
# File 'lib/dogeventer/event_emitter.rb', line 107

def source_type_name()
  "Pingdom"
end

#to_event(alert_state, date = nil) ⇒ Object



111
112
113
114
115
116
117
118
119
120
121
# File 'lib/dogeventer/event_emitter.rb', line 111

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          => "Pingdom:#{@check_name}"
  }
end

#up(date = nil) ⇒ Object



126
127
128
# File 'lib/dogeventer/event_emitter.rb', line 126

def up(date=nil)
  to_event :up
end