2008-11-23 01:28:34 +00:00
|
|
|
# Nagios system/network monitoring daemon.
|
2008-12-04 15:48:27 +00:00
|
|
|
{config, pkgs, ...}:
|
2007-11-12 16:43:35 +00:00
|
|
|
|
2008-11-23 01:28:34 +00:00
|
|
|
###### interface
|
2007-11-12 16:43:35 +00:00
|
|
|
let
|
2008-11-23 01:28:34 +00:00
|
|
|
inherit (pkgs.lib) mkOption;
|
|
|
|
|
|
|
|
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 {
|
|
|
|
default = [pkgs.nagiosPluginsOfficial pkgs.ssmtp];
|
|
|
|
description = "
|
|
|
|
Packages to be added to the Nagios <envar>PATH</envar>.
|
|
|
|
Typically used to add plugins, but can be anything.
|
|
|
|
";
|
|
|
|
};
|
|
|
|
|
|
|
|
enableWebInterface = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "
|
|
|
|
Whether to enable the Nagios web interface. You should also
|
|
|
|
enable Apache (<option>services.httpd.enable</option>).
|
|
|
|
";
|
|
|
|
};
|
|
|
|
|
|
|
|
urlPath = mkOption {
|
|
|
|
default = "/nagios";
|
|
|
|
description = "
|
|
|
|
The URL path under which the Nagios web interface appears.
|
|
|
|
That is, you can access the Nagios web interface through
|
|
|
|
<literal>http://<replaceable>server</replaceable>/<replaceable>urlPath</replaceable></literal>.
|
|
|
|
";
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
in
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
let
|
|
|
|
cfg = config.services.nagios;
|
2008-11-23 01:29:25 +00:00
|
|
|
inherit (pkgs.lib) mkIf mkThenElse;
|
2007-11-12 16:43:35 +00:00
|
|
|
|
|
|
|
nagiosUser = "nagios";
|
|
|
|
nagiosGroup = "nogroup";
|
|
|
|
|
|
|
|
nagiosState = "/var/lib/nagios";
|
|
|
|
nagiosLogDir = "/var/log/nagios";
|
|
|
|
|
|
|
|
nagiosObjectDefs = [
|
|
|
|
./timeperiods.cfg
|
|
|
|
./host-templates.cfg
|
|
|
|
./service-templates.cfg
|
|
|
|
./commands.cfg
|
2008-11-23 01:28:34 +00:00
|
|
|
] ++ cfg.objectDefs;
|
2007-11-12 16:43:35 +00:00
|
|
|
|
2007-11-19 15:50:02 +00:00
|
|
|
nagiosObjectDefsDir = pkgs.runCommand "nagios-objects" {inherit nagiosObjectDefs;}
|
|
|
|
"ensureDir $out; ln -s $nagiosObjectDefs $out/";
|
2007-11-12 16:43:35 +00: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
|
|
|
|
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
|
|
|
|
|
|
|
|
# Configuration files.
|
|
|
|
#resource_file=resource.cfg
|
|
|
|
cfg_dir=${nagiosObjectDefsDir}
|
|
|
|
|
|
|
|
# Uid/gid that the daemon runs under.
|
|
|
|
nagios_user=${nagiosUser}
|
|
|
|
nagios_group=${nagiosGroup}
|
|
|
|
|
|
|
|
# Misc. options.
|
|
|
|
illegal_macro_output_chars=`~$&|'\"<>
|
|
|
|
retain_state_information=1
|
|
|
|
|
|
|
|
";
|
|
|
|
|
2007-11-23 10:56:12 +00:00
|
|
|
# Plain configuration for the Nagios web-interface with no
|
|
|
|
# authentication.
|
|
|
|
nagiosCGICfgFile = pkgs.writeText "nagios.cgi.conf" "
|
|
|
|
main_config_file=${nagiosCfgFile}
|
|
|
|
use_authentication=0
|
|
|
|
url_html_path=/nagios
|
|
|
|
";
|
|
|
|
|
2008-11-23 01:28:34 +00:00
|
|
|
urlPath = cfg.urlPath;
|
2007-11-23 10:56:12 +00:00
|
|
|
|
|
|
|
extraHttpdConfig = "
|
|
|
|
ScriptAlias ${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}
|
|
|
|
</Directory>
|
|
|
|
|
|
|
|
Alias ${urlPath} ${pkgs.nagios}/share
|
|
|
|
|
|
|
|
<Directory \"${pkgs.nagios}/share\">
|
|
|
|
Options None
|
|
|
|
AllowOverride None
|
|
|
|
Order allow,deny
|
|
|
|
Allow from all
|
|
|
|
</Directory>
|
|
|
|
";
|
2008-11-23 01:28:34 +00:00
|
|
|
|
|
|
|
user = {
|
|
|
|
name = nagiosUser;
|
|
|
|
uid = (import ../../system/ids.nix).uids.nagios;
|
|
|
|
description = "Nagios monitoring daemon";
|
|
|
|
home = nagiosState;
|
|
|
|
};
|
|
|
|
|
|
|
|
job = {
|
|
|
|
name = "nagios";
|
2007-11-23 10:56:12 +00:00
|
|
|
|
2008-11-23 01:28:34 +00:00
|
|
|
# Run `nagios -v' to check the validity of the configuration file so
|
|
|
|
# that a nixos-rebuild fails *before* we kill the running Nagios
|
|
|
|
# daemon.
|
|
|
|
buildHook = "${pkgs.nagios}/bin/nagios -v ${nagiosCfgFile}";
|
|
|
|
|
|
|
|
job = "
|
|
|
|
description \"Nagios monitoring daemon\"
|
|
|
|
|
|
|
|
start on network-interfaces/started
|
|
|
|
stop on network-interfaces/stop
|
|
|
|
|
|
|
|
start script
|
|
|
|
mkdir -m 0755 -p ${nagiosState} ${nagiosLogDir}
|
|
|
|
chown ${nagiosUser} ${nagiosState} ${nagiosLogDir}
|
|
|
|
end script
|
|
|
|
|
|
|
|
respawn
|
|
|
|
|
|
|
|
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}
|
|
|
|
end script
|
|
|
|
";
|
|
|
|
};
|
2007-11-12 16:43:35 +00:00
|
|
|
in
|
|
|
|
|
2008-11-23 01:29:25 +00:00
|
|
|
mkIf cfg.enable {
|
2008-11-23 01:28:34 +00:00
|
|
|
require = [
|
2009-05-20 00:14:45 +01:00
|
|
|
../../upstart-jobs/default.nix # config.services.extraJobs
|
|
|
|
# ../../system/user.nix # users = { .. }
|
|
|
|
# ? # config.environment.etc
|
|
|
|
# ? # config.environment.extraPackages
|
|
|
|
# ../../upstart-jobs/httpd.nix # config.services.httpd
|
2008-11-23 01:28:34 +00:00
|
|
|
options
|
2007-11-12 16:43:35 +00:00
|
|
|
];
|
|
|
|
|
2008-11-23 01:28:34 +00:00
|
|
|
environment = {
|
|
|
|
# This isn't needed, it's just so that the user can type "nagiostats
|
|
|
|
# -c /etc/nagios.cfg".
|
2008-11-23 01:29:25 +00:00
|
|
|
etc = [
|
2008-11-23 01:28:34 +00:00
|
|
|
{ source = nagiosCfgFile;
|
|
|
|
target = "nagios.cfg";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2008-11-23 01:29:25 +00:00
|
|
|
extraPackages = [pkgs.nagios];
|
2008-11-23 01:28:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
users = {
|
2008-11-23 01:29:25 +00:00
|
|
|
extraUsers = [user];
|
2008-11-23 01:28:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
services = {
|
2008-11-23 01:29:25 +00:00
|
|
|
extraJobs = [job];
|
2008-11-23 01:28:34 +00:00
|
|
|
|
2008-11-23 01:29:25 +00:00
|
|
|
httpd = mkIf cfg.enableWebInterface {
|
|
|
|
extraConfig = mkThenElse {
|
|
|
|
thenPart = extraHttpdConfig;
|
|
|
|
elsePart = "";
|
|
|
|
};
|
2008-11-23 01:28:34 +00:00
|
|
|
};
|
|
|
|
};
|
2007-11-12 16:43:35 +00:00
|
|
|
}
|