Commit graph

45 commits

Author SHA1 Message Date
792825f682
major overhaul to use more C for snmp, may not be stable 2026-02-09 12:31:41 -06:00
cd45e9ff51
feat: add agent-side ICMP ping health monitoring
Implements health monitoring in the agent using ICMP ping, allowing
devices assigned to local (non-cloud) agents to be monitored.

Changes:
- Add surge-ping library for async ICMP ping operations
- Create ping.rs module with ping_device() function (5s timeout)
- Rename JobType::MONITOR to JobType::PING in protobuf
- Add monitoring_check channels for result communication
- Implement execute_ping_job() to handle PING jobs
- Update TUI to display ping result events

The agent now receives PING jobs from Phoenix, executes ICMP pings,
and sends MonitoringCheck results back for storage in the database.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-08 13:44:09 -06:00
cee0788300
format 2026-02-07 11:43:50 -06:00
f5b7e589f2
fix: implement agent IP detection and remove dead poller code
- Implement get_local_ip() using UDP socket trick to resolve local
  interface address without sending traffic, so heartbeat reports
  actual agent IP instead of "unknown"
- Remove dead poller/scheduler/executor and api_client modules that
  referenced non-existent modules and were never compiled
2026-02-07 09:17:47 -06:00
2111453653
Fix TUI 2026-02-06 13:18:23 -06:00
6275562f35
Resolve issues from TUI implementation 2026-02-06 13:08:06 -06:00
a2cef243ee
Handle discovered ip addresses 2026-02-06 12:20:53 -06:00
8c969401fb
fix live and scheduled polling 2026-02-05 12:45:13 -06:00
f454a1f7ea
experimental tcp snmp handling 2026-02-04 17:25:39 -06:00
df334e4db8
Security hardening and performance improvements 2026-02-04 16:50:36 -06:00
91913bd6e4
Implement snmp v3 support 2026-02-04 12:02:10 -06:00
1be76b0049
show partially redacted snmp community 2026-02-03 16:50:11 -06:00
0f19518065
snmpv3 first stab 2026-02-03 16:46:19 -06:00
89a53eb07a
fix snmp community redaction 2026-02-02 17:03:46 -06:00
78aee7ce40
add ssh support 2026-02-02 16:39:09 -06:00
8e8ea6426d
mikrotik api improvements 2026-02-02 14:02:27 -06:00
d137925a0f
update deps 2026-02-02 13:26:02 -06:00
575735b0da
Handle generic mikrotik commands 2026-02-02 13:18:31 -06:00
98d1bbbb21
structured logging 2026-01-31 15:40:42 -06:00
c3e6e8c5b0
fix clippy error 2026-01-30 16:00:33 -06:00
380beaca1a
Agent overhaul with zero persistence 2026-01-30 15:50:20 -06:00
3793477e2f
relax ping failures 2026-01-29 12:12:01 -06:00
b8932f16b0
fix clippy issues 2026-01-29 12:02:20 -06:00
cee8d693da
make websocket client more robust 2026-01-29 11:55:01 -06:00
dbf66af5c0
support snmp v1 2026-01-29 11:28:45 -06:00
0548ca313d
include device id and ip in snmp error logs 2026-01-25 12:20:45 -06:00
8ee809d21e
websocket improvements 2026-01-23 12:43:11 -06:00
84b7519ad0
cargo clippy fix 2026-01-20 11:33:52 -06:00
6cea690e6b
format 2026-01-20 11:33:37 -06:00
71267870b0
refactor: remove log dependency, replace with custom macros
- Added custom logging macros (log_error!, log_warn!, log_info!, log_debug!)
- Implemented LogLevel enum and LOG_LEVEL static for runtime level control
- Exported macros with #[macro_export] for use across all modules
- Replaced all log:: calls in websocket_client.rs, health.rs, and version.rs
- Removed obsolete test code referencing old log crate
- Removed log dependency from Cargo.toml
- Fixed useless comparison warning in test
- Binary size: still 1.5M (no change - log was lightweight)
- Tests: 65 passing, 0 warnings

This completes the removal of 9 dependencies (thiserror, hostname, chrono,
base64, rand, ureq, tiny_http, anyhow, log). Dependency count: 19 → 10.

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-19 17:31:12 -06:00
55fb691440
refactor: remove 4 more dependencies (rand, ureq, tiny_http, anyhow)
Removed dependencies:
- rand: Replaced with SystemTime-based random for ICMP ID/sequence
- ureq: Removed Docker Hub version checking (Watchtower handles updates)
- tiny_http: Replaced with raw TCP listener for /health endpoint
- anyhow: Replaced with std::error::Error trait

Benefits:
- Binary size: 2.3M → 1.5M (800KB reduction, 35% smaller!)
- Dependencies: 19 → 11 direct dependencies (-8 total)
- Tests: 80 → 67 (removed Docker Hub API tests)
- All tests passing

Custom implementations:
- ICMP random: Use nanosecond timestamp for ID/sequence
- Health endpoint: Simple HTTP/1.1 parser on raw TCP
- Error handling: type Result<T> = std::result::Result<T, Box<dyn Error>>

Total progress from initial state:
- Binary: 2.4M → 1.5M (37.5% reduction!)
- Dependencies removed: 8 (thiserror, hostname, chrono, base64, rand, ureq, tiny_http, anyhow)
2026-01-19 17:20:49 -06:00
d132f03d8b
refactor: replace 4 dependencies with custom implementations
Removed dependencies and replaced with custom code:
- thiserror: Not used (only pulled by tokio-tungstenite)
- hostname: Replaced with /proc/sys/kernel/hostname reader
- chrono: Replaced with std::time::SystemTime + custom formatting
- base64: Replaced with custom base64 encoder/decoder

