Skip to content

Filters

Filters allow you to control which data is retrieved from IP Fabric during synchronization. By associating filters with Endpoints and Syncs, you can limit the scope of data collection to specific devices, networks, or other criteria. The plugin uses a two-tier filtering system consisting of Filters and Filter Expressions to provide flexibility in defining complex query conditions.

Understanding the Filtering System

The filtering system is designed to mirror IP Fabric’s native filtering capabilities, allowing you to apply the same filters you use in the IP Fabric UI to your NetBox synchronization process. Since some filters can be used on multiple endpoints, the filters is designed with reusability of filter expressions in mind.

How Filters Work

During a sync, the plugin:

  1. Identifies which Endpoints need to be queried based on enabled Sync parameters.
  2. For each endpoint, retrieves all associated Filters that are linked to this Sync.
  3. Merges all Filter Expressions from those Filters according to their Filter Type (AND/OR).
  4. Combines the merged filters with any site filters from the Sync configuration.
  5. Uses the final combined filter when querying the IP Fabric API.

This hierarchical approach allows you to create reusable filter components and combine them in different ways for different synchronization scenarios.

Filters

A Filter is a container that groups one or more Filter Expressions together and defines how they should be combined (using AND/OR logic). Filters can be associated with multiple endpoints and syncs, making them reusable across your synchronization configuration.

Parameters

Field Description Type
Name Unique name for the filter (e.g., “Production Sites Only”) CharField
Description Optional description explaining the filter’s purpose TextField
Endpoints IP Fabric endpoints this filter applies to ManyToMany
Filter Type How to combine expressions: AND/OR ChoiceField
Syncs Sync jobs that should use this filter ManyToMany
Expressions Filter Expression objects that define the actual filter conditions ManyToMany

Filter Types

  • AND: All filter expressions must match. Use this for restrictive filtering where all conditions must be met.
  • OR: At least one filter expression must match. Use this for inclusive filtering where any condition can satisfy the filter.

Filter List

Creating a Filter

To create a filter, navigate to Plugins → IP Fabric → Filters → + Add.

  1. Provide a descriptive Name and optional Description.
  2. Select the Endpoints this filter should apply to.
  3. Choose the Filter Type (AND or OR).
  4. Optionally associate the filter with specific Syncs.
  5. Add Filter Expressions that define the actual filtering logic.

Best Practice

Create focused filters that target specific endpoints or use cases. For example, create separate filters for “Core Routers” and “Cisco Devices” rather than combining all filtering logic into a single filter. This makes filters more reusable and easier to maintain.

Filter Combination

When multiple filters are associated with the same endpoint and sync, they are combined on the endpoint model. The combination process:

  1. Groups all filter expressions by their filter type (AND/OR).
  2. Recursively merges expressions with matching nested structures.
  3. Adds any site-specific filters from the sync parameters.
  4. Returns a final filter object that is sent to the IP Fabric API.

When filters have the same nested structure (matching and/or keys at the same level), they are intelligently merged. For example, if you have:

  • Filter A (AND type) with expression {"or": [{"hostname": ["like", "router1"]}]}
  • Filter B (AND type) with expression {"or": [{"hostname": ["like", "router2"]}]}
  • Filter C (OR type) with expression {"vendor": ["eq", "cisco"]}

The final combined filter sent to IP Fabric would be:

{
  "or": [
    {"vendor": ["eq", "cisco"]}
  ],
  "and": [
    {
      "or": [
        {"hostname": ["like", "router1"]},
        {"hostname": ["like", "router2"]}
      ]
    }
  ]
}

Filter Combination Example

Note how filters A and B were merged into a single or array because they had the same nested structure, while filter C remained separate as it has a different filter type.

Filter Expressions

Filter Expressions contain the actual JSON filter criteria that will be sent to the IP Fabric API. These expressions use the same format as IP Fabric’s native filtering system, specifically the Advanced Filtering format, which can be captured directly from the IP Fabric UI.

