aboutsummaryrefslogtreecommitdiff
path: root/systems/monitoring-1/monitoring-master.nix
blob: 09319b8fe7ebb061f9417f9c9226b660f7b84b9a (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
{ config, pkgs, lib, nodes, name, monitoring, ... }:
let
  mlib = monitoring.lib;
  nodesWithMonitoring = lib.filterAttrs (n: v: (v.config.myServices or {}) ? "monitoring") nodes;
in
{
  imports = [
    ./monitoring/master.nix
    ./monitoring/phare.nix
    ./monitoring/ulminfo-fr.nix
  ];
  myServices.monitoring.activatedPlugins = lib.flatten (lib.mapAttrsToList (_: n: n.config.myServices.monitoring.fromMasterActivatedPlugins) nodesWithMonitoring);
  myServices.monitoring.objects = lib.mkMerge (
    lib.mapAttrsToList (_: n:
      mlib.toMasterPassiveObject "external-passive-service" 1.5 n.config.myServices.monitoring.objects
    ) (lib.filterAttrs (n: v: n != name) nodesWithMonitoring)
    ++
    lib.mapAttrsToList (_: n: n.config.myServices.monitoring.fromMasterObjects) nodesWithMonitoring
  );
  myServices.chatonsProperties.hostings.monitoring = {
    file.datetime = "2022-08-27T16:00:00";
    hosting = {
      name = "Monitoring";
      description = "Website and server health monitoring";
      website = "https://status.immae.eu";
      logo = "https://www.naemon.io/favicon.ico";
      status.level = "OK";
      status.description = "OK";
      registration.load = "OPEN";
      install.type = "PACKAGE";
    };
    software = {
      name = "naemon";
      website = "https://www.naemon.io/";
      license.url = "https://github.com/naemon/naemon-core/blob/master/COPYING";
      license.name = "GNU General Public License v2.0";
      version = config.services.naemon.package.version;
      source.url = "https://github.com/naemon/naemon-core";
      modules = "livestatus,status-engine";
    };
  };

  services.nginx = {
    virtualHosts."status.immae.eu".locations = {
      "=/common/immae.cfg" = {
        alias = pkgs.writeText "immae.cfg" ''
          # put me for instance in /etc/naemon/module-conf.d/immae.cfg
          # Make sure that you have include_dir=module-conf.d in
          # naemon.cfg
          log_initial_states=1
          date_format=iso8601
          admin_email=${config.myEnv.monitoring.email}
          obsess_over_services=1
          ocsp_command=notify-master
        '';
      };
      "=/common/resource.cfg" = {
        alias = pkgs.writeText "resource.cfg" ''
          # Resource.cfg file
          # Replace this with path to monitoring plugins
          $USER1$=@@COMMON_PLUGINS@@
          # Replace this with a path to scripts from
          # https://git.immae.eu/cgit/perso/Immae/Config/Nix.git/tree/modules/private/monitoring/plugins
          $USER2$=@@IMMAE_PLUGINS@@
          $USER200$=https://status.immae.eu/
          $USER201$=@@TOKEN@@
        '';
      };
    };
  };

  secrets.keys = lib.mapAttrs' (k: v: lib.nameValuePair "${k}_access_key" {
    user = "naemon";
    group = "naemon";
    permissions = "0400";
    text = ''
      export AWS_ACCESS_KEY_ID="${v.accessKeyId}"
      export AWS_SECRET_ACCESS_KEY="${v.secretAccessKey}"
      export BASE_URL="${v.remote "immae-eldiron"}"
    '';
  }) config.myEnv.backup.remotes;

  services.naemon.extraConfig = ''
    broker_module=${pkgs.naemon-livestatus}/lib/naemon-livestatus/livestatus.so ${config.services.naemon.runDir}/live
    broker_module=${pkgs.status-engine-module}/lib/status-engine/naemon/statusengine-${pkgs.naemon.status_engine_version}.o use_service_perfdata=1 use_process_data=0 use_system_command_data=0 use_external_command_data=0 use_flapping_data=0 use_program_status_data=0 use_notification_data=0 use_contact_status_data=0 use_contact_notification_data=0 use_event_handler_data=0 use_object_data=0
  '';
}