Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _show_all(cls, args):
api._timeout = args.timeout
format = args.format
params = {"offset": args.offset, "limit": args.limit}
if args.query:
params["query"] = args.query
else:
params["ids"] = args.slo_ids
res = api.ServiceLevelObjective.get_all(return_raw=True, **params)
report_warnings(res)
report_errors(res)
if format == "pretty":
print(pretty_json(res))
else:
print(json.dumps(res))
def _file_update(cls, args):
api._timeout = args.timeout
format = args.format
monitor = json.load(args.file)
res = api.Monitor.update(monitor['id'], type=monitor['type'], query=monitor['query'],
name=monitor['name'], message=monitor['message'],
options=monitor['options'])
report_warnings(res)
report_errors(res)
if format == 'pretty':
print(pretty_json(res))
else:
print(json.dumps(res))
def _post(cls, args):
api._timeout = args.timeout
format = args.format
graphs = args.graphs
if args.graphs is None:
graphs = sys.stdin.read()
graphs = json.loads(graphs)
res = api.Timeboard.create(title=args.title, description=args.description, graphs=[graphs],
template_variables=args.template_variables)
report_warnings(res)
report_errors(res)
if format == 'pretty':
print(pretty_json(res))
else:
print(json.dumps(res))
def _delete(cls, args):
api._timeout = args.timeout
format = args.format
dashboard_list_id = args.dashboard_list_id
res = api.DashboardList.delete(dashboard_list_id)
report_warnings(res)
report_errors(res)
if format == 'pretty':
print(pretty_json(res))
else:
print(json.dumps(res))
def _delete_dashboards(cls, args):
api._timeout = args.timeout
format = args.format
dashboard_list_id = args.dashboard_list_id
dashboards = json.loads(args.dashboards)
res = api.DashboardList.delete_items(dashboard_list_id, dashboards=dashboards)
report_warnings(res)
report_errors(res)
if format == 'pretty':
print(pretty_json(res))
else:
print(json.dumps(res))
def _file_create(cls, args):
api._timeout = args.timeout
format = args.format
slo = json.load(args.file)
res = api.ServiceLevelObjective.create(return_raw=True, **slo)
report_warnings(res)
report_errors(res)
if format == "pretty":
print(pretty_json(res))
else:
print(json.dumps(res))
def _show(cls, args):
api._timeout = args.timeout
format = args.format
res = api.Event.get(args.event_id)
report_warnings(res)
report_errors(res)
if format == 'pretty':
prettyprint_event_details(res['event'])
elif format == 'raw':
print(json.dumps(res))
else:
print_event_details(res['event'])
def _show_all(cls, args):
api._timeout = args.timeout
format = args.format
res = api.Timeboard.get_all()
report_warnings(res)
report_errors(res)
if args.string_ids:
for d in res["dashes"]:
d["id"] = str(d["id"])
if format == 'pretty':
print(pretty_json(res))
elif format == 'raw':
print(json.dumps(res))
else:
for d in res["dashes"]:
print("\t".join([(d["id"]),
(d["resource"]),
(d["title"]),
cls._escape(d["description"])]))
def _replace(cls, args):
api._timeout = args.timeout
format = args.format
res = api.Tag.update(args.host, tags=args.tag)
report_warnings(res)
report_errors(res)
if format == 'pretty':
print("Tags for '%s':" % res['host'])
for c in res['tags']:
print(' ' + c)
elif format == 'raw':
print(json.dumps(res))
else:
for c in res['tags']:
print(c)
def _can_delete(cls, args):
api._timeout = args.timeout
res = api.ServiceLevelObjective.can_delete(args.slo_ids)
if res is not None:
report_warnings(res)
report_errors(res)
if format == "pretty":
print(pretty_json(res))
else:
print(json.dumps(res))