Skip to main content

Alcatel-Lucent Enterprise AOS CLI parsing (TextFSM)

Project description

TEXTFSM-AOS

Alcatel-Lucent Enterprise AOS CLI parsing

Python package for Alcatel-Lucent Enterprise aos6 and aos8 parsing based on TextFSM templates.

Why TextFSM-AOS?

Parse semi-structured cli data to structured data ready to be ingested by your network automation pipeline. Autmatically transform gathered output from screen-scraping tools like Netmiko, Scrapli and Paramiko. Receive uniform data accross Alcatel-Lucent Enterprise devices running aos6 or aos8.

Installing / Getting started

Python package available through PyPi

pip install textfsm-aos

Provide screen-scraped data to parser

from textfsm_aos.parser import parse

sample_data = """
   Package           Release       Size     Description
-----------------+---------------+--------+-----------------------------------
KFbase.img        6.7.2.89.R06    18059551 Alcatel-Lucent Enterprise Base Softw
KFos.img          6.7.2.89.R06     3566798 Alcatel-Lucent Enterprise OS
KFeni.img         6.7.2.89.R06     6123991 Alcatel-Lucent Enterprise NI softwar
KFsecu.img        6.7.2.89.R06      649383 Alcatel-Lucent Enterprise Security M
"""

parse("ale_aos6", "show microcode", sample_data)

parsed result

[
   {
      "package":"KFbase.img",
      "release":"6.7.2.89.R06",
      "size":"18059551",
      "description":"Alcatel-Lucent Enterprise Base Softw"
   },
   {
      "package":"KFos.img",
      "release":"6.7.2.89.R06",
      "size":"3566798",
      "description":"Alcatel-Lucent Enterprise OS"
   },
   {
      "package":"KFeni.img",
      "release":"6.7.2.89.R06",
      "size":"6123991",
      "description":"Alcatel-Lucent Enterprise NI softwar"
   },
   {
      "package":"KFsecu.img",
      "release":"6.7.2.89.R06",
      "size":"649383",
      "description":"Alcatel-Lucent Enterprise Security M"
   }
]

Supported commands

command aos6 aos8
show 802.1x users :heavy_check_mark: :x:
show 802.1x non-supplicant :heavy_check_mark: :x:
show 802.1x non-supplicant unp :heavy_check_mark: :x:
show chassis :heavy_check_mark: :heavy_check_mark:
show cmm :x: :heavy_check_mark:
show command-log :heavy_check_mark: :heavy_check_mark:
show health :heavy_check_mark: :x:
show history :heavy_check_mark: :x:
show interface status :heavy_check_mark: :x:
show ip interface :heavy_check_mark: :x:
show ip route :heavy_check_mark: :x:
show lld remote system :heavy_check_mark: :x:
show log events :x: :heavy_check_mark:
show mac-address-table :heavy_check_mark: alias: show mac-learning
show mac-learning alias: show mac-address-table :heavy_check_mark:
show microcode :heavy_check_mark: :heavy_check_mark:
show ntp server status :heavy_check_mark: :heavy_check_mark:
show unp user :x: :heavy_check_mark:
show user :heavy_check_mark: :heavy_check_mark:
show running-directory :x: :heavy_check_mark:
show snmp station :heavy_check_mark: :heavy_check_mark:
show snmp community map :heavy_check_mark: alias: show snmp community-map
show snmp community-map alias: show snmp community map :heavy_check_mark:
show system :heavy_check_mark: :heavy_check_mark:
show vlan :heavy_check_mark: :heavy_check_mark:
show vlan port mobile :heavy_check_mark: :x:

Direct TextFSM example usage

Bypass the build-in parser functionality and use the TextFSM templates directly in network cli scraping and orchestration tools like Netmiko, Scrapli and Ansible.

Scrapli

Python script:

from scrapli import Scrapli
from scrapli.helper import textfsm_parse

device = {
    "host": "<host ip>",
    "auth_username": "<username>",
    "auth_password": "<password>",
    "auth_strict_key": False,
    "transport": "ssh2",
    "platform": "alcatel_aos",
}

with Scrapli(**device) as conn:
    response = conn.send_command("show health").result
    structured_response = textfsm_parse(
        "templates/ale_aos6_show_health.textfsm", response
    )

Example output:

[
   {
      "resource":"Receive",
      "limit":"80",
      "current":"01",
      "min_avg":"01",
      "hr_avg":"01",
      "hr_max":"01"
   },
   {
      "resource":"Transmit/Receive",
      "limit":"80",
      "current":"01",
      "min_avg":"01",
      "hr_avg":"01",
      "hr_max":"01"
   },
   {
      "resource":"Memory",
      "limit":"80",
      "current":"76",
      "min_avg":"76",
      "hr_avg":"76",
      "hr_max":"76"
   },
   {
      "resource":"Cpu",
      "limit":"80",
      "current":"32",
      "min_avg":"33",
      "hr_avg":"29",
      "hr_max":"97"
   }
]

