コード例 #1
0
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') == {}
コード例 #2
0
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') == {}
コード例 #3
0
 def read_config(self):
     self.config = Config()
     if self.args.config:
         fp = self.args.config
     else:
         fp = '/etc/grafyaml/grafyaml.conf'
     self.config.read(os.path.expanduser(fp))
コード例 #4
0
def test_initialize_exporters():
    config_file = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                               'config.yaml')
    config = Config(config_file)
    # noinspection PyProtectedMember
    exporters = cli._initialize_exporters('dummy', [DummyExporter], config)

    assert exporters is not None
    assert len(exporters) == 1
    assert exporters[0].prop == 'value'
    assert exporters[0].kwargs == {'other': True}
コード例 #5
0
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)
コード例 #6
0
 def read_config(self):
     self.config = Config()
     if self.args.config:
         fp = self.args.config
     else:
         fp = '/etc/grafyaml/grafyaml.conf'
     self.config.read(os.path.expanduser(fp))
     if self.args.grafana_url:
         self.config.set('grafana', 'url', self.args.grafana_url)
         LOG.debug('Grafana URL override: {}'.format(self.args.grafana_url))
     if self.args.grafana_apikey:
         self.config.set('grafana', 'apikey', self.args.grafana_apikey)
         LOG.debug('Grafana APIKey overridden')
コード例 #7
0
ファイル: cmd.py プロジェクト: sassyn/grafyaml
 def read_config(self):
     self.config = Config()
     if self.args.config:
         fp = self.args.config
     else:
         fp = "/etc/grafyaml/grafyaml.conf"
     self.config.read(os.path.expanduser(fp))
     if self.args.grafana_url:
         self.config.set("grafana", "url", self.args.grafana_url)
         LOG.debug("Grafana URL override: {}".format(self.args.grafana_url))
     if self.args.grafana_apikey:
         self.config.set("grafana", "apikey", self.args.grafana_apikey)
         LOG.debug("Grafana APIKey overridden")
     if self.args.grafana_folderid:
         self.config.set("grafana", "folderid", self.args.grafana_folderid)
         LOG.debug("Grafana Folderid overridden")
コード例 #8
0
ファイル: test_config.py プロジェクト: sassyn/grafyaml
 def setUp(self):
     super(TestCaseConfig, self).setUp()
     self.config = Config()
コード例 #9
0
ファイル: base.py プロジェクト: pombredanne/grafyaml
 def setup_config(self):
     self.config = Config()
     self.config.read(os.path.join(FIXTURE_DIR, 'grafyaml.conf'))