From: Ismaƫl Bouya Date: Fri, 17 Jan 2020 16:57:49 +0000 (+0100) Subject: Add e-mail relay monitoring for backup-2 and monitoring-1 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=ef0a9217fba817d7fb71ccd4cca65919dd89ebec;p=perso%2FImmae%2FConfig%2FNix.git Add e-mail relay monitoring for backup-2 and monitoring-1 --- diff --git a/modules/private/environment.nix b/modules/private/environment.nix index ffb61c5..c4c32c8 100644 --- a/modules/private/environment.nix +++ b/modules/private/environment.nix @@ -493,8 +493,8 @@ in port = mkOption { type = nullOr str; default = null; description = "Port to connect to ssh"; }; login = mkOption { type = nullOr str; default = null; description = "Login to connect to ssh"; }; targets = mkOption { type = listOf str; description = "Hosts to send E-mails to"; }; - mail_address = mkOption { type = str; description = "E-mail recipient part to send e-mail to"; }; - mail_domain = mkOption { type = str; description = "E-mail domain part to send e-mail to"; }; + mail_address = mkOption { type = nullOr str; default = null; description = "E-mail recipient part to send e-mail to"; }; + mail_domain = mkOption { type = nullOr str; default = null; description = "E-mail domain part to send e-mail to"; }; }; }); }; diff --git a/modules/private/mail/postfix.nix b/modules/private/mail/postfix.nix index 51f4de7..2af1849 100644 --- a/modules/private/mail/postfix.nix +++ b/modules/private/mail/postfix.nix @@ -267,9 +267,12 @@ ); }; sasl_access = { - host_sender_login = pkgs.writeText "host-sender-login" - (builtins.concatStringsSep "\n" (lib.flatten (lib.attrsets.mapAttrsToList - (n: v: (map (e: "${e} ${n}@immae.eu") v.emails)) config.myEnv.servers))); + host_sender_login = with lib.attrsets; let + addresses = zipAttrs (lib.flatten (mapAttrsToList + (n: v: (map (e: { "${e}" = "${n}@immae.eu"; }) v.emails)) config.myEnv.servers)); + joined = builtins.concatStringsSep ","; + in pkgs.writeText "host-sender-login" + (builtins.concatStringsSep "\n" (mapAttrsToList (n: v: "${n} ${joined v}") addresses)); host_dummy_mailboxes = pkgs.writeText "host-virtual-mailbox" (builtins.concatStringsSep "\n" (lib.attrsets.mapAttrsToList (n: v: "${n}@immae.eu dummy") nodes)); }; diff --git a/modules/private/monitoring/objects_backup-2.nix b/modules/private/monitoring/objects_backup-2.nix index 52289dd..927cc25 100644 --- a/modules/private/monitoring/objects_backup-2.nix +++ b/modules/private/monitoring/objects_backup-2.nix @@ -1,4 +1,4 @@ -{ config, pkgs, lib, hostFQDN, ... }: +{ config, pkgs, lib, hostFQDN, emailCheck, ... }: let defaultPassiveInfo = { filter = lib.attrsets.filterAttrs @@ -12,6 +12,9 @@ let in { service = [ + (emailCheck "backup-2" hostFQDN // { + passiveInfo = defaultPassiveInfo // { servicegroups = "webstatus-email"; freshness_threshold = "1350"; }; + }) { passiveInfo = defaultPassiveInfo; service_description = "Size on /backup2 partition"; diff --git a/modules/private/monitoring/objects_monitoring-1.nix b/modules/private/monitoring/objects_monitoring-1.nix index f69d3ff..3200d5c 100644 --- a/modules/private/monitoring/objects_monitoring-1.nix +++ b/modules/private/monitoring/objects_monitoring-1.nix @@ -1,4 +1,4 @@ -{ config, pkgs, ... }: +{ config, pkgs, hostFQDN, emailCheck, ... }: { host = { # Dummy host for testing @@ -22,6 +22,8 @@ # check_command = "check_critical"; # } + (emailCheck "monitoring-1" hostFQDN) + { service_description = "ftp has access to database for authentication"; host_name = "eldiron.immae.eu"; diff --git a/modules/private/monitoring/plugins/check_emails b/modules/private/monitoring/plugins/check_emails index 0ee3e4e..5a8453e 100755 --- a/modules/private/monitoring/plugins/check_emails +++ b/modules/private/monitoring/plugins/check_emails @@ -37,7 +37,7 @@ my @emails_to_expect = split(/,/, $opts{'f'}); my $cmd_result; if ($local_directory ne '') { - if (! -d $local_directory) { + if (@emails_to_expect and ! -d $local_directory) { print "Emails $host UNKNOWN - Could not find local directory"; exit($STATE_UNKNOWN); }