forked from DataDog/Miscellany
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremove_single_tag_tmp.py
30 lines (17 loc) · 958 Bytes
/
remove_single_tag_tmp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from datadog import initialize, api
import json
def removeSingleTag(myHost, myAPIKey, myAPPKey, tagToRemove):
hostName = myHost
options = {'api_key': myAPIKey,
'app_key': myAPPKey}
initialize(**options)
myTagList = [] # interim list to hold tags from host
hosts = api.Infrastructure.search(q='hosts:' + hostName) # Get tags by host id.
myTags = api.Tag.get(hosts['results']['hosts'][0])
for tag in myTags['tags']: # Save tags to interim list
myTagList.append(tag)
myTagList.remove(tagToRemove)
api.Tag.delete(hostName) # This deletes all tags from your host
api.Tag.create(hosts['results']['hosts'][0], tags=myTagList) # This adds back all of your other tags
if __name__=="__main__":
removeSingleTag('HOSTNAME', 'API_KEY', 'APP_KEY','TAG')