Skip to content

Commit

Permalink
Fix Logic Monitor HMAC authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
armiiller committed Oct 12, 2023
1 parent 2e600b0 commit 400ef61
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
9 changes: 5 additions & 4 deletions app/models/pager_tree/integrations/logic_monitor/v3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def adapter_incoming_can_defer?
end

def adapter_thirdparty_id
adapter_incoming_request_params.dig("alertid")
adapter_incoming_request_params.dig("internalid")
end

def adapter_action
Expand Down Expand Up @@ -118,9 +118,10 @@ def send_request_with_hmac(resource_path, http_verb, data)
url = base_url + resource_path
timestamp_ms = Time.current.to_i * 1000
data_string = data.to_json
signature = Base64.strict_encode64(
OpenSSL::HMAC.digest(
OpenSSL::Digest.new("sha256"),
# https://gist.github.com/abeland/e09a559e243f70670f2f4da3fd0fdabd
signature = Base64.urlsafe_encode64(
OpenSSL::HMAC.hexdigest(
"SHA256",
option_access_key,
(http_verb.upcase + timestamp_ms.to_s + data_string + resource_path)
)
Expand Down
9 changes: 5 additions & 4 deletions test/models/pager_tree/integrations/logic_monitor/v3_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ class LogicMonitor::V3Test < ActiveSupport::TestCase
servicedetail: nil,
serviceurl: "https://pagertree-test-server.net/",
servicegroup: "Functional Testing",
clearvalue: "1"
clearvalue: "1",
internalid: "1234567890"
}.with_indifferent_access

@resolve_request = @create_request.deep_dup
Expand Down Expand Up @@ -81,7 +82,7 @@ class LogicMonitor::V3Test < ActiveSupport::TestCase

test "adapter_thirdparty_id" do
@integration.adapter_incoming_request_params = @create_request
assert_equal @create_request.dig("alertid"), @integration.adapter_thirdparty_id
assert_equal @create_request.dig("internalid"), @integration.adapter_thirdparty_id
end

test "adapter_process_create" do
Expand All @@ -91,7 +92,7 @@ class LogicMonitor::V3Test < ActiveSupport::TestCase
title: @create_request.dig("eventmsg"),
description: @create_request.dig("eventlogmsg"),
urgency: "medium",
thirdparty_id: @create_request.dig("alertid"),
thirdparty_id: @create_request.dig("internalid"),
dedup_keys: [],
additional_data: [
AdditionalDatum.new(format: "text", label: "Host", value: @create_request.dig("host")),
Expand All @@ -112,7 +113,7 @@ class LogicMonitor::V3Test < ActiveSupport::TestCase
outgoing_event = OutgoingEvent.new
outgoing_event.event_name = :alert_acknowledged
outgoing_event.alert = OpenStruct.new(
thirdparty_id: "LMS22",
thirdparty_id: "1234567890",
foo: "bar",
source: @integration
)
Expand Down

0 comments on commit 400ef61

Please sign in to comment.