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-19 10:35:47 +01:00
|
|
|
@template_dir "lib/ha_handler/web/templates"
|
|
|
|
@index_template EEx.compile_file(
|
|
|
|
Path.join(@template_dir, "index.html.eex")
|
|
|
|
)
|
2022-02-18 17:52:38 +01:00
|
|
|
|
|
|
|
defp render(conn, template, assigns) do
|
2022-02-19 10:35:47 +01:00
|
|
|
{body, _binding} = Code.eval_quoted(template, assigns)
|
2022-02-18 17:52:38 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
2022-02-18 17:52:38 +01:00
|
|
|
assigns = [
|
2022-02-21 09:31:24 +01:00
|
|
|
haproxy_stats: HAProxy.get_stats([hide_error: true]),
|
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()
|
|
|
|
]
|
2022-02-19 10:35:47 +01:00
|
|
|
render(conn, @index_template, assigns)
|
2022-01-24 16:53:04 +01:00
|
|
|
end
|
|
|
|
end
|