summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlassulus <lass@lassul.us>2017-01-28 18:36:53 +0100
committerlassulus <lass@lassul.us>2017-01-28 18:36:53 +0100
commit0112e59b1f40097fb1fe4dcc239ed082cc1ac0e7 (patch)
tree88c5e49c87959ec36ef5565d6b493b84daf1c8a5
parent97edec1f2dd9785d515fe99e031b38f8f379258a (diff)
l 3 kapacitor: add alert definition
-rw-r--r--lass/3modules/kapacitor.nix31
1 files changed, 31 insertions, 0 deletions
diff --git a/lass/3modules/kapacitor.nix b/lass/3modules/kapacitor.nix
index 8524c8198..a2ee71732 100644
--- a/lass/3modules/kapacitor.nix
+++ b/lass/3modules/kapacitor.nix
@@ -21,6 +21,14 @@ let
type = types.str;
default = "kapacitor";
};
+ alarms = mkOption {
+ type = with types; attrsOf str;
+ default = {};
+ };
+ check_db = mkOption {
+ type = types.str;
+ default = "kapacitor_example";
+ };
config = mkOption {
type = types.str;
#TODO: find a good default
@@ -216,6 +224,29 @@ let
ExecStart = "${pkgs.kapacitor}/bin/kapacitord -config ${configFile}";
};
};
+
+ systemd.services.kapacitor-alarms = {
+ description = "kapacitor-alarms";
+ after = [ "kapacitor.service" ];
+ wantedBy = [ "multi-user.target" ];
+
+ restartIfChanged = true;
+
+ serviceConfig = {
+ Type = "oneshot";
+ ExecStart = pkgs.writeDash "add_alarms" ''
+ ${pkgs.kapacitor}/bin/kapacitor delete tasks \*
+ ${concatStrings (mapAttrsToList (name: alarm: ''
+ ${pkgs.kapacitor}/bin/kapacitor define ${name} \
+ -type batch \
+ -tick ${pkgs.writeText "${name}.tick" alarm} \
+ -dbrp ${cfg.check_db}.default
+ ${pkgs.kapacitor}/bin/kapacitor enable ${name}
+ '') cfg.alarms)}
+ '';
+ };
+ };
+
};
in out