Benefits:
- Binary size: 2.4M → 2.3M (100KB reduction)
- Reduced dependency count: 19 → 15 direct dependencies
- Added 7 new tests (73 → 80 total tests)
- All tests pass

Custom implementations:
- format_timestamp(): YYYY-MM-DD HH:MM:SS.mmm format
- get_hostname(): Read from /proc/sys/kernel/hostname
- get_uptime_seconds(): Read from /proc/uptime
- base64_encode/decode(): Standard base64 encoding

No functionality changes, all existing features work identically.
2026-01-19 17:15:07 -06:00
0b3cc9121e
Add comprehensive unit test coverage (29.19%)
Add 73 unit tests covering all testable business logic:

- src/snmp/types.rs: 100% coverage (17/17 lines)
  * SnmpError display formatting
  * SnmpValue conversions (as_i64, as_f64)

- src/snmp/client.rs: 34.4% coverage (32/93 lines)
  * OID parsing/formatting/validation
  * SNMP value conversion for all types
  * Error mapping from snmp crate
  * Helper functions (starts_with, format_oid)

- src/ping.rs: 65.2% coverage (58/89 lines)
  * ICMP checksum calculation and verification
  * Echo request packet building
  * Reply packet parsing (raw and IP-wrapped)
  * IP header length extraction (IHL field)
  * Error handling for invalid packets

- src/version.rs: 54.0% coverage (27/50 lines)
  * Version parsing with optional 'v' prefix
  * Version comparison and sorting
  * Docker Hub response deserialization
  * Latest version extraction from tags

- src/websocket_client.rs: 7.7% coverage (17/221 lines)
  * SnmpValue to string conversion
  * Agent ID generation
  * Phoenix message serialization/deserialization
  * Helper functions (get_uptime_seconds, get_local_ip)

- src/main.rs: 20.0% coverage (11/55 lines)
  * SimpleLogger enabled() logic
  * HTTP/HTTPS to WebSocket URL conversion

- .gitlab-ci.yml: Add 'cargo test' to CI pipeline

Uncovered code requires integration testing:
- Network I/O (WebSocket, HTTP, Docker Hub API)
- System privileges (raw ICMP sockets)
- External services (SNMP devices, WebSocket servers)
- Runtime initialization (tokio main, logger setup)

All 73 tests pass. No test failures.
2026-01-19 15:07:00 -06:00
aa32be93be
fix: remove unused code to pass clippy CI checks 2026-01-19 13:42:00 -06:00
4269591803
Add ICMP monitoring support via WebSocket
- Add MonitoringCheck message to protobuf definitions
- Add monitoring_enabled and check_interval_seconds to Device and SnmpDevice
- Implement continuous ICMP ping monitoring for devices
- Send monitoring check results to Phoenix via WebSocket
- Integrate existing ping module with agent client
- Spawn background tasks for devices with monitoring enabled
2026-01-19 13:38:37 -06:00
a514cef8d0
update to new schema 2026-01-17 15:26:55 -06:00
02ea81cae3
Fix double slash in WebSocket URL by stripping trailing slash from base URL 2026-01-16 20:08:13 -06:00
6223638acf
Move token from URL to channel join payload 2026-01-16 18:23:37 -06:00
5f39f748a9
Fix WebSocket URL: add /websocket suffix for Phoenix Channels 2026-01-16 18:16:15 -06:00
cc0e250a88
Add Phoenix channel join handshake after WebSocket connection 2026-01-16 18:15:31 -06:00
13e45febce
Add detailed WebSocket connection error logging 2026-01-16 18:14:43 -06:00
b57c6ee3ec
format 2026-01-16 18:06:01 -06:00
812ee08ac5
Fix clippy warnings to pass CI build
- Remove unused SnmpError import
- Replace deprecated from_i32 with TryFrom
- Add #[allow(dead_code)] to unused SnmpValue methods
- Remove unused perform_self_update function
- Remove unused token field from AgentClient
- Remove unused send_error method
- Add #[allow(dead_code)] to protobuf generated module
2026-01-16 18:02:33 -06:00
967d317b69
Complete WebSocket migration for agent communication
Major architectural change from REST API polling to WebSocket-based
bidirectional communication:

**What Changed:**
- Agent now uses persistent WebSocket connection instead of REST API
- Server pushes SNMP query jobs to agent via Phoenix Channels
- Agent executes raw SNMP queries and returns results
- Removed complex polling/scheduling/buffering architecture

**New Files:**
- src/websocket_client.rs - WebSocket client with SNMP job execution
- Extended proto/agent.proto with WebSocket message types

**Modified Files:**
- src/main.rs - Simplified to connect and run WebSocket client
- src/health.rs - Simplified health endpoint (no storage needed)
- src/snmp/mod.rs - Export SnmpValue for WebSocket client

**Removed Files:**
- src/api_client.rs - Old REST API client
- src/config.rs - Old config types
- src/buffer/ - SQLite buffering (no longer needed)
- src/metrics/ - Old metric types
- src/poller/ - Polling/scheduling logic
- src/snmp/neighbor.rs - High-level neighbor discovery

**Dependencies:**
- Switched from native-tls to rustls for WebSocket TLS
- Uses tokio-tungstenite for WebSocket communication
- Protobuf for efficient binary message encoding

**Benefits:**
- Simpler agent architecture (~500 lines vs 5000+)
- Real-time job execution (<1s vs 60s polling)
- No duplicate SNMP profile logic
- No local storage/buffering complexity
- 68% smaller message payloads (protobuf vs JSON)
2026-01-16 17:57:41 -06:00
efa8404ea6
rewrite with much simpler runtime 2026-01-16 17:27:10 -06:00