Esempio n. 1
0
def main():
    """The main program sets up the commands then delegates to one of them."""
    all_command_handlers = []
    parser = argparse.ArgumentParser(
        description='Helper tool to interact with Spinnaker deployment metrics.'
    )
    add_global_args(parser)

    spectator_client.CONFIG_DIR = os.path.join(CONFIG_DIR)

    subparsers = parser.add_subparsers(title='commands', dest='command')
    spectator_handlers.add_handlers(all_command_handlers, subparsers)
    datadog_handlers.add_handlers(all_command_handlers, subparsers)
    stackdriver_handlers.add_handlers(all_command_handlers, subparsers)
    server_handlers.MonitorCommandHandler.register_metric_service_factory(
        prometheus_service.PrometheusServiceFactory())
    server_handlers.MonitorCommandHandler.register_metric_service_factory(
        datadog_service.DatadogServiceFactory())
    server_handlers.MonitorCommandHandler.register_metric_service_factory(
        stackdriver_service.StackdriverServiceFactory())
    server_handlers.add_handlers(all_command_handlers, subparsers)

    opts = parser.parse_args()
    options = vars(opts)
    init_logging(options)
    options = util.merge_options_and_yaml_from_path(
        options, os.path.join(opts.config_dir, 'spinnaker-monitoring.conf'))

    command_processor.process_command(options['command'], options,
                                      all_command_handlers)
def main():
    """The main program sets up the commands then delegates to one of them."""

    disable_ssl_verification()

    all_command_handlers, parser = prepare_commands()
    opts = parser.parse_args()
    options = vars(opts)
    init_logging(options)
    options = util.merge_options_and_yaml_from_path(options, opts.config)

    # TODO(ewiseblatt): decouple this so we dont need to know about this here.
    # Take the union of stores enabled on the command line or in the config file.
    if options.get('monitor') is None:
        options['monitor'] = {}
    stores = options['monitor'].get('metric_store', [])
    if not isinstance(stores, list):
        stores = [stores]
    stores.extend([
        store for store in ['datadog', 'prometheus', 'stackdriver']
        if options.get('monitor_' + store)
    ])
    options['monitor']['metric_store'] = set(stores)

    command_processor.set_global_options(options)
    command_processor.process_command(options['command'], options,
                                      all_command_handlers)
    def test_process_command(self):
        mock_a = mock.Mock()
        mock_a.command_name = 'CommandA'
        mock_a.process_commandline_request = mock.Mock()
        mock_b = mock.Mock()
        mock_b.command_name = 'CommandB'
        mock_b.process_commandline_request = mock.Mock()
        registry = [mock_a, mock_b]
        options = {}

        command_processor.process_command('CommandB', options, registry)
        self.assertEquals(0, mock_a.process_commandline_request.call_count)
        self.assertEquals(1, mock_b.process_commandline_request.call_count)
        mock_b.process_commandline_request.assert_called_with(options)
Esempio n. 4
0
def main():
  """The main program sets up the commands then delegates to one of them."""
  all_command_handlers = []
  parser = argparse.ArgumentParser(
      description='Helper tool to interact with Spinnaker deployment metrics.')
  add_global_args(parser)

  subparsers = parser.add_subparsers(title='commands', dest='command')
  server_handlers.add_handlers(all_command_handlers, subparsers)
  spectator_handlers.add_handlers(all_command_handlers, subparsers)
  stackdriver_handlers.add_handlers(all_command_handlers, subparsers)
  datadog_handlers.add_handlers(all_command_handlers, subparsers)

  opts = parser.parse_args()
  options = vars(opts)

  init_logging(options)

  command_processor.process_command(
      options['command'], options, all_command_handlers)
Esempio n. 5
0
def main():
    """The main program sets up the commands then delegates to one of them."""
    all_command_handlers = []
    parser = argparse.ArgumentParser(
        description='Helper tool to interact with Spinnaker deployment metrics.'
    )
    add_global_args(parser)

    subparsers = parser.add_subparsers(title='commands', dest='command')
    server_handlers.add_handlers(all_command_handlers, subparsers)
    spectator_handlers.add_handlers(all_command_handlers, subparsers)
    stackdriver_handlers.add_handlers(all_command_handlers, subparsers)
    datadog_handlers.add_handlers(all_command_handlers, subparsers)

    opts = parser.parse_args()
    options = vars(opts)

    init_logging(options)

    command_processor.process_command(options['command'], options,
                                      all_command_handlers)
 def test_process_command_not_found(self):
     mock_a = mock.Mock()
     mock_a.command_name = 'CommandA'
     with self.assertRaises(ValueError):
         command_processor.process_command('CommandB', {}, [mock_a])
Esempio n. 7
0
def proccess_command(cmd_msg):
    print('* {}: {}, {}'.format(cmd_msg.message_id, cmd_msg.data,
                                cmd_msg.attributes))
    Thread(target=command_processor.process_command(cmd_msg.data)).start()
    return True
