defmodule Integrations.TlsCert.Display do @moduledoc """ Dashboard panel for `Integrations.TlsCert` (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.TlsCert` starts, the same as if they were still one module. """ use CodeNameRaven.Display, category: :infrastructure, size_hint: :medium @default_port 443 @default_warn_days 30 @default_critical_days 7 @impl true def display_name, do: "TLS Certificate" @impl true def compatible_monitors, do: [Integrations.TlsCert] @impl true def render(assigns) do result = assigns[:result] days_label = if result do d = result.days_remaining cond do d < 0 -> "Expired #{abs(d)}d ago" d == 0 -> "Expires today" true -> "#{d} days" end end days_class = if result do d = result.days_remaining warn = result[:warn_days] || @default_warn_days crit = result[:critical_days] || @default_critical_days cond do d <= crit -> "text-error" d <= warn -> "text-warning" true -> "text-success" end else "" end assigns = Map.merge(assigns, %{ result: result, days_label: days_label, days_class: days_class }) ~H"""

<%= @config.name || host_port(@config.params) %>

<%= host_port(@config.params) %>

Expiry

<%= @days_label %>

Not After

<%= @result.not_after |> Date.to_string() %>

Subject: <%= @result.subject %>

Issuer: <%= @result.issuer %>

""" end # --------------------------------------------------------------------------- # Helpers # --------------------------------------------------------------------------- defp host_port(params) do host = params[:host] || params["host"] || "?" port = params[:port] || params["port"] || @default_port "#{host}:#{port}" end end