Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions bin/ccdc-team-mappings/create_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,14 @@ def get_hosts(self):
graphql_query = """
query getHosts($where:HostWhereInput){
hosts(where:$where) {
id
primaryIP
name
edges {
node {
id
primaryIP
externalIP
name
}
}
}
} """

Expand All @@ -54,7 +59,11 @@ def get_tag(self, tag_name):
graphql_query = """
query getTag($input:TagWhereInput){
tags(where:$input) {
id
edges {
node {
id
}
}
}
} """

Expand All @@ -63,8 +72,8 @@ def get_tag(self, tag_name):
if 'errors' in res:
return -1
else:
if len(res['data']['tags']) > 0:
return res['data']['tags'][0]['id']
if len(res['data']['tags']['edges']) > 0:
return res['data']['tags']['edges'][0]['node']['id']
else:
return -1

Expand Down Expand Up @@ -142,12 +151,16 @@ def run(self):
"id": tag_id,
}

for row in data["data"]["hosts"]:
for row in data["data"]["hosts"]["edges"]:
row = row["node"]
for tag_profile in tag_profiles:
re_match = None
if 'ip_regex' in tag_profile:
re_match = re.search(
tag_profile["ip_regex"], row["primaryIP"])
if 'ip_regex' in tag_profile and re_match is None:
re_match = re.search(
tag_profile["ip_regex"], row["externalIP"])
if 'hostname_regex' in tag_profile:
re_match = re.search(
tag_profile["hostname_regex"], row["name"])
Expand Down
Loading