+ toObjects = pkgs.callPackage ./to_objects.nix {};
+ commonConfig = {
+ eldiron = {
+ processWarn = "250"; processAlert = "400";
+ loadWarn = "8.0"; loadAlert = "10.0";
+ };
+ backup-2 = {
+ processWarn = "60"; processAlert = "70";
+ loadWarn = "1.0"; loadAlert = "2.0";
+ };
+ monitoring-1 = {
+ processWarn = "50"; processAlert = "60";
+ loadWarn = "1.0"; loadAlert = "2.0";
+ };
+ };
+ masterPassiveObjects = let
+ passiveNodes = lib.attrsets.filterAttrs (n: _: builtins.elem n ["backup-2" "eldiron"]) nodes;
+ toPassiveServices = map (s: s.passiveInfo.filter s // s.passiveInfo);
+ passiveServices = lib.flatten (lib.attrsets.mapAttrsToList
+ (_: n: toPassiveServices n.config.myServices.monitoring.services)
+ passiveNodes
+ );
+ in {
+ service = passiveServices;
+ host = lib.lists.foldr
+ (a: b: a//b)
+ {}
+ (lib.attrsets.mapAttrsToList (_: h: h.config.myServices.monitoring.hosts) passiveNodes);
+ };
+ emailCheck = host: hostFQDN: let
+ allCfg = config.myEnv.monitoring.email_check;
+ cfg = allCfg."${host}";
+ reverseTargets = builtins.attrNames (lib.attrsets.filterAttrs (k: v: builtins.elem host v.targets) allCfg);
+ to_email = cfg': host':
+ let sep = if lib.strings.hasInfix "+" cfg'.mail_address then "_" else "+";
+ in "${cfg'.mail_address}${sep}${host'}@${cfg'.mail_domain}";
+ mails_to_send = builtins.concatStringsSep "," (map (n: to_email allCfg."${n}" host) cfg.targets);
+ mails_to_receive = builtins.concatStringsSep "," (map (n: "${to_email cfg n}:${n}") reverseTargets);
+ command = if cfg.local
+ then
+ [ "check_emails_local" "/var/lib/naemon/checks/email" mails_to_send mails_to_receive ]
+ else
+ [ "check_emails" cfg.login cfg.port mails_to_send mails_to_receive ];
+ in
+ {
+ service_description = "${hostFQDN} email service is active";
+ use = "mail-service";
+ host_name = hostFQDN;
+ servicegroups = "webstatus-email";
+ check_command = command;
+ };
+ otherObjects = map
+ (n: (pkgs.callPackage (./. + "/objects_" + n + ".nix") { inherit emailCheck; }))
+ [ "caldance-1" "ulminfo-fr" "phare" "tiboqorl-fr" ];
+ masterObjects = pkgs.callPackage ./objects_master.nix { inherit config; };
+ commonObjects = pkgs.callPackage ./objects_common.nix ({
+ master = cfg.master;
+ hostFQDN = config.hostEnv.fqdn;
+ hostName = name;
+ sudo = "/run/wrappers/bin/sudo";
+ } // builtins.getAttr name commonConfig);
+ hostObjects =
+ let
+ specific_file = ./. + "/objects_" + name + ".nix";
+ in
+ lib.attrsets.optionalAttrs
+ (builtins.pathExists specific_file)
+ (pkgs.callPackage specific_file {
+ inherit config emailCheck;
+ hostFQDN = config.hostEnv.fqdn;
+ hostName = name;
+ });