Skip to content

Commit c484b20

Browse files
authored
Auvik Integration (#19)
1 parent 54d8960 commit c484b20

14 files changed

Lines changed: 214 additions & 21 deletions

File tree

.github/workflows/ci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ jobs:
4141
bundler: default
4242
bundler-cache: true
4343
- name: StandardRb check
44-
run: bundle exec standardrb
44+
run: |
45+
bundle exec standardrb -v
46+
bundle exec standardrb
4547
- name: Run tests
4648
env:
4749
DATABASE_URL: postgres://postgres:password@localhost:5432/test

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ group :development, :test do
1212
gem "dotenv-rails", "~> 2.7" # .env files
1313
# Start debugger with binding.b [https://github.com/ruby/debug]
1414
gem "debug", ">= 1.0.0"
15+
gem "standard", "1.12.0"
1516
gem "vcr", "~> 6.0"
1617
end
1718

Gemfile.lock

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,8 @@ GEM
176176
nio4r (2.5.8)
177177
nokogiri (1.13.3-x86_64-linux)
178178
racc (~> 1.4)
179-
parallel (1.21.0)
180-
parser (3.1.1.0)
179+
parallel (1.22.1)
180+
parser (3.1.2.0)
181181
ast (~> 2.4.1)
182182
pg (1.3.2)
183183
public_suffix (4.0.6)
@@ -213,22 +213,22 @@ GEM
213213
zeitwerk (~> 2.5)
214214
rainbow (3.1.1)
215215
rake (13.0.6)
216-
regexp_parser (2.2.1)
216+
regexp_parser (2.4.0)
217217
reline (0.3.1)
218218
io-console (~> 0.5)
219219
rexml (3.2.5)
220-
rubocop (1.25.1)
220+
rubocop (1.29.0)
221221
parallel (~> 1.10)
222222
parser (>= 3.1.0.0)
223223
rainbow (>= 2.2.2, < 4.0)
224224
regexp_parser (>= 1.8, < 3.0)
225-
rexml
226-
rubocop-ast (>= 1.15.1, < 2.0)
225+
rexml (>= 3.2.5, < 4.0)
226+
rubocop-ast (>= 1.17.0, < 2.0)
227227
ruby-progressbar (~> 1.7)
228228
unicode-display_width (>= 1.4.0, < 3.0)
229-
rubocop-ast (1.16.0)
229+
rubocop-ast (1.17.0)
230230
parser (>= 3.1.1.0)
231-
rubocop-performance (1.13.2)
231+
rubocop-performance (1.13.3)
232232
rubocop (>= 1.7.0, < 2.0)
233233
rubocop-ast (>= 0.4.0)
234234
ruby-progressbar (1.11.0)
@@ -243,11 +243,9 @@ GEM
243243
actionpack (>= 5.2)
244244
activesupport (>= 5.2)
245245
sprockets (>= 3.0.0)
246-
standard (1.7.2)
247-
rubocop (= 1.25.1)
248-
rubocop-performance (= 1.13.2)
249-
standardrb (1.0.1)
250-
standard
246+
standard (1.12.0)
247+
rubocop (= 1.29.0)
248+
rubocop-performance (= 1.13.3)
251249
strscan (3.0.1)
252250
thor (1.2.1)
253251
timeout (0.2.0)
@@ -286,7 +284,7 @@ DEPENDENCIES
286284
pg (~> 1.3)
287285
sanitize (~> 6.0)
288286
sprockets-rails
289-
standardrb
287+
standard (= 1.12.0)
290288
twilio-ruby (~> 5.64)
291289
ulid (~> 1.3)
292290
validate_url (~> 1.0)
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
module PagerTree::Integrations
2+
class Auvik::V3 < Integration
3+
AUVIK_SEVERITY = {
4+
emergency: 1,
5+
critical: 2,
6+
warning: 3,
7+
info: 4
8+
}
9+
10+
OPTIONS = []
11+
store_accessor :options, *OPTIONS.map { |x| x[:key] }.map(&:to_s), prefix: "option"
12+
13+
after_initialize do
14+
end
15+
16+
def adapter_supports_incoming?
17+
true
18+
end
19+
20+
def adapter_supports_outgoing?
21+
false
22+
end
23+
24+
def adapter_incoming_can_defer?
25+
true
26+
end
27+
28+
def adapter_thirdparty_id
29+
_correlation_id
30+
end
31+
32+
def adapter_action
33+
case _alert_status
34+
when 0 then :create
35+
when 1 then :resolve
36+
else
37+
:other
38+
end
39+
end
40+
41+
def adapter_process_create
42+
Alert.new(
43+
title: _title,
44+
description: _description,
45+
urgency: _urgency,
46+
thirdparty_id: adapter_thirdparty_id,
47+
dedup_keys: [adapter_thirdparty_id],
48+
additional_data: _additional_datums
49+
)
50+
end
51+
52+
private
53+
54+
def _correlation_id
55+
adapter_incoming_request_params.dig("correlationId")
56+
end
57+
58+
def _alert_status
59+
adapter_incoming_request_params.dig("alertStatus")
60+
end
61+
62+
def _title
63+
adapter_incoming_request_params.dig("alertName")
64+
end
65+
66+
def _description
67+
adapter_incoming_request_params.dig("alertDescription")
68+
end
69+
70+
def _urgency
71+
case adapter_incoming_request_params.dig("alertSeverity")
72+
when AUVIK_SEVERITY[:info] then "low"
73+
when AUVIK_SEVERITY[:warning] then "medium"
74+
when AUVIK_SEVERITY[:critical] then "high"
75+
when AUVIK_SEVERITY[:emergency] then "critical"
76+
end
77+
end
78+
79+
def _additional_datums
80+
[
81+
AdditionalDatum.new(format: "link", label: "URL", value: adapter_incoming_request_params.dig("link")),
82+
AdditionalDatum.new(format: "text", label: "Alert Severity", value: adapter_incoming_request_params.dig("alertSeverityString")),
83+
AdditionalDatum.new(format: "text", label: "Correlation ID", value: adapter_incoming_request_params.dig("correlationId")),
84+
AdditionalDatum.new(format: "text", label: "Alert ID", value: adapter_incoming_request_params.dig("alertId")),
85+
AdditionalDatum.new(format: "text", label: "Entity ID", value: adapter_incoming_request_params.dig("entityId")),
86+
AdditionalDatum.new(format: "text", label: "Entity Name", value: adapter_incoming_request_params.dig("entityName")),
87+
AdditionalDatum.new(format: "text", label: "Entity Type", value: adapter_incoming_request_params.dig("entityType")),
88+
AdditionalDatum.new(format: "text", label: "Entity ID", value: adapter_incoming_request_params.dig("entityId")),
89+
AdditionalDatum.new(format: "text", label: "Company Name", value: adapter_incoming_request_params.dig("companyName")),
90+
AdditionalDatum.new(format: "datetime", label: "Date", value: adapter_incoming_request_params.dig("date"))
91+
]
92+
end
93+
end
94+
end

app/models/pager_tree/integrations/outgoing_webhook_delivery.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class OutgoingWebhookDelivery < PagerTree::Integrations.outgoing_webhook_deliver
88
store_accessor :data, *[:url, :body, :auth].map(&:to_s)
99

1010
HTTP_OPTIONS = {
11-
headers: {'Content-Type': "application/json"},
11+
headers: {"Content-Type": "application/json"},
1212
timeout: 15
1313
}
1414

app/models/pager_tree/integrations/outgoing_webhook_delivery/hook_relay.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ def deliver
4040
pagertree_options = {
4141
headers: {
4242
Accept: "*/*",
43-
'User-Agent': "pagertree outgoing webhook service; ref: #{resource&.id}; report: support@pagertree.com",
44-
'Content-Type': "application/json"
43+
"User-Agent": "pagertree outgoing webhook service; ref: #{resource&.id}; report: support@pagertree.com",
44+
"Content-Type": "application/json"
4545
}
4646
}
4747

@@ -77,15 +77,15 @@ def delivery
7777

7878
options = {
7979
headers: {
80-
'Content-Type': "application/json",
80+
"Content-Type": "application/json",
8181
Authorization: "Bearer #{OutgoingWebhookDelivery::HookRelay.hook_relay_api_key}"
8282
},
8383
timeout: 15
8484
}
8585

8686
response = ::HTTParty.get(hook_relay_delivery_url, **options)
8787
@delivery = response.parsed_response if response.success?
88-
88+
8989
@delivery || {}
9090
end
9191

app/views/pager_tree/integrations/auvik/v3/_form_options.html.erb

Whitespace-only changes.

app/views/pager_tree/integrations/auvik/v3/_show_options.html.erb

Whitespace-only changes.

config/locales/en.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ en:
77
apex_ping:
88
v3:
99
form_options:
10+
auvik:
11+
v3:
12+
form_options:
1013
email:
1114
v3:
1215
form_options:

gemfiles/rails_7.gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ gem "rails", "~> 7.0.0"
1717
group :development, :test do
1818
gem "dotenv-rails", "~> 2.7"
1919
gem "debug", ">= 1.0.0"
20+
gem "standard", "1.12.0"
2021
gem "vcr", "~> 6.0"
2122
end
2223

0 commit comments

Comments
 (0)