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