Module: Mackerel::REST::Alert

Included in:
Client
Defined in:
lib/mackerel/alert.rb

Instance Method Summary collapse

Instance Method Details

#close_alert(alertId, reason) ⇒ Object



49
50
51
52
53
54
# File 'lib/mackerel/alert.rb', line 49

def close_alert(alertId, reason)
  command = ApiCommand.new(:post, "/api/v0/alerts/#{alertId}/close", @api_key)
  command.body = { reason: reason.to_s }.to_json
  data = command.execute(client)
  Mackerel::Alert.new(data)
end

#get_alert(alert_id) ⇒ Object



43
44
45
46
47
# File 'lib/mackerel/alert.rb', line 43

def get_alert(alert_id)
  command = ApiCommand.new(:get, "/api/v0/alerts/#{alert_id}", @api_key)
  data = command.execute(client)
  Mackerel::Alert.new(data)
end

#get_alerts(opts = {}) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/mackerel/alert.rb', line 34

def get_alerts(opts = {})
  command = ApiCommand.new(:get, "/api/v0/alerts", @api_key)
  command.params['withClosed'] = opts[:with_closed] if opts[:with_closed]
  command.params['nextId'] = opts[:next_id] if opts[:next_id]
  command.params['limit'] = opts[:limit] if opts[:limit]
  data = command.execute(client)
  data["alerts"].map { |a| Mackerel::Alert.new(a) }
end