Class: PagerDuty::Incident

Inherits:
Report::Item show all
Defined in:
lib/pagerduty_tools/pagerduty.rb

Instance Attribute Summary collapse

Attributes inherited from Report::Item

#time

Instance Method Summary collapse

Methods inherited from Report::Item

#between?, #graveyard?, #off_hours?

Constructor Details

#initialize(incident) ⇒ Incident

Returns a new instance of Incident.



210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/pagerduty_tools/pagerduty.rb', line 210

def initialize(incident)
  super(Time.xmlschema(incident['created_on']))
  @status  = incident['status']
  @service = incident['service']['name']
  @trigger = incident['trigger_details']
  @event   = incident['trigger_details']['event']

  if status == 'resolved'
    if incident['resolved_by'].nil? # nil resolvers are automatic, e.g. Nagios
      @resolver = "[Automatic]"
    else
      @resolver = incident['resolved_by']['name']
    end
  end
end

Instance Attribute Details

#eventObject

Returns the value of attribute event.



208
209
210
# File 'lib/pagerduty_tools/pagerduty.rb', line 208

def event
  @event
end

#resolverObject

Returns the value of attribute resolver.



208
209
210
# File 'lib/pagerduty_tools/pagerduty.rb', line 208

def resolver
  @resolver
end

#serviceObject

Returns the value of attribute service.



208
209
210
# File 'lib/pagerduty_tools/pagerduty.rb', line 208

def service
  @service
end

#statusObject

Returns the value of attribute status.



208
209
210
# File 'lib/pagerduty_tools/pagerduty.rb', line 208

def status
  @status
end

#triggerObject

Returns the value of attribute trigger.



208
209
210
# File 'lib/pagerduty_tools/pagerduty.rb', line 208

def trigger
  @trigger
end

Instance Method Details

#resolved?Boolean

Returns:

  • (Boolean)


226
227
228
# File 'lib/pagerduty_tools/pagerduty.rb', line 226

def resolved?
  status == 'resolved'
end

#trigger_nameObject



230
231
232
233
234
235
236
# File 'lib/pagerduty_tools/pagerduty.rb', line 230

def trigger_name
  if trigger['type'] == 'nagios_trigger'
    return "#{service}: #{event['host']} - #{event['service']}"
  else
    return "#{service}: #{event['description']}"
  end
end