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: 135a20c25de376d383417a2422e23aa21b0beaef
4
- data.tar.gz: e1f3761d1879482fd78adea7ed02bb4646f019d2
3
+ metadata.gz: b94afa9f628189dc66075b34239930dcfa60fa37
4
+ data.tar.gz: 2d566d59b5c4ac62784c359925df1e74f7711fb5
5
5
  SHA512:
6
- metadata.gz: 73d944dfb3d1cb0e0082f406c54faf72bef2636b9e980278770d8e8cb95acf49106634e7a36388ae8b28d3812648860b42d40324b2b017641915fdb58d5eeb83
7
- data.tar.gz: 5e7b9b47b9556bb0e102aad9cd5c7b4d8f678d5d7772e3fb534181d9eddd5afd92f0690b395efc7ac3fcb095fe240b7209dea874d8e1b5afb1ad386ebc50fded
6
+ metadata.gz: 5f458bfc7b930b91519e1b94098ba92eac52e2c0c4af9b63493d77e9230b8b787e2be63a89e0a0af7f5bc5b0edb07284dbbe1a037bf1a72914e0af32ab870730
7
+ data.tar.gz: 0c875b39a8df08c93588a8ea3c4726df280eb6d93a5f8e808ce58404859d6d71a22e130c5587f4412c183815be63069103d3e6a12cce85e02008f63e2f361a65
@@ -14,6 +14,7 @@ module Interferon
14
14
  end
15
15
 
16
16
  def evaluate(hostinfo)
17
+ return self if @dsl && @dsl.applies == :once
17
18
  dsl = AlertDSL.new(hostinfo)
18
19
  dsl.instance_eval(@text, @filename, 1)
19
20
  @dsl = dsl
@@ -122,6 +122,10 @@ module Interferon
122
122
  def audit(v = nil, &block)
123
123
  get_or_set(:@audit, v, block, false)
124
124
  end
125
+
126
+ def recovery(v = nil, &block)
127
+ get_or_set(:@recovery, v, block, true)
128
+ end
125
129
  end
126
130
 
127
131
  class MetricDSL
@@ -66,8 +66,15 @@ module Interferon::Destinations
66
66
  @api_errors ||= []
67
67
  end
68
68
 
69
- def self.generate_message(message, people)
70
- [message, ALERT_KEY, people.sort.map { |p| "@#{p}" }].flatten.join("\n")
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(alert['message'], people)
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(alert['message'], people).strip,
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'],
@@ -1,3 +1,3 @@
1
1
  module Interferon
2
- VERSION = '0.2.1'.freeze
2
+ VERSION = '0.2.2'.freeze
3
3
  end
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
- raise "Alerts failed to apply or evaluate for all hosts: #{alerts.map(&:to_s).join(', ')}"
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: interferon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Serebryany