Commit graph

30 commits

Author SHA1 Message Date
44fc017653
test: improve test coverage and code quality
- Update pre-commit config
- Add test coverage for URL validation, security modules, and monitoring executors
- Improve network map implementation and tests
- Add coverage for API controllers and LiveView endpoints
- Refactor code to fix Credo issues (reduce nesting, extract helper functions)
2026-03-15 14:49:55 -05:00
e5fc396d0b test: add controller and LiveView test coverage for untested endpoints 2026-03-14 15:21:12 -05:00
5045c9b8ff test: add monitoring executor test coverage 2026-03-14 15:15:22 -05:00
146289a14e test: add security, recovery code, and URL validation test coverage 2026-03-14 15:13:13 -05:00
e612f50157 test: add on-call, incident, and PagerDuty notification test coverage 2026-03-14 15:10:27 -05:00
7613a4dde5
add missing REST API controller tests
Tests for agents, alerts, integrations, organization, members, and
invitations controllers. Refactor alert filters to reduce complexity.
75 new tests, all passing.
2026-03-11 14:43:17 -05:00
17fa005781
add maintenance windows REST API and GraphQL support
REST endpoints for CRUD, scoped filtering (active/upcoming/past).
GraphQL queries and mutations for maintenance windows.
Fix agent edit test assertion message.
2026-03-11 14:33:25 -05:00
f6e9063577
feat: add REST API and GraphQL for on-call schedules and escalation policies
REST API v1 endpoints for schedules (14 endpoints) and escalation
policies (10 endpoints) with full CRUD for nested resources (layers,
members, overrides, rules, targets). GraphQL types, resolvers, and
schema mutations for both resource trees.
2026-03-11 14:01:15 -05:00
9d513b77ee
fix: tag flaky GitHub API test as :integration
The test makes a real HTTP call to GitHub which can fail or return
different responses depending on network conditions, rate limits, etc.

Tagged as :integration to exclude from normal test runs, consistent
with other GitHub API tests in ReleaseCheckerTest.
2026-03-10 15:49:11 -05:00
b3cff9afbb
stripe and email after signup 2026-03-06 10:07:27 -06:00
0c7d195e52
chore: remove backup files from sed operations 2026-03-06 07:57:30 -06:00
83d47d1502
perf(tests): remove/reduce Process.sleep calls for faster tests
- Remove all 25ms and 50ms sleeps from agent_channel_test
- Add poll_until helper for async DB operations (early exit on success)
- Reduce timeout test sleeps from 100ms to 60ms
- Reduce polling delays from 10ms to 5ms in multiple tests
- Remove unnecessary timestamp and background task sleeps
- Reduce circuit breaker recovery sleep from 150ms to 110ms

Performance: 30.3s → 28.3s (6.6% faster)
Total improvement from baseline: 52s → 28.3s (45.6% faster)
2026-03-06 07:57:30 -06:00
0ac99f679c
fix: convert alert_type from enum to string and fix SQL array syntax
Two critical production bugs fixed:

1. **Alert type enum → string conversion**
   - Changed Alert.alert_type from Ecto.Enum to :string for flexibility
   - Updated all queries to use "device_down"/"device_up" strings instead of atoms
   - Fixed pattern matching in alerts.ex and device_monitor_worker.ex
   - Updated 44+ test files to use string literals

2. **SQL array indexing syntax error in activity feed**
   - Fixed PostgreSQL syntax: `array_agg(...)[1]` → `(array_agg(...))[1]`
   - Prevents "syntax error at or near [" in activity feed queries

3. **Added comprehensive timer cleanup tests**
   - Tests for mobile_qr_live.ex timer cleanup on terminate
   - Tests for agent_live index timer cleanup
   - Verifies memory leak fixes from previous commits

Files changed:
- lib/towerops/alerts.ex
- lib/towerops/alerts/alert.ex
- lib/towerops/activity_feed.ex
- lib/towerops/workers/device_monitor_worker.ex
- test/**/*_test.exs (44+ files with alert_type references)
- test/towerops_web/live/mobile_qr_live_test.exs
- test/towerops_web/live/agent_live_test.exs
- test/towerops/workers/device_poller_worker_test.exs

