1 { config, lib, utils, pkgs, ... }:
12 cfg = config.services.filebeat;
14 json = pkgs.formats.json {};
21 enable = mkEnableOption (lib.mdDoc "filebeat");
25 default = pkgs.filebeat;
26 defaultText = literalExpression "pkgs.filebeat";
27 example = literalExpression "pkgs.filebeat7";
28 description = lib.mdDoc ''
29 The filebeat package to use.
34 description = lib.mdDoc ''
35 Inputs specify how Filebeat locates and processes input data.
37 This is like `services.filebeat.settings.filebeat.inputs`,
38 but structured as an attribute set. This has the benefit
39 that multiple NixOS modules can contribute settings to a
40 single filebeat input.
42 An input type can be specified multiple times by choosing a
43 different `<name>` for each, but setting
44 [](#opt-services.filebeat.inputs._name_.type)
47 See <https://www.elastic.co/guide/en/beats/filebeat/current/configuration-filebeat-options.html>.
50 type = types.attrsOf (types.submodule ({ name, ... }: {
51 freeformType = json.type;
56 description = lib.mdDoc ''
59 Look for the value after `type:` on
60 the individual input pages linked from
61 <https://www.elastic.co/guide/en/beats/filebeat/current/configuration-filebeat-options.html>.
66 example = literalExpression ''
68 journald.id = "everything"; # Only for filebeat7
80 description = lib.mdDoc ''
81 Filebeat modules provide a quick way to get started
82 processing common log formats. They contain default
83 configurations, Elasticsearch ingest pipeline definitions,
84 and Kibana dashboards to help you implement and deploy a log
87 This is like `services.filebeat.settings.filebeat.modules`,
88 but structured as an attribute set. This has the benefit
89 that multiple NixOS modules can contribute settings to a
90 single filebeat module.
92 A module can be specified multiple times by choosing a
93 different `<name>` for each, but setting
94 [](#opt-services.filebeat.modules._name_.module)
97 See <https://www.elastic.co/guide/en/beats/filebeat/current/filebeat-modules.html>.
100 type = types.attrsOf (types.submodule ({ name, ... }: {
101 freeformType = json.type;
106 description = lib.mdDoc ''
107 The name of the module.
109 Look for the value after `module:` on
110 the individual input pages linked from
111 <https://www.elastic.co/guide/en/beats/filebeat/current/filebeat-modules.html>.
116 example = literalExpression ''
121 var.paths = [ "/path/to/log/nginx/access.log*" ];
125 var.paths = [ "/path/to/log/nginx/error.log*" ];
132 settings = mkOption {
133 type = types.submodule {
134 freeformType = json.type;
138 output.elasticsearch.hosts = mkOption {
139 type = with types; listOf str;
140 default = [ "127.0.0.1:9200" ];
141 example = [ "myEShost:9200" ];
142 description = lib.mdDoc ''
143 The list of Elasticsearch nodes to connect to.
145 The events are distributed to these nodes in round
146 robin order. If one node becomes unreachable, the
147 event is automatically sent to another node. Each
148 Elasticsearch node can be defined as a URL or
149 IP:PORT. For example:
151 `https://es.found.io:9230` or
152 `192.24.3.2:9300`. If no port is
153 specified, `9200` is used.
159 type = types.listOf json.type;
162 description = lib.mdDoc ''
163 Inputs specify how Filebeat locates and processes
164 input data. Use [](#opt-services.filebeat.inputs) instead.
166 See <https://www.elastic.co/guide/en/beats/filebeat/current/configuration-filebeat-options.html>.
170 type = types.listOf json.type;
173 description = lib.mdDoc ''
174 Filebeat modules provide a quick way to get started
175 processing common log formats. They contain default
176 configurations, Elasticsearch ingest pipeline
177 definitions, and Kibana dashboards to help you
178 implement and deploy a log monitoring solution.
180 Use [](#opt-services.filebeat.modules) instead.
182 See <https://www.elastic.co/guide/en/beats/filebeat/current/filebeat-modules.html>.
189 example = literalExpression ''
192 output.elasticsearch = {
193 hosts = [ "myEShost:9200" ];
194 username = "filebeat_internal";
195 password = { _secret = "/var/keys/elasticsearch_password"; };
197 logging.level = "info";
202 description = lib.mdDoc ''
203 Configuration for filebeat. See
204 <https://www.elastic.co/guide/en/beats/filebeat/current/filebeat-reference-yml.html>
205 for supported values.
207 Options containing secret data should be set to an attribute
208 set containing the attribute `_secret` - a
209 string pointing to a file containing the value the option
210 should be set to. See the example to get a better picture of
211 this: in the resulting
212 {file}`filebeat.yml` file, the
213 `output.elasticsearch.password`
214 key will be set to the contents of the
215 {file}`/var/keys/elasticsearch_password` file.
221 config = mkIf cfg.enable {
223 services.filebeat.settings.filebeat.inputs = attrValues cfg.inputs;
224 services.filebeat.settings.filebeat.modules = attrValues cfg.modules;
226 systemd.services.filebeat = {
227 description = "Filebeat log shipper";
228 wantedBy = [ "multi-user.target" ];
229 wants = [ "elasticsearch.service" ];
230 after = [ "elasticsearch.service" ];
232 ExecStartPre = pkgs.writeShellScript "filebeat-exec-pre" ''
237 ${utils.genJqSecretsReplacementSnippet
239 "/var/lib/filebeat/filebeat.yml"
243 ${cfg.package}/bin/filebeat -e \
244 -c "/var/lib/filebeat/filebeat.yml" \
245 --path.data "/var/lib/filebeat"
248 StateDirectory = "filebeat";