Viewing File: /usr/lib/python2.7/site-packages/cloudinit/config/cc_rsyslog.pyc

ó
oBú]c@sdZddlZddlZddlZddlmZddlmZdZdZ	dZ
iZdZd	Z
d
ZdZdZd
ZdZejeƒZejdƒZejdƒZe
ed„Zd„Zd„Zdd„Zdefd„ƒYZ ddd„Z!d„Z"dS(sí
.. _cc_rsyslog:

Rsyslog
-------
**Summary:** configure system loggig via rsyslog

This module configures remote system logging using rsyslog.

The rsyslog config file to write to can be specified in ``config_filename``,
which defaults to ``20-cloud-config.conf``. The rsyslog config directory to
write config files to may be specified in ``config_dir``, which defaults to
``/etc/rsyslog.d``.

A list of configurations for rsyslog can be specified under the ``configs`` key
in the ``rsyslog`` config. Each entry in ``configs`` is either a string or a
dictionary. Each config entry contains a configuration string and a file to
write it to. For config entries that are a dictionary, ``filename`` sets the
target filename and ``content`` specifies the config string to write. For
config entries that are only a string, the string is used as the config string
to write. If the filename to write the config to is not specified, the value of
the ``config_filename`` key is used. A file with the selected filename will be
written inside the directory specified by ``config_dir``.

The command to use to reload the rsyslog service after the config has been
updated can be specified in ``service_reload_command``. If this is set to
``auto``, then an appropriate command for the distro will be used. This is the
default behavior. To manually set the command, use a list of command args (e.g.
``[systemctl, restart, rsyslog]``).

Configuration for remote servers can be specified in ``configs``, but for
convenience it can be specified as key value pairs in ``remotes``. Each key
is the name for an rsyslog remote entry. Each value holds the contents of the
remote config for rsyslog. The config consists of the following parts:

    - filter for log messages (defaults to ``*.*``)
    - optional leading ``@`` or ``@@``, indicating udp and tcp respectively
      (defaults to ``@``, for udp)
    - ipv4 or ipv6 hostname or address. ipv6 addresses must be in ``[::1]``
      format, (e.g. ``@[fd00::1]:514``)
    - optional port number (defaults to ``514``)

This module will provide sane defaults for any part of the remote entry that is
not specified, so in most cases remote hosts can be specified just using
``<name>: <address>``.

For backwards compatibility, this module still supports legacy names for the
config entries. Legacy to new mappings are as follows:

    - ``rsyslog`` -> ``rsyslog/configs``
    - ``rsyslog_filename`` -> ``rsyslog/config_filename``
    - ``rsyslog_dir`` -> ``rsyslog/config_dir``

.. note::
    The legacy config format does not support specifying
    ``service_reload_command``.

**Internal name:** ``cc_rsyslog``

**Module frequency:** per instance

**Supported distros:** all

**Config keys**::

    rsyslog:
        config_dir: config_dir
        config_filename: config_filename
        configs:
            - "*.* @@192.158.1.1"
            - content: "*.*   @@192.0.2.1:10514"
              filename: 01-example.conf
            - content: |
                *.*   @@syslogd.example.com
        remotes:
            maas: "192.168.1.1"
            juju: "10.0.4.1"
        service_reload_command: [your, syslog, restart, command]

**Legacy config keys**::

    rsyslog:
        - "*.* @@192.158.1.1"
    rsyslog_dir: /etc/rsyslog-config.d/
    rsyslog_filename: 99-local.conf
