flapjack_configurator 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +2 -0
  3. data/.rubocop.yml +47 -0
  4. data/Dockerfile +11 -0
  5. data/Gemfile +3 -0
  6. data/README.md +139 -0
  7. data/Rakefile +19 -0
  8. data/bin/flapjack_configurator +82 -0
  9. data/example.yml +121 -0
  10. data/flapjack_configurator.gemspec +29 -0
  11. data/lib/flapjack_configurator.rb +32 -0
  12. data/lib/flapjack_configurator/entity_mapper.rb +70 -0
  13. data/lib/flapjack_configurator/flapjack_config.rb +72 -0
  14. data/lib/flapjack_configurator/flapjack_contact.rb +156 -0
  15. data/lib/flapjack_configurator/flapjack_media.rb +23 -0
  16. data/lib/flapjack_configurator/flapjack_notification_rule.rb +39 -0
  17. data/lib/flapjack_configurator/flapjack_object_base.rb +86 -0
  18. data/lib/flapjack_configurator/flapjack_pagerduty.rb +28 -0
  19. data/lib/flapjack_configurator/flapjack_sub_object_base.rb +33 -0
  20. data/lib/flapjack_configurator/user_configuration.rb +107 -0
  21. data/lib/flapjack_configurator/version.rb +6 -0
  22. data/spec/docker_test_wrapper.rb +52 -0
  23. data/spec/functional/all_entity_spec.rb +19 -0
  24. data/spec/functional/config_test_common.rb +58 -0
  25. data/spec/functional/configuration_contact_attributes_spec.rb +18 -0
  26. data/spec/functional/configuration_contact_entities_spec.rb +116 -0
  27. data/spec/functional/configuration_contact_notification_media_spec.rb +73 -0
  28. data/spec/functional/configuration_contact_notification_rules_spec.rb +58 -0
  29. data/spec/functional/configuration_contact_removal_spec.rb +83 -0
  30. data/spec/functional/test_configs/changes/attributes.yaml +24 -0
  31. data/spec/functional/test_configs/changes/notification_media.yaml +155 -0
  32. data/spec/functional/test_configs/changes/notification_rules.yaml +143 -0
  33. data/spec/functional/test_configs/entities.yaml +71 -0
  34. data/spec/functional/test_configs/initial/attributes.yaml +24 -0
  35. data/spec/functional/test_configs/initial/notification_media.yaml +155 -0
  36. data/spec/functional/test_configs/initial/notification_rules.yaml +143 -0
  37. data/spec/functional/test_configs/obj_removal_setup.yaml +106 -0
  38. data/spec/spec_helper.rb +9 -0
  39. metadata +211 -0
@@ -0,0 +1,73 @@
1
+ require_relative '../spec_helper.rb'
2
+ require_relative 'config_test_common.rb'
3
+
4
+ TestCommon.setup_config_test('notification_media') do |rspec_obj, test_config|
5
+ # Table defining which media attributes should be used for each test contact
6
+ test_attr_table = {
7
+ nmt_baseline_inheritence:
8
+ { pagerduty: { subdomain: :baseline, token: :baseline, service_key: :baseline },
9
+ email: { interval: :baseline, rollup_threshold: :baseline, address: :baseline },
10
+ jabber: { interval: :baseline, rollup_threshold: :baseline, address: :baseline } },
11
+ nmt_default_partial_inheritance:
12
+ { pagerduty: { subdomain: :defaults, token: :baseline, service_key: :baseline },
13
+ email: { interval: :defaults, rollup_threshold: :baseline, address: :defaults },
14
+ jabber: { interval: :defaults, rollup_threshold: :baseline, address: :defaults } },
15
+ nmt_default_full_inheritance:
16
+ { pagerduty: { subdomain: :defaults, token: :defaults, service_key: :defaults },
17
+ email: { interval: :defaults, rollup_threshold: :defaults, address: :defaults },
18
+ jabber: { interval: :defaults, rollup_threshold: :defaults, address: :defaults } },
19
+ nmt_partial_contacts:
20
+ { pagerduty: { subdomain: :contact, token: :baseline, service_key: :baseline },
21
+ email: { interval: :baseline, rollup_threshold: :baseline, address: :contact },
22
+ jabber: { interval: :baseline, rollup_threshold: :baseline, address: :contact } },
23
+ nmt_full_contacts:
24
+ { pagerduty: { subdomain: :contact, token: :contact, service_key: :contact },
25
+ email: { interval: :contact, rollup_threshold: :contact, address: :contact },
26
+ jabber: { interval: :contact, rollup_threshold: :contact, address: :contact } },
27
+ nmt_real_world:
28
+ { pagerduty: { subdomain: :contact, token: :baseline, service_key: :baseline },
29
+ email: { interval: :defaults, rollup_threshold: :defaults, address: :contact },
30
+ jabber: { interval: :defaults, rollup_threshold: :defaults, address: :contact } }
31
+ }
32
+
33
+ test_attr_table.each do |test_contact, contact_attr_table|
34
+ rspec_obj.describe "#{test_contact} notification_media" do
35
+ it 'should only have media from the config' do
36
+ contact_rules = @test_diner.diner.contacts(test_contact)[0][:links][:media]
37
+ expect(contact_rules - contact_attr_table.keys.map { |media| "#{test_contact}_#{media}" }).to eq([])
38
+ end
39
+
40
+ contact_attr_table.each do |media, media_attr_table|
41
+ describe "#{media} media" do
42
+ before :all do
43
+ # Pagerduty is handled as a special case by (bolted onto) the API
44
+ @api_media = case media
45
+ when :pagerduty
46
+ @test_diner.diner.pagerduty_credentials(test_contact)[0]
47
+ else
48
+ @test_diner.diner.media("#{test_contact}_#{media}")[0]
49
+ end
50
+ end
51
+
52
+ it 'should be associated to the contact' do
53
+ expect(@api_media[:links][:contacts][0]).to eql(test_contact.to_s)
54
+ end
55
+
56
+ media_attr_table.each do |media_attr, attr_source|
57
+ test_value = case attr_source
58
+ when :baseline
59
+ test_config['baseline_options']['notification_media'][media.to_s][media_attr.to_s]
60
+ when :defaults
61
+ test_config['contacts'][test_contact.to_s]['notification_media']['defaults'][media_attr.to_s]
62
+ when :contact
63
+ test_config['contacts'][test_contact.to_s]['notification_media'][media.to_s][media_attr.to_s]
64
+ end
65
+ it "should use the #{attr_source} attribute for #{media_attr}" do
66
+ expect(@api_media[media_attr]).to eql(test_value)
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,58 @@
1
+ require_relative '../spec_helper.rb'
2
+ require_relative 'config_test_common.rb'
3
+
4
+ TestCommon.setup_config_test('notification_rules') do |rspec_obj, test_config|
5
+ # Table defining which media attributes should be used for each test contact
6
+ test_attr_table = {
7
+ nrt_baseline_inheritence:
8
+ { rules_1: { warning_media: :baseline, critical_media: :baseline },
9
+ rules_2: { warning_media: :baseline, critical_media: :baseline } },
10
+ nrt_default_partial_inheritance:
11
+ { rules_1: { unknown_media: :defaults, warning_media: :defaults, critical_media: :baseline },
12
+ rules_2: { unknown_media: :defaults, warning_media: :defaults, critical_media: :baseline } },
13
+ nrt_default_full_inheritance:
14
+ { rules_1: { unknown_media: :defaults, warning_media: :defaults, critical_media: :defaults },
15
+ rules_2: { unknown_media: :defaults, warning_media: :defaults, critical_media: :defaults } },
16
+ nrt_partial_contacts:
17
+ { rules_1: { unknown_media: :defaults, warning_media: :contact, critical_media: :contact },
18
+ rules_2: { unknown_media: :defaults, warning_media: :defaults, critical_media: :baseline } },
19
+ nrt_full_contacts:
20
+ { rules_1: { unknown_media: :contact, warning_media: :contact, critical_media: :contact },
21
+ rules_2: { unknown_media: :contact, warning_media: :contact, critical_media: :contact } }
22
+ }
23
+
24
+ test_attr_table.each do |test_contact, contact_attr_table|
25
+ rspec_obj.describe "#{test_contact} notification_rules" do
26
+ it 'should only have rules from the config' do
27
+ contact_rules = @test_diner.diner.contacts(test_contact)[0][:links][:notification_rules]
28
+ expect(contact_rules - contact_attr_table.keys.map { |rule| "#{test_contact}_#{rule}" }).to eq([])
29
+ end
30
+
31
+ contact_attr_table.each do |rule, rules_attr_table|
32
+ describe "#{rule} rules" do
33
+ before :all do
34
+ @api_rules = @test_diner.diner.notification_rules("#{test_contact}_#{rule}")[0]
35
+ end
36
+
37
+ it 'should be associated to the contact' do
38
+ expect(@api_rules[:links][:contacts][0]).to eql(test_contact.to_s)
39
+ end
40
+
41
+ rules_attr_table.each do |rules_attr, attr_source|
42
+ test_value = case attr_source
43
+ when :baseline
44
+ test_config['baseline_options']['notification_rules'][rule.to_s][rules_attr.to_s]
45
+ when :defaults
46
+ test_config['contacts'][test_contact.to_s]['notification_rules']['defaults'][rules_attr.to_s]
47
+ when :contact
48
+ test_config['contacts'][test_contact.to_s]['notification_rules'][rule.to_s][rules_attr.to_s]
49
+ end
50
+ it "should use the #{attr_source} attribute for #{rules_attr}" do
51
+ expect(@api_rules[rules_attr]).to eql(test_value)
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,83 @@
1
+ require_relative '../spec_helper.rb'
2
+ require_relative 'config_test_common.rb'
3
+
4
+ TestCommon.setup_test do |rspec_obj|
5
+ rspec_obj.describe 'object removal' do
6
+ before :all do
7
+ # Load flapjack with test entities
8
+ fail 'Failed to create test entities' unless @test_diner.diner.create_entities(Array.new(100) { |c| { name: "testentity-#{c}", id: "testentity-#{c}" } })
9
+ @test_config = TestCommon.load_config('obj_removal_setup')
10
+ # Load Flapjack with the things
11
+ FlapjackConfigurator.configure_flapjack(@test_config, @test_container.api_url, @logger, true)
12
+ end
13
+
14
+ # Because I don't trust anything and we're testing absence
15
+ describe 'pretest sanity' do
16
+ # The test sets up two contacts the same way
17
+ %w(loaded_test removal_test).each do |contact_name|
18
+ describe "#{contact_name} contact" do
19
+ before :all do
20
+ @api_contact_links = @test_diner.diner.contacts(contact_name)[0][:links]
21
+ end
22
+
23
+ [:entities, :media, :notification_rules].each do |thing|
24
+ it "has #{thing}s linked to it" do
25
+ # media is 2, notification_rules has 2, entities has 101 or so
26
+ expect(@api_contact_links[thing].length).to be >= 2
27
+ end
28
+ end
29
+
30
+ # special case...
31
+ it 'has pagerduty linked to it' do
32
+ expect(@test_diner.diner.pagerduty_credentials(contact_name)).not_to be_nil
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ describe 'operation' do
39
+ before :all do
40
+ # Strip down the config
41
+ #
42
+ # Delete the test delete contact
43
+ @test_config['contacts'].delete('removal_test')
44
+ # Delete things from the loaded test
45
+ @test_config['contacts']['loaded_test'].delete('entities')
46
+ @test_config['contacts']['loaded_test']['notification_media'] = {}
47
+ # Leave the default notification rule to prevent false failures from Flapjack adding a default
48
+ @test_config['contacts']['loaded_test']['notification_rules'].delete('rule1')
49
+ @test_config['contacts']['loaded_test']['notification_rules'].delete('rule2')
50
+ end
51
+
52
+ it 'returns true as changes are made' do
53
+ expect(FlapjackConfigurator.configure_flapjack(@test_config, @test_container.api_url, @logger, true)).to eql(true)
54
+ end
55
+
56
+ it 'deletes the removal_test contact' do
57
+ expect(@test_diner.diner.contacts('removal_test')).to be_nil
58
+ end
59
+
60
+ # Wording is getting contrived...
61
+ describe 'against the loaded_test user' do
62
+ before :all do
63
+ @api_contact_links = @test_diner.diner.contacts('loaded_test')[0][:links]
64
+ end
65
+
66
+ [:entities, :media].each do |thing|
67
+ it "removes the #{thing}s" do
68
+ expect(@api_contact_links[thing]).to eql([])
69
+ end
70
+ end
71
+
72
+ it 'removes all but the default notification rule' do
73
+ expect(@api_contact_links[:notification_rules]).to eql(%w(loaded_test_default))
74
+ end
75
+
76
+ # special case...
77
+ it 'removes the pagerduty credentials' do
78
+ expect(@test_diner.diner.pagerduty_credentials('loaded_test')).to eql([])
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,24 @@
1
+ # Changed attributes write
2
+ ---
3
+
4
+ contacts:
5
+ attribute_test:
6
+ details:
7
+ first_name: ChangedTestFirstName
8
+ last_name: ChangedTestLastName
9
+ email: changed.test.contact.email@example.com
10
+ timezone: CST6CDT
11
+
12
+ notification_media: {}
13
+ notification_rules: {}
14
+
15
+ # Write two contacts to check for crosstalk
16
+ attribute_test2:
17
+ details:
18
+ first_name: ChangedTest2FirstName
19
+ last_name: ChangedTest2LastName
20
+ email: changedtest2.contact.email@example.com
21
+ timezone: PST8PDT
22
+
23
+ notification_media: {}
24
+ notification_rules: {}
@@ -0,0 +1,155 @@
1
+ # Changed notification_media test config
2
+ # Intentionally big to hit many scenarios
3
+ ---
4
+ baseline_options:
5
+ notification_media:
6
+ pagerduty:
7
+ subdomain: BaselinePDSubdomain2
8
+ token: BaselinePDToken2
9
+ service_key: BaselinePDServiceKey2
10
+ interval: 2100
11
+ rollup_threshold: 210
12
+
13
+ email:
14
+ address: baseline.address@example2.foo
15
+ interval: 2102
16
+ rollup_threshold: 211
17
+
18
+ jabber:
19
+ address: baseline_room@jabber.example2.foo
20
+ interval: 2103
21
+ rollup_threshold: 212
22
+
23
+ contacts:
24
+ # nmt: Notification media test
25
+ nmt_baseline_inheritence:
26
+ details:
27
+ first_name: TestFirstName
28
+ last_name: TestLastName
29
+ email: test.contact.email@example.com
30
+ timezone: MST7MDT
31
+ notification_rules:
32
+ defaults: {}
33
+
34
+ notification_media:
35
+ pagerduty: {}
36
+ email: {}
37
+ jabber: {}
38
+
39
+ nmt_default_partial_inheritance:
40
+ details:
41
+ first_name: TestFirstName
42
+ last_name: TestLastName
43
+ email: test.contact.email@example.com
44
+ timezone: MST7MDT
45
+ notification_rules:
46
+ defaults: {}
47
+
48
+ notification_media:
49
+ defaults:
50
+ address: default_address2@example.foo
51
+ subdomain: DefaultPDSubdomain2
52
+ interval: 2200
53
+
54
+ pagerduty: {}
55
+ email: {}
56
+ jabber: {}
57
+
58
+ nmt_default_full_inheritance:
59
+ details:
60
+ first_name: TestFirstName
61
+ last_name: TestLastName
62
+ email: test.contact.email@example.com
63
+ timezone: MST7MDT
64
+ notification_rules:
65
+ defaults: {}
66
+
67
+ notification_media:
68
+ defaults:
69
+ subdomain: DefaultPDSubdomain2
70
+ token: DefaultPDToken2
71
+ service_key: DefaultPDServiceKey2
72
+ address: default.address@example2.foo
73
+ interval: 300
74
+ rollup_threshold: 30
75
+
76
+ pagerduty: {}
77
+ email: {}
78
+ jabber: {}
79
+
80
+ nmt_partial_contacts:
81
+ details:
82
+ first_name: TestFirstName
83
+ last_name: TestLastName
84
+ email: test.contact.email@example.com
85
+ timezone: MST7MDT
86
+ notification_rules:
87
+ defaults: {}
88
+
89
+ notification_media:
90
+ pagerduty:
91
+ subdomain: ContactPDSubdomain2
92
+
93
+ email:
94
+ address: contact.address@example2.com
95
+
96
+ jabber:
97
+ address: contact_room@jabber.example2.com
98
+
99
+ nmt_full_contacts:
100
+ details:
101
+ first_name: TestFirstName
102
+ last_name: TestLastName
103
+ email: test.contact.email@example.com
104
+ timezone: MST7MDT
105
+ notification_rules:
106
+ defaults: {}
107
+
108
+ notification_media:
109
+ defaults:
110
+ subdomain: DefaultPDSubdomain2
111
+ token: DefaultPDToken2
112
+ service_key: DefaultPDServiceKey2
113
+ address: default.address@example2.foo
114
+ interval: 2300
115
+ rollup_threshold: 230
116
+
117
+ pagerduty:
118
+ token: ContactPDToken2
119
+ service_key: ContactPDServiceKey2
120
+ subdomain: ContactPDSubdomain2
121
+ interval: 2400
122
+ rollup_threshold: 240
123
+
124
+ email:
125
+ address: contact.address@example2.com
126
+ interval: 2401
127
+ rollup_threshold: 241
128
+
129
+ jabber:
130
+ address: contact_room@jabber.example2.com
131
+ interval: 2402
132
+ rollup_threshold: 242
133
+
134
+ nmt_real_world:
135
+ details:
136
+ first_name: TestFirstName
137
+ last_name: TestLastName
138
+ email: test.contact.email@example.com
139
+ timezone: MST7MDT
140
+ notification_rules:
141
+ defaults: {}
142
+
143
+ notification_media:
144
+ defaults:
145
+ interval: 2500
146
+ rollup_threshold: 250
147
+
148
+ pagerduty:
149
+ subdomain: ContactPDSubdomain22
150
+
151
+ email:
152
+ address: contact.address22@example.com
153
+
154
+ jabber:
155
+ address: contact_room22@jabber.example.com
@@ -0,0 +1,143 @@
1
+ # Initial test config
2
+ # Intentionally big to hit many scenarios
3
+ ---
4
+ baseline_options:
5
+ notification_rules:
6
+ rules_1:
7
+ warning_media:
8
+ - basechengedthing1
9
+ - basechengedthing2
10
+ critical_media:
11
+ - basechengedthing3
12
+ - basechengedthing4
13
+
14
+ rules_2:
15
+ warning_media:
16
+ - basechengedthing5
17
+ - basechengedthing6
18
+ critical_media:
19
+ - basechengedthing7
20
+ - basechengedthing8
21
+
22
+ contacts:
23
+ # nrt: Notification media test
24
+ nrt_baseline_inheritence:
25
+ details:
26
+ first_name: TestFirstName
27
+ last_name: TestLastName
28
+ email: test.contact.email@example.com
29
+ timezone: MST7MDT
30
+ notification_media: {}
31
+
32
+ notification_rules:
33
+ rules_1: {}
34
+ rules_2: {}
35
+
36
+ nrt_default_partial_inheritance:
37
+ details:
38
+ first_name: TestFirstName
39
+ last_name: TestLastName
40
+ email: test.contact.email@example.com
41
+ timezone: MST7MDT
42
+ notification_media: {}
43
+
44
+ notification_rules:
45
+ defaults:
46
+ warning_media:
47
+ - defaultchengedthing1
48
+ - defaultchengedthing2
49
+ unknown_media:
50
+ - defaultchengedthing3
51
+ - defaultchengedthing4
52
+
53
+ rules_1: {}
54
+ rules_2: {}
55
+
56
+ nrt_default_full_inheritance:
57
+ details:
58
+ first_name: TestFirstName
59
+ last_name: TestLastName
60
+ email: test.contact.email@example.com
61
+ timezone: MST7MDT
62
+ notification_media: {}
63
+
64
+ notification_rules:
65
+ defaults:
66
+ critical_media:
67
+ - defaultchengedthing5
68
+ - defaultchengedthing6
69
+ warning_media:
70
+ - defaultchengedthing7
71
+ - defaultchengedthing8
72
+ unknown_media:
73
+ - defaultchengedthing9
74
+ - defaultchengedthing10
75
+
76
+ rules_1: {}
77
+ rules_2: {}
78
+
79
+ nrt_partial_contacts:
80
+ details:
81
+ first_name: TestFirstName
82
+ last_name: TestLastName
83
+ email: test.contact.email@example.com
84
+ timezone: MST7MDT
85
+ notification_media: {}
86
+
87
+ notification_rules:
88
+ defaults:
89
+ warning_media:
90
+ - defaultchengedthing11
91
+ - defaultchengedthing12
92
+ unknown_media:
93
+ - defaultchengedthing13
94
+ - defaultchengedthing14
95
+
96
+ rules_1:
97
+ warning_media:
98
+ - contactchengedthing1
99
+ - contactchengedthing2
100
+ critical_media:
101
+ - contactchengedthing3
102
+ - contactchengedthing4
103
+
104
+ rules_2: {}
105
+
106
+ nrt_full_contacts:
107
+ details:
108
+ first_name: TestFirstName
109
+ last_name: TestLastName
110
+ email: test.contact.email@example.com
111
+ timezone: MST7MDT
112
+ notification_media: {}
113
+
114
+ notification_rules:
115
+ defaults:
116
+ warning_media:
117
+ - defaultchengedthing15
118
+ - defaultchengedthing16
119
+ unknown_media:
120
+ - defaultchengedthing17
121
+ - defaultchengedthing18
122
+
123
+ rules_1:
124
+ warning_media:
125
+ - contactchengedthing5
126
+ - contactchengedthing6
127
+ critical_media:
128
+ - contactchengedthing7
129
+ - contactchengedthing8
130
+ unknown_media:
131
+ - contactchengedthing9
132
+ - contactchengedthing10
133
+
134
+ rules_2:
135
+ warning_media:
136
+ - contactchengedthing11
137
+ - contactchengedthing12
138
+ critical_media:
139
+ - contactchengedthing13
140
+ - contactchengedthing14
141
+ unknown_media:
142
+ - contactchengedthing15
143
+ - contactchengedthing16