Class: OpenObserve::Destinations
- Includes:
- DirectorySource
- Defined in:
- lib/openobserve/destinations.rb
Overview
Alert destinations — where a firing alert is sent (webhook, e-mail, SNS).
Served by the v1 alerting API even though alert CRUD moved to v2; see Alerts for that split.
Every request goes through Resource#raw. That retires the generated
ListDestinations200ResponseInner, which the generator pressed into service as both the
response type of the listing and the write parameter of every mutation — accepting
only the thirteen attributes the checked-in spec declares, and raising ArgumentError
on any other.
Constant Summary collapse
- DEFAULT_PATTERN =
Glob applied inside a #sync directory.
'*.json'
Constants inherited from Resource
Instance Method Summary collapse
- #create(**attributes) ⇒ OpenObserve::Destination
- #delete(name) ⇒ void
- #get(name) ⇒ OpenObserve::Destination
- #list(module_name: nil) ⇒ Array<OpenObserve::Destination>
-
#sync(directory, pattern: DEFAULT_PATTERN) ⇒ Hash{Symbol=>Array<String>}
Bring the destinations of a directory into OpenObserve, matching on
name. - #update(name, **attributes) ⇒ OpenObserve::Destination
Methods included from DirectorySource
Methods inherited from Resource
Constructor Details
This class inherits a constructor from OpenObserve::Resource
Instance Method Details
#create(**attributes) ⇒ OpenObserve::Destination
39 40 41 |
# File 'lib/openobserve/destinations.rb', line 39 def create(**attributes) Destination.from(call { raw(:POST, destinations_path, body: attributes) }) end |
#delete(name) ⇒ void
This method returns an undefined value.
52 53 54 55 |
# File 'lib/openobserve/destinations.rb', line 52 def delete(name) call { raw(:DELETE, "#{destinations_path}/#{encode(name)}") } nil end |
#get(name) ⇒ OpenObserve::Destination
31 32 33 34 35 |
# File 'lib/openobserve/destinations.rb', line 31 def get(name) Destination.from( one('destination') { raw(:GET, "#{destinations_path}/#{encode(name)}") } ) end |
#list(module_name: nil) ⇒ Array<OpenObserve::Destination>
22 23 24 25 26 |
# File 'lib/openobserve/destinations.rb', line 22 def list(module_name: nil) payload = collection { raw(:GET, destinations_path, query: { 'module' => module_name }) } Array(payload).map { |destination| Destination.from(destination) } end |
#sync(directory, pattern: DEFAULT_PATTERN) ⇒ Hash{Symbol=>Array<String>}
Bring the destinations of a directory into OpenObserve, matching on name.
Creates what is missing and overwrites what is there; nothing is deleted, since an alert this run does not know about may still notify through it.
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/openobserve/destinations.rb', line 70 def sync(directory, pattern: DEFAULT_PATTERN) known = list.filter_map { |destination| destination['name'] }.to_set result = { created: [], updated: [] } read_definitions(directory, pattern, 'name').each do |name, definition| exists = known.include?(name) result[exists ? :updated : :created] << name exists ? update(name, **definition) : create(**definition) end result end |
#update(name, **attributes) ⇒ OpenObserve::Destination
46 47 48 |
# File 'lib/openobserve/destinations.rb', line 46 def update(name, **attributes) Destination.from(call { raw(:PUT, "#{destinations_path}/#{encode(name)}", body: attributes) }) end |