sol1 / icingaweb2-module-netbox

Netbox importer for director, and integration with netbox
28 stars 6 forks source link

Get tags from device in device properties as array #30

Closed willfurnell closed 8 months ago

willfurnell commented 8 months ago

Hello, Sorry yet another issue/feature request from me - is it possible to get the tags assigned to a device in the device properties - so we can use the tags later to assign certain services,

I note that tags do show up in the preview/JSON output of it like so:

        "tags__0__id": 46,
        "tags__0__url": "https://netbox/api/extras/tags/46/",
        "tags__0__display": "icinga:check_md3060e",
        "tags__0__name": "icinga:check_md3060e",
        "tags__0__slug": "icingacheck_md3060e",
        "tags__0__color": "9e9e9e",

but it would be useful to have the following as something like

"tags": ["icinga:check_md3060e"] 

as well or instead. Then it would be possible to use the list of tags as a way to specify checks I want via service apply rules, Thanks!

davekempe commented 8 months ago

I'm certain we already have a way of getting tags into host vars, as an array, I can see in a number of instances. I'm not sure how to explain it without a bunch of screenshots though. Perhaps @sol1-matt can help here.

sol1-matt commented 8 months ago

Old Netbox used to store tags as strings and did indeed create an array of strings which was heavily used (by me in automation), then they changed tags to be objects (dicts) and we had a array of dicts.

This isn't particularly useful for monitoring automation so the import module creates a new property tag_slugs which is a list of strings based on the slug of each tag.

My typical usage is to

You will then be able to use the host tag var and tag host groups.

willfurnell commented 8 months ago

Thank you for your help. The weird thing is, I don't actually see a tag_slugs property to use in my sync rule (source column bit): image I also tried to use it via a custom expression - but that didn't return anything either?

willfurnell commented 8 months ago

@sol1-matt Apologies to disturb you - but do you know why I can't actually see tag_slugs in my source column selection? Is there any information I can provide or should be looking for to debug? Thanks!

sol1-matt commented 7 months ago

@willfurnell you can see the code where the tag slugs are being created here https://github.com/sol1/icingaweb2-module-netbox/blob/v3.6.1.0/library/Netbox/Netbox.php#L182, which should match your installed module code.

From there look at the preview of you Import Source. That has all the fields and should include tag_slugs.

If you have the code but not the values then look at the data in Netbox (https://netbox.you/api/dcim/devices/), you should find the tags value in there.

If Netbox has the right data then create a new Import Source with only the required fields and the data you saw in the api above should be in that import source with the additional modifiers the module adds.

I like to filter on a single host when I do this as it makes it easier to compare the two.