Exemplo n.º 1
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()
Exemplo n.º 2
0
 def _post(cls, args):
     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
     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=args.host,
         device=args.device, aggregation_key=args.aggregation_key,
         source_type_name=args.type)
     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'])
Exemplo n.º 3
0
 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)
Exemplo n.º 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"])]))
Exemplo n.º 5
0
 def _unmute(cls, args):
     api._timeout = args.timeout
     # TODO CHECK
     res = api.Monitor.unmute(args.monitor_id, scope=args.scope)
     if res is not None:
         report_warnings(res)
         report_errors(res)
Exemplo n.º 6
0
 def _delete(cls, args):
     api._timeout = args.timeout
     # TODO CHECK
     res = api.Monitor.delete(args.monitor_id)
     if res is not None:
         report_warnings(res)
         report_errors(res)
Exemplo n.º 7
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__())
Exemplo n.º 8
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"]))
Exemplo n.º 9
0
 def _delete(cls, args):
     api._timeout = args.timeout
     # TODO CHECK
     res = api.Screenboard.delete(args.screenboard_id)
     if res is not None:
         report_warnings(res)
         report_errors(res)
Exemplo n.º 10
0
    def _pull_all(cls, args):
        api._timeout = args.timeout

        def _title_to_filename(title):
            # Get a lowercased version with most punctuation stripped out...
            no_punct = ''.join([c for c in title.lower() if c.isalnum() or c in [" ", "_", "-"]])
            # Now replace all -'s, _'s and spaces with "_", and strip trailing _
            return no_punct.replace(" ", "_").replace("-", "_").strip("_")

        format = args.format
        res = api.Timeboard.get_all()
        report_warnings(res)
        report_errors(res)

        if not os.path.exists(args.pull_dir):
            os.mkdir(args.pull_dir, 0o755)

        used_filenames = set()
        for dash_summary in res['dashes']:
            filename = _title_to_filename(dash_summary['title'])
            if filename in used_filenames:
                filename = filename + "-" + dash_summary['id']
            used_filenames.add(filename)

            cls._write_dash_to_file(
                dash_summary['id'], os.path.join(args.pull_dir, filename + ".json"),
                args.timeout, format, args.string_ids)
        if format == 'pretty':
            print(("\n### Total: {0} dashboards to {1} ###"
                  .format(len(used_filenames), os.path.realpath(args.pull_dir))))
Exemplo n.º 11
0
 def _delete(cls, args):
     api._timeout = args.timeout
     id = args.comment_id
     res = api.Comment.delete(id)
     if res is not None:
         report_warnings(res)
         report_errors(res)
Exemplo n.º 12
0
    def _post(cls, args):
        """
        Post a metric.
        """
        # Format parameters
        api._timeout = args.timeout

        host = None if args.no_host else args.host

        if args.tags:
            tags = sorted(set([t.strip() for t in
                               args.tags.split(',') if t]))
        else:
            tags = None

        # Submit metric
        res = api.Metric.send(
            metric=args.name, points=args.value, host=host,
            device=args.device, tags=tags, metric_type=args.type)

        # Report
        res = defaultdict(list, res)

        if args.localhostname:
            # Warn about`--localhostname` command line flag deprecation
            res['warnings'].append(
                u"`--localhostname` command line flag is deprecated, made default when no `--host` "
                u"is specified. See the `--host` option for more information."
            )
        report_warnings(res)
        report_errors(res)
Exemplo n.º 13
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(cls._pretty_json(res))
     else:
         print(json.dumps(res))
Exemplo n.º 14
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(cls._pretty_json(res))
     else:
         print(json.dumps(res))
Exemplo n.º 15
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))
Exemplo n.º 16
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))
Exemplo n.º 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))
Exemplo n.º 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(pretty_json(res))
     else:
         print(json.dumps(res))
Exemplo n.º 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))
Exemplo n.º 20
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))
Exemplo n.º 21
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))
Exemplo n.º 22
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'])
Exemplo n.º 23
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))
Exemplo n.º 24
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))
Exemplo n.º 25
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))
Exemplo n.º 26
0
 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)
Exemplo n.º 27
0
 def _post(cls, args):
     api._timeout = args.timeout
     if args.localhostname:
         host = find_localhost()
     else:
         host = args.host
     if args.tags:
         tags = sorted(set([t.strip() for t in
                            args.tags.split(',') if t]))
     else:
         tags = None
     res = api.Metric.send(
         metric=args.name, points=args.value, host=host,
         device=args.device, tags=tags, metric_type=args.type)
     report_warnings(res)
     report_errors(res)
Exemplo n.º 28
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))
Exemplo n.º 29
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))
Exemplo n.º 30
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))
Exemplo n.º 31
0
    def _update(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.Screenboard.update(
            args.screenboard_id,
            board_title=args.title,
            description=args.description,
            widgets=graphs,
            template_variables=args.template_variables,
            width=args.width,
            height=args.height)
        report_warnings(res)
        report_errors(res)
        if format == 'pretty':
            print(pretty_json(res))
        else:
            print(json.dumps(res))
Exemplo n.º 32
0
    def _new_file(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.filename,
            description="Description for {0}".format(args.filename),
            graphs=[graphs])

        report_warnings(res)
        report_errors(res)

        cls._write_dash_to_file(res['dash']['id'], args.filename,
                                args.timeout, format, args.string_ids)

        if format == 'pretty':
            print(pretty_json(res))
        else:
            print(json.dumps(res))
Exemplo n.º 33
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.Timeboard.update(args.timeboard_id,
                                   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))