iÿÿÿÿN(tlog(tutils20-cloud-config.confs/etc/rsyslog.dtautotconfigstconfig_filenamet
config_dirtservice_reload_commandtrsyslog_filenametrsyslog_dirtremotess[ ]*[#]+[ ]*s_^(?P<proto>[@]{0,2})(([\[](?P<bracket_addr>[^\]]*)[\]])|(?P<addr>[^:]*))([:](?P<port>[0-9]+))?$cCsYd}|tkr<|r*dd|g}qBd|dg}n|}tj|dtƒdS(Ntrsyslogt	systemctlsreload-or-try-restarttservicetrestarttcapture(t
DEF_RELOADRtsubptTrue(tcommandtsystemdRtcmd((s?/usr/lib/python2.7/site-packages/cloudinit/config/cc_rsyslog.pyt
reload_syslogÒscCs|jdiƒ}t|jdƒtƒr}i|jdƒt6}t|kr]|t|t<nt|kr}|t|t<q}ntgtfttt	j
fttt	j
ftt
t	j
tfftttff}xD|D]<\}}}||kst|||ƒrÖ|||<qÖqÖW|S(NR
(tgett
isinstancetlisttKEYNAME_CONFIGStKEYNAME_LEGACY_FILENAMEtKEYNAME_FILENAMEtKEYNAME_LEGACY_DIRtKEYNAME_DIRtDEF_DIRtsixtstring_typestDEF_FILENAMEtKEYNAME_RELOADRtKEYNAME_REMOTEStDEF_REMOTEStdict(tcfgtmycfgtfilluptkeytdefaulttvtypes((s?/usr/lib/python2.7/site-packages/cloudinit/config/cc_rsyslog.pytload_configÞs  c
CsSg}xFt|ƒD]8\}}t|tƒrsd|krTtjd|dƒqn|d}|jd|ƒ}n|}|}|jƒ}|s«tjd|dƒqntjj	||ƒ}d}||krèd}|j
|ƒny<d}	|jd	ƒs	d	}	ntj
|||	d
|ƒWqtk
rJtjtd|ƒqXqW|S(Ntcontents%No 'content' entry in config entry %sitfilenamesEntry %s has an empty filenametabtwbts
tomodesFailed to write to %s(t	enumerateRR%tLOGtwarningRtstriptostpathtjointappendtendswithRt
write_filet	Exceptiontlogexc(
Rt	def_fnametcfg_dirtfilestcur_postentR-R.R2tendl((s?/usr/lib/python2.7/site-packages/cloudinit/config/cc_rsyslog.pytapply_rsyslog_changesøs8	
	
cCs‹y%tj|ƒ\}}|jƒ}Wntk
rE|d}}nX|jƒjƒ}d}t|ƒdkry|}n1t|ƒdkrš|\}}ntd|ƒ‚tj|ƒ}|sÒtd|ƒ‚n|jdƒ}|jdƒpü|jdƒ}|jdƒ}	|j	d	ƒr@|j
d
ƒr@td|ƒ‚n|rV|rV|}ntd|d
|d|d|d|	ƒ}
|
jƒ|
S(Niisline had multiple spaces: %ssInvalid host specification '%s'tprototaddrtbracket_addrtportt[t]s"host spec had invalid brackets: %stnametmatch(
t
COMMENT_REtsplitR6t
ValueErrortNonetlentHOST_PORT_RERMtgroupt
startswithR;tSyslogRemotesLinetvalidate(tlineRLtdatatcommentttoksRMt	host_portRFRGRItt((s?/usr/lib/python2.7/site-packages/cloudinit/config/cc_rsyslog.pytparse_remotes_line s4
	
	
RVcBs;eZdddddd„Zd„Zd„Zd„ZRS(cCs‘|sd}n||_||_|s0d}n|dkrEd}n|dkrZd}n||_||_|r„t|ƒ|_n	d|_dS(Ns*.*tudpt@s@@ttcp(RLRMRFRGtintRIRQ(tselfRLRMRFRGRI((s?/usr/lib/python2.7/site-packages/cloudinit/config/cc_rsyslog.pyt__init__Fs								cCs`|jrDyt|jƒWqDtk
r@td|jƒ‚qDXn|js\tdƒ‚ndS(Nsport '%s' is not an integersaddress is required(RIRbRPRG(Rc((s?/usr/lib/python2.7/site-packages/cloudinit/config/cc_rsyslog.pyRWZs	
	cCs&d|j|j|j|j|jfS(Ns.[name=%s match=%s proto=%s address=%s port=%s](RLRMRFRGRI(Rc((s?/usr/lib/python2.7/site-packages/cloudinit/config/cc_rsyslog.pyt__repr__dscCs·|jd}|jdkr)|d7}n|jdkrE|d7}nd|jkrl|d|jd7}n
||j7}|jr–|d	|j7}n|jr³|d
|j7}n|S(Nt R_R`Ras@@t:RJRKs:%ss # %s(RMRFRGRIRL(Rctbuf((s?/usr/lib/python2.7/site-packages/cloudinit/config/cc_rsyslog.pyt__str__is



		N(t__name__t
__module__RQRdRWReRi(((s?/usr/lib/python2.7/site-packages/cloudinit/config/cc_rsyslog.pyRVEs
	
	cCsÑ|s
dSg}|dk	r,|j|ƒnxu|jƒD]g\}}|sQq9ny#|jtt|d|ƒƒƒWq9tk
rŸ}tjd|||ƒq9Xq9W|dk	rÀ|j|ƒndj|ƒdS(NRLs!failed loading remote %s: %s [%s]s
(	RQR:titemststrR^RPR4R5R9(R	theadertfootertlinesRLRXte((s?/usr/lib/python2.7/site-packages/cloudinit/config/cc_rsyslog.pytremotes_to_rsyslog_cfg}s#c
CsAd|kr |jd|ƒdSt|ƒ}|t}|trf|jt|tddddƒƒn|ds|jdƒdStd|td	|td
|tƒ}|s¿|jdƒdSy)t	d|t
d
|jjƒƒf}Wn,t
jk
r}	t}|jd|	ƒnX|r=|jƒ|jd||ƒndS(NR
s;Skipping module named %s, no 'rsyslog' key in configurationRns# begin remotesRos
# end remotesRs.Empty config rsyslog['configs'], nothing to doR?R@s0restart of syslog not necessary, no changes madeRRsFailed to reload syslogs%s configured %s files(tdebugR,RR#R:RrRERRRR"tdistrotuses_systemdRtProcessExecutionErrortFalseR5t
cycle_logging(
RLR&tcloudRt_argsR'Rtchangest	restartedRq((s?/usr/lib/python2.7/site-packages/cloudinit/config/cc_rsyslog.pythandles@	











(#t__doc__R7treRt	cloudinitRtloggingRR!RRR$RRRR"RRR#t	getLoggerRjR4tcompileRNRSRwRR,RERQR^tobjectRVRrR}(((s?/usr/lib/python2.7/site-packages/cloudinit/config/cc_rsyslog.pyt<module>^s6W			(%8
Back to Directory File Manager