towerops/lib/towerops_web/controllers
Graham McIntire d7741cdc0e
feat: implement unified checks system (Phase 1-4)
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>
2026-02-12 16:58:40 -06:00
..
api Add CI-triggered mass agent update webhook 2026-02-10 13:40:32 -06:00
api_docs_html feat: implement unified checks system (Phase 1-4) 2026-02-12 16:58:40 -06:00
error_html add error pages 2026-01-06 14:37:48 -06:00
page_html enhance user auditing 2026-01-30 17:38:07 -06:00
user_registration_html mikrotik api update 2026-02-02 10:35:44 -06:00
user_reset_password_html purge more passkey and gettext updates 2026-02-02 10:20:59 -06:00
user_session_html add snmp port 2026-02-03 12:51:50 -06:00
user_settings_html paginate discovered devices 2026-01-31 10:31:37 -06:00
user_sudo_html fix: address UserSudoController critical issues 2026-02-01 14:45:05 -06:00
admin_controller.ex Add superuser system with user impersonation for admin support 2026-01-06 12:50:10 -06:00
api_docs_controller.ex updates 2026-01-17 17:49:53 -06:00
api_docs_html.ex updates 2026-01-17 17:49:53 -06:00
debug_controller.ex add headers debug in prod 2026-02-01 10:54:13 -06:00
error_html.ex add error pages 2026-01-06 14:37:48 -06:00
error_json.ex init 2025-12-21 11:10:43 -06:00
health_controller.ex security fixes 2026-01-28 17:02:36 -06:00
page_controller.ex cookie improvements 2026-01-28 12:30:28 -06:00
page_html.ex init 2025-12-21 11:10:43 -06:00
user_registration_controller.ex impersonate fixes 2026-01-28 14:41:27 -06:00
user_registration_html.ex credo cleanup 2026-01-17 15:00:52 -06:00
user_reset_password_controller.ex forgot password flow 2026-01-31 17:03:22 -06:00
user_reset_password_html.ex forgot password flow 2026-01-31 17:03:22 -06:00
user_session_controller.ex add snmp port 2026-02-03 12:51:50 -06:00
user_session_html.ex credo cleanup 2026-01-17 15:00:52 -06:00
user_settings_controller.ex Convert User Settings from controller to LiveView 2026-01-15 16:29:50 -06:00
user_settings_html.ex credo cleanup 2026-01-17 15:00:52 -06:00
user_sudo_controller.ex sudo redirect fix 2026-02-02 10:54:32 -06:00
user_sudo_html.ex feat: implement sudo mode MFA-only verification controller 2026-02-01 14:34:17 -06:00