Exemplo n.º 1
0
def log_cef(msg, request, **kw):
    g = functools.partial(getattr, settings)
    severity = kw.pop('severity', g('CEF_DEFAULT_SEVERITY', 5))
    cef_kw = {
        'msg': msg,
        'signature': request.get_full_path(),
        'config': {
            'cef.product': 'Solitude',
            'cef.vendor': g('CEF_VENDOR', 'Mozilla'),
            'cef.version': g('CEF_VERSION', '0'),
            'cef.device_version': g('CEF_DEVICE_VERSION', '0'),
            'cef.file': g('CEF_FILE', 'syslog'),
        }
    }

    if severity > 2:
        # Only send more severe logging to syslog. Messages lower than that
        # could be every http request, etc.
        sys_cef_log.error('CEF Severity: {sev} Message: {msg}'
                          .format(sev=severity, msg=msg))

    # Allow the passing of additional cs* values.
    for k, v in kw.items():
        if k.startswith('cs'):
            cef_kw[k] = v

    _log_cef(msg, severity, request.META.copy(), **cef_kw)
Exemplo n.º 2
0
def log_cef(msg, request, **kw):
    g = functools.partial(getattr, settings)
    severity = kw.pop('severity', g('CEF_DEFAULT_SEVERITY', 5))
    cef_kw = {
        'msg': msg,
        'signature': request.get_full_path(),
        'config': {
            'cef.product': 'Solitude',
            'cef.vendor': g('CEF_VENDOR', 'Mozilla'),
            'cef.version': g('CEF_VERSION', '0'),
            'cef.device_version': g('CEF_DEVICE_VERSION', '0'),
            'cef.file': g('CEF_FILE', 'syslog'),
        }
    }

    if severity > 2:
        # Only send more severe logging to syslog. Messages lower than that
        # could be every http request, etc.
        sys_cef_log.error('CEF Severity: {sev} Message: {msg}'.format(
            sev=severity, msg=msg))

    # Allow the passing of additional cs* values.
    for k, v in kw.items():
        if k.startswith('cs'):
            cef_kw[k] = v

    _log_cef(msg, severity, request.META.copy(), **cef_kw)
Exemplo n.º 3
0
def log_cef(msg, request, **kw):
    g = functools.partial(getattr, settings)
    severity = kw.pop("severity", g("CEF_DEFAULT_SEVERITY", 5))
    cef_kw = {
        "msg": msg,
        "signature": request.get_full_path(),
        "config": {
            "cef.product": "Solitude",
            "cef.vendor": g("CEF_VENDOR", "Mozilla"),
            "cef.version": g("CEF_VERSION", "0"),
            "cef.device_version": g("CEF_DEVICE_VERSION", "0"),
            "cef.file": g("CEF_FILE", "syslog"),
        },
    }

    if severity > 2:
        # Only send more severe logging to syslog. Messages lower than that
        # could be every http request, etc.
        sys_cef_log.error("CEF Severity: {sev} Message: {msg}".format(sev=severity, msg=msg))

    # Allow the passing of additional cs* values.
    for k, v in kw.items():
        if k.startswith("cs"):
            cef_kw[k] = v

    _log_cef(msg, severity, request.META.copy(), **cef_kw)
Exemplo n.º 4
0
def log_cef(msg, request, **kw):
    g = functools.partial(getattr, settings)
    severity = kw.get('severity', g('CEF_DEFAULT_SEVERITY', 5))
    cef_kw = {'msg': msg, 'signature': request.get_full_path(),
            'config': {
                'cef.product': 'Solitude',
                'cef.vendor': g('CEF_VENDOR', 'Mozilla'),
                'cef.version': g('CEF_VERSION', '0'),
                'cef.device_version': g('CEF_DEVICE_VERSION', '0'),
                'cef.file': g('CEF_FILE', 'syslog'),
            }
        }
    _log_cef(msg, severity, request.META.copy(), **cef_kw)
