mirror of
https://github.com/Evolix/chexpire.git
synced 2024-04-25 21:40:49 +02:00
Notifications grouped of checks in error to user email.
This is not dependent of Notificatioon model.
This commit is contained in:
parent
d61b6d9c8a
commit
ea610ee185
|
@ -1,34 +1,38 @@
|
|||
class NotificationsMailer < ApplicationMailer
|
||||
helper :application
|
||||
|
||||
before_action do
|
||||
before_action except: :recurrent_failures do
|
||||
@notification = params.fetch(:notification)
|
||||
@check = @notification.check
|
||||
end
|
||||
|
||||
default to: -> { @notification.recipient }
|
||||
|
||||
def domain_expires_soon
|
||||
@expire_in_days = Integer(@check.domain_expires_at.to_date - Date.today)
|
||||
|
||||
subject = t(".subject", domain: @check.domain, count: @expire_in_days)
|
||||
mail subject: subject
|
||||
end
|
||||
|
||||
def domain_recurrent_failures
|
||||
subject = t(".subject", domain: @check.domain)
|
||||
mail subject: subject
|
||||
I18n.with_locale params&.fetch(:locale) { @check.user.locale } do
|
||||
subject = t(".subject", domain: @check.domain, count: @expire_in_days)
|
||||
mail subject: subject, to: @notification.recipient
|
||||
end
|
||||
end
|
||||
|
||||
def ssl_expires_soon
|
||||
@expire_in_days = Integer(@check.domain_expires_at.to_date - Date.today)
|
||||
|
||||
subject = t(".subject", domain: @check.domain, count: @expire_in_days)
|
||||
mail subject: subject
|
||||
I18n.with_locale params&.fetch(:locale) { @check.user.locale } do
|
||||
subject = t(".subject", domain: @check.domain, count: @expire_in_days)
|
||||
mail subject: subject, to: @notification.recipient
|
||||
end
|
||||
end
|
||||
|
||||
def ssl_recurrent_failures
|
||||
subject = t(".subject", domain: @check.domain)
|
||||
mail subject: subject
|
||||
def recurrent_failures(user, checks)
|
||||
@checks = checks
|
||||
|
||||
# params generally not set, except for preview mailer
|
||||
params_locale = (params[:locale] if params.present?)
|
||||
|
||||
I18n.with_locale params_locale || user.locale do
|
||||
subject = t(".subject", count: checks.count, domain: checks.first.domain)
|
||||
mail subject: subject, to: user.email
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,39 +1,33 @@
|
|||
module Notifier
|
||||
module Channels
|
||||
class Base
|
||||
def notify(reason, notification) # rubocop:disable Metrics/MethodLength
|
||||
return unless supports?(reason, notification)
|
||||
def notify(notification) # rubocop:disable Metrics/MethodLength
|
||||
return unless supports?(notification)
|
||||
|
||||
notification.ongoing!
|
||||
|
||||
case [notification.check.kind.to_sym, reason]
|
||||
when [:domain, :expires_soon]
|
||||
case notification.check.kind.to_sym
|
||||
when :domain
|
||||
domain_notify_expires_soon(notification)
|
||||
when [:domain, :recurrent_failures]
|
||||
domain_notify_recurrent_failures(notification)
|
||||
when [:ssl, :expires_soon]
|
||||
when :ssl
|
||||
ssl_notify_expires_soon(notification)
|
||||
when [:ssl, :recurrent_failures]
|
||||
ssl_notify_recurrent_failures(notification)
|
||||
else
|
||||
fail ArgumentError,
|
||||
"Invalid notification reason `#{reason}` for check kind `#{notification.check.kind}`."
|
||||
"Invalid notification for check kind `#{notification.check.kind}`."
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# :nocov:
|
||||
def supports?(_reason, _notification)
|
||||
def supports?(_notification)
|
||||
fail NotImplementedError,
|
||||
"#{self.class.name} channel did not implemented method #{__callee__}"
|
||||
end
|
||||
|
||||
%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,
|
||||
|
|
|
@ -1,29 +1,25 @@
|
|||
module Notifier
|
||||
module Channels
|
||||
class Email < Base
|
||||
REASONS = %i[expires_soon recurrent_failures].freeze
|
||||
# Error notifications - all checks grouped by user
|
||||
def notify_recurrent_failures(user, checks)
|
||||
NotificationsMailer.recurrent_failures(user, checks).deliver_now
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def supports?(reason, _notification)
|
||||
REASONS.include?(reason)
|
||||
def supports?(_notification)
|
||||
true
|
||||
end
|
||||
|
||||
# Expiration notifications
|
||||
def domain_notify_expires_soon(notification)
|
||||
NotificationsMailer.with(notification: notification).domain_expires_soon.deliver_now
|
||||
end
|
||||
|
||||
def domain_notify_recurrent_failures(notification)
|
||||
NotificationsMailer.with(notification: notification).domain_recurrent_failures.deliver_now
|
||||
end
|
||||
|
||||
def ssl_notify_expires_soon(notification)
|
||||
NotificationsMailer.with(notification: notification).ssl_expires_soon.deliver_now
|
||||
end
|
||||
|
||||
def ssl_notify_recurrent_failures(notification)
|
||||
NotificationsMailer.with(notification: notification).ssl_recurrent_failures.deliver_now
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -16,16 +16,19 @@ module Notifier
|
|||
end
|
||||
|
||||
def process_expires_soon
|
||||
resolver.resolve_expires_soon.find_each do |notification|
|
||||
notifier_channel_for(notification).notify(:expires_soon, notification)
|
||||
resolver.notifications_expiring_soon.find_each do |notification|
|
||||
notifier_channel_for(notification).notify(notification)
|
||||
|
||||
sleep configuration.interval
|
||||
end
|
||||
end
|
||||
|
||||
# Notify checks in error by email to the check owner adress email.
|
||||
# A single email contains all checks for a same user.
|
||||
def process_recurrent_failures
|
||||
resolver.resolve_check_failed(configuration.consecutive_failures).find_each do |notification|
|
||||
notifier_channel_for(notification).notify(:recurrent_failures, notification)
|
||||
failed_checks = resolver.checks_recurrent_failures(configuration.consecutive_failures)
|
||||
failed_checks.group_by(&:user).each_pair do |user, checks|
|
||||
channels[:email].notify_recurrent_failures(user, checks)
|
||||
|
||||
sleep configuration.interval
|
||||
end
|
||||
|
@ -34,12 +37,7 @@ module Notifier
|
|||
private
|
||||
|
||||
def default_configuration
|
||||
config = Rails.configuration.chexpire.fetch("notifier", {})
|
||||
|
||||
Configuration.new(
|
||||
config.fetch("interval") { 0.00 },
|
||||
config.fetch("consecutive_failures") { 3 },
|
||||
)
|
||||
Rails.configuration.chexpire.fetch("notifier")
|
||||
end
|
||||
|
||||
def notifier_channel_for(notification)
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
module Notifier
|
||||
class Resolver
|
||||
def resolve_expires_soon
|
||||
def notifications_expiring_soon
|
||||
scope
|
||||
.where("checks.domain_expires_at >= CURDATE()")
|
||||
.where("DATE(checks.domain_expires_at)
|
||||
<= DATE_ADD(CURDATE(), INTERVAL notifications.interval DAY)")
|
||||
end
|
||||
|
||||
def resolve_check_failed
|
||||
# Only gets here the checks having its last run in error
|
||||
# Logical rules are in plain ruby inside processor
|
||||
scope
|
||||
.includes(check: :logs)
|
||||
.merge(Check.last_run_failed)
|
||||
def checks_recurrent_failures(min_consecutive)
|
||||
Check
|
||||
.active
|
||||
.consecutive_failures(min_consecutive)
|
||||
.includes(:user)
|
||||
.where.not(user: ignore_users)
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
<%- if @check.comment.present? -%>
|
||||
<%- if check.comment.present? -%>
|
||||
<p>
|
||||
You wrote the following comment with this domain:
|
||||
|
||||
<blockquote>
|
||||
<%= @check.comment -%>
|
||||
<%= check.comment -%>
|
||||
</blockquote>
|
||||
</p>
|
||||
<%- end -%>
|
||||
|
||||
<%- if @check.vendor.present? -%>
|
||||
Vendor: <%= @check.vendor %>
|
||||
<%- if check.vendor.present? -%>
|
||||
Vendor: <%= check.vendor %>
|
||||
<% end %>
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
<%- if @check.comment.present? -%>
|
||||
<%- if check.comment.present? -%>
|
||||
You wrote the following comment with this domain:
|
||||
|
||||
<%= @check.comment -%>
|
||||
<%= check.comment -%>
|
||||
<%- end -%>
|
||||
|
||||
|
||||
|
||||
<%- if @check.vendor.present? -%>
|
||||
Vendor: <%= @check.vendor %>
|
||||
<%- if check.vendor.present? -%>
|
||||
Vendor: <%= check.vendor %>
|
||||
<% end %>
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
<%- if @check.comment.present? -%>
|
||||
<%- if check.comment.present? -%>
|
||||
<p>
|
||||
Vous avez saisi le commentaire suivant pour ce domaine :
|
||||
|
||||
<blockquote>
|
||||
<%= @check.comment -%>
|
||||
<%= check.comment -%>
|
||||
</blockquote>
|
||||
</p>
|
||||
<%- end -%>
|
||||
|
||||
<%- if @check.vendor.present? -%>
|
||||
Fournisseur : <%= @check.vendor %>
|
||||
<%- if check.vendor.present? -%>
|
||||
Fournisseur : <%= check.vendor %>
|
||||
<% end %>
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
<%- if @check.comment.present? -%>
|
||||
<%- if check.comment.present? -%>
|
||||
Vous avez saisi le commentaire suivant pour ce domaine :
|
||||
|
||||
<%= @check.comment -%>
|
||||
<%= check.comment -%>
|
||||
<%- end -%>
|
||||
|
||||
|
||||
|
||||
<%- if @check.vendor.present? -%>
|
||||
Fournisseur : <%= @check.vendor %>
|
||||
<%- if check.vendor.present? -%>
|
||||
Fournisseur : <%= check.vendor %>
|
||||
<% end %>
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
<p>
|
||||
<strong>Domain: <%= check.domain %></strong> (<%= check.consecutive_failures %> consecutive errors)
|
||||
|
||||
<br />
|
||||
|
||||
<%- if check.domain_expires_at.present? %>
|
||||
Last known expiry date : <%= format_utc(check.domain_expires_at) %>.
|
||||
<br />
|
||||
<% end %>
|
||||
|
||||
<%- if check.last_success_at.present? %>
|
||||
Last successful check occured : <%= format_utc(check.last_success_at) %>.
|
||||
<br />
|
||||
<% end %>
|
||||
</p>
|
||||
|
||||
|
||||
<p>If you have deleted your domain or have not renewed it, please disable
|
||||
or delete the check by following this link: <br />
|
||||
<%= edit_check_url(check) %>
|
||||
</p>
|
||||
|
||||
<%= render "check_comment_vendor", check: check %>
|
|
@ -0,0 +1,15 @@
|
|||
Domain: <%= check.domain %> (<%= check.consecutive_failures %> consecutive errors)
|
||||
<%= "-" * (check.domain.length + "Domain: ".length) %>
|
||||
|
||||
<%- if check.domain_expires_at.present? %>
|
||||
Last known expiry date : <%= format_utc(check.domain_expires_at) %>.
|
||||
<% end %>
|
||||
<%- if check.last_success_at.present? %>
|
||||
Last successful check occured : <%= format_utc(check.last_success_at) %>.
|
||||
<% end %>
|
||||
|
||||
If you have deleted your domain or have not renewed it, please disable
|
||||
or delete the check by following this link:
|
||||
<%= edit_check_url(check) %>
|
||||
|
||||
<%= render "check_comment_vendor", check: check %>
|
|
@ -0,0 +1,18 @@
|
|||
<p>
|
||||
<strong>Domaine: <%= check.domain %></strong> (<%= check.consecutive_failures %> erreurs consécutives)
|
||||
<br />
|
||||
<%- if check.domain_expires_at.present? %>
|
||||
Dernière date d'expiration connue : <%= format_utc(check.domain_expires_at) %>.
|
||||
<br />
|
||||
<% end %>
|
||||
|
||||
<%- if check.last_success_at.present? %>
|
||||
Dernière vérification réussie : <%= format_utc(check.last_success_at) %>.
|
||||
<% end %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Si vous avez supprimé le domaine ou ne l'avez pas renouvellé, merci de désactiver la vérification associée, avec ce lien :<br />
|
||||
<%= link_to nil, edit_check_url(check) %>
|
||||
</p>
|
||||
<%= render "check_comment_vendor", check: check %>
|
|
@ -0,0 +1,15 @@
|
|||
Domaine: <%= check.domain %> (<%= check.consecutive_failures %> erreurs consécutives)
|
||||
<%= "-" * (check.domain.length + "Domaine: ".length) %>
|
||||
|
||||
<%- if check.domain_expires_at.present? %>
|
||||
Dernière date d'expiration connue : <%= format_utc(check.domain_expires_at) %>.
|
||||
<% end %>
|
||||
<%- if check.last_success_at.present? %>
|
||||
Dernière vérification réussie : <%= format_utc(check.last_success_at) %>.
|
||||
<% end %>
|
||||
|
||||
Si vous avez supprimé le domaine ou ne l'avez pas renouvellé,
|
||||
merci de désactiver la vérification associée, avec ce lien :
|
||||
<%= edit_check_url(check) %>
|
||||
|
||||
<%= render "check_comment_vendor", check: check %>
|
|
@ -1,11 +1,8 @@
|
|||
<br />
|
||||
<br />
|
||||
--
|
||||
|
||||
<p>You received this email because of the notification <%= interval %> days before
|
||||
the last known expiry date.<br />
|
||||
You can handle the check by following this link: <br />
|
||||
<%= link_to nil, edit_check_url(check) %>
|
||||
<p>You can handle all your checks by following this link:<br />
|
||||
<%= link_to nil, checks_url %>
|
||||
</p>
|
||||
|
||||
<p>The Chexpire Team</p>
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
--
|
||||
|
||||
You received this email because of the notification <%= interval %> days before
|
||||
the last known expiry date.
|
||||
You can handle the check by following this link:
|
||||
<%= edit_check_url(check) %>
|
||||
You can handle all your checks by following this link:
|
||||
<%= checks_url %>
|
||||
|
||||
The Chexpire Team
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
<br />
|
||||
<br />
|
||||
--
|
||||
|
||||
<p>Vous avez reçu ce courriel à <%= pluralize(interval, "jour", "jours") %> avant la dernière date d'expiration connue.<br />
|
||||
Vous pouvez gérer les notifications pour cette vérification à ce adresse :
|
||||
<%= link_to nil, edit_check_url(check) %>
|
||||
<p>Vous pouvez gérer l'ensemble de vos vérifications à cette adresse : <br />
|
||||
<%= link_to nil, checks_url %>
|
||||
</p>
|
||||
|
||||
<p>L'équipe Chexpire</p>
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
--
|
||||
|
||||
Vous avez reçu ce courriel à <%= pluralize(interval, "jour", "jours") %>
|
||||
avant la dernière date d'expiration connue.
|
||||
Vous pouvez gérer les notifications pour cette vérification à ce adresse :
|
||||
<%= edit_check_url(check) %>
|
||||
Vous pouvez gérer l'ensemble de vos vérifications à cette adresse :
|
||||
<%= checks_url %>
|
||||
|
||||
L'équipe Chexpire
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
<p>
|
||||
<strong>SSL: <%= check.domain %></strong> (<%= check.consecutive_failures %> erreurs consécutives)
|
||||
<br />
|
||||
|
||||
<%- if check.domain_expires_at.present? %>
|
||||
Last known expiry date : <%= format_utc(check.domain_expires_at) %>.
|
||||
<br />
|
||||
<%- end %>
|
||||
|
||||
<%- if check.last_success_at.present? %>
|
||||
Last successful check : <%= format_utc(check.last_success_at) %>.
|
||||
<br />
|
||||
<%- end %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
If there is no more SSL endpoint for this domain, please disable
|
||||
or delete the check by following this link: <br />
|
||||
<%= edit_check_url(check) %>
|
||||
</p>
|
||||
|
||||
<%= render "check_comment_vendor", check: check %>
|
|
@ -0,0 +1,15 @@
|
|||
SSL: <%= check.domain %> (<%= check.consecutive_failures %> erreurs consécutives)
|
||||
<%= "-" * (check.domain.length + "SSL: ".length) %>
|
||||
|
||||
<%- if check.domain_expires_at.present? %>
|
||||
Last known expiry date : <%= format_utc(check.domain_expires_at) %>.
|
||||
<%- end %>
|
||||
<%- if check.last_success_at.present? %>
|
||||
Last successful check : <%= format_utc(check.last_success_at) %>.
|
||||
<%- end %>
|
||||
|
||||
If there is no more SSL endpoint for this domain, please disable
|
||||
or delete the check by following this link:
|
||||
<%= edit_check_url(check) %>
|
||||
|
||||
<%= render "check_comment_vendor", check: check %>
|
|
@ -0,0 +1,20 @@
|
|||
<p>
|
||||
<strong>SSL: <%= check.domain %></strong> (<%= check.consecutive_failures %> erreurs consécutives)
|
||||
<br />
|
||||
|
||||
<%- if check.domain_expires_at.present? %>
|
||||
Dernière date d'expiration connue : <%= format_utc(check.domain_expires_at) %>.
|
||||
<br />
|
||||
<% end %>
|
||||
|
||||
<%- if check.last_success_at.present? %>
|
||||
Dernière vérification réussie : <%= format_utc(check.last_success_at) %>.
|
||||
<% end %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
S'il n'y a plus de terminaison SSL pour ce site ou s'il n'existe plus,
|
||||
merci de désactiver la vérification associée, avec ce lien :<br />
|
||||
<%= link_to nil, edit_check_url(check) %>
|
||||
</p>
|
||||
<%= render "check_comment_vendor", check: check %>
|
|
@ -0,0 +1,15 @@
|
|||
SSL: <%= check.domain %> (<%= check.consecutive_failures %> erreurs consécutives)
|
||||
<%= "-" * (check.domain.length + "SSL: ".length) %>
|
||||
|
||||
<%- if check.domain_expires_at.present? %>
|
||||
Dernière date d'expiration connue : <%= format_utc(check.domain_expires_at) %>.
|
||||
<% end %>
|
||||
<%- if check.last_success_at.present? %>
|
||||
Dernière vérification réussie : <%= format_utc(check.last_success_at) %>.
|
||||
<% end %>
|
||||
|
||||
S'il n'y a plus de terminaison SSL pour ce site ou s'il n'existe plus,
|
||||
merci de désactiver la vérification associée, avec ce lien :
|
||||
<%= edit_check_url(check) %>
|
||||
|
||||
<%= render "check_comment_vendor", check: check %>
|
|
@ -7,6 +7,6 @@
|
|||
</p>
|
||||
<br />
|
||||
|
||||
<%= render "check_comment_vendor" %>
|
||||
<%= render "check_comment_vendor", check: @check %>
|
||||
|
||||
<%= render "footer_expires_soon", interval: @notification.interval, check: @check %>
|
||||
|
|
|
@ -3,7 +3,7 @@ Hi,
|
|||
the domain <%= @check.domain %> will expire <%= format_utc(@check.domain_expires_at) %>.
|
||||
|
||||
|
||||
<%= render "check_comment_vendor" %>
|
||||
<%= render "check_comment_vendor", check: @check %>
|
||||
|
||||
|
||||
<%= render "footer_expires_soon", interval: @notification.interval, check: @check %>
|
||||
|
|
|
@ -7,6 +7,6 @@
|
|||
</p>
|
||||
<br />
|
||||
|
||||
<%= render "check_comment_vendor" %>
|
||||
<%= render "check_comment_vendor", check: @check %>
|
||||
|
||||
<%= render "footer_expires_soon", interval: @notification.interval, check: @check %>
|
||||
|
|
|
@ -3,7 +3,7 @@ Salut,
|
|||
le domaine <%= @check.domain %> va expirer le <%= format_utc(@check.domain_expires_at) %>.
|
||||
|
||||
|
||||
<%= render "check_comment_vendor" %>
|
||||
<%= render "check_comment_vendor", check: @check %>
|
||||
|
||||
|
||||
<%= render "footer_expires_soon", interval: @notification.interval, check: @check %>
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
<p>
|
||||
Hi,
|
||||
<br />
|
||||
<br />
|
||||
|
||||
We had <strong>recurrent failures</strong> while checking the whois database for domain
|
||||
<strong><%= @check.domain %></strong>. As of today, we can't anymore verify the expiry date.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<%- if @check.domain_expires_at.present? %>
|
||||
Our last known expiry date is <%= format_utc(@check.domain_expires_at) %>.
|
||||
<br />
|
||||
<% end %>
|
||||
|
||||
<%- if @check.last_success_at.present? %>
|
||||
Our last successful check occured <%= format_utc(@check.last_success_at) %>.
|
||||
<% end %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
If you have deleted the domain or have not renewed it, please disable
|
||||
or delete the check by following this link: <br /><br />
|
||||
<%= link_to nil, edit_check_url(@check) %>
|
||||
</p>
|
||||
<br />
|
||||
<%= render "check_comment_vendor" %>
|
||||
|
||||
|
||||
<%= render "footer_recurrent_failures", interval: @notification.interval, check: @check %>
|
|
@ -1,20 +0,0 @@
|
|||
Hi,
|
||||
|
||||
We had recurrent failures while checking the whois database for domain
|
||||
<%= @check.domain %>. As of today, we can't anymore verify the expiry date.
|
||||
|
||||
<%- if @check.domain_expires_at.present? %>
|
||||
The last known expiry date is <%= format_utc(@check.domain_expires_at) %>.
|
||||
<% end %>
|
||||
<%- if @check.last_success_at.present? %>
|
||||
The last successful check occured <%= format_utc(@check.last_success_at) %>.
|
||||
<% end %>
|
||||
|
||||
If you have deleted your domain or have not renewed it, please disable
|
||||
or delete the check by following this link:
|
||||
|
||||
<%= edit_check_url(@check) %>
|
||||
|
||||
<%= render "check_comment_vendor" %>
|
||||
|
||||
<%= render "footer_recurrent_failures", interval: @notification.interval, check: @check %>
|
|
@ -1,29 +0,0 @@
|
|||
<p>
|
||||
Salut,
|
||||
<br />
|
||||
<br />
|
||||
|
||||
Nous avons rencontré de <strong>multiples erreurs</strong> pendant l'exécution des vérifications du domaine <strong><%= @check.domain %></strong>.
|
||||
Nous ne pouvons plus interroger la base Whois pour vérifier la date d'expiration.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<%- if @check.domain_expires_at.present? %>
|
||||
La dernière date d'expiration connue est le <%= format_utc(@check.domain_expires_at) %>.
|
||||
<br />
|
||||
<% end %>
|
||||
|
||||
<%- if @check.last_success_at.present? %>
|
||||
Notre dernière vérification réussie a eu lieu le <%= format_utc(@check.last_success_at) %>.
|
||||
<% end %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Si vous avez supprimé le domaine ou ne l'avez pas renouvellé, merci de désactiver la vérification associée, avec ce lien :<br /><br />
|
||||
<%= link_to nil, edit_check_url(@check) %>
|
||||
</p>
|
||||
<br />
|
||||
<%= render "check_comment_vendor" %>
|
||||
|
||||
|
||||
<%= render "footer_recurrent_failures", interval: @notification.interval, check: @check %>
|
|
@ -1,20 +0,0 @@
|
|||
Salut,
|
||||
|
||||
Nous avons rencontré de multiples erreurs pendant l'exécution des vérifications
|
||||
du domaine <strong><%= @check.domain %></strong>.
|
||||
Nous ne pouvons plus interroger la base Whois pour vérifier la date d'expiration.
|
||||
|
||||
<%- if @check.domain_expires_at.present? %>
|
||||
La dernière date d'expiration connue est le <%= format_utc(@check.domain_expires_at) %>.
|
||||
<% end %>
|
||||
<%- if @check.last_success_at.present? %>
|
||||
Notre dernière vérification réussie a eu lieu le <%= format_utc(@check.last_success_at) %>.
|
||||
<% end %>
|
||||
|
||||
Si vous avez supprimé le domaine ou ne l'avez pas renouvellé,
|
||||
merci de désactiver la vérification associée, avec ce lien :
|
||||
<%= edit_check_url(@check) %>
|
||||
|
||||
<%= render "check_comment_vendor" %>
|
||||
|
||||
<%= render "footer_recurrent_failures", interval: @notification.interval, check: @check %>
|
|
@ -0,0 +1,22 @@
|
|||
<p>
|
||||
Hi,
|
||||
<br />
|
||||
<br />
|
||||
|
||||
<%= t(".header", count: @checks.count) %>
|
||||
</p>
|
||||
|
||||
|
||||
<%- @checks.each_with_index do |check, index| %>
|
||||
<%- if index > 0 -%>
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<%- end -%>
|
||||
|
||||
<%= render "#{check.kind}_recurrent_failure", check: check %>
|
||||
<%- end -%>
|
||||
|
||||
<br />
|
||||
<br />
|
||||
<%= render "footer_recurrent_failures" %>
|
|
@ -0,0 +1,14 @@
|
|||
Hi,
|
||||
|
||||
<%= t(".header", count: @checks.count) %>
|
||||
|
||||
<%- @checks.each_with_index do |check, index| %>
|
||||
<%- if index > 0 -%>
|
||||
|
||||
<%- end -%>
|
||||
|
||||
<%= render "#{check.kind}_recurrent_failure", check: check %>
|
||||
<%- end -%>
|
||||
|
||||
|
||||
<%= render "footer_recurrent_failures" %>
|
|
@ -0,0 +1,22 @@
|
|||
<p>
|
||||
Salut,
|
||||
<br />
|
||||
<br />
|
||||
|
||||
<%= t(".header", count: @checks.count) %>
|
||||
</p>
|
||||
|
||||
|
||||
<%- @checks.each_with_index do |check, index| %>
|
||||
<%- if index > 0 -%>
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<%- end -%>
|
||||
|
||||
<%= render "#{check.kind}_recurrent_failure", check: check %>
|
||||
<%- end -%>
|
||||
|
||||
<br />
|
||||
<br />
|
||||
<%= render "footer_recurrent_failures" %>
|
|
@ -0,0 +1,14 @@
|
|||
Salut,
|
||||
|
||||
<%= t(".header", count: @checks.count) %>
|
||||
|
||||
<%- @checks.each_with_index do |check, index| %>
|
||||
<%- if index > 0 -%>
|
||||
|
||||
<%- end -%>
|
||||
|
||||
<%= render "#{check.kind}_recurrent_failure", check: check %>
|
||||
<%- end -%>
|
||||
|
||||
|
||||
<%= render "footer_recurrent_failures" %>
|
|
@ -7,6 +7,6 @@
|
|||
</p>
|
||||
<br />
|
||||
|
||||
<%= render "check_comment_vendor" %>
|
||||
<%= render "check_comment_vendor", check: @check %>
|
||||
|
||||
<%= render "footer_expires_soon", interval: @notification.interval, check: @check %>
|
||||
|
|
|
@ -3,7 +3,7 @@ Hi,
|
|||
the SSL certificate for <%= @check.domain %> will expire <%= format_utc(@check.domain_expires_at) %>.
|
||||
|
||||
|
||||
<%= render "check_comment_vendor" %>
|
||||
<%= render "check_comment_vendor", check: @check %>
|
||||
|
||||
|
||||
<%= render "footer_expires_soon", interval: @notification.interval, check: @check %>
|
||||
|
|
|
@ -7,6 +7,6 @@
|
|||
</p>
|
||||
<br />
|
||||
|
||||
<%= render "check_comment_vendor" %>
|
||||
<%= render "check_comment_vendor", check: @check %>
|
||||
|
||||
<%= render "footer_expires_soon", interval: @notification.interval, check: @check %>
|
||||
|
|
|
@ -3,7 +3,7 @@ Salut,
|
|||
le certificat SSL pour <%= @check.domain %> va expirer le <%= format_utc(@check.domain_expires_at) %>.
|
||||
|
||||
|
||||
<%= render "check_comment_vendor" %>
|
||||
<%= render "check_comment_vendor", check: @check %>
|
||||
|
||||
|
||||
<%= render "footer_expires_soon", interval: @notification.interval, check: @check %>
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
<p>
|
||||
Hi,
|
||||
<br />
|
||||
<br />
|
||||
|
||||
We had <strong>recurrent failures</strong> while checking the SSL certificate for
|
||||
<strong><%= @check.domain %></strong>. As of today, we can no longer verify the certificate
|
||||
expiry date.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<%- if @check.domain_expires_at.present? %>
|
||||
Our last known expiry date is <%= format_utc(@check.domain_expires_at) %>.
|
||||
<br />
|
||||
<%- end %>
|
||||
|
||||
<%- if @check.last_success_at.present? %>
|
||||
Our last successful check occured <%= format_utc(@check.last_success_at) %>.
|
||||
<%- end %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
If there is no more SSL endpoint for this domain, please disable
|
||||
or delete the check by following this link: <br /><br />
|
||||
<%= link_to nil, edit_check_url(@check) %>
|
||||
</p>
|
||||
<br />
|
||||
<%= render "check_comment_vendor" %>
|
||||
|
||||
|
||||
<%= render "footer_recurrent_failures", interval: @notification.interval, check: @check %>
|
|
@ -1,22 +0,0 @@
|
|||
Hi,
|
||||
|
||||
We had recurrent failures while checking the SSL certificate for
|
||||
<%= @check.domain %>. As of today, we can no longer verify the certificate
|
||||
expiry date.
|
||||
|
||||
<%- if @check.domain_expires_at.present? %>
|
||||
The last known expiry date is <%= format_utc(@check.domain_expires_at) %>.
|
||||
<%- end %>
|
||||
|
||||
<%- if @check.last_success_at.present? %>
|
||||
The last successful check occured <%= format_utc(@check.last_success_at) %>.
|
||||
<%- end %>
|
||||
|
||||
If there is no more SSL endpoint for this domain, please disable
|
||||
or delete the check by following this link:
|
||||
|
||||
<%= edit_check_url(@check) %>
|
||||
|
||||
<%= render "check_comment_vendor" %>
|
||||
|
||||
<%= render "footer_recurrent_failures", interval: @notification.interval, check: @check %>
|
|
@ -1,35 +0,0 @@
|
|||
<p>
|
||||
Salut,
|
||||
<br />
|
||||
<br />
|
||||
|
||||
Nous avons rencontré de <strong>multiples erreurs</strong>
|
||||
pendant l'exécution des vérifications du certificat SSL
|
||||
du site <strong><%= @check.domain %></strong>.
|
||||
Nous ne pouvons plus vérifier la date d'expiration du certificat
|
||||
en nous connectant au site.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<%- if @check.domain_expires_at.present? %>
|
||||
La dernière date d'expiration connue est le <%= format_utc(@check.domain_expires_at) %>.
|
||||
<br />
|
||||
<% end %>
|
||||
|
||||
<%- if @check.last_success_at.present? %>
|
||||
Notre dernière vérification réussie a eu lieu le <%= format_utc(@check.last_success_at) %>.
|
||||
<% end %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
S'il n'y a plus de terminaison SSL pour ce site ou s'il n'existe plus,
|
||||
merci de désactiver la vérification associée, avec ce lien :
|
||||
<br />
|
||||
<br />
|
||||
<%= link_to nil, edit_check_url(@check) %>
|
||||
</p>
|
||||
<br />
|
||||
<%= render "check_comment_vendor" %>
|
||||
|
||||
|
||||
<%= render "footer_recurrent_failures", interval: @notification.interval, check: @check %>
|
|
@ -1,22 +0,0 @@
|
|||
Salut,
|
||||
|
||||
Nous avons rencontré de multiples erreurs pendant l'exécution des vérifications
|
||||
du certificat SSL pour le site <strong><%= @check.domain %></strong>.
|
||||
Nous ne pouvons plus vérifier la date d'expiration du certificat
|
||||
en nous connectant au site.
|
||||
|
||||
<%- if @check.domain_expires_at.present? %>
|
||||
La dernière date d'expiration connue est le <%= format_utc(@check.domain_expires_at) %>.
|
||||
<% end %>
|
||||
|
||||
<%- if @check.last_success_at.present? %>
|
||||
Notre dernière vérification réussie a eu lieu le <%= format_utc(@check.last_success_at) %>.
|
||||
<% end %>
|
||||
|
||||
S'il n'y a plus de terminaison SSL pour ce site ou s'il n'existe plus,
|
||||
merci de désactiver la vérification associée, avec ce lien :
|
||||
<%= edit_check_url(@check) %>
|
||||
|
||||
<%= render "check_comment_vendor" %>
|
||||
|
||||
<%= render "footer_recurrent_failures", interval: @notification.interval, check: @check %>
|
|
@ -40,8 +40,13 @@ en:
|
|||
one: "Domain %{domain} expires TOMORROW!"
|
||||
other: "Domain %{domain} expires in %{count} days"
|
||||
|
||||
domain_recurrent_failures:
|
||||
subject: "Recurrent failures in %{domain} domain expiry check"
|
||||
recurrent_failures:
|
||||
subject:
|
||||
one: "Recurrent failures for %{domain} expiry check"
|
||||
other: "%{count} checks in error"
|
||||
header:
|
||||
one: "We had recurrent failures during excution of the following check:"
|
||||
other: "We had recurrent failures during excution of the %{count} following checks:"
|
||||
|
||||
ssl_expires_soon:
|
||||
subject:
|
||||
|
|
|
@ -75,8 +75,13 @@ fr:
|
|||
one: "Le domaine %{domain} expire DEMAIN !"
|
||||
other: "Le domaine %{domain} expire dans %{count} jours"
|
||||
|
||||
domain_recurrent_failures:
|
||||
subject: "Erreurs dans la vérification d'expiration du domaine %{domain}"
|
||||
recurrent_failures:
|
||||
subject:
|
||||
one: "Erreurs de vérification d'expiration pour %{domain}"
|
||||
other: "%{count} vérifications en erreur"
|
||||
header:
|
||||
one: "Nous avons rencontré des erreurs pendant l'exécution d'une de vos vérifications :"
|
||||
other: "Nous avons rencontré des erreurs pendant l'exécution des %{count} vérifications suivantes :"
|
||||
|
||||
ssl_expires_soon:
|
||||
subject:
|
||||
|
@ -84,10 +89,6 @@ fr:
|
|||
one: "Le certificat SSL pour %{domain} expire DEMAIN !"
|
||||
other: "Le certificat SSL pour %{domain} expire dans %{count} jours"
|
||||
|
||||
ssl_recurrent_failures:
|
||||
subject: "Erreurs dans la vérification d'expiration du certificat SSL %{domain}"
|
||||
|
||||
|
||||
shared:
|
||||
locales:
|
||||
en: Anglais
|
||||
|
|
|
@ -43,6 +43,7 @@ check_chexpire_org_error = Check.create!(
|
|||
vendor: "Some random registrar",
|
||||
last_run_at: 20.minutes.ago,
|
||||
created_at: 3.weeks.ago,
|
||||
consecutive_failures: 4,
|
||||
)
|
||||
|
||||
ssl_check_chexpire_org = Check.create!(
|
||||
|
@ -67,6 +68,7 @@ ssl_check_chexpire_org_error = Check.create!(
|
|||
vendor: "Some random registrar",
|
||||
last_run_at: 20.minutes.ago,
|
||||
last_success_at: 4.days.ago,
|
||||
consecutive_failures: 8,
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ FactoryBot.define do
|
|||
end
|
||||
|
||||
trait :last_runs_failed do
|
||||
consecutive_failures 4
|
||||
consecutive_failures 5
|
||||
last_run_at 3.days.ago - 90.minutes
|
||||
last_success_at 7.days.ago - 2.hours
|
||||
end
|
||||
|
|
|
@ -40,5 +40,9 @@ FactoryBot.define do
|
|||
notifications_enabled true
|
||||
locale "en"
|
||||
tos_accepted true
|
||||
|
||||
trait :fr do
|
||||
locale "fr"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -31,32 +31,32 @@ class NotificationsMailerTest < ActionMailer::TestCase # rubocop:disable Metrics
|
|||
end
|
||||
|
||||
test "domain_expires_soon FR" do
|
||||
check = create(:check, domain_expires_at: Time.new(2018, 6, 10, 12, 0, 5, "+02:00"))
|
||||
check = create(:check,
|
||||
domain_expires_at: Time.new(2018, 6, 10, 12, 0, 5, "+02:00"),
|
||||
user: build(:user, :fr))
|
||||
notification = build(:notification, interval: 10, check: check, recipient: "colin@example.org")
|
||||
|
||||
I18n.with_locale :fr do
|
||||
Date.stub :today, Date.new(2018, 6, 2) do
|
||||
mail = NotificationsMailer.with(notification: notification).domain_expires_soon
|
||||
Date.stub :today, Date.new(2018, 6, 2) do
|
||||
mail = NotificationsMailer.with(notification: notification).domain_expires_soon
|
||||
|
||||
assert_emails 1 do
|
||||
mail.deliver_now
|
||||
end
|
||||
assert_emails 1 do
|
||||
mail.deliver_now
|
||||
end
|
||||
|
||||
assert_match "domain.fr", mail.subject
|
||||
assert_match "dans 8 jours", mail.subject
|
||||
assert_equal ["colin@example.org"], mail.to
|
||||
assert_equal [Rails.configuration.chexpire.fetch("mailer_default_from")], mail.from
|
||||
assert_match "domain.fr", mail.subject
|
||||
assert_match "dans 8 jours", mail.subject
|
||||
assert_equal ["colin@example.org"], mail.to
|
||||
assert_equal [Rails.configuration.chexpire.fetch("mailer_default_from")], mail.from
|
||||
|
||||
parts = [mail.text_part.decode_body, mail.html_part.decode_body]
|
||||
parts = [mail.text_part.decode_body, mail.html_part.decode_body]
|
||||
|
||||
parts.each do |part|
|
||||
assert_match "domain.fr", part
|
||||
assert_match "dim 10 juin 2018 10:00:05 +0000", part
|
||||
assert_match "10 jours", part
|
||||
assert_match "/checks/#{check.id}/edit", part
|
||||
assert_no_match "commentaire", part
|
||||
assert_no_match "fournisseur", part
|
||||
end
|
||||
parts.each do |part|
|
||||
assert_match "domain.fr", part
|
||||
assert_match "dim 10 juin 2018 10:00:05 +0000", part
|
||||
assert_match "10 jours", part
|
||||
assert_match "/checks/#{check.id}/edit", part
|
||||
assert_no_match "commentaire", part
|
||||
assert_no_match "fournisseur", part
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -82,36 +82,34 @@ class NotificationsMailerTest < ActionMailer::TestCase # rubocop:disable Metrics
|
|||
check = create(:check,
|
||||
domain_expires_at: 1.week.from_now,
|
||||
comment: "My comment",
|
||||
vendor: "The vendor")
|
||||
vendor: "The vendor",
|
||||
user: build(:user, :fr))
|
||||
notification = build(:notification, check: check)
|
||||
|
||||
I18n.with_locale :fr do
|
||||
mail = NotificationsMailer.with(notification: notification).domain_expires_soon
|
||||
mail = NotificationsMailer.with(notification: notification).domain_expires_soon
|
||||
|
||||
parts = [mail.text_part.decode_body, mail.html_part.decode_body]
|
||||
parts = [mail.text_part.decode_body, mail.html_part.decode_body]
|
||||
|
||||
parts.each do |part|
|
||||
assert_match "commentaire", part
|
||||
assert_match "Fournisseur", part
|
||||
end
|
||||
parts.each do |part|
|
||||
assert_match "commentaire", part
|
||||
assert_match "Fournisseur", part
|
||||
end
|
||||
end
|
||||
|
||||
test "domain_recurrent_failures" do
|
||||
test "recurrent_failures" do
|
||||
last_success_at = Time.new(2018, 5, 30, 6, 10, 0, "+00:00")
|
||||
domain_expires_at = Time.new(2018, 10, 10, 7, 20, 0, "+04:00")
|
||||
check = build(:check, :last_runs_failed,
|
||||
domain: "invalid-domain.fr",
|
||||
last_success_at: last_success_at,
|
||||
domain_expires_at: domain_expires_at,
|
||||
comment: "My comment")
|
||||
notification = create(:notification, check: check)
|
||||
check = create(:check, :last_runs_failed,
|
||||
domain: "invalid-domain.fr",
|
||||
last_success_at: last_success_at,
|
||||
domain_expires_at: domain_expires_at,
|
||||
comment: "My comment")
|
||||
|
||||
mail = NotificationsMailer.with(notification: notification).domain_recurrent_failures
|
||||
mail = NotificationsMailer.recurrent_failures(check.user, [check])
|
||||
assert_match "failures", mail.subject
|
||||
assert_match "invalid-domain.fr", mail.subject
|
||||
|
||||
assert_equal ["recipient@domain.fr"], mail.to
|
||||
assert_match(/user-\d+@chexpire.org/, mail.to.first)
|
||||
assert_equal [Rails.configuration.chexpire.fetch("mailer_default_from")], mail.from
|
||||
|
||||
parts = [mail.text_part.decode_body, mail.html_part.decode_body]
|
||||
|
@ -119,41 +117,39 @@ class NotificationsMailerTest < ActionMailer::TestCase # rubocop:disable Metrics
|
|||
parts.each do |part|
|
||||
assert_match "invalid-domain.fr", part
|
||||
assert_match "recurrent failures", part
|
||||
assert_match(/success[a-z ]+ Wed, 30 May 2018 06:10:00 \+0000/, part)
|
||||
assert_match(/expiry[a-z ]+ Wed, 10 Oct 2018 03:20:00 \+0000/, part)
|
||||
assert_match(/success[a-z: ]+ Wed, 30 May 2018 06:10:00 \+0000/, part)
|
||||
assert_match(/expiry[a-z: ]+ Wed, 10 Oct 2018 03:20:00 \+0000/, part)
|
||||
assert_match "My comment", part
|
||||
assert_match "/checks/#{check.id}/edit", part
|
||||
end
|
||||
end
|
||||
|
||||
test "domain_recurrent_failures - FR" do
|
||||
test "recurrent_failures - FR" do
|
||||
last_success_at = Time.new(2018, 5, 30, 6, 10, 0, "+00:00")
|
||||
domain_expires_at = Time.new(2018, 10, 10, 7, 20, 0, "+04:00")
|
||||
check = build(:check, :last_runs_failed,
|
||||
domain: "invalid-domain.fr",
|
||||
last_success_at: last_success_at,
|
||||
domain_expires_at: domain_expires_at,
|
||||
comment: "My comment")
|
||||
notification = create(:notification, check: check)
|
||||
check = create(:check, :last_runs_failed,
|
||||
domain: "invalid-domain.fr",
|
||||
last_success_at: last_success_at,
|
||||
domain_expires_at: domain_expires_at,
|
||||
comment: "My comment",
|
||||
user: build(:user, :fr))
|
||||
|
||||
I18n.with_locale :fr do
|
||||
mail = NotificationsMailer.with(notification: notification).domain_recurrent_failures
|
||||
assert_match "Erreurs", mail.subject
|
||||
assert_match "invalid-domain.fr", mail.subject
|
||||
mail = NotificationsMailer.recurrent_failures(check.user, [check])
|
||||
assert_match "Erreurs", mail.subject
|
||||
assert_match "invalid-domain.fr", mail.subject
|
||||
|
||||
assert_equal ["recipient@domain.fr"], mail.to
|
||||
assert_equal [Rails.configuration.chexpire.fetch("mailer_default_from")], mail.from
|
||||
assert_match(/user-\d+@chexpire.org/, mail.to.first)
|
||||
assert_equal [Rails.configuration.chexpire.fetch("mailer_default_from")], mail.from
|
||||
|
||||
parts = [mail.text_part.decode_body, mail.html_part.decode_body]
|
||||
parts = [mail.text_part.decode_body, mail.html_part.decode_body]
|
||||
|
||||
parts.each do |part|
|
||||
assert_match "invalid-domain.fr", part
|
||||
assert_match "erreurs", part
|
||||
assert_match(/réussie[a-z ]+ mer 30 mai 2018 06:10:00 \+0000/, part)
|
||||
assert_match(/expiration[a-z ]+ mer 10 oct. 2018 03:20:00 \+0000/, part)
|
||||
assert_match "commentaire", part
|
||||
assert_match "/checks/#{check.id}/edit", part
|
||||
end
|
||||
parts.each do |part|
|
||||
assert_match "invalid-domain.fr", part
|
||||
assert_match "erreurs", part
|
||||
assert_match(/réussie[a-z: ]+ mer 30 mai 2018 06:10:00 \+0000/, part)
|
||||
assert_match(/expiration[a-z: ]+ mer 10 oct. 2018 03:20:00 \+0000/, part)
|
||||
assert_match "commentaire", part
|
||||
assert_match "/checks/#{check.id}/edit", part
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -188,95 +184,33 @@ class NotificationsMailerTest < ActionMailer::TestCase # rubocop:disable Metrics
|
|||
end
|
||||
|
||||
test "ssl_expires_soon - FR" do
|
||||
check = create(:check, :ssl, domain_expires_at: Time.new(2018, 6, 10, 12, 0, 5, "+02:00"))
|
||||
check = create(:check, :ssl,
|
||||
domain_expires_at: Time.new(2018, 6, 10, 12, 0, 5, "+02:00"),
|
||||
user: build(:user, :fr))
|
||||
notification = build(:notification, interval: 10, check: check, recipient: "colin@example.org")
|
||||
|
||||
I18n.with_locale :fr do
|
||||
Date.stub :today, Date.new(2018, 6, 2) do
|
||||
mail = NotificationsMailer.with(notification: notification).ssl_expires_soon
|
||||
Date.stub :today, Date.new(2018, 6, 2) do
|
||||
mail = NotificationsMailer.with(notification: notification).ssl_expires_soon
|
||||
|
||||
assert_emails 1 do
|
||||
mail.deliver_now
|
||||
end
|
||||
|
||||
assert_match "domain.fr", mail.subject
|
||||
assert_match "SSL", mail.subject
|
||||
assert_match "dans 8 jours", mail.subject
|
||||
assert_equal ["colin@example.org"], mail.to
|
||||
assert_equal [Rails.configuration.chexpire.fetch("mailer_default_from")], mail.from
|
||||
|
||||
parts = [mail.text_part.decode_body, mail.html_part.decode_body]
|
||||
|
||||
parts.each do |part|
|
||||
assert_match "domain.fr", part
|
||||
assert_match "dim 10 juin 2018 10:00:05 +0000", part
|
||||
assert_match "10 jours", part
|
||||
assert_match "/checks/#{check.id}/edit", part
|
||||
assert_no_match "commentaire", part
|
||||
assert_no_match "fournisseur", part
|
||||
end
|
||||
assert_emails 1 do
|
||||
mail.deliver_now
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
test "ssl_recurrent_failures" do
|
||||
last_success_at = Time.new(2018, 5, 30, 6, 10, 0, "+00:00")
|
||||
domain_expires_at = Time.new(2018, 10, 10, 7, 20, 0, "+04:00")
|
||||
check = build(:check, :ssl, :last_runs_failed,
|
||||
domain: "invalid-domain.fr",
|
||||
last_success_at: last_success_at,
|
||||
domain_expires_at: domain_expires_at,
|
||||
comment: "My comment")
|
||||
notification = create(:notification, check: check)
|
||||
|
||||
mail = NotificationsMailer.with(notification: notification).ssl_recurrent_failures
|
||||
assert_match "failures", mail.subject
|
||||
assert_match "invalid-domain.fr", mail.subject
|
||||
assert_match "SSL", mail.subject
|
||||
|
||||
assert_equal ["recipient@domain.fr"], mail.to
|
||||
assert_equal [Rails.configuration.chexpire.fetch("mailer_default_from")], mail.from
|
||||
|
||||
parts = [mail.text_part.decode_body, mail.html_part.decode_body]
|
||||
|
||||
parts.each do |part|
|
||||
assert_match "invalid-domain.fr", part
|
||||
assert_match "recurrent failures", part
|
||||
assert_match(/success[a-z ]+ Wed, 30 May 2018 06:10:00 \+0000/, part)
|
||||
assert_match(/expiry[a-z ]+ Wed, 10 Oct 2018 03:20:00 \+0000/, part)
|
||||
assert_match "My comment", part
|
||||
assert_match "/checks/#{check.id}/edit", part
|
||||
end
|
||||
end
|
||||
|
||||
test "ssl_recurrent_failures - FR" do
|
||||
last_success_at = Time.new(2018, 5, 30, 6, 10, 0, "+00:00")
|
||||
domain_expires_at = Time.new(2018, 10, 10, 7, 20, 0, "+04:00")
|
||||
check = build(:check, :ssl, :last_runs_failed,
|
||||
domain: "invalid-domain.fr",
|
||||
last_success_at: last_success_at,
|
||||
domain_expires_at: domain_expires_at,
|
||||
comment: "My comment")
|
||||
notification = create(:notification, check: check)
|
||||
|
||||
I18n.with_locale :fr do
|
||||
mail = NotificationsMailer.with(notification: notification).ssl_recurrent_failures
|
||||
assert_match "Erreurs", mail.subject
|
||||
assert_match "invalid-domain.fr", mail.subject
|
||||
assert_match "domain.fr", mail.subject
|
||||
assert_match "SSL", mail.subject
|
||||
|
||||
assert_equal ["recipient@domain.fr"], mail.to
|
||||
assert_match "dans 8 jours", mail.subject
|
||||
assert_equal ["colin@example.org"], mail.to
|
||||
assert_equal [Rails.configuration.chexpire.fetch("mailer_default_from")], mail.from
|
||||
|
||||
parts = [mail.text_part.decode_body, mail.html_part.decode_body]
|
||||
|
||||
parts.each do |part|
|
||||
assert_match "invalid-domain.fr", part
|
||||
assert_match "erreurs", part
|
||||
assert_match(/réussie[a-z ]+ mer 30 mai 2018 06:10:00 \+0000/, part)
|
||||
assert_match(/expiration[a-z ]+ mer 10 oct. 2018 03:20:00 \+0000/, part)
|
||||
assert_match "commentaire", part
|
||||
assert_match "domain.fr", part
|
||||
assert_match "dim 10 juin 2018 10:00:05 +0000", part
|
||||
assert_match "10 jours", part
|
||||
assert_match "/checks/#{check.id}/edit", part
|
||||
assert_no_match "commentaire", part
|
||||
assert_no_match "fournisseur", part
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,21 +6,16 @@ class NotificationsMailerPreview < ActionMailer::Preview
|
|||
NotificationsMailer.with(notification: check.notifications.first).domain_expires_soon
|
||||
end
|
||||
|
||||
# Preview this email at http://localhost:3000/rails/mailers/notifications_mailer/domain_recurrent_failures
|
||||
def domain_recurrent_failures
|
||||
check = Check.domain.where("last_run_at != last_success_at").first
|
||||
NotificationsMailer.with(notification: check.notifications.first).domain_recurrent_failures
|
||||
end
|
||||
|
||||
# Preview this email at http://localhost:3000/rails/mailers/notifications_mailer/ssl_expires_soon
|
||||
def ssl_expires_soon
|
||||
check = Check.ssl.first
|
||||
NotificationsMailer.with(notification: check.notifications.first).ssl_expires_soon
|
||||
end
|
||||
|
||||
# Preview this email at http://localhost:3000/rails/mailers/notifications_mailer/ssl_recurrent_failures
|
||||
def ssl_recurrent_failures
|
||||
check = Check.ssl.where("last_run_at != last_success_at").first
|
||||
NotificationsMailer.with(notification: check.notifications.first).ssl_recurrent_failures
|
||||
# Preview this email at http://localhost:3000/rails/mailers/notifications_mailer/recurrent_failures
|
||||
def recurrent_failures
|
||||
user = User.first
|
||||
checks = Check.consecutive_failures(2).where(user: user)
|
||||
NotificationsMailer.recurrent_failures(user, checks)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,8 +5,8 @@ module Notifier
|
|||
class BaseTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
class FakeChannel < Base
|
||||
def supports?(reason, _notification)
|
||||
reason != :unsupported
|
||||
def supports?(notification)
|
||||
notification.interval < 1_000
|
||||
end
|
||||
|
||||
def domain_notify_expires_soon(*); end
|
||||
|
@ -18,7 +18,7 @@ module Notifier
|
|||
test "#notify change the status of the notification" do
|
||||
notification = create(:notification)
|
||||
|
||||
@channel.notify(:expires_soon, notification)
|
||||
@channel.notify(notification)
|
||||
|
||||
notification.reload
|
||||
|
||||
|
@ -26,18 +26,30 @@ module Notifier
|
|||
assert_just_now notification.sent_at
|
||||
end
|
||||
|
||||
test "#notify raises an exception for a invalid reason" do
|
||||
notification = build(:notification)
|
||||
test "#notify raises an exception for a non supported check kind" do
|
||||
notification = Minitest::Mock.new
|
||||
notification.expect :ongoing!, true
|
||||
notification.expect :interval, 10
|
||||
|
||||
check = Minitest::Mock.new
|
||||
check.expect(:kind, :invalid_kind)
|
||||
check.expect(:kind, :invalid_kind) # twice (second call for exception message)
|
||||
|
||||
notification.expect :check, check
|
||||
notification.expect :check, check
|
||||
|
||||
assert_raises ArgumentError do
|
||||
@channel.notify(:unknown, notification)
|
||||
@channel.notify(notification)
|
||||
end
|
||||
|
||||
check.verify
|
||||
notification.verify
|
||||
end
|
||||
|
||||
test "#notify does nothing when channel does not support a reason" do
|
||||
notification = create(:notification)
|
||||
test "#notify does nothing when channel doesn't support a notification whatever the reason" do
|
||||
notification = create(:notification, interval: 10_000)
|
||||
|
||||
@channel.notify(:unsupported, notification)
|
||||
@channel.notify(notification)
|
||||
|
||||
notification.reload
|
||||
|
||||
|
|
|
@ -22,9 +22,9 @@ module Notifier
|
|||
end
|
||||
|
||||
test "#process_recurrent_failures respects the interval configuration between sends" do
|
||||
create_list(:notification, 3, :email, check: build(:check, :last_runs_failed))
|
||||
create_list(:check, 3, :last_runs_failed)
|
||||
test_interval_respected(:process_recurrent_failures, 3) do |configuration|
|
||||
configuration.expect(:consecutive_failures, 4)
|
||||
configuration.expect(:consecutive_failures, 4.2)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -6,58 +6,58 @@ module Notifier
|
|||
@resolver = Notifier::Resolver.new
|
||||
end
|
||||
|
||||
test "#resolve_expires_soon ignores user having notification disabled" do
|
||||
test "#notifications_expiring_soon ignores user having notification disabled" do
|
||||
n1 = create(:notification, check: build(:check, :expires_next_week))
|
||||
n1.check.user.update_attribute(:notifications_enabled, false)
|
||||
n2 = create(:notification, check: build(:check, :expires_next_week))
|
||||
|
||||
notifications = @resolver.resolve_expires_soon
|
||||
notifications = @resolver.notifications_expiring_soon
|
||||
|
||||
assert_not_includes notifications, n1
|
||||
assert_includes notifications, n2
|
||||
end
|
||||
|
||||
test "#resolve_expires_soon ignores inactive checks" do
|
||||
test "#notifications_expiring_soon ignores inactive checks" do
|
||||
n1 = create(:notification, check: build(:check, :expires_next_week, :inactive))
|
||||
n2 = create(:notification, check: build(:check, :expires_next_week))
|
||||
|
||||
notifications = @resolver.resolve_expires_soon
|
||||
notifications = @resolver.notifications_expiring_soon
|
||||
|
||||
assert_not_includes notifications, n1
|
||||
assert_includes notifications, n2
|
||||
end
|
||||
|
||||
test "#resolve_expires_soon gets only checks inside interval" do
|
||||
test "#notifications_expiring_soon gets only checks inside interval" do
|
||||
n1 = create(:notification, check: build(:check, :expires_next_week), interval: 6)
|
||||
n2 = create(:notification, check: build(:check, :expires_next_week), interval: 7)
|
||||
|
||||
notifications = @resolver.resolve_expires_soon
|
||||
notifications = @resolver.notifications_expiring_soon
|
||||
|
||||
assert_not_includes notifications, n1
|
||||
assert_includes notifications, n2
|
||||
end
|
||||
|
||||
test "#resolve_expires_soon can gets several notifications for a same check" do
|
||||
test "#notifications_expiring_soon can gets several notifications for a same check" do
|
||||
check = create(:check, :expires_next_week)
|
||||
n1 = create(:notification, check: check, interval: 3)
|
||||
n2 = create(:notification, check: check, interval: 10)
|
||||
n3 = create(:notification, check: check, interval: 30)
|
||||
|
||||
notifications = @resolver.resolve_expires_soon
|
||||
notifications = @resolver.notifications_expiring_soon
|
||||
|
||||
assert_not_includes notifications, n1
|
||||
assert_includes notifications, n2
|
||||
assert_includes notifications, n3
|
||||
end
|
||||
|
||||
test "#resolve_expires_soon takes care of the status" do
|
||||
test "#notifications_expiring_soon takes care of the status" do
|
||||
check = create(:check, :expires_next_week)
|
||||
n1 = create(:notification, check: check)
|
||||
n2 = create(:notification, :failed, check: check)
|
||||
n3 = create(:notification, :ongoing, check: check)
|
||||
n4 = create(:notification, :succeed, check: check)
|
||||
|
||||
notifications = @resolver.resolve_expires_soon
|
||||
notifications = @resolver.notifications_expiring_soon
|
||||
|
||||
assert_includes notifications, n1
|
||||
assert_includes notifications, n2
|
||||
|
@ -65,49 +65,51 @@ module Notifier
|
|||
assert_not_includes notifications, n4
|
||||
end
|
||||
|
||||
test "#resolve_expires_soon ignores checks expired and without date" do
|
||||
test "#notifications_expiring_soon ignores checks expired and without date" do
|
||||
n1 = create(:notification, check: build(:check, :expires_next_week))
|
||||
n2 = create(:notification, check: build(:check, domain_expires_at: 1.week.ago))
|
||||
n3 = create(:notification, check: build(:check, :nil_dates))
|
||||
|
||||
notifications = @resolver.resolve_expires_soon
|
||||
notifications = @resolver.notifications_expiring_soon
|
||||
|
||||
assert_includes notifications, n1
|
||||
assert_not_includes notifications, n2
|
||||
assert_not_includes notifications, n3
|
||||
end
|
||||
|
||||
test "#resolve_check_failed ignores inactive checks" do
|
||||
n1 = create(:notification, check: build(:check, :last_runs_failed, :inactive))
|
||||
n2 = create(:notification, check: build(:check, :last_runs_failed))
|
||||
test "#checks_recurrent_failures ignores inactive checks" do
|
||||
c1 = create(:check, :last_runs_failed, :inactive)
|
||||
c2 = create(:check, :last_runs_failed)
|
||||
|
||||
notifications = @resolver.resolve_check_failed
|
||||
checks = @resolver.checks_recurrent_failures(4)
|
||||
|
||||
assert_not_includes notifications, n1
|
||||
assert_includes notifications, n2
|
||||
assert_not_includes checks, c1
|
||||
assert_includes checks, c2
|
||||
end
|
||||
|
||||
test "#resolve_check_failed ignores user having notification disabled" do
|
||||
n1 = create(:notification, check: build(:check, :last_runs_failed))
|
||||
n1.check.user.update_attribute(:notifications_enabled, false)
|
||||
n2 = create(:notification, check: build(:check, :last_runs_failed))
|
||||
test "#checks_recurrent_failures ignores user having notification disabled" do
|
||||
c1 = create(:check, :last_runs_failed)
|
||||
c1.user.update_attribute(:notifications_enabled, false)
|
||||
c2 = create(:check, :last_runs_failed)
|
||||
|
||||
notifications = @resolver.resolve_check_failed
|
||||
checks = @resolver.checks_recurrent_failures(4)
|
||||
|
||||
assert_not_includes notifications, n1
|
||||
assert_includes notifications, n2
|
||||
assert_not_includes checks, c1
|
||||
assert_includes checks, c2
|
||||
end
|
||||
|
||||
test "#resolve_check_failed gets only checks having last run in error" do
|
||||
n1 = create(:notification, check: build(:check, :nil_dates))
|
||||
n2 = create(:notification, check: build(:check, :last_run_succeed))
|
||||
n3 = create(:notification, check: build(:check, :last_runs_failed))
|
||||
test "#checks_recurrent_failures gets only checks having consecutive failures" do
|
||||
c1 = create(:check, :nil_dates)
|
||||
c2 = create(:check, :last_run_succeed)
|
||||
c3 = create(:check, :last_runs_failed, consecutive_failures: 5)
|
||||
c4 = create(:check, :last_runs_failed, consecutive_failures: 3)
|
||||
|
||||
notifications = @resolver.resolve_check_failed
|
||||
checks = @resolver.checks_recurrent_failures(4)
|
||||
|
||||
assert_not_includes notifications, n1
|
||||
assert_not_includes notifications, n2
|
||||
assert_includes notifications, n3
|
||||
assert_not_includes checks, c1
|
||||
assert_not_includes checks, c2
|
||||
assert_not_includes checks, c4
|
||||
assert_includes checks, c3
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue