summaryrefslogtreecommitdiff
path: root/it.class
diff options
context:
space:
mode:
Diffstat (limited to 'it.class')
-rw-r--r--it.class41
1 files changed, 13 insertions, 28 deletions
diff --git a/it.class b/it.class
index 24653cd..bb61397 100644
--- a/it.class
+++ b/it.class
@@ -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>";
}