mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-10-22 19:02:23 +03:00
fix: use shlex.split for tshark_args parsing
- Replace str.split() with shlex.split() to handle quoted arguments - LLM may pass args with or without quotes, both work correctly now
This commit is contained in:
parent
e0c2d64b7c
commit
b991125c6c
@ -65,37 +65,23 @@ class PacketAnalysisTool(BaseTool):
|
|||||||
description: str = """
|
description: str = """
|
||||||
Analyze packets from an active GNS3 capture using tshark.
|
Analyze packets from an active GNS3 capture using tshark.
|
||||||
|
|
||||||
Use this tool to analyze network packets captured on a link.
|
Use this to analyze captured packets when diagnosing network issues.
|
||||||
|
|
||||||
`WORKFLOW`:
|
**Before calling this tool**, first query `get_packet_analysis_protocol`
|
||||||
1. Call `device_skills` or `get_packet_analysis_protocol` to query the protocol definition
|
to get the correct tshark field names and display filter for the protocol.
|
||||||
(available fields, display filters, filter examples) from packet_analysis skills.
|
Construct `tshark_args` from the skills data, not from memory.
|
||||||
2. Based on the user's issue, select relevant fields and construct tshark_args.
|
|
||||||
3. Call this tool with the constructed tshark_args.
|
|
||||||
4. Analyze the returned data and identify issues.
|
|
||||||
5. Repeat step 2-4 with different filters/fields as needed for deeper analysis.
|
|
||||||
|
|
||||||
Input (JSON format):
|
Input (JSON format):
|
||||||
- project_id (str, required): UUID of the GNS3 project
|
- project_id (str, required): UUID of the GNS3 project
|
||||||
- link_id (str, required): UUID of the link to analyze
|
- link_id (str, required): UUID of the link to analyze
|
||||||
- tshark_args (str, required): tshark command arguments (after '-r <pcap>')
|
- tshark_args (str, required): tshark command arguments (after '-r <pcap>')
|
||||||
|
|
||||||
Common tshark arguments:
|
Common tshark argument patterns:
|
||||||
-Y "<filter>": Display filter (e.g., 'ospf', 'bgp', 'icmp')
|
-Y "<filter>" Display filter
|
||||||
-T fields: Output as tab-separated fields
|
-T fields Tab-separated field output
|
||||||
-e <field>: Extract specific field (can use multiple -e)
|
-e <field> Extract field (use multiple -e for multiple fields)
|
||||||
-T json: Output as JSON
|
-T json JSON output
|
||||||
-c <count>: Limit packet count to N
|
-c <count> Limit packet count
|
||||||
|
|
||||||
Examples:
|
|
||||||
# Step 1: Query protocol fields from skills
|
|
||||||
packet_analysis_skills protocol=ospf → get fields
|
|
||||||
# Step 2: Call tool with constructed args
|
|
||||||
{"project_id": "xxx", "link_id": "yyy",
|
|
||||||
"tshark_args": "-Y 'ospf.msg == 1' -T fields -e ip.src -e ospf.hello.hello_interval -e ospf.hello.router_dead_interval"}
|
|
||||||
# Step 3: Further drill-down
|
|
||||||
{"project_id": "xxx", "link_id": "yyy",
|
|
||||||
"tshark_args": "-Y 'ospf.msg == 4' -T fields -e ip.src -e ospf.lsa.type"}
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def _run(
|
def _run(
|
||||||
@ -270,7 +256,8 @@ class PacketAnalysisTool(BaseTool):
|
|||||||
str: tshark output
|
str: tshark output
|
||||||
"""
|
"""
|
||||||
# Build command: tshark -r <file> <user_args>
|
# Build command: tshark -r <file> <user_args>
|
||||||
cmd = ["tshark", "-r", pcap_file] + tshark_args.split()
|
import shlex
|
||||||
|
cmd = ["tshark", "-r", pcap_file] + shlex.split(tshark_args)
|
||||||
|
|
||||||
logger.info(f"Running tshark: {' '.join(cmd)}")
|
logger.info(f"Running tshark: {' '.join(cmd)}")
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user