How to use the grafanalib._gen.DashboardError function in grafanalib

To help you get started, we’ve selected a few grafanalib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github weaveworks / grafanalib / grafanalib / _gen.py View on Github external
def load_dashboard(path):
    """Load a ``Dashboard`` from a Python definition.

    :param str path: Path to a *.dashboard.py file that defines a variable,
        ``dashboard``.
    :return: A ``Dashboard``
    """
    module = imp.load_source("dashboard", path)
    marker = object()
    dashboard = getattr(module, 'dashboard', marker)
    if dashboard is marker:
        raise DashboardError(
            "Dashboard definition {} does not define 'dashboard'".format(path))
    return dashboard
github weaveworks / grafanalib / grafanalib / _gen.py View on Github external
def generate_dashboards(args):
    """Script for generating multiple dashboards at a time."""
    parser = argparse.ArgumentParser(prog='generate-dashboards')
    parser.add_argument(
        'dashboards', metavar='DASHBOARD', type=os.path.abspath,
        nargs='+', help='Path to dashboard definition',
    )
    opts = parser.parse_args(args)
    try:
        write_dashboards(opts.dashboards)
    except DashboardError as e:
        sys.stderr.write('ERROR: {}\n'.format(e))
        return 1
    return 0