forked from mirrors/nixpkgs
nagios: significant upgrades
- Upgrade Nagios Core to 4.x - Expose mainConfigFile and cgiConfigFile in module for finer configuration control. - Upgrade Plugins to 2.x - Remove default objectDefs, which users probably want to customize. - Systemd-ify Nagios module and simplify directory structure - Upgrade Nagios package with more modern patch, and ensure the statedir is set to /var/lib/nagios Signed-off-by: Austin Seipp <aseipp@pobox.com>
This commit is contained in:
parent
b8ede68b25
commit
6cfa38ce7d
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
<Directory "${pkgs.nagios}/sbin">
|
||||
Options ExecCGI
|
||||
AllowOverride None
|
||||
Order allow,deny
|
||||
Allow from all
|
||||
SetEnv NAGIOS_CGI_CONFIG ${nagiosCGICfgFile}
|
||||
SetEnv NAGIOS_CGI_CONFIG ${cfg.cgiConfigFile}
|
||||
</Directory>
|
||||
|
||||
Alias ${urlPath} ${pkgs.nagios}/share
|
||||
Alias ${cfg.urlPath} ${pkgs.nagios}/share
|
||||
|
||||
<Directory "${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
|
|||
<literal>http://<replaceable>server</replaceable>/<replaceable>urlPath</replaceable></literal>.
|
||||
";
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
|
||||
###### 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;
|
||||
|
||||
};
|
||||
|
||||
}
|
|
@ -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$
|
||||
}
|
|
@ -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
|
||||
}
|
|
@ -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
|
||||
}
|
|
@ -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
|
||||
}
|
|
@ -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 ];
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 ];
|
||||
};
|
||||
}
|
|
@ -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 { };
|
||||
|
||||
|
|
Loading…
Reference in a new issue