summaryrefslogtreecommitdiff
path: root/pkgs/servers/monitoring/zabbix/proxy.nix
blob: 65cc2c024e1a3b1bd2518d589e5ff5d825212825 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
{
  lib,
  stdenv,
  fetchurl,
  pkg-config,
  curl,
  libevent,
  libiconv,
  openssl,
  pcre,
  zlib,
  buildPackages,
  odbcSupport ? true,
  unixODBC,
  snmpSupport ? stdenv.buildPlatform == stdenv.hostPlatform,
  net-snmp,
  sshSupport ? true,
  libssh2,
  sqliteSupport ? false,
  sqlite,
  mysqlSupport ? false,
  libmysqlclient,
  postgresqlSupport ? false,
  libpq,
}:

# ensure exactly one database type is selected
assert mysqlSupport -> !postgresqlSupport && !sqliteSupport;
assert postgresqlSupport -> !mysqlSupport && !sqliteSupport;
assert sqliteSupport -> !mysqlSupport && !postgresqlSupport;

let
  inherit (lib) optional optionalString;

  fake_mysql_config = buildPackages.writeShellScript "mysql_config" ''
    if [[ "$1" == "--version" ]]; then
      $PKG_CONFIG mysqlclient --modversion
    else
      $PKG_CONFIG mysqlclient $@
    fi
  '';

in
import ./versions.nix (
  { version, hash, ... }:
  stdenv.mkDerivation {
    pname = "zabbix-proxy";
    inherit version;

    src = fetchurl {
      url = "https://cdn.zabbix.com/zabbix/sources/stable/${lib.versions.majorMinor version}/zabbix-${version}.tar.gz";
      inherit hash;
    };

    nativeBuildInputs = [
      pkg-config
    ] ++ optional postgresqlSupport libpq.pg_config;
    buildInputs =
      [
        curl
        libevent
        libiconv
        openssl
        pcre
        zlib
      ]
      ++ optional odbcSupport unixODBC
      ++ optional snmpSupport net-snmp
      ++ optional sqliteSupport sqlite
      ++ optional sshSupport libssh2
      ++ optional mysqlSupport libmysqlclient
      ++ optional postgresqlSupport libpq;

    configureFlags =
      [
        "--enable-ipv6"
        "--enable-proxy"
        "--with-iconv"
        "--with-libcurl"
        "--with-libevent"
        "--with-libpcre"
        "--with-openssl=${openssl.dev}"
        "--with-zlib=${zlib}"
      ]
      ++ optional odbcSupport "--with-unixodbc"
      ++ optional snmpSupport "--with-net-snmp"
      ++ optional sqliteSupport "--with-sqlite3=${sqlite.dev}"
      ++ optional sshSupport "--with-ssh2=${libssh2.dev}"
      ++ optional mysqlSupport "--with-mysql=${fake_mysql_config}"
      ++ optional postgresqlSupport "--with-postgresql";

    prePatch = ''
      find database -name data.sql -exec sed -i 's|/usr/bin/||g' {} +
    '';

    makeFlags = [
      "AR:=$(AR)"
      "RANLIB:=$(RANLIB)"
    ];

    postInstall =
      ''
        mkdir -p $out/share/zabbix/database/
      ''
      + optionalString sqliteSupport ''
        mkdir -p $out/share/zabbix/database/sqlite3
        cp -prvd database/sqlite3/schema.sql $out/share/zabbix/database/sqlite3/
      ''
      + optionalString mysqlSupport ''
        mkdir -p $out/share/zabbix/database/mysql
        cp -prvd database/mysql/schema.sql $out/share/zabbix/database/mysql/
      ''
      + optionalString postgresqlSupport ''
        mkdir -p $out/share/zabbix/database/postgresql
        cp -prvd database/postgresql/schema.sql $out/share/zabbix/database/postgresql/
      '';

    meta = {
      description = "Enterprise-class open source distributed monitoring solution (client-server proxy)";
      homepage = "https://www.zabbix.com/";
      license =
        if (lib.versions.major version >= "7") then lib.licenses.agpl3Only else lib.licenses.gpl2Plus;
      maintainers = with lib.maintainers; [
        bstanderline
        mmahut
      ];
      platforms = lib.platforms.linux;
    };
  }
)