Skip to content

Commit ec5401d

Browse files
Tests and juniper (#109)
* 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 --------- Co-authored-by: mailsanjayhere <mailsanjayhere@gmail.com>
1 parent ccbfbc1 commit ec5401d

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

EXAMPLES.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ A set of common Netpicker compliance use-cases.
1111
1. [Format of the Rules](#format-of-the-rules)
1212
2. [Simple Examples](#simple-examples)
1313
3. [Multiple Lines](#multiple-lines)
14+
4. [Using Configuration and Commands](#configuration-commands)
1415

1516
## Format of the Rules
1617

@@ -94,3 +95,22 @@ def rule_bgp_neighbors_up(commands):
9495
assert len(neighbors_down) == 0, f"BGP neighbors down: {', '.join([line.split()[0] for line in neighbors_down])}"
9596
```
9697
*This example 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.*
98+
99+
## Using Configuration and Commands
100+
101+
### Example: Conditional BGP Neighbor Status Check
102+
103+
This rule first verifies whether BGP is configured on a Cisco IOS device. If BGP is configured, then it checks the status of BGP neighbors and reports if any neighbor is down.
104+
105+
```python
106+
@medium(
107+
name='rule_bgp_neighbors_status',
108+
platform=['cisco_ios'],
109+
)
110+
def rule_bgp_neighbors_status(configuration, device):
111+
if "router bgp" in configuration:
112+
bgp_output = device.cli("show ip bgp summary")
113+
neighbors_down = [line for line in bgp_output.splitlines() if 'Idle' in line or 'Active' in line or 'Connect' in line]
114+
assert len(neighbors_down) == 0, f"BGP neighbors down: {', '.join([line.split()[0] for line in neighbors_down])}"
115+
```
116+
*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.*

0 commit comments

Comments
 (0)