2008-11-23 02:28:34 +01:00
|
|
|
# Nagios system/network monitoring daemon.
|
2014-04-14 16:26:48 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
2007-11-12 17:43:35 +01:00
|
|
|
|
2014-04-14 16:26:48 +02:00
|
|
|
with lib;
|
2008-11-23 02:28:34 +01:00
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.nagios;
|
2007-11-12 17:43:35 +01:00
|
|
|
|
|
|
|
nagiosState = "/var/lib/nagios";
|
|
|
|
nagiosLogDir = "/var/log/nagios";
|
2019-11-04 22:24:55 +01:00
|
|
|
urlPath = "/nagios";
|
2007-11-12 17:43:35 +01:00
|
|
|
|
2014-06-22 06:35:09 +02:00
|
|
|
nagiosObjectDefs = cfg.objectDefs;
|
2007-11-12 17:43:35 +01:00
|
|
|
|
2018-11-08 11:59:03 +01:00
|
|
|
nagiosObjectDefsDir = pkgs.runCommand "nagios-objects" {
|
|
|
|
inherit nagiosObjectDefs;
|
|
|
|
preferLocalBuild = true;
|
|
|
|
} "mkdir -p $out; ln -s $nagiosObjectDefs $out/";
|
2007-11-12 17:43:35 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
nagiosCfgFile = pkgs.writeText "nagios.cfg"
|
|
|
|
''
|
|
|
|
# Paths for state and logs.
|
|
|
|
log_file=${nagiosLogDir}/current
|
|
|
|
log_archive_path=${nagiosLogDir}/archive
|
|
|
|
status_file=${nagiosState}/status.dat
|
|
|
|
object_cache_file=${nagiosState}/objects.cache
|
|
|
|
temp_file=${nagiosState}/nagios.tmp
|
2018-12-19 22:38:14 +01:00
|
|
|
lock_file=/run/nagios.lock # Not used I think.
|
2009-10-12 18:36:19 +02:00
|
|
|
state_retention_file=${nagiosState}/retention.dat
|
2014-06-22 06:35:09 +02:00
|
|
|
query_socket=${nagiosState}/nagios.qh
|
|
|
|
check_result_path=${nagiosState}
|
|
|
|
command_file=${nagiosState}/nagios.cmd
|
2009-10-12 18:36:19 +02:00
|
|
|
|
|
|
|
# Configuration files.
|
|
|
|
#resource_file=resource.cfg
|
|
|
|
cfg_dir=${nagiosObjectDefsDir}
|
|
|
|
|
|
|
|
# Uid/gid that the daemon runs under.
|
2014-06-22 06:35:09 +02:00
|
|
|
nagios_user=nagios
|
2019-05-25 16:13:12 +02:00
|
|
|
nagios_group=nagios
|
2009-10-12 18:36:19 +02:00
|
|
|
|
|
|
|
# Misc. options.
|
|
|
|
illegal_macro_output_chars=`~$&|'"<>
|
|
|
|
retain_state_information=1
|
|
|
|
''; # "
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2007-11-23 11:56:12 +01:00
|
|
|
# Plain configuration for the Nagios web-interface with no
|
|
|
|
# authentication.
|
2009-10-12 18:36:19 +02:00
|
|
|
nagiosCGICfgFile = pkgs.writeText "nagios.cgi.conf"
|
|
|
|
''
|
2014-06-22 06:35:09 +02:00
|
|
|
main_config_file=${cfg.mainConfigFile}
|
2009-10-12 18:36:19 +02:00
|
|
|
use_authentication=0
|
2019-11-04 22:24:55 +01:00
|
|
|
url_html_path=${urlPath}
|
2009-10-12 18:36:19 +02:00
|
|
|
'';
|
2007-11-23 11:56:12 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
extraHttpdConfig =
|
|
|
|
''
|
2019-11-04 22:24:55 +01:00
|
|
|
ScriptAlias ${urlPath}/cgi-bin ${pkgs.nagios}/sbin
|
2009-10-12 18:36:19 +02:00
|
|
|
|
|
|
|
<Directory "${pkgs.nagios}/sbin">
|
|
|
|
Options ExecCGI
|
2019-05-25 16:38:07 +02:00
|
|
|
Require all granted
|
2014-06-22 06:35:09 +02:00
|
|
|
SetEnv NAGIOS_CGI_CONFIG ${cfg.cgiConfigFile}
|
2009-10-12 18:36:19 +02:00
|
|
|
</Directory>
|
|
|
|
|
2019-11-04 22:24:55 +01:00
|
|
|
Alias ${urlPath} ${pkgs.nagios}/share
|
2009-10-12 18:36:19 +02:00
|
|
|
|
|
|
|
<Directory "${pkgs.nagios}/share">
|
|
|
|
Options None
|
2019-05-25 16:38:07 +02:00
|
|
|
Require all granted
|
2009-10-12 18:36:19 +02:00
|
|
|
</Directory>
|
|
|
|
'';
|
2008-11-23 02:28:34 +01:00
|
|
|
|
2007-11-12 17:43:35 +01:00
|
|
|
in
|
2009-10-12 18:36:19 +02:00
|
|
|
{
|
2019-11-04 22:24:55 +01:00
|
|
|
imports = [
|
|
|
|
(mkRemovedOptionModule [ "services" "nagios" "urlPath" ] "The urlPath option has been removed as it is hard coded to /nagios in the nagios package.")
|
|
|
|
];
|
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
options = {
|
|
|
|
services.nagios = {
|
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "
|
|
|
|
Whether to use <link
|
|
|
|
xlink:href='http://www.nagios.org/'>Nagios</link> to monitor
|
|
|
|
your system or network.
|
|
|
|
";
|
|
|
|
};
|
|
|
|
|
|
|
|
objectDefs = mkOption {
|
|
|
|
description = "
|
|
|
|
A list of Nagios object configuration files that must define
|
|
|
|
the hosts, host groups, services and contacts for the
|
|
|
|
network that you want Nagios to monitor.
|
|
|
|
";
|
|
|
|
};
|
|
|
|
|
|
|
|
plugins = mkOption {
|
2016-01-17 19:34:55 +01:00
|
|
|
type = types.listOf types.package;
|
2009-10-12 18:36:19 +02:00
|
|
|
default = [pkgs.nagiosPluginsOfficial pkgs.ssmtp];
|
2016-01-17 19:34:55 +01:00
|
|
|
defaultText = "[pkgs.nagiosPluginsOfficial pkgs.ssmtp]";
|
2009-10-12 18:36:19 +02:00
|
|
|
description = "
|
|
|
|
Packages to be added to the Nagios <envar>PATH</envar>.
|
|
|
|
Typically used to add plugins, but can be anything.
|
|
|
|
";
|
|
|
|
};
|
|
|
|
|
2014-06-22 06:35:09 +02:00
|
|
|
mainConfigFile = mkOption {
|
2016-01-17 19:34:55 +01:00
|
|
|
type = types.package;
|
2014-06-22 06:35:09 +02:00
|
|
|
default = nagiosCfgFile;
|
2016-01-17 19:34:55 +01:00
|
|
|
defaultText = "nagiosCfgFile";
|
2014-06-22 06:35:09 +02:00
|
|
|
description = "
|
|
|
|
Derivation for the main configuration file of Nagios.
|
|
|
|
";
|
|
|
|
};
|
|
|
|
|
|
|
|
cgiConfigFile = mkOption {
|
2016-01-17 19:34:55 +01:00
|
|
|
type = types.package;
|
2014-06-22 06:35:09 +02:00
|
|
|
default = nagiosCGICfgFile;
|
2016-01-17 19:34:55 +01:00
|
|
|
defaultText = "nagiosCGICfgFile";
|
2014-06-22 06:35:09 +02:00
|
|
|
description = "
|
|
|
|
Derivation for the configuration file of Nagios CGI scripts
|
|
|
|
that can be used in web servers for running the Nagios web interface.
|
|
|
|
";
|
|
|
|
};
|
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
enableWebInterface = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "
|
|
|
|
Whether to enable the Nagios web interface. You should also
|
|
|
|
enable Apache (<option>services.httpd.enable</option>).
|
|
|
|
";
|
|
|
|
};
|
|
|
|
|
2019-11-04 22:24:55 +01:00
|
|
|
virtualHost = mkOption {
|
|
|
|
type = types.submodule (import ../web-servers/apache-httpd/per-server-options.nix);
|
|
|
|
example = literalExample ''
|
|
|
|
{ hostName = "example.org";
|
|
|
|
adminAddr = "webmaster@example.org";
|
|
|
|
enableSSL = true;
|
|
|
|
sslServerCert = "/var/lib/acme/example.org/full.pem";
|
|
|
|
sslServerKey = "/var/lib/acme/example.org/key.pem";
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
Apache configuration can be done by adapting <option>services.httpd.virtualHosts</option>.
|
|
|
|
See <xref linkend="opt-services.httpd.virtualHosts"/> for further information.
|
|
|
|
'';
|
2009-10-12 18:36:19 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2018-06-30 01:58:35 +02:00
|
|
|
users.users.nagios = {
|
2014-06-22 06:35:09 +02:00
|
|
|
description = "Nagios user ";
|
|
|
|
uid = config.ids.uids.nagios;
|
|
|
|
home = nagiosState;
|
2019-05-25 16:13:12 +02:00
|
|
|
group = "nagios";
|
2014-06-22 06:35:09 +02:00
|
|
|
};
|
2007-11-12 17:43:35 +01:00
|
|
|
|
2019-05-25 16:13:12 +02:00
|
|
|
users.groups.nagios = { };
|
|
|
|
|
2008-11-23 02:28:34 +01:00
|
|
|
# This isn't needed, it's just so that the user can type "nagiostats
|
|
|
|
# -c /etc/nagios.cfg".
|
2014-06-22 06:35:09 +02:00
|
|
|
environment.etc = [
|
|
|
|
{ source = cfg.mainConfigFile;
|
2008-11-23 02:28:34 +01:00
|
|
|
target = "nagios.cfg";
|
2014-06-22 06:35:09 +02:00
|
|
|
}
|
|
|
|
];
|
2008-11-23 02:28:34 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
environment.systemPackages = [ pkgs.nagios ];
|
2014-06-22 06:35:09 +02:00
|
|
|
systemd.services.nagios = {
|
|
|
|
description = "Nagios monitoring daemon";
|
|
|
|
path = [ pkgs.nagios ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2016-09-10 20:13:40 +02:00
|
|
|
after = [ "network.target" ];
|
2014-06-22 06:35:09 +02:00
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
User = "nagios";
|
2019-05-25 16:13:12 +02:00
|
|
|
Group = "nagios";
|
2014-06-22 06:35:09 +02:00
|
|
|
Restart = "always";
|
|
|
|
RestartSec = 2;
|
2019-05-25 16:33:58 +02:00
|
|
|
LogsDirectory = "nagios";
|
|
|
|
StateDirectory = "nagios";
|
2009-10-12 18:36:19 +02:00
|
|
|
};
|
|
|
|
|
2014-06-22 06:35:09 +02:00
|
|
|
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}
|
|
|
|
'';
|
|
|
|
};
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2019-11-04 22:24:55 +01:00
|
|
|
services.httpd.virtualHosts = optionalAttrs cfg.enableWebInterface {
|
|
|
|
${cfg.virtualHost.hostName} = mkMerge [ cfg.virtualHost { extraConfig = extraHttpdConfig; } ];
|
|
|
|
};
|
2008-11-23 02:28:34 +01:00
|
|
|
};
|
2007-11-12 17:43:35 +01:00
|
|
|
}
|