From 0253c5c241e9d85e9e1ac7e797ed1c7365279c2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Janne=20He=C3=9F?= Date: Tue, 27 Apr 2021 21:28:57 +0200 Subject: [PATCH] icinga2: Init at 2.12.3 --- pkgs/servers/monitoring/icinga2/default.nix | 101 ++++++++++++++++++ .../monitoring/icinga2/etc-icinga2.patch | 13 +++ .../icinga2/no-systemd-service.patch | 15 +++ .../icinga2/no-var-directories.patch | 66 ++++++++++++ pkgs/top-level/all-packages.nix | 11 +- 5 files changed, 205 insertions(+), 1 deletion(-) create mode 100644 pkgs/servers/monitoring/icinga2/default.nix create mode 100644 pkgs/servers/monitoring/icinga2/etc-icinga2.patch create mode 100644 pkgs/servers/monitoring/icinga2/no-systemd-service.patch create mode 100644 pkgs/servers/monitoring/icinga2/no-var-directories.patch diff --git a/pkgs/servers/monitoring/icinga2/default.nix b/pkgs/servers/monitoring/icinga2/default.nix new file mode 100644 index 000000000000..e3ea1a802510 --- /dev/null +++ b/pkgs/servers/monitoring/icinga2/default.nix @@ -0,0 +1,101 @@ +{ stdenv, lib, fetchFromGitHub, cmake, flex, bison, systemd +, boost, openssl, patchelf, mariadb-connector-c, postgresql, zlib +# Databases +, withMysql ? true, withPostgresql ? false +# Features +, withChecker ? true, withCompat ? false, withLivestatus ? false +, withNotification ? true, withPerfdata ? true, withIcingadb ? true +, nameSuffix ? "" }: + +stdenv.mkDerivation rec { + pname = "icinga2${nameSuffix}"; + version = "2.12.3"; + + src = fetchFromGitHub { + owner = "icinga"; + repo = "icinga2"; + rev = "v${version}"; + sha256 = "0pq6ixv7d9bqys8qjxqq0jki3zncj8jdfavkp7qw125iyfjq48xk"; + }; + + patches = [ + ./etc-icinga2.patch # Makes /etc/icinga2 relative to / instead of the store path + ./no-systemd-service.patch # Prevent systemd service from being written to /usr + ./no-var-directories.patch # Prevent /var directories from being created + ]; + + cmakeFlags = let + mkFeatureFlag = label: value: "-DICINGA2_WITH_${label}=${if value then "ON" else "OFF"}"; + in [ + # Paths + "-DCMAKE_INSTALL_SYSCONFDIR=etc" + "-DCMAKE_INSTALL_LOCALSTATEDIR=/var" + "-DCMAKE_INSTALL_FULL_SBINDIR=bin" + "-DICINGA2_RUNDIR=/run" + "-DMYSQL_INCLUDE_DIR=${mariadb-connector-c.dev}/include/mariadb" + "-DMYSQL_LIB=${mariadb-connector-c.out}/lib/mariadb/libmysqlclient.a" + "-DICINGA2_PLUGINDIR=bin" + "-DICINGA2_UNITY_BUILD=no" + # Features + (mkFeatureFlag "MYSQL" withMysql) + (mkFeatureFlag "PGSQL" withPostgresql) + (mkFeatureFlag "CHECKER" withChecker) + (mkFeatureFlag "COMPAT" withCompat) + (mkFeatureFlag "LIVESTATUS" withLivestatus) + (mkFeatureFlag "NOTIFICATION" withNotification) + (mkFeatureFlag "PERFDATA" withPerfdata) + (mkFeatureFlag "ICINGADB" withIcingadb) + # Misc. + "-DICINGA2_USER=icinga2" + "-DICINGA2_GROUP=icinga2" + "-DICINGA2_GIT_VERSION_INFO=OFF" + "-DICINGA2_WITH_TESTS=OFF" + "-DUSE_SYSTEMD=ON" + ]; + + buildInputs = [ boost openssl systemd ] + ++ lib.optional withPostgresql postgresql; + + nativeBuildInputs = [ cmake flex bison patchelf ]; + + postFixup = '' + rm -r $out/etc/logrotate.d $out/etc/sysconfig $out/lib/icinga2/prepare-dirs + + # Fix hardcoded paths + sed -i 's:/usr/bin/::g' $out/etc/icinga2/scripts/* + + # Cleanup sbin + sed -i 's/sbin/bin/g' $out/lib/icinga2/safe-reload + rm $out/sbin + + ${lib.optionalString withMysql '' + # Add dependencies of the MySQL shim to the shared library + patchelf --add-needed ${zlib.out}/lib/libz.so $(readlink -f $out/lib/icinga2/libmysql_shim.so) + + # Make Icinga find the MySQL shim + icinga2Bin=$out/lib/icinga2/sbin/icinga2 + patchelf --set-rpath $out/lib/icinga2:$(patchelf --print-rpath $icinga2Bin) $icinga2Bin + ''} + ''; + + vim = stdenv.mkDerivation { + pname = "vim-icinga2"; + inherit version src; + + dontConfigure = true; + dontBuild = true; + + installPhase = '' + mkdir -p $out/share/vim-plugins + cp -r tools/syntax/vim $out/share/vim-plugins/icinga2 + ''; + }; + + meta = { + description = "Open source monitoring system"; + homepage = "https://www.icinga.com"; + license = lib.licenses.gpl2Plus; + platforms = lib.platforms.linux; + maintainers = with lib.maintainers; [ das_j ]; + }; +} diff --git a/pkgs/servers/monitoring/icinga2/etc-icinga2.patch b/pkgs/servers/monitoring/icinga2/etc-icinga2.patch new file mode 100644 index 000000000000..a08f7ba979c5 --- /dev/null +++ b/pkgs/servers/monitoring/icinga2/etc-icinga2.patch @@ -0,0 +1,13 @@ +diff --git a/config.h.cmake b/config.h.cmake +index 16fa190..152bf43 100644 +--- a/config.h.cmake ++++ b/config.h.cmake +@@ -13,7 +13,7 @@ + + #cmakedefine ICINGA2_UNITY_BUILD + +-#define ICINGA_CONFIGDIR "${ICINGA2_FULL_CONFIGDIR}" ++#define ICINGA_CONFIGDIR "/etc/icinga2" + #define ICINGA_DATADIR "${ICINGA2_FULL_DATADIR}" + #define ICINGA_LOGDIR "${ICINGA2_FULL_LOGDIR}" + #define ICINGA_CACHEDIR "${ICINGA2_FULL_CACHEDIR}" diff --git a/pkgs/servers/monitoring/icinga2/no-systemd-service.patch b/pkgs/servers/monitoring/icinga2/no-systemd-service.patch new file mode 100644 index 000000000000..a032a90647d7 --- /dev/null +++ b/pkgs/servers/monitoring/icinga2/no-systemd-service.patch @@ -0,0 +1,15 @@ +diff --git a/etc/initsystem/CMakeLists.txt b/etc/initsystem/CMakeLists.txt +index e702c83..c23cabb 100644 +--- a/etc/initsystem/CMakeLists.txt ++++ b/etc/initsystem/CMakeLists.txt +@@ -50,10 +50,5 @@ if(NOT WIN32) + + if (USE_SYSTEMD OR INSTALL_SYSTEMD_SERVICE_AND_INITSCRIPT) + configure_file(icinga2.service.cmake ${CMAKE_CURRENT_BINARY_DIR}/initsystem/icinga2.service @ONLY) +- install( +- FILES ${CMAKE_CURRENT_BINARY_DIR}/initsystem/icinga2.service +- DESTINATION ${DESTDIR}/usr/lib/systemd/system +- PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ +- ) + endif() + endif() diff --git a/pkgs/servers/monitoring/icinga2/no-var-directories.patch b/pkgs/servers/monitoring/icinga2/no-var-directories.patch new file mode 100644 index 000000000000..3a1d48055852 --- /dev/null +++ b/pkgs/servers/monitoring/icinga2/no-var-directories.patch @@ -0,0 +1,66 @@ +diff --git a/icinga-app/CMakeLists.txt b/icinga-app/CMakeLists.txt +index 87993df..819c87b 100644 +--- a/icinga-app/CMakeLists.txt ++++ b/icinga-app/CMakeLists.txt +@@ -106,7 +106,3 @@ install( + TARGETS icinga-app + RUNTIME DESTINATION ${InstallPath} + ) +- +-install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${ICINGA2_FULL_LOGDIR}\")") +-install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${ICINGA2_FULL_DATADIR}\")") +-install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${ICINGA2_FULL_INITRUNDIR}\")") +diff --git a/lib/base/CMakeLists.txt b/lib/base/CMakeLists.txt +index 5dda179..22cf69f 100644 +--- a/lib/base/CMakeLists.txt ++++ b/lib/base/CMakeLists.txt +@@ -125,7 +125,4 @@ set_target_properties ( + FOLDER Lib + ) + +-install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${ICINGA2_FULL_CACHEDIR}\")") +-install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${ICINGA2_FULL_LOGDIR}/crash\")") +- + set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS "${CPACK_NSIS_EXTRA_INSTALL_COMMANDS}" PARENT_SCOPE) +diff --git a/lib/perfdata/CMakeLists.txt b/lib/perfdata/CMakeLists.txt +index ab963f7..3d9d506 100644 +--- a/lib/perfdata/CMakeLists.txt ++++ b/lib/perfdata/CMakeLists.txt +@@ -74,7 +74,4 @@ install_if_not_exists( + ${ICINGA2_CONFIGDIR}/features-available + ) + +-install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${ICINGA2_FULL_SPOOLDIR}/perfdata\")") +-install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${ICINGA2_FULL_SPOOLDIR}/tmp\")") +- + set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS "${CPACK_NSIS_EXTRA_INSTALL_COMMANDS}" PARENT_SCOPE) +diff --git a/lib/remote/CMakeLists.txt b/lib/remote/CMakeLists.txt +index 65113d2..5e4398f 100644 +--- a/lib/remote/CMakeLists.txt ++++ b/lib/remote/CMakeLists.txt +@@ -55,12 +55,3 @@ set_target_properties ( + remote PROPERTIES + FOLDER Lib + ) +- +-#install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${ICINGA2_FULL_DATADIR}/api\")") +-install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${ICINGA2_FULL_DATADIR}/api/log\")") +-install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${ICINGA2_FULL_DATADIR}/api/zones\")") +-install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${ICINGA2_FULL_DATADIR}/api/zones-stage\")") +-install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${ICINGA2_FULL_DATADIR}/certs\")") +-install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${ICINGA2_FULL_DATADIR}/certificate-requests\")") +- +- +diff --git a/lib/compat/CMakeLists.txt b/lib/compat/CMakeLists.txt +index 1438626..d882ae2 100644 +--- a/lib/compat/CMakeLists.txt ++++ b/lib/compat/CMakeLists.txt +@@ -55,8 +55,4 @@ install_if_not_exists( + ${ICINGA2_CONFIGDIR}/features-available + ) + +-install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${ICINGA2_FULL_LOGDIR}/compat/archives\")") +-install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${ICINGA2_FULL_SPOOLDIR}\")") +-install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${ICINGA2_FULL_INITRUNDIR}/cmd\")") +- + set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS "${CPACK_NSIS_EXTRA_INSTALL_COMMANDS}" PARENT_SCOPE) diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 29d4fb7e1d7d..9986660ece85 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -19047,10 +19047,19 @@ in miniflux = callPackage ../servers/miniflux { }; - nagios = callPackage ../servers/monitoring/nagios { }; + icinga2 = callPackage ../servers/monitoring/icinga2 { }; + + icinga2-agent = callPackage ../servers/monitoring/icinga2 { + nameSuffix = "-agent"; + withMysql = false; + withNotification = false; + withIcingadb = false; + }; munin = callPackage ../servers/monitoring/munin { }; + nagios = callPackage ../servers/monitoring/nagios { }; + monitoring-plugins = callPackage ../servers/monitoring/plugins { }; inherit (callPackage ../servers/monitoring/plugins/labs_consol_de.nix { })