SCADA Telemetry Stream Anomaly Monitor Generator
Generate a resilient Python telemetry monitoring script for power grid SCADA sensors.
Use this template when setting up real-time edge monitoring for utility substation sensors. It produces a hardened script that polls telemetry endpoints and fires alerts upon threshold breaches.
Role: Senior SCADA Systems Integration Engineer with deep expertise in industrial control systems and power distribution networks.
Context
- Operating entity: {{utility_provider}}
- Ingestion protocol: {{scada_protocol}}
- Sensor feed location: {{telemetry_data_source}}
- Operational threshold schema: {{sensor_threshold_profile}}
- Incident notification endpoint: {{alert_webhook_url}}
- Polling frequency: {{poll_interval_seconds}}
Task
Construct a production-ready Python monitoring script that ingests time-series telemetry from {{telemetry_data_source}} using {{scada_protocol}}, evaluates readings against {{sensor_threshold_profile}}, and publishes structured incident payloads to {{alert_webhook_url}} without stalling real-time telemetry processing for {{utility_provider}}.
Method
- Import required standard networking and industrial protocol client libraries based on {{scada_protocol}}.
- Define configuration constants and load {{sensor_threshold_profile}} boundaries into structured memory objects.
- Implement a resilient network connection wrapper targeting {{telemetry_data_source}} with exponential backoff retry logic.
- Build an asynchronous polling loop governed by {{poll_interval_seconds}} to sample voltage, current, and temperature streams.
- Write continuous anomaly detection logic comparing active sensor readings against deadbands and critical trip levels.
- Structure a standardized alert payload containing sensor tag, value, timestamp, threshold delta, and severity code.
- Implement an HTTP dispatcher transmitting the payload to {{alert_webhook_url}} using TLS verification and timeout guards.
- Add graceful SIGINT/SIGTERM handling to release industrial socket handles cleanly upon shutdown.
Constraints
- MUST implement strictly non-blocking I/O or background worker threads for alert dispatching.
- MUST NOT log cleartext authentication tokens or sensitive network credentials to standard output.
- Code MUST include inline type annotations and standard PEP 8 docstrings for every utility function.
- Script dependencies must be restricted to standard library modules plus one verified protocol driver.
Output format
1. Environment and Prerequisites
- Required external libraries and environment variables (max 10 lines).
2. Executable Script
- Fully commented Python script ready for systemd daemonization (100-180 lines).
3. Execution Verification
- Concrete command line example to start the script and test dry-run alerting (max 15 lines).
Self-review
- Confirm every variable from context is actively referenced in the generated script logic.
- Verify error handling catches transient connection drops without terminating the main process loop.
- Check that timestamp formatting strictly follows ISO 8601 UTC standards.
Explicit role, a named task, and discrete steps the model can follow.
Background, inputs and variables the model needs before it starts.
Hard boundaries — what the model must and must not do.
A named, field-level shape for the response.
Ordered work items that force analysis before an answer.
Length and structure that travel across frontier models.
Signal density — instruction weight without padding.
Documented variables so the scaffold adapts to new inputs.
Quality bar, assumptions and behaviour when inputs are thin.
How much real usage the template has behind it.