Import source (Netbox) filter expression

Hello,

I try to filter my import source from netbox.
I want to filter on a custom field so I previously create a modifier like this

And next I set the filter expression into the import source rule like this

status=active&environment=cust

No error when I store the config or when I check for change but nothing change since the last run (with this filter, the import should get only one record…)

How can I achieve this ?

Thanks

Hello.

Which netbox import module are you using?
Did you flatten the custom_fields so that you can access the individual values?
Can you share the preview of your import?

Hello,

I use this one GitHub - sol1/icingaweb2-module-netbox: Netbox importer for director, and integration with netbox
Yes I flat the custom field with the propertie modifier as shown on the screenshot (but maybe it’s not the good way)
Here the first line of the preview

{
        "id": 303,
        "url": "https://netbox_url/api/dcim/devices/303/",
        "display": "tt",
        "name": "tt",
        "device_type": {
            "id": 1123,
            "url": "https://netbox_url/api/dcim/device-types/1123/",
            "display": "tt",
            "manufacturer": {
                "id": 52,
                "url": "https://netbox_url/api/dcim/manufacturers/52/",
                "display": "tt",
                "name": "tt",
                "slug": "tt"
            },
            "model": "tt",
            "slug": "tt-tt"
        },
        "role": {
            "id": 28,
            "url": "https://netbox_url/api/dcim/device-roles/28/",
            "display": "WLC",
            "name": "WLC",
            "slug": "wlc"
        },
        "device_role": {
            "id": 28,
            "url": "https://netbox_url/api/dcim/device-roles/28/",
            "display": "WLC",
            "name": "WLC",
            "slug": "wlc"
        },
        "tenant": null,
        "platform": null,
        "serial": "102346878197",
        "asset_tag": null,
        "site": {
            "id": 7,
            "url": "https://netbox_url/api/dcim/sites/7/",
            "display": "lyo01",
            "name": "lyo01",
            "slug": "lyo01"
        },
        "location": {
            "id": 15,
            "url": "https://netbox_url/api/dcim/locations/15/",
            "display": "SS1",
            "name": "SS1",
            "slug": "ss1",
            "_depth": 0
        },
        "rack": {
            "id": 50,
            "url": "https://netbox_url/api/dcim/racks/50/",
            "display": "tt",
            "name": "tt"
        },
        "position": 1,
        "face": {
            "value": "front",
            "label": "Front"
        },
        "latitude": null,
        "longitude": null,
        "parent_device": null,
        "status": {
            "value": "active",
            "label": "Active"
        },
        "airflow": null,
        "primary_ip": {
            "id": 621,
            "url": "https://netbox_url/api/ipam/ip-addresses/621/",
            "display": "x.x.x.x/xx",
            "family": 4,
            "address": "x.x.x.x/xx"
        },
        "primary_ip4": {
            "id": 621,
            "url": "https://netbox_url/api/ipam/ip-addresses/621/",
            "display": "x.x.x.x/xx",
            "family": 4,
            "address": "x.x.x.x/xx"
        },
        "primary_ip6": null,
        "oob_ip": null,
        "cluster": null,
        "virtual_chassis": null,
        "vc_position": null,
        "vc_priority": null,
        "description": "tt",
        "comments": "",
        "config_template": null,
        "config_context": {},
        "local_context_data": null,
        "tags": [],
        "custom_fields": {
            "bgp_asn_priv_16b": null,
            "bgp_asn_private_16b": null,
            "customer": "corp",
            "environment": "corp",
            "ip_anycast_vtep": null,
            "ipmi_type": null,
            "os_family": null,
            "os_version": null,
            "supervision_tag": null,
            "vpc_id": null
        },
        "created": "2024-04-10T12:49:19.507389Z",
        "last_updated": "2024-06-07T11:58:08.856831Z",
        "console_port_count": 1,
        "console_server_port_count": 0,
        "power_port_count": 1,
        "power_outlet_count": 0,
        "interface_count": 13,
        "front_port_count": 0,
        "rear_port_count": 0,
        "device_bay_count": 0,
        "module_bay_count": 0,
        "inventory_item_count": 0,
        "keyid": "nbdevice tt",
        "primary_ip_address": "x.x.x.x",
        "primary_ip4_address": "x.x.x.x",
        "primary_ip6_address": null,
        "tag_slugs": [],
        "device_role_keyid": "nbdevice_role wlc",
        "device_keyid": null,
        "platform_keyid": null,
        "location_keyid": "nblocation ss1",
        "rack_keyid": "nbrack tt",
        "cluster_keyid": null,
        "site_keyid": "nbsite tt",
        "tenant_keyid": null,
        "device_model_keyid": "nbmodel tt",
        "device_model": "tt",
        "device_manufacturer_keyid": "nbmanufacturer tt",
        "device_manufacturer": "tt",
        "role_keyid": "nbrole wlc",
        "icinga_satellite_client_zone": null,
        "icinga_satellite_parent_endpoint": null,
        "icinga_satellite_parent_fqdn": null,
        "icinga_satellite_parent_zone": null,
        "icinga_host_zone": null,
        "icinga_service": null,
        "icinga_service_type": null,
        "icinga_var": null,
        "icinga_var_type": null,
        "ip_range_keyid": null,
        "ip_range_zone": null,
        "contacts": [],
        "contact_keyids": [],
        "services": {},
        "service_names": [],
        "manufacturer": "tt",
        "os_family": null,
        "supervision_tag": null,
        "ipmi_type": null,
        "device_type-slug": "tt",
        "environment": "corp",
        "customer": "corp"
    },

The filter expression I use in the import source is : status=active&environment=cust
When I use similar custom expression in the sync rule it’s working (but I have to import all the netbox database for nothing…)

I don’t have experience with this module yet, as we still use a different (outdated) module and have not made the switch yet…

It seems the “flatten” is different from the module we use.
On our side the flatten would render custom_fields to custome_fields__xyz (double underscore)

Looking at the docs from the sol1 module, you need to use the Get specific array element property modifier instead of custom_fields[dot]something

See: GitHub - sol1/icingaweb2-module-netbox: Netbox importer for director, and integration with netbox

edit: I just saw that we had the module installed in our DEV env and noticed that there is flatten seperator field. Do you have that filled, e.g. with a _?

I already use the property modifier to get subvalue of the “custom_fileds” object.
When I watch the preview of the import I can see value I need, in the variable I configure.

In my search filter I set “status=active&environment=cust” and, as you can see, object with environment not equal cust (“corp” in my screenshot)… Maybe the problem is just with my search filter ?
Any idea ?

If I understand correctly you want to use a discovered/fetched property in the search filter you use for discovering/fetching the information.

That sounds like a chicken-and-egg-problem :slight_smile:

Maybe try to use the Reject or keep ... modifier to discard rows that you don’t want based on the environment property
image

Oh… your right, I hadn’t seen it like that…
But I try your suggestion and it’s working !!!
Thank you very much !!!