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/graphite.nix
|
||||||
./services/monitoring/monit.nix
|
./services/monitoring/monit.nix
|
||||||
./services/monitoring/munin.nix
|
./services/monitoring/munin.nix
|
||||||
./services/monitoring/nagios/default.nix
|
./services/monitoring/nagios.nix
|
||||||
./services/monitoring/smartd.nix
|
./services/monitoring/smartd.nix
|
||||||
./services/monitoring/statsd.nix
|
./services/monitoring/statsd.nix
|
||||||
./services/monitoring/systemhealth.nix
|
./services/monitoring/systemhealth.nix
|
||||||
|
@ -4,21 +4,12 @@
|
|||||||
with lib;
|
with lib;
|
||||||
|
|
||||||
let
|
let
|
||||||
|
|
||||||
cfg = config.services.nagios;
|
cfg = config.services.nagios;
|
||||||
|
|
||||||
nagiosUser = "nagios";
|
|
||||||
nagiosGroup = "nogroup";
|
|
||||||
|
|
||||||
nagiosState = "/var/lib/nagios";
|
nagiosState = "/var/lib/nagios";
|
||||||
nagiosLogDir = "/var/log/nagios";
|
nagiosLogDir = "/var/log/nagios";
|
||||||
|
|
||||||
nagiosObjectDefs =
|
nagiosObjectDefs = cfg.objectDefs;
|
||||||
[ ./timeperiods.cfg
|
|
||||||
./host-templates.cfg
|
|
||||||
./service-templates.cfg
|
|
||||||
./commands.cfg
|
|
||||||
] ++ cfg.objectDefs;
|
|
||||||
|
|
||||||
nagiosObjectDefsDir = pkgs.runCommand "nagios-objects" {inherit nagiosObjectDefs;}
|
nagiosObjectDefsDir = pkgs.runCommand "nagios-objects" {inherit nagiosObjectDefs;}
|
||||||
"ensureDir $out; ln -s $nagiosObjectDefs $out/";
|
"ensureDir $out; ln -s $nagiosObjectDefs $out/";
|
||||||
@ -30,19 +21,20 @@ let
|
|||||||
log_archive_path=${nagiosLogDir}/archive
|
log_archive_path=${nagiosLogDir}/archive
|
||||||
status_file=${nagiosState}/status.dat
|
status_file=${nagiosState}/status.dat
|
||||||
object_cache_file=${nagiosState}/objects.cache
|
object_cache_file=${nagiosState}/objects.cache
|
||||||
comment_file=${nagiosState}/comment.dat
|
|
||||||
downtime_file=${nagiosState}/downtime.dat
|
|
||||||
temp_file=${nagiosState}/nagios.tmp
|
temp_file=${nagiosState}/nagios.tmp
|
||||||
lock_file=/var/run/nagios.lock # Not used I think.
|
lock_file=/var/run/nagios.lock # Not used I think.
|
||||||
state_retention_file=${nagiosState}/retention.dat
|
state_retention_file=${nagiosState}/retention.dat
|
||||||
|
query_socket=${nagiosState}/nagios.qh
|
||||||
|
check_result_path=${nagiosState}
|
||||||
|
command_file=${nagiosState}/nagios.cmd
|
||||||
|
|
||||||
# Configuration files.
|
# Configuration files.
|
||||||
#resource_file=resource.cfg
|
#resource_file=resource.cfg
|
||||||
cfg_dir=${nagiosObjectDefsDir}
|
cfg_dir=${nagiosObjectDefsDir}
|
||||||
|
|
||||||
# Uid/gid that the daemon runs under.
|
# Uid/gid that the daemon runs under.
|
||||||
nagios_user=${nagiosUser}
|
nagios_user=nagios
|
||||||
nagios_group=${nagiosGroup}
|
nagios_group=nogroup
|
||||||
|
|
||||||
# Misc. options.
|
# Misc. options.
|
||||||
illegal_macro_output_chars=`~$&|'"<>
|
illegal_macro_output_chars=`~$&|'"<>
|
||||||
@ -53,26 +45,24 @@ let
|
|||||||
# authentication.
|
# authentication.
|
||||||
nagiosCGICfgFile = pkgs.writeText "nagios.cgi.conf"
|
nagiosCGICfgFile = pkgs.writeText "nagios.cgi.conf"
|
||||||
''
|
''
|
||||||
main_config_file=${nagiosCfgFile}
|
main_config_file=${cfg.mainConfigFile}
|
||||||
use_authentication=0
|
use_authentication=0
|
||||||
url_html_path=/nagios
|
url_html_path=${cfg.urlPath}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
urlPath = cfg.urlPath;
|
|
||||||
|
|
||||||
extraHttpdConfig =
|
extraHttpdConfig =
|
||||||
''
|
''
|
||||||
ScriptAlias ${urlPath}/cgi-bin ${pkgs.nagios}/sbin
|
ScriptAlias ${cfg.urlPath}/cgi-bin ${pkgs.nagios}/sbin
|
||||||
|
|
||||||
<Directory "${pkgs.nagios}/sbin">
|
<Directory "${pkgs.nagios}/sbin">
|
||||||
Options ExecCGI
|
Options ExecCGI
|
||||||
AllowOverride None
|
AllowOverride None
|
||||||
Order allow,deny
|
Order allow,deny
|
||||||
Allow from all
|
Allow from all
|
||||||
SetEnv NAGIOS_CGI_CONFIG ${nagiosCGICfgFile}
|
SetEnv NAGIOS_CGI_CONFIG ${cfg.cgiConfigFile}
|
||||||
</Directory>
|
</Directory>
|
||||||
|
|
||||||
Alias ${urlPath} ${pkgs.nagios}/share
|
Alias ${cfg.urlPath} ${pkgs.nagios}/share
|
||||||
|
|
||||||
<Directory "${pkgs.nagios}/share">
|
<Directory "${pkgs.nagios}/share">
|
||||||
Options None
|
Options None
|
||||||
@ -83,14 +73,9 @@ let
|
|||||||
'';
|
'';
|
||||||
|
|
||||||
in
|
in
|
||||||
|
|
||||||
{
|
{
|
||||||
###### interface
|
|
||||||
|
|
||||||
options = {
|
options = {
|
||||||
|
|
||||||
services.nagios = {
|
services.nagios = {
|
||||||
|
|
||||||
enable = mkOption {
|
enable = mkOption {
|
||||||
default = false;
|
default = false;
|
||||||
description = "
|
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 {
|
enableWebInterface = mkOption {
|
||||||
default = false;
|
default = false;
|
||||||
description = "
|
description = "
|
||||||
@ -132,55 +132,53 @@ in
|
|||||||
<literal>http://<replaceable>server</replaceable>/<replaceable>urlPath</replaceable></literal>.
|
<literal>http://<replaceable>server</replaceable>/<replaceable>urlPath</replaceable></literal>.
|
||||||
";
|
";
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
###### implementation
|
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
|
users.extraUsers.nagios = {
|
||||||
users.extraUsers = singleton
|
description = "Nagios user ";
|
||||||
{ name = nagiosUser;
|
uid = config.ids.uids.nagios;
|
||||||
uid = config.ids.uids.nagios;
|
home = nagiosState;
|
||||||
description = "Nagios monitoring daemon";
|
createHome = true;
|
||||||
home = nagiosState;
|
};
|
||||||
};
|
|
||||||
|
|
||||||
# This isn't needed, it's just so that the user can type "nagiostats
|
# This isn't needed, it's just so that the user can type "nagiostats
|
||||||
# -c /etc/nagios.cfg".
|
# -c /etc/nagios.cfg".
|
||||||
environment.etc = singleton
|
environment.etc = [
|
||||||
{ source = nagiosCfgFile;
|
{ source = cfg.mainConfigFile;
|
||||||
target = "nagios.cfg";
|
target = "nagios.cfg";
|
||||||
};
|
}
|
||||||
|
];
|
||||||
|
|
||||||
environment.systemPackages = [ pkgs.nagios ];
|
environment.systemPackages = [ pkgs.nagios ];
|
||||||
|
systemd.services.nagios = {
|
||||||
|
description = "Nagios monitoring daemon";
|
||||||
|
path = [ pkgs.nagios ];
|
||||||
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
after = [ "network-interfaces.target" ];
|
||||||
|
|
||||||
jobs.nagios =
|
serviceConfig = {
|
||||||
{ description = "Nagios monitoring daemon";
|
User = "nagios";
|
||||||
|
Restart = "always";
|
||||||
startOn = "started network-interfaces";
|
RestartSec = 2;
|
||||||
stopOn = "stopping network-interfaces";
|
PermissionsStartOnly = true;
|
||||||
|
|
||||||
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}
|
|
||||||
'';
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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;
|
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
|
{ stdenv, fetchurl, perl, php, gd, libpng, zlib }:
|
||||||
, gd ? null, libpng ? null, zlib ? null
|
|
||||||
}:
|
|
||||||
|
|
||||||
stdenv.mkDerivation {
|
stdenv.mkDerivation {
|
||||||
name = "nagios-2.10";
|
name = "nagios-4.0.7";
|
||||||
|
|
||||||
src = fetchurl {
|
src = fetchurl {
|
||||||
url = mirror://sourceforge/nagios/nagios-2.10.tar.gz;
|
url = mirror://sourceforge/nagios/nagios-4.x/nagios-4.0.7/nagios-4.0.7.tar.gz;
|
||||||
md5 = "8c3a29e138f2ff8c8abbd3dd8a40c4b6";
|
sha256 = "1687qnbsag84r57y9745g2klypacfixd6gkzaj42lmzn0v8y27gg";
|
||||||
};
|
};
|
||||||
|
|
||||||
patches = [./nagios.patch];
|
patches = [ ./nagios.patch ];
|
||||||
buildInputs = [perl] ++ (if gdSupport then [gd libpng zlib] else []);
|
buildInputs = [ php perl gd libpng zlib ];
|
||||||
|
|
||||||
|
configureFlags = [ "--localstatedir=/var/lib/nagios" ];
|
||||||
buildFlags = "all";
|
buildFlags = "all";
|
||||||
|
|
||||||
|
# Do not create /var directories
|
||||||
|
preInstall = ''
|
||||||
|
substituteInPlace Makefile --replace '$(MAKE) install-basic' ""
|
||||||
|
'';
|
||||||
installTargets = "install install-config";
|
installTargets = "install install-config";
|
||||||
|
|
||||||
meta = {
|
meta = {
|
||||||
description = "A host, service and network monitoring program";
|
description = "A host, service and network monitoring program";
|
||||||
homepage = http://www.nagios.org/;
|
homepage = http://www.nagios.org/;
|
||||||
license = "GPL";
|
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
|
diff -ruN nagios-4.0.7.orig/configure nagios-4.0.7/configure
|
||||||
--- nagios-2.6/configure 2006-11-28 03:29:04.000000000 +0100
|
--- nagios-4.0.7.orig/configure 2014-06-03 10:41:42.000000000 -0400
|
||||||
+++ nagios-2.6.new/configure 2006-12-28 01:22:56.000000000 +0100
|
+++ nagios-4.0.7/configure 2014-06-12 00:30:17.516468583 -0400
|
||||||
@@ -4810,7 +4810,8 @@
|
@@ -6014,7 +6014,8 @@
|
||||||
#define DEFAULT_NAGIOS_GROUP "$nagios_grp"
|
#define DEFAULT_NAGIOS_GROUP "$nagios_grp"
|
||||||
_ACEOF
|
_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 {
|
stdenv.mkDerivation rec {
|
||||||
name = "nagios-plugins-1.4.10";
|
name = "nagios-plugins-${version}";
|
||||||
|
version = "2.0";
|
||||||
|
|
||||||
src = fetchurl {
|
src = fetchurl {
|
||||||
url = https://www.monitoring-plugins.org/download/nagios-plugins-1.4.10.tar.gz;
|
url = "http://nagios-plugins.org/download/${name}.tar.gz";
|
||||||
sha256 = "0vm7sjiygxbfc5vbsi1g0dakpvynfzi86fhqx4yxd61brn0g8ghr";
|
sha256 = "113nv9jqpbqpdjqilqbj1iyshxyvcmq8w94bq5ajz4dxi9j8045s";
|
||||||
};
|
};
|
||||||
|
|
||||||
# !!! Awful hack. Grrr... this of course only works on NixOS.
|
# !!! Awful hack. Grrr... this of course only works on NixOS.
|
||||||
@ -22,11 +23,14 @@ stdenv.mkDerivation {
|
|||||||
|
|
||||||
postInstall = "ln -s libexec $out/bin";
|
postInstall = "ln -s libexec $out/bin";
|
||||||
|
|
||||||
buildInputs = [openssh]; # !!! make openssh a runtime dependency only
|
# !!! make openssh a runtime dependency only
|
||||||
|
buildInputs = [ openssh ];
|
||||||
|
|
||||||
meta = {
|
meta = {
|
||||||
description = "Plugins for Nagios";
|
description = "Official plugins for Nagios";
|
||||||
homepage = http://www.monitoring-plugins.org;
|
homepage = http://www.nagios.org/download/plugins;
|
||||||
license = "GPL";
|
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 { };
|
mysql_jdbc = callPackage ../servers/sql/mysql/jdbc { };
|
||||||
|
|
||||||
nagios = callPackage ../servers/monitoring/nagios {
|
nagios = callPackage ../servers/monitoring/nagios { };
|
||||||
gdSupport = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
munin = callPackage ../servers/monitoring/munin { };
|
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 { };
|
net_snmp = callPackage ../servers/monitoring/net-snmp { };
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user