A Python-based monitoring system that tracks the Kp geomagnetic index from GFZ Potsdam and sends automated email alerts when space weather conditions exceed specified thresholds.
- Real-time monitoring of Kp geomagnetic index from GFZ ensemble forecast data
- Configurable alert thresholds with YAML-based configuration
- Email notifications via local SMTP with HTML formatting and embedded forecast images
- Multiple operation modes: single check (
--once) and continuous monitoring (--continuous) - Comprehensive logging with configurable levels and log folder management
- Smart alert management to prevent spam (6-hour cooldown between alerts)
- Rich HTML emails with detailed space weather information, probability tables, and forecast charts
- Aurora watch notifications for Kp ≥ 6+ conditions
- NOAA scale integration for geomagnetic storm classification
git clone https://github.com/GFZ/kp_alert.git
cd kp_alert
pip install -r requirements.txtpip install -e .This installs the kp-alert command-line tool globally.
Copy config.yaml.template to customize your monitoring setup:
cp config.yaml.template config.yaml# Alert settings
kp_alert_threshold: 6.0 # Kp value to trigger alerts (0-9 scale)
check_interval_hours: 1 # Hours between checks in continuous mode
# Email recipients
recipients:
- "spaceweather@yourorg.com"
- "alerts@yourorg.com"
# Logging configuration
log_folder: "./logs" # Path to log folder
log_level: "INFO" # DEBUG, INFO, WARNING, ERROR
# Debug settings
debug_with_swpc: false # Use SWPC overplot images if trueSingle check:
python -m src.kp_index_monitor --onceContinuous monitoring:
python -m src.kp_index_monitor --continuousUsing the installed command-line tool (after pip install):
kp-alert --once
kp-alert --continuousThe system uses YAML configuration files for easy management. You can specify a custom config file using the KP_MONITOR_CONFIG environment variable:
export KP_MONITOR_CONFIG=/path/to/custom_config.yaml
python -m src.kp_index_monitor --once| Parameter | Type | Description | Valid Range |
|---|---|---|---|
kp_alert_threshold |
float | Kp value triggering alerts | 0.0 - 9.0 |
check_interval_hours |
float | Hours between checks | > 0.0 |
recipients |
list | Email addresses for alerts | Valid email format |
log_folder |
string | Path to log folder | Valid directory path |
log_level |
string | Logging verbosity | DEBUG/INFO/WARNING/ERROR |
debug_with_swpc |
bool | Use SWPC comparison images | true/false |
Research Station (High Sensitivity):
kp_alert_threshold: 4.0
check_interval_hours: 1.0
recipients: ["operations@station.gov"]
log_folder: "./logs"
log_level: "DEBUG"
debug_with_swpc: falsePower Grid Monitoring (Critical Events Only):
kp_alert_threshold: 6.0
check_interval_hours: 0.5
recipients: ["grid-ops@utility.com", "duty-manager@utility.com"]
log_folder: "./logs_production"
log_level: "INFO"
debug_with_swpc: trueRun one monitoring check and exit:
python -m src.kp_index_monitor --once
# or
kp-alert --oncePerfect for cron jobs or testing
Run continuously with scheduled checks:
python -m src.kp_index_monitor --continuous
# or
kp-alert --continuousIdeal for dedicated monitoring servers
This system uses the local Linux mail system (localhost SMTP) to send emails. This approach is more reliable for server deployments than external SMTP.
Ubuntu/Debian:
sudo apt-get install postfix mailutils
sudo dpkg-reconfigure postfixCentOS/RHEL:
sudo yum install postfix mailx
sudo systemctl enable postfix
sudo systemctl start postfixIf you prefer external SMTP, modify the send_alert() method in kp_index_monitor.py to use your preferred SMTP server and authentication.
- Provider: GFZ Helmholtz Centre for Geosciences
- URL: Internal GFZ data paths for ensemble forecast data
- Update Frequency: Every 3 hours (GFZ updates their forecast data)
- Format: CSV with ensemble forecast data
The system accesses GFZ internal data paths:
- CSV Data:
/PAGER/FLAG/data/published/products/Kp/kp_product_file_SWIFT_LAST.csv - Forecast Image:
/PAGER/FLAG/data/published/kp_swift_ensemble_LAST.png - SWPC Comparison Image:
/PAGER/FLAG/data/published/kp_swift_ensemble_with_swpc_LAST.png
The latest ensemble predictions contain the following information:
- Time (UTC): Forecast time in dd-mm-yyyy HH:MM format
- minimum: Minimum forecasted Kp value
- 0.25-quantile: Value such that 25% of forecasts are below this level
- median: Median forecasted Kp value
- 0.75-quantile: Value such that 75% of forecasts are below this level
- maximum: Maximum forecasted Kp value
- prob 4-5: Probability of 4 ≤ Kp ≤ 5
- prob 5-6: Probability of 5 ≤ Kp ≤ 6
- prob 6-7: Probability of 6 ≤ Kp ≤ 7
- prob 7-8: Probability of 7 ≤ Kp ≤ 8
- prob ≥ 8: Probability of Kp ≥ 8
- Individual ensemble members: Indexed as
kp_i, where i is a progressive integer number - Current ensemble size: Varies between 12 and 20 members
- Used for probability calculations: Percentage of ensemble members exceeding thresholds
The Kp index scale and corresponding geomagnetic storm levels:
| Kp Range | Classification | NOAA Scale | Impact Level |
|---|---|---|---|
| Kp 0-2 | Quiet | - | No impact |
| Kp 3-4 | Unsettled to Active | - | Minor impact |
| Kp 5 | Minor Storm | G1 | Weak power grid fluctuations |
| Kp 6 | Moderate Storm | G2 | High-latitude power systems affected |
| Kp 7 | Strong Storm | G3 | Power systems voltage corrections needed |
| Kp 8 | Severe Storm | G4 | Widespread voltage control problems |
| Kp 9 | Extreme Storm | G5 | Complete power system blackouts possible |
Add to crontab for automatic execution:
crontab -e
# Run single check every hour
0 * * * * cd /path/to/kp_alert && /usr/bin/python3 -m src.kp_index_monitor --once
# Or using the installed command
0 * * * * cd /path/to/kp_alert && kp-alert --onceCreate /etc/systemd/system/kp-monitor.service:
[Unit]
Description=Kp Index Space Weather Monitor
After=network.target
[Service]
Type=simple
User=kp-monitor
WorkingDirectory=/opt/kp-alert
ExecStart=/usr/bin/python3 -m src.kp_index_monitor --continuous
Restart=always
RestartSec=300
Environment=KP_MONITOR_CONFIG=/opt/kp-alert/config.yaml
[Install]
WantedBy=multi-user.targetEnable and start:
sudo systemctl enable kp-monitor
sudo systemctl start kp-monitor
sudo systemctl status kp-monitor-
Test single monitoring check:
python -m src.kp_index_monitor --once
-
Validate configuration:
python -c "from src.config import MonitorConfig; config = MonitorConfig.from_yaml(); print('Configuration valid!')"
-
Email sending fails:
- Check if local mail system (postfix) is running:
sudo systemctl status postfix - Test mail system:
echo "Test" | mail -s "Test Subject" your-email@domain.com - Check mail logs:
sudo tail -f /var/log/mail.log
- Check if local mail system (postfix) is running:
-
Data fetch fails:
- Check GFZ internal network connectivity
- Verify access to internal data paths
- Check logs for specific error messages
-
Configuration errors:
- Validate YAML syntax:
python -c "import yaml; yaml.safe_load(open('config.yaml'))" - Check file permissions:
ls -la config.yaml - Verify email format in recipients list
- Validate YAML syntax:
-
Permission errors on server:
- Ensure proper file permissions:
chmod 644 config.yaml - Run as appropriate user
- Check systemd service user permissions
- Ensure proper file permissions:
Monitor system activity with timestamped log files:
# Watch real-time logs (adjust date as needed)
tail -f ./logs/kp_monitor_once_20251510.log
# Check for errors
grep ERROR ./logs/kp_monitor_*.log
# View recent activity
tail -50 ./logs/kp_monitor_*.logThe system automatically validates configuration on startup:
- Kp threshold: Must be between 0-9
- Check interval: Must be positive
- Email addresses: Must be valid format
- Log file: Must be accessible path
Error messages will indicate specific validation failures.
- Configuration files: Keep
config.yamlsecure with appropriate file permissions (644 or 600) - Email security: Uses local mail system to avoid storing external credentials
- Service accounts: Use dedicated user accounts for production deployment
- Log management: Monitor log files and implement log rotation
- Network security: Firewall rules for production servers
kp_alert/
├── src/
│ ├── __init__.py # Package initialization
│ ├── config.py # Configuration management with YAML support
│ └── kp_index_monitor.py # Main monitoring application with typer CLI
├── config.yaml # Main configuration file
├── config.yaml.template # Configuration template
├── pyproject.toml # Python project configuration
├── requirements.txt # Python dependencies
└── README.md # Documentation
- YAML Configuration: Type-safe configuration with validation
- Robust Error Handling: Graceful handling of network and data issues
- Smart Alert Logic: 6-hour cooldown to prevent alert spam
- Local SMTP: No external credentials required
- Rich HTML Emails: Embedded forecast images and probability tables
- Aurora Notifications: Special alerts for Kp ≥ 6+ conditions
- CLI Interface: Typer-based command line interface with
--onceand--continuousmodes - Flexible Installation: Can be installed as a pip package with
kp-alertcommand
This project is for educational and research purposes.
Data Attribution: Kp data provided by GFZ Helmholtz Centre for Geosciences.
Authors: Sahil Jhawar, Infant Ronald Reagan Johnson Amalraj
For issues and questions:
- GitHub Issues:
- Mail to the authors at (provided in
pyproject.toml)