Skip to content

Commit

Permalink
standardrb
Browse files Browse the repository at this point in the history
  • Loading branch information
armiiller committed Apr 30, 2024
1 parent de3ad77 commit 7a4c3ed
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 97 deletions.
20 changes: 10 additions & 10 deletions app/models/pager_tree/integrations/hetrix_tools/v3.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module PagerTree::Integrations
class HetrixTools::V3 < Integration
OPTIONS = [
{key: :authentication_token, type: :string, default: nil},
{key: :authentication_token, type: :string, default: nil}
]
store_accessor :options, *OPTIONS.map { |x| x[:key] }.map(&:to_s), prefix: "option"

Expand All @@ -26,11 +26,11 @@ def adapter_incoming_can_defer?
end

def adapter_thirdparty_id
try("_adapter_thirdparty_id_#{_webhook_type.to_s}") || SecureRandom.hex(16)
try("_adapter_thirdparty_id_#{_webhook_type}") || SecureRandom.hex(16)
end

def adapter_action
try("_adapter_action_#{_webhook_type.to_s}") || :other
try("_adapter_action_#{_webhook_type}") || :other
end

def _adapter_action_uptime
Expand Down Expand Up @@ -98,7 +98,7 @@ def _webhook_type_resource_usage?
end

def _title
try("_title_#{_webhook_type.to_s}") || "HetrixTools Alert"
try("_title_#{_webhook_type}") || "HetrixTools Alert"
end

def _title_uptime
Expand All @@ -114,12 +114,12 @@ def _title_resource_usage
end

def _description
try("_description_#{_webhook_type.to_s}") || "No description provided"
try("_description_#{_webhook_type}") || "No description provided"
end

def _description_uptime
"<p>#{adapter_incoming_request_params.dig("monitor_target")} is #{adapter_incoming_request_params.dig("monitor_status")}</p>" +
adapter_incoming_request_params.dig("monitor_errors").map{ |k, v| "<p>#{k}: #{v}</p>" }.join("")
adapter_incoming_request_params.dig("monitor_errors").map { |k, v| "<p>#{k}: #{v}</p>" }.join("")
end

def _description_blacklist
Expand All @@ -128,21 +128,21 @@ def _description_blacklist

def _description_resource_usage
[
"<p>Resource Type: #{adapter_incoming_request_params.dig("resource_usage", "resource_type")}</p>",
"<p>Current Usage: #{adapter_incoming_request_params.dig("resource_usage", "current_usage")}</p>",
"<p>Resource Type: #{adapter_incoming_request_params.dig("resource_usage", "resource_type")}</p>",
"<p>Current Usage: #{adapter_incoming_request_params.dig("resource_usage", "current_usage")}</p>",
"<p>Average Usage: #{adapter_incoming_request_params.dig("resource_usage", "average_usage")} / #{adapter_incoming_request_params.dig("resource_usage", "average_minutes")}m</p>"
].join("")
end

def _additional_datums
try("_additional_datums_#{_webhook_type.to_s}") || []
try("_additional_datums_#{_webhook_type}") || []
end

def _additional_datums_uptime
[
AdditionalDatum.new(format: "datetime", label: "Timestamp", value: Time.at(adapter_incoming_request_params.dig("timestamp"))),
AdditionalDatum.new(format: "text", label: "Monitor Type", value: adapter_incoming_request_params.dig("monitor_type")),
AdditionalDatum.new(format: "link", label: "Monitor Target", value: adapter_incoming_request_params.dig("monitor_target")),
AdditionalDatum.new(format: "link", label: "Monitor Target", value: adapter_incoming_request_params.dig("monitor_target"))
]
end

Expand Down
174 changes: 87 additions & 87 deletions test/models/pager_tree/integrations/hetrix_tools/v3_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,92 +8,92 @@ class HetrixTools::V3Test < ActiveSupport::TestCase
@integration = pager_tree_integrations_integrations(:hetrix_tools_v3)

