Closed willfurnell closed 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.
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
add the tag_slugs
to the host as a array var tags
object Host "nbdevice nas" {
import "nbtenant bob"
import "nbsite earth"
display_name = "nas"
address = "25.0.0.160"
check_command = "hostalive"
groups += [
"nbdevice_role nas"
]
vars.manufacturer = "Synology"
vars.model = "DS416j"
vars.tags = [ "byo-nas" ]
}
create a import source for the tags themselves and create host group sync rules for tags with an assign_filter
property with a value of %22${name}%22=host.vars.tags
. (edit: I also prefix the host group name, Tag: {name}
so it is easy to tell what is a tag in the UI)
You will then be able to use the host tag var and tag host groups.
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):
I also tried to use it via a custom expression - but that didn't return anything either?
@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!
@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.
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:
but it would be useful to have the following as something like
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!