blob: c1525711713701006a3e3f60101ee5809a3d7fcf (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.ntopng;
redisCfg = config.services.redis;
configFile = if cfg.configText != "" then
pkgs.writeText "ntopng.conf" ''
${cfg.configText}
''
else
pkgs.writeText "ntopng.conf" ''
${concatStringsSep " " (map (e: "--interface=" + e) cfg.interfaces)}
--http-port=${toString cfg.http-port}
--redis=localhost:${toString redisCfg.port}
${cfg.extraConfig}
'';
in
{
options = {
services.ntopng = {
enable = mkOption {
default = false;
type = types.bool;
description = ''
Enable ntopng, a high-speed web-based traffic analysis and flow
collection tool.
With the default configuration, ntopng monitors all network
interfaces and displays its findings at http://localhost:${toString
cfg.http-port}. Default username and password is admin/admin.
See the ntopng(8) manual page and http://www.ntop.org/products/ntop/
for more info.
Note that enabling ntopng will also enable redis (key-value
database server) for persistent data storage.
'';
};
interfaces = mkOption {
default = [ "any" ];
example = [ "eth0" "wlan0" ];
type = types.listOf types.str;
description = ''
List of interfaces to monitor. Use "any" to monitor all interfaces.
'';
};
http-port = mkOption {
default = 3000;
type = types.int;
description = ''
Sets the HTTP port of the embedded web server.
'';
};
configText = mkOption {
default = "";
example = ''
--interface=any
--http-port=3000
--disable-login
'';
type = types.lines;
description = ''
Overridable configuration file contents to use for ntopng. By
default, use the contents automatically generated by NixOS.
'';
};
extraConfig = mkOption {
default = "";
type = types.lines;
description = ''
Configuration lines that will be appended to the generated ntopng
configuration file. Note that this mechanism does not work when the
manual <option>configText</option> option is used.
'';
};
};
};
config = mkIf cfg.enable {
# ntopng uses redis for data storage
services.redis.enable = true;
# nice to have manual page and ntopng command in PATH
environment.systemPackages = [ pkgs.ntopng ];
systemd.services.ntopng = {
description = "Ntopng Network Monitor";
requires = [ "redis.service" ];
after = [ "network.target" "redis.service" ];
wantedBy = [ "multi-user.target" ];
preStart = "mkdir -p /var/lib/ntopng/";
serviceConfig.ExecStart = "${pkgs.ntopng}/bin/ntopng ${configFile}";
unitConfig.Documentation = "man:ntopng(8)";
};
# ntopng drops priveleges to user "nobody" and that user is already defined
# in users-groups.nix.
};
}
|