示例#1
0
文件: tag.py 项目: kuzmich/datadogpy
 def _show(cls, args):
     api._timeout = args.timeout
     format = args.format
     if args.host == 'all':
         res = api.Tag.get_all()
     else:
         res = api.Tag.get(args.host)
     report_warnings(res)
     report_errors(res)
     if args.host == 'all':
         if format == 'pretty':
             for tag, hosts in list(res['tags'].items()):
                 for host in hosts:
                     print(tag)
                     print('  ' + host)
                 print()
         elif format == 'raw':
             print(json.dumps(res))
         else:
             for tag, hosts in list(res['tags'].items()):
                 for host in hosts:
                     print(tag + '\t' + host)
     else:
         if format == 'pretty':
             for tag in res['tags']:
                 print(tag)
         elif format == 'raw':
             print(json.dumps(res))
         else:
             for tag in res['tags']:
                 print(tag)
示例#2
0
 def _update(cls, args):
     handle = args.handle
     comment = args.comment
     id = args.comment_id
     format = args.format
     if comment is None:
         comment = sys.stdin.read()
     res = api.Comment.update(id, handle=handle, message=comment)
     report_warnings(res)
     report_errors(res)
     if format == 'pretty':
         message = res['comment']['message']
         lines = message.split('\n')
         message = '\n'.join(['    ' + line for line in lines])
         print('id\t\t' + str(res['comment']['id']))
         print('url\t\t' + res['comment']['url'])
         print('resource\t' + res['comment']['resource'])
         print('handle\t\t' + res['comment']['handle'])
         print('message\n' + message)
     elif format == 'raw':
         print(json.dumps(res))
     else:
         print('id\t\t' + str(res['comment']['id']))
         print('url\t\t' + res['comment']['url'])
         print('resource\t' + res['comment']['resource'])
         print('handle\t\t' + res['comment']['handle'])
         print('message\t\t' + res['comment']['message'].__repr__())
示例#3
0
 def _update(cls, args):
     handle = args.handle
     comment = args.comment
     id = args.comment_id
     format = args.format
     if comment is None:
         comment = sys.stdin.read()
     res = api.Comment.update(id, handle=handle, message=comment)
     report_warnings(res)
     report_errors(res)
     if format == 'pretty':
         message = res['comment']['message']
         lines = message.split('\n')
         message = '\n'.join(['    ' + line for line in lines])
         print('id\t\t' + str(res['comment']['id']))
         print('url\t\t' + res['comment']['url'])
         print('resource\t' + res['comment']['resource'])
         print('handle\t\t' + res['comment']['handle'])
         print('message\n' + message)
     elif format == 'raw':
         print(json.dumps(res))
     else:
         print('id\t\t' + str(res['comment']['id']))
         print('url\t\t' + res['comment']['url'])
         print('resource\t' + res['comment']['resource'])
         print('handle\t\t' + res['comment']['handle'])
         print('message\t\t' + res['comment']['message'].__repr__())
示例#4
0
    def _show_all(cls, args):
        api._timeout = args.timeout
        format = args.format

        res = api.Monitor.get_all(group_states=args.group_states,
                                  name=args.name,
                                  tags=args.tags,
                                  monitor_tags=args.monitor_tags)
        report_warnings(res)
        report_errors(res)

        if args.string_ids:
            for d in res:
                d["id"] = str(d["id"])

        if format == 'pretty':
            print(pretty_json(res))
        elif format == 'raw':
            print(json.dumps(res))
        else:
            for d in res:
                print("\t".join([(str(d["id"])), (cls._escape(d["message"])),
                                 (cls._escape(d["name"])), (str(d["options"])),
                                 (str(d["org_id"])), (d["query"]),
                                 (d["type"])]))
示例#5
0
    def _update(cls, args):
        api._timeout = args.timeout
        format = args.format
        graphs = args.graphs
        if args.graphs is None:
            graphs = sys.stdin.read()
        try:
            graphs = json.loads(graphs)
        except:
            raise Exception('bad json parameter')

        res = api.Screenboard.update(
            args.screenboard_id,
            title=args.title,
            description=args.description,
            graphs=graphs,
            template_variables=args.template_variables,
            width=args.width,
            height=args.height)
        report_warnings(res)
        report_errors(res)
        if format == 'pretty':
            print(cls._pretty_json(res))
        else:
            print(json.dumps(res))
