Python script to detect high cpu on device and automatically collect command outputs
Budget: ₹600 – ₹1,500 INR
from netmiko import ConnectHandler
# create a dictionary with the connection details
device = {
"device_type": "ruckus_fastiron",
"ip": "10.10.10.10",
"username": "admin",
"password": "pass",
}
# create an SSH connection to the device
ssh_conn = ConnectHandler(**device)
# send a command to the device and print the output
output = ssh_conn.send_command("show cpu")
print(output)
# close the SSH connection
ssh_conn.disconnect()
Code output:
============
1 percent busy, from 10874 sec ago
1 sec avg: 1 percent busy
5 sec avg: 1 percent busy
60 sec avg: 1 percent busy
300 sec avg: 1 percent busy
I am able to login into the device with above code in python and run the command "show cpu"
Task:
======
I need python script to loging into the device every 5 minutes interval,
read the output of 'show cpu' and whenever cpu utilization of 300 secs exceeds 50 percent then script should automatically run some commands as below and save it to a file
show cpu unitlization-task
show version
show interfaces
show module
Let me know if you can write a script for it.
# create a dictionary with the connection details
device = {
"device_type": "ruckus_fastiron",
"ip": "10.10.10.10",
"username": "admin",
"password": "pass",
}
# create an SSH connection to the device
ssh_conn = ConnectHandler(**device)
# send a command to the device and print the output
output = ssh_conn.send_command("show cpu")
print(output)
# close the SSH connection
ssh_conn.disconnect()
Code output:
============
1 percent busy, from 10874 sec ago
1 sec avg: 1 percent busy
5 sec avg: 1 percent busy
60 sec avg: 1 percent busy
300 sec avg: 1 percent busy
I am able to login into the device with above code in python and run the command "show cpu"
Task:
======
I need python script to loging into the device every 5 minutes interval,
read the output of 'show cpu' and whenever cpu utilization of 300 secs exceeds 50 percent then script should automatically run some commands as below and save it to a file
show cpu unitlization-task
show version
show interfaces
show module
Let me know if you can write a script for it.