mirror of
https://github.com/TheNetworkGuy/netbox-zabbix-sync.git
synced 2025-07-14 01:41:25 -06:00
Merge pull request #140 from retigra/hostgroup_static_text
✨ Hostgroup static text
This commit is contained in:
commit
3e1657e575
11
README.md
11
README.md
@ -212,6 +212,17 @@ in `config.py` the script will render a full region path of all parent regions
|
|||||||
for the hostgroup name. `traverse_site_groups` controls the same behaviour for
|
for the hostgroup name. `traverse_site_groups` controls the same behaviour for
|
||||||
site_groups.
|
site_groups.
|
||||||
|
|
||||||
|
**Hardcoded text**
|
||||||
|
|
||||||
|
You can add hardcoded text in the hostgroup format by using quotes, this will
|
||||||
|
insert the literal text:
|
||||||
|
|
||||||
|
```python
|
||||||
|
hostgroup_format = "'MyDevices'/location/role"
|
||||||
|
```
|
||||||
|
|
||||||
|
In this case, the prefix MyDevices will be used for all generated groups.
|
||||||
|
|
||||||
**Custom fields**
|
**Custom fields**
|
||||||
|
|
||||||
You can use the value of custom fields for hostgroup generation. This allows
|
You can use the value of custom fields for hostgroup generation. This allows
|
||||||
|
@ -117,19 +117,24 @@ class Hostgroup:
|
|||||||
for hg_item in hg_items:
|
for hg_item in hg_items:
|
||||||
# Check if requested data is available as option for this host
|
# Check if requested data is available as option for this host
|
||||||
if hg_item not in self.format_options:
|
if hg_item not in self.format_options:
|
||||||
# Check if a custom field exists with this name
|
if hg_item.startswith(("'", '"')) and hg_item.endswith(("'", '"')):
|
||||||
cf_data = self.custom_field_lookup(hg_item)
|
hg_item = hg_item.strip("\'")
|
||||||
# CF does not exist
|
hg_item = hg_item.strip('\"')
|
||||||
if not cf_data["result"]:
|
hg_output.append(hg_item)
|
||||||
msg = (
|
else:
|
||||||
f"Unable to generate hostgroup for host {self.name}. "
|
# Check if a custom field exists with this name
|
||||||
f"Item type {hg_item} not supported."
|
cf_data = self.custom_field_lookup(hg_item)
|
||||||
)
|
# CF does not exist
|
||||||
self.logger.error(msg)
|
if not cf_data["result"]:
|
||||||
raise HostgroupError(msg)
|
msg = (
|
||||||
# CF data is populated
|
f"Unable to generate hostgroup for host {self.name}. "
|
||||||
if cf_data["cf"]:
|
f"Item type {hg_item} not supported."
|
||||||
hg_output.append(cf_data["cf"])
|
)
|
||||||
|
self.logger.error(msg)
|
||||||
|
raise HostgroupError(msg)
|
||||||
|
# CF data is populated
|
||||||
|
if cf_data["cf"]:
|
||||||
|
hg_output.append(cf_data["cf"])
|
||||||
continue
|
continue
|
||||||
# Check if there is a value associated to the variable.
|
# Check if there is a value associated to the variable.
|
||||||
# For instance, if a device has no location, do not use it with hostgroup calculation
|
# For instance, if a device has no location, do not use it with hostgroup calculation
|
||||||
|
@ -160,6 +160,7 @@ def verify_hg_format(
|
|||||||
if (
|
if (
|
||||||
hg_object not in allowed_objects[hg_type]
|
hg_object not in allowed_objects[hg_type]
|
||||||
and hg_object not in allowed_objects["cfs"][hg_type]
|
and hg_object not in allowed_objects["cfs"][hg_type]
|
||||||
|
and not hg_object.startswith(('"',"'"))
|
||||||
):
|
):
|
||||||
e = (
|
e = (
|
||||||
f"Hostgroup item {hg_object} is not valid. Make sure you"
|
f"Hostgroup item {hg_object} is not valid. Make sure you"
|
||||||
|
Loading…
Reference in New Issue
Block a user