···
1
+
{ config, lib, utils, pkgs, ... }:
12
+
cfg = config.services.filebeat;
14
+
json = pkgs.formats.json {};
19
+
services.filebeat = {
21
+
enable = mkEnableOption "filebeat";
23
+
package = mkOption {
24
+
type = types.package;
25
+
default = pkgs.filebeat;
26
+
defaultText = literalExpression "pkgs.filebeat";
27
+
example = literalExpression "pkgs.filebeat7";
29
+
The filebeat package to use.
35
+
Inputs specify how Filebeat locates and processes input data.
37
+
This is like <literal>services.filebeat.settings.filebeat.inputs</literal>,
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 <literal><name></literal> for each, but setting
44
+
<xref linkend="opt-services.filebeat.inputs._name_.type"/>
47
+
See <link xlink:href="https://www.elastic.co/guide/en/beats/filebeat/current/configuration-filebeat-options.html"/>.
50
+
type = types.attrsOf (types.submodule ({ name, ... }: {
51
+
freeformType = json.type;
59
+
Look for the value after <literal>type:</literal> on
60
+
the individual input pages linked from
61
+
<link xlink:href="https://www.elastic.co/guide/en/beats/filebeat/current/configuration-filebeat-options.html"/>.
66
+
example = literalExpression ''
68
+
journald.id = "everything"; # Only for filebeat7
79
+
modules = mkOption {
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
85
+
monitoring solution.
87
+
This is like <literal>services.filebeat.settings.filebeat.modules</literal>,
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 <literal><name></literal> for each, but setting
94
+
<xref linkend="opt-services.filebeat.modules._name_.module"/>
97
+
See <link xlink:href="https://www.elastic.co/guide/en/beats/filebeat/current/filebeat-modules.html"/>.
100
+
type = types.attrsOf (types.submodule ({ name, ... }: {
101
+
freeformType = json.type;
103
+
module = mkOption {
107
+
The name of the module.
109
+
Look for the value after <literal>module:</literal> on
110
+
the individual input pages linked from
111
+
<link xlink:href="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" ];
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:
150
+
<literal>http://192.15.3.2</literal>,
151
+
<literal>https://es.found.io:9230</literal> or
152
+
<literal>192.24.3.2:9300</literal>. If no port is
153
+
specified, <literal>9200</literal> is used.
158
+
inputs = mkOption {
159
+
type = types.listOf json.type;
163
+
Inputs specify how Filebeat locates and processes
164
+
input data. Use <xref
165
+
linkend="opt-services.filebeat.inputs"/> instead.
167
+
See <link xlink:href="https://www.elastic.co/guide/en/beats/filebeat/current/configuration-filebeat-options.html"/>.
170
+
modules = mkOption {
171
+
type = types.listOf json.type;
175
+
Filebeat modules provide a quick way to get started
176
+
processing common log formats. They contain default
177
+
configurations, Elasticsearch ingest pipeline
178
+
definitions, and Kibana dashboards to help you
179
+
implement and deploy a log monitoring solution.
181
+
Use <xref linkend="opt-services.filebeat.modules"/> instead.
183
+
See <link xlink:href="https://www.elastic.co/guide/en/beats/filebeat/current/filebeat-modules.html"/>.
190
+
example = literalExpression ''
193
+
output.elasticsearch = {
194
+
hosts = [ "myEShost:9200" ];
195
+
username = "filebeat_internal";
196
+
password = { _secret = "/var/keys/elasticsearch_password"; };
198
+
logging.level = "info";
204
+
Configuration for filebeat. See
205
+
<link xlink:href="https://www.elastic.co/guide/en/beats/filebeat/current/filebeat-reference-yml.html"/>
206
+
for supported values.
208
+
Options containing secret data should be set to an attribute
209
+
set containing the attribute <literal>_secret</literal> - a
210
+
string pointing to a file containing the value the option
211
+
should be set to. See the example to get a better picture of
212
+
this: in the resulting
213
+
<filename>filebeat.yml</filename> file, the
214
+
<literal>output.elasticsearch.password</literal>
215
+
key will be set to the contents of the
216
+
<filename>/var/keys/elasticsearch_password</filename> file.
222
+
config = mkIf cfg.enable {
224
+
services.filebeat.settings.filebeat.inputs = attrValues cfg.inputs;
225
+
services.filebeat.settings.filebeat.modules = attrValues cfg.modules;
227
+
systemd.services.filebeat = {
228
+
description = "Filebeat log shipper";
229
+
wantedBy = [ "multi-user.target" ];
230
+
wants = [ "elasticsearch.service" ];
231
+
after = [ "elasticsearch.service" ];
233
+
ExecStartPre = pkgs.writeShellScript "filebeat-exec-pre" ''
238
+
${utils.genJqSecretsReplacementSnippet
240
+
"/var/lib/filebeat/filebeat.yml"
244
+
${cfg.package}/bin/filebeat -e \
245
+
-c "/var/lib/filebeat/filebeat.yml" \
246
+
--path.data "/var/lib/filebeat"
248
+
Restart = "always";
249
+
StateDirectory = "filebeat";