cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
158
Views
1
Helpful
2
Replies

Cisco router Speed test automation

Hi Cisco Community team,

I have cisco ISR 4331 router on which i want to perform speed test automation so when speed goes down i should get email trigger.

use cases.

1. every hour speed test automation result on email

2. If speed goes beyond x limit IT team should get email trigger.

Let me know if any guide or documents to achieve this use case.

2 Replies 2

Are you looking to have the speed test run from the router via your ISP/Upstream provider link, or a VM/Host behind the machine. Just trying to gather if you are wanting to this on box or off box.

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

suppy
Level 1
Level 1

First, you'll need to install the speedtest-cli library for speed testing and smtplib library for sending emails.

pip install speedtest-cli


Secondly, here's a Python script that performs the speed test, sends an email with the result every hour, and triggers an email if the speed goes beyond a specified limit (x_limit).

You can create a file named speed_test.py:


import speedtest
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import time

# Email Configuration
smtp_server = "smtp.yourmailserver.com"
smtp_port = 587
sender_email = "your_email@example.com"
receiver_email = "recipient_email@example.com"
password = "your_email_password"

# Speed Test Configuration
x_limit = 50  # Set your speed limit in Mbps

def send_email(subject, body
    msg = MIMEMultipart()
    msg['From'] = sender_email
    msg['To'] = receiver_email
    msg['Subject'] = subject
    msg.attach(MIMEText(body, 'plain'))

    server = smtplib.SMTP(smtp_server, smtp_port)
    server.starttls()
    server.login(sender_email, password)
    text = msg.as_string()
    server.sendmail(sender_email, receiver_email, text)
    server.quit()

def perform_speed_test():
    st = speedtest.Speedtest()
    st.get_best_server()
    download_speed = st.download() / 1e6  # in Mbps
    upload_speed = st.upload() / 1e6  # in Mbps
    return download_speed, upload_speed

while True:
    # Perform Speed Test
    download, upload = perform_speed_test()

    # Email the results
    subject = "Hourly Speed Test Results"
    body = f"Download Speed: {download:.2f} Mbps\nUpload Speed: {upload:.2f} Mbps"

    send_email(subject, body)

    # Check if speed is beyond the limit
    if download > x_limit:
        alert_subject = "High Speed Alert!"
        alert_body = f"Download speed ({download:.2f} Mbps) is beyond the limit of {x_limit} Mbps!"
        send_email(alert_subject, alert_body)

    # Wait for an hour before the next speed test
    time.sleep(3600)  # 3600 seconds = 1 hour

Please make sure you update the smtp_server, smtp_port, sender_email, receiver_email, and password variables with your email server details. Also, modify x_limit to set your desired speed limit in Mbps.

All the best.