Monitor Interface Errors and Alert on Slack
Lesson 5 of 10
The Scenario
CRC errors are slowly climbing on your core uplinks but nobody notices until users start complaining. You need a script that checks interface counters periodically and sends a Slack alert when errors exceed a threshold.
The Prompt
Write a Python script that:
1. SSHs into a list of core switches from devices.csv
2. Runs "show interfaces" and parses CRC errors, input errors, and output errors for each interface
3. Compares against thresholds: alert if any counter > 100 in the last check
4. Sends a Slack webhook message with the device, interface, error type, and count
5. Saves the current counters to a JSON file so the next run can calculate the delta
6. Designed to run every 15 minutes via cron
Slack webhook URL: https://hooks.slack.com/services/YOUR/WEBHOOK/URL
What AI Gives You
A polling script with delta tracking (compares current vs last run), threshold checking, and Slack integration via a simple HTTP POST.
Review and Validate
- Delta tracking is key — you want errors since last check, not total lifetime errors
- Slack webhook setup: Create one at api.slack.com/messaging/webhooks
- Threshold tuning: Start with 100, adjust based on your baseline
Try It Yourself
Start with a single switch. Run the script twice with 15 minutes apart. Check if the delta calculation works correctly before scaling to all devices.