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
|
|
|
|
|
|
|
|
PidFile = ${pidFile}
|
|
|
|
|
2010-02-15 17:13:43 +00:00
|
|
|
StartAgents = 1
|
2009-10-12 16:36:19 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
2008-06-06 09:13:16 +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.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
2008-06-06 09:13:16 +00:00
|
|
|
|
2008-11-18 18:00:21 +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";
|
|
|
|
};
|
|
|
|
|
2009-10-12 18:09:34 +00:00
|
|
|
jobs.zabbix_agent =
|
2010-02-15 17:13:43 +00:00
|
|
|
{ name = "zabbix-agent";
|
2008-06-06 09:13:16 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
description = "Zabbix agent daemon";
|
2008-06-06 09:13:16 +00:00
|
|
|
|
2009-11-06 22:19:17 +00:00
|
|
|
startOn = "started network-interfaces";
|
|
|
|
stopOn = "stopping network-interfaces";
|
2008-09-12 16:31:39 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
preStart =
|
|
|
|
''
|
|
|
|
mkdir -m 0755 -p ${stateDir} ${logDir}
|
|
|
|
chown zabbix ${stateDir} ${logDir}
|
2010-02-15 17:13:43 +00:00
|
|
|
|
|
|
|
# Grrr, zabbix_agentd cannot be properly monitored by
|
|
|
|
# Upstart. Upstart's "expect fork/daemon" feature doesn't
|
|
|
|
# work because zabbix_agentd runs some programs on
|
|
|
|
# startup, and zabbix_agentd doesn't have a flag to
|
|
|
|
# prevent daemonizing.
|
2009-10-12 16:36:19 +00:00
|
|
|
export PATH=${pkgs.nettools}/bin:$PATH
|
2010-02-15 17:13:43 +00:00
|
|
|
${pkgs.zabbix.agent}/sbin/zabbix_agentd --config ${configFile}
|
2009-10-12 16:36:19 +00:00
|
|
|
'';
|
2008-11-18 18:00:21 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
postStop =
|
2010-02-15 17:13:43 +00:00
|
|
|
''
|
|
|
|
pid=$(cat ${pidFile})
|
|
|
|
test -n "$pid" && kill "$pid"
|
|
|
|
# Wait until they're really gone.
|
|
|
|
while ${pkgs.procps}/bin/pgrep -u zabbix zabbix_agentd > /dev/null; do sleep 1; done
|
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
|
|
|
}
|