proxMon/agent/lib/proxmox_agent/application.ex

32 lines
854 B
Elixir

defmodule ProxmoxAgent.Application do
@moduledoc false
use Application
require Logger
@impl true
def start(_type, _args) do
children =
case load_config() do
{:ok, cfg} ->
Logger.info("agent: starting with host_id=#{cfg.host_id}")
[{ProxmoxAgent.Reporter, cfg}]
{:error, reason} ->
Logger.error("agent: no config loaded (#{inspect(reason)}); running in idle mode")
[]
end
Supervisor.start_link(children, strategy: :one_for_one, name: ProxmoxAgent.Supervisor)
end
defp load_config do
path =
System.get_env("AGENT_CONFIG") ||
Application.get_env(:agent, :config_path, "/etc/proxmox-monitor/agent.toml")
case File.exists?(path) do
true -> ProxmoxAgent.Config.load(path)
false -> {:error, {:file_missing, path}}
end
end
end