Exemplo n.º 34
0
 def _post(cls, args):
     graphs = sys.stdin.read()
     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.Screenboard.create(
         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(pretty_json(res))
     else:
         print(json.dumps(res))
Exemplo n.º 35
0
 def _show(cls, args):
     api._timeout = args.timeout
     id = args.comment_id
     format = args.format
     res = api.Event.get(id)
     report_warnings(res)
     report_errors(res)
     if format == 'pretty':
         message = res['event']['text']
         lines = message.split('\n')
         message = '\n'.join(['    ' + line for line in lines])
         print('id\t\t' + str(res['event']['id']))
         print('url\t\t' + res['event']['url'])
         print('resource\t' + res['event']['resource'])
         print('message\n' + message)
     elif format == 'raw':
         print(json.dumps(res))
     else:
         print('id\t\t' + str(res['event']['id']))
         print('url\t\t' + res['event']['url'])
         print('resource\t' + res['event']['resource'])
         print('message\t\t' + res['event']['text'].__repr__())
Exemplo n.º 36
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,
                               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'])
Exemplo n.º 37
0
    def _write_screen_to_file(cls, screenboard_id, filename, timeout,
                              format='raw', string_ids=False):
        with open(filename, "w") as f:
            res = api.Screenboard.get(screenboard_id)
            report_warnings(res)
            report_errors(res)

            screen_obj = res
            if "resource" in screen_obj:
                del screen_obj["resource"]
            if "url" in screen_obj:
                del screen_obj["url"]

            if string_ids:
                screen_obj["id"] = str(screen_obj["id"])

            json.dump(screen_obj, f, indent=2)

            if format == 'pretty':
                print("Downloaded screenboard {0} to file {1}".format(screenboard_id, filename))
            else:
                print("{0} {1}".format(screenboard_id, filename))
Exemplo n.º 38
0
 def _show(cls, args):
     api._timeout = args.timeout
     id = args.comment_id
     format = args.format
     res = api.Event.get(id)
     report_warnings(res)
     report_errors(res)
     if format == "pretty":
         message = res["event"]["text"]
         lines = message.split("\n")
         message = "\n".join(["    " + line for line in lines])
         print("id\t\t" + str(res["event"]["id"]))
         print("url\t\t" + res["event"]["url"])
         print("resource\t" + res["event"]["resource"])
         print("message\n" + message)
     elif format == "raw":
         print(json.dumps(res))
     else:
         print("id\t\t" + str(res["event"]["id"]))
         print("url\t\t" + res["event"]["url"])
         print("resource\t" + res["event"]["resource"])
         print("message\t\t" + res["event"]["text"].__repr__())
Exemplo n.º 39
0
 def _check(cls, args):
     api._timeout = args.timeout
     format = args.format
     if args.tags:
         tags = sorted(
             set([t.strip() for t in args.tags.split(",") if t.strip()]))
     else:
         tags = None
     res = api.ServiceCheck.check(
         check=args.check,
         host_name=args.host_name,
         status=int(args.status),
         timestamp=args.timestamp,
         message=args.message,
         tags=tags,
     )
     report_warnings(res)
     report_errors(res)
     if format == "pretty":
         print(pretty_json(res))
     else:
         print(json.dumps(res))
Exemplo n.º 40
0
    def _new_file(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.create(title=args.filename,
                                     description="Description for {0}".format(args.filename),
                                     graphs=[graphs])
        report_warnings(res)
        report_errors(res)

        cls._write_screen_to_file(res['id'], args.filename, args.timeout, format, args.string_ids)

        if format == 'pretty':
            print(pretty_json(res))
        else:
            print(json.dumps(res))
Exemplo n.º 41
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(cls._pretty_json(res))
            else:
                print(json.dumps(res))

            if args.format == 'pretty':
                print("Uploaded file {0} (screenboard {1})".format(
                    f.name, screen_obj["id"]))
Exemplo n.º 42
0
    def _show_all(cls, args):
        api._timeout = args.timeout
        format = args.format
        res = api.Monitor.get_all()
        report_warnings(res)
        report_errors(res)

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

        if format == 'pretty':
            print(cls._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"])]))
Exemplo n.º 43
0
    def _write_dash_to_file(cls, dash_id, filename, timeout, format="raw", string_ids=False):
        with open(filename, "w") as f:
            res = api.Timeboard.get(dash_id)
            report_warnings(res)
            report_errors(res)

            dash_obj = res["dash"]
            if "resource" in dash_obj:
                del dash_obj["resource"]
            if "url" in dash_obj:
                del dash_obj["url"]

            if string_ids:
                dash_obj["id"] = str(dash_obj["id"])

            if not dash_obj.get("template_variables"):
                dash_obj.pop("template_variables", None)

            json.dump(dash_obj, f, indent=2)

            if format == "pretty":
                print(u"Downloaded dashboard {0} to file {1}".format(dash_id, filename))
            else:
                print(u"{0} {1}".format(dash_id, filename))
Exemplo n.º 44
0
 def _post(cls, args):
     graphs = sys.stdin.read()
     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.create(
         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))
Exemplo n.º 45
0
 def _detach(cls, args):
     api._timeout = args.timeout
     res = api.Tag.delete(args.host)
     if res is not None:
         report_warnings(res)
         report_errors(res)
Exemplo n.º 46
0
 def _cancel_downtime(cls, args):
     api._timeout = args.timeout
     res = api.Downtime.delete(args.downtime_id)
     if res is not None:
         report_warnings(res)
         report_errors(res)
Exemplo n.º 47
0
 def _delete(cls, args):
     api._timeout = args.timeout
     res = api.Timeboard.delete(args.timeboard_id)
     if res is not None:
         report_warnings(res)
         report_errors(res)
Exemplo n.º 48
0
 def _unmute_all(cls, args):
     api._timeout = args.timeout
     res = api.Monitor.unmute_all()
     if res is not None:
         report_warnings(res)
         report_errors(res)