Skip to content

Commit

Permalink
feat: Adds AppDynamics Integration (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
armiiller authored Feb 28, 2022
1 parent 24e978e commit 5ccff05
Show file tree
Hide file tree
Showing 8 changed files with 185 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CREATING_AN_INTEGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
You can run the following generator to create a new integration:

```bash
rails g scaffold integration #{vendor}/#{version}
rails g integration #{vendor}/#{version}
```

This will create:
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
pager_tree-integrations (1.0.0)
pager_tree-integrations (1.0.1)
rails (>= 7.0.1)

GEM
Expand Down
74 changes: 74 additions & 0 deletions app/models/pager_tree/integrations/app_dynamics/v3.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
module PagerTree::Integrations
class AppDynamics::V3 < Integration
OPTIONS = []
store_accessor :options, *OPTIONS.map { |x| x[:key] }.map(&:to_s), prefix: "option"

def adapter_supports_incoming?
true
end

def adapter_action
if _is_create?
:create
elsif _is_resolve?
:resolve
else
:other
end
end

def adapter_thirdparty_id
_thirdparty_id
end

def adapter_process_create
Alert.new(
title: _title,
description: _description,
thirdparty_id: _thirdparty_id,
dedup_keys: [_thirdparty_id],
additional_data: _additional_datums
)
end

private

def _thirdparty_id
adapter_incoming_request_params.dig("details", "event_id")
end

def _state
adapter_incoming_request_params.dig("event_type")
end

def _is_create?
_state == "trigger"
end

def _is_resolve?
_state == "resolve"
end

def _title
adapter_incoming_request_params.dig("incident_key")
end

def _description
[
adapter_incoming_request_params.dig("description"),
adapter_incoming_request_params.dig("details", "summary")
].join("\n\n")
end

def _additional_datums
[
AdditionalDatum.new(format: "text", label: "Event Name", value: adapter_incoming_request_params.dig("details", "event_name")),
AdditionalDatum.new(format: "datetime", label: "Event Time", value: adapter_incoming_request_params.dig("details", "event_time")),
AdditionalDatum.new(format: "text", label: "Application Name", value: adapter_incoming_request_params.dig("details", "application_name")),
AdditionalDatum.new(format: "text", label: "Node Name", value: adapter_incoming_request_params.dig("details", "node_name")),
AdditionalDatum.new(format: "img", label: adapter_incoming_request_params.dig("contexts", 0, "alt"), value: adapter_incoming_request_params.dig("contexts", 0, "src")),
AdditionalDatum.new(format: "link", label: adapter_incoming_request_params.dig("contexts", 1, "text"), value: adapter_incoming_request_params.dig("contexts", 1, "href"))
]
end
end
end
3 changes: 3 additions & 0 deletions app/models/pager_tree/integrations/integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ def adapter_action

def adapter_process_create
end

def adapter_process_other
end
# END basic incoming functions

# START basic outgoing functions
Expand Down
Empty file.
Empty file.
4 changes: 4 additions & 0 deletions test/fixtures/pager_tree/integrations/integrations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ apex_ping_v3:
type: "PagerTree::Integrations::ApexPing::V3"
# options: no_options

app_dynamics_v3:
type: "PagerTree::Integrations::AppDynamics::V3"
# options: no_options

outgoing_webhook_v3:
type: "PagerTree::Integrations::OutgoingWebhook::V3"
options:
Expand Down
102 changes: 102 additions & 0 deletions test/models/pager_tree/integrations/app_dynamics/v3_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
require "test_helper"

module PagerTree::Integrations
class AppDynamics::V3Test < ActiveSupport::TestCase
include Integrateable

setup do
@integration = pager_tree_integrations_integrations(:app_dynamics_v3)

# TODO: Write some requests to test the integration
@create_request = {
incident_key: "${latestEvent.node.name} - ${latestEvent.application.name}",
event_type: "trigger",
description: "${latestEvent.displayName} on ${latestEvent.node.name}",
client: "AppDynamics",
client_url: "${controllerUrl}",
details: {
event_name: "${latestEvent.displayName}",
summary: "${latestEvent.summaryMessage}",
event_id: "${latestEvent.id}",
guid: "${latestEvent.guid}",
event_time: "${latestEvent.eventTime}",
event_type: "${latestEvent.eventType}",
event_type_key: "${latestEvent.eventTypeKey}",
application_name: "${latestEvent.application.name}",
node_name: "${latestEvent.node.name}",
message: "${latestEvent.eventMessage}",
severity: "${latestEvent.severity}"
},
contexts: [
{
type: "image",
src: "${latestEvent.severityImage.deepLink}",
alt: "${latestEvent.severity}"
},
{
type: "link",
href: "${latestEvent.deepLink}",
text: "View this transaction in AppDynamics"
}
]
}.with_indifferent_access

@resolve_request = @create_request.deep_dup
@resolve_request[:event_type] = "resolve"

@other_request = @create_request.deep_dup
@other_request[:event_type] = "baaad"
end

test "sanity" do
# TODO: Check some sane defaults your integration should have
assert @integration.adapter_supports_incoming?
assert @integration.adapter_incoming_can_defer?
assert_not @integration.adapter_supports_outgoing?
assert @integration.adapter_show_alerts?
assert @integration.adapter_show_logs?
assert_not @integration.adapter_show_outgoing_webhook_delivery?
end

test "adapter_actions" do
# TODO: Check that the adapter_actions returns expected results based on the inputs
@integration.adapter_incoming_request_params = @create_request
assert_equal :create, @integration.adapter_action

@integration.adapter_incoming_request_params = @resolve_request
assert_equal :resolve, @integration.adapter_action

@integration.adapter_incoming_request_params = @other_request
assert_equal :other, @integration.adapter_action
end

test "adapter_thirdparty_id" do
# TODO: Check that the third party id comes back as expected
@integration.adapter_incoming_request_params = @create_request
assert_equal "${latestEvent.id}", @integration.adapter_thirdparty_id
end

test "adapter_process_create" do
# TODO: Check tthe entire transform
@integration.adapter_incoming_request_params = @create_request

true_alert = Alert.new(
title: "${latestEvent.node.name} - ${latestEvent.application.name}",
description: "${latestEvent.displayName} on ${latestEvent.node.name}\n\n${latestEvent.summaryMessage}",
urgency: nil,
thirdparty_id: "${latestEvent.id}",
dedup_keys: ["${latestEvent.id}"],
additional_data: [
AdditionalDatum.new(format: "text", label: "Event Name", value: "${latestEvent.displayName}"),
AdditionalDatum.new(format: "datetime", label: "Event Time", value: "${latestEvent.eventTime}"),
AdditionalDatum.new(format: "text", label: "Application Name", value: "${latestEvent.application.name}"),
AdditionalDatum.new(format: "text", label: "Node Name", value: "${latestEvent.node.name}"),
AdditionalDatum.new(format: "img", label: "${latestEvent.severity}", value: "${latestEvent.severityImage.deepLink}"),
AdditionalDatum.new(format: "link", label: "View this transaction in AppDynamics", value: "${latestEvent.deepLink}")
]
)

assert_equal true_alert.to_json, @integration.adapter_process_create.to_json
end
end
end

0 comments on commit 5ccff05

Please sign in to comment.