NOTE: Every script is having a minimal functionality to show the way to approach the subject.
The project files can be pulled from GitHub: https://github.com/highwayofbits/hobpublic
——————————————————————————————————–
Normally we would run a command and get the result straight away. However when investigating issues we can monitor specific things, like interfaces and these commands would be interrupted by hand with Ctrl + C. The commands are called Nonreturning. When running them in the script we don’t want to run it endlessly.
Start_shell is a module as part of utils directory in PyEZ package. It allows to operate shell on Junos device. For the purpose of this post we will want to monitor an interface for 15s.
Parameters:
- ‘cli -c “monitor traffic interface ge-1/0/5 no-resolve size 1500″‘ – nonreturning command
- ‘this=None’ (it will allow nonreturning commands)
- ‘timeout=x’ – where ‘x’ will specify the duration in seconds
The result will be a tuple with the first item boolean (executed fine or not) and second item with the command output. In order to not have it all mixed up in one big tuple with no line breaks, grab the [1] item of the tuple and convert to string or print out directly.
The script:
Example result:
Leave a Reply