Ejemplo n.º 1
0
def test_load_config_multiple_times():
    """
    This used to crash because of pop() operations
    """
    cfg = {'logger': 'addons-marketplace-dev',
           'stream': {'class': 'heka.streams.UdpStream',
                      'host': ['logstash1', 'logstash2'],
                      'port': '5566'},
           }

    client_from_dict_config(cfg)
    client_from_dict_config(cfg)
Ejemplo n.º 2
0
def test_load_config_multiple_times():
    """
    This used to crash because of pop() operations
    """
    cfg = {
        'logger': 'addons-marketplace-dev',
        'stream': {
            'class': 'heka.streams.UdpStream',
            'host': ['logstash1', 'logstash2'],
            'port': '5566'
        },
    }

    client_from_dict_config(cfg)
    client_from_dict_config(cfg)
Ejemplo n.º 3
0
    def setUp(self):
        """
        This is not entirely obvious.

        settings.SENTRY_CLIENT :
            * This is the classname of the object that
              raven.contrib.django.models.get_client() will return.

              The sentry client is a subclass of raven.base.Client.

              This is the control point that all messages are going
              to get routed through

              For heka integration, this *must* be
              'raven_heka.djangoheka.HekaDjangoClient'

        settings.HEKA_CONF :
            * configuration for the heka client instance

        settings.HEKA :
            * This is the actual heka client instance
        """

        self.HEKA_CONF = {
                'stream_class': 'heka.streams.DebugCaptureStream',
                'plugins': {'raven':
                    ('heka_raven.raven_plugin:config_plugin', {'dsn':
                        DSN})
                    },
        }

        self.SENTRY_CLIENT = 'djangoraven.heka.HekaDjangoClient'

        from heka.config import client_from_dict_config
        self.HEKA = client_from_dict_config(self.HEKA_CONF)
Ejemplo n.º 4
0
def get_client(name, config_dict=None):
    """Return client of the specified name from the CLIENT_HOLDER.

    :param name: String token to identify the HekaClient, also used for
                 the default `logger` value of that client.
                 `ValueError` will be raised if a config is provided
                 w/ a different `logger` value.

                 If name isn't specified, the default client will be
                 returned if one exists
    :param config_dict: Configuration dictionary to be applied to the
                        fetched client.

    """
    client = CLIENT_HOLDER.get_client(name)

    if config_dict:
        logger = config_dict.get('logger')
        if logger and logger != name:
            raise ValueError('Config `logger` value must either match `name` '
                             'argument or be left blank.')
        if not logger:
            config_dict['logger'] = name
        client = client_from_dict_config(config_dict, client=client)
    return client
Ejemplo n.º 5
0
def mb():
    arguments = docopt(mb_doc)
    host = arguments.get('HOST')
    port = int(arguments.get('PORT'))

    DEFAULT_CONFIG = {'logger': 'mb',
                      'sender': {'class': 'heka.senders.udp.UdpSender',
                                 'args': (host, port),
                                 },
                      }

    if arguments.get('--raw'):
        udpsock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        utcnow = datetime.utcnow()
        if utcnow.microsecond == 0:
            timestamp = "%s.000000Z" % utcnow.isoformat()
        else:
            timestamp = "%sZ" % utcnow.isoformat()
        msg = {"severity": 6, "timestamp": timestamp,
               "heka_hostname": "spire",
               "fields": {"userid": 25, "req_time": 4}, "heka_pid": 34328,
               "logger": "syncstorage", "type": "services", "payload": "foo",
               "env_version": "0.8"}
        json_msg = json.dumps(msg)
        while True:
            udpsock.sendto(json_msg, (host, port))

    if arguments.get('--hekacfg'):
        with open(arguments['--hekacfg']) as cfgfile:
            client = client_from_stream_config(cfgfile, 'heka')
    else:
        client = client_from_dict_config(DEFAULT_CONFIG)

    while True:
        client.heka('MBTEST', payload='MBTEST')