Exemplo n.º 5
0
def log_cef(msg, request, **kw):
    g = functools.partial(getattr, settings)
    severity = kw.get('severity', g('CEF_DEFAULT_SEVERITY', 5))
    cef_kw = {
        'msg': msg,
        'signature': request.get_full_path(),
        'config': {
            'cef.product': 'WebPay',
            'cef.vendor': g('CEF_VENDOR', 'Mozilla'),
            'cef.version': g('CEF_VERSION', '0'),
            'cef.device_version': g('CEF_DEVICE_VERSION', '0'),
            'cef.file': g('CEF_FILE', 'syslog'),
        },
    }
    _log_cef(msg, severity, request.META.copy(), **cef_kw)
Exemplo n.º 6
0
def log_cef_meta(msg, meta, full_path, **kw):
    g = functools.partial(getattr, settings)
    severity = kw.get('severity', g('CEF_DEFAULT_SEVERITY', 5))
    cef_kw = {
        'msg': msg,
        'signature': full_path,
        'config': {
            'cef.product': 'WebPay',
            'cef.vendor': g('CEF_VENDOR', 'Mozilla'),
            'cef.version': g('CEF_VERSION', '0'),
            'cef.device_version': g('CEF_DEVICE_VERSION', '0'),
            'cef.file': g('CEF_FILE', 'syslog'),
        },
    }
    _log_cef(msg, severity, meta, **cef_kw)
Exemplo n.º 7
0
def log_cef(name, severity, env, *args, **kwargs):
    """Simply wraps the cef_log function so we don't need to pass in the config
    dictionary every time.  See bug 707060.  env can be either a request
    object or just the request.META dictionary"""

    c = {'cef.product': getattr(settings, 'CEF_PRODUCT', 'AMO'),
         'cef.vendor': getattr(settings, 'CEF_VENDOR', 'Mozilla'),
         'cef.version': getattr(settings, 'CEF_VERSION', '0'),
         'cef.device_version': getattr(settings, 'CEF_DEVICE_VERSION', '0'),
         'cef.file': getattr(settings, 'CEF_FILE', 'syslog'), }

    # The CEF library looks for some things in the env object like
    # REQUEST_METHOD and any REMOTE_ADDR stuff.  Django not only doesn't send
    # half the stuff you'd expect, but it specifically doesn't implement
    # readline on its FakePayload object so these things fail.  I have no idea
    # if that's outdated code in Django or not, but andym made this
    # <strike>awesome</strike> less crappy so the tests will actually pass.
    # In theory, the last part of this if() will never be hit except in the
    # test runner.  Good luck with that.
    if isinstance(env, HttpRequest):
        r = env.META.copy()
        if 'PATH_INFO' in r:
            r['PATH_INFO'] = env.build_absolute_uri(r['PATH_INFO'])
    elif isinstance(env, dict):
        r = env
    else:
        r = {}
    if settings.USE_HEKA_FOR_CEF:
        return heka.cef(name, severity, r, *args, config=c, **kwargs)
    else:
        return _log_cef(name, severity, r, *args, config=c, **kwargs)
Exemplo n.º 8
0
def log_cef(name, severity, env, *args, **kwargs):
    """Simply wraps the cef_log function so we don't need to pass in the config
    dictionary every time.  See bug 707060.  env can be either a request
    object or just the request.META dictionary"""

    c = {
        'cef.product': getattr(settings, 'CEF_PRODUCT', 'AMO'),
        'cef.vendor': getattr(settings, 'CEF_VENDOR', 'Mozilla'),
        'cef.version': getattr(settings, 'CEF_VERSION', '0'),
        'cef.device_version': getattr(settings, 'CEF_DEVICE_VERSION', '0'),
        'cef.file': getattr(settings, 'CEF_FILE', 'syslog'),
    }

    # The CEF library looks for some things in the env object like
    # REQUEST_METHOD and any REMOTE_ADDR stuff.  Django not only doesn't send
    # half the stuff you'd expect, but it specifically doesn't implement
    # readline on its FakePayload object so these things fail.  I have no idea
    # if that's outdated code in Django or not, but andym made this
    # <strike>awesome</strike> less crappy so the tests will actually pass.
    # In theory, the last part of this if() will never be hit except in the
    # test runner.  Good luck with that.
    if isinstance(env, HttpRequest):
        r = env.META.copy()
        if 'PATH_INFO' in r:
            r['PATH_INFO'] = env.build_absolute_uri(r['PATH_INFO'])
    elif isinstance(env, dict):
        r = env
    else:
        r = {}
    if settings.USE_HEKA_FOR_CEF:
        return heka.cef(name, severity, r, *args, config=c, **kwargs)
    else:
        return _log_cef(name, severity, r, *args, config=c, **kwargs)
