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}
|
|
|
|
|
|
|
|
StartAgents = 5
|
|
|
|
'';
|
|
|
|
|
|
|
|
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 =
|
2009-10-12 18:36:19 +02:00
|
|
|
{ #name = "zabbix-agent"; !!! mkIf bug
|
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
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
startOn = "network-interfaces/started";
|
|
|
|
stopOn = "network-interfaces/stop";
|
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}
|
2008-11-18 19:00:21 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
export PATH=${pkgs.nettools}/bin:$PATH
|
|
|
|
${pkgs.zabbixAgent}/sbin/zabbix_agentd --config ${configFile}
|
|
|
|
'';
|
2008-11-18 19:00:21 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
postStop =
|
|
|
|
''
|
|
|
|
# !!! this seems to leave processes behind.
|
|
|
|
#pid=$(cat ${pidFile})
|
|
|
|
#if test -n "$pid"; then
|
|
|
|
# kill $pid
|
|
|
|
#fi
|
2008-11-18 19:00:21 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
# So instead kill the agent in a brutal fashion.
|
|
|
|
while ${pkgs.procps}/bin/pkill -u zabbix zabbix_agentd; do true; done
|
|
|
|
'';
|
|
|
|
};
|
2008-11-18 19:00:21 +01:00
|
|
|
|
|
|
|
};
|
2009-10-12 18:36:19 +02:00
|
|
|
|
2008-06-06 11:13:16 +02:00
|
|
|
}
|