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.0.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.0.1-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for iosxe_guestshell_logging-1.0.1.tar.gz
Algorithm Hash digest
SHA256 29b8f47230c0e45dd2b02dc741fe595b1ad3aa47336cf075a75cdb2233e4f219
MD5 7c49275bf338b41431ba7cc79d8e2345
BLAKE2b-256 07365b0af0626aa6ab420a6e62deb3ec2dc33ec06df3066599618d86e1ee4835

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for iosxe_guestshell_logging-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2ad37b8bb44b1b278f7970d3be603a835f691933de8fec23a582a1d21cbb9a76
MD5 2dc530091a99dfd3d37b913c57f26f52
BLAKE2b-256 3d206f866f3635ff7e07f37888305e5288b64d467c3b66e210da671eafa5325f

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