mirror of
https://github.com/TheNetworkGuy/netbox-zabbix-sync.git
synced 2026-01-07 12:37:04 -06:00
Compare commits
3 Commits
c275e08953
...
fd66a4c943
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fd66a4c943 | ||
|
|
fdaeb79d4d | ||
|
|
765b4713a6 |
@@ -869,8 +869,10 @@ class PhysicalDevice:
|
|||||||
|
|
||||||
# Check host tags
|
# Check host tags
|
||||||
if config["tag_sync"]:
|
if config["tag_sync"]:
|
||||||
if remove_duplicates(host["tags"], sortkey="tag") == remove_duplicates(
|
if remove_duplicates(
|
||||||
self.tags, sortkey="tag"
|
host["tags"], lambda tag: f"{tag['tag']}{tag['value']}"
|
||||||
|
) == remove_duplicates(
|
||||||
|
self.tags, lambda tag: f"{tag['tag']}{tag['value']}"
|
||||||
):
|
):
|
||||||
self.logger.debug("Host %s: Tags in-sync.", self.name)
|
self.logger.debug("Host %s: Tags in-sync.", self.name)
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
"""A collection of tools used by several classes"""
|
"""A collection of tools used by several classes"""
|
||||||
|
|
||||||
|
from typing import Any, Callable, Optional, overload
|
||||||
from modules.exceptions import HostgroupError
|
from modules.exceptions import HostgroupError
|
||||||
|
|
||||||
|
|
||||||
@@ -108,15 +109,42 @@ def field_mapper(host, mapper, nbdevice, logger):
|
|||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
def remove_duplicates(input_list, sortkey=None):
|
@overload
|
||||||
|
def remove_duplicates(
|
||||||
|
input_list: list[dict[Any, Any]],
|
||||||
|
sortkey: Optional[str | Callable[[dict[str, Any]], str]] = None,
|
||||||
|
): ...
|
||||||
|
|
||||||
|
|
||||||
|
@overload
|
||||||
|
def remove_duplicates(
|
||||||
|
input_list: dict[Any, Any],
|
||||||
|
sortkey: Optional[str | Callable[[dict[str, Any]], str]] = None,
|
||||||
|
):
|
||||||
|
"""
|
||||||
|
deprecated: input_list as dict is deprecated, use list of dicts instead
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
def remove_duplicates(
|
||||||
|
input_list: list[dict[Any, Any]] | dict[Any, Any],
|
||||||
|
sortkey: Optional[str | Callable[[dict[str, Any]], str]] = None,
|
||||||
|
):
|
||||||
"""
|
"""
|
||||||
Removes duplicate entries from a list and sorts the list
|
Removes duplicate entries from a list and sorts the list
|
||||||
|
|
||||||
|
sortkey: Optional; key to sort the list on. Can be a string or a callable function.
|
||||||
"""
|
"""
|
||||||
output_list = []
|
output_list = []
|
||||||
if isinstance(input_list, list):
|
if isinstance(input_list, list):
|
||||||
output_list = [dict(t) for t in {tuple(d.items()) for d in input_list}]
|
output_list = [dict(t) for t in {tuple(d.items()) for d in input_list}]
|
||||||
|
|
||||||
if sortkey and isinstance(sortkey, str):
|
if sortkey and isinstance(sortkey, str):
|
||||||
output_list.sort(key=lambda x: x[sortkey])
|
output_list.sort(key=lambda x: x[sortkey])
|
||||||
|
|
||||||
|
elif sortkey and callable(sortkey):
|
||||||
|
output_list.sort(key=sortkey)
|
||||||
|
|
||||||
return output_list
|
return output_list
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user