Merge pull request #41 from FHE3/partition-handling

Fix for issue #39. Cluster setting cluster_partition_handling can now…
diff --git a/README.rst b/README.rst
index 6a8a131..16f89e8 100644
--- a/README.rst
+++ b/README.rst
@@ -27,11 +27,11 @@
         plugins:
         - amqp_client
         - rabbitmq_management
-        virtual_hosts:
-        - enabled: true
-          host: '/monitor'
-          user: 'monitor'
-          password: 'password'
+        host:
+          '/monitor':
+            enabled: true
+            user: 'monitor'
+            password: 'password'
 
 RabbitMQ as a Stomp broker
 
@@ -44,11 +44,11 @@
         bind:
           address: 0.0.0.0
           port: 5672
-        virtual_hosts:
-        - enabled: true
-          host: '/monitor'
-          user: 'monitor'
-          password: 'password'
+        host:
+          '/monitor':
+            enabled: true
+            user: 'monitor'
+            password: 'password'
         plugins:
         - rabbitmq_stomp
 
@@ -87,16 +87,15 @@
       server:
         enabled: true
         ...
-        virtual_hosts:
-        - enabled: true
-          host: '/monitor'
-          user: 'monitor'
-          password: 'password'
-          policies:
-          - name: HA
-            pattern: '^(?!amq\.).*'
-            definition: '{"ha-mode": "all"}'
-
+        host:
+          '/monitor':
+            enabled: true
+            user: 'monitor'
+            password: 'password'
+            policies:
+            - name: HA
+              pattern: '^(?!amq\.).*'
+              definition: '{"ha-mode": "all"}'
 
 
 Enable TLS support
diff --git a/metadata/service/support.yml b/metadata/service/support.yml
index 8430304..afaa3b6 100644
--- a/metadata/service/support.yml
+++ b/metadata/service/support.yml
@@ -19,3 +19,5 @@
         enabled: true
       prometheus:
         enabled: true
+      fluentd:
+        enabled: true
diff --git a/rabbitmq/files/limits.conf b/rabbitmq/files/limits.conf
new file mode 100644
index 0000000..c44792b
--- /dev/null
+++ b/rabbitmq/files/limits.conf
@@ -0,0 +1,4 @@
+{%- from "rabbitmq/map.jinja" import server with context -%}
+# Managed by Salt
+[Service]
+LimitNOFILE={{ server.ulimit }}
diff --git a/rabbitmq/map.jinja b/rabbitmq/map.jinja
index 9415bd7..f169d0b 100644
--- a/rabbitmq/map.jinja
+++ b/rabbitmq/map.jinja
@@ -12,6 +12,7 @@
         'env_file': '/etc/rabbitmq/rabbitmq-env.conf',
         'cookie_file': '/var/lib/rabbitmq/.erlang.cookie',
         'ulimit': 8192,
+        'limits_file': '/etc/systemd/system/rabbitmq-server.service.d/limits.conf',
         'disk_free_limit': 50000000,
         'bind': {
             'address': '0.0.0.0',
diff --git a/rabbitmq/meta/fluentd.yml b/rabbitmq/meta/fluentd.yml
new file mode 100644
index 0000000..0b75d10
--- /dev/null
+++ b/rabbitmq/meta/fluentd.yml
@@ -0,0 +1,37 @@
+{%- if pillar.get('fluentd', {}).get('agent', {}).get('enabled', False) %}
+agent:
+  config:
+    label:
+      rabbitmq:
+        input:
+          tail_rabbitmq:
+            type: tail
+            tag: rabbitmq
+            path: /var/log/rabbitmq/rabbit*.log
+            pos_file: {{ pillar.fluentd.agent.dir.positiondb }}/rabbitmq.pos
+            parser:
+              type: multiline
+              time_key: Timestamp
+              time_format: '%d-%b-%Y::%H:%M:%S'
+              keep_time_key: false
+              format_firstline: '/=[A-Z]+\sREPORT====/'
+              format: '/^=(?<orig_severity_label>[A-Z]+)\sREPORT====\s(?<Timestamp>.*)\s===\n(?<Payload>.*)/'
+        filter:
+          match_severity:
+            type: record_transformer
+            tag: rabbitmq
+            remove_keys: orig_severity_label
+            enable_ruby: true
+            record:
+              - name: programname
+                value: rabbitmq
+              - name: severity_label
+                value: ${ {'INFO'=>'INFO','NOTICE'=>'NOTICE','SUPERVISOR'=>'NOTICE','WARNING'=>'WARNING','ERROR'=>'ERROR','CRASH'=>'CRITICAL'}[record['orig_severity_label']] }
+              - name: Severity
+                value: ${ {'INFO'=>6,'NOTICE'=>5,'SUPERVISOR'=>5,'WARNING'=>4,'ERROR'=>3,'CRASH'=>2}[record['orig_severity_label']].to_i }
+        match:
+          push_to_default:
+            tag: rabbitmq
+            type: relabel
+            label: default_output
+{%- endif %}
diff --git a/rabbitmq/server/service.sls b/rabbitmq/server/service.sls
index 363c23b..1333144 100644
--- a/rabbitmq/server/service.sls
+++ b/rabbitmq/server/service.sls
@@ -32,6 +32,22 @@
 
 {%- endif %}
 
+{%- if grains.init == 'systemd' %}
+
+rabbitmq_limits_systemd:
+  file.managed:
+  - name: {{ server.limits_file }}
+  - source: salt://rabbitmq/files/limits.conf
+  - template: jinja
+  - user: root
+  - group: root
+  - makedirs: True
+  - mode: 0644
+  - require:
+    - pkg: rabbitmq_packages
+
+{%- endif %}
+
 {%- if server.secret_key is defined and not grains.get('noservices', False) %}
 
 {%- if salt['cmd.run']('cat '+server.cookie_file) != server.secret_key %}
@@ -96,6 +112,9 @@
   - name: {{ server.service }}
   - watch:
     - file: rabbitmq_config
+      {%- if grains.init == 'systemd' %}
+    - file: rabbitmq_limits_systemd
+      {%- endif %}
       {% if server.ssl.enabled %}
     - file: rabbitmq_cacertificate
     - file: rabbitmq_certificate