Esempio n. 8
0
    (retcode, data) = mailbox.fetch(id, "(RFC822)")

    # Fetch email string for parser
    raw_email = data[0][1].decode()

    # Construct Message object from raw_message
    m = Message(raw_email)

    # Process command email
    if m.subject == "COMMAND_EMAIL_SUBJECT":
        # process command
        print("Subject:", m.subject)
        print("Sender:", "{} <{}>".format(m.sender[0], m.sender[1]))
        print("Executing commands", end='')
        sys.stdout.flush()
        reply = process_command(m.text)
        print(" -- done")
        print(reply)

        # reply message
        print("Sending reply", end='')
        sys.stdout.flush()
        send_reply(sendbox, m, reply)
        print(" -- done")

        # Mark as read
        print("Set command email as SEEN", end='')
        sys.stdout.flush()
        (retcode, data) = mailbox.uid("STORE", id, "+FLAGS", "(\\Seen)")
        print(" --", retcode, [d.decode() for d in data])
        print()
Esempio n. 9
0
def main():
    init_logging('metric_collector.log')
    options = get_options()

    spectator = spectator_client.SpectatorClient(options)
    try:
        stackdriver = stackdriver_client.StackdriverClient.make_client(options)
    except IOError as ioerror:
        logging.error(
            'Could not create stackdriver client'
            ' -- Stackdriver will be unavailable\n%s', ioerror)
        stackdriver = None

    registry = []
    registry.extend([
        CommandDefinition(handlers.BaseHandler(options, registry), '/', 'Home',
                          CommandRequest(options=options),
                          'Home page for Spinnaker metric administration.'),
        CommandDefinition(
            stackdriver_handlers.ClearCustomDescriptorsHandler(
                options,
                stackdriver), '/stackdriver/clear_descriptors', 'clear',
            CommandRequest(options=options),
            'Clear all the Stackdriver Custom Metrics'),
        CommandDefinition(
            stackdriver_handlers.ListCustomDescriptorsHandler(
                options, stackdriver), '/stackdriver/list_descriptors', 'list',
            CommandRequest(content_type='application/json', options=options),
            'Get the JSON of all the Stackdriver Custom Metric Descriptors.'),
        CommandDefinition(
            handlers.DumpMetricsHandler(options, spectator), '/dump', 'dump',
            CommandRequest(options=options),
            'Show current raw metric JSON from all the servers.'),
        CommandDefinition(
            handlers.ExploreCustomDescriptorsHandler(options, spectator),
            '/explore',
            'explore',
            CommandRequest(options=options),
            'Explore metric type usage across Spinnaker microservices.',
        ),
        CommandDefinition(
            handlers.ShowCurrentMetricsHandler(options,
                                               spectator), '/show', 'show',
            CommandRequest(options=options),
            'Show current metric JSON for all Spinnaker.'),
    ])

    if options.command:
        command_processor.process_command(options.command, registry)
        return

    if options.monitor:
        logging.info('Starting Monitor every %d s', options.period)

        # TODO: Replace this with a real service.
        metric_service = DummyMetricService()

        monitor = Monitor(spectator, metric_service, options)
        threading.Thread(target=monitor, name='monitor').start()

    logging.info('Starting HTTP server on port %d', options.port)
    url_path_to_handler = {entry.url_path: entry.handler for entry in registry}
    httpd = HttpServer(options.port, url_path_to_handler)
    httpd.serve_forever()
    sys.exit(-1)
Esempio n. 10
0
    (retcode, data) = mailbox.fetch(id, "(RFC822)")

    # Fetch email string for parser
    raw_email = data[0][1].decode()

    # Construct Message object from raw_message
    m = Message(raw_email)

    # Process command email
    if m.subject == "COMMAND_EMAIL_SUBJECT":
        # process command
        print("Subject:", m.subject)
        print("Sender:", "{} <{}>".format(m.sender[0], m.sender[1]))
        print("Executing commands", end='')
        sys.stdout.flush()
        reply = process_command(m.text)
        print(" -- done")
        print(reply)

        # reply message
        print("Sending reply", end='')
        sys.stdout.flush()
        send_reply(sendbox, m, reply)
        print(" -- done")

        # Mark as read
        print("Set command email as SEEN", end='')
        sys.stdout.flush()
        (retcode, data) = mailbox.uid("STORE", id, "+FLAGS", "(\\Seen)")
        print(" --", retcode, [d.decode() for d in data])
        print()
