summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--lib/maintainers.nix1
-rw-r--r--nixos/modules/module-list.nix1
-rw-r--r--nixos/modules/services/logging/journalbeat.nix76
-rw-r--r--pkgs/tools/system/journalbeat/default.nix34
-rw-r--r--pkgs/top-level/all-packages.nix2
5 files changed, 114 insertions, 0 deletions
diff --git a/lib/maintainers.nix b/lib/maintainers.nix
index 1e9a6fe0f0d..43e79fa2d32 100644
--- a/lib/maintainers.nix
+++ b/lib/maintainers.nix
@@ -290,6 +290,7 @@
   mbbx6spp = "Susan Potter <me@susanpotter.net>";
   mbe = "Brandon Edens <brandonedens@gmail.com>";
   mboes = "Mathieu Boespflug <mboes@tweag.net>";
+  mbrgm = "Marius Bergmann <marius@yeai.de>";
   mcmtroffaes = "Matthias C. M. Troffaes <matthias.troffaes@gmail.com>";
   mdaiter = "Matthew S. Daiter <mdaiter8121@gmail.com>";
   meditans = "Carlo Nucera <meditans@gmail.com>";
diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix
index 4ec4c5a6f5b..6ec5ac73b21 100644
--- a/nixos/modules/module-list.nix
+++ b/nixos/modules/module-list.nix
@@ -212,6 +212,7 @@
   ./services/logging/awstats.nix
   ./services/logging/fluentd.nix
   ./services/logging/graylog.nix
+  ./services/logging/journalbeat.nix
   ./services/logging/klogd.nix
   ./services/logging/logcheck.nix
   ./services/logging/logrotate.nix
diff --git a/nixos/modules/services/logging/journalbeat.nix b/nixos/modules/services/logging/journalbeat.nix
new file mode 100644
index 00000000000..8186a3b02c3
--- /dev/null
+++ b/nixos/modules/services/logging/journalbeat.nix
@@ -0,0 +1,76 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+
+let
+  cfg = config.services.journalbeat;
+
+  journalbeatYml = pkgs.writeText "journalbeat.yml" ''
+    name: ${cfg.name}
+    tags: ${builtins.toJSON cfg.tags}
+
+    journalbeat.cursor_state_file: ${cfg.stateDir}/cursor-state
+
+    ${cfg.extraConfig}
+  '';
+
+in
+{
+  options = {
+
+    services.journalbeat = {
+
+      enable = mkEnableOption "journalbeat";
+
+      name = mkOption {
+        type = types.str;
+        default = "journalbeat";
+        description = "Name of the beat";
+      };
+
+      tags = mkOption {
+        type = types.listOf types.str;
+        default = [];
+        description = "Tags to place on the shipped log messages";
+      };
+
+      stateDir = mkOption {
+        type = types.str;
+        default = "/var/lib/journalbeat";
+        description = "The state directory. Journalbeat's own logs and other data are stored here.";
+      };
+
+      extraConfig = mkOption {
+        type = types.lines;
+        default = ''
+          journalbeat:
+            seek_position: cursor
+            cursor_seek_fallback: tail
+            write_cursor_state: true
+            cursor_flush_period: 5s
+            clean_field_names: true
+            convert_to_numbers: false
+            move_metadata_to_field: journal
+            default_type: journal
+        '';
+        description = "Any other configuration options you want to add";
+      };
+
+    };
+  };
+
+  config = mkIf cfg.enable {
+
+    systemd.services.journalbeat = with pkgs; {
+      description = "Journalbeat log shipper";
+      wantedBy = [ "multi-user.target" ];
+      preStart = ''
+        mkdir -p ${cfg.stateDir}/data
+        mkdir -p ${cfg.stateDir}/logs
+      '';
+      serviceConfig = {
+        ExecStart = "${pkgs.journalbeat}/bin/journalbeat -c ${journalbeatYml} -path.data ${cfg.stateDir}/data -path.logs ${cfg.stateDir}/logs";
+      };
+    };
+  };
+}
diff --git a/pkgs/tools/system/journalbeat/default.nix b/pkgs/tools/system/journalbeat/default.nix
new file mode 100644
index 00000000000..5a66fcf5299
--- /dev/null
+++ b/pkgs/tools/system/journalbeat/default.nix
@@ -0,0 +1,34 @@
+{ lib, pkgs, buildGoPackage, fetchFromGitHub, makeWrapper }:
+
+let
+
+  libPath = lib.makeLibraryPath [ pkgs.systemd.lib ];
+
+in buildGoPackage rec {
+
+  name = "journalbeat-${version}";
+  version = "5.1.2";
+
+  goPackagePath = "github.com/mheese/journalbeat";
+
+  buildInputs = [ makeWrapper pkgs.systemd ];
+
+  postInstall = ''
+    wrapProgram $bin/bin/journalbeat \
+      --prefix LD_LIBRARY_PATH : ${libPath}
+  '';
+
+  src = fetchFromGitHub {
+    owner = "mheese";
+    repo = "journalbeat";
+    rev = "v${version}";
+    sha256 = "179jayzvd5k4mwhn73yflbzl5md1fmv7a9hb8vz2ir76lvr33g3l";
+  };
+
+  meta = with lib; {
+    homepage = https://github.com/mheese/journalbeat;
+    description = "Journalbeat is a log shipper from systemd/journald to Logstash/Elasticsearch";
+    license = licenses.asl20;
+    maintainers = with maintainers; [ mbrgm ];
+  };
+}
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index d17bd889df5..f8f5421ecc7 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -2361,6 +2361,8 @@ in
     gcc = gcc49; # doesn't build with gcc5
   };
 
+  journalbeat = callPackage ../tools/system/journalbeat { };
+
   jp = callPackage ../development/tools/jp { };
 
   jp2a = callPackage ../applications/misc/jp2a { };