diff options
-rw-r--r-- | it.class | 41 | ||||
-rw-r--r-- | url.class | 4 |
2 files changed, 15 insertions, 30 deletions
@@ -65,14 +65,11 @@ function timerlog($label = '') * @parma $title (optional) error title, one line * @param $body (optional) error body, multiline * @param $to (optional) comma separated recipient list - * @param named parameter ok indicates no error happened - * @param named parameter ok_key indicates which variable to store failure counts in - * @param named parameter ok_maxfail number of failures needed for alert; default 2. only 1 failure per 60 seconds counted + * @param named parameter id identifier of error. if given, only subsequent errors of same id will trigger message + * @param named parameter timewindow number of seconds within which the second error must occur */ function error($p = array(), $body = "", $to = "") { - $p += array('ok_key' => "it_error", 'ok_maxfail' => 2); - if (is_array($p)) { $title = $p['title']; @@ -82,36 +79,24 @@ function error($p = array(), $body = "", $to = "") else { $title = $p; - unset($p); + $p = array(); } + $p += array('timewindow' => 25*3600); + if (!$to) $to = strtr(trim(@file_get_contents($GLOBALS['ULTRAHOME'] . "/.diffnotice")), array("\n"=>',', ' '=>'')); - if (isset($p['ok'])) + if ($p['id']) { - $counterfn = $GLOBALS['ULTRAHOME'] . "/tmp/" . urlencode($p['ok_key']); - - if (time() - @filemtime($counterfn) >= 60) # only modify counter if unmodified for 60 secs - { - $oldcounter = intval(@file_get_contents($counterfn)); - $newcounter = $p['ok'] ? 0 : $oldcounter + 1; + $stampfn = $GLOBALS['ULTRAHOME'] . "/tmp/errstamp_" . urlencode($p['id']); + $stampage = time() - @filemtime($stampfn); - if ($newcounter != $oldcounter) - { - $fh = fopen($counterfn, "w"); - fputs($fh, "$newcounter\n"); - fclose($fh); - - if ($newcounter >= $p['ok_maxfail'] && (time() - @filemtime("$counterfn.mailsent")) >= 86400) # 1 mail per day - { - $sendalert = true; + if ($stampage >= 60 && $stampage <= $p['timewindow']) + $sendalert = true; - if (!ereg('twin|devel', $GLOBALS['ULTRASERVERTYPE'])) - touch("$counterfn.mailsent"); - } - } - } + if ($stampage >= 60) # constantly occurring errors should not suppress mail + touch($stampfn); } else $sendalert = true; @@ -124,7 +109,7 @@ function error($p = array(), $body = "", $to = "") $body .= "\nUrl: $url\n\n\$_REQUEST: ".print_r($_REQUEST, true). "\nStack:\n" . print_r(array_slice(debug_backtrace(), 1), true) . "\n\$_SERVER: " . print_r($_SERVER, true); - if (ereg('twin|devel', $GLOBALS['ULTRASERVERTYPE'])) + if (!ereg('live', $GLOBALS['ULTRASERVERTYPE'])) { echo "<pre>$title\n$body\n</pre>"; } @@ -362,8 +362,8 @@ function get_cache($p = array()) if (($parts = parse_url($p['url'])) === false) it::error('malformed url ' . $p['url']); - if ($p['safety'] == 1) - it::error(array('title'=>"get_cache: download failures on {$p['url']}", 'ok_key'=>"ok_".$parts['host'], 'ok'=>$result ? 1 : 0)); # send err only if multi failure + if ($p['safety'] == 1 && !$result) + it::error(array('title'=>"get_cache: download failures on {$p['url']}", 'id'=>$parts['host'])); # send err only if multi failure @unlink("$path.lock"); } |