示例#6
0
 def _stream(cls, args):
     api._timeout = args.timeout
     format = args.format
     if args.sources is not None:
         sources = [s.strip() for s in args.sources.split(',')]
     else:
         sources = None
     if args.tags is not None:
         tags = [t.strip() for t in args.tags.split(',')]
     else:
         tags = None
     start = parse_time(args.start)
     end = parse_time(args.end)
     # res = api.Event.query(start=start, end=end)
     # TODO FIXME
     res = api.Event.query(start=start, end=end, priority=args.priority,
                           sources=sources, tags=tags)
     report_warnings(res)
     report_errors(res)
     if format == 'pretty':
         for event in res['events']:
             prettyprint_event(event)
             print()
     elif format == 'raw':
         print(json.dumps(res))
     else:
         for event in res['events']:
             print_event(event)
             print()
示例#7
0
 def test_revoke_embed(self):
     # Create a graph that we can try getting
     graph_def = {
         "viz": "toplist",
         "requests": [{
             "q": "top(system.disk.free{$var} by {device}, 10, 'mean', 'desc')",
             "style": {
                 "palette": "dog_classic"
             },
             "conditional_formats": [{
                 "palette": "red",
                 "comparator": ">",
                 "value": 50000000000
             }, {
                 "palette": "green",
                 "comparator": ">",
                 "value": 30000000000
             }]
         }]
     }
     timeframe = "1_hour"
     size = "medium"
     legend = "no"
     graph_json = json.dumps(graph_def)
     created_graph = dog.Embed.create(graph_json=graph_json, timeframe=timeframe, size=size, legend=legend)
     # Save the embed_id into a variable and enable it again
     embed_id = created_graph["embed_id"]
     result = dog.Embed.revoke(embed_id)
     # Check embed is revoked and that we can't get it again
     assert "success" in result
     with self.assertRaises(ApiError):
         dog.Embed.get(embed_id)
示例#8
0
 def test_get_embed(self):
     # Create a graph that we can try getting
     graph_def = {
         "viz": "toplist",
         "requests": [{
             "q": "top(system.disk.free{$var} by {device}, 10, 'mean', 'desc')",
             "style": {
                 "palette": "dog_classic"
             },
             "conditional_formats": [{
                 "palette": "red",
                 "comparator": ">",
                 "value": 50000000000
             }, {
                 "palette": "green",
                 "comparator": ">",
                 "value": 30000000000
             }]
         }]
     }
     timeframe = "1_hour"
     size = "medium"
     legend = "no"
     graph_json = json.dumps(graph_def)
     created_graph = dog.Embed.create(graph_json=graph_json, timeframe=timeframe, size=size, legend=legend)
     # Save the html to check against replaced var get
     html = created_graph["html"]
     # Save the embed_id into a variable and get it again
     embed_id = created_graph["embed_id"]
     response_graph = dog.Embed.get(embed_id, var="asdfasdfasdf")
     # Check the graph has the same embed_id and the template_var is added to the url
     assert "embed_id" in response_graph
     assert response_graph["embed_id"] == embed_id
     assert len(response_graph["html"]) > len(html)
示例#9
0
 def test_create_embed(self):
     # Initialize a graph definition
     graph_def = {
         "viz": "toplist",
         "requests": [{
             "q": "top(system.disk.free{$var} by {device}, 10, 'mean', 'desc')",
             "style": {
                 "palette": "dog_classic"
             },
             "conditional_formats": [{
                 "palette": "red",
                 "comparator": ">",
                 "value": 50000000000
             }, {
                 "palette": "green",
                 "comparator": ">",
                 "value": 30000000000
             }]
         }]
     }
     timeframe = "1_hour"
     size = "medium"
     legend = "no"
     title = "Custom titles!"
     # Dump the dictionary to a JSON string and make an API call
     graph_json = json.dumps(graph_def)
     result = dog.Embed.create(graph_json=graph_json, timeframe=timeframe, size=size, legend=legend, title=title)
     # Check various result attributes
     assert "embed_id" in result
     assert result["revoked"] is False
     assert len(result["template_variables"]) == 1
     assert result["template_variables"][0] == "var"
     assert "html" in result
     assert result["graph_title"] == title
