2008-11-18 19:00:21 +01:00
|
|
|
# Zabbix agent daemon.
|
2009-01-25 16:48:39 +01:00
|
|
|
{config, pkgs, ...}:
|
2008-06-06 11:13:16 +02:00
|
|
|
|
2008-11-18 19:00:21 +01:00
|
|
|
###### interface
|
|
|
|
let
|
|
|
|
inherit (pkgs.lib) mkOption;
|
|
|
|
|
|
|
|
options = {
|
|
|
|
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.
|
|
|
|
";
|
|
|
|
};
|
|
|
|
|
|
|
|
server = mkOption {
|
|
|
|
default = "127.0.0.1";
|
|
|
|
description = ''
|
|
|
|
The IP address or hostname of the Zabbix server to connect to.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
in
|
|
|
|
|
|
|
|
###### implementation
|
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";
|
|
|
|
|
|
|
|
configFile = pkgs.writeText "zabbix_agentd.conf" ''
|
2008-06-09 00:21:56 +02:00
|
|
|
Server = ${cfg.server}
|
2008-06-06 11:13:16 +02:00
|
|
|
|
|
|
|
LogFile = ${logDir}/zabbix_agentd
|
|
|
|
|
|
|
|
PidFile = ${pidFile}
|
|
|
|
|
2008-06-06 14:38:40 +02:00
|
|
|
StartAgents = 5
|
2008-06-06 11:13:16 +02:00
|
|
|
'';
|
|
|
|
|
2008-11-18 19:00:21 +01:00
|
|
|
user = {
|
|
|
|
name = "zabbix";
|
2009-05-29 16:25:56 +02:00
|
|
|
uid = config.ids.uids.zabbix;
|
2008-11-18 19:00:21 +01:00
|
|
|
description = "Zabbix daemon user";
|
|
|
|
};
|
2008-06-06 11:13:16 +02:00
|
|
|
|
2008-11-18 19:00:21 +01:00
|
|
|
job = {
|
|
|
|
name = "zabbix-agent";
|
|
|
|
|
|
|
|
job = ''
|
|
|
|
start on network-interfaces/started
|
|
|
|
stop on network-interfaces/stop
|
2008-06-06 11:13:16 +02:00
|
|
|
|
2008-11-18 19:00:21 +01:00
|
|
|
description "Zabbix agent daemon"
|
2008-09-12 18:31:39 +02:00
|
|
|
|
2008-11-18 19:00:21 +01:00
|
|
|
start script
|
|
|
|
mkdir -m 0755 -p ${stateDir} ${logDir}
|
|
|
|
chown zabbix ${stateDir} ${logDir}
|
|
|
|
|
|
|
|
export PATH=${pkgs.nettools}/bin:$PATH
|
|
|
|
${pkgs.zabbixAgent}/sbin/zabbix_agentd --config ${configFile}
|
|
|
|
end script
|
2008-06-06 11:13:16 +02:00
|
|
|
|
2008-11-18 19:00:21 +01:00
|
|
|
respawn sleep 100000
|
2008-06-06 11:13:16 +02:00
|
|
|
|
2008-11-18 19:00:21 +01:00
|
|
|
stop script
|
|
|
|
# !!! this seems to leave processes behind.
|
|
|
|
#pid=$(cat ${pidFile})
|
|
|
|
#if test -n "$pid"; then
|
|
|
|
# kill $pid
|
|
|
|
#fi
|
2008-06-06 11:13:16 +02:00
|
|
|
|
2008-11-18 19:00:21 +01:00
|
|
|
# So instead kill the agent in a brutal fashion.
|
|
|
|
while ${pkgs.procps}/bin/pkill -u zabbix zabbix_agentd; do true; done
|
|
|
|
end script
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
ifEnable = pkgs.lib.ifEnable cfg.enable;
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
require = [
|
2009-05-25 01:13:23 +02:00
|
|
|
# ../upstart-jobs/default.nix
|
2009-05-20 01:14:45 +02:00
|
|
|
# ../system/user.nix # users = { .. }
|
2008-11-18 19:00:21 +01:00
|
|
|
options
|
|
|
|
];
|
|
|
|
|
|
|
|
services = {
|
|
|
|
extraJobs = ifEnable [job];
|
|
|
|
};
|
|
|
|
|
|
|
|
users = {
|
|
|
|
extraUsers = ifEnable [user];
|
|
|
|
};
|
2008-06-06 11:13:16 +02:00
|
|
|
}
|