@ -4,21 +4,12 @@
with lib ;
let
cfg = config . services . nagios ;
nagiosUser = " n a g i o s " ;
nagiosGroup = " n o g r o u p " ;
nagiosState = " / v a r / l i b / n a g i o s " ;
nagiosLogDir = " / v a r / l o g / n a g i o s " ;
nagiosObjectDefs =
[ ./timeperiods.cfg
./host-templates.cfg
./service-templates.cfg
./commands.cfg
] ++ cfg . objectDefs ;
nagiosObjectDefs = cfg . objectDefs ;
nagiosObjectDefsDir = pkgs . runCommand " n a g i o s - o b j e c t s " { inherit nagiosObjectDefs ; }
" e n s u r e D i r $ o u t ; l n - s $ n a g i o s O b j e c t D e f s $ o u t / " ;
@ -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 " n a g i o s . c g i . c o n f "
''
main_config_file = $ { nagiosCf gFile}
main_config_file = $ { cfg . mainConfi gFile}
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 } / s b i n " >
Options ExecCGI
AllowOverride None
Order allow , deny
Allow from all
SetEnv NAGIOS_CGI_CONFIG $ { nagiosCGICf gFile}
SetEnv NAGIOS_CGI_CONFIG $ { cfg . cgiConfi gFile}
< /Directory >
Alias $ { urlPath } $ { pkgs . nagios } /share
Alias $ { cfg . urlPath } $ { pkgs . nagios } /share
< Directory " ${ pkgs . nagios } / s h a r e " >
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 = " N a g i o s m o n i t o r i n g d a e m o n " ;
home = nagiosState ;
} ;
users . extraUsers . nagios = {
description = " N a g i o s u s e r " ;
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 = nagiosCf gFile;
environment . etc = [
{ source = cfg . mainConfi gFile;
target = " n a g i o s . c f g " ;
} ;
}
] ;
environment . systemPackages = [ pkgs . nagios ] ;
jobs . nagios =
{ description = " N a g i o s m o n i t o r i n g d a e m o n " ;
startOn = " s t a r t e d n e t w o r k - i n t e r f a c e s " ;
stopOn = " s t o p p i n g n e t w o r k - i n t e r f a c e s " ;
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 }
'' ;
systemd . services . nagios = {
description = " N a g i o s m o n i t o r i n g d a e m o n " ;
path = [ pkgs . nagios ] ;
wantedBy = [ " m u l t i - u s e r . t a r g e t " ] ;
after = [ " n e t w o r k - i n t e r f a c e s . t a r g e t " ] ;
serviceConfig = {
User = " n a g i o s " ;
Restart = " a l w a y s " ;
RestartSec = 2 ;
PermissionsStartOnly = true ;
} ;
services . httpd . extraConfig = optionalString cfg . enableWebInterface extraHttpdConfig ;
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 ;
} ;
}