Skip to content

Enhance SNMP monitoring with full agent implementation - #19

Closed
NickBorgers wants to merge 4 commits into
NickBorgers:mainfrom
NickBorgersOnLowSecurityNode:claude/enhance-snmp-monitor-011CV2b3XeAzdtne85thkDDJ
Closed

Enhance SNMP monitoring with full agent implementation#19
NickBorgers wants to merge 4 commits into
NickBorgers:mainfrom
NickBorgersOnLowSecurityNode:claude/enhance-snmp-monitor-011CV2b3XeAzdtne85thkDDJ

Conversation

@NickBorgers

Copy link
Copy Markdown
Owner

Major Enhancements

1. Complete SNMP Agent Server

  • Implemented full SNMP v2c agent responding to GET, GETNEXT, and GETBULK requests
  • Proper OID tree structure with hierarchical organization
  • Support for general statistics, per-site statistics, and recent test results
  • Community string authentication

2. OID Tree Structure

  • Branch 1 (.1.3.6.1.4.1.99999.1): General statistics (cache size, monitored sites, totals)
  • Branch 2 (.1.3.6.1.4.1.99999.2): Per-site statistics table (tests, success/failure, timing metrics)
  • Branch 3 (.1.3.6.1.4.1.99999.3): Recent test results table (last N tests with details)

3. SNMP Traps

  • Automatic trap sending for test failures
  • Service degradation traps when failure rate exceeds 50%
  • Configurable trap destinations (future feature, groundwork laid)

4. HTTP API for SNMP Data

  • /snmp/data - JSON representation of all SNMP metrics
  • /snmp/mib - Text format MIB definition
  • /snmp/oids - List of all available OIDs
  • Runs on SNMP_PORT + 1 (default 162)

5. Formal MIB Definition

  • Complete INTERNET-CONNECTION-MONITOR-MIB.txt following SNMPv2-SMI standards
  • Includes MODULE-IDENTITY, OBJECT-TYPE, and NOTIFICATION-TYPE definitions
  • Table structures for site statistics and recent tests
  • Conformance information with object groups

6. Comprehensive Testing

  • Unit tests for SNMP module (OID comparison, sorting, data export, statistics)
  • Integration tests for HTTP API endpoints
  • Tests for cache circular buffer behavior
  • Tests for GetSNMPData and MIB export functionality

7. Documentation

  • New SNMP_GUIDE.md with:
    • Configuration examples
    • OID reference tables
    • Usage examples (snmpget, snmpwalk, HTTP API)
    • Zabbix integration guide
    • Troubleshooting section
    • Security best practices
  • Updated README.md to highlight SNMP features
  • Updated TESTING.md to reflect SNMP test coverage

Technical Details

Implementation Changes

  • internal/outputs/snmp.go:
    • Replaced placeholder runSNMPAgent with full UDP server
    • Added OID tree initialization and handlers
    • Implemented SNMP packet processing (unmarshal, handle, marshal, respond)
    • Added HTTP server for easier debugging and testing
    • Implemented trap functionality with proper PDU construction
    • Enhanced Write() to send traps on failures

New Files

  • INTERNET-CONNECTION-MONITOR-MIB.txt: Formal MIB definition
  • SNMP_GUIDE.md: Comprehensive SNMP setup and usage guide
  • internal/outputs/snmp_test.go: Unit tests for SNMP functionality

Modified Files

  • README.md: Added SNMP features and documentation link
  • TESTING.md: Updated to reflect SNMP test coverage
  • test-integration.sh: Added SNMP HTTP API integration tests
  • go.mod: Temporarily set to Go 1.24 for build compatibility

Breaking Changes

None - SNMP is enabled by default but backwards compatible

Configuration

All configuration via environment variables:

  • SNMP_ENABLED (default: true)
  • SNMP_PORT (default: 161)
  • SNMP_COMMUNITY (default: public)
  • SNMP_LISTEN_ADDRESS (default: 0.0.0.0)
  • SNMP_ENTERPRISE_OID (default: .1.3.6.1.4.1.99999)

Future Enhancements

  • SNMPv3 with authentication and encryption
  • Configurable trap destinations via environment variables
  • SNMP protocol integration tests (requires snmp client tools)
  • Custom OID registration with IANA

🤖 Generated with Claude Code

## Major Enhancements

### 1. Complete SNMP Agent Server
- Implemented full SNMP v2c agent responding to GET, GETNEXT, and GETBULK requests
- Proper OID tree structure with hierarchical organization
- Support for general statistics, per-site statistics, and recent test results
- Community string authentication

