2008-11-18 18:00:21 +00:00
|
|
|
# Zabbix agent daemon.
|
2014-04-14 14:26:48 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
2008-06-06 09:13:16 +00:00
|
|
|
|
2014-04-14 14:26:48 +00:00
|
|
|
with 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;
|
|
|
|
|
2018-08-28 14:10:45 +00:00
|
|
|
zabbix = cfg.package;
|
|
|
|
|
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
|
|
|
|
2018-08-28 14:10:45 +00:00
|
|
|
package = mkOption {
|
|
|
|
type = types.attrs; # Note: pkgs.zabbixXY isn't a derivation, but an attrset of { server = ...; agent = ...; }.
|
|
|
|
default = pkgs.zabbix;
|
|
|
|
defaultText = "pkgs.zabbix";
|
|
|
|
example = literalExample "pkgs.zabbix34";
|
|
|
|
description = ''
|
|
|
|
The Zabbix package to use.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
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 = "";
|
2016-10-23 17:33:41 +00:00
|
|
|
type = types.lines;
|
2010-02-16 12:51:28 +00:00
|
|
|
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 {
|
|
|
|
|
2018-06-29 23:58:35 +00:00
|
|
|
users.users = mkIf (!config.services.zabbixServer.enable) (singleton
|
2009-10-12 16:36:19 +00:00
|
|
|
{ name = "zabbix";
|
|
|
|
uid = config.ids.uids.zabbix;
|
|
|
|
description = "Zabbix daemon user";
|
2014-04-30 14:16:16 +00:00
|
|
|
});
|
2009-10-12 16:36:19 +00:00
|
|
|
|
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
|
|
|
|
2018-08-28 14:10:45 +00:00
|
|
|
serviceConfig.ExecStart = "@${zabbix.agent}/sbin/zabbix_agentd zabbix_agentd --config ${configFile}";
|
2012-10-26 13:15:26 +00:00
|
|
|
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
|
|
|
|
2018-08-28 14:10:45 +00:00
|
|
|
environment.systemPackages = [ zabbix.agent ];
|
2010-02-15 17:13:43 +00:00
|
|
|
|
2008-11-18 18:00:21 +00:00
|
|
|
};
|
2009-10-12 16:36:19 +00:00
|
|
|
|
2008-06-06 09:13:16 +00:00
|
|
|
}
|