Ubuntu Pastebin

Paste from stub at Fri, 11 Dec 2015 14:30:25 +0000

Download as text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# Copyright 2015 Canonical Ltd.
#
# This file is part of the PostgreSQL Charm for Juju.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3, as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranties of
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
# PURPOSE.  See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import glob
import os.path

from charmhelpers import context
from charmhelpers.core import hookenv, host, templating

from decorators import data_ready_action, relation_handler

from charms import reactive


@when('syslog.available')
def configure_syslog(rel):
    programname = hookenv.local_unit().replace('/', '_')
    rel.configure(programname=programname)
    extend_syslog(rel.conversation())


@when('postgresql.cluster.configured')
def reconfigure_syslog():
    rel = SyslogProvides.from_name('syslog')
    if not rel:
        return
    for conv in rel.conversations():
        extend_syslog(conv)


def extend_syslog(conv):
    '''Add extra relation settings, extending the basic syslog interface.

    Adds programname and log_line_prefix, required for consumers such
    as pgBadger to be able to decode the logs.
    '''
    store = unitdata.kv()
    log_line_prefix_key = 'postgresql.cluster.pgconf.current.log_line_prefix'
    conv.set_remote('log_line_prefix', store.get(log_line_prefix_key))
    conv.set_remote('programname', hookenv.local_unit().replace('/', '_'))
Download as text