Exemplo n.º 9
0
    def log(self, environ, app, msg, longer, severity=None, extra_kwargs=None):
        """Log something important using the CEF library.

        Parameters:
        **environ**
            Typically a Django request object. It can also be
            a plain dict.
        **app**
            An app/addon object.
        **msg**
            A short message about the incident.
        **longer**
            A more description message about the incident.
        **severity=None**
            A 0-10 int to override the default severity.
        **extra_kwargs**
            A dict to override anything sent to the CEF library.
        """
        c = {
            'cef.product': getattr(settings, 'CEF_PRODUCT', 'AMO'),
            'cef.vendor': getattr(settings, 'CEF_VENDOR', 'Mozilla'),
            'cef.version': getattr(settings, 'CEF_VERSION', '0'),
            'cef.device_version': getattr(settings, 'CEF_DEVICE_VERSION', '0'),
            'cef.file': getattr(settings, 'CEF_FILE', 'syslog'),
        }
        user = getattr(environ, 'user', None)
        # Sometimes app is a string, eg: "unknown". Boo!
        try:
            app_str = app.pk
        except AttributeError:
            app_str = app

        kwargs = {
            'username': getattr(user, 'name', ''),
            'suid': str(getattr(user, 'pk', '')),
            'signature': '%s%s' % (self.sig_prefix, msg.upper()),
            'msg': longer,
            'config': c,
            # Until the CEF log can cope with unicode app names, just
            # use primary keys.
            'cs2': app_str,
            'cs2Label': self.cs2label
        }
        if extra_kwargs:
            kwargs.update(extra_kwargs)

        if not severity:
            severity = self.default_severity
        if not severity:
            raise ValueError('CEF severity was not defined')

        if isinstance(environ, HttpRequest):
            environ = environ.META.copy()

        if settings.USE_HEKA_FOR_CEF:
            return heka.cef('%s %s' % (self.msg_prefix, msg), severity,
                            environ, **kwargs)
        else:
            return _log_cef('%s %s' % (self.msg_prefix, msg), severity,
                            environ, **kwargs)
Exemplo n.º 10
0
def log_cef(name, severity, env, *args, **kwargs):
    """Simply wraps the cef_log function so we don't need to pass in the config
    dictionary every time.  See bug 707060.  env can be either a request
    object or just the request.META dictionary"""

    c = {
        "cef.product": getattr(settings, "CEF_PRODUCT", "AMO"),
        "cef.vendor": getattr(settings, "CEF_VENDOR", "Mozilla"),
        "cef.version": getattr(settings, "CEF_VERSION", "0"),
        "cef.device_version": getattr(settings, "CEF_DEVICE_VERSION", "0"),
        "cef.file": getattr(settings, "CEF_FILE", "syslog"),
    }

    # The CEF library looks for some things in the env object like
    # REQUEST_METHOD and any REMOTE_ADDR stuff.  Django not only doesn't send
    # half the stuff you'd expect, but it specifically doesn't implement
    # readline on its FakePayload object so these things fail.  I have no idea
    # if that's outdated code in Django or not, but andym made this
    # <strike>awesome</strike> less crappy so the tests will actually pass.
    # In theory, the last part of this if() will never be hit except in the
    # test runner.  Good luck with that.
    if isinstance(env, HttpRequest):
        r = env.META.copy()
    elif isinstance(env, dict):
        r = env
    else:
        r = {}

    return _log_cef(name, severity, r, *args, config=c, **kwargs)
