2022-01-25 10:46:25 +01:00
|
|
|
defmodule HAHandler.Web.Controller do
|
2022-02-23 17:53:00 +01:00
|
|
|
import Plug.Conn
|
2022-01-24 16:53:04 +01:00
|
|
|
|
2022-02-25 13:39:58 +01:00
|
|
|
alias HAHandler.{HAProxy, PGSQL, DRBD}
|
2022-01-24 16:53:04 +01:00
|
|
|
|
2022-02-19 10:35:47 +01:00
|
|
|
@template_dir "lib/ha_handler/web/templates"
|
2022-02-23 17:53:00 +01:00
|
|
|
@index_template EEx.compile_file(Path.join(@template_dir, "index.html.eex"))
|
|
|
|
|
|
|
|
defp render(conn, template, assigns) do
|
|
|
|
{body, _binding} = Code.eval_quoted(template, assigns)
|
|
|
|
|
|
|
|
conn
|
|
|
|
|> put_resp_content_type("text/html")
|
|
|
|
|> send_resp(200, body)
|
|
|
|
end
|
|
|
|
|
|
|
|
def index(conn) do
|
|
|
|
{:ok, hostname} = :net_adm.dns_hostname(:net_adm.localhost())
|
|
|
|
|
|
|
|
haproxy_stats = HAProxy.get_stats(hide_error: true)
|
|
|
|
pgsql_stats = PGSQL.get_stats()
|
2022-02-25 13:39:58 +01:00
|
|
|
drbd_stats = DRBD.get_stats()
|
2022-02-23 17:53:00 +01:00
|
|
|
|
|
|
|
assigns = [
|
|
|
|
haproxy_stats: haproxy_stats,
|
|
|
|
pgsql_status: pgsql_stats,
|
2022-02-25 13:39:58 +01:00
|
|
|
drbd_status: drbd_stats,
|
2022-02-23 17:53:00 +01:00
|
|
|
hostname: hostname,
|
|
|
|
otp_app: HAHandler.otp_app(),
|
|
|
|
version: HAHandler.version(),
|
|
|
|
env: HAHandler.env()
|
|
|
|
]
|
|
|
|
|
|
|
|
render(conn, @index_template, assigns)
|
|
|
|
end
|
2022-01-24 16:53:04 +01:00
|
|
|
end
|