rollbar-notification-rules-generator 0.2.0 → 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 +4 -4
- data/README.md +3 -1
- data/lib/rollbar/notification/channel.rb +9 -5
- data/lib/rollbar/notification/condition/base.rb +14 -0
- data/lib/rollbar/notification/condition/path.rb +12 -0
- data/lib/rollbar/notification/rule.rb +35 -21
- data/lib/rollbar/notification/trigger.rb +17 -6
- data/lib/rollbar/notification.rb +2 -7
- data/rollbar-notification-rules-generator.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b69971ea33eb831637b2fbc7170b01dd6cce53e45f02d6f0b2c45c019900ed5a
|
4
|
+
data.tar.gz: 43b362b542727d83795bbc5efd0f9f219a224e0f2030d3579be755e97477f111
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f61baf0e620d426b92f9bcd5ea00709969d1b183febcbfe0f4cc8b9f288f2f23e33d4aea71d8e4a0357eb441b4a111ebbdfd40b45e54d37df971ff475df061ec
|
7
|
+
data.tar.gz: 0baee819bff11502752157d296a978a5a50e48f2e9efcaac4593a9820e192fe3801c2cafa1566857f12dc2b2df98fcd8e570fd17c8b760548a1c893effd48bc4
|
data/README.md
CHANGED
@@ -88,10 +88,12 @@ Usage: rollbar-notification-rules-generator [options] <input>
|
|
88
88
|
--format FORMAT terraform|text (default: terraform)
|
89
89
|
```
|
90
90
|
|
91
|
-
The input file is in YAML format like the following:
|
91
|
+
The input file is in YAML format like the following:
|
92
92
|
|
93
93
|
```yaml
|
94
94
|
channel: "slack" # slack or pagerduty
|
95
|
+
# This optional value is used as the namespace of Terraform resources.
|
96
|
+
terraform_provider: foo_
|
95
97
|
# This optional value is used as provider meta-argument of Terraform.
|
96
98
|
terraform_provider: rollbar.alias_value
|
97
99
|
# You can define variables, and they are expanded with the syntax "${{ var.variable_name }}".
|
@@ -4,16 +4,20 @@ require "rollbar/notification/trigger"
|
|
4
4
|
module Rollbar
|
5
5
|
class Notification
|
6
6
|
class Channel
|
7
|
-
|
7
|
+
CHANNEL_TO_TEXT = {
|
8
|
+
"slack" => "Slack",
|
9
|
+
"pagerduty" => "PagerDuty",
|
10
|
+
}
|
8
11
|
|
9
12
|
# @param channel [String]
|
10
13
|
# @param triggers [Hash{String => Array<Hash>}]
|
11
14
|
# @param variables [Hash{String => String}]
|
12
15
|
def initialize(channel, triggers, variables)
|
13
|
-
unless
|
16
|
+
unless CHANNEL_TO_TEXT.include?(channel)
|
14
17
|
raise ArgumentError, "Unsupported channel: #{channel}"
|
15
18
|
end
|
16
19
|
|
20
|
+
@channel = channel
|
17
21
|
@triggers = triggers.map do |trigger, rules|
|
18
22
|
Rollbar::Notification::Trigger.new(channel, trigger, rules, variables)
|
19
23
|
end
|
@@ -21,12 +25,12 @@ module Rollbar
|
|
21
25
|
|
22
26
|
# @return [String]
|
23
27
|
def to_s
|
24
|
-
@triggers.map(&:to_s).join.chomp
|
28
|
+
"# #{CHANNEL_TO_TEXT.fetch(@channel)}\n#{@triggers.map(&:to_s).join.chomp}"
|
25
29
|
end
|
26
30
|
|
27
31
|
# @param provider [String]
|
28
|
-
def to_tf(provider)
|
29
|
-
@triggers.map { |t| t.to_tf(provider) }.join("\n")
|
32
|
+
def to_tf(provider, namespace)
|
33
|
+
@triggers.map { |t| t.to_tf(provider, namespace) }.join("\n")
|
30
34
|
end
|
31
35
|
end
|
32
36
|
end
|
@@ -17,6 +17,20 @@ module Rollbar
|
|
17
17
|
@value = value
|
18
18
|
end
|
19
19
|
|
20
|
+
# @param other [Object]
|
21
|
+
# @return [Boolean]
|
22
|
+
def ==(other)
|
23
|
+
self.class == other.class &&
|
24
|
+
type == other.type &&
|
25
|
+
operation == other.operation &&
|
26
|
+
value == other.value
|
27
|
+
end
|
28
|
+
alias :eql? :==
|
29
|
+
|
30
|
+
def hash
|
31
|
+
[self.class, type, operation, value].hash
|
32
|
+
end
|
33
|
+
|
20
34
|
def to_tf
|
21
35
|
<<~TF
|
22
36
|
filters {
|
@@ -28,6 +28,18 @@ module Rollbar
|
|
28
28
|
@path = path
|
29
29
|
end
|
30
30
|
|
31
|
+
# @param other [Object]
|
32
|
+
# @return [Boolean]
|
33
|
+
def ==(other)
|
34
|
+
super && path == other.path
|
35
|
+
end
|
36
|
+
alias :eql? :==
|
37
|
+
|
38
|
+
def hash
|
39
|
+
[self.class, type, operation, value, path].hash
|
40
|
+
end
|
41
|
+
|
42
|
+
|
31
43
|
def to_tf
|
32
44
|
<<~TF
|
33
45
|
filters {
|
@@ -40,14 +40,32 @@ module Rollbar
|
|
40
40
|
super
|
41
41
|
end
|
42
42
|
|
43
|
+
# @param other [Object]
|
44
|
+
# @return [Boolean]
|
45
|
+
def ==(other)
|
46
|
+
self.class == other.class &&
|
47
|
+
conditions == other.conditions &&
|
48
|
+
configs == other.configs
|
49
|
+
end
|
50
|
+
|
43
51
|
# @return [Rule]
|
44
52
|
def remove_redundant_conditions!
|
53
|
+
@conditions.uniq!
|
45
54
|
@conditions.delete_if do |condition|
|
46
55
|
@conditions.any? { |other| condition.redundant_to?(other) }
|
47
56
|
end
|
48
57
|
self
|
49
58
|
end
|
50
59
|
|
60
|
+
def never_met?
|
61
|
+
@conditions.each.with_index.any? do |condition, i|
|
62
|
+
@conditions[i + 1 ..].any? do |other|
|
63
|
+
next false unless condition.respond_to?(:build_complement_condition)
|
64
|
+
other == condition.build_complement_condition
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
51
69
|
# @param old_condition [Condition::Base]
|
52
70
|
# @param new_condition [Condition::Base]
|
53
71
|
# @return [Rule]
|
@@ -101,37 +119,33 @@ module Rollbar
|
|
101
119
|
# @param new_conditions [Condition::Base, Array<Condition::Base>]
|
102
120
|
# @return [Rule]
|
103
121
|
def add_conditions!(new_conditions)
|
104
|
-
Array(new_conditions)
|
105
|
-
@conditions << new_condition
|
106
|
-
end
|
122
|
+
@conditions.concat(Array(new_conditions))
|
107
123
|
self
|
108
124
|
end
|
109
125
|
|
110
|
-
# @return [Hash{String => Array<Condition::Base
|
126
|
+
# @return [Hash{String => Array<Array<Condition::Base>>}]
|
111
127
|
def build_additional_conditions_set_for_subsequent_rules
|
112
128
|
target_levels = level_condition&.target_level_values || Rollbar::Notification::Condition::Level::SUPPORTED_VALUES
|
113
129
|
|
114
130
|
conditions_with_complement = @conditions.select { |c| c.respond_to?(:build_complement_condition) }
|
115
131
|
return {} if conditions_with_complement.empty?
|
116
132
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
# ]
|
130
|
-
additional_conditions = conditions_with_complement.map do |condition|
|
131
|
-
[condition, condition.build_complement_condition]
|
132
|
-
end.reduce(&:product).map(&:flatten) - [conditions_with_complement]
|
133
|
+
# [cond1, cond2, cond3]
|
134
|
+
# => [
|
135
|
+
# [cond1, cond2, not-cond3],
|
136
|
+
# [cond1, not-cond2, cond3],
|
137
|
+
# [cond1, not-cond2, not-cond3],
|
138
|
+
# [not-cond1, cond2, cond3],
|
139
|
+
# [not-cond1, cond2, not-cond3],
|
140
|
+
# [not-cond1, not-cond2, cond3],
|
141
|
+
# [not-cond1, not-cond2, not-cond3],
|
142
|
+
# ]
|
143
|
+
first_cond, *other_conds = conditions_with_complement.map do |condition|
|
144
|
+
[condition, condition.build_complement_condition]
|
133
145
|
end
|
134
|
-
|
146
|
+
additional_conditions_set = first_cond.product(*other_conds) - [conditions_with_complement]
|
147
|
+
|
148
|
+
target_levels.zip([additional_conditions_set].cycle).to_h
|
135
149
|
end
|
136
150
|
|
137
151
|
private
|
@@ -71,13 +71,13 @@ module Rollbar
|
|
71
71
|
str
|
72
72
|
end
|
73
73
|
|
74
|
-
def to_tf(provider)
|
74
|
+
def to_tf(provider, namespace)
|
75
75
|
i = -1
|
76
76
|
build_mutually_exclusive_rules.flat_map do |rule|
|
77
77
|
rule.configs.map do |config|
|
78
78
|
i += 1
|
79
79
|
TF_TEMPLATE.result_with_hash({
|
80
|
-
resource_name: "#{@channel}_#{@name}_#{i}",
|
80
|
+
resource_name: "#{namespace}#{@channel}_#{@name}_#{i}",
|
81
81
|
provider: provider,
|
82
82
|
channel: @channel,
|
83
83
|
trigger: @name,
|
@@ -102,9 +102,12 @@ module Rollbar
|
|
102
102
|
new_rules << new_rule
|
103
103
|
else
|
104
104
|
additional_conditions_set.each do |additional_conditions|
|
105
|
-
|
106
|
-
|
107
|
-
|
105
|
+
new_rule_with_additional_conds = new_rule.dup
|
106
|
+
.add_conditions!(additional_conditions)
|
107
|
+
.remove_redundant_conditions!
|
108
|
+
unless new_rule_with_additional_conds.never_met?
|
109
|
+
new_rules << new_rule_with_additional_conds
|
110
|
+
end
|
108
111
|
end
|
109
112
|
end
|
110
113
|
end
|
@@ -114,7 +117,15 @@ module Rollbar
|
|
114
117
|
highest_lowest_target_level = lowest_target_level
|
115
118
|
end
|
116
119
|
level_value_to_additional_conditions_set.merge!(rule.build_additional_conditions_set_for_subsequent_rules) do |_, v1, v2|
|
117
|
-
v1.product(v2).map(&:flatten)
|
120
|
+
additional_conditions_set = v1.product(v2).map(&:flatten)
|
121
|
+
|
122
|
+
additional_conditions_set.reject! do |conditions|
|
123
|
+
conditions.each.with_index.any? do |condition, i|
|
124
|
+
conditions[i + 1 ..].any? { |other| other == condition.build_complement_condition }
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
additional_conditions_set
|
118
129
|
end
|
119
130
|
end
|
120
131
|
|
data/lib/rollbar/notification.rb
CHANGED
@@ -5,11 +5,6 @@ require "rollbar/notification/channel"
|
|
5
5
|
|
6
6
|
module Rollbar
|
7
7
|
class Notification
|
8
|
-
CHANNEL_TO_TEXT = {
|
9
|
-
"slack" => "Slack",
|
10
|
-
"pagerduty" => "PagerDuty",
|
11
|
-
}
|
12
|
-
|
13
8
|
# @param config_file [String]
|
14
9
|
def initialize(config_file)
|
15
10
|
@config = YAML.load_file(config_file)
|
@@ -22,12 +17,12 @@ module Rollbar
|
|
22
17
|
|
23
18
|
# @return [String]
|
24
19
|
def to_s
|
25
|
-
|
20
|
+
@channel.to_s
|
26
21
|
end
|
27
22
|
|
28
23
|
# @return [String]
|
29
24
|
def to_tf
|
30
|
-
@channel.to_tf(@config["terraform_provider"])
|
25
|
+
@channel.to_tf(@config["terraform_provider"], @config["terraform_namespace"])
|
31
26
|
end
|
32
27
|
end
|
33
28
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rollbar-notification-rules-generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- abicky
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-12-
|
11
|
+
date: 2022-12-20 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: This tool generates Rollbar notification rules that are mutually exclusive
|
14
14
|
from a simple YAML file.
|