Skip to content

Commit 5ccff05

Browse files
authored
feat: Adds AppDynamics Integration (#7)
1 parent 24e978e commit 5ccff05

8 files changed

Lines changed: 185 additions & 2 deletions

File tree

CREATING_AN_INTEGRATION.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
You can run the following generator to create a new integration:
44

55
```bash
6-
rails g scaffold integration #{vendor}/#{version}
6+
rails g integration #{vendor}/#{version}
77
```
88

99
This will create:

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
pager_tree-integrations (1.0.0)
4+
pager_tree-integrations (1.0.1)
55
rails (>= 7.0.1)
66

77
GEM
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
module PagerTree::Integrations
2+
class AppDynamics::V3 < Integration
3+
OPTIONS = []
4+
store_accessor :options, *OPTIONS.map { |x| x[:key] }.map(&:to_s), prefix: "option"
5+
6+
def adapter_supports_incoming?
7+
true
8+
end
9+
10+
def adapter_action
11+
if _is_create?
12+
:create
13+
elsif _is_resolve?
14+
:resolve
15+
else
16+
:other
17+
end
18+
end
19+
20+
def adapter_thirdparty_id
21+
_thirdparty_id
22+
end
23+
24+
def adapter_process_create
25+
Alert.new(
26+
title: _title,
27+
description: _description,
28+
thirdparty_id: _thirdparty_id,
29+
dedup_keys: [_thirdparty_id],
30+
additional_data: _additional_datums
31+
)
32+
end
33+
34+
private
35+
36+
def _thirdparty_id
37+
adapter_incoming_request_params.dig("details", "event_id")
38+
end
39+
40+
def _state
41+
adapter_incoming_request_params.dig("event_type")
42+
end
43+
44+
def _is_create?
45+
_state == "trigger"
46+
end
47+
48+
def _is_resolve?
49+
_state == "resolve"
50+
end
51+
52+
def _title
53+
adapter_incoming_request_params.dig("incident_key")
54+
end
55+
56+
def _description
57+
[
58+
adapter_incoming_request_params.dig("description"),
59+
adapter_incoming_request_params.dig("details", "summary")
60+
].join("\n\n")
61+
end
62+
63+
def _additional_datums
64+
[
65+
AdditionalDatum.new(format: "text", label: "Event Name", value: adapter_incoming_request_params.dig("details", "event_name")),
66+
AdditionalDatum.new(format: "datetime", label: "Event Time", value: adapter_incoming_request_params.dig("details", "event_time")),
67+
AdditionalDatum.new(format: "text", label: "Application Name", value: adapter_incoming_request_params.dig("details", "application_name")),
68+
AdditionalDatum.new(format: "text", label: "Node Name", value: adapter_incoming_request_params.dig("details", "node_name")),
69+
AdditionalDatum.new(format: "img", label: adapter_incoming_request_params.dig("contexts", 0, "alt"), value: adapter_incoming_request_params.dig("contexts", 0, "src")),
70+
AdditionalDatum.new(format: "link", label: adapter_incoming_request_params.dig("contexts", 1, "text"), value: adapter_incoming_request_params.dig("contexts", 1, "href"))
71+
]
72+
end
73+
end
74+
end

app/models/pager_tree/integrations/integration.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ def adapter_action
5050

5151
def adapter_process_create
5252
end
53+
54+
def adapter_process_other
55+
end
5356
# END basic incoming functions
5457

5558
# START basic outgoing functions

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

Whitespace-only changes.

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

Whitespace-only changes.

test/fixtures/pager_tree/integrations/integrations.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ apex_ping_v3:
44
type: "PagerTree::Integrations::ApexPing::V3"
55
# options: no_options
66

7+
app_dynamics_v3:
8+
type: "PagerTree::Integrations::AppDynamics::V3"
9+
# options: no_options
10+
711
outgoing_webhook_v3:
812
type: "PagerTree::Integrations::OutgoingWebhook::V3"
913
options:
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
require "test_helper"
2+
3+
module PagerTree::Integrations
4+
class AppDynamics::V3Test < ActiveSupport::TestCase
5+
include Integrateable
6+
7+
setup do
8+
@integration = pager_tree_integrations_integrations(:app_dynamics_v3)
9+
10+
# TODO: Write some requests to test the integration
11+
@create_request = {
12+
incident_key: "${latestEvent.node.name} - ${latestEvent.application.name}",
13+
event_type: "trigger",
14+
description: "${latestEvent.displayName} on ${latestEvent.node.name}",
15+
client: "AppDynamics",
16+
client_url: "${controllerUrl}",
17+
details: {
18+
event_name: "${latestEvent.displayName}",
19+
summary: "${latestEvent.summaryMessage}",
20+
event_id: "${latestEvent.id}",
21+
guid: "${latestEvent.guid}",
22+
event_time: "${latestEvent.eventTime}",
23+
event_type: "${latestEvent.eventType}",
24+
event_type_key: "${latestEvent.eventTypeKey}",
25+
application_name: "${latestEvent.application.name}",
26+
node_name: "${latestEvent.node.name}",
27+
message: "${latestEvent.eventMessage}",
28+
severity: "${latestEvent.severity}"
29+
},
30+
contexts: [
31+
{
32+
type: "image",
33+
src: "${latestEvent.severityImage.deepLink}",
34+
alt: "${latestEvent.severity}"
35+
},
36+
{
37+
type: "link",
38+
href: "${latestEvent.deepLink}",
39+
text: "View this transaction in AppDynamics"
40+
}
41+
]
42+
}.with_indifferent_access
43+
44+
@resolve_request = @create_request.deep_dup
45+
@resolve_request[:event_type] = "resolve"
46+
47+
@other_request = @create_request.deep_dup
48+
@other_request[:event_type] = "baaad"
49+
end
50+
51+
test "sanity" do
52+
# TODO: Check some sane defaults your integration should have
53+
assert @integration.adapter_supports_incoming?
54+
assert @integration.adapter_incoming_can_defer?
55+
assert_not @integration.adapter_supports_outgoing?
56+
assert @integration.adapter_show_alerts?
57+
assert @integration.adapter_show_logs?
58+
assert_not @integration.adapter_show_outgoing_webhook_delivery?
59+
end
60+
61+
test "adapter_actions" do
62+
# TODO: Check that the adapter_actions returns expected results based on the inputs
63+
@integration.adapter_incoming_request_params = @create_request
64+
assert_equal :create, @integration.adapter_action
65+
66+
@integration.adapter_incoming_request_params = @resolve_request
67+
assert_equal :resolve, @integration.adapter_action
68+
69+
@integration.adapter_incoming_request_params = @other_request
70+
assert_equal :other, @integration.adapter_action
71+
end
72+
73+
test "adapter_thirdparty_id" do
74+
# TODO: Check that the third party id comes back as expected
75+
@integration.adapter_incoming_request_params = @create_request
76+
assert_equal "${latestEvent.id}", @integration.adapter_thirdparty_id
77+
end
78+
79+
test "adapter_process_create" do
80+
# TODO: Check tthe entire transform
81+
@integration.adapter_incoming_request_params = @create_request
82+
83+
true_alert = Alert.new(
84+
title: "${latestEvent.node.name} - ${latestEvent.application.name}",
85+
description: "${latestEvent.displayName} on ${latestEvent.node.name}\n\n${latestEvent.summaryMessage}",
86+
urgency: nil,
87+
thirdparty_id: "${latestEvent.id}",
88+
dedup_keys: ["${latestEvent.id}"],
89+
additional_data: [
90+
AdditionalDatum.new(format: "text", label: "Event Name", value: "${latestEvent.displayName}"),
91+
AdditionalDatum.new(format: "datetime", label: "Event Time", value: "${latestEvent.eventTime}"),
92+
AdditionalDatum.new(format: "text", label: "Application Name", value: "${latestEvent.application.name}"),
93+
AdditionalDatum.new(format: "text", label: "Node Name", value: "${latestEvent.node.name}"),
94+
AdditionalDatum.new(format: "img", label: "${latestEvent.severity}", value: "${latestEvent.severityImage.deepLink}"),
95+
AdditionalDatum.new(format: "link", label: "View this transaction in AppDynamics", value: "${latestEvent.deepLink}")
96+
]
97+
)
98+
99+
assert_equal true_alert.to_json, @integration.adapter_process_create.to_json
100+
end
101+
end
102+
end

0 commit comments

Comments
 (0)