Skip to main content

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

  1. Enable IOx and configure the guestshell application using the Programmability Configuration Guide.

  2. Enter the bash prompt from the network device:

    # guestshell run bash
  3. Create a Python Virtual Environment inside the guestshell. Note: The system-installed Python installation includes Cisco-specific Python packages such as eem and cli. To ensure those packages are available, use the --system-site-packages argument to the Python venv module, as shown below:

    python3 -m venv --system-site-packages venv
    
  4. Activate the virtual environment:

    source venv/bin/activate
    
  5. Install this Python package, using pip:

    pip install iosxe_guestshell_logging
    
  6. 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
    
  7. Exit guestshell to return to the Cisco IOS XE privileged exec prompt:

    exit
    
  8. 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

iosxe_guestshell_logging-1.1.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

iosxe_guestshell_logging-1.1-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file iosxe_guestshell_logging-1.1.tar.gz.

File metadata

  • Download URL: iosxe_guestshell_logging-1.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

Hashes for iosxe_guestshell_logging-1.1.tar.gz
Algorithm Hash digest
SHA256 3daef47e13fc047eb7c771239224738e8df96bd34f86086b7b95aef32c397056
MD5 43c18af92a0fdb0265820f6ecae7311f
BLAKE2b-256 882b99b31839749f446e2901956616b91118436ea39e7eb87458d1fc348269dc

See more details on using hashes here.

File details

Details for the file iosxe_guestshell_logging-1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for iosxe_guestshell_logging-1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4cf051cca1e1b154b023f3d56910c42874f5bf34309e86d1d22f2ee4e81d224f
MD5 724ceb2f30226d70897055b0c47dcafa
BLAKE2b-256 51d359a7cc7eb3e46ddd2b87d6323f900aed24154b77827ae43ae9006ae4f764

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page