nix

configuration files that power my machines
Log | Files | Refs | README | LICENSE

alertmanager.nix (1561B)


      1 {
      2   config,
      3   lib,
      4   haravara,
      5   ...
      6 }: let
      7   cfg = config.services.haravara.monitoring;
      8   authSnippet = haravara.mkAuthImport cfg.authLabel;
      9 in {
     10   options.services.haravara.monitoring.alertmanager = {
     11     enable = lib.mkEnableOption "Alertmanager for alert routing and notifications";
     12     domain = lib.mkOption {
     13       type = lib.types.nullOr lib.types.str;
     14       default = null;
     15       description = "Domain to expose the Alertmanager UI via Caddy (optional)";
     16     };
     17     port = lib.mkOption {
     18       type = lib.types.port;
     19       default = 9093;
     20     };
     21     configuration = lib.mkOption {
     22       type = lib.types.attrs;
     23       description = "Alertmanager configuration (route, receivers, etc.)";
     24       example = lib.literalExpression ''
     25         {
     26           route = {
     27             receiver = "default";
     28             group_wait = "30s";
     29             group_interval = "5m";
     30             repeat_interval = "4h";
     31           };
     32           receivers = [{
     33             name = "default";
     34             webhook_configs = [{ url = "https://example.com/hook"; }];
     35           }];
     36         }
     37       '';
     38     };
     39   };
     40 
     41   config = lib.mkIf (cfg.enable && cfg.alertmanager.enable) {
     42     services.prometheus.alertmanager = {
     43       enable = true;
     44       listenAddress = "127.0.0.1";
     45       inherit (cfg.alertmanager) port configuration;
     46     };
     47 
     48     services.caddy.virtualHosts = lib.optionalAttrs (cfg.alertmanager.domain != null) {
     49       "${cfg.alertmanager.domain}".extraConfig = ''
     50         ${authSnippet}
     51         reverse_proxy 127.0.0.1:${toString cfg.alertmanager.port}
     52       '';
     53     };
     54   };
     55 }