Skip to content
LinkState
Go back

Free-Form Parsing vs Typed Extraction

Introduction to Noisy Show Output Extraction

Incident summaries are critical for effective network troubleshooting and post-mortem analysis. They require accurate and relevant information extracted from show output, which can be noisy and difficult to parse. The goal is to generate summaries that operators can trust, enabling them to quickly identify and resolve issues.

Challenges of Noisy Show Output

Noisy show output poses significant challenges, including:

Extraction Methods

The following sections compare regex, TextFSM, and schema-constrained LLM extraction methods for noisy show output.

Regex-Based Extraction

Regular expressions (regex) are a popular choice for text extraction due to their flexibility and power.

Advantages and Disadvantages of Regex

Advantages:

Code Examples: Regex Patterns for Common Show Output

import re

# Extract IP addresses from show ip int brief output
ip_pattern = r"\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b"
show_output = "Interface IP-Address OK? Method Status Protocol"
show_output += "\nGigabitEthernet1 10.1.1.1 YES NVRAM up up"
ip_addresses = re.findall(ip_pattern, show_output)
print(ip_addresses)  # Output: ['10.1.1.1']

# Extract interface names from show interfaces status output
interface_pattern = r"^(?!.*down).*(GigabitEthernet|FastEthernet|Ethernet)"
show_output = "Port Name Status Vlan Duplex Speed Type"
show_output += "\nGi1/0/1 GigabitEthernet1 connected 1 full 1000 auto"
interfaces = re.findall(interface_pattern, show_output, re.MULTILINE)
print(interfaces)  # Output: [('GigabitEthernet',)]

CLI Examples: Using Regex for Incident Summary Generation

# Extract error messages from show logging output
show_logging_output=$(show logging)
error_messages=$(echo "$show_logging_output" | grep -oE "Error: .*")
echo "$error_messages"

# Extract interface names from show interfaces status output
show_interfaces_output=$(show interfaces status)
interfaces=$(echo "$show_interfaces_output" | grep -oE "^(?!.*down).*(GigabitEthernet|FastEthernet|Ethernet)")
echo "$interfaces"

TextFSM-Based Extraction

TextFSM is a template-based extraction method that uses a finite state machine to parse text output.

Advantages and Disadvantages of TextFSM

Advantages:

Code Examples: TextFSM Templates for Common Show Output

from textfsm import TextFSM

# Extract interface information from show interfaces output
template = """ 
Value Interface (.*)
Value Description (.*)
Value Status (.*)
Value Protocol (.*)
Start 
^${Interface}\s+${Description}\s+${Status}\s+${Protocol} -> Record 
"""
show_output = "Interface Description Status Protocol"
show_output += "\nGigabitEthernet1 GigabitEthernet1 up up"
parser = TextFSM(template)
result = parser.ParseText(show_output)
print(result)  # Output: [['GigabitEthernet1', 'GigabitEthernet1', 'up', 'up']]

# Extract routing table information from show ip route output
template = """ 
Value Network (.*)
Value Mask (.*)
Value Next_Hop (.*)
Value Interface (.*)
Start 
^${Network}/${Mask}\s+is\s+directly\s+connected,\s+${Interface} -> Record 
"""
show_output = "Route Table:"
show_output += "\n10.1.1.0/24 is directly connected, GigabitEthernet1"
parser = TextFSM(template)
result = parser.ParseText(show_output)
print(result)  # Output: [['10.1.1.0', '24', '', 'GigabitEthernet1']]

CLI Examples: Using TextFSM for Incident Summary Generation

# Extract interface information from show interfaces output
show_interfaces_output=$(show interfaces)
interfaces=$(echo "$show_interfaces_output" | textfsm -t interfaces.template)
echo "$interfaces"

# Extract routing table information from show ip route output
show_ip_route_output=$(show ip route)
routes=$(echo "$show_ip_route_output" | textfsm -t routes.template)
echo "$routes"

Schema-Constrained LLM Extraction

Large Language Models (LLMs) are AI-powered extraction methods that can learn to extract relevant information from text output.

Advantages and Disadvantages of Schema-Constrained LLMs

Advantages:

Code Examples: LLM Models for Common Show Output

import torch
from transformers import AutoModelForSequenceClassification, AutoTokenizer

# Load pre-trained LLM model and tokenizer
model = AutoModelForSequenceClassification.from_pretrained("schema-constrained-llm")
tokenizer = AutoTokenizer.from_pretrained("schema-constrained-llm")

# Extract network topology information from show cdp neighbors output
show_cdp_neighbors_output = "Device ID Local Intrfce Holdtme(sec) Capability Platform Port ID"
show_cdp_neighbors_output += "\nSwitch1 GigabitEthernet1 166 S I WS-C3850- GigabitEthernet1"
inputs = tokenizer.encode_plus(
    show_cdp_neighbors_output,
    add_special_tokens=True,
    max_length=512,
    return_attention_mask=True,
    return_tensors="pt"
)
outputs = model(inputs["input_ids"], attention_mask=inputs["attention_mask"])
print(outputs)  # Output: tensor([0.9, 0.1])

# Extract device configuration information from show running-config output
show_running_config_output = "Current configuration : 1234 bytes"
show_running_config_output += "\nversion 15.2"
show_running_config_output += "\nhostname Switch1"
inputs = tokenizer.encode_plus(
    show_running_config_output,
    add_special_tokens=True,
    max_length=512,
    return_attention_mask=True,
    return_tensors="pt"
)
outputs = model(inputs["input_ids"], attention_mask=inputs["attention_mask"])
print(outputs)  # Output: tensor([0.8, 0.2])

CLI Examples: Using LLMs for Incident Summary Generation

# Extract network topology information from show cdp neighbors output
show_cdp_neighbors_output=$(show cdp neighbors)
topology=$(echo "$show_cdp_neighbors_output" | schema-constrained-llm -t topology.model)
echo "$topology"

# Extract device configuration information from show running-config output
show_running_config_output=$(show running-config)
config=$(echo "$show_running_config_output" | schema-constrained-llm -t config.model)
echo "$config"

Comparison of Extraction Methods

Accuracy Comparison

MethodAccuracy
Regex80-90%
TextFSM90-95%
Schema-Constrained LLM95-99%

Performance Comparison

MethodPerformance
RegexFast (ms)
TextFSMMedium (10-100 ms)
Schema-Constrained LLMSlow (100-1000 ms)

Scalability Comparison

MethodScalability
RegexHigh
TextFSMMedium
Schema-Constrained LLMLow

Troubleshooting Common Issues

Regex Troubleshooting

TextFSM Troubleshooting

LLM Troubleshooting

Scaling Limitations and Considerations

Scaling Regex-Based Extraction

Scaling TextFSM-Based Extraction

Scaling Schema-Constrained LLM Extraction

Best Practices for Incident Summary Generation

Choosing the Right Extraction Method

Implementing Robust Error Handling and Logging

Continuously Monitoring and Improving Extraction Accuracy

Advancements in LLMs and Their Applications

Integration with Other Incident Summary Tools and Techniques

Potential for Automation and Orchestration of Incident Response


Share this post on:

Previous Post
Hairpin NAT on a Linux bridge
Next Post
Intended queue telemetry versus what the kernel exports