This project leverages Genie/pyATS framework, WebEx Messenger and python logging module to check access into network devices by displaying, sending the result to WebEx Messenger Space and triggering logs to Syslog server for information and maintenance purposes. This project exploits the simplicity of Genie/pyATS framework with its connect() method in order to check the access by simply handling ConnectionError exception.
Keep in mind that this project is not to test connectivity, it allows to check access and can be used in many ways :
Here is the topology used in this project:
GNS3 was used with Cisco routers and a Linux machine as Admin since the framework Genie/PyATS works only on Linux or Mac OSX. However, you can use the Windows Subsystem for Linux (WSL), as the case of this project represented here by the Admin host as shown in the topology. You can also test this project using your own emulator or the DevNet Sandbox Cisco Modeling Labs (CML). You just need to modify the parameters concerning the information about the devices used in the connex.yml file (IP addresses, users, IOS type, ...).
The best practice is to leverage Python Virtual Environments (env). Please follow these steps to clone the Git repository and create and active the virtual environment:
git clone https://github.com/cherifimehdi/Check_Access.git
cd Check_Access
python3 -m venv venv
source venv/bin/activate
pip3 install -r requirements.txt
As the packages used are found in requirements.txt file, alternatively, you can install the packages as follows:
pip3 install pyats[full]
pip3 install requests
pip3 install requests-toolbelt
pip3 install prettytable
pip3 install python-dotenv
Please consider to:
Once the dependenties are installed and parameters are taken into account for connex.yml, .env files and check_access.py script, you can run the script check_access.py.
This project allows :
Here we run check_access.py script from the Admin host:
(Check_Access) [mehdi@Check_Access]$ python check_access.py +--------------------+ | Access Check | +--------+-----------+ | Device | Status | +--------+-----------+ | R1 | Access Ok | | R2 | Access Ok | | R3 | Access Ok | +--------+-----------+
Here the result sent to the Syslog Server:
Here the result sent as a text file to our Webex Space:
Now, we can download the Result.txt file and consult the check access result for the network devices as shown below:
Now we will deactivate the management interface of the router R2
Now we run the check_access.py script from the Admin host:
(Check_Access) [mehdi@Check_Access]$ python check_access.py +--------------------+ | Access Check | +--------+-----------+ | Device | Status | +--------+-----------+ | R1 | Access Ok | | R2 | No Access | | R3 | Access Ok | +--------+-----------+
As expected, the Syslog server received the logs:
The Result.txt file is now available for download and viewing from WebEx Messenger Space
As it shows from the console, the Syslog server and the Result.txt file, we have an access issue with the Router R2.
Active Cisco CCAI Instructor and Network Engineering Trainer. Part of Cisco DevNet Class 2020. Cisco DevNet Code Exchange and Automation Exchange Contributor.
I am interesting in all about NetDevOps, Networking programmability and automation. I am a Cisco contents fan.
Validate/Monitor access to network devices
The present use case leverages Genie/pyATS, WebEx Messenger and python logging module to efficiency Validate/Monitor access to network devices by displaying, sending the result to WebEx Messenger Space and triggering logs to Syslog server for information and maintenance purposes. The present project can be used for:
Keep in mind that this project is not to test connectivity, it allows to check access to network devices through their management interfaces.
Please refer to these white papers:
Getting started with pyATS Library Genie : Kickoff your Genie experience!
Here a blog post from Hank Preston in case of using CML2: How can I automate device configurations using CML2?
Cisco DevNet Sandbox Cisco Modeling Labs
How pyATS can be used as an end-to-end DevOps automation ecosystem: Accelerating your DevOps with pyATS
This use case shows an efficent and optimized way to retrieve data from network devices with checking access process by leveraging the Validate/Monitor access to network devices with the integration of Genie/pyATS, WebEx Messenger and Syslog server use case relating with the project Check_Access.
Suppose we have 100 network devices and we have access only to 50 of them, the retriving data process is applied only to these 50 devices witch conduct to save the time with generating logs to Syslog server for maintenance purposes besides the report sent to WebEx Messenger Space.
In summary, this project aims to :
We focus here only on the result for the Syslog server notifications and the package installation and requirements, the others details like configuration files modification, topology and the WebEx Messenger result could be found at Check_Access repository related to Validate/Monitor access to network devices with the integration of Genie/pyATS, WebEx Messenger and Syslog server use case as it is a part of this project.
Cisco DevNet Sandbox Cisco Modeling Labs
How pyATS can be used as an end-to-end DevOps automation ecosystem: Accelerating your DevOps with pyATS
Code Exchange Community
Get help, share code, and collaborate with other developers in the Code Exchange community.View Community