1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6 cfg = config.services.elasticsearch-curator;
7 curatorConfig = pkgs.writeTextFile {
8 name = "config.yaml";
9 text = ''
10 ---
11 # Remember, leave a key empty if there is no value. None will be a string,
12 # not a Python "NoneType"
13 client:
14 hosts: ${builtins.toJSON cfg.hosts}
15 port: ${toString cfg.port}
16 url_prefix:
17 use_ssl: False
18 certificate:
19 client_cert:
20 client_key:
21 ssl_no_validate: False
22 http_auth:
23 timeout: 30
24 master_only: False
25 logging:
26 loglevel: INFO
27 logfile:
28 logformat: default
29 blacklist: ['elasticsearch', 'urllib3']
30 '';
31 };
32 curatorAction = pkgs.writeTextFile {
33 name = "action.yaml";
34 text = cfg.actionYAML;
35 };
36in {
37
38 options.services.elasticsearch-curator = {
39
40 enable = mkEnableOption (lib.mdDoc "elasticsearch curator");
41 interval = mkOption {
42 description = lib.mdDoc "The frequency to run curator, a systemd.time such as 'hourly'";
43 default = "hourly";
44 type = types.str;
45 };
46 hosts = mkOption {
47 description = lib.mdDoc "a list of elasticsearch hosts to connect to";
48 type = types.listOf types.str;
49 default = ["localhost"];
50 };
51 port = mkOption {
52 description = lib.mdDoc "the port that elasticsearch is listening on";
53 type = types.port;
54 default = 9200;
55 };
56 actionYAML = mkOption {
57 description = lib.mdDoc "curator action.yaml file contents, alternatively use curator-cli which takes a simple action command";
58 type = types.lines;
59 example = ''
60 ---
61 actions:
62 1:
63 action: delete_indices
64 description: >-
65 Delete indices older than 45 days (based on index name), for logstash-
66 prefixed indices. Ignore the error if the filter does not result in an
67 actionable list of indices (ignore_empty_list) and exit cleanly.
68 options:
69 ignore_empty_list: True
70 disable_action: False
71 filters:
72 - filtertype: pattern
73 kind: prefix
74 value: logstash-
75 - filtertype: age
76 source: name
77 direction: older
78 timestring: '%Y.%m.%d'
79 unit: days
80 unit_count: 45
81 '';
82 };
83 };
84
85 config = mkIf cfg.enable {
86 systemd.services.elasticsearch-curator = {
87 startAt = cfg.interval;
88 serviceConfig = {
89 ExecStart =
90 "${pkgs.elasticsearch-curator}/bin/curator" +
91 " --config ${curatorConfig} ${curatorAction}";
92 };
93 };
94 };
95}