def get_client(name, config_dict=None):
    """Return client of the specified name from the CLIENT_HOLDER.

    :param name: String token to identify the HekaClient, also used for
                 the default `logger` value of that client.
                 `ValueError` will be raised if a config is provided
                 w/ a different `logger` value.

                 If name isn't specified, the default client will be
                 returned if one exists
    :param config_dict: Configuration dictionary to be applied to the
                        fetched client.

    """
    client = CLIENT_HOLDER.get_client(name)

    if config_dict:
        logger = config_dict.get('logger')
        if logger and logger != name:
            raise ValueError('Config `logger` value must either match `name` '
                             'argument or be left blank.')
        if not logger:
            config_dict['logger'] = name
        client = client_from_dict_config(config_dict, client=client)
    return client
Ejemplo n.º 7
0
    def setUp(self):
        self.orig_default_client = CLIENT_HOLDER._default_clientname
        client = CLIENT_HOLDER.get_client(self.client_name)
        client_config = {'stream_class': 'heka.streams.DebugCaptureStream'}

        self.client = client_from_dict_config(client_config, client)
        self.stream = self.client.stream

        CLIENT_HOLDER.set_default_client_name(self.client_name)
Ejemplo n.º 8
0
    def setUp(self):
        self.orig_default_client = CLIENT_HOLDER._default_clientname
        client = CLIENT_HOLDER.get_client(self.client_name)
        client_config = {'stream_class': 'heka.streams.DebugCaptureStream'}

        self.client = client_from_dict_config(client_config, client)
        self.stream = self.client.stream

        CLIENT_HOLDER.set_default_client_name(self.client_name)
Ejemplo n.º 9
0
def test_clients_expose_configuration():
    cfg = {'logger': 'addons-marketplace-dev',
           'stream': {'class': 'heka.streams.UdpStream',
                      'host': ['logstash1', 'logstash2'],
                      'port': '5566'},
           }

    client = client_from_dict_config(cfg)
    eq_(client._config, json.dumps(cfg))
Ejemplo n.º 10
0
    def setUp(self):
        client = CLIENT_HOLDER.get_client(self.client_name)

        client_config = {'stream_class': 'heka.senders.DebugCaptureSender',
                'plugins': {'plugin_section_name':
                    ('heka_raven.raven_plugin:config_plugin',
                        {'dsn': 'udp://*****:*****@somehost.com:5000/2'})}
                    }
        self.client = client_from_dict_config(client_config, client)
        CLIENT_HOLDER.set_default_client_name(self.client_name)
Ejemplo n.º 11
0
    def setUp(self):
        self.dsn = "udp://*****:*****@somehost.com:9000/2"
        client = CLIENT_HOLDER.get_client(self.client_name)

        client_config = {'stream_class': 'heka.senders.DebugCaptureSender',
                'plugins': {'plugin_section_name':
                    ['heka_raven.raven_plugin:config_plugin',
                        {'dsn': self.dsn}]
                    }}
        self.client = client_from_dict_config(client_config, client)
        CLIENT_HOLDER.set_default_client_name(self.client_name)
Ejemplo n.º 12
0
def test_clients_expose_configuration():
    cfg = {
        'logger': 'addons-marketplace-dev',
        'stream': {
            'class': 'heka.streams.UdpStream',
            'host': ['logstash1', 'logstash2'],
            'port': '5566'
        },
    }

    client = client_from_dict_config(cfg)
    eq_(client._config, json.dumps(cfg))
Ejemplo n.º 13
0
 def setUp(self):
     self.client.login(username='******', password='******')
     heka = settings.HEKA
     HEKA_CONF = {
         'logger': 'zamboni',
         'plugins': {'cef': ('heka_cef.cef_plugin:config_plugin',
                             {'override': True})},
         'stream': {'class': 'heka.streams.DebugCaptureStream'},
         'encoder': 'heka.encoders.NullEncoder',
     }
     from heka.config import client_from_dict_config
     self.heka = client_from_dict_config(HEKA_CONF, heka)
     self.heka.stream.msgs.clear()
