2008-11-18 21:00:21 +03:00
|
|
|
# Zabbix server daemon.
|
2009-10-12 20:36:19 +04:00
|
|
|
{ config, pkgs, ... }:
|
2008-06-06 13:13:16 +04:00
|
|
|
|
2009-10-12 20:36:19 +04:00
|
|
|
with pkgs.lib;
|
2008-11-18 21:00:21 +03:00
|
|
|
|
2008-06-06 13:13:16 +04:00
|
|
|
let
|
|
|
|
|
2010-11-27 01:50:57 +03:00
|
|
|
cfg = config.services.zabbixServer;
|
|
|
|
|
2008-06-06 13:13:16 +04:00
|
|
|
stateDir = "/var/run/zabbix";
|
|
|
|
|
|
|
|
logDir = "/var/log/zabbix";
|
|
|
|
|
|
|
|
libDir = "/var/lib/zabbix";
|
|
|
|
|
|
|
|
pidFile = "${stateDir}/zabbix_server.pid";
|
|
|
|
|
2009-10-12 20:36:19 +04:00
|
|
|
configFile = pkgs.writeText "zabbix_server.conf"
|
|
|
|
''
|
|
|
|
LogFile = ${logDir}/zabbix_server
|
2011-09-14 22:20:50 +04:00
|
|
|
|
2009-10-12 20:36:19 +04:00
|
|
|
PidFile = ${pidFile}
|
2008-06-06 13:13:16 +04:00
|
|
|
|
2012-02-20 17:40:47 +04:00
|
|
|
${optionalString (cfg.dbServer != "localhost") ''
|
|
|
|
DBHost = ${cfg.dbServer}
|
|
|
|
''}
|
2010-11-27 01:50:57 +03:00
|
|
|
|
2009-10-12 20:36:19 +04:00
|
|
|
DBName = zabbix
|
2008-06-06 13:13:16 +04:00
|
|
|
|
2009-10-12 20:36:19 +04:00
|
|
|
DBUser = zabbix
|
2010-11-27 01:50:57 +03:00
|
|
|
|
|
|
|
${optionalString (cfg.dbPassword != "") ''
|
|
|
|
DBPassword = ${cfg.dbPassword}
|
|
|
|
''}
|
2008-11-18 21:00:21 +03:00
|
|
|
'';
|
|
|
|
|
2013-06-13 04:40:46 +04:00
|
|
|
useLocalPostgres = cfg.dbServer == "localhost" || cfg.dbServer == "";
|
|
|
|
|
2008-11-18 21:00:21 +03:00
|
|
|
in
|
2011-09-14 22:20:50 +04:00
|
|
|
|
2008-11-18 21:00:21 +03:00
|
|
|
{
|
2009-10-12 20:36:19 +04:00
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
2011-09-14 22:20:50 +04:00
|
|
|
|
2009-10-12 20:36:19 +04:00
|
|
|
services.zabbixServer.enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether to run the Zabbix server on this machine.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2010-11-27 01:50:57 +03:00
|
|
|
services.zabbixServer.dbServer = mkOption {
|
|
|
|
default = "localhost";
|
2013-06-13 04:40:46 +04:00
|
|
|
description = ''
|
|
|
|
Hostname or IP address of the database server.
|
|
|
|
Use an empty string ("") to use peer authentication.
|
|
|
|
'';
|
2010-11-27 01:50:57 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
services.zabbixServer.dbPassword = mkOption {
|
|
|
|
default = "";
|
|
|
|
description = "Password used to connect to the database server.";
|
|
|
|
};
|
|
|
|
|
2008-11-18 21:00:21 +03:00
|
|
|
};
|
|
|
|
|
2009-10-12 20:36:19 +04:00
|
|
|
###### implementation
|
|
|
|
|
2010-11-27 01:50:57 +03:00
|
|
|
config = mkIf cfg.enable {
|
2009-10-12 20:36:19 +04:00
|
|
|
|
2013-06-13 04:40:46 +04:00
|
|
|
services.postgresql.enable = useLocalPostgres;
|
2010-02-15 22:02:42 +03:00
|
|
|
|
2009-10-12 20:36:19 +04:00
|
|
|
users.extraUsers = singleton
|
|
|
|
{ name = "zabbix";
|
|
|
|
uid = config.ids.uids.zabbix;
|
|
|
|
description = "Zabbix daemon user";
|
|
|
|
};
|
|
|
|
|
2013-01-16 15:33:18 +04:00
|
|
|
systemd.services."zabbix-server" =
|
2012-10-26 17:15:26 +04:00
|
|
|
{ description = "Zabbix Server";
|
2009-10-12 20:36:19 +04:00
|
|
|
|
2012-10-26 17:15:26 +04:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
2013-06-13 04:40:46 +04:00
|
|
|
after = optional useLocalPostgres "postgresql.service";
|
2009-10-12 20:36:19 +04: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 22:02:42 +03: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 05:29:29 +04: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 20:36:19 +04:00
|
|
|
touch "${libDir}/db-created"
|
|
|
|
fi
|
2010-02-16 13:10:59 +03:00
|
|
|
'';
|
2009-10-12 20:36:19 +04:00
|
|
|
|
2012-10-26 17:15:26 +04:00
|
|
|
path = [ pkgs.nettools ];
|
2009-10-12 20:36:19 +04:00
|
|
|
|
2012-10-26 17:15:26 +04: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 03:56:09 +04:00
|
|
|
serviceConfig.PIDFile = pidFile;
|
2009-10-12 20:36:19 +04:00
|
|
|
};
|
2011-09-14 22:20:50 +04:00
|
|
|
|
2008-11-18 21:00:21 +03:00
|
|
|
};
|
2009-10-12 20:36:19 +04:00
|
|
|
|
2008-06-06 13:13:16 +04:00
|
|
|
}
|