示例#10
0
    def _push(cls, args):
        api._timeout = args.timeout
        for f in args.file:
            try:
                screen_obj = json.load(f)
            except Exception as err:
                raise Exception("Could not parse {0}: {1}".format(f.name, err))

            if args.append_auto_text:
                datetime_str = datetime.now().strftime('%x %X')
                auto_text = ("<br/>\nUpdated at {0} from {1} ({2}) on {3}"
                             .format(datetime_str, f.name, screen_obj["id"], platform.node()))
                screen_obj["description"] += auto_text

            if 'id' in screen_obj:
                # Always convert to int, in case it was originally a string.
                screen_obj["id"] = int(screen_obj["id"])
                res = api.Screenboard.update(**screen_obj)
            else:
                res = api.Screenboard.create(**screen_obj)

            if 'errors' in res:
                print_err('Upload of screenboard {0} from file {1} failed.'
                          .format(screen_obj["id"], f.name))

            report_warnings(res)
            report_errors(res)

            if format == 'pretty':
                print(pretty_json(res))
            else:
                print(json.dumps(res))

            if args.format == 'pretty':
                print("Uploaded file {0} (screenboard {1})".format(f.name, screen_obj["id"]))
示例#11
0
    def _post(cls, args):
        """
        Post an event.
        """
        api._timeout = args.timeout
        format = args.format
        message = args.message
        if message is None:
            message = sys.stdin.read()
        if args.tags is not None:
            tags = [t.strip() for t in args.tags.split(',')]
        else:
            tags = None

        host = None if args.no_host else args.host

        # Submit event
        res = api.Event.create(
            title=args.title, text=message,
            # TODO FXIME
            # date_happened=args.date_happened,
            handle=args.handle, priority=args.priority,
            related_event_id=args.related_event_id, tags=tags, host=host,
            device=args.device, aggregation_key=args.aggregation_key,
            source_type_name=args.type, alert_type=args.alert_type)

        # Report
        report_warnings(res)
        report_errors(res)
        if format == 'pretty':
            prettyprint_event(res['event'])
        elif format == 'raw':
            print(json.dumps(res))
        else:
            print_event(res['event'])
示例#12
0
    def _show_all(cls, args):
        api._timeout = args.timeout
        format = args.format

        res = api.Monitor.get_all(
            group_states=args.group_states, name=args.name,
            tags=args.tags, monitor_tags=args.monitor_tags
        )
        report_warnings(res)
        report_errors(res)

        if args.string_ids:
            for d in res:
                d["id"] = str(d["id"])

        if format == 'pretty':
            print(pretty_json(res))
        elif format == 'raw':
            print(json.dumps(res))
        else:
            for d in res:
                print("\t".join([(str(d["id"])),
                                 (cls._escape(d["message"])),
                                 (cls._escape(d["name"])),
                                 (str(d["options"])),
                                 (str(d["org_id"])),
                                 (d["query"]),
                                 (d["type"])]))
示例#13
0
    def _revoke(cls, args):
        api._timeout = args.timeout
        format = args.format
        res = api.Screenboard.revoke(args.screenboard_id)

        if format == 'pretty':
            print(pretty_json(res))
        else:
            print(json.dumps(res))
示例#14
0
 def _unmute(cls, args):
     api._timeout = args.timeout
     res = api.Monitor.unmute(args.monitor_id, scope=args.scope, all_scopes=args.all_scopes)
     report_warnings(res)
     report_errors(res)
     if format == 'pretty':
         print(pretty_json(res))
     else:
         print(json.dumps(res))
示例#15
0
文件: host.py 项目: kuzmich/datadogpy
 def _unmute(cls, args):
     api._timeout = args.timeout
     format = args.format
     res = api.Host.unmute(args.host_name)
     report_warnings(res)
     report_errors(res)
     if format == 'pretty':
         print(cls._pretty_json(res))
     else:
         print(json.dumps(res))
示例#16
0
 def _show_downtime(cls, args):
     api._timeout = args.timeout
     format = args.format
     res = api.Downtime.get(args.downtime_id)
     report_warnings(res)
     report_errors(res)
     if format == 'pretty':
         print(pretty_json(res))
     else:
         print(json.dumps(res))
示例#17
0
 def _show_downtime(cls, args):
     api._timeout = args.timeout
     format = args.format
     res = api.Downtime.get(args.downtime_id)
     report_warnings(res)
     report_errors(res)
     if format == 'pretty':
         print(pretty_json(res))
     else:
         print(json.dumps(res))
示例#18
0
 def _mute(cls, args):
     api._timeout = args.timeout
     format = args.format
     res = api.Monitor.mute(args.monitor_id, scope=args.scope, end=args.end)
     report_warnings(res)
     report_errors(res)
     if format == 'pretty':
         print(cls._pretty_json(res))
     else:
         print(json.dumps(res))
