示例#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"]))
示例#2
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"]))
示例#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"]))
示例#4
0
 def _web_view(cls, args):
     dash_id = json.load(args.file)['id']
     url = api._api_host + "/dash/dash/{0}".format(dash_id)
     webbrowser.open(url)
示例#5
0
 def _web_view(cls, args):
     dash_id = json.load(args.file)['id']
     url = api._api_host + "/dash/dash/{0}".format(dash_id)
     webbrowser.open(url)