Class: Dogapi::V1::ServiceLevelObjectiveService

Inherits:
APIService
  • Object
show all
Defined in:
lib/dogapi/v1/service_level_objective.rb

Overview

Implements Service Level Objectives endpoints

Constant Summary collapse

API_VERSION =
'v1'

Instance Attribute Summary

Attributes inherited from APIService

#api_key, #application_key

Instance Method Summary collapse

Methods inherited from APIService

#connect, #handle_redirect, #handle_response, #initialize, #prepare_params, #prepare_request, #request, #should_set_api_and_app_keys_in_params?, #suppress_error_if_silent

Constructor Details

This class inherits a constructor from Dogapi::APIService

Instance Method Details

#can_delete_service_level_objective(slo_ids) ⇒ Object


103
104
105
106
107
108
109
110
111
# File 'lib/dogapi/v1/service_level_objective.rb', line 103

def can_delete_service_level_objective(slo_ids)
  params = {}
  params[:ids] = if slo_ids.is_a? Array
                   slo_ids.join(',')
                 else
                   slo_ids
                 end
  request(Net::HTTP::Get, "/api/#{API_VERSION}/slo/can_delete", params, nil, false)
end

#create_service_level_objective(type, slo_name, thresholds, options = {}) ⇒ Object


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/dogapi/v1/service_level_objective.rb', line 13

def create_service_level_objective(type, slo_name, thresholds, options = {})
  body = {
    type: type,
    name: slo_name,
    thresholds: thresholds
  }

  symbolized_options = Dogapi.symbolized_access(options)
  if type.to_s == 'metric'
    body[:query] = {
      numerator: symbolized_options[:numerator],
      denominator: symbolized_options[:denominator]
    }
  else
    body[:monitor_search] = symbolized_options[:monitor_search] if symbolized_options[:monitor_search]
    body[:monitor_ids] = symbolized_options[:monitor_ids] if symbolized_options[:monitor_ids]
    body[:groups] = symbolized_options[:groups] if symbolized_options[:groups]
  end
  body[:tags] = symbolized_options[:tags] if symbolized_options[:tags]
  body[:description] = symbolized_options[:description] if symbolized_options[:description]

  request(Net::HTTP::Post, "/api/#{API_VERSION}/slo", nil, body, true)
end

#delete_many_service_level_objective(slo_ids) ⇒ Object


83
84
85
86
87
88
# File 'lib/dogapi/v1/service_level_objective.rb', line 83

def delete_many_service_level_objective(slo_ids)
  body = {
    ids: slo_ids
  }
  request(Net::HTTP::Delete, "/api/#{API_VERSION}/slo/", nil, body, true)
end

#delete_service_level_objective(slo_id) ⇒ Object


79
80
81
# File 'lib/dogapi/v1/service_level_objective.rb', line 79

def delete_service_level_objective(slo_id)
  request(Net::HTTP::Delete, "/api/#{API_VERSION}/slo/#{slo_id}", nil, nil, false)
end

#delete_timeframes_service_level_objective(ops) ⇒ Object


90
91
92
93
# File 'lib/dogapi/v1/service_level_objective.rb', line 90

def delete_timeframes_service_level_objective(ops)
  # ops is a hash of slo_id: [<timeframe>] to delete
  request(Net::HTTP::Post, "/api/#{API_VERSION}/slo/bulk_delete", nil, ops, true)
end

#get_service_level_objective(slo_id) ⇒ Object


62
63
64
# File 'lib/dogapi/v1/service_level_objective.rb', line 62

def get_service_level_objective(slo_id)
  request(Net::HTTP::Get, "/api/#{API_VERSION}/slo/#{slo_id}", nil, nil, false)
end

#get_service_level_objective_history(slo_id, from_ts, to_ts) ⇒ Object


95
96
97
98
99
100
101
# File 'lib/dogapi/v1/service_level_objective.rb', line 95

def get_service_level_objective_history(slo_id, from_ts, to_ts)
  params = {
    from_ts: from_ts,
    to_ts: to_ts
  }
  request(Net::HTTP::Get, "/api/#{API_VERSION}/slo/#{slo_id}/history", params, nil, false)
end

#search_service_level_objective(slo_ids, query, offset, limit) ⇒ Object


66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/dogapi/v1/service_level_objective.rb', line 66

def search_service_level_objective(slo_ids, query, offset, limit)
  params = {}
  params[:offset] = offset unless offset.nil?
  params[:limit] = limit unless limit.nil?
  if !slo_ids.nil?
    params[:ids] = slo_ids.join(',')
  else
    params[:query] = query
  end

  request(Net::HTTP::Get, "/api/#{API_VERSION}/slo/", params, nil, false)
end

#update_service_level_objective(slo_id, type, options = {}) ⇒ Object


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/dogapi/v1/service_level_objective.rb', line 37

def update_service_level_objective(slo_id, type, options = {})
  body = {
    type: type
  }

  symbolized_options = Dogapi.symbolized_access(options)
  if type == 'metric'
    if symbolized_options[:numerator] && symbolized_options[:denominator]
      body[:query] = {
        numerator: symbolized_options[:numerator],
        denominator: symbolized_options[:denominator]
      }
    end
  else
    body[:monitor_search] = symbolized_options[:monitor_search] if symbolized_options[:monitor_search]
    body[:monitor_ids] = symbolized_options[:monitor_ids] if symbolized_options[:monitor_ids]
    body[:groups] = symbolized_options[:groups] if symbolized_options[:groups]
  end
  [:name, :thresholds, :tags, :description].each do |a|
    body[a] = symbolized_options[a] if symbolized_options[a]
  end

  request(Net::HTTP::Put, "/api/#{API_VERSION}/slo/#{slo_id}", nil, body, true)
end