Packages

SMTP server monitor, with its dashboard panel bundled in the same package as a separate module (Integrations.Smtp.Display) — one install, both halves; a release without raven_web simply runs the monitor headless.

Current section

Files

Jump to
raven_integration_smtp lib integrations smtp display.ex
Raw

lib/integrations/smtp/display.ex

defmodule Integrations.Smtp.Display do
@moduledoc """
Dashboard panel for `Integrations.Smtp` (same package).
Nested under the monitor's own namespace deliberately — the package's
top-level module name never changes, and this module's name is
guaranteed distinct from any separately-published standalone display
package. `Display.BundledDefault` auto-hooks this whenever
`Integrations.Smtp` starts, the same as if they were still one module.
"""
use CodeNameRaven.Display, category: :infrastructure, size_hint: :medium
@default_port 25
@impl true
def display_name, do: "SMTP"
@impl true
def compatible_monitors, do: [Integrations.Smtp]
@impl true
def render(assigns) do
result = assigns[:result]
assigns = Map.merge(assigns, %{result: result})
~H"""
<div class="space-y-3">
<div class="flex items-start justify-between gap-2">
<div class="min-w-0">
<h2 class="text-sm font-semibold text-base-content truncate">
<%= @config.name || smtp_title(@config.params) %>
</h2>
<p class="text-xs font-mono text-base-content/40 truncate">
<%= @result && @result.banner %>
</p>
</div>
<CodeNameRaven.MonitorComponents.status_chip status={@status} />
</div>
<div :if={@result} class="flex gap-2 flex-wrap">
<CodeNameRaven.MonitorComponents.stat
label="Banner"
value={"#{@result.banner_code}"} />
<CodeNameRaven.MonitorComponents.stat
label="Time to Banner"
value={"#{@result.banner_ms} ms"} />
<CodeNameRaven.MonitorComponents.stat
:if={@result.ehlo_attempted}
label="EHLO"
value={if @result.ehlo_ok, do: "OK", else: "Failed"} />
</div>
<div :if={@result && @result.capabilities != []} class="flex flex-wrap gap-1">
<span :for={cap <- @result.capabilities}
class="text-xs font-mono bg-base-200 rounded px-1.5 py-0.5 text-base-content/60">
<%= cap %>
</span>
</div>
<CodeNameRaven.MonitorComponents.error_message message={@last_error} />
<CodeNameRaven.MonitorComponents.check_time checked_at={@last_checked_at} />
</div>
"""
end
# ---------------------------------------------------------------------------
# Helpers
# ---------------------------------------------------------------------------
defp smtp_title(params) do
host = params[:host] || params["host"] || "?"
port = parse_int(params[:port] || params["port"], @default_port)
"#{host}:#{port}"
end
defp parse_int(nil, default), do: default
defp parse_int(v, _) when is_integer(v), do: v
defp parse_int(v, default) when is_binary(v) do
case Integer.parse(v) do
{n, _} -> n
:error -> default
end
end
defp parse_int(_, default), do: default
end