示例#19
0
 def _unmute(cls, args):
     api._timeout = args.timeout
     format = args.format
     res = api.Host.unmute(args.host_name)
     report_warnings(res)
     report_errors(res)
     if format == 'pretty':
         print(cls._pretty_json(res))
     else:
         print(json.dumps(res))
示例#20
0
 def _mute_all(cls, args):
     api._timeout = args.timeout
     format = args.format
     res = api.Monitor.mute_all()
     report_warnings(res)
     report_errors(res)
     if format == 'pretty':
         print(pretty_json(res))
     else:
         print(json.dumps(res))
示例#21
0
 def _mute_all(cls, args):
     api._timeout = args.timeout
     format = args.format
     res = api.Monitor.mute_all()
     report_warnings(res)
     report_errors(res)
     if format == 'pretty':
         print(pretty_json(res))
     else:
         print(json.dumps(res))
示例#22
0
 def _show_all_downtime(cls, args):
     api._timeout = args.timeout
     format = args.format
     res = api.Downtime.get_all(current_only=args.current_only)
     report_warnings(res)
     report_errors(res)
     if format == 'pretty':
         print(pretty_json(res))
     else:
         print(json.dumps(res))
示例#23
0
 def _show_all_downtime(cls, args):
     api._timeout = args.timeout
     format = args.format
     res = api.Downtime.get_all(current_only=args.current_only)
     report_warnings(res)
     report_errors(res)
     if format == 'pretty':
         print(pretty_json(res))
     else:
         print(json.dumps(res))
示例#24
0
 def _mute(cls, args):
     api._timeout = args.timeout
     format = args.format
     res = api.Monitor.mute(args.monitor_id, scope=args.scope, end=args.end)
     report_warnings(res)
     report_errors(res)
     if format == 'pretty':
         print(pretty_json(res))
     else:
         print(json.dumps(res))
示例#25
0
文件: host.py 项目: kuzmich/datadogpy
 def _mute(cls, args):
     api._timeout = args.timeout
     format = args.format
     res = api.Host.mute(args.host_name, end=args.end, message=args.message,
                         override=args.override)
     report_warnings(res)
     report_errors(res)
     if format == 'pretty':
         print(cls._pretty_json(res))
     else:
         print(json.dumps(res))
示例#26
0
 def _schedule_downtime(cls, args):
     api._timeout = args.timeout
     format = args.format
     res = api.Downtime.create(scope=args.scope, start=args.start,
                               end=args.end, message=args.message)
     report_warnings(res)
     report_errors(res)
     if format == 'pretty':
         print(cls._pretty_json(res))
     else:
         print(json.dumps(res))
示例#27
0
 def _update_downtime(cls, args):
     api._timeout = args.timeout
     format = args.format
     res = api.Downtime.update(args.downtime_id, scope=args.scope, start=args.start,
                               end=args.end, message=args.message)
     report_warnings(res)
     report_errors(res)
     if format == 'pretty':
         print(cls._pretty_json(res))
     else:
         print(json.dumps(res))
示例#28
0
 def _update_downtime(cls, args):
     api._timeout = args.timeout
     format = args.format
     res = api.Downtime.update(args.downtime_id, scope=args.scope, start=args.start,
                               end=args.end, message=args.message)
     report_warnings(res)
     report_errors(res)
     if format == 'pretty':
         print(pretty_json(res))
     else:
         print(json.dumps(res))
示例#29
0
 def _check(cls, args):
     api._timeout = args.timeout
     format = args.format
     res = api.ServiceCheck.check(
         check=args.check, host_name=args.host_name, status=int(args.status),
         timestamp=args.timestamp, message=args.message, tags=args.tags)
     report_warnings(res)
     report_errors(res)
     if format == 'pretty':
         print(pretty_json(res))
     else:
         print(json.dumps(res))
示例#30
0
 def _check(cls, args):
     api._timeout = args.timeout
     format = args.format
     res = api.ServiceCheck.check(
         check=args.check, host_name=args.host_name, status=int(args.status),
         timestamp=args.timestamp, message=args.message, tags=args.tags)
     report_warnings(res)
     report_errors(res)
     if format == 'pretty':
         print(cls._pretty_json(res))
     else:
         print(json.dumps(res))
