Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

66uptime and Hydrozen integrations #121

Merged
merged 5 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/models/pager_tree/integrations/hydrozen/v3.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module PagerTree::Integrations
class Hydrozen::V3 < SixtySixUptime::V3
# we can just piggy back the SixtySixUptime::V3 since Hydrozen is a clone of SixtySixUptime
# both integrations have the same exact functionality
end
end
118 changes: 118 additions & 0 deletions app/models/pager_tree/integrations/sixty_six_uptime/v3.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
module PagerTree::Integrations
class SixtySixUptime::V3 < Integration
OPTIONS = []
store_accessor :options, *OPTIONS.map { |x| x[:key] }.map(&:to_s), prefix: "option"

after_initialize do
end

def adapter_supports_incoming?
true
end

def adapter_supports_outgoing?
false
end

def adapter_incoming_can_defer?
true
end

def adapter_thirdparty_id
id_part = case _webhoook_type
when "website", "ping", "port" then adapter_incoming_request_params.dig("monitor_id")
when "heartbeat" then adapter_incoming_request_params.dig("heartbeat_id")
when "domain-expiry", "ssl-expiry" then adapter_incoming_request_params.dig("domain_name_id")
else
SecureRandom.uuid
end
"#{_webhoook_type}-#{id_part}"
end

def adapter_action
case _webhoook_type
when "website", "ping", "port", "heartbeat"
adapter_incoming_request_params.dig("is_ok") == 1 ? :resolve : :create
when "domain-expiry", "ssl-expiry"
:create
else
:other
end
end

def adapter_process_create
Alert.new(
title: _title,
description: _description,
thirdparty_id: adapter_thirdparty_id,
dedup_keys: [],
additional_data: _additional_datums
)
end

private

def _title
case _webhoook_type
when "website", "ping", "port" then "#{_webhoook_type.capitalize} monitor #{adapter_incoming_request_params.dig("name")} is DOWN"
when "heartbeat" then "Heartbeat monitor #{adapter_incoming_request_params.dig("name")} has not checked in"
when "domain-expiry" then "Domain monitor #{adapter_incoming_request_params.dig("name")} is expiring soon"
when "ssl-expiry" then "SSL Certificate monitor #{adapter_incoming_request_params.dig("name")} is expiring soon"
else
"Unknown Webhook Type"
end
end

def _description
case _webhoook_type
when "website", "ping", "port" then "#{_webhoook_type.capitalize} monitor #{adapter_incoming_request_params.dig("name")} (#{adapter_incoming_request_params.dig("target")}) is DOWN"
when "heartbeat" then "Heartbeat monitor #{adapter_incoming_request_params.dig("name")} has not checked in"
when "domain-expiry" then "Domain monitor #{adapter_incoming_request_params.dig("name")} (#{adapter_incoming_request_params.dig("target")}) is expiring soon (#{adapter_incoming_request_params.dig("whois_end_datetime")} #{adapter_incoming_request_params.dig("timezone")})"
when "ssl-expiry" then "SSL Certificate monitor #{adapter_incoming_request_params.dig("name")} (#{adapter_incoming_request_params.dig("target")}) is expiring soon (#{adapter_incoming_request_params.dig("ssl_end_datetime")} #{adapter_incoming_request_params.dig("timezone")})"
else
"Unknown Webhook Type"
end
end

def _additional_datums
case _webhoook_type
when "website", "ping", "port"
[
AdditionalDatum.new(format: "link", label: "URL", value: adapter_incoming_request_params.dig("url")),
AdditionalDatum.new(format: "text", label: "Name", value: adapter_incoming_request_params.dig("name")),
AdditionalDatum.new(format: "text", label: "Type", value: adapter_incoming_request_params.dig("type")),
AdditionalDatum.new(format: "link", label: "Target", value: adapter_incoming_request_params.dig("target")),
AdditionalDatum.new(format: "text", label: "port", value: adapter_incoming_request_params.dig("port"))
]
when "heartbeat"
[
AdditionalDatum.new(format: "link", label: "URL", value: adapter_incoming_request_params.dig("url")),
AdditionalDatum.new(format: "text", label: "Name", value: adapter_incoming_request_params.dig("name")),
AdditionalDatum.new(format: "text", label: "Type", value: adapter_incoming_request_params.dig("type"))
]
when "domain-expiry"
[
AdditionalDatum.new(format: "link", label: "URL", value: adapter_incoming_request_params.dig("url")),
AdditionalDatum.new(format: "text", label: "Name", value: adapter_incoming_request_params.dig("name")),
AdditionalDatum.new(format: "text", label: "Type", value: adapter_incoming_request_params.dig("type")),
AdditionalDatum.new(format: "link", label: "Target", value: adapter_incoming_request_params.dig("target")),
AdditionalDatum.new(format: "text", label: "WHOIS End DateTime", value: "#{adapter_incoming_request_params.dig("whois_end_datetime")} #{adapter_incoming_request_params.dig("timezone")}")
]
when "ssl-expiry"
[
AdditionalDatum.new(format: "link", label: "URL", value: adapter_incoming_request_params.dig("url")),
AdditionalDatum.new(format: "text", label: "Name", value: adapter_incoming_request_params.dig("name")),
AdditionalDatum.new(format: "text", label: "Type", value: adapter_incoming_request_params.dig("type")),
AdditionalDatum.new(format: "link", label: "Target", value: adapter_incoming_request_params.dig("target")),
AdditionalDatum.new(format: "text", label: "SSL End DateTime", value: "#{adapter_incoming_request_params.dig("ssl_end_datetime")} #{adapter_incoming_request_params.dig("timezone")}")
]
else
[]
end
end

def _webhoook_type
adapter_incoming_request_params.dig("type")
end
end
end
Empty file.
Empty file.
8 changes: 8 additions & 0 deletions test/fixtures/pager_tree/integrations/integrations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ honeybadger_v3:
options:
token: "abc123"

hydrozen_v3:
type: "PagerTree::Integrations::Hydrozen::V3"
# options: no_options

hyperping_v3:
type: "PagerTree::Integrations::Hyperping::V3"
# options: no_options
Expand Down Expand Up @@ -160,6 +164,10 @@ site24x7_v3:
type: "PagerTree::Integrations::Site24x7::V3"
# options: no_options

sixty_six_uptime_v3:
type: "PagerTree::Integrations::SixtySixUptime::V3"
# options: no_options

slack_webhook_v3:
type: "PagerTree::Integrations::Slack::Webhook::V3"
# options: no_options
Expand Down
Loading