2008-12-24 Evi Vanoost <vanooste@rcbi.rochester.edu>

* include/functions_reporting.php, include/functions_db.php, 
	include/functions_html.php, operation/agentes/datos_agente.php, 
	operation/agentes/estado_agente.php, 
	operation/agentes/estado_generalagente.php, 
	operation/agentes/estado_grupo.php, operation/agentes/estado_monitores.php,
	operation/agentes/networkmap.php, operation/agentes/status_monitor.php,
	operation/incidents/incident_detail.php, 
	operation/reporting/reporting_viewer.php, 
	operation/reporting/reporting_xml.php, reporting/fgraph.php, 
	godmode/db/db_audit.php, godmode/db/db_event.php, godmode/db/db_purge.php:
	Added get_system_time in favor of time ();

	* include/functions.php: Added get_system_time which gets the time from 
	a source based on user preference

	* include/help/en/help_timesource.php: Explanation of timesource.
	
	* godmode/setup/setup.php, include/config_process.php: Added timesource
	selection and preference

git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1310 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
guruevi 2008-12-24 16:53:00 +00:00
parent 555246536d
commit bc221d3211
22 changed files with 130 additions and 49 deletions

View File

@ -1,3 +1,25 @@
2008-12-24 Evi Vanoost <vanooste@rcbi.rochester.edu>
* include/functions_reporting.php, include/functions_db.php,
include/functions_html.php, operation/agentes/datos_agente.php,
operation/agentes/estado_agente.php,
operation/agentes/estado_generalagente.php,
operation/agentes/estado_grupo.php, operation/agentes/estado_monitores.php,
operation/agentes/networkmap.php, operation/agentes/status_monitor.php,
operation/incidents/incident_detail.php,
operation/reporting/reporting_viewer.php,
operation/reporting/reporting_xml.php, reporting/fgraph.php,
godmode/db/db_audit.php, godmode/db/db_event.php, godmode/db/db_purge.php:
Added get_system_time in favor of time ();
* include/functions.php: Added get_system_time which gets the time from
a source based on user preference
* include/help/en/help_timesource.php: Explanation of timesource.
* godmode/setup/setup.php, include/config_process.php: Added timesource
selection and preference
2008-12-24 Raul Mateos <raulofpandora@gmail.com>
* index.php: Updated build, again due to the use of the new custom ID.

View File

@ -29,7 +29,7 @@ if (! give_acl ($config['id_user'], 0, "DM")) {
}
// All data (now)
$time["all"] = time ();
$time["all"] = get_system_time ();
// 1 day ago
$time["1day"] = $time["all"]-86400;

View File

@ -70,7 +70,7 @@ echo '<form name="db_audit" method="post" action="index.php?sec=gdbman&sec2=godm
echo '<table width="300" cellpadding="4" cellspacing="4" class="databox">
<tr><td class="datos">';
$time = time ();
$time = get_system_time ();
$fields = array ();
$fields[$time - 7776000] = __('Purge event data over 90 days');
$fields[$time - 2592000] = __('Purge event data over 30 days');

View File

@ -44,7 +44,7 @@ echo '<h2>'.__('Database Maintenance').' &gt; '.__('Database purge').'</h2>
<h3>'.__('Get data from agent').'</h3>';
// All data (now)
$time["all"] = time ();
$time["all"] = get_system_time ();
// 1 day ago
$time["1day"] = $time["all"]-86400;

View File