示例#31
0
    def _show_all(cls, args):
        api._timeout = args.timeout
        format = args.format

        res = api.DashboardList.get_all()
        report_warnings(res)
        report_errors(res)

        if format == 'pretty':
            print(pretty_json(res))
        else:
            print(json.dumps(res))
示例#32
0
 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'])
示例#33
0
 def _mute(cls, args):
     api._timeout = args.timeout
     format = args.format
     res = api.Host.mute(args.host_name,
                         end=args.end,
                         message=args.message,
                         override=args.override)
     report_warnings(res)
     report_errors(res)
     if format == 'pretty':
         print(cls._pretty_json(res))
     else:
         print(json.dumps(res))
示例#34
0
 def _schedule_downtime(cls, args):
     api._timeout = args.timeout
     format = args.format
     res = api.Downtime.create(scope=args.scope,
                               start=args.start,
                               end=args.end,
                               message=args.message)
     report_warnings(res)
     report_errors(res)
     if format == 'pretty':
         print(pretty_json(res))
     else:
         print(json.dumps(res))
示例#35
0
    def _show_dashboards(cls, args):
        api._timeout = args.timeout
        format = args.format
        dashboard_list_id = args.dashboard_list_id

        res = api.DashboardList.get_items(dashboard_list_id)
        report_warnings(res)
        report_errors(res)

        if format == 'pretty':
            print(pretty_json(res))
        else:
            print(json.dumps(res))
示例#36
0
    def _post(cls, args):
        api._timeout = args.timeout
        format = args.format
        name = args.name

        res = api.DashboardList.create(name=name)
        report_warnings(res)
        report_errors(res)

        if format == 'pretty':
            print(pretty_json(res))
        else:
            print(json.dumps(res))
示例#37
0
    def _show(cls, args):
        api._timeout = args.timeout
        format = args.format
        res = api.Monitor.get(args.monitor_id)
        report_warnings(res)
        report_errors(res)

        if args.string_ids:
            res["id"] = str(res["id"])

        if format == 'pretty':
            print(cls._pretty_json(res))
        else:
            print(json.dumps(res))
示例#38
0
文件: helper.py 项目: adqio/datadogpy
    def request_called_with(self, method, url, data=None, params=None):
        (req_method, req_url), others = self.request_mock.request.call_args
        self.assertEquals(method, req_method, req_method)
        self.assertEquals(url, req_url, req_url)

        if data:
            self.assertIn('data', others)
            self.assertEquals(json.dumps(data), others['data'], others['data'])

        if params:
            self.assertIn('params', others)
            for (k, v) in iteritems(params):
                self.assertIn(k, others['params'], others['params'])
                self.assertEquals(v, others['params'][k])
示例#39
0
    def _show(cls, args):
        api._timeout = args.timeout
        format = args.format
        res = api.Screenboard.get(args.screenboard_id)
        report_warnings(res)
        report_errors(res)

        if args.string_ids:
            res["id"] = str(res["id"])

        if format == 'pretty':
            print(pretty_json(res))
        else:
            print(json.dumps(res))
示例#40
0
    def request_called_with(self, method, url, data=None, params=None):
        (req_method, req_url), others = self.request_mock.request.call_args
        assert method == req_method, req_method
        assert url == req_url, req_url

        if data:
            assert 'data' in others
            assert json.dumps(data) == others['data'], others['data']

        if params:
            assert 'params' in others
            for (k, v) in iteritems(params):
                assert k in others['params'], others['params']
                assert v == others['params'][k]
示例#41
0
    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))
示例#42
0
    def _update(cls, args):
        api._timeout = args.timeout
        format = args.format
        dashboard_list_id = args.dashboard_list_id
        name = args.name

        res = api.DashboardList.update(dashboard_list_id, name=name)
        report_warnings(res)
        report_errors(res)

        if format == 'pretty':
            print(pretty_json(res))
        else:
            print(json.dumps(res))
示例#43
0
    def _show(cls, args):
        api._timeout = args.timeout
        format = args.format
        res = api.Timeboard.get(args.timeboard_id)
        report_warnings(res)
        report_errors(res)

        if args.string_ids:
            res["dash"]["id"] = str(res["dash"]["id"])

        if format == 'pretty':
            print(pretty_json(res))
        else:
            print(json.dumps(res))
示例#44
0
    def request_called_with(self, method, url, data=None, params=None):
        (req_method, req_url), others = self.request_mock.request.call_args
        assert method == req_method, req_method
        assert url == req_url, req_url

        if data:
            assert 'data' in others
            assert json.dumps(data) == others['data'], others['data']

        if params:
            assert 'params' in others
            for (k, v) in iteritems(params):
                assert k in others['params'], others['params']
                assert v == others['params'][k]
