Skip to content

Tests and juniper #109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 34 commits into from
Aug 21, 2024
Merged
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
71691c6
adding wireless tests
mailsanjayhere Aug 2, 2024
ced476c
renamed vendor names
mailsanjayhere Aug 2, 2024
a32f586
testing juniper file
mailsanjayhere Aug 2, 2024
b45c401
testing with rule_11.py
mailsanjayhere Aug 2, 2024
592c5de
updated the first rule
mailsanjayhere Aug 2, 2024
addcd0a
adding EXAMPLES.md
mailsanjayhere Aug 19, 2024
01883e8
updated the URL for EXAMPLES.md
mailsanjayhere Aug 19, 2024
e4473f7
Merge branch 'main' into tests_and_juniper
netpicker Aug 19, 2024
b4d1115
TOC for EXAMPLES.md
mailsanjayhere Aug 19, 2024
1bb817e
Tests and juniper (#96) (#97)
netpicker Aug 19, 2024
634ffa1
Merge branch 'tests_and_juniper' of https://github.com/netpicker/pyte…
mailsanjayhere Aug 19, 2024
cb25c11
updating TOC
mailsanjayhere Aug 19, 2024
8f545d5
Merge branch 'main' into tests_and_juniper
netpicker Aug 19, 2024
1575a16
updated for EXAMPLES.md
mailsanjayhere Aug 19, 2024
d8e6bfb
one more update
mailsanjayhere Aug 19, 2024
e0225d7
Merge branch 'main' into tests_and_juniper
netpicker Aug 19, 2024
d046490
removed example inside EXAMPLE.md
mailsanjayhere Aug 20, 2024
cc1fe9d
Squashed commit of the following:
netpicker Aug 20, 2024
eaa20b5
Merge branch 'main' into tests_and_juniper
netpicker Aug 20, 2024
33a850c
changed entire file contents
mailsanjayhere Aug 20, 2024
6a2e73a
Merge branch 'tests_and_juniper' of https://github.com/netpicker/pyte…
mailsanjayhere Aug 20, 2024
5830aeb
Merge branch 'main' into tests_and_juniper
netpicker Aug 20, 2024
e14a500
fixed typo for devices
mailsanjayhere Aug 20, 2024
a6aeaab
Merge branch 'tests_and_juniper' of https://github.com/netpicker/pyte…
mailsanjayhere Aug 20, 2024
a6b5929
Merge branch 'main' into tests_and_juniper
netpicker Aug 20, 2024
6aef930
update EXAMPLES.md README.md
mailsanjayhere Aug 20, 2024
5ff7b35
Merge branch 'tests_and_juniper' of https://github.com/netpicker/pyte…
mailsanjayhere Aug 20, 2024
949ccf0
removed few items from TOC
mailsanjayhere Aug 20, 2024
eb15933
replaced : with = in commands check
mailsanjayhere Aug 20, 2024
9bed9ed
added 2nd example for multiple lines check
mailsanjayhere Aug 21, 2024
973b666
Merge branch 'main' into tests_and_juniper
netpicker Aug 21, 2024
0b45225
updated example 2
mailsanjayhere Aug 21, 2024
691eac5
Merge branch 'main' into tests_and_juniper
netpicker Aug 21, 2024
25e3767
add 4th example
mailsanjayhere Aug 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions EXAMPLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ A set of common Netpicker compliance use-cases.
1. [Format of the Rules](#format-of-the-rules)
2. [Simple Examples](#simple-examples)
3. [Multiple Lines](#multiple-lines)
4. [Using Configuration and Commands](#configuration-commands)

## Format of the Rules

Expand Down Expand Up @@ -86,11 +87,30 @@ This rule checks the status of BGP neighbors and reports if any neighbor is down
@medium(
name='rule_bgp_neighbors_up',
platform=['cisco_ios'],
commands={'show_bgp_summary': 'show ip bgp summary'},
commands=dict('show_bgp_summary'='show ip bgp summary'),
)
def rule_bgp_neighbors_up(configuration, commands, device, devices):
def rule_bgp_neighbors_up(commands):
bgp_output = commands.show_bgp_summary
neighbors_down = [line for line in bgp_output.splitlines() if 'Idle' in line or 'Active' in line or 'Connect' in line]
assert len(neighbors_down) == 0, f"BGP neighbors down: {', '.join([line.split()[0] for line in neighbors_down])}"
```
*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.*

## Using Configuration and Commands

### Example: Conditional BGP Neighbor Status Check

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.

```python
@medium(
name='rule_bgp_neighbors_status',
platform=['cisco_ios'],
)
def rule_bgp_neighbors_status(configuration, device):
if "router bgp" in configuration:
bgp_output = device.cli("show ip bgp summary")
neighbors_down = [line for line in bgp_output.splitlines() if 'Idle' in line or 'Active' in line or 'Connect' in line]
assert len(neighbors_down) == 0, f"BGP neighbors down: {', '.join([line.split()[0] for line in neighbors_down])}"
```
*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.*
Loading