-
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.
Add collector endpoint, host discovery integration event handler and …
…monitoring context (#34) * Add discovery integration event handler * Add monitoring context * Add discovery API controller * Add /api/collect route Co-authored-by: Alessio Biancalana <[email protected]>
- Loading branch information
1 parent
6b9f21a
commit b362faa
Showing
4 changed files
with
72 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,30 @@ | ||
defmodule Tronto.Monitoring.Integration.Discovery do | ||
@moduledoc """ | ||
This module contains functions to handle integration events | ||
from the discovery bounded-context | ||
""" | ||
|
||
alias Tronto.Monitoring.Domain.Commands.RegisterHost | ||
|
||
@spec handle_discovery_event(map) :: {:error, any} | {:ok, struct} | ||
def handle_discovery_event(%{ | ||
"discovery_type" => "host_discovery", | ||
"agent_id" => agent_id, | ||
"payload" => %{ | ||
"hostname" => hostname, | ||
"ip_addresses" => ip_addresses, | ||
"agent_version" => agent_version | ||
} | ||
}) do | ||
RegisterHost.new( | ||
id_host: agent_id, | ||
hostname: hostname, | ||
ip_addresses: ip_addresses, | ||
agent_version: agent_version | ||
) | ||
end | ||
|
||
def handle_discovery_event(_) do | ||
{:error, :invalid_payload} | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
defmodule Tronto.Monitoring do | ||
@moduledoc """ | ||
This module encapuslates the access to the monitoring bounded context | ||
""" | ||
|
||
alias Tronto.Monitoring.Integration.Discovery | ||
|
||
def handle_discovery_event(event) do | ||
case Discovery.handle_discovery_event(event) do | ||
{:ok, command} -> | ||
Tronto.Commanded.dispatch(command) | ||
|
||
{:error, _} = error -> | ||
error | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
defmodule TrontoWeb.DiscoveryController do | ||
use TrontoWeb, :controller | ||
|
||
alias Tronto.Monitoring | ||
|
||
@spec collect(Plug.Conn.t(), map) :: Plug.Conn.t() | ||
def collect(conn, event) do | ||
case Monitoring.handle_discovery_event(event) do | ||
:ok -> | ||
conn | ||
|> put_status(:accepted) | ||
|> json(%{}) | ||
|
||
{:error, reason} -> | ||
conn | ||
|> put_status(:bad_request) | ||
|> json(%{error: reason}) | ||
end | ||
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