1 { config, lib, pkgs, ... }:
6 cfg = config.services.alerta;
8 alertaConf = pkgs.writeTextFile {
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"}
23 options.services.alerta = {
24 enable = mkEnableOption (lib.mdDoc "alerta");
29 description = lib.mdDoc "Port of Alerta";
35 description = lib.mdDoc "Address to bind to. The default is to bind to all addresses";
40 description = lib.mdDoc "Location where the logfiles are stored";
41 default = "/var/log/alerta";
44 databaseUrl = mkOption {
46 description = lib.mdDoc "URL of the MongoDB or PostgreSQL database to connect to";
47 default = "mongodb://localhost";
50 databaseName = mkOption {
52 description = lib.mdDoc "Name of the database instance to connect to";
53 default = "monitoring";
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" ];
62 authenticationRequired = mkOption {
64 description = lib.mdDoc "Whether users must authenticate when using the web UI or command-line tool";
68 signupEnabled = mkOption {
70 description = lib.mdDoc "Whether to prevent sign-up of new users via the web UI";
74 extraConfig = mkOption {
75 description = lib.mdDoc "These lines go into alertad.conf verbatim.";
81 config = mkIf cfg.enable {
82 systemd.tmpfiles.rules = [
83 "d '${cfg.logDir}' - alerta alerta - -"
86 systemd.services.alerta = {
87 description = "Alerta Monitoring System";
88 wantedBy = [ "multi-user.target" ];
89 after = [ "networking.target" ];
91 ALERTA_SVR_CONF_FILE = alertaConf;
94 ExecStart = "${pkgs.alerta-server}/bin/alertad run --port ${toString cfg.port} --host ${cfg.bind}";
100 environment.systemPackages = [ pkgs.alerta ];
102 users.users.alerta = {
103 uid = config.ids.uids.alerta;
104 description = "Alerta user";
107 users.groups.alerta = {
108 gid = config.ids.gids.alerta;