Class: Dogapi::V1::MonitorService

Inherits:
APIService show all
Defined in:
lib/dogapi/v1/monitor.rb

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_monitors(monitor_ids) ⇒ Object



45
46
47
48
49
50
51
52
53
54
# File 'lib/dogapi/v1/monitor.rb', line 45

def can_delete_monitors(monitor_ids)
  extra_params =
    if monitor_ids.respond_to?(:join)
      { "monitor_ids" => monitor_ids.join(",") }
    else
      { "monitor_ids" => monitor_ids }
    end

  request(Net::HTTP::Get, "/api/#{API_VERSION}/monitor/can_delete", extra_params, nil, false)
end

#cancel_downtime(downtime_id) ⇒ Object



140
141
142
# File 'lib/dogapi/v1/monitor.rb', line 140

def cancel_downtime(downtime_id)
  request(Net::HTTP::Delete, "/api/#{API_VERSION}/downtime/#{downtime_id}", nil, nil, false)
end

#cancel_downtime_by_scope(scope) ⇒ Object



144
145
146
# File 'lib/dogapi/v1/monitor.rb', line 144

def cancel_downtime_by_scope(scope)
  request(Net::HTTP::Post, "/api/#{API_VERSION}/downtime/cancel/by_scope", nil, { 'scope' => scope }, true)
end

#delete_monitor(monitor_id, options = {}) ⇒ Object



56
57
58
# File 'lib/dogapi/v1/monitor.rb', line 56

def delete_monitor(monitor_id, options = {})
  request(Net::HTTP::Delete, "/api/#{API_VERSION}/monitor/#{monitor_id}", options, nil, false)
end

#get_all_downtimes(options = {}) ⇒ Object



148
149
150
# File 'lib/dogapi/v1/monitor.rb', line 148

def get_all_downtimes(options = {})
  request(Net::HTTP::Get, "/api/#{API_VERSION}/downtime", options, nil, false)
end

#get_all_monitors(options = {}) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/dogapi/v1/monitor.rb', line 60

def get_all_monitors(options = {})
  extra_params = options.clone
  # :group_states is an optional list of statuses to filter returned
  # groups. If no value is given then no group states will be returned.
  # Possible values are: "all", "ok", "warn", "alert", "no data".
  if extra_params[:group_states].respond_to?(:join)
    extra_params[:group_states] = extra_params[:group_states].join(',')
  end

  # :tags is an optional list of scope tags to filter the list of monitors
  # returned. If no value is given, then all monitors, regardless of
  # scope, will be returned.
  extra_params[:tags] = extra_params[:tags].join(',') if extra_params[:tags].respond_to?(:join)

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

#get_downtime(downtime_id, options = {}) ⇒ Object



136
137
138
# File 'lib/dogapi/v1/monitor.rb', line 136

def get_downtime(downtime_id, options = {})
  request(Net::HTTP::Get, "/api/#{API_VERSION}/downtime/#{downtime_id}", options, nil, false)
end

#get_monitor(monitor_id, options = {}) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/dogapi/v1/monitor.rb', line 32

def get_monitor(monitor_id, options = {})
  extra_params = options.clone
  # :group_states is an optional list of statuses to filter returned
  # groups. If no value is given then no group states will be returned.
  # Possible values are: "all", "ok", "warn", "alert", "no data".

  if extra_params[:group_states].respond_to?(:join)
    extra_params[:group_states] = extra_params[:group_states].join(',')
  end

  request(Net::HTTP::Get, "/api/#{API_VERSION}/monitor/#{monitor_id}", extra_params, nil, false)
end

#monitor(type, query, options = {}) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/dogapi/v1/monitor.rb', line 10

def monitor(type, query, options = {})
  body = {
    'type' => type,
    'query' => query,
  }.merge options

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

#mute_host(hostname, options = {}) ⇒ Object

HOST MUTING



155
156
157
# File 'lib/dogapi/v1/monitor.rb', line 155