Exemplo n.º 11
0
    def log(self, environ, app, msg, longer, severity=None,
            extra_kwargs=None):
        """Log something important using the CEF library.

        Parameters:
        **environ**
            Typically a Django request object. It can also be
            a plain dict.
        **app**
            An app/addon object.
        **msg**
            A short message about the incident.
        **longer**
            A more description message about the incident.
        **severity=None**
            A 0-10 int to override the default severity.
        **extra_kwargs**
            A dict to override anything sent to the CEF library.
        """
        c = {'cef.product': getattr(settings, 'CEF_PRODUCT', 'AMO'),
             'cef.vendor': getattr(settings, 'CEF_VENDOR', 'Mozilla'),
             'cef.version': getattr(settings, 'CEF_VERSION', '0'),
             'cef.device_version': getattr(settings,
                                           'CEF_DEVICE_VERSION',
                                           '0'),
             'cef.file': getattr(settings, 'CEF_FILE', 'syslog'), }
        user = getattr(environ, 'amo_user', None)
        # Sometimes app is a string, eg: "unknown". Boo!
        try:
            app_str = app.pk
        except AttributeError:
            app_str = app

        kwargs = {'username': getattr(user, 'name', ''),
                  'suid': str(getattr(user, 'pk', '')),
                  'signature': '%s%s' % (self.sig_prefix, msg.upper()),
                  'msg': longer, 'config': c,
                  # Until the CEF log can cope with unicode app names, just
                  # use primary keys.
                  'cs2': app_str, 'cs2Label': self.cs2label}
        if extra_kwargs:
            kwargs.update(extra_kwargs)

        if not severity:
            severity = self.default_severity
        if not severity:
            raise ValueError('CEF severity was not defined')

        if isinstance(environ, HttpRequest):
            environ = environ.META.copy()

        if settings.USE_HEKA_FOR_CEF:
            return heka.cef('%s %s' % (self.msg_prefix, msg), severity,
                            environ, **kwargs)
        else:
            return _log_cef('%s %s' % (self.msg_prefix, msg),
                     severity, environ, **kwargs)
Exemplo n.º 12
0
def log_cef_meta(msg, meta, path_info, **kw):
    g = functools.partial(getattr, settings)
    severity = kw.get('severity', g('CEF_DEFAULT_SEVERITY', 5))
    cef_kw = {
        'msg': msg,
        'signature': path_info,
        'config': {
            'cef.product': 'WebPay',
            'cef.vendor': g('CEF_VENDOR', 'Mozilla'),
            'cef.version': g('CEF_VERSION', '0'),
            'cef.device_version': g('CEF_DEVICE_VERSION', '0'),
            'cef.file': g('CEF_FILE', 'syslog'),
        },
    }
    if severity > 2:
        # Only send more severe logging to syslog. Messages lower than that
        # could be every http request, etc.
        log.error('CEF Severity: {sev} Message: {msg}'
                  .format(sev=severity, msg=msg))
    _log_cef(msg, severity, meta, **cef_kw)
Exemplo n.º 13
0
def log_cef(request, app, msg, longer):
    """Log receipt transactions to the CEF library."""
    c = {'cef.product': getattr(settings, 'CEF_PRODUCT', 'AMO'),
         'cef.vendor': getattr(settings, 'CEF_VENDOR', 'Mozilla'),
         'cef.version': getattr(settings, 'CEF_VERSION', '0'),
         'cef.device_version': getattr(settings, 'CEF_DEVICE_VERSION', '0'),
         'cef.file': getattr(settings, 'CEF_FILE', 'syslog'), }

    kwargs = {'username': getattr(request, 'amo_user', ''),
              'signature': 'RECEIPT%s' % msg.upper(),
              'msg': longer, 'config': c,
              'cs2': app, 'cs2Label': 'ReceiptTransaction'}
    return _log_cef('Receipt %s' % msg, 5, request, **kwargs)