Esempio n. 11
0
def main():
    init_logging('metric_collector.log')
    options = vars(get_options())

    spectator = spectator_client.SpectatorClient(options)
    try:
        stackdriver = StackdriverMetricsService.make_service(options)

    except IOError as ioerror:
        logging.error(
            'Could not create stackdriver client'
            ' -- Stackdriver will be unavailable\n%s', ioerror)
        stackdriver = None

    registry = []
    registry.extend([
        CommandDefinition(handlers.BaseHandler(options, registry), '/', 'Home',
                          CommandRequest(options=options),
                          'Home page for Spinnaker metric administration.'),
        CommandDefinition(
            stackdriver_handlers.ClearCustomDescriptorsHandler(
                options,
                stackdriver), '/stackdriver/clear_descriptors', 'clear',
            CommandRequest(options=options),
            'Clear all the Stackdriver Custom Metrics'),
        CommandDefinition(
            stackdriver_handlers.ListCustomDescriptorsHandler(
                options, stackdriver), '/stackdriver/list_descriptors', 'list',
            CommandRequest(content_type='application/json', options=options),
            'Get the JSON of all the Stackdriver Custom Metric Descriptors.'),
        CommandDefinition(
            stackdriver_handlers.UpsertCustomDescriptorsHandler(
                options, stackdriver), None, 'upsert_descriptors',
            CommandRequest(options=options),
            'Given a file of Stackdriver Custom Metric Desciptors,'
            ' update the existing ones and add the new ones.'
            ' WARNING: Historic time-series data may be lost on update.'),
        CommandDefinition(
            handlers.DumpMetricsHandler(options, spectator), '/dump', 'dump',
            CommandRequest(options=options),
            'Show current raw metric JSON from all the servers.'),
        CommandDefinition(
            handlers.ExploreCustomDescriptorsHandler(options, spectator),
            '/explore',
            'explore',
            CommandRequest(options=options),
            'Explore metric type usage across Spinnaker microservices.',
        ),
        CommandDefinition(
            handlers.ShowCurrentMetricsHandler(options,
                                               spectator), '/show', 'show',
            CommandRequest(options=options),
            'Show current metric JSON for all Spinnaker.'),
    ])

    if options.get('command', None):
        command_processor.process_command(options['command'], registry)
        return

    if options.get('monitor', None):
        logging.info('Starting Monitor every %d s', options['period'])

        metric_service = stackdriver

        monitor = Monitor(spectator, metric_service, options)
        threading.Thread(target=monitor, name='monitor').start()

    logging.info('Starting HTTP server on port %d', options['port'])
    url_path_to_handler = {entry.url_path: entry.handler for entry in registry}
    httpd = HttpServer(options['port'], url_path_to_handler)
    httpd.serve_forever()
    sys.exit(-1)
Esempio n. 12
0
def main():
  init_logging('metric_collector.log')
  options = get_options()

  spectator = spectator_client.SpectatorClient(options)
  try:
    stackdriver = stackdriver_client.StackdriverClient.make_client(options)
  except IOError as ioerror:
    logging.error('Could not create stackdriver client'
                  ' -- Stackdriver will be unavailable\n%s',
                  ioerror)
    stackdriver = None

  registry = []
  registry.extend([
      CommandDefinition(
          handlers.BaseHandler(options, registry),
          '/',
          'Home',
          CommandRequest(options=options),
          'Home page for Spinnaker metric administration.'),
      CommandDefinition(
          stackdriver_handlers.ClearCustomDescriptorsHandler(
              options, stackdriver),
          '/stackdriver/clear_descriptors',
          'clear',
          CommandRequest(options=options),
          'Clear all the Stackdriver Custom Metrics'),
      CommandDefinition(
          stackdriver_handlers.ListCustomDescriptorsHandler(
              options, stackdriver),
          '/stackdriver/list_descriptors',
          'list',
          CommandRequest(content_type='application/json', options=options),
          'Get the JSON of all the Stackdriver Custom Metric Descriptors.'
          ),

      CommandDefinition(
          handlers.DumpMetricsHandler(options, spectator),
          '/dump',
          'dump',
          CommandRequest(options=options),
          'Show current raw metric JSON from all the servers.'),
      CommandDefinition(
          handlers.ExploreCustomDescriptorsHandler(options, spectator),
          '/explore',
          'explore',
          CommandRequest(options=options),
          'Explore metric type usage across Spinnaker microservices.',
          ),
      CommandDefinition(
          handlers.ShowCurrentMetricsHandler(options, spectator),
          '/show',
          'show',
          CommandRequest(options=options),
          'Show current metric JSON for all Spinnaker.'
          ),
      ])

  if options.command:
    command_processor.process_command(options.command, registry)
    return

  if options.monitor:
    logging.info('Starting Monitor every %d s', options.period)

    # TODO: Replace this with a real service.
    metric_service = DummyMetricService()

    monitor = Monitor(spectator, metric_service, options)
    threading.Thread(target=monitor, name='monitor').start()

  logging.info('Starting HTTP server on port %d', options.port)
  url_path_to_handler = {entry.url_path: entry.handler for entry in registry}
  httpd = HttpServer(options.port, url_path_to_handler)
  httpd.serve_forever()
  sys.exit(-1)