Skip to content

Commit 199832e

Browse files
netpickermailsanjayhere
authored and
imi
committed
Tests and juniper (#110)
* adding wireless tests * renamed vendor names * testing juniper file * testing with rule_11.py * updated the first rule * adding EXAMPLES.md * updated the URL for EXAMPLES.md * TOC for EXAMPLES.md * Tests and juniper (#96) (#97) * adding wireless tests * renamed vendor names * testing juniper file * testing with rule_11.py * updated the first rule * adding EXAMPLES.md * updated the URL for EXAMPLES.md --------- Co-authored-by: mailsanjayhere <mailsanjayhere@gmail.com> * updating TOC * updated for EXAMPLES.md * removed example inside EXAMPLE.md * Squashed commit of the following: commit 8d3fe28 Author: Netpicker <156186606+netpicker@users.noreply.github.com> Date: Mon Aug 19 09:26:59 2024 +0200 Tests and juniper (#100) * adding wireless tests * renamed vendor names * testing juniper file * testing with rule_11.py * updated the first rule * adding EXAMPLES.md * updated the URL for EXAMPLES.md * TOC for EXAMPLES.md * Tests and juniper (#96) (#97) * adding wireless tests * renamed vendor names * testing juniper file * testing with rule_11.py * updated the first rule * adding EXAMPLES.md * updated the URL for EXAMPLES.md --------- Co-authored-by: mailsanjayhere <mailsanjayhere@gmail.com> * updating TOC * updated for EXAMPLES.md --------- Co-authored-by: mailsanjayhere <mailsanjayhere@gmail.com> * changed entire file contents * fixed typo for devices * update EXAMPLES.md README.md * removed few items from TOC * replaced : with = in commands check * added 2nd example for multiple lines check * updated example 2 * add 4th example * added textfsm example --------- Co-authored-by: mailsanjayhere <mailsanjayhere@gmail.com>
1 parent 508624e commit 199832e

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

EXAMPLES.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ A set of common Netpicker compliance use-cases.
1212
2. [Simple Examples](#simple-examples)
1313
3. [Multiple Lines](#multiple-lines)
1414
4. [Using Configuration and Commands](#configuration-commands)
15+
5. [Using TextFSM](#using-textfsm)
16+
1517

1618
## Format of the Rules
1719

@@ -114,3 +116,26 @@ def rule_bgp_neighbors_status(configuration, device):
114116
assert len(neighbors_down) == 0, f"BGP neighbors down: {', '.join([line.split()[0] for line in neighbors_down])}"
115117
```
116118
*This example looks for 'router bgp' in configuration and if found then executes the `show ip bgp summary` command and checks the status of all BGP neighbors. If any neighbor is in an "Idle," "Active," or "Connect" state, the rule will fail, listing the IP addresses of the down neighbors.*
119+
120+
## Using TextFSM
121+
122+
### Example: Interface Status Check Using TextFSM
123+
124+
This rule checks the status of a specific interface on a Cisco IOS device using TextFSM for command output parsing. It ensures that the interface is up and running.
125+
126+
```python
127+
@medium(
128+
name='rule_interface_status_check',
129+
platform=['cisco_ios'],
130+
)
131+
def rule_interface_status_check(device):
132+
# Execute the command to get interface details using TextFSM parsing
133+
inf_output = device.cli("show interface eth0/0").fsm[0]
134+
135+
# Print the parsed output for debugging or verification purposes
136+
print(inf_output)
137+
138+
# Assert that the interface is up; fail the test if it is down
139+
assert inf_output.link_status == "up", "Interface is down"
140+
```
141+
*This example uses TextFSM to parse the output of the `show interface eth0/0` command. The rule then checks the parsed output to verify that the interface is up. If the interface is down, the rule will fail, reporting the issue.*

0 commit comments

Comments
 (0)