review: 1.0.17 #77

Closed
opened 2026-03-28 04:21:02 +00:00 by mfreeman451 · 1 comment
Owner

Imported from GitHub.

Original GitHub issue: #211
Original author: @mfreeman451
Original URL: https://github.com/carverauto/serviceradar/issues/211
Original created: 2025-02-17T22:52:30Z


SNMP Checker Code Review Findings

Here's a list of findings from the recent code review. Please address these issues to improve the security, usability, and reliability of the SNMP checker.

Security

  • Critical: SNMP Community String: The default public community string is a major security risk. The configuration must require strong, unique community strings for each target. Document this prominently in the README.
  • High Priority: SNMP v3 Support: Implement SNMP v3 with proper authentication and encryption (USM).
  • Input Validation (Target Names, OIDs): Strengthen input validation for target names (use regular expressions) and OIDs (prevent injection).
  • Data Type Conversion Vulnerabilities: Ensure comprehensive error handling and logging in convertValue and helper functions. Consider fuzzing.
  • Denial-of-Service (DoS): Implement rate limiting and resource quotas to mitigate DoS risks. Add metrics on SNMP requests and errors.

Usability and Readability

  • #214
  • Clarity in Error Messages: Improve error messages (include OID name, target name, etc.).
  • Comments on Constants: Add comments to explain the purpose of constants.
  • Consider structured logging: Use a structured logging library like zap or logrus.

Potential Goroutine Problems

  • Error Channel Blocking: Increase the buffer size of errorChan or use a non-blocking send with error logging in SNMPCollector.
  • Collector Shutdown: Use a sync.WaitGroup in SNMPCollector.Stop to wait for the collect and handleErrors goroutines to exit.
  • Data Race on TargetStatus: The TargetStatus is updated by both the pollTarget and handleDataPoint functions. Protect with Mutexes.
  • Aggregator Reset: Protect reads/writes around Aggregator.Reset() to prevent race conditions.

Context Issues

  • #216
  • Context Timeout Configuration: Make defaultServiceStatusTimeout configurable.

Unbounded Growth

  • Time Series Data: Implement persistent storage or a more sophisticated in-memory caching mechanism with eviction policies for TimeSeriesData.
  • Target and OID Count: Consider strategies for horizontal scaling and resource management as the number of targets and OIDs increases.

Resource Leaks

  • SNMP Client Connections: Double-check that SNMP client connections are always closed properly (use defer).
  • Channel Closure: Double-check that all channels are eventually closed to prevent goroutine leaks.

Performance Issues

  • String Conversions: Use a sync.Pool to reuse string buffers in convertString.
  • OID Lookup: Use a map to store OID configurations in findOIDConfig.
  • Data Aggregation: Optimize the data structure used to store time series data for faster range queries.
  • Optimize SNMP GET requests: Consider using SNMP bulk GET requests.
Imported from GitHub. Original GitHub issue: #211 Original author: @mfreeman451 Original URL: https://github.com/carverauto/serviceradar/issues/211 Original created: 2025-02-17T22:52:30Z --- ## SNMP Checker Code Review Findings Here's a list of findings from the recent code review. Please address these issues to improve the security, usability, and reliability of the SNMP checker. ### Security - [ ] **Critical: SNMP Community String:** The default `public` community string is a major security risk. The configuration *must* require strong, unique community strings for each target. Document this prominently in the README. - [ ] **High Priority: SNMP v3 Support:** Implement SNMP v3 with proper authentication and encryption (USM). - [ ] **Input Validation (Target Names, OIDs):** Strengthen input validation for target names (use regular expressions) and OIDs (prevent injection). - [ ] **Data Type Conversion Vulnerabilities:** Ensure comprehensive error handling and logging in `convertValue` and helper functions. Consider fuzzing. - [x] **Denial-of-Service (DoS):** Implement rate limiting and resource quotas to mitigate DoS risks. Add metrics on SNMP requests and errors. ### Usability and Readability - [x] #214 - [ ] **Clarity in Error Messages:** Improve error messages (include OID name, target name, etc.). - [ ] **Comments on Constants:** Add comments to explain the purpose of constants. - [ ] **Consider structured logging:** Use a structured logging library like `zap` or `logrus`. ### Potential Goroutine Problems - [ ] **Error Channel Blocking:** Increase the buffer size of `errorChan` or use a non-blocking send with error logging in `SNMPCollector`. - [x] **Collector Shutdown:** Use a `sync.WaitGroup` in `SNMPCollector.Stop` to wait for the `collect` and `handleErrors` goroutines to exit. - [x] **Data Race on `TargetStatus`:** The `TargetStatus` is updated by both the `pollTarget` and `handleDataPoint` functions. Protect with Mutexes. - [x] **Aggregator Reset:** Protect reads/writes around `Aggregator.Reset()` to prevent race conditions. ### Context Issues - [x] #216 - [ ] **Context Timeout Configuration:** Make `defaultServiceStatusTimeout` configurable. ### Unbounded Growth - [ ] **Time Series Data:** Implement persistent storage or a more sophisticated in-memory caching mechanism with eviction policies for `TimeSeriesData`. - [ ] **Target and OID Count:** Consider strategies for horizontal scaling and resource management as the number of targets and OIDs increases. ### Resource Leaks - [ ] **SNMP Client Connections:** Double-check that SNMP client connections are always closed properly (use `defer`). - [ ] **Channel Closure:** Double-check that all channels are eventually closed to prevent goroutine leaks. ### Performance Issues - [ ] **String Conversions:** Use a `sync.Pool` to reuse string buffers in `convertString`. - [ ] **OID Lookup:** Use a map to store OID configurations in `findOIDConfig`. - [ ] **Data Aggregation:** Optimize the data structure used to store time series data for faster range queries. - [ ] **Optimize SNMP GET requests:** Consider using SNMP bulk GET requests.
Author
Owner

Imported GitHub comment.

Original author: @mfreeman451
Original URL: https://github.com/carverauto/serviceradar/issues/211#issuecomment-2670445644
Original created: 2025-02-20T04:38:26Z


closing, will run again for 1.0.18

Imported GitHub comment. Original author: @mfreeman451 Original URL: https://github.com/carverauto/serviceradar/issues/211#issuecomment-2670445644 Original created: 2025-02-20T04:38:26Z --- closing, will run again for 1.0.18
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
carverauto/serviceradar#77
No description provided.