2014-04-14 15:26:48 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
2008-06-06 10:13:16 +01:00
|
|
|
|
|
|
|
let
|
2008-06-08 23:21:56 +01:00
|
|
|
cfg = config.services.zabbixAgent;
|
|
|
|
|
2019-07-11 23:54:15 +01:00
|
|
|
inherit (lib) mkDefault mkEnableOption mkIf mkOption;
|
|
|
|
inherit (lib) attrValues concatMapStringsSep literalExample optionalString types;
|
2008-06-06 10:13:16 +01:00
|
|
|
|
2019-07-11 23:54:15 +01:00
|
|
|
user = "zabbix-agent";
|
|
|
|
group = "zabbix-agent";
|
2008-06-06 10:13:16 +01:00
|
|
|
|
2019-07-11 23:54:15 +01:00
|
|
|
moduleEnv = pkgs.symlinkJoin {
|
|
|
|
name = "zabbix-agent-module-env";
|
|
|
|
paths = attrValues cfg.modules;
|
|
|
|
};
|
2010-02-16 12:51:28 +00:00
|
|
|
|
2019-07-11 23:54:15 +01:00
|
|
|
configFile = pkgs.writeText "zabbix_agent.conf" ''
|
|
|
|
LogType = console
|
|
|
|
Server = ${cfg.server}
|
|
|
|
ListenIP = ${cfg.listen.ip}
|
|
|
|
ListenPort = ${toString cfg.listen.port}
|
|
|
|
${optionalString (cfg.modules != {}) "LoadModulePath = ${moduleEnv}/lib"}
|
|
|
|
${concatMapStringsSep "\n" (name: "LoadModule = ${name}") (builtins.attrNames cfg.modules)}
|
|
|
|
${cfg.extraConfig}
|
|
|
|
'';
|
2009-10-12 17:36:19 +01:00
|
|
|
|
|
|
|
in
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
{
|
2019-07-11 23:54:15 +01:00
|
|
|
# interface
|
2009-10-12 17:36:19 +01:00
|
|
|
|
|
|
|
options = {
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
services.zabbixAgent = {
|
2019-07-11 23:54:15 +01:00
|
|
|
enable = mkEnableOption "the Zabbix Agent";
|
2009-10-12 17:36:19 +01:00
|
|
|
|
2019-07-11 23:54:15 +01:00
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.zabbix.agent;
|
|
|
|
defaultText = "pkgs.zabbix.agent";
|
|
|
|
description = "The Zabbix package to use.";
|
|
|
|
};
|
|
|
|
|
|
|
|
extraPackages = mkOption {
|
|
|
|
type = types.listOf types.package;
|
|
|
|
default = with pkgs; [ nettools ];
|
|
|
|
defaultText = "[ nettools ]";
|
|
|
|
example = "[ nettools mysql ]";
|
2009-10-12 17:36:19 +01:00
|
|
|
description = ''
|
2019-07-11 23:54:15 +01:00
|
|
|
Packages to be added to the Zabbix <envar>PATH</envar>.
|
|
|
|
Typically used to add executables for scripts, but can be anything.
|
2009-10-12 17:36:19 +01:00
|
|
|
'';
|
|
|
|
};
|
2008-06-06 10:13:16 +01:00
|
|
|
|
2019-07-11 23:54:15 +01:00
|
|
|
modules = mkOption {
|
|
|
|
type = types.attrsOf types.package;
|
|
|
|
description = "A set of modules to load.";
|
|
|
|
default = {};
|
|
|
|
example = literalExample ''
|
|
|
|
{
|
|
|
|
"dummy.so" = pkgs.stdenv.mkDerivation {
|
|
|
|
name = "zabbix-dummy-module-''${cfg.package.version}";
|
|
|
|
src = cfg.package.src;
|
|
|
|
buildInputs = [ cfg.package ];
|
|
|
|
sourceRoot = "zabbix-''${cfg.package.version}/src/modules/dummy";
|
|
|
|
installPhase = '''
|
|
|
|
mkdir -p $out/lib
|
|
|
|
cp dummy.so $out/lib/
|
|
|
|
''';
|
|
|
|
};
|
|
|
|
}
|
2018-08-28 15:10:45 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
server = mkOption {
|
2019-07-11 23:54:15 +01:00
|
|
|
type = types.str;
|
2009-10-12 17:36:19 +01:00
|
|
|
description = ''
|
|
|
|
The IP address or hostname of the Zabbix server to connect to.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2019-07-11 23:54:15 +01:00
|
|
|
listen = {
|
|
|
|
ip = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "0.0.0.0";
|
|
|
|
description = ''
|
|
|
|
List of comma delimited IP addresses that the agent should listen on.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
type = types.port;
|
|
|
|
default = 10050;
|
|
|
|
description = ''
|
|
|
|
Agent will listen on this port for connections from the server.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
openFirewall = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Open ports in the firewall for the Zabbix Agent.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
# TODO: for bonus points migrate this to https://github.com/NixOS/rfcs/pull/42
|
2010-02-16 12:51:28 +00:00
|
|
|
extraConfig = mkOption {
|
|
|
|
default = "";
|
2016-10-23 18:33:41 +01:00
|
|
|
type = types.lines;
|
2010-02-16 12:51:28 +00:00
|
|
|
description = ''
|
2019-07-11 23:54:15 +01:00
|
|
|
Configuration that is injected verbatim into the configuration file. Refer to
|
|
|
|
<link xlink:href="https://www.zabbix.com/documentation/current/manual/appendix/config/zabbix_agentd"/>
|
|
|
|
for details on supported values.
|
2010-02-16 12:51:28 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
};
|
2008-06-06 10:13:16 +01:00
|
|
|
|
2008-11-18 18:00:21 +00:00
|
|
|
};
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2019-07-11 23:54:15 +01:00
|
|
|
# implementation
|
2009-10-12 17:36:19 +01:00
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
2019-07-11 23:54:15 +01:00
|
|
|
networking.firewall = mkIf cfg.openFirewall {
|
|
|
|
allowedTCPPorts = [ cfg.listen.port ];
|
|
|
|
};
|
2009-10-12 17:36:19 +01:00
|
|
|
|
2019-07-11 23:54:15 +01:00
|
|
|
users.users.${user} = {
|
|
|
|
description = "Zabbix Agent daemon user";
|
|
|
|
inherit group;
|
|
|
|
};
|
2008-06-06 10:13:16 +01:00
|
|
|
|
2019-07-11 23:54:15 +01:00
|
|
|
users.groups.${group} = { };
|
2008-06-06 10:13:16 +01:00
|
|
|
|
2019-07-11 23:54:15 +01:00
|
|
|
systemd.services."zabbix-agent" = {
|
|
|
|
description = "Zabbix Agent";
|
2012-03-19 19:43:31 +00:00
|
|
|
|
2019-07-11 23:54:15 +01:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
2010-02-15 17:13:43 +00:00
|
|
|
|
2019-07-11 23:54:15 +01:00
|
|
|
path = [ "/run/wrappers" ] ++ cfg.extraPackages;
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = "@${cfg.package}/sbin/zabbix_agentd zabbix_agentd -f --config ${configFile}";
|
|
|
|
Restart = "always";
|
|
|
|
RestartSec = 2;
|
2008-11-18 18:00:21 +00:00
|
|
|
|
2019-07-11 23:54:15 +01:00
|
|
|
User = user;
|
|
|
|
Group = group;
|
|
|
|
PrivateTmp = true;
|
|
|
|
};
|
|
|
|
};
|
2010-02-15 17:13:43 +00:00
|
|
|
|
2008-11-18 18:00:21 +00:00
|
|
|
};
|
2009-10-12 17:36:19 +01:00
|
|
|
|
2008-06-06 10:13:16 +01:00
|
|
|
}
|