All tests passing except 1 unrelated brute force protection test.
2026-03-05 09:12:39 -06:00
91dd7ad985
fix: allow site_id on device create regardless of use_sites setting
The API was silently stripping site_id when use_sites was false, causing
the Terraform provider to report inconsistent state after apply.
2026-02-15 12:28:06 -06:00
c790794191 Fix tests, credo issues, and Gaiia sync bugs
- Fix CLOAK_KEY placeholder in nix shell (invalid base64)
- Fix error HTML test assertion to match actual template
- Fix Gaiia sync: read 'subnet' field instead of 'block' for IP blocks
- Fix Gaiia sync: extract nested status name from subscription objects
- Fix security headers tests for environment detection
- Fix mobile auth tests to use raw_token
- Fix LiveView test assertions to match actual template content
- Fix SNMP config test expectations for test environment
- Refactor: resolve all Credo complexity/nesting issues
  - Extract helper functions in NetBox sync, VISP sync, Sonar sync
  - Flatten nested conditionals in settings, integrations, alerts
  - Use with/validate_present pattern for connection testing
2026-02-15 11:55:49 -06:00
bad1590fed
add gaiia webhook listener with per-org signature verification
Stage 3 of Gaiia integration: webhook event processing for real-time
incremental updates from Gaiia. HMAC-SHA256 signature verification
using per-organization secrets stored in integration credentials.
Handles account, billing subscription, and inventory item events.
2026-02-13 10:40:49 -06:00
95e3870fec
feat: add Force10 FTOS and optical transceiver monitoring (ProCurve, Comware)
Completed Tier 1 (critical network switches) and Tier 2 (optical transceiver monitoring)
from Phase 3 implementation plan. All major network switches now have comprehensive sensor
coverage including temperature and fiber optic link diagnostics.

Files Changed:
- priv/profiles/os_discovery/ftos.yaml (enhanced)
  Added Dell Force10 FTOS temperature monitoring for all 3 series:
  - S-Series: Stack unit temperature (chStackUnitTemp)
    OID: .1.3.6.1.4.1.6027.3.10.1.2.2.1.14
    MIB: F10-S-SERIES-CHASSIS-MIB
  - C-Series: Card temperature (chSysCardTemp)
    OID: .1.3.6.1.4.1.6027.3.8.1.2.1.1.5
    MIB: F10-C-SERIES-CHASSIS-MIB
  - E-Series: Card upper + lower temperature (chSysCardUpperTemp, chSysCardLowerTemp)
    OIDs: .1.3.6.1.4.1.6027.3.1.1.2.3.1.8-9
    MIB: F10-CHASSIS-MIB
  Gap: CRITICAL (no sensors) → RESOLVED
  Parity: 0% → 90%

- priv/profiles/os_discovery/procurve.yaml (enhanced)
  Added HP ProCurve transceiver optical monitoring (5 sensor types):
  MIB: HP-ICF-TRANSCEIVER-MIB::hpicfXcvrInfoTable
  Sensors:
    - Temperature: hpicfXcvrTemp (OID .1.3.6.1.4.1.11.2.14.11.5.1.82.1.1.1.1.11, divisor 1000)
    - Bias Current: hpicfXcvrBias (OID .1.3.6.1.4.1.11.2.14.11.5.1.82.1.1.1.1.13, divisor 1000)
    - Supply Voltage: hpicfXcvrVoltage (OID .1.3.6.1.4.1.11.2.14.11.5.1.82.1.1.1.1.12, divisor 1000)
    - RX Power (dBm): hpicfXcvrRxPower (OID .1.3.6.1.4.1.11.2.14.11.5.1.82.1.1.1.1.14, divisor 10)
    - TX Power (dBm): hpicfXcvrTxPower (OID .1.3.6.1.4.1.11.2.14.11.5.1.82.1.1.1.1.15, divisor 10)
  Gap: HIGH (missing transceivers) → RESOLVED
  Parity: 60% → 100%

