2018-06-04 14:06:37 +02:00
|
|
|
module Notifier
|
|
|
|
module Channels
|
|
|
|
class Base
|
|
|
|
def notify(reason, notification) # rubocop:disable Metrics/MethodLength
|
|
|
|
return unless supports?(reason, notification)
|
|
|
|
|
|
|
|
notification.ongoing!
|
|
|
|
|
|
|
|
case [notification.check.kind.to_sym, reason]
|
|
|
|
when [:domain, :expires_soon]
|
|
|
|
domain_notify_expires_soon(notification)
|
|
|
|
when [:domain, :recurrent_failures]
|
|
|
|
domain_notify_recurrent_failures(notification)
|
2018-07-02 18:40:09 +02:00
|
|
|
when [:ssl, :expires_soon]
|
|
|
|
ssl_notify_expires_soon(notification)
|
|
|
|
when [:ssl, :recurrent_failures]
|
|
|
|
ssl_notify_recurrent_failures(notification)
|
2018-06-04 14:06:37 +02:00
|
|
|
else
|
|
|
|
fail ArgumentError,
|
|
|
|
"Invalid notification reason `#{reason}` for check kind `#{notification.check.kind}`."
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
# :nocov:
|
|
|
|
def supports?(_reason, _notification)
|
|
|
|
fail NotImplementedError,
|
|
|
|
"#{self.class.name} channel did not implemented method #{__callee__}"
|
|
|
|
end
|
|
|
|
|
2018-07-02 18:40:09 +02:00
|
|
|
%i[
|
|
|
|
domain_notify_expires_soon
|
|
|
|
domain_notify_recurrent_failures
|
|
|
|
ssl_notify_expires_soon
|
|
|
|
ssl_notify_recurrent_failures
|
|
|
|
].each do |method|
|
|
|
|
define_method(method) do
|
|
|
|
fail NotImplementedError,
|
|
|
|
"Channel #{self.class.name} does not implement method #{method}."
|
|
|
|
end
|
2018-06-04 14:06:37 +02:00
|
|
|
end
|
|
|
|
# :nocov:
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|