2009-12-18 Ramon Novoa <rnovoa@artica.es>
* include/functions_reporting.php: Fixed SLA calculation. Was not working. * include/functions_fsgraph.php: Fixed bug #2913813. * include/functions_config.php, include/config_process.php, include/fgraph.php, include/functions_db.php, operation/events/export_csv.php, operation/agentes/export_csv.php, operation/agentes/datos_agente.php, godmode/menu.ph: Added history database support. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2214 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
7d5d535db3
commit
16eb0d2b96
|
@ -1,3 +1,15 @@
|
|||
2009-12-18 Ramon Novoa <rnovoa@artica.es>
|
||||
|
||||
* include/functions_reporting.php: Fixed SLA calculation. Was not working.
|
||||
|
||||
* include/functions_fsgraph.php: Fixed bug #2913813.
|
||||
|
||||
* include/functions_config.php, include/config_process.php,
|
||||
include/fgraph.php, include/functions_db.php,
|
||||
operation/events/export_csv.php, operation/agentes/export_csv.php,
|
||||
operation/agentes/datos_agente.php, godmode/menu.ph: Added history
|
||||
database support.
|
||||
|
||||
2009-12-17 Miguel de Dios <miguel.dedios@artica.es>
|
||||
|
||||
* pandora_console/godmode/reporting/graph_builder.php: fix blank row when
|
||||
|
|
|
@ -165,6 +165,7 @@ if (give_acl ($config['id_user'], 0, "PM")) {
|
|||
$sub["godmode/setup/file_manager"]["text"] = __('File manager');
|
||||
$sub["godmode/setup/links"]["text"] = __('Links');
|
||||
$sub["godmode/setup/news"]["text"] = __('Site news');
|
||||
enterprise_hook ('historydb_submenu');
|
||||
$menu["gsetup"]["sub"] = $sub;
|
||||
}
|
||||
|
||||
|
|
|
@ -97,4 +97,13 @@ require_once ('functions_extensions.php');
|
|||
|
||||
$config['extensions'] = get_extensions ();
|
||||
|
||||
// Connect to the history DB
|
||||
if ($config['history_db_enabled']) {
|
||||
$config['history_db_connection'] = mysql_connect ($config['history_db_host'] . ':' . $config['history_db_port'], $config['history_db_user'], $config['history_db_pass']);
|
||||
mysql_select_db ($config['history_db_name'], $config['history_db_connection']);
|
||||
}
|
||||
|
||||
// Make dbconnection the default connection again (the link identifier of the already opened link will be returned)
|
||||
$config['dbconnection'] = mysql_connect ($config["dbhost"], $config["dbuser"], $config["dbpass"]);
|
||||
|
||||
?>
|
||||
|
|
|
@ -197,7 +197,7 @@ function graphic_combined_module ($module_list, $weight_list, $period, $width, $
|
|||
"utimestamp > $datelimit",
|
||||
"utimestamp < $date",
|
||||
'order' => 'utimestamp ASC'),
|
||||
array ('datos', 'utimestamp'));
|
||||
array ('datos', 'utimestamp'), 'AND', true);
|
||||
|
||||
if ($result === false) {
|
||||
if (! $graphic_type) {
|
||||
|
@ -341,7 +341,7 @@ function grafico_modulo_sparse ($id_agente_modulo, $period, $show_event,
|
|||
"utimestamp > $datelimit",
|
||||
"utimestamp < $date",
|
||||
'order' => 'utimestamp ASC'),
|
||||
array ('datos', 'utimestamp'));
|
||||
array ('datos', 'utimestamp'), 'AND', true);
|
||||
|
||||
if ($all_data === false) {
|
||||
if (! $graphic_type) {
|
||||
|
@ -1165,17 +1165,17 @@ function grafico_db_agentes_purge ($id_agent, $width, $height) {
|
|||
// Three months ago
|
||||
$time["3month"] = $time["all"] - 7776000;
|
||||
|
||||
$data[__("Today")] = get_db_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos WHERE utimestamp > %d %s", $time["1day"], $query));
|
||||
$data["1 ".__("Week")] = get_db_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos WHERE utimestamp > %d %s", $time["1week"], $query));
|
||||
$data["1 ".__("Month")] = get_db_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos WHERE utimestamp > %d %s", $time["1month"], $query));
|
||||
$data["3 ".__("Months")] = get_db_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos WHERE utimestamp > %d %s", $time["3month"], $query));
|
||||
$data[__("Today")] = get_db_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos WHERE utimestamp > %d %s", $time["1day"], $query), 0, true);
|
||||
$data["1 ".__("Week")] = get_db_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos WHERE utimestamp > %d %s", $time["1week"], $query), 0, true);
|
||||
$data["1 ".__("Month")] = get_db_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos WHERE utimestamp > %d %s", $time["1month"], $query), 0, true);
|
||||
$data["3 ".__("Months")] = get_db_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos WHERE utimestamp > %d %s", $time["3month"], $query), 0, true);
|
||||
$data[__("Older")] = get_db_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos WHERE 1=1 %s", $query));
|
||||
|
||||
$data[__("Today")] += get_db_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos_string WHERE utimestamp > %d %s", $time["1day"], $query));
|
||||
$data["1 ".__("Week")] += get_db_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos_string WHERE utimestamp > %d %s", $time["1week"], $query));
|
||||
$data["1 ".__("Month")] += get_db_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos_string WHERE utimestamp > %d %s", $time["1month"], $query));
|
||||
$data["3 ".__("Months")] += get_db_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos_string WHERE utimestamp > %d %s", $time["3month"], $query));
|
||||
$data[__("Older")] += get_db_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos_string WHERE 1=1 %s", $query));
|
||||
$data[__("Today")] += get_db_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos_string WHERE utimestamp > %d %s", $time["1day"], $query), 0, true);
|
||||
$data["1 ".__("Week")] += get_db_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos_string WHERE utimestamp > %d %s", $time["1week"], $query), 0, true);
|
||||
$data["1 ".__("Month")] += get_db_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos_string WHERE utimestamp > %d %s", $time["1month"], $query), 0, true);
|
||||
$data["3 ".__("Months")] += get_db_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos_string WHERE utimestamp > %d %s", $time["3month"], $query), 0, true);
|
||||
$data[__("Older")] += get_db_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos_string WHERE 1=1 %s", $query), 0, true);
|
||||
|
||||
$data[__("Older")] = $data[__("Older")] - $data["3 ".__("Months")];
|
||||
|
||||
|
@ -1267,8 +1267,8 @@ function grafico_modulo_boolean ($id_agente_modulo, $period, $show_event,
|
|||
$alert_low = false;
|
||||
// If we want to show alerts limits
|
||||
|
||||
$alert_high = get_db_value ('MAX(max_value)', 'talert_template_modules', 'id_agent_module', (int) $id_agente_modulo);
|
||||
$alert_low = get_db_value ('MIN(min_value)', 'talert_template_modules', 'id_agent_module', (int) $id_agente_modulo);
|
||||
$alert_high = get_db_value ('MAX(max_value)', 'talert_template_modules', 'id_agent_module', (int) $id_agente_modulo, true);
|
||||
$alert_low = get_db_value ('MIN(min_value)', 'talert_template_modules', 'id_agent_module', (int) $id_agente_modulo, true);
|
||||
|
||||
// if no valid alert defined to render limits, disable it
|
||||
if (($alert_low === false || $alert_low === NULL) &&
|
||||
|
@ -1313,7 +1313,7 @@ function grafico_modulo_boolean ($id_agente_modulo, $period, $show_event,
|
|||
"utimestamp > $datelimit",
|
||||
"utimestamp < $date",
|
||||
'order' => 'utimestamp ASC'),
|
||||
array ('datos', 'utimestamp'));
|
||||
array ('datos', 'utimestamp'), 'AND', true);
|
||||
|
||||
if ($all_data === false)
|
||||
$all_data = array ();
|
||||
|
@ -1447,11 +1447,13 @@ function grafico_modulo_string ($id_agente_modulo, $period, $show_event,
|
|||
|
||||
|
||||
$sql1="SELECT utimestamp FROM tagente_datos_string WHERE id_agente_modulo = ".$id_agente_modulo." and utimestamp > '".$fechatope."'";
|
||||
$result = get_db_all_rows_sql ($sql1, true);
|
||||
if ($result === false)
|
||||
$result = array ();
|
||||
|
||||
$result=mysql_query($sql1);
|
||||
while ($row=mysql_fetch_array($result)){
|
||||
foreach ($result as $row){
|
||||
for ($i = 0; $i < $resolution; $i++){
|
||||
if (($row[0] < $valores[$i][3]) and ($row[0] >= $valores[$i][2]) ){
|
||||
if (($row['utimestamp'] < $valores[$i][3]) and ($row['utimestamp'] >= $valores[$i][2]) ){
|
||||
// entra en esta fila
|
||||
$valores[$i][0]++;
|
||||
}
|
||||
|
|
|
@ -163,6 +163,16 @@ function update_config () {
|
|||
update_config_value ('list_ACL_IPs_for_API', (string) get_parameter('list_ACL_IPs_for_API', implode("\n", $config['list_ACL_IPs_for_API'])));
|
||||
|
||||
update_config_value ('custom_logo', (string) get_parameter ('custom_logo', $config["custom_logo"]));
|
||||
update_config_value ('history_db_enabled', (bool) get_parameter ('history_db_enabled', $config['history_db_enabled']));
|
||||
update_config_value ('history_db_host', (string) get_parameter ('history_db_host', $config['history_db_host']));
|
||||
update_config_value ('history_db_port', (int) get_parameter ('history_db_port', $config['history_db_port']));
|
||||
update_config_value ('history_db_name', (string) get_parameter ('history_db_name', $config['history_db_name']));
|
||||
update_config_value ('history_db_user', (string) get_parameter ('history_db_user', $config['history_db_user']));
|
||||
update_config_value ('history_db_pass', (string) get_parameter ('history_db_pass', $config['history_db_pass']));
|
||||
update_config_value ('history_db_days', (string) get_parameter ('history_db_days', $config['history_db_days']));
|
||||
update_config_value ('history_db_step', (string) get_parameter ('history_db_step', $config['history_db_step']));
|
||||
update_config_value ('history_db_delay', (string) get_parameter ('history_db_delay', $config['history_db_delay']));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -309,6 +319,42 @@ function process_config () {
|
|||
update_config_value ('custom_logo', 'none.png');
|
||||
}
|
||||
|
||||
if (!isset ($config['history_db_enabled'])) {
|
||||
update_config_value ( 'history_db_enabled', false);
|
||||
}
|
||||
|
||||
if (!isset ($config['history_db_host'])) {
|
||||
update_config_value ( 'history_db_host', '');
|
||||
}
|
||||
|
||||
if (!isset ($config['history_db_port'])) {
|
||||
update_config_value ( 'history_db_port', 3306);
|
||||
}
|
||||
|
||||
if (!isset ($config['history_db_name'])) {
|
||||
update_config_value ( 'history_db_name', 'pandora');
|
||||
}
|
||||
|
||||
if (!isset ($config['history_db_user'])) {
|
||||
update_config_value ( 'history_db_user', 'pandora');
|
||||
}
|
||||
|
||||
if (!isset ($config['history_db_pass'])) {
|
||||
update_config_value ( 'history_db_pass', '');
|
||||
}
|
||||
|
||||
if (!isset ($config['history_db_days'])) {
|
||||
update_config_value ( 'history_db_days', 0);
|
||||
}
|
||||
|
||||
if (!isset ($config['history_db_step'])) {
|
||||
update_config_value ( 'history_db_step', 0);
|
||||
}
|
||||
|
||||
if (!isset ($config['history_db_delay'])) {
|
||||
update_config_value ( 'history_db_delay', 0);
|
||||
}
|
||||
|
||||
/* Finally, check if any value was overwritten in a form */
|
||||
update_config ();
|
||||
}
|
||||
|
|
|
@ -1127,7 +1127,7 @@ function get_agent_modules_data_count ($id_agent = 0) {
|
|||
$modules = array_keys (get_agent_modules ($agent_id));
|
||||
foreach ($query as $sql) {
|
||||
//Add up each table's data
|
||||
$count[$agent_id] += (int) get_db_sql ($sql." WHERE id_agente_modulo IN (".implode (",", $modules).")");
|
||||
$count[$agent_id] += (int) get_db_sql ($sql." WHERE id_agente_modulo IN (".implode (",", $modules).")", 0, true);
|
||||
}
|
||||
//Add total agent count to total count
|
||||
$count["total"] += $count[$agent_id];
|
||||
|
@ -1135,7 +1135,7 @@ function get_agent_modules_data_count ($id_agent = 0) {
|
|||
|
||||
if ($count["total"] == 0) {
|
||||
foreach ($query as $sql) {
|
||||
$count["total"] += (int) get_db_sql ($sql);
|
||||
$count["total"] += (int) get_db_sql ($sql, 0, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1602,7 +1602,7 @@ $sql_cache = array ('saved' => 0);
|
|||
*
|
||||
* @return mixed Value of first column of the first row. False if there were no row.
|
||||
*/
|
||||
function get_db_value ($field, $table, $field_search = 1, $condition = 1) {
|
||||
function get_db_value ($field, $table, $field_search = 1, $condition = 1, $search_history_db = false) {
|
||||
if (is_int ($condition)) {
|
||||
$sql = sprintf ("SELECT %s FROM %s WHERE %s = %d LIMIT 1",
|
||||
$field, $table, $field_search, $condition);
|
||||
|
@ -1613,7 +1613,7 @@ function get_db_value ($field, $table, $field_search = 1, $condition = 1) {
|
|||
$sql = sprintf ("SELECT %s FROM %s WHERE %s = '%s' LIMIT 1",
|
||||
$field, $table, $field_search, $condition);
|
||||
}
|
||||
$result = get_db_all_rows_sql ($sql);
|
||||
$result = get_db_all_rows_sql ($sql, $search_history_db);
|
||||
|
||||
if ($result === false)
|
||||
return false;
|
||||
|
@ -1691,9 +1691,9 @@ function get_db_value_sql ($sql) {
|
|||
*
|
||||
* @return mixed The first row of the result or false
|
||||
*/
|
||||
function get_db_row_sql ($sql) {
|
||||
function get_db_row_sql ($sql, $search_history_db = false) {
|
||||
$sql .= " LIMIT 1";
|
||||
$result = get_db_all_rows_sql ($sql);
|
||||
$result = get_db_all_rows_sql ($sql, $search_history_db);
|
||||
|
||||
if($result === false)
|
||||
return false;
|
||||
|
@ -1796,8 +1796,8 @@ function get_db_row_filter ($table, $filter, $fields = false, $where_join = 'AND
|
|||
*
|
||||
* @return mixed The selected field of the first row in a select statement.
|
||||
*/
|
||||
function get_db_sql ($sql, $field = 0) {
|
||||
$result = get_db_all_rows_sql ($sql);
|
||||
function get_db_sql ($sql, $field = 0, $search_history_db = false) {
|
||||
$result = get_db_all_rows_sql ($sql, $search_history_db);
|
||||
if($result === false)
|
||||
return false;
|
||||
|
||||
|
@ -1812,11 +1812,34 @@ function get_db_sql ($sql, $field = 0) {
|
|||
* @return mixed A matrix with all the values returned from the SQL statement or
|
||||
* false in case of empty result
|
||||
*/
|
||||
function get_db_all_rows_sql ($sql) {
|
||||
$return = process_sql ($sql);
|
||||
|
||||
if (! empty ($return))
|
||||
return $return;
|
||||
function get_db_all_rows_sql ($sql, $search_history_db = false) {
|
||||
global $config;
|
||||
$cache = true;
|
||||
$history = array ();
|
||||
|
||||
// Read from the history DB if necessary
|
||||
if ($search_history_db) {
|
||||
$cache = false;
|
||||
$history = process_sql ($sql, 'affected_rows', $config['history_db_connection'], false);
|
||||
if ($history === false) {
|
||||
$history = array ();
|
||||
}
|
||||
}
|
||||
|
||||
$return = process_sql ($sql, 'affected_rows', $config['dbconnection'], $cache);
|
||||
if ($return === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Append result to the history DB data
|
||||
if (! empty ($return)) {
|
||||
foreach ($return as $row) {
|
||||
array_push ($history, $row);
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty ($history))
|
||||
return $history;
|
||||
//Return false, check with === or !==
|
||||
return false;
|
||||
}
|
||||
|
@ -1845,7 +1868,7 @@ function get_db_all_rows_sql ($sql) {
|
|||
*
|
||||
* @return mixed Array of the row or false in case of error.
|
||||
*/
|
||||
function get_db_all_rows_filter ($table, $filter, $fields = false, $where_join = 'AND', $returnSQL = false) {
|
||||
function get_db_all_rows_filter ($table, $filter, $fields = false, $where_join = 'AND', $search_history_db = false, $returnSQL = false) {
|
||||
//TODO: Validate and clean fields
|
||||
if (empty ($fields)) {
|
||||
$fields = '*';
|
||||
|
@ -1868,7 +1891,7 @@ function get_db_all_rows_filter ($table, $filter, $fields = false, $where_join =
|
|||
if ($returnSQL)
|
||||
return $sql;
|
||||
else
|
||||
return get_db_all_rows_sql ($sql);
|
||||
return get_db_all_rows_sql ($sql, $search_history_db);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1971,7 +1994,7 @@ function add_database_debug_trace ($sql, $result = false, $affected = false, $ex
|
|||
*
|
||||
* @return mixed An array with the rows, columns and values in a multidimensional array or false in error
|
||||
*/
|
||||
function process_sql ($sql, $rettype = "affected_rows") {
|
||||
function process_sql ($sql, $rettype = "affected_rows", $dbconnection = '', $cache = true) {
|
||||
global $config;
|
||||
global $sql_cache;
|
||||
|
||||
|
@ -1980,14 +2003,19 @@ function process_sql ($sql, $rettype = "affected_rows") {
|
|||
if ($sql == '')
|
||||
return false;
|
||||
|
||||
if (! empty ($sql_cache[$sql])) {
|
||||
if ($cache && ! empty ($sql_cache[$sql])) {
|
||||
$retval = $sql_cache[$sql];
|
||||
$sql_cache['saved']++;
|
||||
add_database_debug_trace ($sql);
|
||||
}
|
||||
else {
|
||||
$start = microtime (true);
|
||||
$result = mysql_query ($sql);
|
||||
if ($dbconnection == '') {
|
||||
$result = mysql_query ($sql);
|
||||
}
|
||||
else {
|
||||
$result = mysql_query ($sql, $dbconnection);
|
||||
}
|
||||
$time = microtime (true) - $start;
|
||||
if ($result === false) {
|
||||
$backtrace = debug_backtrace ();
|
||||
|
@ -2395,7 +2423,7 @@ function get_previous_data ($id_agent_module, $utimestamp = 0) {
|
|||
ORDER BY utimestamp DESC',
|
||||
$id_agent_module, $utimestamp, $utimestamp - $interval);
|
||||
|
||||
return get_db_row_sql ($sql);
|
||||
return get_db_row_sql ($sql, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2418,7 +2446,7 @@ function get_agentmodule_data ($id_agent_module, $period, $date = 0) {
|
|||
AND utimestamp > %d AND utimestamp <= %d ORDER BY utimestamp ASC",
|
||||
$id_agent_module, $datelimit, $date);
|
||||
|
||||
$values = get_db_all_rows_sql ($sql);
|
||||
$values = get_db_all_rows_sql ($sql, true);
|
||||
|
||||
if ($values === false) {
|
||||
return array ();
|
||||
|
@ -2459,7 +2487,7 @@ function get_agentmodule_data_average ($id_agent_module, $period, $date = 0) {
|
|||
ORDER BY utimestamp ASC",
|
||||
$id_agent_module, $datelimit, $date);
|
||||
|
||||
$values = get_db_row_sql ($sql);
|
||||
$values = get_db_row_sql ($sql, true);
|
||||
|
||||
$sum = (float) $values[0];
|
||||
$total = (int) $values[1];
|
||||
|
@ -2494,7 +2522,7 @@ function get_agentmodule_data_max ($id_agent_module, $period, $date = 0) {
|
|||
WHERE id_agente_modulo = %d
|
||||
AND utimestamp > %d AND utimestamp <= %d",
|
||||
$id_agent_module, $datelimit, $date);
|
||||
$max = (float) get_db_sql ($sql);
|
||||
$max = (float) get_db_sql ($sql, 0, true);
|
||||
|
||||
/* Get also the previous report before the selected interval. */
|
||||
$previous_data = get_previous_data ($id_agent_module, $datelimit);
|
||||
|
@ -2522,7 +2550,7 @@ function get_agentmodule_data_min ($id_agent_module, $period, $date = 0) {
|
|||
WHERE id_agente_modulo = %d
|
||||
AND utimestamp > %d AND utimestamp <= %d",
|
||||
$id_agent_module, $datelimit, $date);
|
||||
$min = (float) get_db_sql ($sql);
|
||||
$min = (float) get_db_sql ($sql, 0, true);
|
||||
|
||||
/* Get also the previous data before the selected interval. */
|
||||
$previous_data = get_previous_data ($id_agent_module, $datelimit);
|
||||
|
@ -2557,7 +2585,7 @@ function get_agentmodule_data_sum ($id_agent_module, $period, $date = 0) {
|
|||
AND utimestamp > %d AND utimestamp <= %d
|
||||
ORDER BY utimestamp ASC',
|
||||
$id_agent_module, $datelimit, $date);
|
||||
$datas = get_db_all_rows_sql ($sql);
|
||||
$datas = get_db_all_rows_sql ($sql, true);
|
||||
|
||||
/* Get also the previous data before the selected interval. */
|
||||
$previous_data = get_previous_data ($id_agent_module, $datelimit);
|
||||
|
|
|
@ -192,7 +192,7 @@ function fs_module_chart ($data, $width, $height, $avg_only = 1, $step = 10, $ti
|
|||
$output .= '<script type="text/javascript">
|
||||
<!--
|
||||
function pie_' . $chart_id . ' () {
|
||||
var myChart = new FusionCharts("' . $pre_url . '/include/FusionCharts/FCF_MSArea2D.swf", "' . $chart_id . '", "' . $width. '", "' . $height. '", "0", "1");
|
||||
var myChart = new FusionCharts("' . $config['homeurl'] . '/include/FusionCharts/FCF_MSArea2D.swf", "' . $chart_id . '", "' . $width. '", "' . $height. '", "0", "1");
|
||||
myChart.setDataXML("' . addslashes($chart->getXML ()) . '");
|
||||
myChart.addParam("WMode", "Transparent");
|
||||
myChart.render("' . $div_id . '");
|
||||
|
|
|
@ -40,49 +40,46 @@ require_once ($config["homedir"]."/include/functions_agents.php");
|
|||
* found
|
||||
*/
|
||||
function get_agentmodule_sla ($id_agentmodule, $period = 0, $min_value = 1, $max_value = false, $date = 0) {
|
||||
if (empty ($date)) {
|
||||
$date = get_system_time ();
|
||||
global $config;
|
||||
|
||||
// Initialize variables
|
||||
if (empty ($date)) $date = get_system_time ();
|
||||
if ((empty ($period)) OR ($period == 0)) $period = $config["sla_period"];
|
||||
|
||||
// Limit date to start searching data
|
||||
$datelimit = $date - $period;
|
||||
|
||||
// Get interval data
|
||||
$sql = sprintf ('SELECT * FROM tagente_datos
|
||||
WHERE id_agente_modulo = %d
|
||||
AND utimestamp > %d AND utimestamp <= %d',
|
||||
$id_agentmodule, $datelimit, $date);
|
||||
$interval_data = get_db_all_rows_sql ($sql, true);
|
||||
if ($interval_data === false) $interval_data = array ();
|
||||
|
||||
// Calculate for how long the module has not met the SLA
|
||||
$mark = 0;
|
||||
$bad_period = 0;
|
||||
foreach ($interval_data as $data) {
|
||||
// bad data
|
||||
if ((($max_value > $min_value AND ($data['datos'] > $max_value OR $data['datos'] < $min_value))) OR
|
||||
($max_value <= $min_value AND $data['datos'] < $min_value)) {
|
||||
// good data turns bad
|
||||
if ($mark == 0) {
|
||||
$mark = $data['utimestamp'];
|
||||
}
|
||||
// good data
|
||||
} else {
|
||||
// bad data turns good
|
||||
if ($mark != 0) {
|
||||
$bad_period += $data['utimestamp'] - $mark;
|
||||
$mark = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((empty ($period)) OR ($period == 0)) {
|
||||
global $config;
|
||||
$period = $config["sla_period"];
|
||||
}
|
||||
|
||||
$datelimit = $date - $period; // start date
|
||||
|
||||
/* Get the total data entries in the interval */
|
||||
$sql = sprintf ('SELECT COUNT(*)
|
||||
FROM tagente_datos
|
||||
WHERE id_agente_modulo = %d
|
||||
AND utimestamp > %d
|
||||
AND utimestamp <= %d', $id_agentmodule, $datelimit, $date);
|
||||
$total = get_db_sql ($sql);
|
||||
|
||||
if (empty ($total)) {
|
||||
//No data to calculate on so we return 100 (fail to good)
|
||||
return false;
|
||||
}
|
||||
|
||||
$sql = sprintf ('SELECT COUNT(*)
|
||||
FROM tagente_datos
|
||||
WHERE id_agente_modulo = %d
|
||||
AND utimestamp > %d
|
||||
AND utimestamp <= %d
|
||||
AND ', $id_agentmodule, $datelimit, $date);
|
||||
if ($max_value > $min_value)
|
||||
$sql .= sprintf ('( datos < %s OR datos > %d )', $min_value, $max_value);
|
||||
else
|
||||
$sql .= sprintf ('datos < %d', $mins_value);
|
||||
$bad = get_db_sql ($sql);
|
||||
if (empty ($bad)) {
|
||||
$bad = 0;
|
||||
}
|
||||
|
||||
//Calculate percentage
|
||||
$result = 100 - ($bad / $total) * 100;
|
||||
|
||||
return (float) $result;
|
||||
// Return the percentage of SLA compliance
|
||||
return (float) (100 - ($bad_period / $period) * 100);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -61,7 +61,7 @@ if (preg_match ("/string/", get_moduletype_name (get_agentmodule_type ($module_i
|
|||
}
|
||||
|
||||
$countData = get_db_value_sql($sqlCount);
|
||||
$result = get_db_all_rows_sql ($sql);
|
||||
$result = get_db_all_rows_sql ($sql, true);
|
||||
if ($result === false) {
|
||||
$result = array ();
|
||||
}
|
||||
|
|
|
@ -65,10 +65,13 @@ if (isset ($_GET["agentmodule"]) && isset ($_GET["agent"]) ){
|
|||
$sql1 = "SELECT * FROM tagente_datos_string WHERE utimestamp > $from_date AND utimestamp < $to_date AND id_agente_modulo = $id_agentmodule ORDER BY utimestamp DESC";
|
||||
else
|
||||
$sql1 = "SELECT * FROM tagente_datos WHERE utimestamp > $from_date AND utimestamp < $to_date AND id_agente_modulo = $id_agentmodule ORDER BY utimestamp DESC";
|
||||
$result1=mysql_query($sql1);
|
||||
|
||||
$result1 = get_db_all_rows_sql ($sql1, true);
|
||||
if ($result1 === false) {
|
||||
$result1 = array ();
|
||||
}
|
||||
|
||||
// Render data
|
||||
while ($row=mysql_fetch_array($result1)){
|
||||
foreach ($result1 as $row){
|
||||
echo $agentmodule_name;
|
||||
echo ",";
|
||||
echo $row["datos"];
|
||||
|
|
|
@ -72,7 +72,7 @@ echo chr (13);
|
|||
$fields = array ('id_grupo', 'id_agente', 'evento', 'estado', 'id_usuario',
|
||||
'event_type', 'criticity', 'timestamp');
|
||||
|
||||
$sql = get_db_all_rows_filter ('tevento', $filter, $fields, 'AND', true);
|
||||
$sql = get_db_all_rows_filter ('tevento', $filter, $fields, 'AND', true, true);
|
||||
|
||||
$new = true;
|
||||
while ($event = get_db_all_row_by_steps_sql($new, $result, $sql)) {
|
||||
|
|
Loading…
Reference in New Issue