From 434f607ada78cb2a2b4c6dadb09d040c8bbe161e Mon Sep 17 00:00:00 2001 From: Urban Müller Date: Thu, 22 Jun 2017 18:02:58 +0200 Subject: only send error mails once per cluster and service --- it.class | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/it.class b/it.class index 3e83081..8d47b3d 100644 --- a/it.class +++ b/it.class @@ -162,7 +162,7 @@ static function error($p = array()) 'omitdebuginfo' => false, 'failcount' => 2, ); - $p += array('blockmailid' => md5($p['to'])); + $p += array('blockmailid' => $GLOBALS['ULTRASITE'] . "." . md5($p['to'])); @mkdir("/tmp/alertdata"); @chmod("/tmp/alertdata", 0777); @@ -199,15 +199,14 @@ static function error($p = array()) if ($sendmail) { - $lastsentfn = "/tmp/alertdata/lastsent_" . getmyuid() . "." . urlencode($p['blockmailid']); - $now = time(); + $lastsentfn = "/tmp/alertdata/it_error_mailsent_" . urlencode($p['blockmailid']); clearstatcache(); - $lastsenttime = @filemtime($lastsentfn); - $sendmail = $now - $lastsenttime > $p['blockmail']; + $sendmail = time() - max(@filemtime($lastsentfn), it_cache::get($lastsentfn, ['distributed' => true])) > $p['blockmail']; if ($sendmail) { @unlink($lastsentfn); @touch($lastsentfn); + it_cache::put($lastsentfn, time(), ['distributed' => true, 'ttl' => 7*86400, 'safety' => 0]); } } } -- cgit v1.2.3