From 2d3b983f2e2d28d17ce85e460eca041bb1bf3c4e Mon Sep 17 00:00:00 2001 From: Aaron Andersen Date: Mon, 4 Jan 2021 16:14:36 -0500 Subject: [PATCH 1/2] zabbix.agent2: init at 5.0.5 --- pkgs/servers/monitoring/zabbix/agent2.nix | 66 +++++++++++++++++++++++ pkgs/top-level/all-packages.nix | 1 + 2 files changed, 67 insertions(+) create mode 100644 pkgs/servers/monitoring/zabbix/agent2.nix diff --git a/pkgs/servers/monitoring/zabbix/agent2.nix b/pkgs/servers/monitoring/zabbix/agent2.nix new file mode 100644 index 00000000000000..f3c1be0f8e2ac9 --- /dev/null +++ b/pkgs/servers/monitoring/zabbix/agent2.nix @@ -0,0 +1,66 @@ +{ lib, buildGoModule, fetchurl, autoreconfHook, pkg-config, libiconv, openssl, pcre, zlib }: + +import ./versions.nix ({ version, sha256 }: + buildGoModule { + pname = "zabbix-agent2"; + inherit version; + + src = fetchurl { + url = "https://cdn.zabbix.com/zabbix/sources/stable/${lib.versions.majorMinor version}/zabbix-${version}.tar.gz"; + inherit sha256; + }; + + vendorSha256 = "1kb3lc9jjv0cpzq93k1b9y496i95fcnwhb03j0gwlyqmgsa6yn81"; + + nativeBuildInputs = [ autoreconfHook pkg-config]; + buildInputs = [ libiconv openssl pcre zlib ]; + + inherit (buildGoModule.go) GOOS GOARCH; + + # need to provide GO* env variables & patch for reproducibility + postPatch = '' + substituteInPlace src/go/Makefile.am \ + --replace '`go env GOOS`' "$GOOS" \ + --replace '`go env GOARCH`' "$GOARCH" \ + --replace '`date +%H:%M:%S`' "00:00:00" \ + --replace '`date +"%b %_d %Y"`' "Jan 1 1970" + ''; + + # manually configure the c dependencies + preConfigure = '' + ./configure \ + --prefix=${placeholder "out"} \ + --enable-agent2 \ + --with-iconv \ + --with-libpcre \ + --with-openssl=${openssl.dev} + ''; + + # zabbix build process is complex to get right in nix... + # we need to manipulate a number of things for their build + # system to properly work + buildPhase = '' + cp -r vendor src/go/vendor + make + ''; + + installPhase = '' + install -Dm0644 src/go/conf/zabbix_agent2.conf $out/etc/zabbix_agent2.conf + install -Dm0755 src/go/bin/zabbix_agent2 $out/bin/zabbix_agent2 + ''; + + # run `go mod vendor` from the correct directory + overrideModAttrs = (_oldAttrs : { + preConfigure = '' + cd src/go + ''; + }); + + meta = with lib; { + description = "An enterprise-class open source distributed monitoring solution (client-side agent)"; + homepage = "https://www.zabbix.com/"; + license = licenses.gpl2Plus; + maintainers = [ maintainers.aanderse ]; + platforms = platforms.linux; + }; + }) diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index b183ed808f06e3..4e3261cf503c1b 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -17956,6 +17956,7 @@ in zabbixFor = version: rec { agent = (callPackages ../servers/monitoring/zabbix/agent.nix {}).${version}; + agent2 = (callPackages ../servers/monitoring/zabbix/agent2.nix {}).${version}; proxy-mysql = (callPackages ../servers/monitoring/zabbix/proxy.nix { mysqlSupport = true; }).${version}; proxy-pgsql = (callPackages ../servers/monitoring/zabbix/proxy.nix { postgresqlSupport = true; }).${version}; proxy-sqlite = (callPackages ../servers/monitoring/zabbix/proxy.nix { sqliteSupport = true; }).${version}; From 6211994f622d3207b46a748b17421d99a8d46837 Mon Sep 17 00:00:00 2001 From: Aaron Andersen Date: Wed, 24 Mar 2021 19:55:00 -0400 Subject: [PATCH 2/2] nixos/zabbixAgent: add a few minor tweaks to make configuration file compatible with both zabbix agent 1 and 2 --- nixos/modules/services/monitoring/zabbix-agent.nix | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/nixos/modules/services/monitoring/zabbix-agent.nix b/nixos/modules/services/monitoring/zabbix-agent.nix index 73eed7aa66af35..e7dd9e3393d0f7 100644 --- a/nixos/modules/services/monitoring/zabbix-agent.nix +++ b/nixos/modules/services/monitoring/zabbix-agent.nix @@ -128,11 +128,16 @@ in { LogType = "console"; Server = cfg.server; - ListenIP = cfg.listen.ip; ListenPort = cfg.listen.port; - LoadModule = builtins.attrNames cfg.modules; } - (mkIf (cfg.modules != {}) { LoadModulePath = "${moduleEnv}/lib"; }) + (mkIf (cfg.modules != {}) { + LoadModule = builtins.attrNames cfg.modules; + LoadModulePath = "${moduleEnv}/lib"; + }) + + # the default value for "ListenIP" is 0.0.0.0 but zabbix agent 2 cannot accept configuration files which + # explicitly set "ListenIP" to the default value... + (mkIf (cfg.listen.ip != "0.0.0.0") { ListenIP = cfg.listen.ip; }) ]; networking.firewall = mkIf cfg.openFirewall {