Created
August 13, 2018 18:26
-
-
Save burnsie7/b0a9a51ead10fb07b7e74580b2cb3061 to your computer and use it in GitHub Desktop.
Basic Tag Update
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import os | |
import requests | |
import pprint | |
from datadog import initialize, api | |
DD_API_KEY = os.getenv('DD_API_KEY', '<YOUR_API_KEY>') | |
DD_APP_KEY = os.getenv('DD_APP_KEY', '<YOUR_APP_KEY>') | |
options = { | |
'api_key': DD_API_KEY, | |
'app_key': DD_APP_KEY | |
} | |
initialize(**options) | |
result = api.Hosts.search() | |
hosts = result['host_list'] | |
host_names = [] | |
for h in hosts: | |
host_names.append(h['host_name']) | |
start_string = 'i-' | |
for name in host_names: | |
if name.startswith(start_string): | |
res = api.Tag.create(name, tags=["api_tag"]) | |
pprint.pprint(res) | |
for name in host_names: | |
pprint.pprint(name) | |
pprint.pprint(api.Tag.get(name)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment