120 lines
4.5 KiB
PHP
120 lines
4.5 KiB
PHP
<?php
|
|
/** \file scripts/other/tasks/statistics.php
|
|
* \brief DI webinterface task manager script, Statistics
|
|
* \author Rob Schalken, Core|Vision
|
|
* \version $Revision: 1.6 $
|
|
* \date $Date: 2013/04/15 10:30:06 $
|
|
*
|
|
* Statistics
|
|
*/
|
|
|
|
/************************************/
|
|
/* Statistics */
|
|
/************************************/
|
|
|
|
// Acquire mutex
|
|
if (db_mutex_acquire(RemoveExtension(basename(__FILE__)) . "_" . $params['task_id'], 0)) {
|
|
// Default skin
|
|
$_PAGE_INFO['skin'] = "dualinventive";
|
|
global $_DATABASE;
|
|
|
|
// Get settings from ini file
|
|
$ini_file = get_all_files($_PAGE_INFO['base_path'] . SKIN_DIR . $_PAGE_INFO['skin'] . "/", array("ini"));
|
|
$_PAGE_INFO['ini'] = parse_ini_file($ini_file[0], true);
|
|
|
|
// Initial values
|
|
$sum['on'] = 0;
|
|
$sum['off'] = 0;
|
|
|
|
foreach( $_DATABASE as $db_name => $db_info ) {
|
|
if( db_connect($db_name, "log") !== FALSE ) {
|
|
// Get switching statistics of all SWITCH 3000 units
|
|
$stats = db_fetch_lance_switch3000_switch_stats();
|
|
|
|
// collect data
|
|
$switch_stats[$db_name] = array();
|
|
$t_set = FALSE;
|
|
if( $stats ) foreach( $stats as $stat ) {
|
|
// update time
|
|
if( !$t_set || $stat['t_min'] < $switch_stats[$db_name]['t_min'] ) $switch_stats[$db_name]['t_min'] = $stat['t_min'];
|
|
if( !$t_set || $stat['t_max'] > $switch_stats[$db_name]['t_max'] ) $switch_stats[$db_name]['t_max'] = $stat['t_max'];
|
|
$t_set = TRUE;
|
|
|
|
if( $stat['minor'] == MIN_SWITCH3000_ON ) {
|
|
$sum['on'] += ($switch_stats[$db_name]['on'] = $stat['actions']);
|
|
}
|
|
else if( $stat['minor'] == MIN_SWITCH3000_OFF ) {
|
|
$sum['off'] += ($switch_stats[$db_name]['off'] = $stat['actions']);
|
|
}
|
|
}
|
|
|
|
// Debugging via syslog
|
|
DBG(sprintf("Statistics SWITCH 3000: db %-10s: %s--%s, on: %7lu, off: %7lu",
|
|
$db_name,
|
|
iso8601($switch_stats[$db_name]['t_min']), iso8601($switch_stats[$db_name]['t_max']),
|
|
$switch_stats[$db_name]['on'],
|
|
$switch_stats[$db_name]['off']
|
|
));
|
|
}
|
|
}
|
|
|
|
// Restore default database connection
|
|
db_connect();
|
|
|
|
// Send email with specific content
|
|
$subject = _("MTinfo") . " " . _("statistics");
|
|
|
|
// Define content
|
|
$content = "<style type=\"text/css\">";
|
|
$content .= "body { font-family: verdana; font-size: 10pt; }\n";
|
|
$content .= "table { border-style: inset; border-width: 1px; }\n";
|
|
$content .= "th { background: rgb(192,192,192); }\n";
|
|
$content .= "</style>";
|
|
$content .= "<p>";
|
|
$content .= _("Dear MTinfo user") . ",<br><br>";
|
|
$content .= _("Hereby the MTinfo statistics") . " " ._("SWITCH 3000") . ": " . "<br><br>";
|
|
$content .= "<table style=\"font-family:verdana;font-size:10pt\">";
|
|
$content .= "<tr><th>" . ucfirst(_("database")) . "<th colspan=\"3\" style=\"width: " . (20 + strlen(_("t/m"))) . "ex;\">" . ucfirst(_("period")) . "<th>" . ucfirst(_("switched on")) . "<th>" . ucfirst(_("switched off")) . "</tr>";
|
|
foreach( $_DATABASE as $db_name => $db_info ) {
|
|
$content .= "<tr>";
|
|
$content .= "<td>" . ucfirst(_($db_name));
|
|
if( $switch_stats[$db_name] ) {
|
|
$content .= "<td style=\"text-align: right\">" . date("Y-m-d H:i:s", $switch_stats[$db_name]['t_min']);
|
|
$content .= "<td>" . _("t/m");
|
|
$content .= "<td style=\"text-align: left\">" . date("Y-m-d H:i:s", $switch_stats[$db_name]['t_max']);
|
|
$content .= "<td style=\"text-align: right\">" . $switch_stats[$db_name]['on'];
|
|
$content .= "<td style=\"text-align: right\">" . $switch_stats[$db_name]['off'];
|
|
}
|
|
else {
|
|
$content .= "<td colspan=\"3\" style=\"text-align: left\">" . _("No data") . "</td>";
|
|
$content .= "<td></td>";
|
|
$content .= "<td></td>";
|
|
}
|
|
$content .= "</tr>";
|
|
}
|
|
$content .= "<tr>";
|
|
$content .= "<td colspan=\"4\">" . ucfirst(_("total number of switch actions"));
|
|
$content .= "<td style=\"text-align: right; border-top: 1px solid black;\">" . $sum['on'];
|
|
$content .= "<td style=\"text-align: right; border-top: 1px solid black;\">" . $sum['off'];
|
|
$content .= "</tr>";
|
|
$content .= "</table>";
|
|
$content .= "<br><br";
|
|
$content .= _("Best regards") . ",<br><br>";
|
|
$content .= "MTinfo";
|
|
$content .= "</p>";
|
|
|
|
// Send mail
|
|
send_mail($_PAGE_INFO['ini']['comm']['statistics'], "", "", $_PAGE_INFO['ini']['report']['no-reply'], $subject, $content, $report, $_PAGE_INFO['file']);
|
|
|
|
// Release mutex
|
|
db_mutex_release(RemoveExtension(basename(__FILE__)) . "_" . $params['task_id']);
|
|
|
|
// Set handled flag
|
|
$handled = 1;
|
|
}
|
|
else {
|
|
// Debug info
|
|
DBG("Mutex not released: " . $params['task_id']);
|
|
}
|
|
|
|
?>
|