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