Skip to content

Commit

Permalink
Tests and juniper (#118)
Browse files Browse the repository at this point in the history
* 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

* updated hyperlink for toc 4

* added one more example.. using tags

* typo

* Update EXAMPLES.md

* Update EXAMPLES.md

---------

Co-authored-by: mailsanjayhere <mailsanjayhere@gmail.com>
  • Loading branch information
2 people authored and imi committed Oct 10, 2024
1 parent 28fab51 commit c0d0157
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion EXAMPLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ A set of common Netpicker compliance use-cases.
4. [Using Configuration and Commands](#using-configuration-and-commands)
5. [Using TextFSM](#using-textfsm)
6. [Using Tags for Device Grouping](#using-tags-for-device-grouping)
7. [Accessing Netbox Data in Netpicker Rules](#accessing-netbox-data-in-netpicker-rules)

## Format of the Rules

Expand Down Expand Up @@ -141,11 +142,11 @@ def rule_interface_status_check(device):
*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.*

## Using Tags for Device Grouping
You can create tags such as `datacenter`, `campus`, or `branch`, and then apply specific rules to all devices in these groups.

### Example: Printing All Devices with a Specific Tag

In this example, the `device_tags` parameter is set to `campus`, meaning the rule is intended to apply only to devices tagged as part of the `campus` group.
You can create tags such as `datacenter`, `campus`, or `branch`, and then apply specific rules to all devices in these groups.

```python
@medium(
Expand All @@ -160,3 +161,25 @@ def rule_one(devices, device):
print(f"Device: {dev.name} and IP address: {dev.ipaddress}")
```
*This example demonstrates how to print the name and IP address of all devices tagged with `campus`.*

## Accessing NetBox Data in Netpicker Rules

Netpicker allows you to integrate with NetBox, a popular open-source IP address management (IPAM) and data center infrastructure management (DCIM) tool. By accessing NetBox data within your Netpicker rules, you can enhance your network automation tasks by incorporating detailed device information directly from your source of truth.

### Example: Accessing and Printing Device Names from NetBox
```python
@medium(
name='rule_netbox',
)
def rule_netbox(netbox):
# Fetch all devices from NetBox
devices = netbox.dcim.devices.all()

# Extract the names of the devices
device_names = [device.name for device in devices]

# Print the names of all devices fetched from NetBox
for name in device_names:
print(name)
```
*The above example demonstrates how to access NetBox data within a Netpicker rule. This rule fetches all devices from NetBox and prints their names.*

0 comments on commit c0d0157

Please sign in to comment.