Exemplo n.º 14
0
def log_cef(request, app, msg, longer):
    """Log receipt transactions to the CEF library."""
    c = {'cef.product': getattr(settings, 'CEF_PRODUCT', 'AMO'),
         'cef.vendor': getattr(settings, 'CEF_VENDOR', 'Mozilla'),
         'cef.version': getattr(settings, 'CEF_VERSION', '0'),
         'cef.device_version': getattr(settings, 'CEF_DEVICE_VERSION', '0'),
         'cef.file': getattr(settings, 'CEF_FILE', 'syslog'), }

    kwargs = {'username': getattr(request, 'amo_user', ''),
              'signature': 'RECEIPT%s' % msg.upper(),
              'msg': longer, 'config': c,
              'cs2': app, 'cs2Label': 'ReceiptTransaction'}
    return _log_cef('Receipt %s' % msg, 5, request, **kwargs)
Exemplo n.º 15
0
    def log(self, environ, app, msg, longer, severity=None, extra_kwargs=None):
        """Log something important using the CEF library.

        Parameters:
        **environ**
            Typically a Django request object. It can also be
            a plain dict.
        **app**
            An app/addon object.
        **msg**
            A short message about the incident.
        **longer**
            A more description message about the incident.
        **severity=None**
            A 0-10 int to override the default severity.
        **extra_kwargs**
            A dict to override anything sent to the CEF library.
        """
        c = {
            'cef.product': getattr(settings, 'CEF_PRODUCT', 'AMO'),
            'cef.vendor': getattr(settings, 'CEF_VENDOR', 'Mozilla'),
            'cef.version': getattr(settings, 'CEF_VERSION', '0'),
            'cef.device_version': getattr(settings, 'CEF_DEVICE_VERSION', '0'),
            'cef.file': getattr(settings, 'CEF_FILE', 'syslog'),
        }

        kwargs = {
            'username': getattr(environ, 'amo_user', ''),
            'signature': '%s%s' % (self.sig_prefix, msg.upper()),
            'msg': longer,
            'config': c,
            'cs2': app,
            'cs2Label': self.cs2label
        }
        if extra_kwargs:
            kwargs.update(extra_kwargs)

        if not severity:
            severity = self.default_severity
        if not severity:
            raise ValueError('CEF severity was not defined')

        if isinstance(environ, HttpRequest):
            environ = environ.META.copy()
        return _log_cef('%s %s' % (self.msg_prefix, msg), severity, environ,
                        **kwargs)
Exemplo n.º 16
0
    def log(self, environ, app, msg, longer, severity=None, extra_kwargs=None):
        """Log something important using the CEF library.

        Parameters:
        **environ**
            Typically a Django request object. It can also be
            a plain dict.
        **app**
            An app/addon object.
        **msg**
            A short message about the incident.
        **longer**
            A more description message about the incident.
        **severity=None**
            A 0-10 int to override the default severity.
        **extra_kwargs**
            A dict to override anything sent to the CEF library.
        """
        c = {
            "cef.product": getattr(settings, "CEF_PRODUCT", "AMO"),
            "cef.vendor": getattr(settings, "CEF_VENDOR", "Mozilla"),
            "cef.version": getattr(settings, "CEF_VERSION", "0"),
            "cef.device_version": getattr(settings, "CEF_DEVICE_VERSION", "0"),
            "cef.file": getattr(settings, "CEF_FILE", "syslog"),
        }

        kwargs = {
            "username": getattr(environ, "amo_user", ""),
            "signature": "%s%s" % (self.sig_prefix, msg.upper()),
            "msg": longer,
            "config": c,
            "cs2": app,
            "cs2Label": self.cs2label,
        }
        if extra_kwargs:
            kwargs.update(extra_kwargs)

        if not severity:
            severity = self.default_severity
        if not severity:
            raise ValueError("CEF severity was not defined")

        if isinstance(environ, HttpRequest):
            environ = environ.META.copy()
        return _log_cef("%s %s" % (self.msg_prefix, msg), severity, environ, **kwargs)