proxMon/agent/lib/proxmox_agent/application.ex

37 lines
1.1 KiB
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}")
:ok = ProxmoxAgent.Diagnostics.configure(cfg.dump_dir)
diagnostics_children(ProxmoxAgent.Diagnostics.dump_dir()) ++
[{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 diagnostics_children(nil), do: []
defp diagnostics_children(dir), do: [{ProxmoxAgent.Diagnostics.Writer, [dir: dir]}]
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