-
Notifications
You must be signed in to change notification settings - Fork 4
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
Showing
8 changed files
with
102 additions
and
3 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 |
---|---|---|
|
@@ -34,4 +34,6 @@ uplink-*.tar | |
|
||
mnesia | ||
|
||
.mnesia | ||
.mnesia | ||
|
||
.envrc |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
defmodule Uplink.Clients.Instellar.Monitor do | ||
alias Uplink.Clients.Instellar | ||
|
||
def list do | ||
headers = Instellar.Self.headers() | ||
|
||
[Instellar.endpoint(), "self", "monitors"] | ||
|> Path.join() | ||
|> Req.get(headers: headers, max_retries: 1) | ||
|> case do | ||
{:ok, %{status: 200, body: %{"data" => monitors}}} -> | ||
{:ok, monitors} | ||
|
||
{:ok, %{status: _, body: body}} -> | ||
{:error, body} | ||
|
||
{:error, 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,26 @@ | ||
defmodule Uplink.Monitors do | ||
alias Uplink.Clients.Instellar | ||
|
||
def index(type) do | ||
%{"uplink" => %{"id" => uplink_id}} = Instellar.get_self() | ||
|
||
"metrics-system.#{type}-uplink-#{uplink_id}-*" | ||
end | ||
|
||
def push(monitor, type, params) do | ||
headers = headers(monitor) | ||
index = index(type) | ||
|
||
[index, "_doc"] | ||
|> Path.join() | ||
|> Repo.post(headers: headers, json: params) | ||
end | ||
|
||
defp headers(%{"attributes" => %{"uid" => uid, "token" => token}}) do | ||
Base.encode64("#{uid}:#{token}") | ||
|
||
[ | ||
{"authorization", "ApiKey #{token}"} | ||
] | ||
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,21 @@ | ||
defmodule Uplink.Monitors.Boot do | ||
use Task | ||
|
||
alias Uplink.Clients.Instellar | ||
|
||
require Logger | ||
|
||
def init(args) do | ||
Task.start_link(__MODULE__, :run, [args]) | ||
end | ||
|
||
def run(args) do | ||
case Instellar.list_monitors() do | ||
{:ok, monitors} -> | ||
nil | ||
|
||
{:error, error} -> | ||
Logger.error("Failed to find monitors: #{inspect(error)}") | ||
end | ||
end | ||
end |
Empty file.
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,21 @@ | ||
defmodule Uplink.Monitors.Router do | ||
use Plug.Router | ||
use Uplink.Web | ||
|
||
alias Uplink.Secret | ||
|
||
plug :match | ||
|
||
plug Plug.Parsers, | ||
parsers: [:urlencoded, :json], | ||
body_reader: {Uplink.Web.CacheBodyReader, :read_body, []}, | ||
json_decoder: Jason | ||
|
||
plug Secret.VerificationPlug | ||
|
||
plug :dispatch | ||
|
||
post "/:action" do | ||
%{"actor" => actor_params, "instance" => instance_params} = conn.body_params | ||
end | ||
end |