at 24.11-pre 3.1 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 cfg = config.services.alerta; 7 8 alertaConf = pkgs.writeTextFile { 9 name = "alertad.conf"; 10 text = '' 11 DATABASE_URL = '${cfg.databaseUrl}' 12 DATABASE_NAME = '${cfg.databaseName}' 13 LOG_FILE = '${cfg.logDir}/alertad.log' 14 LOG_FORMAT = '%(asctime)s - %(name)s - %(levelname)s - %(message)s' 15 CORS_ORIGINS = [ ${concatMapStringsSep ", " (s: "\"" + s + "\"") cfg.corsOrigins} ]; 16 AUTH_REQUIRED = ${if cfg.authenticationRequired then "True" else "False"} 17 SIGNUP_ENABLED = ${if cfg.signupEnabled then "True" else "False"} 18 ${cfg.extraConfig} 19 ''; 20 }; 21in 22{ 23 options.services.alerta = { 24 enable = mkEnableOption "alerta"; 25 26 port = mkOption { 27 type = types.port; 28 default = 5000; 29 description = "Port of Alerta"; 30 }; 31 32 bind = mkOption { 33 type = types.str; 34 default = "0.0.0.0"; 35 description = "Address to bind to. The default is to bind to all addresses"; 36 }; 37 38 logDir = mkOption { 39 type = types.path; 40 description = "Location where the logfiles are stored"; 41 default = "/var/log/alerta"; 42 }; 43 44 databaseUrl = mkOption { 45 type = types.str; 46 description = "URL of the MongoDB or PostgreSQL database to connect to"; 47 default = "mongodb://localhost"; 48 }; 49 50 databaseName = mkOption { 51 type = types.str; 52 description = "Name of the database instance to connect to"; 53 default = "monitoring"; 54 }; 55 56 corsOrigins = mkOption { 57 type = types.listOf types.str; 58 description = "List of URLs that can access the API for Cross-Origin Resource Sharing (CORS)"; 59 default = [ "http://localhost" "http://localhost:5000" ]; 60 }; 61 62 authenticationRequired = mkOption { 63 type = types.bool; 64 description = "Whether users must authenticate when using the web UI or command-line tool"; 65 default = false; 66 }; 67 68 signupEnabled = mkOption { 69 type = types.bool; 70 description = "Whether to prevent sign-up of new users via the web UI"; 71 default = true; 72 }; 73 74 extraConfig = mkOption { 75 description = "These lines go into alertad.conf verbatim."; 76 default = ""; 77 type = types.lines; 78 }; 79 }; 80 81 config = mkIf cfg.enable { 82 systemd.tmpfiles.settings."10-alerta".${cfg.logDir}.d = { 83 user = "alerta"; 84 group = "alerta"; 85 }; 86 87 systemd.services.alerta = { 88 description = "Alerta Monitoring System"; 89 wantedBy = [ "multi-user.target" ]; 90 after = [ "networking.target" ]; 91 environment = { 92 ALERTA_SVR_CONF_FILE = alertaConf; 93 }; 94 serviceConfig = { 95 ExecStart = "${pkgs.alerta-server}/bin/alertad run --port ${toString cfg.port} --host ${cfg.bind}"; 96 User = "alerta"; 97 Group = "alerta"; 98 }; 99 }; 100 101 environment.systemPackages = [ pkgs.alerta ]; 102 103 users.users.alerta = { 104 uid = config.ids.uids.alerta; 105 description = "Alerta user"; 106 }; 107 108 users.groups.alerta = { 109 gid = config.ids.gids.alerta; 110 }; 111 }; 112}