Current section
Files
Jump to
Current section
Files
lib/integrations/dns/display.ex
defmodule Integrations.Dns.Display do
@moduledoc """
Dashboard panel for `Integrations.Dns` (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.Dns` starts, the same as if they were still one module.
"""
use CodeNameRaven.Display, category: :infrastructure, size_hint: :medium
@default_type "A"
@default_port 53
@impl true
def display_name, do: "DNS"
@impl true
def compatible_monitors, do: [Integrations.Dns]
@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 || dns_title(@config.params) %>
</h2>
<p class="text-xs font-mono text-base-content/40 truncate">
<%= dns_subtitle(@config.params) %>
</p>
</div>
<CodeNameRaven.MonitorComponents.status_chip status={@status} />
</div>
<div :if={@result} class="grid grid-cols-2 gap-2">
<CodeNameRaven.MonitorComponents.stat
label="Latency"
value={"#{@result.latency_ms} ms"} />
<CodeNameRaven.MonitorComponents.stat
label="Answers"
value={"#{length(@result.answers)} #{@result.type}"} />
</div>
<div :if={@result && @result.answers != []} class="space-y-1">
<div :for={answer <- @result.answers}
class="text-xs font-mono text-base-content/60 bg-base-200 rounded px-2 py-1">
<%= answer %>
</div>
</div>
<div :if={@result && @result.expected && not @result.matched}
class="text-xs text-warning font-mono">
Expected: <%= @result.expected %>
</div>
<CodeNameRaven.MonitorComponents.error_message message={@last_error} />
<CodeNameRaven.MonitorComponents.check_time checked_at={@last_checked_at} />
</div>
"""
end
# ---------------------------------------------------------------------------
# Helpers
# ---------------------------------------------------------------------------
defp dns_title(params) do
query = params[:query] || params["query"] || "DNS"
type = params[:type] || params["type"] || @default_type
"#{query} (#{type})"
end
defp dns_subtitle(params) do
ns = params[:nameserver] || params["nameserver"] || "?"
port = params[:nameserver_port] || params["nameserver_port"] || @default_port
"#{ns}:#{port}"
end
end