1 { config, lib, pkgs, ... }:
6 cfg = config.services.naemon;
8 naemonConfig = pkgs.runCommand "naemon-config" {
9 objectsFile = pkgs.writeText "naemon_objects.cfg" cfg.objectDefs;
10 resourceFile = config.secrets.fullPaths."naemon/resources.cfg";
11 extraConfig = pkgs.writeText "extra.cfg" cfg.extraConfig;
12 inherit (cfg) logDir varDir runDir cacheDir;
14 substituteAll ${./naemon.cfg} $out
15 cat $extraConfig >> $out
25 xlink:href='http://www.naemon.org/'>Naemon</link> to monitor
26 your system or network.
30 objectDefs = mkOption {
34 A list of Naemon object configuration that must define
35 the hosts, host groups, services and contacts for the
36 network that you want Naemon to monitor.
40 extraResource = mkOption {
44 # Sets $USER2$ to be the path to event handlers
45 #$USER2$=/usr/lib/monitoring-plugins/eventhandlers
47 # Store some usernames and passwords (hidden from the CGIs)
52 Lines to add to the resource file
53 # You can define $USERx$ macros in this file, which can in turn be used
54 # in command definitions in your host config file(s). $USERx$ macros are
55 # useful for storing sensitive information such as usernames, passwords,
56 # etc. They are also handy for specifying the path to plugins and
57 # event handlers - if you decide to move the plugins or event handlers to
58 # a different directory in the future, you can just update one or two
59 # $USERx$ macros, instead of modifying a lot of command definitions.
61 # Naemon supports up to 256 $USERx$ macros ($USER1$ through $USER256$)
63 # Resource files may also be used to store configuration directives for
64 # external data sources like MySQL...
69 extraConfig = mkOption {
73 Extra config to append to main config
80 description = "User for naemon";
86 description = "Group for naemon";
91 default = "/var/lib/naemon";
92 description = "The directory where naemon stores its data";
97 default = "/var/cache/naemon";
98 description = "The directory where naemon stores its cache";
103 default = "/run/naemon";
104 description = "The directory where naemon stores its runtime files";
109 default = "/var/log/naemon";
110 description = "The directory where naemon stores its log files";
114 type = types.package;
115 default = pkgs.naemon.override {
116 inherit (cfg) varDir cacheDir logDir runDir user group;
119 Naemon package to use
126 config = mkIf cfg.enable {
129 dest = "naemon/resources.cfg";
132 permissions = "0400";
134 $USER1$=${pkgs.monitoring-plugins}/libexec
140 users.users = optionalAttrs (cfg.user == "naemon") {
143 uid = config.ids.uids.nagios;
144 extraGroups = [ "keys" ];
147 users.groups = optionalAttrs (cfg.user == "naemon") {
149 gid = config.ids.gids.nagios;
153 services.filesWatcher.naemon = {
154 paths = [ config.secrets.fullPaths."naemon/resources.cfg" ];
156 systemd.services.naemon = {
157 description = "Naemon monitoring daemon";
158 path = [ cfg.package pkgs.monitoring-plugins ];
159 wantedBy = [ "multi-user.target" ];
160 after = [ "network.target" ];
162 preStart = "${cfg.package}/bin/naemon -vp ${naemonConfig}";
163 script = "${cfg.package}/bin/naemon --daemon ${naemonConfig}";
164 reload = "${pkgs.utillinux}/bin/kill -HUP $MAINPID";
169 StandardOutput = "journal";
170 StandardError = "inherit";
171 PIDFile = "${cfg.runDir}/naemon.pid";
172 LogsDirectory = assert lib.strings.hasPrefix "/var/log/" cfg.logDir;
173 lib.strings.removePrefix "/var/log/" cfg.logDir;
174 CacheDirectory = assert lib.strings.hasPrefix "/var/cache/" cfg.cacheDir;
175 let unprefixed = lib.strings.removePrefix "/var/cache/" cfg.cacheDir;
176 in [ unprefixed "${unprefixed}/checkresults" ];
177 StateDirectory = assert lib.strings.hasPrefix "/var/lib/" cfg.varDir;
178 lib.strings.removePrefix "/var/lib/" cfg.varDir;
179 RuntimeDirectory = assert lib.strings.hasPrefix "/run/" cfg.runDir;
180 lib.strings.removePrefix "/run/" cfg.runDir;