diff --git a/system/options.nix b/system/options.nix
index 9eb92f7322fc..2fb33c40c2fc 100644
--- a/system/options.nix
+++ b/system/options.nix
@@ -2150,53 +2150,6 @@ in
};
- nagios = {
-
- enable = mkOption {
- default = false;
- description = "
- Whether to use Nagios 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 PATH.
- 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 ().
- ";
- };
-
- 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
- http://server/urlPath.
- ";
- };
-
- };
-
-
mysql = {
enable = mkOption {
default = false;
@@ -3082,6 +3035,7 @@ root ALL=(ALL) SETENV: ALL
(import ../upstart-jobs/pcmcia.nix)
# services
+ (import ../upstart-jobs/nagios/default.nix)
(import ../upstart-jobs/zabbix-agent.nix)
(import ../upstart-jobs/zabbix-server.nix)
(import ../upstart-jobs/disnix.nix)
diff --git a/upstart-jobs/default.nix b/upstart-jobs/default.nix
index a8c422e2427f..7604587fe1df 100644
--- a/upstart-jobs/default.nix
+++ b/upstart-jobs/default.nix
@@ -412,12 +412,6 @@ let
gpmConfig = config.services.gpm;
})
- # Nagios system/network monitoring daemon.
- ++ optional config.services.nagios.enable
- (import ../upstart-jobs/nagios {
- inherit config pkgs;
- })
-
# Postfix mail server.
++ optional config.services.postfix.enable
(import ../upstart-jobs/postfix.nix {
diff --git a/upstart-jobs/nagios/default.nix b/upstart-jobs/nagios/default.nix
index 256693ba072c..f8294b203c6b 100644
--- a/upstart-jobs/nagios/default.nix
+++ b/upstart-jobs/nagios/default.nix
@@ -1,6 +1,64 @@
+# Nagios system/network monitoring daemon.
{config, pkgs}:
+###### interface
let
+ inherit (pkgs.lib) mkOption;
+
+ options = {
+ services = {
+ nagios = {
+
+ enable = mkOption {
+ default = false;
+ description = "
+ Whether to use Nagios 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 PATH.
+ 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 ().
+ ";
+ };
+
+ 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
+ http://server/urlPath.
+ ";
+ };
+
+ };
+ };
+ };
+in
+
+###### implementation
+let
+ cfg = config.services.nagios;
nagiosUser = "nagios";
nagiosGroup = "nogroup";
@@ -13,7 +71,7 @@ let
./host-templates.cfg
./service-templates.cfg
./commands.cfg
- ] ++ config.services.nagios.objectDefs;
+ ] ++ cfg.objectDefs;
nagiosObjectDefsDir = pkgs.runCommand "nagios-objects" {inherit nagiosObjectDefs;}
"ensureDir $out; ln -s $nagiosObjectDefs $out/";
@@ -53,7 +111,7 @@ let
url_html_path=/nagios
";
- urlPath = config.services.nagios.urlPath;
+ urlPath = cfg.urlPath;
extraHttpdConfig = "
ScriptAlias ${urlPath}/cgi-bin ${pkgs.nagios}/sbin
@@ -75,57 +133,81 @@ let
Allow from all
";
+
+ user = {
+ name = nagiosUser;
+ uid = (import ../../system/ids.nix).uids.nagios;
+ description = "Nagios monitoring daemon";
+ home = nagiosState;
+ };
+
+ job = {
+ name = "nagios";
+ # 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
+ ";
+ };
+
+ ifEnable = pkgs.lib.ifEnable cfg.enable;
in
{
- name = "nagios";
-
- users = [
- { name = nagiosUser;
- uid = (import ../../system/ids.nix).uids.nagios;
- description = "Nagios monitoring daemon";
- home = nagiosState;
- }
+ require = [
+ (import ../../upstart-jobs/default.nix) # config.services.extraJobs
+ # (import ../../system/user.nix) # users = { .. }
+ # (import ?) # config.environment.etc
+ # (import ?) # config.environment.extraPackages
+ # (import ../../upstart-jobs/httpd.nix) # config.services.httpd
+ options
];
- extraPath = [pkgs.nagios];
+ environment = {
+ # This isn't needed, it's just so that the user can type "nagiostats
+ # -c /etc/nagios.cfg".
+ etc = ifEnable [
+ { source = nagiosCfgFile;
+ target = "nagios.cfg";
+ }
+ ];
- # This isn't needed, it's just so that the user can type "nagiostats
- # -c /etc/nagios.cfg".
- extraEtc = [
- { source = nagiosCfgFile;
- target = "nagios.cfg";
- }
- ];
+ extraPackages = ifEnable [pkgs.nagios];
+ };
- extraHttpdConfig =
- if config.services.nagios.enableWebInterface then extraHttpdConfig else "";
-
- # 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}";
+ users = {
+ extraUsers = ifEnable [user];
+ };
- job = "
- description \"Nagios monitoring daemon\"
+ services = {
+ extraJobs = ifEnable [job];
- 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
- ";
-
+ httpd = {
+ extraConfig = # ifEnable does not handle strings yet.
+ if cfg.enable && cfg.enableWebInterface
+ then extraHttpdConfig
+ else "";
+ };
+ };
}