at 18.09-beta 2.7 kB view raw
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 "elasticsearch curator"; 41 interval = mkOption { 42 description = "The frequency to run curator, a systemd.time such as 'hourly'"; 43 default = "hourly"; 44 type = types.str; 45 }; 46 hosts = mkOption { 47 description = "a list of elasticsearch hosts to connect to"; 48 type = types.listOf types.str; 49 default = ["localhost"]; 50 }; 51 port = mkOption { 52 description = "the port that elasticsearch is listening on"; 53 type = types.int; 54 default = 9200; 55 }; 56 actionYAML = mkOption { 57 description = "curator action.yaml file contents, alternatively use curator-cli which takes a simple action command"; 58 example = '' 59 --- 60 actions: 61 1: 62 action: delete_indices 63 description: >- 64 Delete indices older than 45 days (based on index name), for logstash- 65 prefixed indices. Ignore the error if the filter does not result in an 66 actionable list of indices (ignore_empty_list) and exit cleanly. 67 options: 68 ignore_empty_list: True 69 disable_action: False 70 filters: 71 - filtertype: pattern 72 kind: prefix 73 value: logstash- 74 - filtertype: age 75 source: name 76 direction: older 77 timestring: '%Y.%m.%d' 78 unit: days 79 unit_count: 45 80 ''; 81 }; 82 }; 83 84 config = mkIf cfg.enable { 85 86 systemd.services.elasticsearch-curator = { 87 startAt = cfg.interval; 88 serviceConfig = { 89 ExecStart = ''${pkgs.python36Packages.elasticsearch-curator}/bin/curator --config ${curatorConfig} ${curatorAction}''; 90 }; 91 }; 92 }; 93}