From 7a4c3ed618974fe7e306d6268b424af283a71697 Mon Sep 17 00:00:00 2001 From: Austin Miller Date: Tue, 30 Apr 2024 16:56:56 -0700 Subject: [PATCH] standardrb --- .../integrations/hetrix_tools/v3.rb | 20 +- .../integrations/hetrix_tools/v3_test.rb | 174 +++++++++--------- 2 files changed, 97 insertions(+), 97 deletions(-) diff --git a/app/models/pager_tree/integrations/hetrix_tools/v3.rb b/app/models/pager_tree/integrations/hetrix_tools/v3.rb index 05741a1..d39c2f1 100644 --- a/app/models/pager_tree/integrations/hetrix_tools/v3.rb +++ b/app/models/pager_tree/integrations/hetrix_tools/v3.rb @@ -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" @@ -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 @@ -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 @@ -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 "

#{adapter_incoming_request_params.dig("monitor_target")} is #{adapter_incoming_request_params.dig("monitor_status")}

" + - adapter_incoming_request_params.dig("monitor_errors").map{ |k, v| "

#{k}: #{v}

" }.join("") + adapter_incoming_request_params.dig("monitor_errors").map { |k, v| "

#{k}: #{v}

" }.join("") end def _description_blacklist @@ -128,21 +128,21 @@ def _description_blacklist def _description_resource_usage [ - "

Resource Type: #{adapter_incoming_request_params.dig("resource_usage", "resource_type")}

", - "

Current Usage: #{adapter_incoming_request_params.dig("resource_usage", "current_usage")}

", + "

Resource Type: #{adapter_incoming_request_params.dig("resource_usage", "resource_type")}

", + "

Current Usage: #{adapter_incoming_request_params.dig("resource_usage", "current_usage")}

", "

Average Usage: #{adapter_incoming_request_params.dig("resource_usage", "average_usage")} / #{adapter_incoming_request_params.dig("resource_usage", "average_minutes")}m

" ].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 diff --git a/test/models/pager_tree/integrations/hetrix_tools/v3_test.rb b/test/models/pager_tree/integrations/hetrix_tools/v3_test.rb index c2447f2..5d4e54f 100644 --- a/test/models/pager_tree/integrations/hetrix_tools/v3_test.rb +++ b/test/models/pager_tree/integrations/hetrix_tools/v3_test.rb @@ -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" @@ -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 @@ -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: "

#{@uptime_request.dig("monitor_target")} is #{@uptime_request.dig("monitor_status")}

" + @uptime_request.dig("monitor_errors").map{ |k, v| "

#{k}: #{v}

" }.join(""), + description: "

#{@uptime_request.dig("monitor_target")} is #{@uptime_request.dig("monitor_status")}

" + @uptime_request.dig("monitor_errors").map { |k, v| "

#{k}: #{v}

" }.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")) ] ) @@ -185,16 +185,16 @@ class HetrixTools::V3Test < ActiveSupport::TestCase true_alert = Alert.new( title: "#{@resource_usage_request.dig("monitor_name")} usage alert", description: [ - "

Resource Type: #{@resource_usage_request.dig("resource_usage", "resource_type")}

", - "

Current Usage: #{@resource_usage_request.dig("resource_usage", "current_usage")}

", - "

Average Usage: #{@resource_usage_request.dig("resource_usage", "average_usage")} / #{@resource_usage_request.dig("resource_usage", "average_minutes")}m

" - ].join(""), + "

Resource Type: #{@resource_usage_request.dig("resource_usage", "resource_type")}

", + "

Current Usage: #{@resource_usage_request.dig("resource_usage", "current_usage")}

", + "

Average Usage: #{@resource_usage_request.dig("resource_usage", "average_usage")} / #{@resource_usage_request.dig("resource_usage", "average_minutes")}m

" + ].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")) ] )