def mute_host(hostname, options = {})
  request(Net::HTTP::Post, "/api/#{API_VERSION}/host/#{hostname}/mute", nil, options, true)
end

#mute_monitor(monitor_id, options = {}) ⇒ Object



94
95
96
# File 'lib/dogapi/v1/monitor.rb', line 94

def mute_monitor(monitor_id, options = {})
  request(Net::HTTP::Post, "/api/#{API_VERSION}/monitor/#{monitor_id}/mute", nil, options, true)
end

#mute_monitorsObject



86
87
88
# File 'lib/dogapi/v1/monitor.rb', line 86

def mute_monitors
  request(Net::HTTP::Post, "/api/#{API_VERSION}/monitor/mute_all", nil, nil, false)
end

#resolve_monitors(monitor_groups = [], options = {}, version = nil) ⇒ Object



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

def resolve_monitors(monitor_groups = [], options = {}, version = nil)
  body = {
    'resolve' => monitor_groups
  }.merge options

  # Currently not part of v1 at this time but adding future compatibility option
  endpoint = version.nil? ? '/api/monitor/bulk_resolve' : "/api/#{version}/monitor/bulk_resolve"

  request(Net::HTTP::Post, endpoint, nil, body, true)
end

#schedule_downtime(scope, options = {}) ⇒ Object

DOWNTIMES



124
125
126
127
128
129
130
# File 'lib/dogapi/v1/monitor.rb', line 124

def schedule_downtime(scope, options = {})
  body = {
    'scope' => scope
  }.merge options

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

#search_monitor_groups(options = {}) ⇒ Object



117
118
119
# File 'lib/dogapi/v1/monitor.rb', line 117

def search_monitor_groups(options = {})
  request(Net::HTTP::Get, "/api/#{API_VERSION}/monitor/groups/search", options, nil, false)
end

#search_monitors(options = {}) ⇒ Object



113
114
115
# File 'lib/dogapi/v1/monitor.rb', line 113

def search_monitors(options = {})
  request(Net::HTTP::Get, "/api/#{API_VERSION}/monitor/search", options, nil, false)
end

#unmute_host(hostname) ⇒ Object



159
160
161
# File 'lib/dogapi/v1/monitor.rb', line 159

def unmute_host(hostname)
  request(Net::HTTP::Post, "/api/#{API_VERSION}/host/#{hostname}/unmute", nil, {}, true)
end

#unmute_monitor(monitor_id, options = {}) ⇒ Object



98
99
100
# File 'lib/dogapi/v1/monitor.rb', line 98

def unmute_monitor(monitor_id, options = {})
  request(Net::HTTP::Post, "/api/#{API_VERSION}/monitor/#{monitor_id}/unmute", nil, options, true)
end

#unmute_monitorsObject



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

def unmute_monitors
  request(Net::HTTP::Post, "/api/#{API_VERSION}/monitor/unmute_all", nil, nil, false)
end

#update_downtime(downtime_id, options = {}) ⇒ Object



132
133
134
# File 'lib/dogapi/v1/monitor.rb', line 132

def update_downtime(downtime_id, options = {})
  request(Net::HTTP::Put, "/api/#{API_VERSION}/downtime/#{downtime_id}", nil, options, true)
end

#update_monitor(monitor_id, query = nil, options = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/dogapi/v1/monitor.rb', line 19

def update_monitor(monitor_id, query = nil, options = {})
  body = {}.merge options
  unless query.nil?
    body = {
      'query' => query
    }.merge body
    warn '[DEPRECATION] query param is not required anymore and should be set to nil.'\
       ' To update the query, set it in the options parameter instead'
  end

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

#validate_monitor(type, query, options = {}) ⇒ Object



77
78
79
80
81
82
83
84
# File 'lib/dogapi/v1/monitor.rb', line 77

def validate_monitor(type, query, options = {})
  body = {
    'type' => type,
    'query' => query,
  }.merge options

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