2022-01-25 10:46:25 +01:00
|
|
|
defmodule HAHandler.Web.Controller do
|
2022-01-24 16:53:04 +01:00
|
|
|
import Plug.Conn
|
|
|
|
|
2022-02-19 10:18:05 +01:00
|
|
|
alias HAHandler.{HAProxy, PGSQL}
|
2022-01-24 16:53:04 +01:00
|
|
|
|
2022-02-18 17:52:38 +01:00
|
|
|
@templates_dir "lib/ha_handler/web/templates"
|
|
|
|
|
|
|
|
defp render(conn, template, assigns) do
|
|
|
|
template_path = Path.join(@templates_dir, template)
|
|
|
|
quoted = EEx.compile_file(template_path)
|
|
|
|
{body, _binding} = Code.eval_quoted(quoted, assigns)
|
|
|
|
|
|
|
|
conn
|
|
|
|
|> put_resp_content_type("text/html")
|
|
|
|
|> send_resp(200, body)
|
|
|
|
end
|
|
|
|
|
2022-01-25 10:46:25 +01:00
|
|
|
def index(conn) do
|
2022-02-18 17:52:38 +01:00
|
|
|
{:ok, hostname} = :net_adm.dns_hostname(:net_adm.localhost)
|
2022-01-24 16:53:04 +01:00
|
|
|
|
|
|
|
stats = HAProxy.get_stats()
|
|
|
|
|
2022-02-18 17:52:38 +01:00
|
|
|
assigns = [
|
|
|
|
haproxy_stats: stats,
|
2022-02-19 10:18:05 +01:00
|
|
|
pgsql_status: PGSQL.status(),
|
2022-02-18 17:52:38 +01:00
|
|
|
hostname: hostname,
|
|
|
|
otp_app: HAHandler.otp_app(),
|
|
|
|
version: HAHandler.version(),
|
|
|
|
env: HAHandler.env()
|
|
|
|
]
|
|
|
|
render(conn, "index.html.eex", assigns)
|
2022-01-24 16:53:04 +01:00
|
|
|
end
|
|
|
|
end
|