Ejemplo n.º 14
0
 def setUp(self):
     self.client.login(username='******', password='******')
     heka = settings.HEKA
     HEKA_CONF = {
         'logger': 'zamboni',
         'plugins': {'cef': ('heka_cef.cef_plugin:config_plugin',
                             {'override': True})},
         'stream': {'class': 'heka.streams.DebugCaptureStream'},
         'encoder': 'heka.encoders.NullEncoder',
     }
     from heka.config import client_from_dict_config
     self.heka = client_from_dict_config(HEKA_CONF, heka)
     self.heka.stream.msgs.clear()
Ejemplo n.º 15
0
    def setUp(self):
        """
        We need to set the settings.HEKA instance to use a
        DebugCaptureStream so that we can inspect the sent messages.
        """

        heka = settings.HEKA
        HEKA_CONF = {
            'logger': 'zamboni',
            'stream': {'class': 'heka.streams.DebugCaptureStream'},
            'encoder': 'heka.encoders.NullEncoder'
        }
        from heka.config import client_from_dict_config
        self.heka = client_from_dict_config(HEKA_CONF, heka)
Ejemplo n.º 16
0
    def setUp(self):
        client = CLIENT_HOLDER.get_client(self.client_name)

        client_config = {
            'stream_class': 'heka.senders.DebugCaptureSender',
            'plugins': {
                'plugin_section_name':
                ('heka_raven.raven_plugin:config_plugin', {
                    'dsn': 'udp://*****:*****@somehost.com:5000/2'
                })
            }
        }
        self.client = client_from_dict_config(client_config, client)
        CLIENT_HOLDER.set_default_client_name(self.client_name)
Ejemplo n.º 17
0
    def setUp(self):
        self.dsn = "udp://*****:*****@somehost.com:9000/2"
        client = CLIENT_HOLDER.get_client(self.client_name)

        client_config = {
            'stream_class': 'heka.senders.DebugCaptureSender',
            'plugins': {
                'plugin_section_name':
                ['heka_raven.raven_plugin:config_plugin', {
                    'dsn': self.dsn
                }]
            }
        }
        self.client = client_from_dict_config(client_config, client)
        CLIENT_HOLDER.set_default_client_name(self.client_name)
Ejemplo n.º 18
0
def mb():
    arguments = docopt(mb_doc)
    host = arguments.get('HOST')
    port = int(arguments.get('PORT'))

    DEFAULT_CONFIG = {
        'logger': 'mb',
        'sender': {
            'class': 'heka.senders.udp.UdpSender',
            'args': (host, port),
        },
    }

    if arguments.get('--raw'):
        udpsock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        utcnow = datetime.utcnow()
        if utcnow.microsecond == 0:
            timestamp = "%s.000000Z" % utcnow.isoformat()
        else:
            timestamp = "%sZ" % utcnow.isoformat()
        msg = {
            "severity": 6,
            "timestamp": timestamp,
            "heka_hostname": "spire",
            "fields": {
                "userid": 25,
                "req_time": 4
            },
            "heka_pid": 34328,
            "logger": "syncstorage",
            "type": "services",
            "payload": "foo",
            "env_version": "0.8"
        }
        json_msg = json.dumps(msg)
        while True:
            udpsock.sendto(json_msg, (host, port))

    if arguments.get('--hekacfg'):
        with open(arguments['--hekacfg']) as cfgfile:
            client = client_from_stream_config(cfgfile, 'heka')
    else:
        client = client_from_dict_config(DEFAULT_CONFIG)

    while True:
        client.heka('MBTEST', payload='MBTEST')
Ejemplo n.º 19
0
    def setUp(self):
        HEKA_CONF = {
            'encoder': 'heka.encoders.StdlibPayloadEncoder',
            'stream': {
                'class': 'heka.streams.logging.StdLibLoggingStream',
                'logger_name': 'z.heka'}}
        self.heka = client_from_dict_config(HEKA_CONF)
        self.logger = logging.getLogger('z.heka')

        """
        When logging.config.dictConfig is used to configure logging
        with a 'one-shot' config dictionary, any previously
        instantiated singleton loggers (ie: all old loggers not in
        the new config) will be explicitly disabled.
        """
        self.logger.disabled = False

        self._orig_handlers = self.logger.handlers
        self.handler = logging.handlers.BufferingHandler(65536)
        self.logger.handlers = [self.handler]
