{ config, pkgs, ... }:
{
  sops.secrets.xmpp-password = {
    owner = "solid-xmpp-alarm";
    group = "solid-xmpp-alarm";
  };

  services.solid-xmpp-alarm = {
    enable = true;
    jid = "feuer@fem-net.de";
    passwordFile = config.sops.secrets.xmpp-password.path;
    receiver = "clerie@fem-net.de";
  };

  services.prometheus.alertmanager = {
    enable = true;
    listenAddress = "[::1]";
    port = 9093;
    configuration = {
      route = {
        receiver = "xmpp-receiver";
        repeat_interval = "4h";
        group_by = [ "instance" ];
        routes = [
          {
            matchers = [
              ''severity = "muted"''
            ];
            receiver = "muted";
          }
          {
            receiver = "xmpp-receiver";
            matchers = [
              ''severity = "warning"''
            ];
            repeat_interval = "70h";
          }
        ];
      };
      receivers = [
        {
          name = "muted";
        }
        {
          name = "xmpp-receiver";
          webhook_configs = [
            {
              url = "http://[::1]:9199/alert";
            }
          ];
        }
      ];
      inhibit_rules = [
        {
          # Mute all alerts for an instance which also has an alert starting with MuteInstanceOn
          target_matchers = [
            ''alertname =~ ".+"''
          ];
          source_matchers = [
            ''mute = "instance"''
          ];
          equal = [
            "instance"
          ];
        }
        {
          target_matchers = [
            ''alertname = "StorageAlmostFull"''
          ];
          source_matchers = [
            ''alertname = "StorageFull"''
          ];
          equal = [
            "instance"
            "mountpoint"
          ];
        }
      ];
    };
  };

}