- priv/profiles/os_discovery/comware.yaml (enhanced)
  Added HP Comware transceiver optical monitoring (5 sensor types):
  MIB: HH3C-TRANSCEIVER-INFO-MIB::hh3cTransceiverInfoTable
  Sensors:
    - Temperature: hh3cTransceiverTemperature (OID .1.3.6.1.4.1.25506.2.70.1.1.1.15)
    - Bias Current: hh3cTransceiverBiasCurrent (OID .1.3.6.1.4.1.25506.2.70.1.1.1.17)
    - Supply Voltage: hh3cTransceiverVoltage (OID .1.3.6.1.4.1.25506.2.70.1.1.1.16)
    - RX Power (dBm): hh3cTransceiverCurRXPower (OID .1.3.6.1.4.1.25506.2.70.1.1.1.9, divisor 100)
    - TX Power (dBm): hh3cTransceiverCurTXPower (OID .1.3.6.1.4.1.25506.2.70.1.1.1.12, divisor 100)
  Gap: HIGH (missing transceivers) → RESOLVED
  Parity: 60% → 95%

- test/towerops_web/controllers/api/mobile_controller_test.exs (fixed)
  Fixed Credo warning: replaced length/1 with empty list comparison

- CHANGELOG.txt (updated)
  Documented Tier 1 + Tier 2 completion

Impact:
- Force10 FTOS: Complete temperature monitoring for S/C/E-Series data center switches
- ProCurve: Full optical transceiver diagnostics (SFP/SFP+ monitoring)
- Comware: Full optical transceiver diagnostics (completes sensor coverage)

Business Value:
- All major network switch platforms now have fundamental temperature monitoring
- Fiber optic link health monitoring enabled for ProCurve and Comware
- Data center switches (Force10 FTOS) fully supported
- Enables proactive maintenance (detect failing transceivers before link failure)

Parity Achievement:
- Tier 1 Complete: HP Comware (60→95%), Dell PowerConnect (0→80%), Dell SONiC (0→95%),
  Dell Force10 FTOS (0→90%)
- Tier 2 Complete: HP ProCurve (60→100%), HP Comware (95% - transceivers added)

Next Steps: Tier 3 (storage/compute platforms: PowerVault, Dell Servers, hpblmos)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-12 08:19:12 -06:00
aa9ed52bff
feat: add critical network switch sensor support (HP Comware, Dell PowerConnect, Dell SONiC)
Implemented top 3 critical network switch sensor gaps identified in Phase 3 analysis.
Restores fundamental temperature monitoring for common enterprise switch platforms.

Files Changed:
- priv/profiles/os_discovery/comware.yaml (enhanced)
  Added HP Comware chassis temperature monitoring via HH3C-ENTITY-EXT-MIB
  OID: 1.3.6.1.4.1.25506.2.6.1.1.1.1.12 (hh3cEntityExtTemperature)
  Uses entPhysicalName for sensor descriptions
  Gap: CRITICAL (broke fundamental monitoring) → RESOLVED
  Parity: 40% → 60%

- priv/profiles/os_discovery/powerconnect.yaml (enhanced)
  Added Dell PowerConnect/DNOS CPU temperature monitoring
  OID: 1.3.6.1.4.1.674.10895.5000.2.6132.1.1.43.1.8.1.5
  MIB: FASTPATH-BOXSERVICES-PRIVATE-MIB
  Gap: CRITICAL (no sensors) → RESOLVED
  Parity: 0% → 80%

- priv/profiles/os_discovery/dell-sonic.yaml (new)
  Created comprehensive Dell SONiC sensor profile
  MIB: NETGEAR-BOXSERVICES-PRIVATE-MIB (Quanta-based)
  Sensors:
    - Temperature: boxServicesTempSensorState (OID .1.3.6.1.4.1.4413.1.1.43.1.8.1.4)
    - Fan Speed: boxServicesFanSpeed (OID .1.3.6.1.4.1.4413.1.1.43.1.6.1.4)
    - PSU State: boxServicesPowSupplyItemState (OID .1.3.6.1.4.1.4413.1.1.43.1.7.1.3)
      States: other, notpresent, operational, failed, powering, nopower,
              notpowering, incompatible
  Gap: CRITICAL (OS detected, no sensors) → RESOLVED
  Parity: 0% → 95%

- test/towerops_web/plugs/brute_force_protection_test.exs (fixed)
  Fixed Credo warning: replaced length/1 with empty list comparison

- CHANGELOG.txt (updated)
  Documented Phase 3 analysis completion and critical fix implementation

Impact:
- HP Comware: Enables overheating alerts (fundamental monitoring restored)
- Dell PowerConnect: First sensor support for common access switches
- Dell SONiC: Complete hardware monitoring for modern data center platform

