Add support for curator
diff --git a/README.rst b/README.rst
index 0c7021f..7e9ccce 100644
--- a/README.rst
+++ b/README.rst
@@ -47,6 +47,78 @@
shards: 5
replicas: 1
+Common definition for curator:
+
+.. code-block:: yaml
+
+ elasticsearch:
+ server:
+ curator:
+ timeout: 900
+ logfile: /var/log/elasticsearch/curator.log
+ logformat: json
+ actions:
+ - action: delete_indices
+ description: >-
+ Delete indices older than 45 days (based on index name).
+ Ignore the error if the filter does not result in an actionable
+ list of indices (ignore_empty_list) and exit cleanly.
+ options:
+ ignore_empty_list: True
+ continue_if_exception: False
+ disable_action: False
+ filters:
+ - filtertype: pattern
+ kind: regex
+ value: '.*\-\d\d\d\d\.\d\d\.\d\d$'
+ - filtertype: age
+ source: name
+ direction: older
+ timestring: '%Y.%m.%d'
+ unit: days
+ unit_count: 90
+ - action: replicas
+ description: >-
+ Reduce the replica count to 0 for indices older than 30 days
+ (based on index creation_date)
+ options:
+ count: 0
+ wait_for_completion: False
+ continue_if_exception: False
+ disable_action: False
+ filters:
+ - filtertype: pattern
+ kind: regex
+ value: '.*\-\d\d\d\d\.\d\d\.\d\d$'
+ - filtertype: age
+ source: creation_date
+ direction: older
+ unit: days
+ unit_count: 30
+ - action: forcemerge
+ description: >-
+ forceMerge indices older than 2 days (based on index
+ creation_date) to 2 segments per shard. Delay 120 seconds
+ between each forceMerge operation to allow the cluster to
+ quiesce.
+ This action will ignore indices already forceMerged to the same
+ or fewer number of segments per shard, so the 'forcemerged'
+ filter is unneeded.
+ options:
+ max_num_segments: 2
+ delay: 120
+ continue_if_exception: False
+ disable_action: True
+ filters:
+ - filtertype: pattern
+ kind: regex
+ value: '.*\-\d\d\d\d\.\d\d\.\d\d$'
+ - filtertype: age
+ source: creation_date
+ direction: older
+ unit: days
+ unit_count: 2
+
Read more
=========
diff --git a/elasticsearch/files/curator.yml b/elasticsearch/files/curator.yml
new file mode 100644
index 0000000..6bb8f1e
--- /dev/null
+++ b/elasticsearch/files/curator.yml
@@ -0,0 +1,25 @@
+{%- from "elasticsearch/map.jinja" import server with context -%}
+---
+# Remember, leave a key empty if there is no value. None will be a string,
+# not a Python "NoneType"
+client:
+ hosts:
+ - {% if server.bind.address == '0.0.0.0' %}127.0.0.1{% else %}{{ server.bind.address }}{% endif %}
+ port: {{ server.bind.port }}
+ url_prefix:
+ use_ssl: False
+ certificate:
+ client_cert:
+ client_key:
+ aws_key:
+ aws_secret_key:
+ aws_region:
+ ssl_no_validate: False
+ http_auth:
+ timeout: {{ server.curator.timeout|default(120) }}
+ master_only: False
+
+logging:
+ loglevel: {{ server.curator.loglevel|default("INFO") }}
+ logfile: {{ server.curator.logfile|default("") }}
+ logformat: {{ server.curator.logformat|default("default") }}
diff --git a/elasticsearch/files/curator_actions.yml b/elasticsearch/files/curator_actions.yml
new file mode 100644
index 0000000..8fafe1a
--- /dev/null
+++ b/elasticsearch/files/curator_actions.yml
@@ -0,0 +1,7 @@
+{%- from "elasticsearch/map.jinja" import server with context -%}
+---
+actions:
+ {%- for action in server.curator.actions %}
+ {{ loop.index }}:
+ {{ action|yaml }}
+ {%- endfor %}
diff --git a/elasticsearch/map.jinja b/elasticsearch/map.jinja
index 392295f..000a1f4 100644
--- a/elasticsearch/map.jinja
+++ b/elasticsearch/map.jinja
@@ -4,11 +4,15 @@
Debian:
pkgs:
- elasticsearch
+ curator_pkgs:
+ - python-elasticsearch-curator
service: elasticsearch
version: '1.4.4'
RedHat:
pkgs:
- elasticsearch
+ curator_pkgs:
+ - python-elasticsearch-curator
service: elasticsearch
version: '1.4.4'
{%- endload %}
diff --git a/elasticsearch/server/curator.sls b/elasticsearch/server/curator.sls
new file mode 100644
index 0000000..9cdfc13
--- /dev/null
+++ b/elasticsearch/server/curator.sls
@@ -0,0 +1,32 @@
+{%- from "elasticsearch/map.jinja" import server with context %}
+
+elasticsearch_curator_packages:
+ pkg.installed:
+ - names: {{ server.curator_pkgs }}
+
+elasticsearch_curator_config:
+ file.managed:
+ - name: /etc/elasticsearch/curator.yml
+ - source: salt://elasticsearch/files/curator.yml
+ - group: elasticsearch
+ - mode: 750
+ - template: jinja
+ - require:
+ - pkg: elasticsearch_packages
+
+elasticsearch_curator_action_config:
+ file.managed:
+ - name: /etc/elasticsearch/curator_actions.yml
+ - source: salt://elasticsearch/files/curator_actions.yml
+ - group: elasticsearch
+ - mode: 750
+ - template: jinja
+ - require:
+ - file: elasticsearch_curator_config
+
+elasticsearch_curator_cron:
+ cron.present:
+ - name: "curator --config /etc/elasticsearch/curator.yml /etc/elasticsearch/curator_actions.yml >/dev/null"
+ - user: elasticsearch
+ - minute: random
+ - hour: 1
diff --git a/elasticsearch/server.sls b/elasticsearch/server/init.sls
similarity index 89%
rename from elasticsearch/server.sls
rename to elasticsearch/server/init.sls
index ea392ad..36e9398 100644
--- a/elasticsearch/server.sls
+++ b/elasticsearch/server/init.sls
@@ -3,6 +3,9 @@
include:
- java
+ {%- if server.curator is defined %}
+ - elasticsearch.server.curator
+ {%- endif %}
elasticsearch_packages:
pkg.installed: