Class: HetrixTools::V3

Inherits:
Integration
  • Object
show all
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

Instance Method Details

#_adapter_action_blacklistObject



45
46
47
# File 'app/models/pager_tree/integrations/hetrix_tools/v3.rb', line 45

def _adapter_action_blacklist
  :create
end

#_adapter_action_resource_usageObject



49
50
51
# File 'app/models/pager_tree/integrations/hetrix_tools/v3.rb', line 49

def _adapter_action_resource_usage
  :create
end

#_adapter_action_uptimeObject



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_blacklistObject



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_usageObject



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_uptimeObject



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_datumsObject



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_blacklistObject



149
150
151
# File 'app/models/pager_tree/integrations/hetrix_tools/v3.rb', line 149

def _additional_datums_blacklist
  []
end

#_additional_datums_resource_usageObject



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_uptimeObject



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

#_descriptionObject



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_blacklistObject



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_usageObject



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_uptimeObject



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

#_titleObject



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_blacklistObject



108
109
110
# File 'app/models/pager_tree/integrations/hetrix_tools/v3.rb', line 108

def _title_blacklist
  "Blacklist Alert"
end

#_title_resource_usageObject



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_uptimeObject



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_typeObject



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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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_actionObject



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

Returns:

  • (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_createObject



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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (Boolean)


20
21
22
# File 'app/models/pager_tree/integrations/hetrix_tools/v3.rb', line 20

def adapter_supports_outgoing?
  false
end

#adapter_thirdparty_idObject



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