|
| 1 | +module PagerTree::Integrations |
| 2 | + class SixtySixUptime::V3 < Integration |
| 3 | + OPTIONS = [] |
| 4 | + store_accessor :options, *OPTIONS.map { |x| x[:key] }.map(&:to_s), prefix: "option" |
| 5 | + |
| 6 | + after_initialize do |
| 7 | + end |
| 8 | + |
| 9 | + def adapter_supports_incoming? |
| 10 | + true |
| 11 | + end |
| 12 | + |
| 13 | + def adapter_supports_outgoing? |
| 14 | + false |
| 15 | + end |
| 16 | + |
| 17 | + def adapter_incoming_can_defer? |
| 18 | + true |
| 19 | + end |
| 20 | + |
| 21 | + def adapter_thirdparty_id |
| 22 | + id_part = case _webhoook_type |
| 23 | + when "website", "ping", "port" then adapter_incoming_request_params.dig("monitor_id") |
| 24 | + when "heartbeat" then adapter_incoming_request_params.dig("heartbeat_id") |
| 25 | + when "domain-expiry", "ssl-expiry" then adapter_incoming_request_params.dig("domain_name_id") |
| 26 | + else |
| 27 | + SecureRandom.uuid |
| 28 | + end |
| 29 | + "#{_webhoook_type}-#{id_part}" |
| 30 | + end |
| 31 | + |
| 32 | + def adapter_action |
| 33 | + case _webhoook_type |
| 34 | + when "website", "ping", "port", "heartbeat" |
| 35 | + adapter_incoming_request_params.dig("is_ok") == 1 ? :resolve : :create |
| 36 | + when "domain-expiry", "ssl-expiry" |
| 37 | + :create |
| 38 | + else |
| 39 | + :other |
| 40 | + end |
| 41 | + end |
| 42 | + |
| 43 | + def adapter_process_create |
| 44 | + Alert.new( |
| 45 | + title: _title, |
| 46 | + description: _description, |
| 47 | + thirdparty_id: adapter_thirdparty_id, |
| 48 | + dedup_keys: [], |
| 49 | + additional_data: _additional_datums |
| 50 | + ) |
| 51 | + end |
| 52 | + |
| 53 | + private |
| 54 | + |
| 55 | + def _title |
| 56 | + case _webhoook_type |
| 57 | + when "website", "ping", "port" then "#{_webhoook_type.capitalize} monitor #{adapter_incoming_request_params.dig("name")} is DOWN" |
| 58 | + when "heartbeat" then "Heartbeat monitor #{adapter_incoming_request_params.dig("name")} has not checked in" |
| 59 | + when "domain-expiry" then "Domain monitor #{adapter_incoming_request_params.dig("name")} is expiring soon" |
| 60 | + when "ssl-expiry" then "SSL Certificate monitor #{adapter_incoming_request_params.dig("name")} is expiring soon" |
| 61 | + else |
| 62 | + "Unknown Webhook Type" |
| 63 | + end |
| 64 | + end |
| 65 | + |
| 66 | + def _description |
| 67 | + case _webhoook_type |
| 68 | + when "website", "ping", "port" then "#{_webhoook_type.capitalize} monitor #{adapter_incoming_request_params.dig("name")} (#{adapter_incoming_request_params.dig("target")}) is DOWN" |
| 69 | + when "heartbeat" then "Heartbeat monitor #{adapter_incoming_request_params.dig("name")} has not checked in" |
| 70 | + 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")})" |
| 71 | + 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")})" |
| 72 | + else |
| 73 | + "Unknown Webhook Type" |
| 74 | + end |
| 75 | + end |
| 76 | + |
| 77 | + def _additional_datums |
| 78 | + case _webhoook_type |
| 79 | + when "website", "ping", "port" |
| 80 | + [ |
| 81 | + AdditionalDatum.new(format: "link", label: "URL", value: adapter_incoming_request_params.dig("url")), |
| 82 | + AdditionalDatum.new(format: "text", label: "Name", value: adapter_incoming_request_params.dig("name")), |
| 83 | + AdditionalDatum.new(format: "text", label: "Type", value: adapter_incoming_request_params.dig("type")), |
| 84 | + AdditionalDatum.new(format: "link", label: "Target", value: adapter_incoming_request_params.dig("target")), |
| 85 | + AdditionalDatum.new(format: "text", label: "port", value: adapter_incoming_request_params.dig("port")) |
| 86 | + ] |
| 87 | + when "heartbeat" |
| 88 | + [ |
| 89 | + AdditionalDatum.new(format: "link", label: "URL", value: adapter_incoming_request_params.dig("url")), |
| 90 | + AdditionalDatum.new(format: "text", label: "Name", value: adapter_incoming_request_params.dig("name")), |
| 91 | + AdditionalDatum.new(format: "text", label: "Type", value: adapter_incoming_request_params.dig("type")) |
| 92 | + ] |
| 93 | + when "domain-expiry" |
| 94 | + [ |
| 95 | + AdditionalDatum.new(format: "link", label: "URL", value: adapter_incoming_request_params.dig("url")), |
| 96 | + AdditionalDatum.new(format: "text", label: "Name", value: adapter_incoming_request_params.dig("name")), |
| 97 | + AdditionalDatum.new(format: "text", label: "Type", value: adapter_incoming_request_params.dig("type")), |
| 98 | + AdditionalDatum.new(format: "link", label: "Target", value: adapter_incoming_request_params.dig("target")), |
| 99 | + AdditionalDatum.new(format: "text", label: "WHOIS End DateTime", value: "#{adapter_incoming_request_params.dig("whois_end_datetime")} #{adapter_incoming_request_params.dig("timezone")}") |
| 100 | + ] |
| 101 | + when "ssl-expiry" |
| 102 | + [ |
| 103 | + AdditionalDatum.new(format: "link", label: "URL", value: adapter_incoming_request_params.dig("url")), |
| 104 | + AdditionalDatum.new(format: "text", label: "Name", value: adapter_incoming_request_params.dig("name")), |
| 105 | + AdditionalDatum.new(format: "text", label: "Type", value: adapter_incoming_request_params.dig("type")), |
| 106 | + AdditionalDatum.new(format: "link", label: "Target", value: adapter_incoming_request_params.dig("target")), |
| 107 | + AdditionalDatum.new(format: "text", label: "SSL End DateTime", value: "#{adapter_incoming_request_params.dig("ssl_end_datetime")} #{adapter_incoming_request_params.dig("timezone")}") |
| 108 | + ] |
| 109 | + else |
| 110 | + [] |
| 111 | + end |
| 112 | + end |
| 113 | + |
| 114 | + def _webhoook_type |
| 115 | + adapter_incoming_request_params.dig("type") |
| 116 | + end |
| 117 | + end |
| 118 | +end |
0 commit comments