Skip to end of metadata
Go to start of metadata

You are viewing an old version of this content. View the current version.

Compare with Current View Version History

« Previous Version 9 Next »

1. Objective

An example of how to use TextFSM-Based Structured Processing

Create an opConfig Command Set for Cisco IOS devices (IOS_HOURLY) that:

·       Runs IOS CLI commands (e.g. show interfaces)

·       Uses TextFSM-based plugins: TextFsm, TextFsmTable, TextFsmInventory, AlertTextFsmMTU

·       Produces structured parsed output

·       Generates custom table data

·       Updates inventory

·       Creates user-based alerts (e.g. MTU)

2. Example CLI command

This is an example output of the show interfaces command on a cisco router. This is for one of the 32 interfaces.

Ethernet2/0 is up, line protocol is up
  Hardware is AmdP2, address is ca02.07c1.0038 (bia ca02.07c1.0038)
  Description: pe1
  Internet address is 10.248.2.58/31
  MTU 1500 bytes, BW 10000 Kbit/sec, DLY 1000 usec,
     reliability 255/255, txload 1/255, rxload 1/255
  Encapsulation ARPA, loopback not set
  Keepalive set (10 sec)
  ARP type: ARPA, ARP Timeout 04:00:00
  Last input never, output 00:00:01, output hang never
  Last clearing of "show interface" counters never
  Input queue: 0/75/0/0 (size/max/drops/flushes); Total output drops: 0
  Queueing strategy: fifo
  Output queue: 0/40 (size/max)
  5 minute input rate 0 bits/sec, 0 packets/sec
  5 minute output rate 0 bits/sec, 0 packets/sec
     0 packets input, 0 bytes, 0 no buffer
     Received 0 broadcasts (0 IP multicasts)
     0 runts, 0 giants, 0 throttles
     0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored
     0 input packets with dribble condition detected
     24855328 packets output, 2442241129 bytes, 0 underruns
     0 output errors, 0 collisions, 1 interface resets
     0 unknown protocol drops
     0 babbles, 0 late collision, 0 deferred
     0 lost carrier, 0 no carrier
     0 output buffer failures, 0 output buffers swapped out
 

3. Command Set Definition (IOS_INTERFACE_INVENTORY)

Create the file under:

/usr/local/omk/conf/command_sets.d/IOS_INTERFACE_INVENTORY.json
and adds the FSM plugins to command set .
use_processing_plugins : which plugins to run during process_configuration step,
custom_table_configuration : How many table configurations are needed and their title and columns (This only works if TextFsmTable is part of use_processing_plugins)


"use_processing_plugins" : [
        "TextFsm","TextFsmTable","TextFsmInventory","AlertTextFsmMTU"
    ],
"custom_table_configuration" : [
        {
            "title" : "Custom Table Data 01",
            "labels" :[ "INTERFACE","DESCRIPTION", "BANDWIDTH", "MTU","SPEED", "PROTOCOL_STATUS"]
        },
        {
            "title" : "Custom Table Data 02",
            "labels" :[ "INTERFACE","DESCRIPTION"]
        }
    ],

Example configuration:

{
   "IOS_INTERFACE_INVENTORY" : {
      "active" : "true",
      "os_info" : {
         "os" : "IOS"
      },
      "modified" : 1770074947,
      "scheduling_info" : {
         "run_local" : null,
         "run_commands_on_separate_connection" : "false",
         "attempt_timeout_recovery" : 1,
         "parameters_required" : null
      },
      "parameters" : [],
      "purging_policy" : {
         "purge_older_than" : null,
         "keep_last" : 0,
         "autoprotect_first_revision" : null
      },
      "commands" : [
         {
            "command" : "show interfaces",
            "compare_to_previous_revision" : null,
            "use_collection_plugin" : "",
            "tags" : [
               "DAILY",
               "detect-change",
               "inventory",
               "report-change"
            ],
            "use_processing_plugins" : [
               "TextFsm","TextFsmTable","TextFsmInventory","AlertTextFsmMTU"
            ],
            "custom_table_configuration" : [
               {
                  "title" : "Custom Table Data 01",
                  "labels" :[ "INTERFACE","DESCRIPTION", "BANDWIDTH", "MTU","SPEED", "PROTOCOL_STATUS"]
               },
               {
                  "title" : "Custom Table Data 02",
                  "labels" :[ "INTERFACE","DESCRIPTION"]
               }
            ], 
            "report_level_min_changes" : null,
            "privileged" : "false",
            "multipage" : "true",
            "active" : "true"
         }
      ]
   }
}

3. Plugin Roles

TextFsm

·       Parses raw CLI output using NTC templates

·       Produces structured JSON data

TextFsmTable

·       Generates structured table output using Command Set parameter: custom_table_configuration

TextFsmInventory

·       Updates node inventory data

AlertTextFsmMTU

·       Evaluates MTU values

·       Creates alerts in opEvents when thresholds are triggered

4. Running the Command Set

Run using opconfig-cli:

/usr/local/omk/bin/opconfig-cli.pl act=run_command_sets nodes=omk-core2 names="IOS_INTERFACE_INVENTORY" debug=9


Or
Create a Virtual Operator Job to run Command Set on selected nodes.

5. Expected Results

·       Structured parsed output from show interfaces

Note that the data has been extracted from the show interfaces command output and placed into structured and named fields in JSON format.

{"OVERRUN": "0","ENCAPSULATION": "ARPA","PROTOCOL_STATUS": "up","BIA": "ca02.07c1.0038","QUEUE_FLUSHES": "0","LAST_OUTPUT": "00:00:01","VLAN_ID_OUTER": "","LAST_OUTPUT_HANG": "never","QUEUE_MAX": "75","MEDIA_TYPE": "","FRAME": "0","ABORT": "0","LAST_INPUT": "never","SPEED": "","DELAY": "1000 usec","DUPLEX": "","QUEUE_DROPS": "0","INPUT_RATE": "0","IP_ADDRESS": "10.248.2.58","QUEUE_STRATEGY": "fifo","OUTPUT_PPS": "0","BANDWIDTH": "10000 Kbit","MAC_ADDRESS": "ca02.07c1.0038",
"MTU": "1500",
"OUTPUT_ERRORS": "0","CRC": "0","VLAN_ID": "","OUTPUT_PACKETS": "24855328","LINK_STATUS": "up","QUEUE_OUTPUT_DROPS": "0","PREFIX_LENGTH": "31","HARDWARE_TYPE": "AmdP2","OUTPUT_RATE": "0","VLAN_ID_INNER": "","DESCRIPTION": "pe1","RUNTS": "0","QUEUE_SIZE": "0","INPUT_PPS": "0","INPUT_PACKETS": "0","INTERFACE": "Ethernet2/0","INPUT_ERRORS": "0","GIANTS": "0"},

·       Custom tables visible in opConfig UI

·       Inventory updates for interfaces

·       Alerts created in opEvents for MTU conditions

6. Architecture Flow

arch-flow.svg

  • No labels