2018-08-01 18:21:10 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.elasticsearch-curator;
|
|
|
|
curatorConfig = pkgs.writeTextFile {
|
|
|
|
name = "config.yaml";
|
|
|
|
text = ''
|
|
|
|
---
|
|
|
|
# Remember, leave a key empty if there is no value. None will be a string,
|
|
|
|
# not a Python "NoneType"
|
|
|
|
client:
|
|
|
|
hosts: ${builtins.toJSON cfg.hosts}
|
2018-08-21 17:24:52 +02:00
|
|
|
port: ${toString cfg.port}
|
2018-08-01 18:21:10 +02:00
|
|
|
url_prefix:
|
|
|
|
use_ssl: False
|
|
|
|
certificate:
|
|
|
|
client_cert:
|
|
|
|
client_key:
|
|
|
|
ssl_no_validate: False
|
|
|
|
http_auth:
|
|
|
|
timeout: 30
|
|
|
|
master_only: False
|
|
|
|
logging:
|
|
|
|
loglevel: INFO
|
|
|
|
logfile:
|
|
|
|
logformat: default
|
|
|
|
blacklist: ['elasticsearch', 'urllib3']
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
curatorAction = pkgs.writeTextFile {
|
|
|
|
name = "action.yaml";
|
|
|
|
text = cfg.actionYAML;
|
|
|
|
};
|
|
|
|
in {
|
|
|
|
|
|
|
|
options.services.elasticsearch-curator = {
|
|
|
|
|
2024-04-13 14:54:15 +02:00
|
|
|
enable = mkEnableOption "elasticsearch curator";
|
2018-08-01 18:21:10 +02:00
|
|
|
interval = mkOption {
|
2024-04-13 14:54:15 +02:00
|
|
|
description = "The frequency to run curator, a systemd.time such as 'hourly'";
|
2018-08-01 18:21:10 +02:00
|
|
|
default = "hourly";
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
hosts = mkOption {
|
2024-04-13 14:54:15 +02:00
|
|
|
description = "a list of elasticsearch hosts to connect to";
|
2018-08-01 18:21:10 +02:00
|
|
|
type = types.listOf types.str;
|
|
|
|
default = ["localhost"];
|
|
|
|
};
|
|
|
|
port = mkOption {
|
2024-04-13 14:54:15 +02:00
|
|
|
description = "the port that elasticsearch is listening on";
|
2022-11-30 17:15:00 +01:00
|
|
|
type = types.port;
|
2018-08-01 18:21:10 +02:00
|
|
|
default = 9200;
|
|
|
|
};
|
|
|
|
actionYAML = mkOption {
|
2024-04-13 14:54:15 +02:00
|
|
|
description = "curator action.yaml file contents, alternatively use curator-cli which takes a simple action command";
|
2021-01-26 20:52:23 +01:00
|
|
|
type = types.lines;
|
2018-08-01 18:21:10 +02:00
|
|
|
example = ''
|
|
|
|
---
|
|
|
|
actions:
|
|
|
|
1:
|
|
|
|
action: delete_indices
|
|
|
|
description: >-
|
|
|
|
Delete indices older than 45 days (based on index name), for logstash-
|
|
|
|
prefixed indices. 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
|
|
|
|
disable_action: False
|
|
|
|
filters:
|
|
|
|
- filtertype: pattern
|
|
|
|
kind: prefix
|
|
|
|
value: logstash-
|
|
|
|
- filtertype: age
|
|
|
|
source: name
|
|
|
|
direction: older
|
|
|
|
timestring: '%Y.%m.%d'
|
|
|
|
unit: days
|
|
|
|
unit_count: 45
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
systemd.services.elasticsearch-curator = {
|
|
|
|
startAt = cfg.interval;
|
|
|
|
serviceConfig = {
|
2018-11-30 00:12:42 +01:00
|
|
|
ExecStart =
|
2019-03-21 11:44:08 +01:00
|
|
|
"${pkgs.elasticsearch-curator}/bin/curator" +
|
2018-11-30 00:12:42 +01:00
|
|
|
" --config ${curatorConfig} ${curatorAction}";
|
2018-08-01 18:21:10 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|