at 23.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 (lib.mdDoc "alerta"); 25 26 port = mkOption { 27 type = types.port; 28 default = 5000; 29 description = lib.mdDoc "Port of Alerta"; 30 }; 31 32 bind = mkOption { 33 type = types.str; 34 default = "0.0.0.0"; 35 description = lib.mdDoc "Address to bind to. The default is to bind to all addresses"; 36 }; 37 38 logDir = mkOption { 39 type = types.path; 40 description = lib.mdDoc "Location where the logfiles are stored"; 41 default = "/var/log/alerta"; 42 }; 43 44 databaseUrl = mkOption { 45 type = types.str; 46 description = lib.mdDoc "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 = lib.mdDoc "Name of the database instance to connect to"; 53 default = "monitoring"; 54 }; 55 56 corsOrigins = mkOption { 57 type = types.listOf types.str; 58 description = lib.mdDoc "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 = lib.mdDoc "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 = lib.mdDoc "Whether to prevent sign-up of new users via the web UI"; 71 default = true; 72 }; 73 74 extraConfig = mkOption { 75 description = lib.mdDoc "These lines go into alertad.conf verbatim."; 76 default = ""; 77 type = types.lines; 78 }; 79 }; 80 81 config = mkIf cfg.enable { 82 systemd.tmpfiles.rules = [ 83 "d '${cfg.logDir}' - alerta alerta - -" 84 ]; 85 86 systemd.services.alerta = { 87 description = "Alerta Monitoring System"; 88 wantedBy = [ "multi-user.target" ]; 89 after = [ "networking.target" ]; 90 environment = { 91 ALERTA_SVR_CONF_FILE = alertaConf; 92 }; 93 serviceConfig = { 94 ExecStart = "${pkgs.alerta-server}/bin/alertad run --port ${toString cfg.port} --host ${cfg.bind}"; 95 User = "alerta"; 96 Group = "alerta"; 97 }; 98 }; 99 100 environment.systemPackages = [ pkgs.alerta ]; 101 102 users.users.alerta = { 103 uid = config.ids.uids.alerta; 104 description = "Alerta user"; 105 }; 106 107 users.groups.alerta = { 108 gid = config.ids.gids.alerta; 109 }; 110 }; 111}