This commit implements the unified checks architecture that consolidates SNMP monitoring with HTTP/TCP/DNS checks under a single "check" abstraction, enabling consistent graphing, alerting, and management across all check types. Database Changes: - Add source_type and source_id to checks table for tracking auto-discovered vs manually created checks - Add value field to check_results for storing numeric sensor readings - Maintain backward compatibility with existing check_results data New SNMP Executors: - SnmpSensorExecutor: Poll sensor OIDs and return formatted values with status determination (OK/WARNING/CRITICAL based on limits) - SnmpInterfaceExecutor: Poll interface stats (bandwidth, packets, errors) - SnmpProcessorExecutor: Poll CPU/processor usage - SnmpStorageExecutor: Poll disk/memory usage with percentage calculations Check Execution Worker: - CheckExecutorWorker: Unified Oban worker that dispatches to appropriate executor based on check_type (snmp_sensor, snmp_interface, http, tcp, etc.) - Self-schedules next execution with distributed polling offsets - Records results in check_results TimescaleDB hypertable - Updates check state (OK/WARNING/CRITICAL/UNKNOWN) Discovery Integration: - Auto-creates checks during SNMP discovery for sensors, interfaces, processors, and storage - Links checks to source entities via source_id for data lookup - Enables/disables checks based on discovery results UI Enhancements: - Checks tab on device detail page with grouped display - FormComponent for adding manual HTTP/TCP/DNS checks - Empty state with "Run Discovery" prompt - Check status badges and last checked times Graphing: - Update GraphLive to accept check_id parameter - Query check_results table for time-series data - Support all check types (SNMP, HTTP response times, etc.) Testing: - Comprehensive test suite for SnmpSensorExecutor (5 tests) - Test suite for CheckExecutorWorker (7 tests) - Test coverage for discovery check creation (6 tests) - Remove deprecated monitoring_test.exs testing old API Bug Fixes: - Fix SNMP executors reading credentials from correct Device schema fields (device.snmp_version instead of device.snmp_device.version) - Update agent channel test to query MonitoringCheck table directly Code Quality: - Extract add_snmp_credentials helper to reduce cyclomatic complexity - Use map-based lookups for sensor formatting and check type grouping - Apply pattern matching in dispatcher to reduce complexity - All credo checks passing with no issues Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
48 lines
1.2 KiB
Elixir
48 lines
1.2 KiB
Elixir
defmodule Towerops.Monitoring.CheckResult do
|
|
@moduledoc """
|
|
Stores results from check executions in TimescaleDB hypertable.
|
|
|
|
Results are time-series data showing check status over time.
|
|
"""
|
|
use Ecto.Schema
|
|
|
|
import Ecto.Changeset
|
|
|
|
alias Towerops.Agents.AgentToken
|
|
alias Towerops.Monitoring.Check
|
|
alias Towerops.Organizations.Organization
|
|
|
|
@primary_key {:id, :binary_id, autogenerate: true}
|
|
@foreign_key_type :binary_id
|
|
|
|
schema "check_results" do
|
|
field :checked_at, :utc_datetime
|
|
field :status, :integer
|
|
field :output, :string
|
|
field :value, :float
|
|
field :response_time_ms, :float
|
|
|
|
belongs_to :organization, Organization
|
|
belongs_to :check, Check
|
|
belongs_to :agent_token, AgentToken
|
|
end
|
|
|
|
def changeset(result, attrs) do
|
|
result
|
|
|> cast(attrs, [
|
|
:checked_at,
|
|
:status,
|
|
:output,
|
|
:value,
|
|
:response_time_ms,
|
|
:organization_id,
|
|
:check_id,
|
|
:agent_token_id
|
|
])
|
|
|> validate_required([:checked_at, :status, :organization_id, :check_id])
|
|
|> validate_inclusion(:status, 0..3)
|
|
|> foreign_key_constraint(:organization_id)
|
|
|> foreign_key_constraint(:check_id)
|
|
|> foreign_key_constraint(:agent_token_id)
|
|
end
|
|
end
|