@ -53,6 +53,7 @@ if ($update_settings) {
$config["trap2agent"] = (string) get_parameter ('trap2agent', $config["trap2agent"]);
$config["autoupdate"] = (string) get_parameter ('autoupdate', $config["autoupdate"]);
$config["prominent_time"] = (string) get_parameter ('prominent_time', $config["prominent_time"]);
$config["timesource"] = (string) get_parameter ('timesource', $config["timesource"]);
$config["style"] = substr ($config["style"], 0, strlen ($config["style"]) - 4);
@ -74,6 +75,7 @@ if ($update_settings) {
process_sql ("UPDATE tconfig SET VALUE='".$config["trap2agent"]."' WHERE token = 'trap2agent'");
process_sql ("UPDATE tconfig SET VALUE='".$config["autoupdate"]."' WHERE token = 'autoupdate'");
process_sql ("UPDATE tconfig SET VALUE='".$config["prominent_time"]."' WHERE token = 'prominent_time'");
process_sql ("UPDATE tconfig SET VALUE='".$config["timesource"]."' WHERE token = 'timesource'");
}
echo "<h2>".__('Pandora Setup')." &gt; ";
@ -134,8 +136,13 @@ $table->data[15][1] .= print_radio_button ('prominent_time', "timestamp", '', $
$table->data[15][1] .= '<br />'.__('Timestamp in rollover').' ';
$table->data[15][1] .= print_radio_button ('prominent_time', "comparation", '', $config["prominent_time"], true);
$table->data[16][0] = __('Automatic update check');
$table->data[16][1] = print_checkbox ('autoupdate', 1, $config["autoupdate"], true);
$table->data[16][0] = __('Time source') . pandora_help("timesource", true);
$sources["system"] = __('System');
$sources["sql"] = __('Database');
$table->data[16][1] = print_select ($sources, 'timesource', $config["timesource"], '', '', '', true);
$table->data[17][0] = __('Automatic update check');
$table->data[17][1] = print_checkbox ('autoupdate', 1, $config["autoupdate"], true);
enterprise_hook ('load_snmpforward_enterprise');

View File

@ -142,4 +142,9 @@ if (!isset ($config["prominent_time"])) {
process_sql ("INSERT INTO tconfig (token,value) VALUES ('prominent_time','comparation')");
}
if (!isset ($config["timesource"])) {
// Prominent time tells us what to show prominently when a timestamp is displayed. The comparation (... days ago) or the timestamp (full date)
$config["timesource"] = "system";
process_sql ("INSERT INTO tconfig (token,value) VALUES ('timesource','system')");
}
?>

View File

@ -426,15 +426,36 @@ function format_for_graph ($number , $decimals = 1, $dec_point = ".", $thousands
* time and given timestamp.
*/
function human_time_comparation ($timestamp) {
global $config;
if (!is_numeric ($timestamp)) {
$timestamp = strtotime ($timestamp);
}
$seconds = time () - $timestamp;
$seconds = get_system_time () - $timestamp;
return human_time_description_raw ($seconds);
}
/**
* @function get_system_time
* @abstract This function gets the time from either system or sql based on preference and returns it
* @result Unix timestamp
**/
function get_system_time () {
global $config;
if ($config["timesource"] = "sql") {
$time = get_db_sql ("SELECT UNIX_TIMESTAMP()");
if (empty ($time)) {
return time ();
}
return $time;
} else {
return time ();
}
}
/**
* Transform an amount of time in seconds into a human readable
* strings of minutes, hours or days.

View File

@ -540,7 +540,7 @@ function dame_nombre_real ($id_user) {
*/
function get_monitor_downs_in_period ($id_agent_module, $period, $date = 0) {
if ($date == 0) {
$date = time ();
$date = get_system_time ();
}
$datelimit = $date - $period;
$sql = sprintf ("SELECT COUNT(`id_agentmodule`) FROM `tevento` WHERE
@ -564,7 +564,7 @@ function get_monitor_downs_in_period ($id_agent_module, $period, $date = 0) {
*/
function get_monitor_last_down_timestamp_in_period ($id_agent_module, $period, $date = 0) {
if ($date == 0) {
$date = time ();
$date = get_system_time ();
}
$datelimit = $date - $period;
$sql = sprintf ("SELECT MAX(`timestamp`) FROM `tevento` WHERE
@ -685,7 +685,7 @@ function get_monitors_down ($monitors, $period = 0, $date = 0) {
*/
function get_alert_fires_in_period ($id_agent_module, $period, $date = 0) {
if (!$date)
$date = time ();
$date = get_system_time ();
$datelimit = $date - $period;
$sql = sprintf ("SELECT COUNT(`id_agentmodule`) FROM `tevento` WHERE
`event_type` = 'alert_fired'
@ -729,7 +729,7 @@ function get_alerts_in_group ($id_group) {
*/
function get_alerts_fired ($alerts, $period = 0, $date = 0) {
if (! $date)
$date = time ();
$date = get_system_time ();
$datelimit = $date - $period;
$alerts_fired = array ();
@ -755,7 +755,7 @@ function get_alerts_fired ($alerts, $period = 0, $date = 0) {
*/
function get_alert_last_fire_timestamp_in_period ($id_agent_module, $period, $date = 0) {
if ($date == 0) {
$date = time ();
$date = get_system_time ();
}
$datelimit = $date - $period;
$sql = sprintf ("SELECT MAX(`timestamp`) FROM `tevento` WHERE
@ -1648,7 +1648,7 @@ function get_previous_data ($id_agent_module, $utimestamp) {
*/
function get_agent_module_value_average ($id_agent_module, $period, $date = 0) {
if (! $date)
$date = time ();
$date = get_system_time ();
$datelimit = $date - $period;
$sql = sprintf ("SELECT SUM(datos), COUNT(*) FROM tagente_datos
@ -1680,7 +1680,7 @@ function get_agent_module_value_average ($id_agent_module, $period, $date = 0) {
*/
function get_agent_module_value_max ($id_agent_module, $period, $date = 0) {
if (! $date)
$date = time ();
$date = get_system_time ();
$datelimit = $date - $period;
$sql = sprintf ("SELECT MAX(datos) FROM tagente_datos
@ -1708,7 +1708,7 @@ function get_agent_module_value_max ($id_agent_module, $period, $date = 0) {
*/
function get_agent_module_value_min ($id_agent_module, $period, $date = 0) {
if (! $date)
$date = time ();
$date = get_system_time ();
$datelimit = $date - $period;
$sql = sprintf ("SELECT MIN(datos) FROM tagente_datos
@ -1735,7 +1735,7 @@ function get_agent_module_value_min ($id_agent_module, $period, $date = 0) {
*/
function get_agent_module_value_sumatory ($id_agent_module, $period, $date = 0) {
if (! $date)
$date = time ();
$date = get_system_time ();
$datelimit = $date - $period; // limit date
$id_module_type = get_db_value ('id_tipo_modulo', 'tagente_modulo','id_agente_modulo', $id_agent_module);
$module_name = get_db_value ('nombre', 'ttipo_modulo', 'id_tipo', $id_module_type);
@ -2146,7 +2146,7 @@ function get_server_info ($id_server = -1) {
if (empty ($server["lag"])) {
$server["lag"] = 0;
} else {
$server["lag"] = time () - $server["lag"];
$server["lag"] = get_system_time () - $server["lag"];
}
//Push the raw data on the return stack

View File

@ -777,10 +777,8 @@ function print_timestamp ($unixtime, $return = false, $option = array ()) {
$tag = "span";
}
if (isset ($option["prominent"]) && $option["prominent"] == "timestamp") {
$prominent = "timestamp";
} elseif (isset ($option["prominent"]) && $option["prominent"] == "comparation") {
$prominent = "comparation";
if (!empty ($option["prominent"])) {
$prominent = $option["prominent"];
} else {
$prominent = $config["prominent_time"];
}

View File

@ -30,7 +30,7 @@
*/
function get_agent_module_sla ($id_agent_module, $period, $min_value, $max_value, $date = 0) {
if (empty ($date))
$date = time ();
$date = get_system_time ();
if (empty ($period))
return false; //We can't calculate a 0 period (division by zero)
@ -158,7 +158,7 @@ function get_group_stats ($id_group) {
$data["data_alerts_fire_count"] = 0;
$cur_time = time ();
$cur_time = get_system_time ();
foreach ($result as $row) {
$last_update = $cur_time - $row["utimestamp"];
@ -293,8 +293,8 @@ function get_group_stats ($id_group) {
*/
function event_reporting ($id_group, $period, $date = 0, $return = false) {
if (empty ($date)) {
$date = time ();
} elseif (!is_int ($date)) {
$date = get_system_time ();
} elseif (!is_numeric ($date)) {
$date = strtotime ($date);
}
@ -430,7 +430,7 @@ function alert_reporting ($id_group, $period = 0, $date = 0, $return = false) {
*/
function monitor_health_reporting ($id_group, $period = 0, $date = 0, $return = false) {
if (empty ($date)) //If date is 0, false or empty
$date = time ();
$date = get_system_time ();
$datelimit = $date - $period;
$output = '';

View File

@ -0,0 +1,28 @@
<p class="para">
What source to use for the time. This can be (for now) either the local system (System) or database (Database).<br /><br />
This is useful when your database is not on the same system as your webserver or your Pandora FMS servers.
In that case any time difference will miscalculate the time differences and timestamps.
You should use NTP to sync all your pandora servers and your MySQL server.
By using these preferences you don't have to sync your webserver but it's still recommended.
<br /><br />
Feel free to implement more sources (eg: ntp, ldap, $_SERVER...)
<br /><br />
Note: The database query will be cached the first time it's called so the time will always be the same on a page load throughout while System time is returned whenever the function is called which might differ slightly (especially near the ending of a second).
</p>
<p class="para">
These examples are all returning Unixtime
<script type="text/javascript">
var date = new Date; // Generic JS date object
var unixtime_ms = date.getTime(); // Returns milliseconds since the epoch
var unixtime = parseInt(unixtime_ms / 1000);
</script><br />
<br />
<?php
$option = array ("prominent" => "timestamp");
?>
<b>Current System time:</b> <?php print_timestamp (time (), false, $option); ?>
<br />
<b>Current Database time:</b> <?php print_timestamp (get_db_sql ("SELECT UNIX_TIMESTAMP()"), false, $option); ?>
<br />
<b>Your browser time:</b> <script type="text/javascript">document.write (date);</script>
</p>

View File

@ -44,10 +44,10 @@ if (isset ($_GET["delete"])) {
// Different query for string data type
if (preg_match ("/string/", get_moduletype_name (get_agentmodule_type ($module_id)))) {
$sql = sprintf ("SELECT * FROM tagente_datos_string WHERE id_agente_modulo = %d AND utimestamp > %d ORDER BY timestamp DESC", $module_id, time () - $period);
$sql = sprintf ("SELECT * FROM tagente_datos_string WHERE id_agente_modulo = %d AND utimestamp > %d ORDER BY timestamp DESC", $module_id, get_system_time () - $period);
$string_type = 1;
} else {
$sql = sprintf ("SELECT * FROM tagente_datos WHERE id_agente_modulo = %d AND utimestamp > %d ORDER BY timestamp DESC", $module_id, time () - $period);
$sql = sprintf ("SELECT * FROM tagente_datos WHERE id_agente_modulo = %d AND utimestamp > %d ORDER BY timestamp DESC", $module_id, get_system_time () - $period);
$string_type = 0;
}

View File

@ -192,7 +192,7 @@ if ($agents !== false) {
$numero_datamodules = 0;
$estado_cambio = 0;
$agent_down = 0;
$now = time ();
$now = get_system_time ();
// Calculate module/monitor totals for this agent
foreach ($modules as $module) {

View File

@ -110,7 +110,7 @@ if ($agent["ultimo_contacto_remoto"] == "0000-00-00 00:00:00") {
echo '</td></tr>';
// Next contact (agent)
$difference = time () - strtotime ($agent["ultimo_contacto"]);
$difference = get_system_time () - strtotime ($agent["ultimo_contacto"]);
$sql = sprintf ("SELECT MAX(module_interval) FROM tagente_modulo WHERE id_agente = %d", $id_agente);
$max = (int) get_db_sql ($sql);
if ($max > 0) {

View File

@ -50,7 +50,7 @@ if (isset ($_GET["update_netgroup"])) {
$groups = get_user_groups ($config['id_user']);
$groups_info = array ();
$total_agents = 0;
$now = time ();
$now = get_system_time ();
// Prepare data to show
// For each valid group for this user, take data from agent and modules
foreach ($groups as $id_group => $group_name) {

View File

@ -91,7 +91,7 @@ foreach ($modules as $module) {
$data[5] = "--";
}
$seconds = time () - $module["utimestamp"];
$seconds = get_system_time () - $module["utimestamp"];
if ($module["current_interval"] > 0 && $module["utimestamp"] > 0 && $seconds >= ($module["current_interval"] * 2)) {
$data[6] = '<span class="redb">';
} else {

View File

@ -340,7 +340,7 @@ if($nooverlap) {
$filename_map .= ".map";
$filename_img .= ".png";
if ($regen != 1 && file_exists ($filename_img) && filemtime ($filename_img) > time () - 300) {
if ($regen != 1 && file_exists ($filename_img) && filemtime ($filename_img) > get_system_time () - 300) {
$result = true;
} else {
$cmd = "echo " . escapeshellarg($graph) . " | $filter -Tcmapx -o".$filename_map." -Tpng -o".$filename_img;

View File

@ -182,7 +182,7 @@ $table->head[5] = __('Status');
$table->align[5] = "center";
$table->head[6] = __('Timestamp');
$table->algin[6] = "center";
$table->align[6] = "right";
foreach ($result as $row) {
$data = array ();
@ -211,16 +211,16 @@ foreach ($result as $row) {
$data[5] = '<img src="images/pixel_red.png" width="40" height="18" title="'.__('Monitor down').'">';
}
$seconds = time () - $row["utimestamp"];
$seconds = get_system_time () - $row["utimestamp"];
if ($seconds >= ($row["agent_interval"] * 2)) {
$data[6] = '<span class="redb">';
$option = array ("html_attr" => 'class="redb"');
} else {
$data[6] = '<span>';
$option = array ();
}
$data[6] .= human_time_comparation ($row["utimestamp"]);
$data[6] .= "</span>";
$data[6] = print_timestamp ($row["utimestamp"], true, $option);
array_push ($table->data, $data);
}

View File

@ -32,8 +32,8 @@ if (! give_acl ($config["id_user"], 0, "IR")) {
exit;
}
$inicio = time (); //Just inits the variable
$actualizacion = time ();
$inicio = get_system_time (); //Just inits the variable
$actualizacion = get_system_time ();
// EDITION MODE
if (isset ($_GET["id"])) {

View File

@ -113,7 +113,7 @@ if ($datetime === false || $datetime == -1) {
return;
}
/* Date must not be older than now */
if ($datetime > time ()) {
if ($datetime > get_system_time ()) {
echo '<h3 class="error">'.__('Selected date is older than current date').'</h3>';
return;
}

View File

@ -134,7 +134,7 @@ if ($datetime === false || $datetime == -1) {
exit;
}
/* Date must not be older than now */
if ($datetime > time ()) {
if ($datetime > get_system_time ()) {
echo "<error>Date is larger than current time</error>"; //Not translatable because this is an error message
exit;
}
@ -307,7 +307,7 @@ function xml_array ($array) {
}
}
$time = time ();
$time = get_system_time ();
echo '<report>';
echo '<generated><unix>'.$time.'</unix>';
echo '<rfc2822>'.date ("r",$time).'</rfc2822></generated>';

View File

@ -95,7 +95,7 @@ function graphic_combined_module ($module_list, $weight_list, $periodo, $width,
$resolution = $config['graph_res'] * 50; // Number of "slices" we want in graph
if (! $date)
$date = time ();
$date = get_system_time ();
//$unix_timestamp = strtotime($mysql_timestamp) // Convert MYSQL format tio utime
$fechatope = $date - $periodo; // limit date
$horasint = $periodo / $resolution; // Each intervalo is $horasint seconds length
@ -401,7 +401,7 @@ function grafico_modulo_sparse ($id_agente_modulo, $periodo, $show_event,
require_once 'Image/Graph.php';
if (empty ($date))
$date = time ();
$date = get_system_time ();
$resolution = $config["graph_res"] * 50; // Number of "slices" we want in graph
$fechatope = $date - $periodo;
@ -883,15 +883,15 @@ function graphic_agentaccess ($id_agent, $periodo, $width, $height) {
$Graph->done();
}
function graphic_string_data ($id_agent_module, $periodo, $width, $height, $pure = 0, $date = "") {
function graphic_string_data ($id_agent_module, $periodo, $width, $height, $pure = 0, $date = 0) {
global $config;
// $color = $config["color_graph1"]; //#437722"; // Green pandora 1.1 octopus color
$color = "#437722";
if ($date == "")
$date = time ();
if ($date == 0)
$date = get_system_time ();
$resolution = $config["graph_res"] * 5; // Number of "slices" we want in graph
$fechatope = $date - $periodo;
$horasint = $periodo / $resolution; // Each intervalo is $horasint seconds length
@ -1452,7 +1452,7 @@ function grafico_db_agentes_purge ($id_agent, $width, $height) {
}
// All data (now)
$time["all"] = time ();
$time["all"] = get_system_time ();
// 1 day ago
$time["1day"] = $time["all"]-86400;