Business Value:
- Resolves production blockers for customers with HP Comware switches
- Adds support for very common Dell enterprise access switches
- Enables monitoring for Dell's modern SONiC-based data center switches

Next Steps: Remaining Tier 1 switches (Dell Force10 FTOS), then Tier 2
(optical transceiver monitoring for ProCurve/Comware).

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-11 17:36:45 -06:00
c7df6a8569
Add CI-triggered mass agent update webhook
POST /api/v1/webhooks/agent-release triggers all connected agents
to self-update via their existing WebSocket channels. Authenticated
with a shared secret (AGENT_WEBHOOK_SECRET env var).

- Add ReleaseChecker.invalidate_cache/0 for fresh GitHub fetch
- Add Agents.list_updatable_agents/0 (enabled + seen < 10min)
- Add Agents.broadcast_mass_update/0 orchestration function
- Add WebhookAuth plug with timing-safe secret comparison
- Add AgentReleaseWebhookController with :webhook pipeline
- Configure AGENT_WEBHOOK_SECRET in dev/test/runtime configs
2026-02-10 13:40:32 -06:00
2911a3c17d
test fixes 2026-02-09 15:30:52 -06:00
8ee39a2d36
Add comprehensive tests for API authentication and authorization
Implemented tests for critical security modules with significant coverage improvements:
- ApiAuth plug: 0% → 100% (12 tests)
- Permissions module: 0% → 85% (32 tests)
- Devices API controller: 0% → 95% (22 tests)

Enhanced test fixtures to support membership roles and device creation with proper organization scoping.
2026-02-05 16:39:01 -06:00
8382b5df6a
make devices site optional and many test fix 2026-02-04 15:05:42 -06:00
6c8e670dae
docs: add gettext internationalization design
- Add comprehensive i18n design document with domain-based organization
  (default, errors, auth, equipment, admin, emails domains)
- Document helper functions, implementation patterns, and migration workflow
- Fix multiple test suite issues:
  * user_settings_live_test.exs: Update all tests to match current UI structure
    - Fix user.name references (use first_name/last_name)
    - Fix TOTP device creation (use create_totp_device/2)
    - Update tab URLs and form IDs
    - Update tab names (Account, API, Notifications)
    - Remove obsolete tabs (Organizations, Activity)
    - Fix password tests (pattern match redirect without flash token)
    - Update sudo mode behavior
  * account_data_controller_test.exs: Fix user profile assertions
  * rate_limit_test.exs: Fix unused variable warning
  * settings_live_test.exs: Fix organization form validation test
2026-02-02 09:33:01 -06:00
3c00dcf37c remove passkeys for now 2026-01-31 09:50:35 -06:00
22ae257b60 refactor 2026-01-31 09:35:07 -06:00
eb91798729
agent improvements and agent config 2026-01-16 17:26:51 -06:00
a2d96f8e6e
Implement hierarchical agent assignment for SNMP polling
Add three-level agent assignment hierarchy (Equipment > Site > Organization)
allowing flexible agent deployment strategies. Agents now receive only equipment
assigned to them through direct assignment or inheritance from site/organization
defaults.

Key changes:
- Add agent_token_id to Sites table with migration
- Implement get_effective_agent_token/1 for hierarchical resolution
- Add list_agent_polling_targets/1 to return polling targets per agent
- Update API config endpoint to use hierarchical polling targets
- Add agent assignment UI to equipment, site, and organization forms
- Show agent source (direct/site/org/none) in equipment form
- Add equipment count column to agent list
- Update terminology from "poll from server" to "cloud polling"

Tests:
- Add 8 comprehensive tests for list_agent_polling_targets/1
- Add end-to-end test for hierarchical config endpoint
- All 775 tests passing
2026-01-14 08:38:50 -06:00
8291c6092a
Add comprehensive AgentController edge case tests
Added 6 new tests covering previously untested scenarios:
- Equipment without SNMP device (nil sensors/interfaces)
- Protobuf metrics with unknown types
- JSON metrics with unknown types
- Metrics with nil timestamps
- Metrics with invalid ISO8601 timestamp strings

Coverage increased from 90.41% to near 100%.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-13 08:37:58 -06:00
3ef04f261f
protobufs 2026-01-09 17:33:01 -06:00
cf77949527
add remote agent setup 2026-01-09 13:15:31 -06:00