Class: HetrixTools::V3
- Inherits:
-
Integration
- Object
- Integration
- HetrixTools::V3
- Defined in:
- app/models/pager_tree/integrations/hetrix_tools/v3.rb
Constant Summary collapse
- OPTIONS =
[ {key: :authentication_token, type: :string, default: nil} ]
Instance Method Summary collapse
- #_adapter_action_blacklist ⇒ Object
- #_adapter_action_resource_usage ⇒ Object
- #_adapter_action_uptime ⇒ Object
- #_adapter_thirdparty_id_blacklist ⇒ Object
- #_adapter_thirdparty_id_resource_usage ⇒ Object
- #_adapter_thirdparty_id_uptime ⇒ Object
- #_additional_datums ⇒ Object
- #_additional_datums_blacklist ⇒ Object
- #_additional_datums_resource_usage ⇒ Object
- #_additional_datums_uptime ⇒ Object
- #_description ⇒ Object
- #_description_blacklist ⇒ Object
- #_description_resource_usage ⇒ Object
- #_description_uptime ⇒ Object
- #_title ⇒ Object
- #_title_blacklist ⇒ Object
- #_title_resource_usage ⇒ Object
- #_title_uptime ⇒ Object
- #_webhook_type ⇒ Object
- #_webhook_type_blacklist? ⇒ Boolean
- #_webhook_type_resource_usage? ⇒ Boolean
- #_webhook_type_uptime? ⇒ Boolean
- #adapter_action ⇒ Object
- #adapter_incoming_can_defer? ⇒ Boolean
- #adapter_process_create ⇒ Object
- #adapter_should_block_incoming?(request) ⇒ Boolean
- #adapter_supports_incoming? ⇒ Boolean
- #adapter_supports_outgoing? ⇒ Boolean
- #adapter_thirdparty_id ⇒ Object
Instance Method Details
#_adapter_action_blacklist ⇒ Object
45 46 47 |
# File 'app/models/pager_tree/integrations/hetrix_tools/v3.rb', line 45 def _adapter_action_blacklist :create end |
#_adapter_action_resource_usage ⇒ Object
49 50 51 |
# File 'app/models/pager_tree/integrations/hetrix_tools/v3.rb', line 49 def _adapter_action_resource_usage :create end |
#_adapter_action_uptime ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'app/models/pager_tree/integrations/hetrix_tools/v3.rb', line 36 def _adapter_action_uptime case adapter_incoming_request_params.dig("monitor_status") when "online" then :resolve when "offline" then :create else :other end end |
#_adapter_thirdparty_id_blacklist ⇒ Object
67 68 69 |
# File 'app/models/pager_tree/integrations/hetrix_tools/v3.rb', line 67 def _adapter_thirdparty_id_blacklist SecureRandom.hex(16) end |
#_adapter_thirdparty_id_resource_usage ⇒ Object
71 72 73 |
# File 'app/models/pager_tree/integrations/hetrix_tools/v3.rb', line 71 def _adapter_thirdparty_id_resource_usage adapter_incoming_request_params.dig("monitor_id") end |
#_adapter_thirdparty_id_uptime ⇒ Object
63 64 65 |
# File 'app/models/pager_tree/integrations/hetrix_tools/v3.rb', line 63 def _adapter_thirdparty_id_uptime adapter_incoming_request_params.dig("monitor_id") end |
#_additional_datums ⇒ Object
137 138 139 |
# File 'app/models/pager_tree/integrations/hetrix_tools/v3.rb', line 137 def _additional_datums try("_additional_datums_#{_webhook_type}") || [] end |
#_additional_datums_blacklist ⇒ Object
149 150 151 |
# File 'app/models/pager_tree/integrations/hetrix_tools/v3.rb', line 149 def _additional_datums_blacklist [] end |
#_additional_datums_resource_usage ⇒ Object
153 154 155 156 157 158 |
# File 'app/models/pager_tree/integrations/hetrix_tools/v3.rb', line 153 def _additional_datums_resource_usage [ AdditionalDatum.new(format: "text", label: "Resource Type", value: adapter_incoming_request_params.dig("resource_usage", "resource_type")), AdditionalDatum.new(format: "text", label: "Current Usage", value: adapter_incoming_request_params.dig("resource_usage", "current_usage")) ] end |
#_additional_datums_uptime ⇒ Object
141 142 143 144 145 146 147 |
# File 'app/models/pager_tree/integrations/hetrix_tools/v3.rb', line 141 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")) ] end |
#_description ⇒ Object
116 117 118 |
# File 'app/models/pager_tree/integrations/hetrix_tools/v3.rb', line 116 def _description try("_description_#{_webhook_type}") || "No description provided" end |
#_description_blacklist ⇒ Object
125 126 127 |
# File 'app/models/pager_tree/integrations/hetrix_tools/v3.rb', line 125 def _description_blacklist adapter_incoming_request_params.dig("_json").map { |x| "#{x["monitor"]} (#{x["blacklisted_now"]})" }.join("<br/>") end |
#_description_resource_usage ⇒ Object
129 130 131 132 133 134 135 |
# File 'app/models/pager_tree/integrations/hetrix_tools/v3.rb', line 129 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>Average Usage: #{adapter_incoming_request_params.dig("resource_usage", "average_usage")} / #{adapter_incoming_request_params.dig("resource_usage", "average_minutes")}m</p>" ].join("") end |
#_description_uptime ⇒ Object
120 121 122 123 |
# File 'app/models/pager_tree/integrations/hetrix_tools/v3.rb', line 120 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("") end |
#_title ⇒ Object
100 101 102 |
# File 'app/models/pager_tree/integrations/hetrix_tools/v3.rb', line 100 def _title try("_title_#{_webhook_type}") || "HetrixTools Alert" end |
#_title_blacklist ⇒ Object
108 109 110 |
# File 'app/models/pager_tree/integrations/hetrix_tools/v3.rb', line 108 def _title_blacklist "Blacklist Alert" end |
#_title_resource_usage ⇒ Object
112 113 114 |
# File 'app/models/pager_tree/integrations/hetrix_tools/v3.rb', line 112 def _title_resource_usage "#{adapter_incoming_request_params.dig("monitor_name")} usage alert" end |
#_title_uptime ⇒ Object
104 105 106 |
# File 'app/models/pager_tree/integrations/hetrix_tools/v3.rb', line 104 def _title_uptime "#{adapter_incoming_request_params.dig("monitor_name")} is #{adapter_incoming_request_params.dig("monitor_status")}" end |
#_webhook_type ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 |
# File 'app/models/pager_tree/integrations/hetrix_tools/v3.rb', line 75 def _webhook_type @_webhook_type ||= if _webhook_type_uptime? :uptime elsif _webhook_type_resource_usage? :resource_usage elsif _webhook_type_blacklist? :blacklist else :unknown end end |
#_webhook_type_blacklist? ⇒ Boolean
91 92 93 94 |
# File 'app/models/pager_tree/integrations/hetrix_tools/v3.rb', line 91 def _webhook_type_blacklist? json = adapter_incoming_request_params.dig("_json") json.present? && json.is_a?(Array) end |
#_webhook_type_resource_usage? ⇒ Boolean
96 97 98 |
# File 'app/models/pager_tree/integrations/hetrix_tools/v3.rb', line 96 def _webhook_type_resource_usage? adapter_incoming_request_params.dig("resource_usage").present? end |
#_webhook_type_uptime? ⇒ Boolean
87 88 89 |
# File 'app/models/pager_tree/integrations/hetrix_tools/v3.rb', line 87 def _webhook_type_uptime? adapter_incoming_request_params.dig("monitor_errors").present? end |
#adapter_action ⇒ Object
32 33 34 |
# File 'app/models/pager_tree/integrations/hetrix_tools/v3.rb', line 32 def adapter_action try("_adapter_action_#{_webhook_type}") || :other end |
#adapter_incoming_can_defer? ⇒ Boolean
24 25 26 |
# File 'app/models/pager_tree/integrations/hetrix_tools/v3.rb', line 24 def adapter_incoming_can_defer? true end |
#adapter_process_create ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'app/models/pager_tree/integrations/hetrix_tools/v3.rb', line 53 def adapter_process_create Alert.new( title: _title, description: _description, thirdparty_id: adapter_thirdparty_id, dedup_keys: [], additional_data: _additional_datums ) end |
#adapter_should_block_incoming?(request) ⇒ Boolean
12 13 14 |
# File 'app/models/pager_tree/integrations/hetrix_tools/v3.rb', line 12 def adapter_should_block_incoming?(request) option_authentication_token.present? && (request.headers["Authorization"] != "Bearer #{option_authentication_token}") end |
#adapter_supports_incoming? ⇒ Boolean
16 17 18 |
# File 'app/models/pager_tree/integrations/hetrix_tools/v3.rb', line 16 def adapter_supports_incoming? true end |
#adapter_supports_outgoing? ⇒ Boolean
20 21 22 |
# File 'app/models/pager_tree/integrations/hetrix_tools/v3.rb', line 20 def adapter_supports_outgoing? false end |
#adapter_thirdparty_id ⇒ Object
28 29 30 |
# File 'app/models/pager_tree/integrations/hetrix_tools/v3.rb', line 28 def adapter_thirdparty_id try("_adapter_thirdparty_id_#{_webhook_type}") || SecureRandom.hex(16) end |