Ejemplo n.º 1
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"]))
Ejemplo n.º 2
0
    def _push(cls, args):
        api._timeout = args.timeout
        for f in args.file:
            screen_obj = json.load(f)

            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"]))
Ejemplo n.º 3
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"]))
Ejemplo n.º 4
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"]))
Ejemplo n.º 5
0
    def _update(cls, args):
        api._timeout = args.timeout
        format = args.format

        to_update = {}
        if args.type:
            if args.type_opt:
                msg = 'Duplicate arguments for `type`. Using optional value --type'
                print_err("WARNING: {}".format(msg))
            else:
                to_update['type'] = args.type
            msg = "[DEPRECATION] `type` is no longer required to `update` and may be omitted"
            print_err("WARNING: {}".format(msg))
        if args.query:
            if args.query_opt:
                msg = 'Duplicate arguments for `query`. Using optional value --query'
                print_err("WARNING: {}".format(msg))
            else:
                to_update['query'] = args.query
            msg = "[DEPRECATION] `query` is no longer required to `update` and may be omitted"
            print_err("WARNING: {}".format(msg))
        if args.name:
            to_update['name'] = args.name
        if args.message:
            to_update['message'] = args.message
        if args.type_opt:
            to_update['type'] = args.type_opt
        if args.query_opt:
            to_update['query'] = args.query_opt

        if args.options is not None:
            to_update['options'] = json.loads(args.options)

        res = api.Monitor.update(args.monitor_id, **to_update)

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