diff --git a/lib/towerops/workers/check_executor_worker.ex b/lib/towerops/workers/check_executor_worker.ex index e95e9a11..0cfcb547 100644 --- a/lib/towerops/workers/check_executor_worker.ex +++ b/lib/towerops/workers/check_executor_worker.ex @@ -40,6 +40,7 @@ defmodule Towerops.Workers.CheckExecutorWorker do require Logger @snmp_check_types ~w(snmp_sensor snmp_interface snmp_processor snmp_storage) + @service_check_types ~w(http tcp dns) @impl Oban.Worker def perform(%Oban.Job{args: %{"check_id" => check_id}}) do @@ -56,6 +57,9 @@ defmodule Towerops.Workers.CheckExecutorWorker do should_skip_snmp_check?(check) -> Logger.debug("Skipping SNMP check #{check_id} - Phoenix SNMP disabled or device assigned to agent") + should_skip_service_check?(check) -> + Logger.debug("Skipping service check #{check_id} - device assigned to agent") + true -> execute_and_record(check) schedule_next_check(check) @@ -72,6 +76,14 @@ defmodule Towerops.Workers.CheckExecutorWorker do defp should_skip_snmp_check?(_check), do: false + defp should_skip_service_check?(%{check_type: check_type} = check) when check_type in @service_check_types do + # Skip service checks (HTTP/TCP/DNS) if device is assigned to an agent + # The agent will execute these checks from the device's network location + check.device_id != nil and not Agents.should_phoenix_poll_device?(%Device{id: check.device_id}) + end + + defp should_skip_service_check?(_check), do: false + defp execute_and_record(check) do Logger.debug("Executing check #{check.id} (#{check.check_type})") diff --git a/lib/towerops_web/live/check_live/form_component.ex b/lib/towerops_web/live/check_live/form_component.ex index 78e29eff..7fb617a9 100644 --- a/lib/towerops_web/live/check_live/form_component.ex +++ b/lib/towerops_web/live/check_live/form_component.ex @@ -97,21 +97,21 @@ defmodule ToweropsWeb.CheckLive.FormComponent do -
+
<.button type="submit" phx-disable-with={if @action == :edit, do: "Saving...", else: "Creating..."} > {if @action == :edit, do: "Save Changes", else: "Create Check"} - <.button +
diff --git a/lib/towerops_web/live/device_live/show.html.heex b/lib/towerops_web/live/device_live/show.html.heex index 63787368..c495e2d3 100644 --- a/lib/towerops_web/live/device_live/show.html.heex +++ b/lib/towerops_web/live/device_live/show.html.heex @@ -2698,8 +2698,10 @@ {check.name} - - {render_status_badge(check.current_state)} + +
+ {render_status_badge(check.current_state)} +
<%= if check.last_check_at do %> diff --git a/test/towerops/workers/check_executor_worker_test.exs b/test/towerops/workers/check_executor_worker_test.exs index abe4bedf..c5e5c727 100644 --- a/test/towerops/workers/check_executor_worker_test.exs +++ b/test/towerops/workers/check_executor_worker_test.exs @@ -392,7 +392,7 @@ defmodule Towerops.Workers.CheckExecutorWorkerTest do assert results == [] end - test "still executes non-SNMP checks when device is assigned to agent", %{ + test "skips service checks (HTTP/TCP/DNS) when device is assigned to agent", %{ device: device, organization: organization } do @@ -413,12 +413,12 @@ defmodule Towerops.Workers.CheckExecutorWorkerTest do Repo.delete_all(Oban.Job) - # HTTP checks should still execute even when device has an agent + # Service checks should be skipped when device has an agent (agent will execute them) assert :ok = perform_job(CheckExecutorWorker, %{check_id: check.id}) - # Should have a result (even if error from network) + # Should have no result since check was skipped results = Repo.all(from(r in CheckResult, where: r.check_id == ^check.id)) - assert length(results) == 1 + assert results == [] end test "skips SNMP check when phoenix_snmp_disabled is true", %{