diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix
index f4f1abba4de..a82cef3e076 100644
--- a/nixos/modules/module-list.nix
+++ b/nixos/modules/module-list.nix
@@ -160,7 +160,7 @@
./services/monitoring/graphite.nix
./services/monitoring/monit.nix
./services/monitoring/munin.nix
- ./services/monitoring/nagios/default.nix
+ ./services/monitoring/nagios.nix
./services/monitoring/smartd.nix
./services/monitoring/statsd.nix
./services/monitoring/systemhealth.nix
diff --git a/nixos/modules/services/monitoring/nagios/default.nix b/nixos/modules/services/monitoring/nagios.nix
similarity index 64%
rename from nixos/modules/services/monitoring/nagios/default.nix
rename to nixos/modules/services/monitoring/nagios.nix
index 2eeddf78250..97d153153a5 100644
--- a/nixos/modules/services/monitoring/nagios/default.nix
+++ b/nixos/modules/services/monitoring/nagios.nix
@@ -4,21 +4,12 @@
with lib;
let
-
cfg = config.services.nagios;
- nagiosUser = "nagios";
- nagiosGroup = "nogroup";
-
nagiosState = "/var/lib/nagios";
nagiosLogDir = "/var/log/nagios";
- nagiosObjectDefs =
- [ ./timeperiods.cfg
- ./host-templates.cfg
- ./service-templates.cfg
- ./commands.cfg
- ] ++ cfg.objectDefs;
+ nagiosObjectDefs = cfg.objectDefs;
nagiosObjectDefsDir = pkgs.runCommand "nagios-objects" {inherit nagiosObjectDefs;}
"ensureDir $out; ln -s $nagiosObjectDefs $out/";
@@ -30,19 +21,20 @@ let
log_archive_path=${nagiosLogDir}/archive
status_file=${nagiosState}/status.dat
object_cache_file=${nagiosState}/objects.cache
- comment_file=${nagiosState}/comment.dat
- downtime_file=${nagiosState}/downtime.dat
temp_file=${nagiosState}/nagios.tmp
lock_file=/var/run/nagios.lock # Not used I think.
state_retention_file=${nagiosState}/retention.dat
+ query_socket=${nagiosState}/nagios.qh
+ check_result_path=${nagiosState}
+ command_file=${nagiosState}/nagios.cmd
# Configuration files.
#resource_file=resource.cfg
cfg_dir=${nagiosObjectDefsDir}
# Uid/gid that the daemon runs under.
- nagios_user=${nagiosUser}
- nagios_group=${nagiosGroup}
+ nagios_user=nagios
+ nagios_group=nogroup
# Misc. options.
illegal_macro_output_chars=`~$&|'"<>
@@ -53,26 +45,24 @@ let
# authentication.
nagiosCGICfgFile = pkgs.writeText "nagios.cgi.conf"
''
- main_config_file=${nagiosCfgFile}
+ main_config_file=${cfg.mainConfigFile}
use_authentication=0
- url_html_path=/nagios
+ url_html_path=${cfg.urlPath}
'';
- urlPath = cfg.urlPath;
-
extraHttpdConfig =
''
- ScriptAlias ${urlPath}/cgi-bin ${pkgs.nagios}/sbin
+ ScriptAlias ${cfg.urlPath}/cgi-bin ${pkgs.nagios}/sbin
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
- SetEnv NAGIOS_CGI_CONFIG ${nagiosCGICfgFile}
+ SetEnv NAGIOS_CGI_CONFIG ${cfg.cgiConfigFile}
- Alias ${urlPath} ${pkgs.nagios}/share
+ Alias ${cfg.urlPath} ${pkgs.nagios}/share
Options None
@@ -83,14 +73,9 @@ let
'';
in
-
{
- ###### interface
-
options = {
-
services.nagios = {
-
enable = mkOption {
default = false;
description = "
@@ -116,6 +101,21 @@ in
";
};
+ mainConfigFile = mkOption {
+ default = nagiosCfgFile;
+ description = "
+ Derivation for the main configuration file of Nagios.
+ ";
+ };
+
+ cgiConfigFile = mkOption {
+ default = nagiosCGICfgFile;
+ description = "
+ Derivation for the configuration file of Nagios CGI scripts
+ that can be used in web servers for running the Nagios web interface.
+ ";
+ };
+
enableWebInterface = mkOption {
default = false;
description = "
@@ -132,55 +132,53 @@ in
http://server/urlPath.
";
};
-
};
-
};
- ###### implementation
-
config = mkIf cfg.enable {
-
- users.extraUsers = singleton
- { name = nagiosUser;
- uid = config.ids.uids.nagios;
- description = "Nagios monitoring daemon";
- home = nagiosState;
- };
+ users.extraUsers.nagios = {
+ description = "Nagios user ";
+ uid = config.ids.uids.nagios;
+ home = nagiosState;
+ createHome = true;
+ };
# This isn't needed, it's just so that the user can type "nagiostats
# -c /etc/nagios.cfg".
- environment.etc = singleton
- { source = nagiosCfgFile;
+ environment.etc = [
+ { source = cfg.mainConfigFile;
target = "nagios.cfg";
- };
+ }
+ ];
environment.systemPackages = [ pkgs.nagios ];
+ systemd.services.nagios = {
+ description = "Nagios monitoring daemon";
+ path = [ pkgs.nagios ];
+ wantedBy = [ "multi-user.target" ];
+ after = [ "network-interfaces.target" ];
- jobs.nagios =
- { description = "Nagios monitoring daemon";
-
- startOn = "started network-interfaces";
- stopOn = "stopping network-interfaces";
-
- preStart =
- ''
- mkdir -m 0755 -p ${nagiosState} ${nagiosLogDir}
- chown ${nagiosUser} ${nagiosState} ${nagiosLogDir}
- '';
-
- script =
- ''
- for i in ${toString config.services.nagios.plugins}; do
- export PATH=$i/bin:$i/sbin:$i/libexec:$PATH
- done
- exec ${pkgs.nagios}/bin/nagios ${nagiosCfgFile}
- '';
+ serviceConfig = {
+ User = "nagios";
+ Restart = "always";
+ RestartSec = 2;
+ PermissionsStartOnly = true;
};
+ preStart = ''
+ mkdir -m 0755 -p ${nagiosState} ${nagiosLogDir}
+ chown nagios ${nagiosState} ${nagiosLogDir}
+ '';
+
+ script = ''
+ for i in ${toString cfg.plugins}; do
+ export PATH=$i/bin:$i/sbin:$i/libexec:$PATH
+ done
+ exec ${pkgs.nagios}/bin/nagios ${cfg.mainConfigFile}
+ '';
+ };
+
services.httpd.extraConfig = optionalString cfg.enableWebInterface extraHttpdConfig;
-
};
-
}
diff --git a/nixos/modules/services/monitoring/nagios/commands.cfg b/nixos/modules/services/monitoring/nagios/commands.cfg
deleted file mode 100644
index 6efdefcd37d..00000000000
--- a/nixos/modules/services/monitoring/nagios/commands.cfg
+++ /dev/null
@@ -1,34 +0,0 @@
-define command {
- command_name host-notify-by-email
- command_line printf "%b" "To: $CONTACTEMAIL$\nSubject: [Nagios] Host $HOSTSTATE$ alert for $HOSTNAME$\n\n***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | sendmail $CONTACTEMAIL$
-}
-
-
-define command {
- command_name notify-by-email
- command_line printf "%b" "To: $CONTACTEMAIL$\nSubject: [Nagios] $NOTIFICATIONTYPE$ alert - $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$\n\n***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$" | sendmail $CONTACTEMAIL$
-}
-
-
-define command {
- command_name dummy-ok
- command_line true
-}
-
-
-define command {
- command_name check-host-alive
- command_line check_ping -H $HOSTADDRESS$ -w 3000.0,80% -c 5000.0,100% -p 1
-}
-
-
-define command {
- command_name check_local_disk
- command_line check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$
-}
-
-
-define command {
- command_name check_ssh
- command_line check_ssh $HOSTADDRESS$
-}
diff --git a/nixos/modules/services/monitoring/nagios/host-templates.cfg b/nixos/modules/services/monitoring/nagios/host-templates.cfg
deleted file mode 100644
index 3a4c269e257..00000000000
--- a/nixos/modules/services/monitoring/nagios/host-templates.cfg
+++ /dev/null
@@ -1,27 +0,0 @@
-define host {
- name generic-host
- notifications_enabled 1
- event_handler_enabled 1
- flap_detection_enabled 1
- failure_prediction_enabled 1
- process_perf_data 1
- retain_status_information 1
- retain_nonstatus_information 1
- notification_period 24x7
- register 0
-}
-
-
-define host {
- name generic-server
- use generic-host
- check_period 24x7
- max_check_attempts 10
- check_command check-host-alive
- notification_period 24x7
- notification_interval 120
- notification_options d,u,r
- contact_groups admins
- register 0
- #check_interval 1
-}
diff --git a/nixos/modules/services/monitoring/nagios/service-templates.cfg b/nixos/modules/services/monitoring/nagios/service-templates.cfg
deleted file mode 100644
index e729ea77675..00000000000
--- a/nixos/modules/services/monitoring/nagios/service-templates.cfg
+++ /dev/null
@@ -1,32 +0,0 @@
-define service {
- name generic-service
- active_checks_enabled 1
- passive_checks_enabled 1
- parallelize_check 1
- obsess_over_service 1
- check_freshness 0
- notifications_enabled 1
- event_handler_enabled 1
- flap_detection_enabled 1
- failure_prediction_enabled 1
- process_perf_data 1
- retain_status_information 1
- retain_nonstatus_information 1
- is_volatile 0
- register 0
-}
-
-
-define service {
- name local-service
- use generic-service
- check_period 24x7
- max_check_attempts 4
- normal_check_interval 5
- retry_check_interval 1
- contact_groups admins
- notification_options w,u,c,r
- notification_interval 0 # notify only once
- notification_period 24x7
- register 0
-}
diff --git a/nixos/modules/services/monitoring/nagios/timeperiods.cfg b/nixos/modules/services/monitoring/nagios/timeperiods.cfg
deleted file mode 100644
index 2669be54d3d..00000000000
--- a/nixos/modules/services/monitoring/nagios/timeperiods.cfg
+++ /dev/null
@@ -1,11 +0,0 @@
-define timeperiod {
- timeperiod_name 24x7
- alias 24 Hours A Day, 7 Days A Week
- sunday 00:00-24:00
- monday 00:00-24:00
- tuesday 00:00-24:00
- wednesday 00:00-24:00
- thursday 00:00-24:00
- friday 00:00-24:00
- saturday 00:00-24:00
-}
diff --git a/pkgs/servers/monitoring/nagios/default.nix b/pkgs/servers/monitoring/nagios/default.nix
index dba063bb106..5af759db1c9 100644
--- a/pkgs/servers/monitoring/nagios/default.nix
+++ b/pkgs/servers/monitoring/nagios/default.nix
@@ -1,23 +1,30 @@
-{ stdenv, fetchurl, perl, gdSupport ? false
-, gd ? null, libpng ? null, zlib ? null
-}:
+{ stdenv, fetchurl, perl, php, gd, libpng, zlib }:
stdenv.mkDerivation {
- name = "nagios-2.10";
+ name = "nagios-4.0.7";
src = fetchurl {
- url = mirror://sourceforge/nagios/nagios-2.10.tar.gz;
- md5 = "8c3a29e138f2ff8c8abbd3dd8a40c4b6";
+ url = mirror://sourceforge/nagios/nagios-4.x/nagios-4.0.7/nagios-4.0.7.tar.gz;
+ sha256 = "1687qnbsag84r57y9745g2klypacfixd6gkzaj42lmzn0v8y27gg";
};
- patches = [./nagios.patch];
- buildInputs = [perl] ++ (if gdSupport then [gd libpng zlib] else []);
+ patches = [ ./nagios.patch ];
+ buildInputs = [ php perl gd libpng zlib ];
+
+ configureFlags = [ "--localstatedir=/var/lib/nagios" ];
buildFlags = "all";
+
+ # Do not create /var directories
+ preInstall = ''
+ substituteInPlace Makefile --replace '$(MAKE) install-basic' ""
+ '';
installTargets = "install install-config";
meta = {
description = "A host, service and network monitoring program";
- homepage = http://www.nagios.org/;
- license = "GPL";
+ homepage = http://www.nagios.org/;
+ license = stdenv.lib.licenses.gpl2;
+ platforms = stdenv.lib.platforms.linux;
+ maintainers = with stdenv.lib.maintainers; [ thoughtpolice relrod ];
};
}
diff --git a/pkgs/servers/monitoring/nagios/nagios.patch b/pkgs/servers/monitoring/nagios/nagios.patch
index 6fc27153617..cec4c4942b5 100644
--- a/pkgs/servers/monitoring/nagios/nagios.patch
+++ b/pkgs/servers/monitoring/nagios/nagios.patch
@@ -1,7 +1,7 @@
-diff -ruN nagios-2.6/configure nagios-2.6.new/configure
---- nagios-2.6/configure 2006-11-28 03:29:04.000000000 +0100
-+++ nagios-2.6.new/configure 2006-12-28 01:22:56.000000000 +0100
-@@ -4810,7 +4810,8 @@
+diff -ruN nagios-4.0.7.orig/configure nagios-4.0.7/configure
+--- nagios-4.0.7.orig/configure 2014-06-03 10:41:42.000000000 -0400
++++ nagios-4.0.7/configure 2014-06-12 00:30:17.516468583 -0400
+@@ -6014,7 +6014,8 @@
#define DEFAULT_NAGIOS_GROUP "$nagios_grp"
_ACEOF
@@ -11,3 +11,13 @@ diff -ruN nagios-2.6/configure nagios-2.6.new/configure
+@@ -6035,7 +6036,8 @@
+
+
+
+-COMMAND_OPTS="-o $command_user -g $command_grp"
++#COMMAND_OPTS="-o $command_user -g $command_grp"
++COMMAND_OPTS=""
+
+
+ MAIL_PROG=no
diff --git a/pkgs/servers/monitoring/nagios/plugins/official/default.nix b/pkgs/servers/monitoring/nagios/plugins/official-2.x.nix
similarity index 50%
rename from pkgs/servers/monitoring/nagios/plugins/official/default.nix
rename to pkgs/servers/monitoring/nagios/plugins/official-2.x.nix
index c466813b23b..3420003c641 100644
--- a/pkgs/servers/monitoring/nagios/plugins/official/default.nix
+++ b/pkgs/servers/monitoring/nagios/plugins/official-2.x.nix
@@ -1,11 +1,12 @@
-{stdenv, fetchurl, openssh}:
+{ stdenv, fetchurl, openssh }:
-stdenv.mkDerivation {
- name = "nagios-plugins-1.4.10";
+stdenv.mkDerivation rec {
+ name = "nagios-plugins-${version}";
+ version = "2.0";
src = fetchurl {
- url = https://www.monitoring-plugins.org/download/nagios-plugins-1.4.10.tar.gz;
- sha256 = "0vm7sjiygxbfc5vbsi1g0dakpvynfzi86fhqx4yxd61brn0g8ghr";
+ url = "http://nagios-plugins.org/download/${name}.tar.gz";
+ sha256 = "113nv9jqpbqpdjqilqbj1iyshxyvcmq8w94bq5ajz4dxi9j8045s";
};
# !!! Awful hack. Grrr... this of course only works on NixOS.
@@ -22,11 +23,14 @@ stdenv.mkDerivation {
postInstall = "ln -s libexec $out/bin";
- buildInputs = [openssh]; # !!! make openssh a runtime dependency only
+ # !!! make openssh a runtime dependency only
+ buildInputs = [ openssh ];
meta = {
- description = "Plugins for Nagios";
- homepage = http://www.monitoring-plugins.org;
- license = "GPL";
+ description = "Official plugins for Nagios";
+ homepage = http://www.nagios.org/download/plugins;
+ license = stdenv.lib.licenses.gpl2;
+ platforms = stdenv.lib.platforms.linux;
+ maintainers = with stdenv.lib.maintainers; [ thoughtpolice relrod ];
};
}
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index e7ade25cbf4..d1619cf52ec 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -6756,13 +6756,11 @@ let
mysql_jdbc = callPackage ../servers/sql/mysql/jdbc { };
- nagios = callPackage ../servers/monitoring/nagios {
- gdSupport = true;
- };
+ nagios = callPackage ../servers/monitoring/nagios { };
munin = callPackage ../servers/monitoring/munin { };
- nagiosPluginsOfficial = callPackage ../servers/monitoring/nagios/plugins/official { };
+ nagiosPluginsOfficial = callPackage ../servers/monitoring/nagios/plugins/official-2.x.nix { };
net_snmp = callPackage ../servers/monitoring/net-snmp { };