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