summaryrefslogtreecommitdiff
path: root/it.class
diff options
context:
space:
mode:
authorChristian Schneider2007-01-17 21:27:14 +0000
committerChristian Schneider2007-01-17 21:27:14 +0000
commitd0ef2fa264f522e067dd4e0a1b51dcf47086e90e (patch)
tree9bddb3d5fe54d41526dc88ed1c127567e49b3172 /it.class
parent25778ef80fedaefaf16cea3a75dc554cfe7e2376 (diff)
downloaditools-d0ef2fa264f522e067dd4e0a1b51dcf47086e90e.tar.gz
itools-d0ef2fa264f522e067dd4e0a1b51dcf47086e90e.tar.bz2
itools-d0ef2fa264f522e067dd4e0a1b51dcf47086e90e.zip
Use itools style
Diffstat (limited to 'it.class')
-rw-r--r--it.class44
1 files changed, 30 insertions, 14 deletions
diff --git a/it.class b/it.class
index 588d279..24653cd 100644
--- a/it.class
+++ b/it.class
@@ -37,7 +37,8 @@ function log($name /* ... */)
$args = func_get_args();
$line = date("Y-m-d H:i:s") . "\t" . implode("\t", array_slice($args, 1)) . "\n";
- if ($fh = fopen($GLOBALS['ULTRAHOME'] . "/log/$name-" . date('Ymd'), "a")) {
+ if ($fh = fopen($GLOBALS['ULTRAHOME'] . "/log/$name-" . date('Ymd'), "a"))
+ {
fputs($fh, $line);
fclose($fh);
}
@@ -68,15 +69,18 @@ function timerlog($label = '')
* @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
*/
-function error($p=array(), $body='', $to='')
+function error($p = array(), $body = "", $to = "")
{
$p += array('ok_key' => "it_error", 'ok_maxfail' => 2);
- if (is_array($p)) {
+ if (is_array($p))
+ {
$title = $p['title'];
$body = $p['body'];
$to = $p['to'];
- } else {
+ }
+ else
+ {
$title = $p;
unset($p);
}
@@ -84,41 +88,53 @@ function error($p=array(), $body='', $to='')
if (!$to)
$to = strtr(trim(@file_get_contents($GLOBALS['ULTRAHOME'] . "/.diffnotice")), array("\n"=>',', ' '=>''));
- if (!isset($p['ok']))
- $sendalert = true;
- else {
+ if (isset($p['ok']))
+ {
$counterfn = $GLOBALS['ULTRAHOME'] . "/tmp/" . urlencode($p['ok_key']);
- if (time() - @filemtime($counterfn) >= 60) { # only modify counter if unmodified for 60 secs
+
+ 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;
- if ($newcounter != $oldcounter) {
+
+ 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
+ if ($newcounter >= $p['ok_maxfail'] && (time() - @filemtime("$counterfn.mailsent")) >= 86400) # 1 mail per day
+ {
$sendalert = true;
+
if (!ereg('twin|devel', $GLOBALS['ULTRASERVERTYPE']))
touch("$counterfn.mailsent");
}
}
}
}
+ else
+ $sendalert = true;
- if ($sendalert) {
+ if ($sendalert)
+ {
$url = ($_SERVER['HTTPS'] ? "https://" : "http://") . $_SERVER['HTTP_HOST'] .$_SERVER['REQUEST_URI'];
if (!$title)
$title="Error in $url";
$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('twin|devel', $GLOBALS['ULTRASERVERTYPE']))
+ {
echo "<pre>$title\n$body\n</pre>";
- } else {
+ }
+ else
+ {
$cmd = "alert -l " . escapeshellarg($to) . " 4 " . escapeshellarg($title);
EDC('exec', $cmd);
- if (($pipe = popen($cmd, "w"))) {
+ if (($pipe = popen($cmd, "w")))
+ {
fputs($pipe, $body);
pclose($pipe);
}