Merge "add support of RainerScript"
diff --git a/README.rst b/README.rst
index 6bff252..bd98749 100644
--- a/README.rst
+++ b/README.rst
@@ -71,6 +71,52 @@
               umask: 0022
               stop_processing: true
 
+Rsyslog service with RainerScript (module, ruleset, template, input).
+
+.. code-block:: yaml
+
+  rsyslog:
+    client:
+      run_user: syslog
+      run_group: adm
+      enabled: true
+      rainerscript:
+        module:
+          imfile: {}
+        input:
+          imfile:
+            nginx:
+              File: "/var/log/nginx/*.log"
+              Tag: "nginx__"
+              Severity: "notice"
+              Facility: "local0"
+              PersistStateInterval: "0"
+              Ruleset: "myapp_logs"
+            apache2:
+              File: "/var/log/apache2/*.log"
+              Tag: "apache2__"
+              Severity: "notice"
+              Facility: "local0"
+              Ruleset: "myapp_logs"
+              PersistStateInterval: "0"
+            rabbitmq:
+              File: "/var/log/rabbitmq/*.log"
+              Tag: "rabbitmq__"
+              Severitet: "notice"
+              Facility: "local0"
+              PersistStateInterval: "0"
+              Ruleset: "myapp_logs"
+        template:
+          ImfileFilePath:
+            parameter:
+              type: string
+              string: "<%PRI%>%TIMESTAMP:::date-rfc3339% %HOSTNAME% %syslogtag:1:32%%$.suffix%%msg:::sp-if-no-1st-sp%%msg%\n"
+        ruleset:
+          remote_logs:
+            description: 'action(type="omfwd" Target="172.16.10.92" Port="10514" Protocol="udp" Template="ImfileFilePath")'
+          myapp_logs:
+            description: 'set $.suffix=re_extract($!metadata!filename, "(.*)/([^/]*[^/.log])", 0, 2, "all.log"); call remote_logs'
+
 Custom templates
 ================
 
diff --git a/rsyslog/files/rsyslog.default.conf b/rsyslog/files/rsyslog.default.conf
index ff7f917..5199ccc 100644
--- a/rsyslog/files/rsyslog.default.conf
+++ b/rsyslog/files/rsyslog.default.conf
@@ -39,6 +39,38 @@
 $ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
 {% endif -%}
 
+{% if global.rainerscript is defined -%}
+
+{%- set rainerscript = global.get('rainerscript', {}) -%}
+
+{%- for mod,parameter in rainerscript.get('module', {}).iteritems() %}
+module(load="{{ mod }}"{%- for name,value in parameter.iteritems() %} {{name}}="{{value}}"{%- endfor -%})
+{%- endfor %}
+
+{%- for name,template in rainerscript.get('template', {}).iteritems() %}
+template(name="{{ name }}" {%- for name,value in template.parameter.iteritems() %} {{name}}="{{value}}"{%- endfor -%})
+{%- if template.description is defined -%}{ {{ template.description }} } {%- endif -%}
+{%- endfor %}
+
+{%- for name,ruleset in rainerscript.get('ruleset', {}).iteritems() %}
+ruleset(name="{{ name }}"){
+{{ ruleset.description }}
+}
+{%- endfor %}
+
+{%- for type,input in rainerscript.get('input', {}).iteritems() %}
+{%- for name,parameter in input.iteritems() %}
+input(type="{{ type }}"{%- for name,value in parameter.iteritems() %} {{name}}="{{value}}"{%- endfor -%})
+{%- endfor %}
+{%- endfor %}
+{% endif -%}
+
+{% if global.output.remote is defined %}
+{% for name,config in global.output.remote.iteritems() if config.get('enabled', False) -%}
+{{ config['filter'] }}      {{ config['action'] }}
+{% endfor -%}
+{% endif -%}
+
 {# Additional configurations should be included after defining the global format otherwise they won't benefit from it #}
 $IncludeConfig {{ global.rsyslog_d }}/*.conf
 
@@ -87,9 +119,3 @@
 {{ config['filter'] }}      {{ config['action'] }}
 {% endfor -%}
 {% endif -%}
-
-{% if global.output.remote is defined %}
-{% for name,config in global.output.remote.iteritems() if config.get('enabled', False) -%}
-{{ config['filter'] }}      {{ config['action'] }}
-{% endfor -%}
-{% endif -%}