Skip to content

Instantly share code, notes, and snippets.

@sacreman
Last active September 19, 2016 07:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sacreman/e579014289ffcc3caac1678f2361ef47 to your computer and use it in GitHub Desktop.
Save sacreman/e579014289ffcc3caac1678f2361ef47 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import sys
from dlcli import api
# need to set the org, account and key
settings = {
'url': 'https://app.dataloop.io/api/v1',
'org': '',
'account': '',
'key': ''
}
agent_list = []
tag_list = []
source_list = []
dashboard_list = []
links_map = {}
rules_list = []
agent_count = 0
try:
print(chr(27) + "[2J") # clear screen
with open('analytics_agents') as f:
for line in f:
agent_list.append(line.strip())
print "\nAgents:\n"
for agent in agent_list:
try:
agent_count += 1
agent_details = api.agents.get_agent(agent_name=agent, **settings)
for tag in agent_details['tags']:
tag_list.append(tag)
source_list.append(agent_details['id'])
sys.stdout.write("Scanned %d / %d agents\r" % (agent_count, len(agent_list)))
sys.stdout.flush()
except TypeError:
continue
print "\nTags:\n"
for tag in sorted(set(tag_list)):
print tag
for dashboard in api.dashboards.get_dashboards(**settings):
for position in dashboard['positions']:
for series in position['series']:
if 'tag' in series['scope']:
if isinstance(series['scope']['tag'], list):
scope = ','.join(series['scope']['tag'])
else:
scope = series['scope']['tag']
if 'source' in series['scope']:
scope = series['scope']['source']
for tag in tag_list:
if tag in scope:
dashboard_list.append(dashboard['name'])
for source in source_list:
if source in scope:
dashboard_list.append(dashboard['name'])
print "\nDashboards:\n"
for dashboard in sorted(set(dashboard_list)):
print dashboard
for link in api.links.get_links(**settings):
for tag in tag_list:
if tag in link['tags']:
links_map[link['plugin']] = link['tags']
print "\nLinks:\n"
for plugin, tags in links_map.iteritems():
if isinstance(tags, list):
tag_string = ','.join(tags)
else:
tag_string = tags
print plugin + ' => ' + tag_string
print "\nRules:\n"
for rule in api.rules.get_rules(**settings):
try:
for criteria in api.rules.get_criteria(rule=rule['name'], **settings):
for tag in tag_list:
if tag in criteria['scopes'][0]['id']:
rules_list.append(rule['name'])
for source in source_list:
if source in criteria['scopes'][0]['id']:
rules_list.append(rule['name'])
except:
continue
for rule in sorted(set(rules_list)):
print rule
except KeyboardInterrupt:
print "aborted"
sys.exit(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment