interferon 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b94afa9f628189dc66075b34239930dcfa60fa37
|
4
|
+
data.tar.gz: 2d566d59b5c4ac62784c359925df1e74f7711fb5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f458bfc7b930b91519e1b94098ba92eac52e2c0c4af9b63493d77e9230b8b787e2be63a89e0a0af7f5bc5b0edb07284dbbe1a037bf1a72914e0af32ab870730
|
7
|
+
data.tar.gz: 0c875b39a8df08c93588a8ea3c4726df280eb6d93a5f8e808ce58404859d6d71a22e130c5587f4412c183815be63069103d3e6a12cce85e02008f63e2f361a65
|
data/lib/interferon/alert.rb
CHANGED
data/lib/interferon/alert_dsl.rb
CHANGED
@@ -66,8 +66,15 @@ module Interferon::Destinations
|
|
66
66
|
@api_errors ||= []
|
67
67
|
end
|
68
68
|
|
69
|
-
def self.generate_message(message, people)
|
70
|
-
|
69
|
+
def self.generate_message(message, people, options = {})
|
70
|
+
mentions = people.sort.map { |p| "@#{p}" }
|
71
|
+
|
72
|
+
unless options[:notify_recovery]
|
73
|
+
# Only mention on alert/warning
|
74
|
+
mentions = "{{^is_recovery}}#{mentions}{{/is_recovery}}"
|
75
|
+
end
|
76
|
+
|
77
|
+
[message, ALERT_KEY, mentions].flatten.join("\n")
|
71
78
|
end
|
72
79
|
|
73
80
|
def fetch_existing_alerts
|
@@ -132,7 +139,11 @@ module Interferon::Destinations
|
|
132
139
|
# create a message which includes the notifications
|
133
140
|
# Datadog may have a race condition where alerts created in a bad state may be triggered
|
134
141
|
# during the dry-run creation process. Delete people from dry-run alerts to avoid this
|
135
|
-
message = self.class.generate_message(
|
142
|
+
message = self.class.generate_message(
|
143
|
+
alert['message'],
|
144
|
+
people,
|
145
|
+
notify_recovery: alert['notify']['recovery']
|
146
|
+
)
|
136
147
|
|
137
148
|
# create the hash of options to send to datadog
|
138
149
|
alert_options = {
|
@@ -338,7 +349,11 @@ EOM
|
|
338
349
|
new_alert = {
|
339
350
|
monitor_type: normalize_monitor_type(alert['monitor_type']),
|
340
351
|
query: alert['metric']['datadog_query'],
|
341
|
-
message: generate_message(
|
352
|
+
message: generate_message(
|
353
|
+
alert['message'],
|
354
|
+
people,
|
355
|
+
notify_recovery: alert['notify']['recovery']
|
356
|
+
).strip,
|
342
357
|
evaluation_delay: alert['evaluation_delay'],
|
343
358
|
notify_no_data: alert['notify_no_data'],
|
344
359
|
notify_audit: alert['notify']['audit'],
|
data/lib/interferon/version.rb
CHANGED
data/lib/interferon.rb
CHANGED
@@ -148,7 +148,8 @@ module Interferon
|
|
148
148
|
def update_alerts(destinations, hosts, alerts, groups)
|
149
149
|
alerts_queue, alert_errors = build_alerts_queue(hosts, alerts, groups)
|
150
150
|
if @dry_run && !alert_errors.empty?
|
151
|
-
|
151
|
+
erroneous_alert_files = alerts_errors.map(&:to_s).join(', ')
|
152
|
+
raise "Alerts failed to apply or evaluate for all hosts: #{erroneous_alert_files}"
|
152
153
|
end
|
153
154
|
|
154
155
|
loader = DestinationsLoader.new([@alerts_repo_path])
|
@@ -114,4 +114,37 @@ describe Interferon::Destinations::Datadog do
|
|
114
114
|
datadog.remove_alert(mock_alert)
|
115
115
|
end
|
116
116
|
end
|
117
|
+
|
118
|
+
describe '.generate_message' do
|
119
|
+
let(:message) { 'test message' }
|
120
|
+
let(:people) { %w(userA userB) }
|
121
|
+
|
122
|
+
it 'adds the ALERT_KEY to the message' do
|
123
|
+
expect(Interferon::Destinations::Datadog.generate_message(message, people)).to include(
|
124
|
+
Interferon::Destinations::Datadog::ALERT_KEY
|
125
|
+
)
|
126
|
+
end
|
127
|
+
|
128
|
+
it 'adds a mention to people' do
|
129
|
+
expect(Interferon::Destinations::Datadog.generate_message(message, people)).to include(
|
130
|
+
*people.map { |person| "@#{person}" }
|
131
|
+
)
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'does not add ^is_recovery template variable when notify_recovery is true' do
|
135
|
+
expect(
|
136
|
+
Interferon::Destinations::Datadog.generate_message(
|
137
|
+
message, people, notify_recovery: true
|
138
|
+
)
|
139
|
+
).not_to include('{{^is_recovery}}')
|
140
|
+
end
|
141
|
+
|
142
|
+
it 'adds a ^is_recovery template variable when notify_recovery is false' do
|
143
|
+
expect(
|
144
|
+
Interferon::Destinations::Datadog.generate_message(
|
145
|
+
message, people, notify_recovery: false
|
146
|
+
)
|
147
|
+
).to include('{{^is_recovery}}')
|
148
|
+
end
|
149
|
+
end
|
117
150
|
end
|