Snippets & Custom Commands
ProfessionalCreate reusable code snippets and custom command aliases to automate repetitive terminal tasks, share operational knowledge across your team, and accelerate network engineering workflows.
Overview
Snippets and Custom Commands let you capture, organize, and reuse frequently executed command sequences in the NetStacks terminal. Instead of typing the same multi-line diagnostic workflow every time a BGP peer goes down, save it as a snippet and execute it with a single action.
Snippet Types
- Session snippets -- temporary snippets scoped to the current session, ideal for ad-hoc troubleshooting sequences
- Global snippets -- saved to your user profile and available across all sessions and devices
- Organization snippets -- shared with your team via the controller, providing a library of approved operational procedures
Custom Commands
Custom commands are named aliases that map a short keyword to a snippet or command sequence. Type the alias in the terminal and NetStacks expands it into the full command set, optionally prompting for variable values.
Combine snippets with variables to create reusable templates. For example, a BGP troubleshooting snippet can accept a {{neighbor_ip}} variable that gets prompted at execution time.
How It Works
The snippet system stores command sequences as structured objects with metadata including name, description, category, variables, and the command body. When you execute a snippet, NetStacks parses variable placeholders, prompts for values, interpolates them into the command body, and sends the resulting commands to the active terminal session.
Storage Hierarchy
- Session snippets -- stored in memory for the duration of the terminal session. Lost when the session closes.
- Global snippets -- persisted to the local database and synced to the controller when connected. Available in all sessions.
- Organization snippets -- stored on the controller and distributed to all team members. Managed by administrators with role-based access control.
Variable Interpolation
Variables use the {{variable_name}} syntax. When a snippet is executed, NetStacks scans for variable placeholders and presents a dialog prompting the user to fill in each value. Variables can have default values and descriptions to guide the user.
Execution Context
Snippets execute in the context of the active terminal session. Commands are sent sequentially with configurable delays between lines to allow device response time. The terminal captures all output for review.
Step-by-Step Guide
Workflow 1: Create and Save a Snippet
- Open the Snippets panel from the terminal toolbar or press
Cmd/Ctrl+Shift+S - Click New Snippet and enter a name (e.g., "BGP Neighbor Check")
- Write your command sequence in the editor, using
{{variable}}placeholders for dynamic values - Set the scope: Session, Global, or Organization
- Click Save -- the snippet appears in your library
Workflow 2: Execute a Snippet
- Open the Snippets panel and locate your snippet
- Click Run or double-click the snippet
- If the snippet contains variables, fill in the prompted values
- The commands are sent to the active terminal session and output is displayed normally
Workflow 3: Create a Custom Command Alias
- Open Settings and navigate to Terminal → Custom Commands
- Click Add Command and enter an alias name (e.g., "bgpcheck")
- Link it to an existing snippet or enter inline commands
- Save -- now typing
/bgpcheckin the terminal executes the linked snippet
Organization snippets require the snippets:write permission. Contact your administrator if you need to publish snippets to the team library.
Code Examples
Interface Status Parsing Snippet
# Snippet: Check Interface Status
# Variables: {{interface_name}}
show interfaces {{interface_name}}
show interfaces {{interface_name}} counters
show interfaces {{interface_name}} transceiverCustom Command Definition
{
"name": "bgpcheck",
"alias": "/bgpcheck",
"description": "Full BGP neighbor diagnostic",
"variables": [
{
"name": "neighbor_ip",
"description": "BGP neighbor IP address",
"default": ""
}
],
"commands": [
"show ip bgp summary",
"show ip bgp neighbors {{neighbor_ip}}",
"show ip bgp neighbors {{neighbor_ip}} advertised-routes",
"show ip bgp neighbors {{neighbor_ip}} received-routes"
],
"delay_ms": 500
}Snippet with Variables and Defaults
{
"name": "OSPF Troubleshoot",
"scope": "organization",
"category": "Routing",
"variables": [
{
"name": "area_id",
"description": "OSPF area number",
"default": "0"
},
{
"name": "process_id",
"description": "OSPF process ID",
"default": "1"
}
],
"commands": [
"show ip ospf {{process_id}}",
"show ip ospf {{process_id}} neighbor",
"show ip ospf {{process_id}} interface brief",
"show ip ospf {{process_id}} database | include Area {{area_id}}"
]
}Organization Snippet Management
# List organization snippets via API
GET /api/v1/snippets?scope=organization
# Create a new organization snippet
POST /api/v1/snippets
Content-Type: application/json
{
"name": "Port Channel Verification",
"scope": "organization",
"category": "Switching",
"commands": [
"show etherchannel summary",
"show etherchannel port-channel",
"show lacp neighbor"
]
}
# Share snippet with specific team
PUT /api/v1/snippets/{id}/permissions
{
"teams": ["network-ops", "noc"],
"access": "execute"
}Q&A
- Q: What is the difference between a snippet and a custom command?
- A: A snippet is a saved command sequence that you execute from the Snippets panel. A custom command is a named alias (e.g.,
/bgpcheck) that you type directly in the terminal to trigger a snippet. Custom commands provide a faster workflow for frequently used snippets.
- Q: Can I share snippets with my team?
- A: Yes. Set the snippet scope to "Organization" to publish it to the shared library on the controller. All team members with appropriate permissions can view and execute organization snippets. You can also restrict access to specific teams.
- Q: How do I use variables in snippets?
- A: Use the
{{variable_name}}syntax in your command body. When the snippet executes, NetStacks prompts you to fill in each variable. You can define default values and descriptions for each variable in the snippet configuration.
- Q: Where are snippets stored?
- A: Session snippets are stored in memory and lost when the session closes. Global snippets are persisted to the local database and synced to the controller. Organization snippets are stored on the controller and distributed to all connected users.
- Q: Can I import or export snippets?
- A: Yes. Snippets can be exported as JSON files from the Snippets panel using the export button. Import snippets by dragging a JSON file into the panel or using the Import option in the menu. This is useful for migrating snippets between environments.
- Q: How do I create a keyboard shortcut for a snippet?
- A: Open Settings → Keyboard Shortcuts and search for your snippet name. Assign a key combination to execute the snippet directly from the keyboard without opening the Snippets panel. You can also use the custom command alias for quick access.
Troubleshooting
Variable Not Resolving
- Verify the variable name in your snippet matches the
{{variable_name}}placeholder syntax exactly, including case sensitivity - Check that the variable dialog appeared and you entered a value -- empty values are not substituted by default
- Ensure there are no extra spaces inside the curly braces:
{{name}}works, but{{ name }}does not
Permission Denied When Sharing Snippets
- Organization snippets require the snippets:write permission. Contact your administrator to grant this permission
- If editing an existing organization snippet, verify you have write access to that specific snippet or are the original author
Snippet Not Appearing in Library
- Check the scope filter in the Snippets panel -- ensure "All" or the correct scope is selected
- For organization snippets, verify the controller connection is active and syncing
- Session snippets only appear in the session where they were created
Related Features
- Keyboard Shortcuts -- assign keyboard shortcuts to execute snippets instantly
- Multi-Send (Broadcast) -- combine snippets with multi-send to execute commands across multiple devices simultaneously
- Terminal Overview -- explore the terminal interface where snippets are executed
- Roles & Permissions -- manage snippet sharing permissions for your organization