2008-11-18 19:00:21 +01:00
|
|
|
# Zabbix agent daemon.
|
2009-10-12 18:36:19 +02:00
|
|
|
{ config, pkgs, ... }:
|
2008-06-06 11:13:16 +02:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
with pkgs.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
|
|
|
|
|
|
|
|
PidFile = ${pidFile}
|
|
|
|
|
2010-02-15 18:13:43 +01:00
|
|
|
StartAgents = 1
|
2009-10-12 18:36:19 +02:00
|
|
|
'';
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
2008-06-06 11:13:16 +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.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
2008-06-06 11:13:16 +02:00
|
|
|
|
2008-11-18 19:00:21 +01:00
|
|
|
};
|
2009-10-12 18:36:19 +02:00
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
users.extraUsers = singleton
|
|
|
|
{ name = "zabbix";
|
|
|
|
uid = config.ids.uids.zabbix;
|
|
|
|
description = "Zabbix daemon user";
|
|
|
|
};
|
|
|
|
|
2009-10-12 20:09:34 +02:00
|
|
|
jobs.zabbix_agent =
|
2010-02-15 18:13:43 +01:00
|
|
|
{ name = "zabbix-agent";
|
2008-06-06 11:13:16 +02:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
description = "Zabbix agent daemon";
|
2008-06-06 11:13:16 +02:00
|
|
|
|
2010-02-15 21:34:01 +01:00
|
|
|
startOn = "ip-up";
|
2009-11-06 23:19:17 +01:00
|
|
|
stopOn = "stopping network-interfaces";
|
2008-09-12 18:31:39 +02:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
preStart =
|
|
|
|
''
|
|
|
|
mkdir -m 0755 -p ${stateDir} ${logDir}
|
|
|
|
chown zabbix ${stateDir} ${logDir}
|
2010-02-15 18:13:43 +01: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 18:36:19 +02:00
|
|
|
export PATH=${pkgs.nettools}/bin:$PATH
|
2010-02-15 18:13:43 +01:00
|
|
|
${pkgs.zabbix.agent}/sbin/zabbix_agentd --config ${configFile}
|
2009-10-12 18:36:19 +02:00
|
|
|
'';
|
2008-11-18 19:00:21 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
postStop =
|
2010-02-15 18:13:43 +01: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 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
|
|
|
}
|