iosxe_guestshell_logging
Example code and wrapper for Python's built-in logging package to enable syslog capture of logging messages on devices running Cisco IOS XE Software.
This implementation was based on information in the Programmability Configuration Guide, Cisco IOS XE Amsterdam 17.3.x.
Getting Started
-
Enable IOx and configure the
guestshellapplication using the Programmability Configuration Guide. -
Enter the
bashprompt from the network device:# guestshell run bash
-
Create a Python Virtual Environment inside the guestshell. Note: The system-installed Python installation includes Cisco-specific Python packages such as
eemandcli. To ensure those packages are available, use the--system-site-packagesargument to the Pythonvenvmodule, as shown below:python3 -m venv --system-site-packages venv
-
Activate the virtual environment:
source venv/bin/activate
-
Install this Python package, using
pip:pip install iosxe_guestshell_logging
-
Add the following lines to /home/guestshell/.bashrc to ensure the virtual environment's Python interpreter is loaded by default when a script is launched from Privileged Exec mode:
cat >> ~/.bashrc << EOF VIRTUAL_ENV=/home/guestshell/venv if [ -d ${VIRTUAL_ENV} ]; then PATH="${VIRTUAL_ENV}/bin:${PATH}" export VIRTUAL_ENV export PATH fi EOF
-
Exit guestshell to return to the Cisco IOS XE privileged exec prompt:
exit -
Verify the desired Python interpreter is executed when started from the device prompt:
rtr# guestshell run which python
The command should return:
/home/guestshell/venv/bin/python
Usage
After you create the virtual environment, update the .bashrc file, and verify the interpreter path, implementation is simple. Example code for logging to different syslog levels is as follows:
from iosxe_guestshell_logging import configure_guestshell_logging
logger = configure_guestshell_logging(__name__)
logger.critical("GuestShell example: Critical message (level 2)")
logger.error("GuestShell example: Error message (level 3)")
logger.warning("GuestShell example: Warning message (level 4)")
logger.notice("GuestShell example: Notice message (level 5)")
logger.info("GuestShell example: Info message (level 6)")
logger.debug("GuestShell example: Debug message (level 7)")
You can view the generated messages directly on the device console, in the logging monitor (ensure your device logging level is set appropriately), or via the show logging command on the device. In all cases, ensure the device logging level is configured appropriately for console, monitor, or buffered, as appropriate.
Enjoy!
Now, instead of using print statements in your code or watching logging messages vanish, you can capture the output of your own guestshell scripts in syslog!
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file iosxe_guestshell_logging-1.0.1.tar.gz.
File metadata
- Download URL: iosxe_guestshell_logging-1.0.1.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
29b8f47230c0e45dd2b02dc741fe595b1ad3aa47336cf075a75cdb2233e4f219
|
|
| MD5 |
7c49275bf338b41431ba7cc79d8e2345
|
|
| BLAKE2b-256 |
07365b0af0626aa6ab420a6e62deb3ec2dc33ec06df3066599618d86e1ee4835
|
File details
Details for the file iosxe_guestshell_logging-1.0.1-py3-none-any.whl.
File metadata
- Download URL: iosxe_guestshell_logging-1.0.1-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ad37b8bb44b1b278f7970d3be603a835f691933de8fec23a582a1d21cbb9a76
|
|
| MD5 |
2dc530091a99dfd3d37b913c57f26f52
|
|
| BLAKE2b-256 |
3d206f866f3635ff7e07f37888305e5288b64d467c3b66e210da671eafa5325f
|