Projet

Général

Profil

0001-debian-add-journald-support-to-debian_config_common-.patch

Benjamin Dauvergne, 27 avril 2018 00:57

Télécharger (2,79 ko)

Voir les différences:

Subject: [PATCH 1/2] debian: add journald support to debian_config_common
 (fixes #23471)

 debian/control                 |  3 ++-
 debian/debian_config_common.py | 35 ++++++++++++++++++++++------------
 2 files changed, 25 insertions(+), 13 deletions(-)
debian/control
19 19
Recommends: python-django (>= 1.8),
20 20
    python-gadjo,
21 21
    python-django-mellon (>= 1.2.22.26),
22
    memcached
22
    memcached,
23
    python-systemd
23 24
Description: Rapid Remote Deployment python module
24 25

  
25 26
Package: hobo
debian/debian_config_common.py
9 9
# execfile('/etc/%s/settings.py' % PROJECT_NAME)
10 10

  
11 11
import os
12
import warnings
13

  
12 14
from django.conf import global_settings
13 15
from django.core.exceptions import ImproperlyConfigured
14 16

  
......
122 124
    },
123 125
}
124 126

  
125
# Graylog support
126
if 'GRAYLOG_URL' in os.environ:
127
# Journald support
128
if os.path.exists('/run/systemd/journal/socket'):
127 129
    try:
128
        from graypy import GELFHandler
130
        from systemd import journal
129 131
    except ImportError:
130
        raise ImproperlyConfigured('cannot configure graypy, import of GELFHandler failed')
132
        warnings.warn('journald will not be used directly, please install python-systemd')
131 133
    else:
132
        host = os.environ['GRAYLOG_URL'].split(':')[0]
133
        port = int(os.environ['GRAYLOG_URL'].split(':')[1])
134
        LOGGING['handlers']['gelf'] = {
135
            'class': 'graypy.GELFHandler',
136
            'fqdn': True,
137
            'host': host,
138
            'port': port,
134
        old_send = journal.send
135
        # uppercase our own structured attributes
136
        def send(msg, **kwargs):
137
            for key in ['tenant', 'ip', 'path', 'application', 'request_id',
138
                        'user_name', 'user_email', 'user_display_name',
139
                        'user_uuid', 'user']:
140
                if key not in kwargs:
141
                    break  # fast path
142
                value = kwargs.pop(key)
143
                kwargs[key.upper()] = value
144
            return old_send(msg, **kwargs)
145
        journal.send = send
146

  
147
        LOGGING['handlers']['journald'] = {
148
            'class': 'systemd.journal.JournalHandler',
139 149
        }
140
        LOGGING['loggers']['']['handlers'].append('gelf')
150
        LOGGING['loggers']['']['handlers'].remove('syslog')
151
        LOGGING['loggers']['']['handlers'].append('journald')
141 152

  
142 153
# Sentry support
143 154
if 'SENTRY_DSN' in os.environ:
144
-