Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zabbix.agent2: init at 5.0.5 #117538

Merged
merged 2 commits into from Mar 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 8 additions & 3 deletions nixos/modules/services/monitoring/zabbix-agent.nix
Expand Up @@ -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 {
Expand Down
66 changes: 66 additions & 0 deletions 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];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
nativeBuildInputs = [ autoreconfHook pkg-config];
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 : {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just setting modRoot = "src/go" instead of overrideModAttrs should work.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately not because source code outside of this directory is needed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to work?

diff --git a/pkgs/servers/monitoring/zabbix/agent2.nix b/pkgs/servers/monitoring/zabbix/agent2.nix
index f3c1be0f8e2..5f77528f48b 100644
--- a/pkgs/servers/monitoring/zabbix/agent2.nix
+++ b/pkgs/servers/monitoring/zabbix/agent2.nix
@@ -40,7 +40,7 @@ import ./versions.nix ({ version, sha256 }:
     # we need to manipulate a number of things for their build
     # system to properly work
     buildPhase = ''
-      cp -r vendor src/go/vendor
+      cd ../..
       make
     '';
 
@@ -49,12 +49,7 @@ import ./versions.nix ({ version, sha256 }:
       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
-        '';
-    });
+    modRoot = "src/go";
 
     meta = with lib; {
       description = "An enterprise-class open source distributed monitoring solution (client-side agent)";

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's great! Thanks for taking a look. Would you be willing to make a PR? I can test.

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;
};
})
1 change: 1 addition & 0 deletions pkgs/top-level/all-packages.nix
Expand Up @@ -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};
Expand Down