-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5a155af
commit 727c23a
Showing
5 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
defmodule Tronto.AlertEmail do | ||
@moduledoc false | ||
|
||
import Swoosh.Email | ||
|
||
def alert(text) do | ||
new() | ||
|> to({"Tronto Admin", "[email protected]"}) | ||
|> from({"Tronto Alerts", "[email protected]"}) | ||
|> subject(text) | ||
|> html_body( | ||
"<h3>#{text}<h3><br><br><img src='https://c.tenor.com/MYZgsN2TDJAAAAAC/this-is.gif'>" | ||
) | ||
end | ||
end |
40 changes: 40 additions & 0 deletions
40
lib/tronto/monitoring/event_handlers/alerts_event_handler.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
defmodule Tronto.Monitoring.AlertsEventsHandler do | ||
@moduledoc """ | ||
This event hanlder is responsible to forward checks execution request to the agent. | ||
""" | ||
|
||
use Commanded.Event.Handler, | ||
application: Tronto.Commanded, | ||
name: "alerts_event_handler" | ||
|
||
alias Tronto.Monitoring.Domain.Events.{ | ||
ClusterHealthChanged, | ||
HeartbeatFailed | ||
} | ||
|
||
alias Tronto.Monitoring.{ | ||
ClusterReadModel, | ||
HostReadModel | ||
} | ||
|
||
def handle( | ||
%ClusterHealthChanged{cluster_id: cluster_id, health: health}, | ||
_metadata | ||
) | ||
when health in [:warning, :critical] do | ||
%ClusterReadModel{name: name} = Tronto.Repo.get!(ClusterReadModel, cluster_id) | ||
|
||
email = Tronto.AlertEmail.alert("Cluster #{name} health is now in #{health} state") | ||
Tronto.Mailer.deliver(email) | ||
end | ||
|
||
def handle( | ||
%HeartbeatFailed{host_id: host_id}, | ||
_metadata | ||
) do | ||
%HostReadModel{hostname: hostname} = Tronto.Repo.get!(HostReadModel, host_id) | ||
|
||
email = Tronto.AlertEmail.alert("Host #{hostname} hearbeat failed") | ||
Tronto.Mailer.deliver(email) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters