added a daily report feature

This commit is contained in:
SJ 2012-05-08 14:25:53 +02:00
parent d36fb202fc
commit 9212dff26b
6 changed files with 204 additions and 0 deletions

103
util/daily-report.php Normal file
View File

@ -0,0 +1,103 @@
<?php
$webuidir = "";
$verbose = 0;
if(isset($_SERVER['argv'][1])) { $webuidir = $_SERVER['argv'][1]; }
for($i=2; $i<$_SERVER['argc']; $i++){
if($_SERVER['argv'][$i] == "verbose") { $verbose = 1; }
}
require_once($webuidir . "/config.php");
require(DIR_SYSTEM . "/startup.php");
$loader = new Loader();
Registry::set('load', $loader);
$loader->load->model('user/user');
$loader->load->model('health/health');
$loader->load->model('stat/counter');
$loader->load->model('mail/mail');
$language = new Language();
Registry::set('language', $language);
extract($language->data);
Registry::set('admin_user', 1);
Registry::set('health_smtp_servers', $health_smtp_servers);
Registry::set('partitions_to_monitor', $partitions_to_monitor);
$db = new DB(DB_DRIVER, DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE, DB_PREFIX);
Registry::set('DB_DATABASE', DB_DATABASE);
Registry::set('db', $db);
Registry::set('DB_DRIVER', DB_DRIVER);
$date = date(AUDIT_DATE_FORMAT, NOW);
$fp = fopen(LOCK_FILE, "r");
if(!$fp) { die("cannot open: " . LOCK_FILE . "\n"); }
if(!flock($fp, LOCK_EX | LOCK_NB)) { fclose($fp); die("cannot get a lock on " . LOCK_FILE . "\n"); }
$health = new ModelHealthHealth();
$counter = new ModelStatCounter();
$mail = new ModelMailMail();
foreach (Registry::get('health_smtp_servers') as $smtp) {
$_health[] = $health->checksmtp($smtp, $text_error);
}
$processed_emails = $health->count_processed_emails();
list ($uptime, $cpuload) = $health->uptime();
$cpuinfo = 100 - (int)file_get_contents(CPUSTAT);
list($totalmem, $meminfo, $totalswap, $swapinfo) = $health->meminfo();
$shortdiskinfo = $health->diskinfo();
list($archive_size, $counters) = $counter->getCounters();
$sysinfo = $health->sysinfo();
$options = $health->get_options();
$msg = "From: " . SMTP_FROMADDR . EOL;
$msg .= "To: " . ADMIN_EMAIL . EOL;
$msg .= "Subject: =?UTF-8?Q?" . preg_replace("/\n/", "", my_qp_encode($text_daily_piler_report)) . "?=" . EOL;
$msg .= "MIME-Version: 1.0" . EOL;
$msg .= "Content-Type: text/html; charset=\"utf-8\"" . EOL;
$msg .= EOL . EOL;
ob_start();
include($webuidir . "/view/theme/default/templates/health/daily-report.tpl");
$msg .= ob_get_contents();
ob_end_clean();
$rcpt = array(ADMIN_EMAIL);
$x = $mail->send_smtp_email(LOCALHOST, SMARTHOST_PORT, SMTP_DOMAIN, SMTP_FROMADDR, $rcpt, $msg);
if($fp) {
flock($fp, LOCK_UN);
fclose($fp);
}
?>

View File

@ -35,6 +35,7 @@ define('SMARTHOST', '127.0.0.1');
define('SMARTHOST_PORT', 10026);
define('SMTP_DOMAIN', 'mailpiler.org');
define('SMTP_FROMADDR', 'no-reply@mailpiler.org');
define('ADMIN_EMAIL', 'admin@mailpiler.org');
define('EOL', "\n");

View File

@ -44,6 +44,7 @@ $_['text_cpu_usage'] = "CPU usage";
$_['text_daily_quarantine_report'] = "Daily quarantine report";
$_['text_daily_quarantine_report_status'] = "Daily quarantine report status";
$_['text_daily_report'] = "Daily report";
$_['text_daily_piler_report'] = "Daily piler report";
$_['text_database_emails'] = "email addresses in piler database";
$_['text_date'] = "Date";
$_['text_date_from'] = "Date from";

View File

@ -44,6 +44,7 @@ $_['text_cpu_usage'] = "CPU haszn
$_['text_daily_quarantine_report'] = "Napi karantén riport";
$_['text_daily_quarantine_report_status'] = "Napi karantén értesítés";
$_['text_daily_report'] = "Napi jelentés";
$_['text_daily_piler_report'] = "Napi piler jelentés";
$_['text_database_emails'] = "email cím a piler adatbázisban";
$_['text_date'] = "Dátum";
$_['text_date_from'] = "Dátumtól";

View File

@ -44,6 +44,7 @@ $_['text_cpu_usage'] = "CPU használat";
$_['text_daily_quarantine_report'] = "Napi karantén riport";
$_['text_daily_quarantine_report_status'] = "Napi karantén értesítés";
$_['text_daily_report'] = "Napi jelentés";
$_['text_daily_piler_report'] = "Napi piler jelentés";
$_['text_database_emails'] = "email cím a piler adatbázisban";
$_['text_date'] = "Dátum";
$_['text_date_from'] = "Dátumtól";

View File

@ -0,0 +1,97 @@
<html>
<head>
<title><?php print $text_daily_piler_report; ?>, <?php print $date; ?></title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="<?php print LANG; ?>" />
<style type="text/css">
.row { display: table-row; }
#health1 { display: table-cell; margin-top: 10px; margin-bottom: 0; }
#health2 { display: table-cell; text-align: right; }
.cellhealthleft { display: table-cell; height: 25px; text-align: left; padding: 3px; font: bold 12px Arial, sans-serif; }
.cellhealthright { display: table-cell; height: 25px; text-align: left; padding: 3px; font: normal 12px Arial, sans-serif; }
#health1 .ok { color: green; font-weight: bold; }
#health1 .error { color: red; font-weight: bold; }
</style>
</head>
<body>
<h1><?php print $text_daily_piler_report; ?>, <?php print $date; ?></h1>
<div id="search">
<div id="health1">
<div class="row">
<div class="cellhealthleft"><?php print $text_server_name; ?>:</div>
<div class="cellhealthright"><?php print $sysinfo[0]; ?></div>
</div>
<div class="row">
<div class="cellhealthleft"><?php print $text_server_operating_system; ?>:</div>
<div class="cellhealthright"><?php print $sysinfo[1]; ?></div>
</div>
<div class="row">
<div class="cellhealthleft"><?php print $text_uptime; ?>:</div>
<div class="cellhealthright"><?php print $uptime; ?></div>
</div>
<div class="row">
<div class="cellhealthleft"><?php print $text_archive_size; ?>:</div>
<div class="cellhealthright"><?php print $archive_size; ?>B</div>
</div>
<div class="row">
<div class="cellhealthleft"><?php print $text_smtp_status; ?>:</div>
<div class="cellhealthright">
<?php foreach($_health as $h) {
if(preg_match("/^220/", $h[1])) {
$status = 'OK'; $class = 'ok';
} else {
$status = 'ERROR'; $class = 'error';
}
?>
<div class="<?php print $class; ?>"><?php print $h[3]; ?>: <?php print $status; ?> (<?php print $h[1]; ?>, <?php print $h[2]; ?>)</div>
<?php } ?>
</div>
</div>
<div class="row">
<div class="cellhealthleft"><?php print $text_processed_emails; ?>:</div>
<div class="cellhealthright"><?php print $processed_emails[0]; ?> (<?php print $text_24_hours; ?>)<br /><?php print $processed_emails[1]; ?> (<?php print $text_1_week; ?>)<br /><?php print $processed_emails[2]; ?> (<?php print $text_30_days; ?>)</div>
</div>
<div class="row">
<div class="cellhealthleft"><?php print $text_cpu_usage; ?>:</div>
<div class="cellhealthright"><span class="<?php if($cpuinfo < HEALTH_RATIO) { ?>ok<?php } else { ?>error<?php } ?>"><?php print $cpuinfo; ?>% <?php print $cpuload; ?></span></div>
</div>
<div class="row">
<div class="cellhealthleft"><?php print $text_memory_usage; ?>:</div>
<div class="cellhealthright"><span class="<?php if($meminfo < HEALTH_RATIO) { ?>ok<?php } else { ?>error<?php } ?>"><?php print $meminfo; ?>% / <?php print $totalmem; ?> MB</span></div>
</div>
<div class="row">
<div class="cellhealthleft"><?php print $text_swap_usage; ?></div>
<div class="cellhealthright"><span class="<?php if($swapinfo < HEALTH_RATIO) { ?>ok<?php } else { ?>error<?php } ?>"><?php print $swapinfo; ?>% / <?php print $totalswap; ?> MB</span></div>
</div>
<div class="row">
<div class="cellhealthleft"><?php print $text_disk_usage; ?></div>
<div class="cellhealthright"><?php foreach($shortdiskinfo as $partition) { ?><span class="<?php if($partition['utilization'] < HEALTH_RATIO) { ?>ok<?php } else { ?>error<?php } ?>"><?php print $partition['partition']; ?> <?php print $partition['utilization']; ?>%</span> <?php } ?></div>
</div>
</div></div>
</body>
</html>