From ee68e001936050a0999bb3fcc12d87fa2fe04bf4 Mon Sep 17 00:00:00 2001 From: Urban Müller Date: Thu, 12 Dec 2013 16:47:33 +0100 Subject: support edge triggered errors, support special chars in blockmailid --- it.class | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'it.class') diff --git a/it.class b/it.class index bec2965..a6091e3 100644 --- a/it.class +++ b/it.class @@ -120,6 +120,8 @@ static function timerlog($label = '') * @param $p['skipfiles'] files to skip in backtrace * @param $p['blockmail'] number of seconds to block mails after having sent a mail [3600] * @param $p['blockmailid'] block mail for $p['blockmail'] seconds with same id. Default: $p['to'] + * @param $p['okstate'] give current ok label and state, e.g. telresult=1 . see failcount + * @param $p['failcount'] give number of consecutive okstate failures needed for creating an error [2] * @param $p['omitdebuginfo'] Do not add stack dump, locals and environment to output [false] * @return true if a mail was sent */ @@ -144,12 +146,22 @@ static function error($p = array(), $body = null, $to = null) # $body and $to de 'backtraceskip' => 0, 'blockmail' => 3600, 'omitdebuginfo' => false, + 'failcount' => 2, ); $p += array('blockmailid' => md5($p['to'])); @mkdir("/tmp/alertdata"); @chmod("/tmp/alertdata", 0777); + if ($p['okstate']) + { + list($okid, $okstatus) = explode("=", $p['okstate']); + $failcount = $okstatus ? 0 : file_get_contents("/tmp/alertdata/$okid") + 1; + file_put_contents("/tmp/alertdata/$okid", "$failcount\n"); + if ($failcount != $p['failcount']) + return; + } + $toscreen = getenv('NOERRORMAILS') || ini_get('display_errors') || (defined("STDOUT") && posix_isatty(STDOUT)) || EDC('astwin') || EDC('asdevel'); @fseek(STDOUT, 0, SEEK_END); # Work around PHP bug 49819: posix_isatty seeks to start @@ -174,7 +186,7 @@ static function error($p = array(), $body = null, $to = null) # $body and $to de if ($sendmail) { - $lastsentfn = "/tmp/alertdata/lastsent_" . getmyuid() . "." . $p['blockmailid']; + $lastsentfn = "/tmp/alertdata/lastsent_" . getmyuid() . "." . urlencode($p['blockmailid']); $now = time(); clearstatcache(); $lastsenttime = @filemtime($lastsentfn); -- cgit v1.2.3