2008-11-18 19:00:21 +01:00
|
|
|
# Zabbix agent 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
|
|
|
|
|
2008-06-09 00:21:56 +02:00
|
|
|
cfg = config.services.zabbixAgent;
|
|
|
|
|
2008-06-06 11:13:16 +02:00
|
|
|
stateDir = "/var/run/zabbix";
|
|
|
|
|
|
|
|
logDir = "/var/log/zabbix";
|
|
|
|
|
|
|
|
pidFile = "${stateDir}/zabbix_agentd.pid";
|
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
configFile = pkgs.writeText "zabbix_agentd.conf"
|
|
|
|
''
|
|
|
|
Server = ${cfg.server}
|
2008-06-06 11:13:16 +02:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
LogFile = ${logDir}/zabbix_agentd
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
PidFile = ${pidFile}
|
|
|
|
|
2010-02-15 18:13:43 +01:00
|
|
|
StartAgents = 1
|
2010-02-16 13:51:28 +01:00
|
|
|
|
|
|
|
${config.services.zabbixAgent.extraConfig}
|
2009-10-12 18:36:19 +02:00
|
|
|
'';
|
|
|
|
|
|
|
|
in
|
2011-09-14 20:20:50 +02: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.zabbixAgent = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether to run the Zabbix monitoring agent on this machine.
|
|
|
|
It will send monitoring data to a Zabbix server.
|
|
|
|
'';
|
|
|
|
};
|
2008-06-06 11:13:16 +02:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
server = mkOption {
|
|
|
|
default = "127.0.0.1";
|
|
|
|
description = ''
|
|
|
|
The IP address or hostname of the Zabbix server to connect to.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2010-02-16 13:51:28 +01:00
|
|
|
extraConfig = mkOption {
|
|
|
|
default = "";
|
2016-10-23 19:33:41 +02:00
|
|
|
type = types.lines;
|
2010-02-16 13:51:28 +01:00
|
|
|
description = ''
|
|
|
|
Configuration that is injected verbatim into the configuration file.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
};
|
2008-06-06 11:13:16 +02:00
|
|
|
|
2008-11-18 19:00:21 +01:00
|
|
|
};
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
2014-04-30 16:16:16 +02:00
|
|
|
users.extraUsers = mkIf (!config.services.zabbixServer.enable) (singleton
|
2009-10-12 18:36:19 +02:00
|
|
|
{ name = "zabbix";
|
|
|
|
uid = config.ids.uids.zabbix;
|
|
|
|
description = "Zabbix daemon user";
|
2014-04-30 16:16:16 +02:00
|
|
|
});
|
2009-10-12 18:36:19 +02:00
|
|
|
|
2013-01-16 12:33:18 +01:00
|
|
|
systemd.services."zabbix-agent" =
|
2012-10-26 15:15:26 +02:00
|
|
|
{ description = "Zabbix Agent";
|
2008-06-06 11:13:16 +02:00
|
|
|
|
2012-10-26 15:15:26 +02:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
2008-06-06 11:13:16 +02:00
|
|
|
|
2012-10-26 15:15:26 +02:00
|
|
|
path = [ pkgs.nettools ];
|
2012-03-19 20:43:31 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
preStart =
|
|
|
|
''
|
|
|
|
mkdir -m 0755 -p ${stateDir} ${logDir}
|
|
|
|
chown zabbix ${stateDir} ${logDir}
|
2010-02-16 11:15:20 +01:00
|
|
|
'';
|
2010-02-15 18:13:43 +01:00
|
|
|
|
2012-10-26 15:15:26 +02:00
|
|
|
serviceConfig.ExecStart = "@${pkgs.zabbix.agent}/sbin/zabbix_agentd zabbix_agentd --config ${configFile}";
|
|
|
|
serviceConfig.Type = "forking";
|
2012-12-11 20:54:19 +01:00
|
|
|
serviceConfig.RemainAfterExit = true;
|
2012-10-26 15:15:26 +02:00
|
|
|
serviceConfig.Restart = "always";
|
|
|
|
serviceConfig.RestartSec = 2;
|
2009-10-12 18:36:19 +02:00
|
|
|
};
|
2008-11-18 19:00:21 +01:00
|
|
|
|
2010-02-15 18:13:43 +01:00
|
|
|
environment.systemPackages = [ pkgs.zabbix.agent ];
|
|
|
|
|
2008-11-18 19:00:21 +01:00
|
|
|
};
|
2009-10-12 18:36:19 +02:00
|
|
|
|
2008-06-06 11:13:16 +02:00
|
|
|
}
|