Ejemplo n.º 20
0
    def setUp(self):
        super(TestHekaStdLibLogging, self).setUp()
        HEKA_CONF = {
            'encoder': 'heka.encoders.StdlibPayloadEncoder',
            'stream': {
                'class': 'heka.streams.logging.StdLibLoggingStream',
                'logger_name': 'z.heka'}}
        self.heka = client_from_dict_config(HEKA_CONF)
        self.logger = logging.getLogger('z.heka')

        """
        When logging.config.dictConfig is used to configure logging
        with a 'one-shot' config dictionary, any previously
        instantiated singleton loggers (ie: all old loggers not in
        the new config) will be explicitly disabled.
        """
        self.logger.disabled = False

        self._orig_handlers = self.logger.handlers
        self.handler = logging.handlers.BufferingHandler(65536)
        self.logger.handlers = [self.handler]
    def setUp(self):
        """
        This is not entirely obvious.

        settings.SENTRY_CLIENT :
            * This is the classname of the object that
              raven.contrib.django.models.get_client() will return.

              The sentry client is a subclass of raven.base.Client.

              This is the control point that all messages are going
              to get routed through

              For heka integration, this *must* be
              'raven_heka.djangoheka.HekaDjangoClient'

        settings.HEKA_CONF :
            * configuration for the heka client instance

        settings.HEKA :
            * This is the actual heka client instance
        """

        self.HEKA_CONF = {
            'stream_class': 'heka.streams.DebugCaptureStream',
            'plugins': {
                'raven': ('heka_raven.raven_plugin:config_plugin', {
                    'dsn': DSN
                })
            },
        }

        self.SENTRY_CLIENT = 'djangoraven.heka.HekaDjangoClient'

        from heka.config import client_from_dict_config
        self.HEKA = client_from_dict_config(self.HEKA_CONF)
Ejemplo n.º 22
0
        # Sentry accepts messages over UDP, you'll need to
        # configure this URL so that logstash can relay the message
        # properly
        'raven': ('heka_raven.raven_plugin:config_plugin', {
            'dsn': 'udp://*****:*****@127.0.0.1:9000/2'
        }),
    },
    'stream': {
        'class': 'heka.streams.UdpStream',
        'host': '127.0.0.1',
        'port': 5565,
    },
}

HEKA = client_from_dict_config(HEKA_CONF)

# Not shown on the site, but .po files exist and these are available on the
# L10n dashboard.  Generally languages start here and move into AMO_LANGUAGES.
# This list also enables translation edits.
HIDDEN_LANGUAGES = (
    # List of languages from AMO's settings (excluding mkt's active locales).
    'af', 'ar', 'fa', 'fi', 'he', 'id', 'mn', 'pt-PT', 'sl', 'sv-SE',
    'uk', 'vi',
    # The hidden list from AMO's settings:
    'cy',
)

# IARC content ratings.
IARC_ALLOW_CERT_REUSE = True
Ejemplo n.º 23
0
            }),

        # Sentry accepts messages over UDP, you'll need to
        # configure this URL so that logstash can relay the message
        # properly
        'raven': ('heka_raven.raven_plugin:config_plugin',
            {'dsn': 'udp://*****:*****@127.0.0.1:9000/2'}),
        },
    'stream': {
        'class': 'heka.streams.UdpStream',
        'host': '127.0.0.1',
        'port': 5565,
    },
}

HEKA = client_from_dict_config(HEKA_CONF)

USE_HEKA_FOR_CEF = False
USE_HEKA_FOR_TASTYPIE = False

CEF_PRODUCT = "amo"

# CSP Settings
CSP_REPORT_URI = '/services/csp/report'
CSP_REPORT_ONLY = True

CSP_DEFAULT_SRC = ("*", "data:")
CSP_SCRIPT_SRC = ("'self'",
                  "https://www.google.com",  # Recaptcha
                  "https://mozorg.cdn.mozilla.net",  # Tabzilla.
                  "https://www.paypalobjects.com",