def main(): logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s', level=logging.INFO) parser = argparse.ArgumentParser() parser.add_argument('-p', '--path', required=True, nargs='+', type=str, help='List of path to YAML definition files') parser.add_argument('--project', help='(deprecated, use path) Location of the file containing project definition.') parser.add_argument('-o', '--out', help='(deprecated, use config file and file exporter) Path to output folder') parser.add_argument('-c', '--config', default='./.grafana/grafana_dashboards.yaml', help='Configuration file containing fine-tuned setup of builder\'s components.') parser.add_argument('--context', default='{}', help='YAML structure defining parameters for dashboard definition.' ' Effectively overrides any parameter defined on project level.') parser.add_argument('--plugins', nargs='+', type=str, help='List of external component plugins to load') parser.add_argument('--exporter', nargs='+', type=str, default=set(), dest='exporters', help='List of dashboard exporters') parser.add_argument('--message', required=False, type=str, help='Set a commit message for the Grafana version history') args = parser.parse_args() if args.plugins: for plugin in args.plugins: try: imp.load_source('grafana_dashboards.components.$loaded', plugin) except Exception as e: print('Cannot load plugin %s: %s' % (plugin, str(e))) if args.project: logging.warn("Using deprecated option '--project'") args.path.add(args.project) paths = _process_paths(args.path) config = Config(args.config) exporters = set(args.exporters) if args.out: logging.warn("Using deprecated option '-o/--out'") exporters.add('file') config.get_config('file').update(output_folder=args.out) if args.message: config.get_config('grafana').update(commit_message=args.message) dashboard_exporters = _initialize_exporters(exporters, [FileExporter, ElasticSearchExporter, GrafanaExporter], config) context = config.get_config('context') context.update(yaml.load(args.context, Loader=yaml.GDBLoader)) projects = DefinitionParser().load_projects(paths) project_processor = ProjectProcessor(dashboard_exporters) project_processor.process_projects(projects, context)
def main(): logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s', level=logging.INFO) parser = argparse.ArgumentParser() parser.add_argument('-p', '--path', required=True, nargs='+', type=str, help='List of path to YAML definition files') parser.add_argument('--project', help='(deprecated, use path) Location of the file containing project definition.') parser.add_argument('-o', '--out', help='(deprecated, use config file and file exporter) Path to output folder') parser.add_argument('-c', '--config', default='./.grafana/grafana_dashboards.yaml', help='Configuration file containing fine-tuned setup of builder\'s components.') parser.add_argument('--context', default='{}', help='YAML structure defining parameters for dashboard definition.' ' Effectively overrides any parameter defined on project level.') parser.add_argument('--plugins', nargs='+', type=str, help='List of external component plugins to load') parser.add_argument('--exporter', nargs='+', type=str, default=set(), dest='exporters', help='List of dashboard exporters') args = parser.parse_args() if args.plugins: for plugin in args.plugins: try: imp.load_source('grafana_dashboards.components.$loaded', plugin) except Exception as e: print('Cannot load plugin %s: %s' % (plugin, str(e))) if args.project: logging.warn("Using deprecated option '--project'") args.path.add(args.project) paths = _process_paths(args.path) config = Config(args.config) exporters = set(args.exporters) if args.out: logging.warn("Using deprecated option '-o/--out'") exporters.add('file') config.get_config('file').update(output_folder=args.out) dashboard_exporters = _initialize_exporters(exporters, [FileExporter, ElasticSearchExporter, GrafanaExporter], config) context = config.get_config('context') context.update(yaml.load(args.context)) projects = DefinitionParser().load_projects(paths) project_processor = ProjectProcessor(dashboard_exporters) project_processor.process_projects(projects, context)
def test_nonexistent_config_file(): config_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'no_file.yaml') config = Config(config_file) assert config.get_config('context') == {} assert config.get_config('unknown') == {}
def test_existent_config_file(): config_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'config.yaml') config = Config(config_file) assert config.get_config('context') == {'component': 'frontend'} assert config.get_config('unknown') == {}