Saltstack Official Syslog-NG Formula
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.5KB

  1. {%- set syslog_config = pillar.get('syslog_ng', {}) -%}
  2. {%- macro rule_builder(rule) -%}
  3. {%- if rule is none -%}
  4. {%- elif rule is sameas true -%}
  5. yes
  6. {%- elif rule is sameas false -%}
  7. no
  8. {%- elif rule is number -%}
  9. {{ rule }}
  10. {%- elif rule is mapping -%}
  11. {%- for k, v in rule.items() -%}
  12. {{ k }}({{ rule_builder(v) }})
  13. {%- endfor -%}
  14. {%- elif rule is iterable and rule is not string -%}
  15. {%- for v in rule -%}
  16. {{ rule_builder(v) }}
  17. {%- endfor -%}
  18. {%- else -%}
  19. {%- if rule[0] == '=' -%}
  20. {{ rule[1:] }}
  21. {%- else -%}
  22. "{{ rule }}"
  23. {%- endif -%}
  24. {%- endif -%}
  25. {%- endmacro -%}
  26. @version: {{ syslog_config.get('version', '3.3') }}
  27. {%- for module in syslog_config.get('module', []) %}
  28. @module {{ rule_builder(module) }}
  29. {%- endfor %}
  30. {%- for inc in syslog_config.get('include', []) %}
  31. @include {{ rule_builder(inc) }}
  32. {%- endfor %}
  33. options {
  34. {%- for rule in syslog_config.get('options', []) %}
  35. {{ rule_builder(rule) }};
  36. {%- endfor %}
  37. };
  38. {%- for obj in ('source', 'destination', 'filter', 'parser', 'rewrite', 'template') %}
  39. {%- for params in syslog_config.get(obj, []) %}
  40. {% for name, rules in params.items() %}
  41. {{ obj }} {{ name }} {
  42. {%- for rule in rules %}
  43. {{ rule_builder(rule) }};
  44. {%- endfor %}
  45. };
  46. {%- endfor %}
  47. {%- endfor %}
  48. {%- endfor %}
  49. {% for loggers in syslog_config.get('log', []) -%}
  50. log {
  51. {%- for rule in loggers %}
  52. {{ rule_builder(rule) }};
  53. {%- endfor %}
  54. };
  55. {%- endfor %}