IP Fabric Advanced Filtering

Filter expressions in NetBox use the exact same format as IP Fabric’s Advanced Filter feature. In IP Fabric, filters are defined by groups and rules, where each group can contain one or more rules or nested groups with logical operators (AND/OR).

For detailed information about how filtering rules work in IP Fabric, see the Advanced Filtering documentation.

For complete filter specifications and available filter fields for each endpoint, refer to IP Fabric’s API documentation in RapiDoc. You can access RapiDoc by following the instructions in the Accessing RapiDoc section of the IP Fabric documentation. Each endpoint has its own set of available filters documented in the API specification.

Parameters

Field Description Type
Name Unique name for the expression (e.g., “Site1 Devices”) CharField
Description Optional description of what the expression filters TextField
Expression JSON filter expression in IP Fabric format JSONField
Filters Filter objects that use this expression ManyToMany

Filter Expression List

Creating a Filter Expression

To create a filter expression, navigate to Plugins → IP Fabric → Filter Expressions → + Add.

Obtaining Filter JSON from IP Fabric

The easiest and most accurate way to create filter expressions is to capture them directly from IP Fabric:

  1. Open IP Fabric in your browser and navigate to any table view.
  2. In IP Fabric, click Advanced Filter to open the filtering interface.
  3. Define your filter using groups and rules with the desired logical operators (AND/OR).
  4. Apply the filter to the table.
  5. Open the Table Description item under the 3-dots menu in the top right corner of the table. 3 Dots - Table Description
  6. Find and copy the filters object value from the request body.

    Table Description - Request Payload

  7. Paste the value (example below) into the Expression field in NetBox.

[
  {
    "hostname": [
      "eq",
      "s4xsw01"
    ]
  },
  {
    "vendor": [
      "eq",
      "arista"
    ]
  }
]

Table Description

The Table Description dialog shows the exact API request that IP Fabric uses to fetch the filtered data. The filters object contains the filter structure that IP Fabric uses internally, ensuring compatibility and correctness when used in NetBox.

Expression Format

Filter expressions must be a JSON array of filter conditions. Each condition is a dictionary with field names as keys and arrays as values. Number of items in the array can be up to 4 but the most common is [operator, value].

Common Operators:

  • eq - Equals
  • neq - Not equals
  • ieq - Equals (case-insensitive)
  • nieq - Not equals (case-insensitive)
  • like - Contains
  • notlike - Not contains
  • reg - Regex
  • nreg - Negative regex
  • ireg - Regex (case-insensitive)
  • nireg - Negative regex (case-insensitive)
  • empty - Is empty (uses True as value or False if not empty)

Available Filter Fields:

The available filter fields depend on the specific endpoint being queried. Each IP Fabric endpoint has its own set of filterable fields. To find the complete list of available filters for a specific endpoint:

  1. Access IP Fabric’s RapiDoc API documentation (see Accessing RapiDoc).
  2. Navigate to the endpoint you want to filter (e.g., /tables/inventory/devices).
  3. Review the filter schema documentation for that endpoint.
  4. Use the field names from the API specification in your filter expressions.

Common filterable fields across endpoints include: siteName, hostname, vendor, family, model, sn (serial number), intName (interface name), but each endpoint has its own specific set of available filters.

Example Expressions:

Simple hostname filter:

[{"hostname": ["eq", "ROUTER-01"]}]

Hostname pattern matching:

[{"hostname": ["regex", "router.*"]}]

Multiple conditions:

[
  {"hostname": ["empty", false]},
  {"vendor": ["eq", "cisco"]}
]

Complex nested filter:

[
  {
    "or": [
      {"vendor": ["eq", "cisco"]},
      {"vendor": ["eq", "juniper"]}
    ]
  }
]

Testing Filter Expressions

The Filter Expression form includes built-in testing capabilities to verify your expressions work correctly before using them in a sync.

Test Filter Expression

