Skip to content

Commit 8256eca

Browse files
Tests and juniper (#118)
* 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>
1 parent 6a2895c commit 8256eca

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

EXAMPLES.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ A set of common Netpicker compliance use-cases.
1414
4. [Using Configuration and Commands](#using-configuration-and-commands)
1515
5. [Using TextFSM](#using-textfsm)
1616
6. [Using Tags for Device Grouping](#using-tags-for-device-grouping)
17+
7. [Accessing Netbox Data in Netpicker Rules](#accessing-netbox-data-in-netpicker-rules)
1718

1819
## Format of the Rules
1920

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

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

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

147149
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.
148-
You can create tags such as `datacenter`, `campus`, or `branch`, and then apply specific rules to all devices in these groups.
149150

150151
```python
151152
@medium(
@@ -160,3 +161,25 @@ def rule_one(devices, device):
160161
print(f"Device: {dev.name} and IP address: {dev.ipaddress}")
161162
```
162163
*This example demonstrates how to print the name and IP address of all devices tagged with `campus`.*
164+
165+
## Accessing NetBox Data in Netpicker Rules
166+
167+
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.
168+
169+
### Example: Accessing and Printing Device Names from NetBox
170+
```python
171+
@medium(
172+
name='rule_netbox',
173+
)
174+
def rule_netbox(netbox):
175+
# Fetch all devices from NetBox
176+
devices = netbox.dcim.devices.all()
177+
178+
# Extract the names of the devices
179+
device_names = [device.name for device in devices]
180+
181+
# Print the names of all devices fetched from NetBox
182+
for name in device_names:
183+
print(name)
184+
```
185+
*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 commit comments

Comments
 (0)