# https://docs.hetrixtools.com/uptime-monitoring-webhook-notifications/
@uptime_request = {
"monitor_id":"ThisWillBeTheMonitorID32CharLong",
"monitor_name":"Test Monitor Label",
"monitor_target":"http:\/\/this-is-a-test.com\/",
"monitor_type":"website",
"monitor_category":"Test Category",
"monitor_status":"offline",
"timestamp":1499666192,
"monitor_errors":{
"New York":"http code 403",
"San Francisco":"http code 403",
"Dallas":"timeout",
"Amsterdam":"http code 403",
"London":"http code 403",
"Frankfurt":"http code 403",
"Singapore":"timeout",
"Sydney":"http code 403",
"Sao Paulo":"http code 403",
"Tokyo":"keyword not found",
"Mumbai":"http code 403",
"Moscow":"keyword not found"
@uptime_request = {
monitor_id: "ThisWillBeTheMonitorID32CharLong",
monitor_name: "Test Monitor Label",
monitor_target: "http:\/\/this-is-a-test.com\/",
monitor_type: "website",
monitor_category: "Test Category",
monitor_status: "offline",
timestamp: 1499666192,
monitor_errors: {
"New York": "http code 403",
"San Francisco": "http code 403",
Dallas: "timeout",
Amsterdam: "http code 403",
London: "http code 403",
Frankfurt: "http code 403",
Singapore: "timeout",
Sydney: "http code 403",
"Sao Paulo": "http code 403",
Tokyo: "keyword not found",
Mumbai: "http code 403",
Moscow: "keyword not found"
}
}.with_indifferent_access

# https://docs.hetrixtools.com/blacklist-monitoring-webhook-notifications/
@blacklist_request = { "_json": [
@blacklist_request = {_json: [
{
"monitor": "98.88.89.102",
"label": "some label",
"blacklisted_before": "7",
"blacklisted_now": "6",
"blacklisted_on": [
{
"rbl": "bl.nszones.com",
"delist": "http://www.nszones.com/contact.shtml"
},
{
"rbl": "bl.score.senderscore.com",
"delist": "https://www.senderscore.org/blacklistlookup/"
},
{
"rbl": "cidr.bl.mcafee.com",
"delist": "https://kc.mcafee.com/corporate/index?page=content&id=KB53783"
},
{
"rbl": "dyn.nszones.com",
"delist": "http://db.nszones.com/dyn.ip?98.88.89.102"
},
{
"rbl": "pbl.spamhaus.org",
"delist": "https://www.spamhaus.org/query/ip/98.88.89.102"
},
{
"rbl": "zen.spamhaus.org",
"delist": "https://www.spamhaus.org/query/ip/98.88.89.102"
}
],
"links": {
"report_link": "https://hetrixtools.com/report/blacklist/c855b5712bd63a3c8153690b56d5385e/",
"whitelabel_report_link": "http://status.hetrixtools.com/report/blacklist/c855b5712bd63a3c8153690b56d5385e/"
}
monitor: "98.88.89.102",
label: "some label",
blacklisted_before: "7",
blacklisted_now: "6",
blacklisted_on: [
{
rbl: "bl.nszones.com",
delist: "http://www.nszones.com/contact.shtml"
},
{
rbl: "bl.score.senderscore.com",
delist: "https://www.senderscore.org/blacklistlookup/"
},
{
rbl: "cidr.bl.mcafee.com",
delist: "https://kc.mcafee.com/corporate/index?page=content&id=KB53783"
},
{
rbl: "dyn.nszones.com",
delist: "http://db.nszones.com/dyn.ip?98.88.89.102"
},
{
rbl: "pbl.spamhaus.org",
delist: "https://www.spamhaus.org/query/ip/98.88.89.102"
},
{
rbl: "zen.spamhaus.org",
delist: "https://www.spamhaus.org/query/ip/98.88.89.102"
}
],
links: {
report_link: "https://hetrixtools.com/report/blacklist/c855b5712bd63a3c8153690b56d5385e/",
whitelabel_report_link: "http://status.hetrixtools.com/report/blacklist/c855b5712bd63a3c8153690b56d5385e/"
}
},
{
"monitor": "190.129.206.24",
"label": "another label",
"blacklisted_before": "2",
"blacklisted_now": "0",
"blacklisted_on": nil,
"links": {
"report_link": "https://hetrixtools.com/report/blacklist/4255d1931a5c5547a0fce88e6cdff008/",
"whitelabel_report_link": "http://status.hetrixtools.com/report/blacklist/4255d1931a5c5547a0fce88e6cdff008/"
}
monitor: "190.129.206.24",
label: "another label",
blacklisted_before: "2",
blacklisted_now: "0",
blacklisted_on: nil,
links: {
report_link: "https://hetrixtools.com/report/blacklist/4255d1931a5c5547a0fce88e6cdff008/",
whitelabel_report_link: "http://status.hetrixtools.com/report/blacklist/4255d1931a5c5547a0fce88e6cdff008/"
}
}
]}.with_indifferent_access
]}.with_indifferent_access

@resource_usage_request = {
"monitor_id":"ThisWillBeTheMonitorID32CharLong",
"monitor_name":"Test Monitor Label",
"timestamp":1499666613,
"resource_usage":{
"resource_type":"cpu",
"current_usage":"24.60",
"average_usage":"25.29",
"average_minutes":"3"
}
}.with_indifferent_access
monitor_id: "ThisWillBeTheMonitorID32CharLong",
monitor_name: "Test Monitor Label",
timestamp: 1499666613,
resource_usage: {
resource_type: "cpu",
current_usage: "24.60",
average_usage: "25.29",
average_minutes: "3"
}
}.with_indifferent_access

@resolve_request = @uptime_request.deep_dup
@resolve_request["monitor_status"] = "online"
Expand All @@ -113,7 +113,7 @@ class HetrixTools::V3Test < ActiveSupport::TestCase
assert_equal :create, @integration.adapter_action
end

test "adapter_action_uptime_resolve" do
test "adapter_action_uptime_resolve" do
@integration.adapter_incoming_request_params = @resolve_request
assert_equal :resolve, @integration.adapter_action
end
Expand Down Expand Up @@ -148,14 +148,14 @@ class HetrixTools::V3Test < ActiveSupport::TestCase

true_alert = Alert.new(
title: "#{@uptime_request.dig("monitor_name")} is #{@uptime_request.dig("monitor_status")}",
description: "<p>#{@uptime_request.dig("monitor_target")} is #{@uptime_request.dig("monitor_status")}</p>" + @uptime_request.dig("monitor_errors").map{ |k, v| "<p>#{k}: #{v}</p>" }.join(""),
description: "<p>#{@uptime_request.dig("monitor_target")} is #{@uptime_request.dig("monitor_status")}</p>" + @uptime_request.dig("monitor_errors").map { |k, v| "<p>#{k}: #{v}</p>" }.join(""),
urgency: nil,
thirdparty_id: @uptime_request.dig("monitor_id"),
dedup_keys: [],
additional_data: [
AdditionalDatum.new(format: "datetime", label: "Timestamp", value: Time.at(@uptime_request.dig("timestamp"))),
AdditionalDatum.new(format: "text", label: "Monitor Type", value: @uptime_request.dig("monitor_type")),
AdditionalDatum.new(format: "link", label: "Monitor Target", value: @uptime_request.dig("monitor_target")),
AdditionalDatum.new(format: "datetime", label: "Timestamp", value: Time.at(@uptime_request.dig("timestamp"))),
AdditionalDatum.new(format: "text", label: "Monitor Type", value: @uptime_request.dig("monitor_type")),
AdditionalDatum.new(format: "link", label: "Monitor Target", value: @uptime_request.dig("monitor_target"))
]
)

Expand Down Expand Up @@ -185,16 +185,16 @@ class HetrixTools::V3Test < ActiveSupport::TestCase
true_alert = Alert.new(
title: "#{@resource_usage_request.dig("monitor_name")} usage alert",
description: [
"<p>Resource Type: #{@resource_usage_request.dig("resource_usage", "resource_type")}</p>",
"<p>Current Usage: #{@resource_usage_request.dig("resource_usage", "current_usage")}</p>",
"<p>Average Usage: #{@resource_usage_request.dig("resource_usage", "average_usage")} / #{@resource_usage_request.dig("resource_usage", "average_minutes")}m</p>"
].join(""),
"<p>Resource Type: #{@resource_usage_request.dig("resource_usage", "resource_type")}</p>",
"<p>Current Usage: #{@resource_usage_request.dig("resource_usage", "current_usage")}</p>",
"<p>Average Usage: #{@resource_usage_request.dig("resource_usage", "average_usage")} / #{@resource_usage_request.dig("resource_usage", "average_minutes")}m</p>"
].join(""),
urgency: nil,
thirdparty_id: nil,
dedup_keys: [],
additional_data: [
AdditionalDatum.new(format: "text", label: "Resource Type", value: @resource_usage_request.dig("resource_usage", "resource_type")),
AdditionalDatum.new(format: "text", label: "Current Usage", value: @resource_usage_request.dig("resource_usage", "current_usage"))
AdditionalDatum.new(format: "text", label: "Resource Type", value: @resource_usage_request.dig("resource_usage", "resource_type")),
AdditionalDatum.new(format: "text", label: "Current Usage", value: @resource_usage_request.dig("resource_usage", "current_usage"))
]
)

Expand Down

0 comments on commit 7a4c3ed

Please sign in to comment.