Parameter normalisation
diff --git a/collectd/client.sls b/collectd/client.sls
index edaff0f..90df072 100644
--- a/collectd/client.sls
+++ b/collectd/client.sls
@@ -1,7 +1,7 @@
{%- from "collectd/map.jinja" import client with context %}
{%- if client.enabled %}
-{% if grains.os == 'Ubuntu' and (grains.osrelease in ['10.04', '12.04']) %}
+{%- if grains.os == 'Ubuntu' and (grains.osrelease in ['10.04', '12.04']) %}
collectd_repo:
pkgrepo.managed:
@@ -9,16 +9,16 @@
- ppa: nikicat/collectd
- file: /etc/apt/sources.list.d/collectd.list
- require_in:
- - pkg: collectd_packages
+ - pkg: collectd_client_packages
collectd_amqp_packages:
pkg.installed:
- names:
- librabbitmq0
-{% endif %}
+{%- endif %}
-collectd_packages:
+collectd_client_packages:
pkg.installed:
- names: {{ client.pkgs }}
@@ -28,50 +28,53 @@
- mode: 750
- makedirs: true
- require:
- - pkg: collectd_packages
+ - pkg: collectd_client_packages
{{ client.config_dir }}:
file.directory:
- user: root
- mode: 750
- makedirs: true
+ - clean: true
- require:
- - pkg: collectd_packages
+ - pkg: collectd_client_packages
-{%- for service in client.supported_services %}
-{%- if service in grains.roles %}
-
-{%- for service_group in service.split('.') %}
-{%- if loop.first %}
-{{ client.config_dir }}/{{ service|replace('.', '_') }}.conf:
+collectd_client_plugins_grain:
file.managed:
- - source: salt://{{ service_group }}/files/collectd.conf
+ - name: /etc/salt/grains.d/collectd_plugins
+ - source: salt://collectd/files/plugins.grain
- template: jinja
- user: root
+ - mode: 600
+ - require:
+ - pkg: collectd_client_packages
+
+{%- set collectd_plugin_yaml = salt['cmd.run']('[ -e /etc/salt/grains.d/collectd_plugins ] && cat /etc/salt/grains.d/collectd_plugins || echo "collectd_plugin: {}"') %}
+{%- load_yaml as collectd_plugin %}
+{{ collectd_plugin_yaml }}
+{%- endload %}
+
+{%- for plugin_name, plugin in collectd_plugin.collectd_plugin.iteritems() %}
+
+{{ client.config_dir }}/{{ plugin_name }}.conf:
+ file.managed:
+ {%- if plugin.template is defined %}
+ - source: salt://{{ plugin.template }}
+ - template: jinja
+ - defaults:
+ plugin: {{ plugin|yaml }}
+ {%- else %}
+ - contents: "LoadPlugin {{ plugin.plugin }}"
+ {%- endif %}
+ - user: root
- mode: 660
- require:
- file: {{ client.config_dir }}
- watch_in:
- service: collectd_service
-{%- endif %}
-{%- endfor %}
-{%- endif %}
{%- endfor %}
-{%- if pillar.get('external', {}).network_device is defined %}
-{{ client.config_dir }}/plugin_snmp.conf:
- file.managed:
- - source: salt://collectd/files/plugin_snmp.conf
- - template: jinja
- - user: root
- - mode: 660
- - require:
- - file: {{ client.config_dir }}
- - watch_in:
- - service: collectd_service
-{%- endif %}
-
/etc/collectd/filters.conf:
file.managed:
- source: salt://collectd/files/filters.conf
@@ -110,7 +113,7 @@
{%- for backend_name, backend in client.backend.iteritems() %}
-{{ client.config_dir }}/{{ backend_name }}.conf:
+{{ client.config_dir }}/collectd_writer_{{ backend_name }}.conf:
file.managed:
- source: salt://collectd/files/backend/{{ backend.engine }}.conf
- template: jinja
@@ -131,6 +134,6 @@
- name: collectd
- enable: true
- require:
- - pkg: collectd_packages
+ - pkg: collectd_client_packages
-{%- endif %}
+{%- endif %}
\ No newline at end of file
diff --git a/collectd/files/collectd_plugins.yml b/collectd/files/collectd_plugins.yml
new file mode 100644
index 0000000..11323e4
--- /dev/null
+++ b/collectd/files/collectd_plugins.yml
@@ -0,0 +1,20 @@
+{%- if pillar.get('external', {}).network_device is defined %}
+collectd_network_device:
+ plugin: snmp
+ data:
+ std_traffic:
+ type: if_octets
+ table: true
+ instance: 1.3.6.1.2.1.31.1.1.1.1
+ values:
+ - 1.3.6.1.2.1.31.1.1.1.6
+ - 1.3.6.1.2.1.31.1.1.1.10
+ std_rate:
+ type: if_packets
+ table: true
+ instance: 1.3.6.1.2.1.31.1.1.1.1
+ values:
+ - 1.3.6.1.2.1.31.1.1.1.7
+ - 1.3.6.1.2.1.31.1.1.1.11
+ host: {{ pillar.external.network_device }}
+{%- endif %}
\ No newline at end of file
diff --git a/collectd/files/collectd_snmp.conf b/collectd/files/collectd_snmp.conf
new file mode 100644
index 0000000..8436469
--- /dev/null
+++ b/collectd/files/collectd_snmp.conf
@@ -0,0 +1,19 @@
+LoadPlugin snmp
+<Plugin snmp>
+ {%- for data_name, data in plugin.data.iteritems() %}
+ <Data "{{ data_name }}">
+ Type "{{ data.type }}"
+ Table true
+ Instance "{{ data.instance }}"
+ Values{%- for value in data.values %} "{{ value }}"{% endfor %}
+ </Data>
+ {%- endfor %}
+ {%- for host_name, host in plugin.host.iteritems() %}
+ <Host "{{ host_name }}">
+ Address "{{ host.address }}"
+ Version {{ host.get('version', '2') }}
+ Community "{{ host.community }}"
+ Collect{% for data_name, data in plugin.data.iteritems() %} "{{ data_name }}"{% endfor %}
+ </Host>
+ {%- endfor %}
+</Plugin>
diff --git a/collectd/files/plugin_snmp.conf b/collectd/files/plugin_snmp.conf
deleted file mode 100644
index 80c0924..0000000
--- a/collectd/files/plugin_snmp.conf
+++ /dev/null
@@ -1,26 +0,0 @@
-{%- if pillar.get('external', {}).network_device is defined %}
-LoadPlugin snmp
-
-<Plugin snmp>
- <Data "std_traffic">
- Type "if_octets"
- Table true
- Instance "1.3.6.1.2.1.31.1.1.1.1"
- Values "1.3.6.1.2.1.31.1.1.1.6" "1.3.6.1.2.1.31.1.1.1.10"
- </Data>
- <Data "std_rate">
- Type "if_packets"
- Table true
- Instance "1.3.6.1.2.1.31.1.1.1.1"
- Values "1.3.6.1.2.1.31.1.1.1.7" "1.3.6.1.2.1.31.1.1.1.11"
- </Data>
- {%- for device_name, device in pillar.external.network_device.iteritems() %}
- <Host "{{ device_name }}">
- Address "{{ device.management.address }}"
- Version {{ device.get('version', '2') }}
- Community "{{ device.community }}"
- Collect "std_traffic" "std_rate"
- </Host>
- {%- endfor %}
-</Plugin>
-{%- endif %}
diff --git a/collectd/files/plugins.grain b/collectd/files/plugins.grain
new file mode 100644
index 0000000..76279c4
--- /dev/null
+++ b/collectd/files/plugins.grain
@@ -0,0 +1,8 @@
+collectd_plugin:
+{%- for service_name, service in pillar.items() %}
+{%- if service.get('_support', {}).get('collectd', {}).get('enabled', False) %}
+{%- set grains_fragment_file = service_name+'/files/collectd_plugins.yml' %}
+{%- macro indent_grains_dict() %}{% include grains_fragment_file %}{% endmacro %}
+{{- indent_grains_dict()|indent(2, true) }}
+{%- endif %}
+{%- endfor %}
\ No newline at end of file
diff --git a/collectd/files/sensu_checks.yml b/collectd/files/sensu_checks.yml
new file mode 100644
index 0000000..76d4c52
--- /dev/null
+++ b/collectd/files/sensu_checks.yml
@@ -0,0 +1,6 @@
+local_collectd_proc:
+ command: "PATH=$PATH:/usr/lib64/nagios/plugins:/usr/lib/nagios/plugins check_procs -C collectd -u root -c 1:1"
+ interval: 60
+ occurrences: 1
+ subscribers:
+ - local-collectd-client
diff --git a/metadata/service/client/init.yml b/metadata/service/client/init.yml
index 9a1b0f6..cbf9f47 100644
--- a/metadata/service/client/init.yml
+++ b/metadata/service/client/init.yml
@@ -1,5 +1,7 @@
applications:
- collectd
+classes:
+- service.collectd.support
parameters:
collectd:
client:
diff --git a/metadata/service/support.yml b/metadata/service/support.yml
new file mode 100644
index 0000000..b51bbb4
--- /dev/null
+++ b/metadata/service/support.yml
@@ -0,0 +1,9 @@
+parameters:
+ collectd:
+ _support:
+ collectd:
+ enabled: true
+ heka:
+ enabled: false
+ sensu:
+ enabled: true