defmodule ToweropsWeb.DeviceLive.Components.ChecksTab do @moduledoc """ LiveComponent for the device monitoring checks tab. Displays all monitoring checks for the device grouped by type (SNMP, HTTP, TCP, DNS, SSL, ping). """ use ToweropsWeb, :live_component alias Towerops.Monitoring alias ToweropsWeb.DeviceLive.Helpers.DataLoaders @impl true def update(assigns, socket) do {:ok, socket |> assign(assigns) |> load_checks_data()} end defp load_checks_data(socket) do device_id = socket.assigns.device.id organization_id = socket.assigns.device.organization_id checks_data = DataLoaders.load_checks_data(device_id, organization_id) socket |> assign(:checks, checks_data.checks) |> assign(:grouped_checks, checks_data.grouped_checks) end @impl true def render(assigns) do ~H"""
{t( "Run discovery to automatically detect sensors, interfaces, and other monitorable items, or add a service check manually." )}
| {t("Name")} | {t("Status")} | {t("Value")} | {t("Last Checked")} | Actions |
|---|---|---|---|---|
| {check.name} | {render_status_badge(check.current_state)} | <%= if check.last_check_at do %> {get_latest_value(check)} <% else %> Pending <% end %> | <%= if check.last_check_at do %> {format_relative_time(check.last_check_at)} <% else %> Never <% end %> |
<.link
navigate={
~p"/devices/#{@device.id}/graph/check?check_id=#{check.id}&range=24h"
}
class="text-blue-600 hover:text-blue-900 dark:text-blue-400 dark:hover:text-blue-300 text-sm font-medium"
>
{t("Graph")}
<%= if check.check_type in ["http", "tcp", "dns", "ssl"] do %>
<% end %>
|