-
Notifications
You must be signed in to change notification settings - Fork 1
Add sensor log monitoring with improved configuration support #388
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Add sensor log monitoring with improved configuration support #388
Conversation
…xisting plugin configs. New issue raised for DRYing the config validation
…iguration flexibility - Introduced `SensorLogMonitorState` model for tracking monitoring state. - Added monitoring job to alert on missing sensor logs based on configurable thresholds. - Updated `SmibhidSensorPluginConfig` to include monitoring settings. - Enhanced utility module with `get_humanized_timedelta` for user-friendly time outputs. - Adjusted plugin to conditionally enable or disable monitoring based on configuration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Implements sensor log monitoring functionality with configurable alerts and improves configuration validation across the codebase.
- Added monitoring job to detect when sensor logs are missing beyond configurable thresholds
- Enhanced configuration system with better error handling and validation
- Introduced timezone-aware database operations for improved reliability
Reviewed Changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.
Show a summary per file
File | Description |
---|---|
src/smib/utilities/init.py | Adds humanized time delta formatting utility |
src/smib/plugins/lifecycle_manager.py | Enhanced plugin registration error handling for configuration failures |
src/smib/db/manager.py | Enables timezone-aware MongoDB operations |
src/smib/config/_env_base_settings.py | Adds enum parsing and none string handling |
src/smib/config/init.py | Makes validation error formatter public and updates signature |
src/plugins/space/spacestate/config.py | Adds configuration validation with proper error handling |
src/plugins/space/smibhid/sensor/models.py | Adds monitoring state model and latest log query method |
src/plugins/space/smibhid/sensor/config.py | New configuration class for sensor monitoring settings |
src/plugins/space/smibhid/sensor/init.py | Implements scheduled sensor log monitoring with Slack alerts |
src/plugins/space/smibhid/init.py | Updates plugin registration to include scheduler interface |
SETTINGS.md | Documents new sensor monitoring configuration options |
README.md | Updates plugin description to mention monitoring feature |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
@sjefferson99 Ok, I've updated as per the GH Copilot review - all made sense! |
@sam57719 Code looks good bar the comment above. I will pull onto smib-dev and confirm I can get it to build and trigger warnings. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactor of code block in comment.
…dability and reuse - Extracted monitoring logic into helper functions: `_log_monitoring_settings`, `_fetch_latest_log`, `_compute_monitor_flags`, `_send_alert`, and `_update_monitor_state`. - Streamlined sensor monitor setup with `setup_monitor_job` and `setup_routes` for clearer structure. - Improved separation of concerns for better maintainability.
Pushed a refactored version |
…ved-within-x-minutes
…ved-within-x-minutes
…ved-within-x-minutes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sam57719 Got these errors in smib log when testing using seconds for config vars as per documentation.
2025-10-04T20:38:56.279610614Z [ERROR] [S.M.I.B.H.I.D. Sensor Plugin Config]: He's dead, Jim 🖖
2025-10-04T20:38:56.279687872Z Validation error for SmibhidSensorPluginConfig:
2025-10-04T20:38:56.279696909Z • monitor_interval:
2025-10-04T20:38:56.279704613Z Error: Input should be a valid timedelta, "day" identifier in duration not correctly formatted
2025-10-04T20:38:56.279712168Z Provided Value: 60
2025-10-04T20:38:56.279719057Z Setting Description: Interval between sensor log monitor checks. Accepts seconds (int), 'HH:MM:SS', or ISO8601 durations like 'PT10M'. If None, no monitoring is performed.
2025-10-04T20:38:56.279726631Z Setting Environment Variable: SMIB_PLUGIN_SMIBHID_SENSOR_MONITOR_INTERVAL
2025-10-04T20:38:56.279733742Z Setting Type: datetime.timedelta | None
2025-10-04T20:38:56.279740538Z Setting Default: 0:01:00
2025-10-04T20:38:56.279777427Z • monitor_alert_threshold:
2025-10-04T20:38:56.279785316Z Error: Input should be a valid timedelta, "day" identifier in duration not correctly formatted
2025-10-04T20:38:56.279792778Z Provided Value: 120
2025-10-04T20:38:56.279799371Z Setting Description: Interval between sensor log monitor alerts. Accepts seconds (int), 'HH:MM:SS', or ISO8601 durations like 'PT10M'.
2025-10-04T20:38:56.279806723Z Setting Environment Variable: SMIB_PLUGIN_SMIBHID_SENSOR_MONITOR_ALERT_THRESHOLD
2025-10-04T20:38:56.279813630Z Setting Type: timedelta
2025-10-04T20:38:56.279820389Z Setting Default: 1:00:00
2025-10-04T20:38:56.279826963Z • monitor_alert_resend_interval:
2025-10-04T20:38:56.279833667Z Error: Input should be a valid timedelta, "day" identifier in duration not correctly formatted
2025-10-04T20:38:56.279840926Z Provided Value: 60
2025-10-04T20:38:56.279847630Z Setting Description: Interval to resend sensor log monitor alerts if the issue is not resolved. Accepts seconds (int), 'HH:MM:SS', or ISO8601 durations like 'PT10M'. If None, alerts are only sent once per issue.
2025-10-04T20:38:56.279855500Z Setting Environment Variable: SMIB_PLUGIN_SMIBHID_SENSOR_MONITOR_ALERT_RESEND_INTERVAL
2025-10-04T20:38:56.279862407Z Setting Type: datetime.timedelta | None
2025-10-04T20:38:56.279869055Z Setting Default: None
2025-10-04T20:38:56.280128497Z [ERROR] [PluginLifecycleManager]: Failed to register plugin smibhid (space/smibhid): Invalid configuration
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sam57719 Otherwise all works as expected. Will approve once the documentation or code has been updated around the monitor option vars accepting seconds.
SensorLogMonitorState
model to track the state of sensor log monitoring.SmibhidSensorPluginConfig
to include new monitoring options. (See SETTINGS.md)get_humanized_timedelta
function for human-readable time differences.tz_aware=True
forAsyncMongoClient
to ensure timezone-aware database operations.