When editing a filter expression:

  1. The Test Source field automatically populates if the expression is associated with filters that have a common source.
  2. The Test Endpoint field automatically populates if the expression is associated with filters that target a single endpoint.
  3. Click the Test button to query IP Fabric using your expression.
  4. Review the results to confirm the filter returns the expected data.

Note

Testing sends real request to your IP Fabric instance. It must be reachable from NetBox for this feature to work.

Viewing Filter Details

To view filter details, navigate to Plugins → IP Fabric → Filters and select a filter. The detail page displays:

  • Filter name, description, and type
  • Linked endpoints, expressions and syncs

Filter Detail

Relationships with Other Models

Endpoints

Filters have a many-to-many relationship with Endpoints. You can associate a filter with multiple endpoints if the same filtering logic applies across different data sources. When an endpoint is queried during a sync, all filters associated with that endpoint are combined into the final query.

Syncs

Filters can be associated with specific Syncs through a many-to-many relationship. This allows you to apply different filtering rules to different synchronization jobs. For example, you might have one sync that filters for production sites only, and another that includes all sites.

When a sync runs, it only uses filters that are explicitly associated with that sync job.

Filter Expressions

Filters contain one or more Filter Expressions through a many-to-many relationship. This allows you to:

  • Reuse common filter expressions across multiple filters.
  • Build complex filtering logic by combining simple expressions.
  • Maintain a library of reusable filter components.

Use Cases and Examples

Filtering by Hostname Pattern

Create a filter to synchronize only devices matching a naming convention:

Filter Expression:

[
  {
    "or": [
      {"hostname": ["like", "core-"]},
      {"hostname": ["like", "dist-"]},
      {"hostname": ["like", "access-"]}
    ]
  }
]

Associate this with the device endpoint and create similar expression replacing hostname with device.hostname for interface and IP address endpoints to limit all synchronized data to devices matching these patterns.

Filtering by Device Type

Create a filter to synchronize only routers and switches:

Filter Expression:

[
  {
    "or": [
      {"family": ["eq", "switch"]},
      {"family": ["eq", "router"]}
    ]
  }
]

Filtering by Vendor

Create a filter for specific vendors:

Filter Expression:

[
  {
    "or": [
      {"vendor": ["eq", "cisco"]},
      {"vendor": ["eq", "juniper"]}
    ]
  }
]

Filtering by VLAN ID

Create a filter to synchronize specific VLANs:

Filter Expression:

[
  {
    "or": [
      {"vlanId": ["eq", "100"]},
      {"vlanId": ["eq", "200"]}
    ]
  }
]

Filtering by VRF

Create a filter to synchronize specific VRFs:

Filter Expression:

[{"vrf": ["like", "PROD-"]}]

Combining Multiple Conditions

Create a filter for Cisco routers in production VRFs using AND logic:

Filter Expression 1 - Vendor:

[{"vendor": ["eq", "cisco"]}]

Filter Expression 2 - VRF:

[{"vrf": ["reg", "PROD-.*"]}]

Filter Expression 3 - Device Type:

[{"family": ["eq", "router"]}]

Create a Filter with type “AND” and add all three expressions. This ensures only Cisco routers in production VRFs are synchronized.

Best Practices

  1. Use Descriptive Names: Name your filters and expressions clearly to indicate their purpose (e.g., “Core Routers Only”, “Production VLANs”).

  2. Test Before Use: Always test filter expressions using the built-in test functionality before associating them with a sync.

  3. Keep Expressions Simple: Create focused filter expressions that do one thing well, then combine them using filters for complex logic.

  4. Reuse Components: Build a library of reusable filter expressions that can be mixed and matched across different filters.

  5. Document Complex Filters: Use the description field to explain complex filtering logic, especially when combining multiple expressions.

  6. Capture from IP Fabric: Rather than manually writing filter JSON, capture it from IP Fabric’s UI to ensure correct syntax.

  7. Consider Performance: Overly broad filters may retrieve large amounts of data. Use specific filtering criteria to improve sync performance.