### 2. OID Tree Structure
- **Branch 1 (.1.3.6.1.4.1.99999.1)**: General statistics (cache size, monitored sites, totals)
- **Branch 2 (.1.3.6.1.4.1.99999.2)**: Per-site statistics table (tests, success/failure, timing metrics)
- **Branch 3 (.1.3.6.1.4.1.99999.3)**: Recent test results table (last N tests with details)

### 3. SNMP Traps
- Automatic trap sending for test failures
- Service degradation traps when failure rate exceeds 50%
- Configurable trap destinations (future feature, groundwork laid)

### 4. HTTP API for SNMP Data
- `/snmp/data` - JSON representation of all SNMP metrics
- `/snmp/mib` - Text format MIB definition
- `/snmp/oids` - List of all available OIDs
- Runs on SNMP_PORT + 1 (default 162)

### 5. Formal MIB Definition
- Complete INTERNET-CONNECTION-MONITOR-MIB.txt following SNMPv2-SMI standards
- Includes MODULE-IDENTITY, OBJECT-TYPE, and NOTIFICATION-TYPE definitions
- Table structures for site statistics and recent tests
- Conformance information with object groups

### 6. Comprehensive Testing
- Unit tests for SNMP module (OID comparison, sorting, data export, statistics)
- Integration tests for HTTP API endpoints
- Tests for cache circular buffer behavior
- Tests for GetSNMPData and MIB export functionality

### 7. Documentation
- New SNMP_GUIDE.md with:
  - Configuration examples
  - OID reference tables
  - Usage examples (snmpget, snmpwalk, HTTP API)
  - Zabbix integration guide
  - Troubleshooting section
  - Security best practices
- Updated README.md to highlight SNMP features
- Updated TESTING.md to reflect SNMP test coverage

## Technical Details

### Implementation Changes
- `internal/outputs/snmp.go`:
  - Replaced placeholder runSNMPAgent with full UDP server
  - Added OID tree initialization and handlers
  - Implemented SNMP packet processing (unmarshal, handle, marshal, respond)
  - Added HTTP server for easier debugging and testing
  - Implemented trap functionality with proper PDU construction
  - Enhanced Write() to send traps on failures

### New Files
- `INTERNET-CONNECTION-MONITOR-MIB.txt`: Formal MIB definition
- `SNMP_GUIDE.md`: Comprehensive SNMP setup and usage guide
- `internal/outputs/snmp_test.go`: Unit tests for SNMP functionality

### Modified Files
- `README.md`: Added SNMP features and documentation link
- `TESTING.md`: Updated to reflect SNMP test coverage
- `test-integration.sh`: Added SNMP HTTP API integration tests
- `go.mod`: Temporarily set to Go 1.24 for build compatibility

## Breaking Changes
None - SNMP is enabled by default but backwards compatible

## Configuration
All configuration via environment variables:
- `SNMP_ENABLED` (default: true)
- `SNMP_PORT` (default: 161)
- `SNMP_COMMUNITY` (default: public)
- `SNMP_LISTEN_ADDRESS` (default: 0.0.0.0)
- `SNMP_ENTERPRISE_OID` (default: .1.3.6.1.4.1.99999)

## Future Enhancements
- SNMPv3 with authentication and encryption
- Configurable trap destinations via environment variables
- SNMP protocol integration tests (requires snmp client tools)
- Custom OID registration with IANA

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

Co-Authored-By: Claude <noreply@anthropic.com>
The dependency github.com/go-json-experiment/json requires Go 1.25.
This was temporarily changed to 1.24 for local build testing but needs
to be 1.25 for CI/CD pipeline.

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

Co-Authored-By: Claude <noreply@anthropic.com>
The handleOIDListRequest function was acquiring s.mu.RLock() and then
calling s.getAllOIDs(), which also acquires the same lock. This caused
a deadlock because RWMutex.RLock() is not reentrant in Go.

Fixed by removing the lock from handleOIDListRequest since getAllOIDs()
already handles its own locking internally.

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

Co-Authored-By: Claude <noreply@anthropic.com>
The custom recursive contains() function was inefficient and potentially
problematic. Replaced with the standard library strings.Contains() which
is faster and more reliable.

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

Co-Authored-By: Claude <noreply@anthropic.com>
@NickBorgers
NickBorgers deleted the claude/enhance-snmp-monitor-011CV2b3XeAzdtne85thkDDJ branch November 11, 2025 22:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants