2008-11-18 18:00:21 +00:00
|
|
|
# Zabbix agent daemon.
|
2014-04-14 15:26:48 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
2008-06-06 10:13:16 +01:00
|
|
|
|
2014-04-14 15:26:48 +01:00
|
|
|
with lib;
|
2008-11-18 18:00:21 +00:00
|
|
|
|
2008-06-06 10:13:16 +01:00
|
|
|
let
|
|
|
|
|
2008-06-08 23:21:56 +01:00
|
|
|
cfg = config.services.zabbixAgent;
|
|
|
|
|
2008-06-06 10:13:16 +01:00
|
|
|
stateDir = "/var/run/zabbix";
|
|
|
|
|
|
|
|
logDir = "/var/log/zabbix";
|
|
|
|
|
|
|
|
pidFile = "${stateDir}/zabbix_agentd.pid";
|
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
configFile = pkgs.writeText "zabbix_agentd.conf"
|
|
|
|
''
|
|
|
|
Server = ${cfg.server}
|
2008-06-06 10:13:16 +01:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
LogFile = ${logDir}/zabbix_agentd
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2009-10-12 17:36:19 +01: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 17:36:19 +01:00
|
|
|
'';
|
|
|
|
|
|
|
|
in
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2009-10-12 17:36:19 +01: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 10:13:16 +01:00
|
|
|
|
2009-10-12 17:36:19 +01: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 17:36:19 +01:00
|
|
|
};
|
2008-06-06 10:13:16 +01:00
|
|
|
|
2008-11-18 18:00:21 +00:00
|
|
|
};
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
2014-04-30 15:16:16 +01:00
|
|
|
users.extraUsers = mkIf (!config.services.zabbixServer.enable) (singleton
|
2009-10-12 17:36:19 +01:00
|
|
|
{ name = "zabbix";
|
|
|
|
uid = config.ids.uids.zabbix;
|
|
|
|
description = "Zabbix daemon user";
|
2014-04-30 15:16:16 +01:00
|
|
|
});
|
2009-10-12 17:36:19 +01:00
|
|
|
|
2013-01-16 11:33:18 +00:00
|
|
|
systemd.services."zabbix-agent" =
|
2012-10-26 14:15:26 +01:00
|
|
|
{ description = "Zabbix Agent";
|
2008-06-06 10:13:16 +01:00
|
|
|
|
2012-10-26 14:15:26 +01:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
2008-06-06 10:13:16 +01:00
|
|
|
|
2012-10-26 14:15:26 +01:00
|
|
|
path = [ pkgs.nettools ];
|
2012-03-19 19:43:31 +00:00
|
|
|
|
2009-10-12 17:36:19 +01: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 14:15:26 +01: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 14:15:26 +01:00
|
|
|
serviceConfig.Restart = "always";
|
|
|
|
serviceConfig.RestartSec = 2;
|
2009-10-12 17:36:19 +01: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 17:36:19 +01:00
|
|
|
|
2008-06-06 10:13:16 +01:00
|
|
|
}
|