]> git.immae.eu Git - perso/Immae/Config/Nix.git/blob - systems/monitoring-1/status.nix
Squash changes containing private information
[perso/Immae/Config/Nix.git] / systems / monitoring-1 / status.nix
1 { config, pkgs, lib, name, ... }:
2 {
3 options = {
4 myServices.status = {
5 enable = lib.mkOption {
6 type = lib.types.bool;
7 default = false;
8 description = ''
9 Whether to enable status app.
10 '';
11 };
12 };
13 };
14 config = lib.mkIf config.myServices.status.enable {
15 secrets.keys."naemon-status/environment" = {
16 user = "naemon";
17 group = "naemon";
18 permissions = "0400";
19 text = ''
20 TOKENS=${builtins.concatStringsSep " " config.myEnv.monitoring.nrdp_tokens}
21 '';
22 };
23 services.nginx = {
24 enable = true;
25 recommendedOptimisation = true;
26 recommendedGzipSettings = true;
27 recommendedProxySettings = true;
28 upstreams."netdata".servers = { "127.0.0.1:19999" = {}; };
29 upstreams."netdata".extraConfig = ''
30 keepalive 64;
31 '';
32 virtualHosts."status.immae.eu" = {
33 acmeRoot = config.security.acme.defaults.webroot;
34 useACMEHost = name;
35 forceSSL = true;
36 locations."/".proxyPass = "http://unix:/run/naemon-status/socket.sock:/";
37
38 locations."= /netdata".return = "301 /netdata/";
39 locations."~ /netdata/(?<ndpath>.*)".extraConfig = ''
40 proxy_redirect off;
41 proxy_set_header Host $host;
42
43 proxy_set_header X-Forwarded-Host $host;
44 proxy_set_header X-Forwarded-Server $host;
45 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
46 proxy_http_version 1.1;
47 proxy_pass_request_headers on;
48 proxy_set_header Connection "keep-alive";
49 proxy_store off;
50 proxy_pass http://netdata/$ndpath$is_args$args;
51
52 gzip on;
53 gzip_proxied any;
54 gzip_types *;
55 '';
56 };
57 };
58 security.acme.certs."${name}" = {
59 extraDomainNames = [ "status.immae.eu" ];
60 group = config.services.nginx.group;
61 };
62
63 networking.firewall.allowedTCPPorts = [ 80 443 ];
64 systemd.services.naemon-status = {
65 description = "Naemon status";
66 after = [ "network.target" ];
67 wantedBy = [ "multi-user.target" ];
68
69 serviceConfig = {
70 EnvironmentFile = config.secrets.fullPaths."naemon-status/environment";
71 Type = "simple";
72 WorkingDirectory = "${./status}";
73 ExecStart = let
74 python = pkgs.python3.withPackages (p: [ p.gunicorn p.flask p.flask_login ]);
75 in
76 "${python}/bin/gunicorn -w4 --bind unix:/run/naemon-status/socket.sock app:app";
77 User = "naemon";
78 RuntimeDirectory = "naemon-status";
79 StandardOutput = "journal";
80 StandardError = "inherit";
81 };
82 };
83 };
84 }