fix: refactor tags handling
This commit is contained in:
parent
c4dfae1833
commit
ca878138a1
2 changed files with 4 additions and 4 deletions
|
@ -12,7 +12,7 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
def die_tag_format_error():
|
||||
logger.error(
|
||||
"Fatal: You must provide tags in monitors in the format [[name, value]]"
|
||||
"Fatal: You must provide tags in monitors in the format [{name:str, value:str}] (value is optional)"
|
||||
)
|
||||
sys.exit(1)
|
||||
|
||||
|
@ -27,10 +27,10 @@ def from_dict(api, tree):
|
|||
for m in monitors:
|
||||
associated_tags = []
|
||||
for tag in m.get("tags", []):
|
||||
if not isinstance(tag, list):
|
||||
if not isinstance(tag, dict) or "name" not in tag:
|
||||
die_tag_format_error()
|
||||
try:
|
||||
associated_tags.append((indexed_tags[tag[0]], tag[1]))
|
||||
associated_tags.append((indexed_tags[tag["name"]], tag.get("value")))
|
||||
except IndexError:
|
||||
die_tag_format_error()
|
||||
m["tags"] = associated_tags
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
"name":"test"
|
||||
}],
|
||||
"monitors": [{
|
||||
"tags": [["test", "value"]],
|
||||
"tags": [{ "name":"test", "value":"value"}],
|
||||
"notifications": [ "dgn" ],
|
||||
"old_name": "test_monitor",
|
||||
"name": "test_monitor2",
|
||||
|
|
Loading…
Reference in a new issue