Class: OpenObserve::Incidents

Inherits:
Resource
  • Object
show all
Defined in:
lib/openobserve/incidents.rb

Overview

Incidents — one firing episode of an alert, with its status and lifecycle.

Served by the v2 alerting API. The listing envelope carries both the page and a server-side total, so #total exposes the count without making the caller reach into the raw payload.

Every request goes through Resource#raw: the listing, the fetch, the stats and the update all declare a response type, which this domain cannot use.

Constant Summary

Constants inherited from Resource

Resource::AUTH

Instance Method Summary collapse

Methods inherited from Resource

#initialize

Constructor Details

This class inherits a constructor from OpenObserve::Resource

Instance Method Details

#get(id) ⇒ OpenObserve::Incident

Parameters:

  • id (String)

    incident id

Returns:

Raises:



29
30
31
# File 'lib/openobserve/incidents.rb', line 29

def get(id)
  Incident.from(one('incident') { raw(:GET, "#{incidents_path}/#{encode(id)}") })
end

#list(status: nil, limit: nil, offset: nil) ⇒ Array<OpenObserve::Incident>

Parameters:

  • status (String, nil) (defaults to: nil)

    restrict to a status (e.g. "firing", "resolved")

Returns:



15
16
17
18
# File 'lib/openobserve/incidents.rb', line 15

def list(status: nil, limit: nil, offset: nil)
  Array(envelope(status: status, limit: limit, offset: offset)['incidents'])
    .map { |incident| Incident.from(incident) }
end

#statsHash

Returns the aggregate counters OpenObserve reports for incidents.

Returns:

  • (Hash)

    the aggregate counters OpenObserve reports for incidents



34
35
36
# File 'lib/openobserve/incidents.rb', line 34

def stats
  collection { raw(:GET, "#{incidents_path}/stats") } || {}
end

#total(status: nil) ⇒ Integer?

The server-side count for the last listing, which is not the size of the page.

Returns:

  • (Integer, nil)


22
23
24
# File 'lib/openobserve/incidents.rb', line 22

def total(status: nil)
  envelope(status: status)['total']
end

#update(id, **attributes) ⇒ void

This method returns an undefined value.

Parameters:

  • id (String)

    incident id

  • attributes (Hash)

    fields to change (e.g. status:)



41
42
43
44
# File 'lib/openobserve/incidents.rb', line 41

def update(id, **attributes)
  call { raw(:PATCH, "#{incidents_path}/#{encode(id)}/update", body: attributes) }
  nil
end