2008-11-18 19:00:21 +01:00
|
|
|
# Zabbix server daemon.
|
2014-04-14 16:26:48 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
2008-06-06 11:13:16 +02:00
|
|
|
|
2014-04-14 16:26:48 +02:00
|
|
|
with lib;
|
2008-11-18 19:00:21 +01:00
|
|
|
|
2008-06-06 11:13:16 +02:00
|
|
|
let
|
|
|
|
|
2010-11-26 23:50:57 +01:00
|
|
|
cfg = config.services.zabbixServer;
|
|
|
|
|
2008-06-06 11:13:16 +02:00
|
|
|
stateDir = "/var/run/zabbix";
|
|
|
|
|
|
|
|
logDir = "/var/log/zabbix";
|
|
|
|
|
|
|
|
libDir = "/var/lib/zabbix";
|
|
|
|
|
|
|
|
pidFile = "${stateDir}/zabbix_server.pid";
|
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
configFile = pkgs.writeText "zabbix_server.conf"
|
|
|
|
''
|
|
|
|
LogFile = ${logDir}/zabbix_server
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
PidFile = ${pidFile}
|
2008-06-06 11:13:16 +02:00
|
|
|
|
2012-02-20 14:40:47 +01:00
|
|
|
${optionalString (cfg.dbServer != "localhost") ''
|
|
|
|
DBHost = ${cfg.dbServer}
|
|
|
|
''}
|
2010-11-26 23:50:57 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
DBName = zabbix
|
2008-06-06 11:13:16 +02:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
DBUser = zabbix
|
2010-11-26 23:50:57 +01:00
|
|
|
|
|
|
|
${optionalString (cfg.dbPassword != "") ''
|
|
|
|
DBPassword = ${cfg.dbPassword}
|
|
|
|
''}
|
2008-11-18 19:00:21 +01:00
|
|
|
'';
|
|
|
|
|
2013-06-13 02:40:46 +02:00
|
|
|
useLocalPostgres = cfg.dbServer == "localhost" || cfg.dbServer == "";
|
|
|
|
|
2008-11-18 19:00:21 +01:00
|
|
|
in
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2008-11-18 19:00:21 +01:00
|
|
|
{
|
2009-10-12 18:36:19 +02:00
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
services.zabbixServer.enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether to run the Zabbix server on this machine.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2010-11-26 23:50:57 +01:00
|
|
|
services.zabbixServer.dbServer = mkOption {
|
|
|
|
default = "localhost";
|
2013-06-13 02:40:46 +02:00
|
|
|
description = ''
|
|
|
|
Hostname or IP address of the database server.
|
|
|
|
Use an empty string ("") to use peer authentication.
|
|
|
|
'';
|
2010-11-26 23:50:57 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
services.zabbixServer.dbPassword = mkOption {
|
|
|
|
default = "";
|
|
|
|
description = "Password used to connect to the database server.";
|
|
|
|
};
|
|
|
|
|
2008-11-18 19:00:21 +01:00
|
|
|
};
|
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
###### implementation
|
|
|
|
|
2010-11-26 23:50:57 +01:00
|
|
|
config = mkIf cfg.enable {
|
2009-10-12 18:36:19 +02:00
|
|
|
|
2013-06-13 02:40:46 +02:00
|
|
|
services.postgresql.enable = useLocalPostgres;
|
2010-02-15 20:02:42 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
users.extraUsers = singleton
|
|
|
|
{ name = "zabbix";
|
|
|
|
uid = config.ids.uids.zabbix;
|
|
|
|
description = "Zabbix daemon user";
|
|
|
|
};
|
|
|
|
|
2013-01-16 12:33:18 +01:00
|
|
|
systemd.services."zabbix-server" =
|
2012-10-26 15:15:26 +02:00
|
|
|
{ description = "Zabbix Server";
|
2009-10-12 18:36:19 +02:00
|
|
|
|
2012-10-26 15:15:26 +02:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
2013-06-13 02:40:46 +02:00
|
|
|
after = optional useLocalPostgres "postgresql.service";
|
2009-10-12 18:36:19 +02:00
|
|
|
|
|
|
|
preStart =
|
|
|
|
''
|
|
|
|
mkdir -m 0755 -p ${stateDir} ${logDir} ${libDir}
|
|
|
|
chown zabbix ${stateDir} ${logDir} ${libDir}
|
|
|
|
|
|
|
|
if ! test -e "${libDir}/db-created"; then
|
|
|
|
${pkgs.postgresql}/bin/createuser --no-superuser --no-createdb --no-createrole zabbix || true
|
|
|
|
${pkgs.postgresql}/bin/createdb --owner zabbix zabbix || true
|
2010-02-15 20:02:42 +01:00
|
|
|
cat ${pkgs.zabbix.server}/share/zabbix/db/schema/postgresql.sql | ${pkgs.su}/bin/su -s "$SHELL" zabbix -c '${pkgs.postgresql}/bin/psql zabbix'
|
|
|
|
cat ${pkgs.zabbix.server}/share/zabbix/db/data/images_pgsql.sql | ${pkgs.su}/bin/su -s "$SHELL" zabbix -c '${pkgs.postgresql}/bin/psql zabbix'
|
2013-06-13 03:29:29 +02:00
|
|
|
cat ${pkgs.zabbix.server}/share/zabbix/db/data/data.sql | ${pkgs.su}/bin/su -s "$SHELL" zabbix -c '${pkgs.postgresql}/bin/psql zabbix'
|
2009-10-12 18:36:19 +02:00
|
|
|
touch "${libDir}/db-created"
|
|
|
|
fi
|
2010-02-16 11:10:59 +01:00
|
|
|
'';
|
2009-10-12 18:36:19 +02:00
|
|
|
|
2012-10-26 15:15:26 +02:00
|
|
|
path = [ pkgs.nettools ];
|
2009-10-12 18:36:19 +02:00
|
|
|
|
2012-10-26 15:15:26 +02:00
|
|
|
serviceConfig.ExecStart = "@${pkgs.zabbix.server}/sbin/zabbix_server zabbix_server --config ${configFile}";
|
|
|
|
serviceConfig.Type = "forking";
|
|
|
|
serviceConfig.Restart = "always";
|
|
|
|
serviceConfig.RestartSec = 2;
|
2013-06-13 01:56:09 +02:00
|
|
|
serviceConfig.PIDFile = pidFile;
|
2009-10-12 18:36:19 +02:00
|
|
|
};
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2008-11-18 19:00:21 +01:00
|
|
|
};
|
2009-10-12 18:36:19 +02:00
|
|
|
|
2008-06-06 11:13:16 +02:00
|
|
|
}
|