flapjack-diner 2.0.0b1 → 2.0.0.pre.alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +21 -0
- data/.rubocop_todo.yml +135 -0
- data/.travis.yml +10 -5
- data/README.md +125 -143
- data/flapjack-diner.gemspec +1 -1
- data/lib/flapjack-diner.rb +24 -54
- data/lib/flapjack-diner/argument_validator.rb +17 -0
- data/lib/flapjack-diner/resources/checks.rb +52 -0
- data/lib/flapjack-diner/resources/contacts.rb +54 -0
- data/lib/flapjack-diner/resources/events.rb +54 -0
- data/lib/flapjack-diner/resources/maintenance_periods.rb +76 -0
- data/lib/flapjack-diner/resources/media.rb +75 -0
- data/lib/flapjack-diner/resources/metrics.rb +23 -0
- data/lib/flapjack-diner/resources/relationships.rb +275 -0
- data/lib/flapjack-diner/resources/rules.rb +75 -0
- data/lib/flapjack-diner/resources/states.rb +24 -0
- data/lib/flapjack-diner/resources/statistics.rb +24 -0
- data/lib/flapjack-diner/resources/tags.rb +47 -0
- data/lib/flapjack-diner/tools.rb +456 -46
- data/lib/flapjack-diner/version.rb +1 -1
- data/spec/flapjack-diner_spec.rb +18 -9
- data/spec/resources/checks_spec.rb +7 -7
- data/spec/resources/contacts_spec.rb +12 -14
- data/spec/resources/events_spec.rb +13 -13
- data/spec/resources/maintenance_periods_spec.rb +3 -3
- data/spec/resources/media_spec.rb +3 -3
- data/spec/resources/metrics_spec.rb +1 -1
- data/spec/{relationships_spec.rb → resources/relationships_spec.rb} +25 -71
- data/spec/resources/rules_spec.rb +62 -62
- data/spec/resources/states_spec.rb +1 -1
- data/spec/resources/statistics_spec.rb +1 -1
- data/spec/resources/tags_spec.rb +19 -75
- data/spec/support/fixture_data.rb +43 -80
- metadata +22 -17
- data/lib/flapjack-diner/configuration.rb +0 -417
- data/lib/flapjack-diner/log_formatter.rb +0 -22
- data/lib/flapjack-diner/query.rb +0 -114
- data/lib/flapjack-diner/relationships.rb +0 -180
- data/lib/flapjack-diner/request.rb +0 -280
- data/lib/flapjack-diner/resources.rb +0 -64
- data/lib/flapjack-diner/response.rb +0 -91
- data/lib/flapjack-diner/utility.rb +0 -16
data/flapjack-diner.gemspec
CHANGED
data/lib/flapjack-diner.rb
CHANGED
@@ -1,75 +1,45 @@
|
|
1
1
|
require 'httparty'
|
2
2
|
require 'json'
|
3
3
|
|
4
|
-
require 'flapjack-diner/log_formatter'
|
5
4
|
require 'flapjack-diner/version'
|
6
5
|
require 'flapjack-diner/argument_validator'
|
7
|
-
require 'flapjack-diner/index_range'
|
8
6
|
|
9
|
-
|
10
|
-
|
11
|
-
require
|
12
|
-
|
13
|
-
# HTTParty master contains a non-hacky way of doing this, but 0.13.5 doesn't
|
14
|
-
module HTTParty
|
15
|
-
module Logger
|
16
|
-
def self.build(logger, level, formatter)
|
17
|
-
level ||= :info
|
18
|
-
formatter ||= :apache
|
19
|
-
|
20
|
-
case formatter
|
21
|
-
when :'flapjack-diner'
|
22
|
-
Flapjack::Diner::LogFormatter.new(logger, level)
|
23
|
-
when :curl
|
24
|
-
Logger::CurlLogger.new(logger, level)
|
25
|
-
else
|
26
|
-
Logger::ApacheLogger.new(logger, level)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
7
|
+
%w(checks contacts events maintenance_periods media metrics rules
|
8
|
+
states statistics tags relationships).each do |resource|
|
9
|
+
require "flapjack-diner/resources/#{resource}"
|
30
10
|
end
|
31
11
|
|
12
|
+
require 'flapjack-diner/tools'
|
13
|
+
|
32
14
|
# NB: clients will need to handle any exceptions caused by,
|
33
15
|
# e.g., network failures or non-parseable JSON data.
|
16
|
+
|
34
17
|
module Flapjack
|
35
18
|
|
36
19
|
# Top level module for Flapjack::Diner API consumer.
|
37
20
|
module Diner
|
38
|
-
UUID_RE = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"
|
39
|
-
|
40
21
|
include HTTParty
|
41
22
|
format :json
|
42
23
|
|
43
|
-
|
44
|
-
attr_accessor :return_keys_as_strings
|
45
|
-
|
46
|
-
# redefine HTTParty logger methods for getter/setter style
|
47
|
-
alias :original_logger :logger
|
48
|
-
def logger=(lgr)
|
49
|
-
original_logger(lgr, :info, :'flapjack-diner')
|
50
|
-
end
|
51
|
-
def logger
|
52
|
-
default_options[:logger]
|
53
|
-
end
|
54
|
-
|
55
|
-
def output
|
56
|
-
return if !instance_variable_defined?('@response') || @response.nil?
|
57
|
-
@response.output
|
58
|
-
end
|
59
|
-
|
60
|
-
def context
|
61
|
-
return if !instance_variable_defined?('@response') || @response.nil?
|
62
|
-
@response.context
|
63
|
-
end
|
24
|
+
UUID_RE = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"
|
64
25
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
26
|
+
class << self
|
27
|
+
attr_accessor :logger, :return_keys_as_strings
|
28
|
+
|
29
|
+
include Flapjack::Diner::Resources::Checks
|
30
|
+
include Flapjack::Diner::Resources::Contacts
|
31
|
+
include Flapjack::Diner::Resources::Events
|
32
|
+
include Flapjack::Diner::Resources::MaintenancePeriods
|
33
|
+
include Flapjack::Diner::Resources::Media
|
34
|
+
include Flapjack::Diner::Resources::Metrics
|
35
|
+
include Flapjack::Diner::Resources::Rules
|
36
|
+
include Flapjack::Diner::Resources::States
|
37
|
+
include Flapjack::Diner::Resources::Statistics
|
38
|
+
include Flapjack::Diner::Resources::Tags
|
39
|
+
|
40
|
+
include Flapjack::Diner::Resources::Relationships
|
41
|
+
|
42
|
+
include Flapjack::Diner::Tools
|
69
43
|
end
|
70
|
-
|
71
|
-
include Flapjack::Diner::Resources
|
72
|
-
include Flapjack::Diner::Relationships
|
73
|
-
include Flapjack::Diner::Tools
|
74
44
|
end
|
75
45
|
end
|
@@ -111,6 +111,14 @@ module Flapjack
|
|
111
111
|
end
|
112
112
|
end
|
113
113
|
|
114
|
+
def singular_link(*elements)
|
115
|
+
elements.each do |element|
|
116
|
+
target = @query[element]
|
117
|
+
next if target.nil? || (target.is_a?(String) && !target.empty?)
|
118
|
+
@errors << "'#{target}' association must be a String ID."
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
114
122
|
def singular_link_uuid(*elements)
|
115
123
|
elements.each do |element|
|
116
124
|
target = @query[element]
|
@@ -120,6 +128,15 @@ module Flapjack
|
|
120
128
|
end
|
121
129
|
end
|
122
130
|
|
131
|
+
def multiple_link(*elements)
|
132
|
+
elements.each do |element|
|
133
|
+
target = @query[element]
|
134
|
+
next if target.nil? || (target.is_a?(Array) &&
|
135
|
+
target.all? {|t| t.is_a?(String) && !t.empty? })
|
136
|
+
@errors << "'#{target}' association must be an Array of String IDs."
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
123
140
|
def multiple_link_uuid(*elements)
|
124
141
|
elements.each do |element|
|
125
142
|
target = @query[element]
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'json'
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
require 'flapjack-diner/version'
|
6
|
+
require 'flapjack-diner/argument_validator'
|
7
|
+
|
8
|
+
module Flapjack
|
9
|
+
module Diner
|
10
|
+
module Resources
|
11
|
+
module Checks
|
12
|
+
def create_checks(*args)
|
13
|
+
data = unwrap_data(*args)
|
14
|
+
validate_params(data) do
|
15
|
+
validate :query => :id, :as => :uuid
|
16
|
+
validate :query => :name, :as => [:required, :non_empty_string]
|
17
|
+
validate :query => :enabled, :as => :boolean
|
18
|
+
validate :query => :tags, :as => :multiple_link
|
19
|
+
end
|
20
|
+
perform_post(:checks, '/checks', data)
|
21
|
+
end
|
22
|
+
|
23
|
+
def checks(*args)
|
24
|
+
ids, data = unwrap_uuids(*args), unwrap_data(*args)
|
25
|
+
validate_params(data) do
|
26
|
+
validate :query => [:fields, :sort, :include], :as => :string_or_array_of_strings
|
27
|
+
validate :query => :filter, :as => :hash
|
28
|
+
validate :query => [:page, :per_page], :as => :positive_integer
|
29
|
+
end
|
30
|
+
perform_get('/checks', ids, data)
|
31
|
+
end
|
32
|
+
|
33
|
+
def update_checks(*args)
|
34
|
+
data = unwrap_data(*args)
|
35
|
+
validate_params(data) do
|
36
|
+
validate :query => :id, :as => [:required, :uuid]
|
37
|
+
validate :query => :name, :as => :non_empty_string
|
38
|
+
validate :query => :enabled, :as => :boolean
|
39
|
+
validate :query => :tags, :as => :multiple_link
|
40
|
+
end
|
41
|
+
perform_patch(:checks, "/checks", data)
|
42
|
+
end
|
43
|
+
|
44
|
+
def delete_checks(*ids)
|
45
|
+
raise "'delete_checks' requires at least one check id " \
|
46
|
+
'parameter' if ids.nil? || ids.empty?
|
47
|
+
perform_delete(:checks, '/checks', *ids)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'json'
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
require 'flapjack-diner/version'
|
6
|
+
require 'flapjack-diner/argument_validator'
|
7
|
+
|
8
|
+
module Flapjack
|
9
|
+
module Diner
|
10
|
+
module Resources
|
11
|
+
module Contacts
|
12
|
+
def create_contacts(*args)
|
13
|
+
data = unwrap_data(*args)
|
14
|
+
validate_params(data) do
|
15
|
+
validate :query => :id, :as => :uuid
|
16
|
+
validate :query => :name, :as => [:required, :non_empty_string]
|
17
|
+
validate :query => :timezone, :as => :non_empty_string
|
18
|
+
end
|
19
|
+
# FIXME validate timezone string, if it's possible to do
|
20
|
+
# this without an extra gem dependency
|
21
|
+
perform_post(:contacts, '/contacts', data)
|
22
|
+
end
|
23
|
+
|
24
|
+
def contacts(*args)
|
25
|
+
ids, data = unwrap_uuids(*args), unwrap_data(*args)
|
26
|
+
validate_params(data) do
|
27
|
+
validate :query => [:fields, :sort, :include], :as => :string_or_array_of_strings
|
28
|
+
validate :query => :filter, :as => :hash
|
29
|
+
validate :query => [:page, :per_page], :as => :positive_integer
|
30
|
+
end
|
31
|
+
perform_get('/contacts', ids, data)
|
32
|
+
end
|
33
|
+
|
34
|
+
def update_contacts(*args)
|
35
|
+
data = unwrap_data(*args)
|
36
|
+
validate_params(data) do
|
37
|
+
validate :query => :id, :as => [:required, :uuid]
|
38
|
+
validate :query => [:name, :timezone], :as => :non_empty_string
|
39
|
+
end
|
40
|
+
# FIXME validate timezone string, if it's possible to do
|
41
|
+
# this without an extra gem dependency
|
42
|
+
perform_patch(:contacts, "/contacts", data)
|
43
|
+
end
|
44
|
+
|
45
|
+
def delete_contacts(*ids)
|
46
|
+
raise "'delete_contacts' requires at least one contact id " \
|
47
|
+
'parameter' if ids.nil? || ids.empty?
|
48
|
+
perform_delete(:contacts, '/contacts', *ids)
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'json'
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
require 'flapjack-diner/version'
|
6
|
+
require 'flapjack-diner/argument_validator'
|
7
|
+
|
8
|
+
module Flapjack
|
9
|
+
module Diner
|
10
|
+
module Resources
|
11
|
+
module Events
|
12
|
+
def create_acknowledgements(*args)
|
13
|
+
data = unwrap_data(*args)
|
14
|
+
validate_params(data) do
|
15
|
+
validate :query => :duration, :as => :positive_integer
|
16
|
+
validate :query => :summary, :as => :non_empty_string
|
17
|
+
validate :query => :check, :as => :singular_link_uuid
|
18
|
+
validate :query => :tag, :as => :singular_link
|
19
|
+
end
|
20
|
+
_events_validate_association(data, 'acknowledgement')
|
21
|
+
perform_post(:acknowledgements, "/acknowledgements", data)
|
22
|
+
end
|
23
|
+
|
24
|
+
def create_test_notifications(*args)
|
25
|
+
data = unwrap_data(*args)
|
26
|
+
validate_params(data) do
|
27
|
+
validate :query => :summary, :as => :non_empty_string
|
28
|
+
validate :query => :check, :as => :singular_link_uuid
|
29
|
+
validate :query => :tag, :as => :singular_link
|
30
|
+
end
|
31
|
+
_events_validate_association(data, 'test notification')
|
32
|
+
perform_post(:test_notifications, "/test_notifications", data)
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def _events_validate_association(data, type)
|
38
|
+
case data
|
39
|
+
when Array
|
40
|
+
data.each do |d|
|
41
|
+
unless d.has_key?(:check) || d.has_key?(:tag)
|
42
|
+
raise ArgumentError.new("Check or tag association must be provided for all #{type}s")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
when Hash
|
46
|
+
unless data.has_key?(:check) || data.has_key?(:tag)
|
47
|
+
raise ArgumentError.new("Check or tag association must be provided for #{type}")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'json'
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
require 'flapjack-diner/version'
|
6
|
+
require 'flapjack-diner/argument_validator'
|
7
|
+
|
8
|
+
module Flapjack
|
9
|
+
module Diner
|
10
|
+
module Resources
|
11
|
+
module MaintenancePeriods
|
12
|
+
|
13
|
+
def create_scheduled_maintenances(*args)
|
14
|
+
data = unwrap_data(*args)
|
15
|
+
validate_params(data) do
|
16
|
+
validate :query => :id, :as => :uuid
|
17
|
+
validate :query => :start_time, :as => [:required, :time]
|
18
|
+
validate :query => :end_time, :as => [:required, :time]
|
19
|
+
validate :query => :summary, :as => :non_empty_string
|
20
|
+
validate :query => :check, :as => :singular_link_uuid
|
21
|
+
validate :query => :tag, :as => :singular_link
|
22
|
+
end
|
23
|
+
_maintenance_periods_validate_association(data, 'scheduled maintenance period')
|
24
|
+
perform_post(:scheduled_maintenances, '/scheduled_maintenances', data)
|
25
|
+
end
|
26
|
+
|
27
|
+
def update_scheduled_maintenances(*args)
|
28
|
+
data = unwrap_data(*args)
|
29
|
+
validate_params(data) do
|
30
|
+
validate :query => :id, :as => [:required, :uuid]
|
31
|
+
validate :query => [:start_time, :end_time], :as => :time
|
32
|
+
end
|
33
|
+
perform_patch(:scheduled_maintenances, '/scheduled_maintenances',
|
34
|
+
data)
|
35
|
+
end
|
36
|
+
|
37
|
+
def update_unscheduled_maintenances(*args)
|
38
|
+
data = unwrap_data(*args)
|
39
|
+
validate_params(data) do
|
40
|
+
validate :query => :id, :as => [:required, :uuid]
|
41
|
+
validate :query => :end_time, :as => :time
|
42
|
+
end
|
43
|
+
perform_patch(:unscheduled_maintenances, '/unscheduled_maintenances',
|
44
|
+
data)
|
45
|
+
end
|
46
|
+
|
47
|
+
def delete_scheduled_maintenances(*ids)
|
48
|
+
if ids.nil? || ids.empty?
|
49
|
+
raise "'delete_scheduled_maintenances' requires " \
|
50
|
+
"at least one scheduled maintenance id parameter"
|
51
|
+
end
|
52
|
+
perform_delete(:scheduled_maintenances, '/scheduled_maintenances',
|
53
|
+
*ids)
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def _maintenance_periods_validate_association(data, type)
|
59
|
+
case data
|
60
|
+
when Array
|
61
|
+
data.each do |d|
|
62
|
+
unless d.has_key?(:check) || d.has_key?(:tag)
|
63
|
+
raise ArgumentError.new("Check or tag association must be provided for all #{type}s")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
when Hash
|
67
|
+
unless data.has_key?(:check) || data.has_key?(:tag)
|
68
|
+
raise ArgumentError.new("Check or tag association must be provided for #{type}")
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'json'
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
require 'flapjack-diner/version'
|
6
|
+
require 'flapjack-diner/argument_validator'
|
7
|
+
|
8
|
+
module Flapjack
|
9
|
+
module Diner
|
10
|
+
module Resources
|
11
|
+
module Media
|
12
|
+
def create_media(*args)
|
13
|
+
data = unwrap_data(*args)
|
14
|
+
validate_params(data) do
|
15
|
+
validate :query => :id, :as => :uuid
|
16
|
+
validate :query => :transport, :as => [:non_empty_string, :required]
|
17
|
+
validate :query => [:address, :pagerduty_subdomain,
|
18
|
+
:pagerduty_token], :as => :non_empty_string
|
19
|
+
validate :query => [:interval, :rollup_threshold,
|
20
|
+
:pagerduty_ack_duration], :as => :positive_integer
|
21
|
+
validate :query => :contact, :as => [:singular_link_uuid, :required]
|
22
|
+
validate :query => :rules, :as => :multiple_link_uuid
|
23
|
+
end
|
24
|
+
perform_post(:media, "/media", data)
|
25
|
+
end
|
26
|
+
|
27
|
+
def media(*args)
|
28
|
+
ids, data = unwrap_uuids(*args), unwrap_data(*args)
|
29
|
+
validate_params(data) do
|
30
|
+
validate :query => [:fields, :sort, :include], :as => :string_or_array_of_strings
|
31
|
+
validate :query => :filter, :as => :hash
|
32
|
+
validate :query => [:page, :per_page], :as => :positive_integer
|
33
|
+
end
|
34
|
+
perform_get('/media', ids, data)
|
35
|
+
end
|
36
|
+
|
37
|
+
def update_media(*args)
|
38
|
+
data = unwrap_data(*args)
|
39
|
+
validate_params(data) do
|
40
|
+
validate :query => :id, :as => [:uuid, :required]
|
41
|
+
validate :query => [:address, :pagerduty_subdomain,
|
42
|
+
:pagerduty_token], :as => :non_empty_string
|
43
|
+
validate :query => [:interval, :rollup_threshold,
|
44
|
+
:pagerduty_ack_duration], :as => :positive_integer
|
45
|
+
validate :query => :rules, :as => :multiple_link_uuid
|
46
|
+
end
|
47
|
+
perform_patch(:media, "/media", data)
|
48
|
+
end
|
49
|
+
|
50
|
+
def delete_media(*ids)
|
51
|
+
raise "'delete_media' requires at least one medium id " \
|
52
|
+
'parameter' if ids.nil? || ids.empty?
|
53
|
+
perform_delete(:media, '/media', *ids)
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def _media_validate_association(data)
|
59
|
+
case data
|
60
|
+
when Array
|
61
|
+
data.each do |d|
|
62
|
+
unless d.has_key?(:contact)
|
63
|
+
raise ArgumentError.new("Contact association must be provided for all media")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
when Hash
|
67
|
+
unless data.has_key?(:contact)
|
68
|
+
raise ArgumentError.new("Contact association must be provided for medium")
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|