Commit graph

16 commits

Author SHA1 Message Date
65fbf3bb31
use datestamp instead of creating a version 2026-02-09 13:49:19 -06:00
df334e4db8
Security hardening and performance improvements 2026-02-04 16:50:36 -06:00
98d1bbbb21
structured logging 2026-01-31 15:40:42 -06:00
b8aecf0a55
more tests 2026-01-31 15:26:36 -06:00
bf1c6314cb
agent version tracking 2026-01-30 17:25:08 -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
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
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
efa8404ea6
rewrite with much simpler runtime 2026-01-16 17:27:10 -06:00
097c4bd581
Add automatic semver versioning for agent
Features:
- Parse and compare semantic versions from Docker Hub
- Check if current version is outdated on startup
- Only pull updates when newer version is available
- GitLab CI now tags images with Cargo.toml version
- Created bump-version.sh script for easy version bumping

How it works:
1. Cargo.toml contains source of truth version (0.1.0)
2. GitLab CI extracts version and tags Docker images with it
3. Agent queries Docker Hub for all semver tags
4. Compares current version against latest available
5. Only pulls and restarts if newer version exists

Version bumping workflow:
  ./scripts/bump-version.sh patch  # 0.1.0 -> 0.1.1
  ./scripts/bump-version.sh minor  # 0.1.0 -> 0.2.0
  ./scripts/bump-version.sh major  # 0.1.0 -> 1.0.0

This creates git commit and tag, ready to push.
2026-01-15 12:52:36 -06:00
38c3451266
Simplify auto-update logic to always pull latest tag
The previous version checking didn't work because:
- GitLab CI only creates semver tags when pushing Git tags
- Most builds use SHA hash tags, not version tags
- Comparing versions was unreliable

New approach:
- Simply pulls latest tag every hour
- Checks docker pull output to see if image changed
- Only restarts if a new image was actually pulled
- Logs the last_updated timestamp from Docker Hub for visibility
2026-01-15 08:39:22 -06:00
824f4388eb
Add automatic self-update capability to agent
The agent now checks for updates every hour and automatically updates
itself when a new version is available on Docker Hub.

Features:
- Periodic update checks (hourly via scheduler)
- Automatic Docker image pull when update available
- Graceful exit and restart with new version
- Non-blocking, runs in background task
- Requires Docker socket mount for self-update

Changes:
- Add UpdateInfo struct and get_update_info() function
- Add perform_self_update() to pull new image and restart
- Add update check ticker to scheduler (hourly)
- Include docker-cli in Dockerfile runtime stage
- Update docker-compose.example.yml with socket mount
- Update README and CLAUDE.md with auto-update docs

The agent will log update status:
- "Already running latest version" - no action
- "Performing self-update: X -> Y" - pulling new image
- "Exiting to allow restart with new version" - restarting

Requires:
- Docker socket mounted: /var/run/docker.sock:/var/run/docker.sock
- restart: unless-stopped in docker-compose (to restart after exit)
2026-01-14 16:50:32 -06:00
4a33be4f23
Fix cargo fmt formatting in version.rs 2026-01-14 16:28:40 -06:00
468528de66
Add Docker image version checking on agent startup
The agent now checks Docker Hub on startup to see if a newer version
is available and logs a warning if an update is detected.

Changes:
- Add version.rs module to query Docker Hub API
- Check for newer versions on startup (non-blocking)
- Log warning with docker pull command if update available
- Gracefully handle Docker Hub API failures
- Update CLAUDE.md with version checking documentation
2026-01-14 16:25:02 -06:00