]> git.immae.eu Git - perso/Immae/Config/Nix.git/blobdiff - modules/private/monitoring/plugins/check_emails
Add status engine website
[perso/Immae/Config/Nix.git] / modules / private / monitoring / plugins / check_emails
index 0ee3e4e698052a3e7c7ed31f95098299ee82a33a..534e5a5096bf3943c766ba4c92ac15e529510923 100755 (executable)
@@ -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);
   }
@@ -61,6 +61,7 @@ foreach my $line (@lines) {
 }
 
 my $output = "";
+my $old = 0;
 foreach my $email_from (@emails_to_expect) {
   my @email_split = split(/:/, $email_from);
   my $email = $email_split[0];
@@ -73,16 +74,17 @@ foreach my $email_from (@emails_to_expect) {
     if ($current_date - $email_date > 60*30) {
       $output = "$output$email ($found_emails{$email} from $from) ";
     }
+    $old = ($current_date - $email_date) > $old ? ($current_date - $email_date) : $old;
   } else {
     $output = "$output$email (missing) "
   }
 }
 
 if ($output ne '') {
-  print "Emails $host CRITICAL - expecting emails: $output\n";
+  print "Emails $host CRITICAL - expecting emails: $output | timestamp=${old}s;;;;\n";
   exit($STATE_CRITICAL);
 } else {
-  print "Emails $host OK\n";
+  print "Emails $host OK | timestamp=${old}s;;;;\n";
   exit($STATE_OK);
 }