Netmiko

Python script:

from netmiko import ConnectHandler

device = {
    'device_type': 'alcatel_aos',
    'host': '<host ip>',
    'username': '<username>',
    'password': '<password>'
}

with ConnecHandler(**device) as conn:
    output = conn.send_command("show health", use_textfsm=True, textfsm_template="textfsm-aos/templates/ale_aos6_show_health.textfsm")

Example Output:

[
   {
      "resource":"Receive",
      "limit":"80",
      "current":"01",
      "min_avg":"01",
      "hr_avg":"01",
      "hr_max":"01"
   },
   {
      "resource":"Transmit/Receive",
      "limit":"80",
      "current":"01",
      "min_avg":"01",
      "hr_avg":"01",
      "hr_max":"01"
   },
   {
      "resource":"Memory",
      "limit":"80",
      "current":"76",
      "min_avg":"76",
      "hr_avg":"76",
      "hr_max":"76"
   },
   {
      "resource":"Cpu",
      "limit":"80",
      "current":"32",
      "min_avg":"33",
      "hr_avg":"29",
      "hr_max":"97"
   }
]

Ansible

Ansible task:

- name: AOS6 >> parsed with textfsm
  set_fact:
    health: "{{ health-aos6 | ansible.netcommon.parse_cli_textfsm('textfsm/templates/ale_aos6_show_health.textfsm') }}"

Example Output:

    health:
    - healthModuleCpu1HrAvg: '29'
      healthModuleCpu1HrMax: '98'
      healthModuleCpu1MinAvg: '26'
      healthModuleCpuLatest: '31'
      healthModuleCpuLimit: '80'
      healthModuleMemory1HrAvg: '76'
      healthModuleMemory1HrMax: '76'
      healthModuleMemory1MinAvg: '76'
      healthModuleMemoryLatest: '76'
      healthModuleMemoryLimit: '80'
      healthModuleRx1HrAvg: '01'
      healthModuleRx1HrMax: '01'
      healthModuleRx1MinAvg: '01'
      healthModuleRxLatest: '01'
      healthModuleRxLimit: '80'
      healthModuleRxTxRx1HrAvg: '01'
      healthModuleRxTxRx1HrMax: '01'
      healthModuleRxTxRx1MinAvg: '01'
      healthModuleRxTxRxLatest: '01'
      healthModuleRxTxRxLimit: '80'
      healthModuleSlot: '1'

How to contribute

  1. Create branch with naming <platform>_<command> (for example: ale_aos8_show_system).

  2. Add TextFSM template file in templates folder with naming <platform>_<command>.textfsm.

  3. Add entry in templates_index with attribute command and platform.

  4. Add test folder in 'templates' with naming <platform>_<command>.

  5. Add sample cli output file in newly created folder <platform>_<command>.txt.

  6. Add expected parsed data from sample cli output in <platform>_<command>.yml.

  7. Run linting tox and tests pytest.

How to setup development environment

  1. Create virtual Python environment python -m .venv venv

  2. Activate environment source .venv/bin/activate

  3. Install Python dependencies pip install -r requirements.txt

  4. Install textfsm_aos package in development mode pip install -e .

Related projects

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

textfsm_aos-0.2.0.tar.gz (20.9 kB view details)

Uploaded Source

Built Distribution

textfsm_aos-0.2.0-py3.8.egg (24.9 kB view details)

Uploaded Source

File details

Details for the file textfsm_aos-0.2.0.tar.gz.

File metadata

  • Download URL: textfsm_aos-0.2.0.tar.gz
  • Upload date:
  • Size: 20.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.10

File hashes

Hashes for textfsm_aos-0.2.0.tar.gz
Algorithm Hash digest
SHA256 697c05e212529da510d23959b81d1cf34b8c2563157afcaf567a350b8172fa02
MD5 a88052036e717b34888e36dce964b638
BLAKE2b-256 f2022214b57cf807df63c0a05d3a26a9ff406fb2f10e6a25fa4411cdbeb906f8

See more details on using hashes here.

File details

Details for the file textfsm_aos-0.2.0-py3.8.egg.

File metadata

  • Download URL: textfsm_aos-0.2.0-py3.8.egg
  • Upload date:
  • Size: 24.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.10

File hashes

Hashes for textfsm_aos-0.2.0-py3.8.egg
Algorithm Hash digest
SHA256 7473ad52fb82c831327dd12432ba661c55fb22dcfbd253f30396b4b67c340416
MD5 bfde618f7e72d3d2309ac786d71743bb
BLAKE2b-256 47fa133689ba0c8233e14197fbb21ce2a91da7f162d7ff30d858c21d12294c94

See more details on using hashes here.

Supported by

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