Explorar el Código

Merge pull request #4 from EvaSDK/master

Switch template to jinja
tags/v0.2.0
Nicolas Rodriguez hace 7 años
padre
commit
984169fb66
Ninguna cuenta vinculada a la dirección de correo electrónico del committer
Se han modificado 2 ficheros con 55 adiciones y 49 borrados
  1. +1
    -1
      syslog_ng/config.sls
  2. +54
    -48
      syslog_ng/files/syslog-ng.conf

+ 1
- 1
syslog_ng/config.sls Ver fichero

@@ -7,7 +7,7 @@ syslog_ng.conf:
file.managed:
- name: {{ syslog_ng.syslog_ng_config }}
- source: {{ syslog_ng.syslog_ng_config_src }}
- template: mako
- template: jinja
- user: root
- group: root
- mode: 644

+ 54
- 48
syslog_ng/files/syslog-ng.conf Ver fichero

@@ -1,56 +1,62 @@
<% syslog_config = pillar.get('syslog_ng', {}) %>\
<%!
def rule_builder(rule):
if rule is None:
return ''
elif type(rule) is bool:
return {True: 'yes', False: 'no'}[rule]
elif type(rule) is int:
return rule
elif type(rule) is list:
return ' '.join([rule_builder(v) for v in rule])
elif type(rule) is dict:
return ' '.join([ '%s(%s)' % (k,rule_builder(v)) for k, v in rule.items()])
else:
if rule[0] == '=':
return rule[1:]
return '"%s"' % rule
%>\

@version: ${ syslog_config.get('version', '3.3') }

% for module in syslog_config.get('module', []):
@module ${ rule_builder(module) }
% endfor

% for inc in syslog_config.get('include', []):
@include ${ rule_builder(inc) }
% endfor

{%- set syslog_config = pillar.get('syslog_ng', {}) -%}

{%- macro rule_builder(rule) -%}
{%- if rule is none -%}
{%- elif rule is sameas true -%}
yes
{%- elif rule is sameas false -%}
no
{%- elif rule is number -%}
{{ rule }}
{%- elif rule is mapping -%}
{%- for k, v in rule.items() -%}
{{ k }}({{ rule_builder(v) }})
{%- endfor -%}
{%- elif rule is iterable and rule is not string -%}
{%- for v in rule -%}
{{ rule_builder(v) }}
{%- endfor -%}
{%- else -%}
{%- if rule[0] == '=' -%}
{{ rule[1:] }}
{%- else -%}
"{{ rule }}"
{%- endif -%}
{%- endif -%}
{%- endmacro -%}

@version: {{ syslog_config.get('version', '3.3') }}

{%- for module in syslog_config.get('module', []) %}
@module {{ rule_builder(module) }}
{%- endfor %}

{%- for inc in syslog_config.get('include', []) %}
@include {{ rule_builder(inc) }}
{%- endfor %}

options {
% for rule in syslog_config.get('options', []):
${ rule_builder(rule) };
% endfor
{%- for rule in syslog_config.get('options', []) %}
{{ rule_builder(rule) }};
{%- endfor %}
};

% for obj in ('source', 'destination', 'filter', 'parser', 'rewrite', 'template'):
% for params in syslog_config.get(obj, []):
% for name, rules in params.items():
${ obj } ${ name } {
% for rule in rules:
${ rule_builder(rule) };
% endfor
{%- for obj in ('source', 'destination', 'filter', 'parser', 'rewrite', 'template') %}
{%- for params in syslog_config.get(obj, []) %}
{% for name, rules in params.items() %}
{{ obj }} {{ name }} {
{%- for rule in rules %}
{{ rule_builder(rule) }};
{%- endfor %}
};
{%- endfor %}
{%- endfor %}
{%- endfor %}

% endfor
% endfor

% endfor
% for loggers in syslog_config.get('log', []):
{% for loggers in syslog_config.get('log', []) -%}
log {
% for rule in loggers:
${ rule_builder(rule) };
% endfor
{%- for rule in loggers %}
{{ rule_builder(rule) }};
{%- endfor %}
};
% endfor
{%- endfor %}

Cargando…
Cancelar
Guardar