summary refs log tree commit diff
path: root/nixos/modules/services/logging/logstash.nix
diff options
context:
space:
mode:
authorJaka Hudoklin <jakahudoklin@gmail.com>2013-10-12 12:28:48 +0200
committerJaka Hudoklin <jakahudoklin@gmail.com>2013-11-01 17:15:53 +0100
commit10e61f53d8d4cd9aa8eefa93ddd23c5428784720 (patch)
treee236d5f92d2b53d9c3c8cbb22e91112da7ff6b26 /nixos/modules/services/logging/logstash.nix
parent9ef07d859b23840e1a5d7d7125a6982720afa391 (diff)
downloadnixlib-10e61f53d8d4cd9aa8eefa93ddd23c5428784720.tar
nixlib-10e61f53d8d4cd9aa8eefa93ddd23c5428784720.tar.gz
nixlib-10e61f53d8d4cd9aa8eefa93ddd23c5428784720.tar.bz2
nixlib-10e61f53d8d4cd9aa8eefa93ddd23c5428784720.tar.lz
nixlib-10e61f53d8d4cd9aa8eefa93ddd23c5428784720.tar.xz
nixlib-10e61f53d8d4cd9aa8eefa93ddd23c5428784720.tar.zst
nixlib-10e61f53d8d4cd9aa8eefa93ddd23c5428784720.zip
nixos/logstash: update and simplify to be fully compatible with new version
Diffstat (limited to 'nixos/modules/services/logging/logstash.nix')
-rw-r--r--nixos/modules/services/logging/logstash.nix143
1 files changed, 22 insertions, 121 deletions
diff --git a/nixos/modules/services/logging/logstash.nix b/nixos/modules/services/logging/logstash.nix
index 79bdf4f7bbca..373476c66999 100644
--- a/nixos/modules/services/logging/logstash.nix
+++ b/nixos/modules/services/logging/logstash.nix
@@ -3,72 +3,8 @@
 with pkgs.lib;
 
 let
-
   cfg = config.services.logstash;
 
-  listToConfig = list: "[ " + (concatStringsSep ", " (map exprToConfig list)) + " ]";
-
-  hashToConfig = attrs:
-    let
-      attrNameToConfigList = name:
-        [ (exprToConfig name)  (exprToConfig (getAttr name attrs)) ];
-    in
-      "[ " +
-      (concatStringsSep ", " (map attrNameToConfigList (attrNames attrs))) +
-      " ]";
-
-  valueToConfig = nvpair: let name = nvpair.name; value = nvpair.value; in
-    if (isAttrs value) && ((!(value ? __type)) || value.__type == "repeated")
-      then ''
-        ${name} {
-          ${exprToConfig value}
-        }
-      ''
-      else "${name} => ${exprToConfig value}";
-
-  repeatedAttrsToConfig = values:
-      concatStringsSep "\n" (map valueToConfig values);
-
-  attrsToConfig = attrs:
-    let
-      attrToConfig = name: valueToConfig {
-        inherit name;
-        value = (getAttr name attrs);
-      };
-    in
-      concatStringsSep "\n" (map attrToConfig (attrNames attrs));
-
-  exprToConfig = expr:
-    let
-      isCustomType = expr: (isAttrs expr) && (expr ? __type);
-
-      isFloat = expr: (isCustomType expr) && (expr.__type == "float");
-
-      isHash = expr: (isCustomType expr) && (expr.__type == "hash");
-
-      isRepeatedAttrs = expr: (isCustomType expr) && (expr.__type == "repeated");
-    in
-      if builtins.isBool expr then (if expr then "true" else "false") else
-      if builtins.isString expr then ''"${expr}"'' else
-      if builtins.isInt expr then toString expr else
-      if isFloat expr then expr.value else
-      if isList expr then listToConfig expr else
-      if isHash expr then hashToConfig expr.value else
-      if isRepeatedAttrs expr then repeatedAttrsToConfig expr.values
-      else attrsToConfig expr;
-
-  mergeConfigs = configs:
-    let
-      op = attrs: newAttrs:
-        let
-          isRepeated = newAttrs ? __type && newAttrs.__type == "repeated";
-        in {
-            values = attrs.values ++ (if isRepeated then newAttrs.values else
-              map (name: { inherit name; value = getAttr name newAttrs; })
-              (attrNames newAttrs));
-          };
-    in (foldl op { values = []; } configs) // { __type = "repeated"; };
-
 in
 
 {
@@ -78,48 +14,22 @@ in
     services.logstash = {
       enable = mkOption {
         default = false;
-        description = ''
-          Enable logstash.
-        '';
+        description = "Enable logstash";
       };
 
       inputConfig = mkOption {
-        default = {};
-        description = ''
-          An attribute set (or an expression generated by mkNameValuePairs)
-          representing a logstash configuration's input section.
-          Logstash configs are name-value pairs, where values can be bools,
-          strings, numbers, arrays, hashes, or other name-value pairs,
-          and names are strings that can be repeated. Name-value pairs with no
-          repeats are represented by attr sets. Bools, strings, ints, and
-          arrays are mapped directly. Name-value pairs with repeats can be
-          generated by the config.lib.logstash.mkNameValuePairs function, which
-          takes a list of attrsets and combines them while preserving attribute
-          name duplicates if they occur. Similarly, there are the mkFloat and
-          mkHash functions, which take a string representation of a float and an
-          attrset, respectively.
-        '';
-        apply = mergeConfigs;
+        default = ''stdin { type => "example" }'';
+        description = "Logstash input configuration";
       };
 
       filterConfig = mkOption {
-        default = {};
-        description = ''
-          An attribute set (or an expression generated by mkNameValuePairs)
-          representing a logstash configuration's filter section.
-          See inputConfig description for details.
-        '';
-        apply = mergeConfigs;
+        default = ''noop {}'';
+        description = "logstash filter configuration";
       };
 
       outputConfig = mkOption {
-        default = {};
-        description = ''
-          An attribute set (or an expression generated by mkNameValuePairs)
-          representing a logstash configuration's output section.
-          See inputConfig description for details.
-        '';
-        apply = mergeConfigs;
+        default = ''stdout { debug => true debug_format => "json"}'';
+        description = "Logstash output configuration";
       };
     };
   };
@@ -127,35 +37,26 @@ in
 
   ###### implementation
 
-  config = mkMerge [ {
-    lib.logstash = {
-      mkFloat = stringRep: { __type = "float"; value = stringRep; };
-
-      mkHash = attrs: { __type = "hash"; value = attrs; };
-
-      mkNameValuePairs = mergeConfigs;
-    };
-  } ( mkIf cfg.enable {
+  config = mkIf cfg.enable {
     systemd.services.logstash = with pkgs; {
       description = "Logstash daemon";
-
       wantedBy = [ "multi-user.target" ];
 
-      path = [ jre ];
-
-      script = "cd /tmp && exec java -jar ${logstash} agent -f ${writeText "logstash.conf" ''
-        input {
-          ${exprToConfig cfg.inputConfig}
-        }
+      serviceConfig = {
+        ExecStart = "${jre}/bin/java -jar ${logstash} agent -f ${writeText "logstash.conf" ''
+          input {
+            ${cfg.inputConfig}
+          }
 
-        filter {
-          ${exprToConfig cfg.filterConfig}
-        }
+          filter {
+            ${cfg.filterConfig}
+          }
 
-        output {
-          ${exprToConfig cfg.outputConfig}
-        }
-      ''} &> /var/log/logstash.log";
+          output {
+            ${cfg.outputConfig}
+          }
+        ''}";
+      };
     };
-  })];
+  };
 }