示例#45
0
    def request_called_with(self, method, url, data=None, params=None):
        (req_method, req_url), others = self.request_mock.request.call_args
        self.assertEquals(method, req_method, req_method)
        self.assertEquals(url, req_url, req_url)

        if data:
            self.assertIn('data', others)
            self.assertEquals(json.dumps(data), others['data'], others['data'])

        if params:
            self.assertIn('params', others)
            for (k, v) in iteritems(params):
                self.assertIn(k, others['params'], others['params'])
                self.assertEquals(v, others['params'][k])
示例#46
0
文件: tag.py 项目: kuzmich/datadogpy
 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)
示例#47
0
 def _update(cls, args):
     api._timeout = args.timeout
     format = args.format
     options = None
     if args.options is not None:
         try:
             options = json.loads(args.options)
         except:
             raise Exception('bad json parameter')
     res = api.Monitor.update(args.monitor_id, type=args.type, query=args.query,
                              name=args.name, message=args.message, options=options)
     report_warnings(res)
     report_errors(res)
     if format == 'pretty':
         print(pretty_json(res))
     else:
         print(json.dumps(res))
示例#48
0
    def _push(cls, args):
        api._timeout = args.timeout
        for f in args.file:
            try:
                dash_obj = json.load(f)
            except Exception as err:
                raise Exception("Could not parse {0}: {1}".format(f.name, err))

            if args.append_auto_text:
                datetime_str = datetime.now().strftime('%x %X')
                auto_text = (
                    "<br/>\nUpdated at {0} from {1} ({2}) on {3}".format(
                        datetime_str, f.name, dash_obj["id"], platform.node()))
                dash_obj["description"] += auto_text
            tpl_vars = dash_obj.get("template_variables", [])

            if 'id' in dash_obj:
                # Always convert to int, in case it was originally a string.
                dash_obj["id"] = int(dash_obj["id"])
                res = api.Timeboard.update(dash_obj["id"],
                                           title=dash_obj["title"],
                                           description=dash_obj["description"],
                                           graphs=dash_obj["graphs"],
                                           template_variables=tpl_vars)
            else:
                res = api.Timeboard.create(title=dash_obj["title"],
                                           description=dash_obj["description"],
                                           graphs=dash_obj["graphs"],
                                           template_variables=tpl_vars)

            if 'errors' in res:
                print_err(
                    'Upload of dashboard {0} from file {1} failed.'.format(
                        dash_obj["id"], f.name))

            report_warnings(res)
            report_errors(res)

            if format == 'pretty':
                print(pretty_json(res))
            else:
                print(json.dumps(res))

            if args.format == 'pretty':
                print("Uploaded file {0} (dashboard {1})".format(
                    f.name, dash_obj["id"]))
示例#49
0
 def _update(cls, args):
     api._timeout = args.timeout
     format = args.format
     options = None
     if args.options is not None:
         try:
             options = json.loads(args.options)
         except:
             raise Exception('bad json parameter')
     res = api.Monitor.update(args.monitor_id, type=args.type, query=args.query,
                              name=args.name, message=args.message, options=options)
     report_warnings(res)
     report_errors(res)
     if format == 'pretty':
         print(cls._pretty_json(res))
     else:
         print(json.dumps(res))
示例#50
0
 def _post(cls, args):
     api._timeout = args.timeout
     format = args.format
     graphs = args.graphs
     if args.graphs is None:
         graphs = sys.stdin.read()
     try:
         graphs = json.loads(graphs)
     except:
         raise Exception('bad json parameter')
     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))
示例#51
0
    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"])]))
示例#52
0
 def _query(cls, args):
     api._timeout = args.timeout
     res = api.Infrastructure.search(q=args.query)
     report_warnings(res)
     report_errors(res)
     if format == 'pretty':
         for facet, results in list(res['results'].items()):
             for idx, result in enumerate(results):
                 if idx == 0:
                     print('\n')
                     print("%s\t%s" % (facet, result))
                 else:
                     print("%s\t%s" % (' ' * len(facet), result))
     elif format == 'raw':
         print(json.dumps(res))
     else:
         for facet, results in list(res['results'].items()):
             for result in results:
                 print("%s\t%s" % (facet, result))
示例#53
0
    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"])]))