Skip to content

Commit 400ef61

Browse files
committed
Fix Logic Monitor HMAC authentication
1 parent 2e600b0 commit 400ef61

File tree

2 files changed

+10
-8
lines changed
  • app/models/pager_tree/integrations/logic_monitor
  • test/models/pager_tree/integrations/logic_monitor

2 files changed

+10
-8
lines changed

Diff for: app/models/pager_tree/integrations/logic_monitor/v3.rb

+5-4
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def adapter_incoming_can_defer?
3838
end
3939

4040
def adapter_thirdparty_id
41-
adapter_incoming_request_params.dig("alertid")
41+
adapter_incoming_request_params.dig("internalid")
4242
end
4343

4444
def adapter_action
@@ -118,9 +118,10 @@ def send_request_with_hmac(resource_path, http_verb, data)
118118
url = base_url + resource_path
119119
timestamp_ms = Time.current.to_i * 1000
120120
data_string = data.to_json
121-
signature = Base64.strict_encode64(
122-
OpenSSL::HMAC.digest(
123-
OpenSSL::Digest.new("sha256"),
121+
# https://gist.github.com/abeland/e09a559e243f70670f2f4da3fd0fdabd
122+
signature = Base64.urlsafe_encode64(
123+
OpenSSL::HMAC.hexdigest(
124+
"SHA256",
124125
option_access_key,
125126
(http_verb.upcase + timestamp_ms.to_s + data_string + resource_path)
126127
)

Diff for: test/models/pager_tree/integrations/logic_monitor/v3_test.rb

+5-4
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ class LogicMonitor::V3Test < ActiveSupport::TestCase
4343
servicedetail: nil,
4444
serviceurl: "https://pagertree-test-server.net/",
4545
servicegroup: "Functional Testing",
46-
clearvalue: "1"
46+
clearvalue: "1",
47+
internalid: "1234567890"
4748
}.with_indifferent_access
4849

4950
@resolve_request = @create_request.deep_dup
@@ -81,7 +82,7 @@ class LogicMonitor::V3Test < ActiveSupport::TestCase
8182

8283
test "adapter_thirdparty_id" do
8384
@integration.adapter_incoming_request_params = @create_request
84-
assert_equal @create_request.dig("alertid"), @integration.adapter_thirdparty_id
85+
assert_equal @create_request.dig("internalid"), @integration.adapter_thirdparty_id
8586
end
8687

8788
test "adapter_process_create" do
@@ -91,7 +92,7 @@ class LogicMonitor::V3Test < ActiveSupport::TestCase
9192
title: @create_request.dig("eventmsg"),
9293
description: @create_request.dig("eventlogmsg"),
9394
urgency: "medium",
94-
thirdparty_id: @create_request.dig("alertid"),
95+
thirdparty_id: @create_request.dig("internalid"),
9596
dedup_keys: [],
9697
additional_data: [
9798
AdditionalDatum.new(format: "text", label: "Host", value: @create_request.dig("host")),
@@ -112,7 +113,7 @@ class LogicMonitor::V3Test < ActiveSupport::TestCase
112113
outgoing_event = OutgoingEvent.new
113114
outgoing_event.event_name = :alert_acknowledged
114115
outgoing_event.alert = OpenStruct.new(
115-
thirdparty_id: "LMS22",
116+
thirdparty_id: "1234567890",
116117
foo: "bar",
117118
source: @integration
118119
)

0 commit comments

Comments
 (0)