ha-handler/lib/ha_handler/web/controller.ex
Timothée Floure b9aa3eeb98
Add initial plumbing for DRBD
This is 'quickly-hacked-together' and needs some love - it's working,
but is ways to fragile. It's no more than a POC atm.
2022-02-25 13:39:58 +01:00

36 lines
931 B
Elixir

defmodule HAHandler.Web.Controller do
import Plug.Conn
alias HAHandler.{HAProxy, PGSQL, DRBD}
@template_dir "lib/ha_handler/web/templates"
@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()
drbd_stats = DRBD.get_stats()
assigns = [
haproxy_stats: haproxy_stats,
pgsql_status: pgsql_stats,
drbd_status: drbd_stats,
hostname: hostname,
otp_app: HAHandler.otp_app(),
version: HAHandler.version(),
env: HAHandler.env()
]
render(conn, @index_template, assigns)
end
end