diff --git a/pandora_console/godmode/admin_access_logs.php b/pandora_console/godmode/admin_access_logs.php index 82f0af0f7e..4af38ec669 100644 --- a/pandora_console/godmode/admin_access_logs.php +++ b/pandora_console/godmode/admin_access_logs.php @@ -106,8 +106,6 @@ $form .= html_print_table($table, true); $form .= '</form>'; ui_toggle($form, __("Filter"), "", false); -// ui_toggle(graphic_user_activity(400, 150), __("Chart")); - $filter = "1=1"; if (!empty($filter_type)) { diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index 4199f2c9a5..b9980bd972 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -1327,56 +1327,6 @@ function agents_get_alias_by_name ($name, $case = 'none') { } } -/** - * Get the number of pandora data packets in the database. - * - * In case an array is passed, it will have a value for every agent passed - * incl. a total otherwise it will just return the total - * - * @param mixed Agent id or array of agent id's, 0 for all - * - * @return mixed The number of data in the database - */ -function agents_get_modules_data_count ($id_agent = 0) { - $id_agent = safe_int ($id_agent, 1); - - if (empty ($id_agent)) { - $id_agent = array (); - } - else { - $id_agent = (array) $id_agent; - } - - $count = array (); - $count["total"] = 0; - - $query[0] = "SELECT COUNT(*) FROM tagente_datos"; - - foreach ($id_agent as $agent_id) { - //Init value - $count[$agent_id] = 0; - // TODO TAGS agents_get_modules - $modules = array_keys (agents_get_modules ($agent_id)); - foreach ($query as $sql) { - //Add up each table's data - //Avoid the count over empty array - if (!empty($modules)) - $count[$agent_id] += (int) db_get_sql ($sql . - " WHERE id_agente_modulo IN (".implode (",", $modules).")", 0, true); - } - //Add total agent count to total count - $count["total"] += $count[$agent_id]; - } - - if ($count["total"] == 0) { - foreach ($query as $sql) { - $count["total"] += (int) db_get_sql ($sql, 0, true); - } - } - - return $count; //Return the array -} - /** * Check if an agent has alerts fired. * diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index b268751fd4..f09bb04c45 100644 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -20,210 +20,6 @@ include_once($config['homedir'] . "/include/functions_agents.php"); include_once($config['homedir'] . "/include/functions_modules.php"); include_once($config['homedir'] . "/include/functions_users.php"); -function get_graph_statistics ($chart_array) { - global $config; - - /// IMPORTANT! - /// - /// The calculus for AVG, MIN and MAX values are in this function - /// because it must be done based on graph array data not using reporting - /// function to get coherent data between stats and graph visualization - - $stats = array (); - - $count = 0; - - $size = sizeof($chart_array); - - //Initialize stats array - $stats = array ("avg" => 0, "min" => null, "max" => null, "last" => 0); - - foreach ($chart_array as $item) { - - //Sum all values later divide by the number of elements - $stats['avg'] = $stats['avg'] + $item; - - //Get minimum - if ($stats['min'] == null) { - $stats['min'] = $item; - } - else if ($item < $stats['min']) { - $stats['min'] = $item; - } - - //Get maximum - if ($stats['max'] == null) { - $stats['max'] = $item; - } - else if ($item > $stats['max']) { - $stats['max'] = $item; - } - - $count++; - - //Get last data - if ($count == $size) { - $stats['last'] = $item; - } - } - - //End the calculus for average - if ($count > 0) { - - $stats['avg'] = $stats['avg'] / $count; - } - - //Format stat data to display properly - $stats['last'] = remove_right_zeros(number_format($stats['last'], $config['graph_precision'])); - $stats['avg'] = remove_right_zeros(number_format($stats['avg'], $config['graph_precision'])); - $stats['min'] = remove_right_zeros(number_format($stats['min'], $config['graph_precision'])); - $stats['max'] = remove_right_zeros(number_format($stats['max'], $config['graph_precision'])); - - return $stats; -} - -function get_statwin_graph_statistics ($chart_array, $series_suffix = '') { - - /// IMPORTANT! - /// - /// The calculus for AVG, MIN and MAX values are in this function - /// because it must be done based on graph array data not using reporting - /// function to get coherent data between stats and graph visualization - - $stats = array (); - - $count = 0; - - $size = sizeof($chart_array); - - //Initialize stats array - $stats['sum'] = array ("avg" => 0, "min" => null, "max" => null, "last" => 0); - $stats['min'] = array ("avg" => 0, "min" => null, "max" => null, "last" => 0); - $stats['max'] = array ("avg" => 0, "min" => null, "max" => null, "last" => 0); - - foreach ($chart_array as $item) { - if ($series_suffix != '') { - if (isset($item['sum' . $series_suffix])) - $item['sum'] = $item['sum' . $series_suffix]; - if (isset($item['min' . $series_suffix])) - $item['min'] = $item['min' . $series_suffix]; - if (isset($item['max' . $series_suffix])) - $item['max'] = $item['max' . $series_suffix]; - } - - //Get stats for normal graph - if (isset($item['sum']) && $item['sum']) { - - //Sum all values later divide by the number of elements - $stats['sum']['avg'] = $stats['sum']['avg'] + $item['sum']; - - //Get minimum - if ($stats['sum']['min'] == null) { - $stats['sum']['min'] = $item['sum']; - } - else if ($item['sum'] < $stats['sum']['min']) { - $stats['sum']['min'] = $item['sum']; - } - - //Get maximum - if ($stats['sum']['max'] == null) { - $stats['sum']['max'] = $item['sum']; - } - else if ($item['sum'] > $stats['sum']['max']) { - $stats['sum']['max'] = $item['sum']; - } - } - - //Get stats for min graph - if (isset($item['min']) && $item['min']) { - //Sum all values later divide by the number of elements - $stats['min']['avg'] = $stats['min']['avg'] + $item['min']; - - //Get minimum - if ($stats['min']['min'] == null) { - $stats['min']['min'] = $item['min']; - } - else if ($item['min'] < $stats['min']['min']) { - $stats['min']['min'] = $item['min']; - } - - //Get maximum - if ($stats['min']['max'] == null) { - $stats['min']['max'] = $item['min']; - } - else if ($item['min'] > $stats['min']['max']) { - $stats['min']['max'] = $item['min']; - } - } - - //Get stats for max graph - if (isset($item['max']) && $item['max']) { - //Sum all values later divide by the number of elements - $stats['max']['avg'] = $stats['max']['avg'] + $item['max']; - - //Get minimum - if ($stats['max']['min'] == null) { - $stats['max']['min'] = $item['max']; - } - else if ($item['max'] < $stats['max']['min']) { - $stats['max']['min'] = $item['max']; - } - - //Get maximum - if ($stats['max']['max'] == null) { - $stats['max']['max'] = $item['max']; - } - else if ($item['max'] > $stats['max']['max']) { - $stats['max']['max'] = $item['max']; - } - } - - //Count elements - $count++; - - //Get last data - if ($count == $size) { - if (isset($item['sum']) && $item['sum']) { - $stats['sum']['last'] = $item['sum']; - } - - if (isset($item['min']) && $item['min']) { - $stats['min']['last'] = $item['min']; - } - - if (isset($item['max']) && $item['max']) { - $stats['max']['last'] = $item['max']; - } - } - } - - //End the calculus for average - if ($count > 0) { - - $stats['sum']['avg'] = $stats['sum']['avg'] / $count; - $stats['min']['avg'] = $stats['min']['avg'] / $count; - $stats['max']['avg'] = $stats['max']['avg'] / $count; - } - - //Format stat data to display properly - $stats['sum']['last'] = round($stats['sum']['last'], 2); - $stats['sum']['avg'] = round($stats['sum']['avg'], 2); - $stats['sum']['min'] = round($stats['sum']['min'], 2); - $stats['sum']['max'] = round($stats['sum']['max'], 2); - - $stats['min']['last'] = round($stats['min']['last'], 2); - $stats['min']['avg'] = round($stats['min']['avg'], 2); - $stats['min']['min'] = round($stats['min']['min'], 2); - $stats['min']['max'] = round($stats['min']['max'], 2); - - $stats['max']['last'] = round($stats['max']['last'], 2); - $stats['max']['avg'] = round($stats['max']['avg'], 2); - $stats['max']['min'] = round($stats['max']['min'], 2); - $stats['max']['max'] = round($stats['max']['max'], 2); - - return $stats; -} - function grafico_modulo_sparse_data_chart ( $agent_module_id, $date_array, @@ -2624,383 +2420,6 @@ function graph_sla_slicebar ($id, $period, $sla_min, $sla_max, $date, $daysWeek $config['fontpath'], $round_corner, $home_url, $ttl); } -/** - * Print a pie graph with purge data of agent - * - * @param integer id_agent ID of agent to show - * @param integer width pie graph width - * @param integer height pie graph height - */ -function grafico_db_agentes_purge ($id_agent, $width = 380, $height = 300) { - global $config; - global $graphic_type; - - $filter = array(); - - if ($id_agent < 1) { - $query = ""; - } - else { - // TODO TAGS agents_get_modules - $modules = agents_get_modules($id_agent); - $module_ids = array_keys($modules); - - if (!empty($module_ids)) - $filter['id_agente_modulo'] = $module_ids; - } - - // All data (now) - $time_now = time(); - - // 1 day ago - $time_1day = $time_now - SECONDS_1DAY; - - // 1 week ago - $time_1week = $time_now - SECONDS_1WEEK; - - // 1 month ago - $time_1month = $time_now - SECONDS_1MONTH; - - // Three months ago - $time_3months = $time_now - SECONDS_3MONTHS; - - $query_error = false; - - // Data from 1 day ago - $num_1day = 0; - $num_1day += (int) db_get_sql('SELECT COUNT(*) - FROM tagente_datos - WHERE utimestamp > ' . $time_1day); - $num_1day += (int) db_get_sql('SELECT COUNT(*) - FROM tagente_datos_string - WHERE utimestamp > ' . $time_1day); - $num_1day += (int) db_get_sql('SELECT COUNT(*) - FROM tagente_datos_log4x - WHERE utimestamp > ' . $time_1day); - if ($num_1day >= 0) { - // Data from 1 week ago - $num_1week = 0; - $num_1week += (int) db_get_sql('SELECT COUNT(*) - FROM tagente_datos - WHERE utimestamp > ' . $time_1week . ' - AND utimestamp < ' . $time_1day); - $num_1week += (int) db_get_sql('SELECT COUNT(*) - FROM tagente_datos_string - WHERE utimestamp > ' . $time_1week . ' - AND utimestamp < ' . $time_1day); - $num_1week += (int) db_get_sql('SELECT COUNT(*) - FROM tagente_datos_log4x - WHERE utimestamp > ' . $time_1week . ' - AND utimestamp < ' . $time_1day); - if ($num_1week >= 0) { - if ($num_1week > 0) { - $num_1week = 0; - $num_1week += (int) db_get_sql('SELECT COUNT(*) - FROM tagente_datos - WHERE utimestamp > ' . $time_1week); - $num_1week += (int) db_get_sql('SELECT COUNT(*) - FROM tagente_datos_string - WHERE utimestamp > ' . $time_1week); - $num_1week += (int) db_get_sql('SELECT COUNT(*) - FROM tagente_datos_log4x - WHERE utimestamp > ' . $time_1week); - } - // Data from 1 month ago - $num_1month = 0; - $num_1month += (int) db_get_sql('SELECT COUNT(*) - FROM tagente_datos - WHERE utimestamp > ' . $time_1month . ' - AND utimestamp < ' . $time_1week); - $num_1month += (int) db_get_sql('SELECT COUNT(*) - FROM tagente_datos_string - WHERE utimestamp > ' . $time_1month . ' - AND utimestamp < ' . $time_1week); - $num_1month += (int) db_get_sql('SELECT COUNT(*) - FROM tagente_datos_log4x - WHERE utimestamp > ' . $time_1month . ' - AND utimestamp < ' . $time_1week); - if ($num_1month >= 0) { - if ($num_1month > 0) { - $num_1month = 0; - $num_1month += (int) db_get_sql('SELECT COUNT(*) - FROM tagente_datos - WHERE utimestamp > ' . $time_1month); - $num_1month += (int) db_get_sql('SELECT COUNT(*) - FROM tagente_datos_string - WHERE utimestamp > ' . $time_1month); - $num_1month += (int) db_get_sql('SELECT COUNT(*) - FROM tagente_datos_log4x - WHERE utimestamp > ' . $time_1month); - } - // Data from 3 months ago - $num_3months = 0; - $num_3months += (int) db_get_sql('SELECT COUNT(*) - FROM tagente_datos - WHERE utimestamp > ' . $time_3months . ' - AND utimestamp < ' . $time_1month); - $num_3months += (int) db_get_sql('SELECT COUNT(*) - FROM tagente_datos - WHERE utimestamp > ' . $time_3months . ' - AND utimestamp < ' . $time_1month); - $num_3months += (int) db_get_sql('SELECT COUNT(*) - FROM tagente_datos - WHERE utimestamp > ' . $time_3months . ' - AND utimestamp < ' . $time_1month); - if ($num_3months >= 0) { - if ($num_3months > 0) { - $num_3months = 0; - $num_3months += (int) db_get_sql('SELECT COUNT(*) - FROM tagente_datos - WHERE utimestamp > ' . $time_3months); - $num_3months += (int) db_get_sql('SELECT COUNT(*) - FROM tagente_datos - WHERE utimestamp > ' . $time_3months); - $num_3months += (int) db_get_sql('SELECT COUNT(*) - FROM tagente_datos - WHERE utimestamp > ' . $time_3months); - } - // All data - $num_all = 0; - $num_all += (int) db_get_sql('SELECT COUNT(*) - FROM tagente_datos - WHERE utimestamp < ' . $time_3months); - $num_all += (int) db_get_sql('SELECT COUNT(*) - FROM tagente_datos - WHERE utimestamp < ' . $time_3months); - $num_all += (int) db_get_sql('SELECT COUNT(*) - FROM tagente_datos - WHERE utimestamp < ' . $time_3months); - if ($num_all >= 0) { - $num_older = $num_all - $num_3months; - if ($config['history_db_enabled'] == 1) { - // All data in common and history database - $num_all_w_history = 0; - $num_all_w_history += (int) db_get_sql('SELECT COUNT(*) - FROM tagente_datos - WHERE utimestamp < ' . $time_3months); - $num_all_w_history += (int) db_get_sql('SELECT COUNT(*) - FROM tagente_datos - WHERE utimestamp < ' . $time_3months); - $num_all_w_history += (int) db_get_sql('SELECT COUNT(*) - FROM tagente_datos - WHERE utimestamp < ' . $time_3months); - if ($num_all_w_history >= 0) { - $num_history = $num_all_w_history - $num_all; - } - } - } - } - } - } - } - else if (($num_1day == 0) && ($num_1week == 0) && ($num_1month == 0) && ($num_3months == 0) && ($num_all == 0)) { - //If no data, returns empty - $query_error = true; - } - - // Error - if ($query_error || $num_older < 0 || ($config['history_db_enabled'] == 1 && $num_history < 0) - || (empty($num_1day) && empty($num_1week) && empty($num_1month) - && empty($num_3months) && empty($num_all) - && ($config['history_db_enabled'] == 1 && empty($num_all_w_history)))) { - return html_print_image('images/image_problem_area_small.png', true); - } - - // Data indexes - $str_1day = __("Today"); - $str_1week = "1 ".__("Week"); - $str_1month = "1 ".__("Month"); - $str_3months = "3 ".__("Months"); - $str_older = "> 3 ".__("Months"); - - // Filling the data array - $data = array(); - if (!empty($num_1day)) - $data[$str_1day] = $num_1day; - if (!empty($num_1week)) - $data[$str_1week] = $num_1week; - if (!empty($num_1month)) - $data[$str_1month] = $num_1month; - if (!empty($num_3months)) - $data[$str_3months] = $num_3months; - if (!empty($num_older)) - $data[$str_older] = $num_older; - if ($config['history_db_enabled'] == 1 && !empty($num_history)) { - // In this pie chart only 5 elements are shown, so we need to remove - // an element. With a history db enabled the >3 months element are dispensable - if (count($data) >= 5 && isset($data[$str_3months])) - unset($data[$str_3months]); - - $time_historic_db = time() - ((int)$config['history_db_days'] * SECONDS_1DAY); - $date_human = human_time_comparation($time_historic_db); - $str_history = "> $date_human (".__("History db").")"; - $data[$str_history] = $num_history; - } - - $water_mark = array( - 'file' => $config['homedir'] . "/images/logo_vertical_water.png", - 'url' => ui_get_full_url("images/logo_vertical_water.png", false, false, false) - ); - - return pie3d_graph($config['flash_charts'], $data, $width, $height, - __('Other'), '', $water_mark, $config['fontpath'], $config['font_size']); -} - -/** - * Print a horizontal bar graph with packets data of agents - * - * @param integer width pie graph width - * @param integer height pie graph height - */ -function grafico_db_agentes_paquetes($width = 380, $height = 300) { - global $config; - global $graphic_type; - - - $data = array (); - $legend = array (); - - $agents = agents_get_group_agents (array_keys (users_get_groups (false, 'RR')), false, "none"); - $count = agents_get_modules_data_count (array_keys ($agents)); - unset ($count["total"]); - arsort ($count, SORT_NUMERIC); - $count = array_slice ($count, 0, 8, true); - - foreach ($count as $agent_id => $value) { - $data[$agents[$agent_id]]['g'] = $value; - } - - if($config["fixed_graph"] == false){ - $water_mark = array('file' => - $config['homedir'] . "/images/logo_vertical_water.png", - 'url' => ui_get_full_url("images/logo_vertical_water.png", false, false, false)); - } - - return hbar_graph($config['flash_charts'], $data, $width, $height, array(), - $legend, "", "", true, "", $water_mark, - $config['fontpath'], $config['font_size'], false, 1, $config['homeurl'], - 'white', - 'black'); -} - -/** - * Print a horizontal bar graph with modules data of agents - * - * @param integer height graph height - * @param integer width graph width - */ -function graph_db_agentes_modulos($width, $height) { - global $config; - global $graphic_type; - - - $data = array (); - - switch ($config['dbtype']) { - case "mysql": - case "postgresql": - $modules = db_get_all_rows_sql (' - SELECT COUNT(id_agente_modulo), id_agente - FROM tagente_modulo - WHERE delete_pending = 0 - GROUP BY id_agente - ORDER BY 1 DESC LIMIT 10'); - break; - case "oracle": - $modules = db_get_all_rows_sql (' - SELECT COUNT(id_agente_modulo), id_agente - FROM tagente_modulo - WHERE rownum <= 10 - AND delete_pending = 0 - GROUP BY id_agente - ORDER BY 1 DESC'); - break; - } - if ($modules === false) - $modules = array (); - - $data = array(); - foreach ($modules as $module) { - $agent_name = agents_get_name ($module['id_agente'], "none"); - - if (empty($agent_name)) { - continue; - } - switch ($config['dbtype']) { - case "mysql": - case "postgresql": - $data[$agent_name]['g'] = $module['COUNT(id_agente_modulo)']; - break; - case "oracle": - $data[$agent_name]['g'] = $module['count(id_agente_modulo)']; - break; - } - } - - if($config["fixed_graph"] == false){ - $water_mark = array('file' => - $config['homedir'] . "/images/logo_vertical_water.png", - 'url' => ui_get_full_url("images/logo_vertical_water.png", false, false, false)); - } - - return hbar_graph($config['flash_charts'], - $data, $width, $height, array(), - array(), "", "", true, "", - $water_mark, - $config['fontpath'], $config['font_size'], false, 1, $config['homeurl'], - 'white', - 'black'); -} - -/** - * Print a pie graph with users activity in a period of time - * - * @param integer width pie graph width - * @param integer height pie graph height - * @param integer period time period - */ -function graphic_user_activity ($width = 350, $height = 230) { - global $config; - global $graphic_type; - - $data = array (); - $max_items = 5; - switch ($config['dbtype']) { - case "mysql": - case "postgresql": - $sql = sprintf ('SELECT COUNT(id_usuario) n_incidents, id_usuario - FROM tsesion - GROUP BY id_usuario - ORDER BY 1 DESC LIMIT %d', $max_items); - break; - case "oracle": - $sql = sprintf ('SELECT COUNT(id_usuario) n_incidents, id_usuario - FROM tsesion - WHERE rownum <= %d - GROUP BY id_usuario - ORDER BY 1 DESC', $max_items); - break; - } - $logins = db_get_all_rows_sql ($sql); - - if ($logins == false) { - $logins = array(); - } - foreach ($logins as $login) { - $data[$login['id_usuario']] = $login['n_incidents']; - } - - if($config["fixed_graph"] == false){ - $water_mark = array('file' => - $config['homedir'] . "/images/logo_vertical_water.png", - 'url' => ui_get_full_url("images/logo_vertical_water.png", false, false, false)); - } - - return pie3d_graph($config['flash_charts'], $data, $width, $height, - __('Other'), '', $water_mark, - $config['fontpath'], $config['font_size']); -} - /** * Print a pie graph with priodity incident */ @@ -3428,70 +2847,6 @@ function grafico_eventos_grupo ($width = 300, $height = 200, $url = "", $meta = $config['fontpath'], $config['font_size'], 1, 'bottom'); } -function grafico_eventos_agente ($width = 300, $height = 200, $result = false, $meta = false, $history = false) { - global $config; - global $graphic_type; - - //It was urlencoded, so we urldecode it - //$url = html_entity_decode (rawurldecode ($url), ENT_QUOTES); - $data = array (); - $loop = 0; - - if ($result === false) { - $result = array(); - } - - $system_events = 0; - $other_events = 0; - $total = array(); - $i = 0; - - foreach ($result as $row) { - if ($meta) { - $count[] = $row["agent_name"]; - } - else { - if ($row["id_agente"] == 0) { - $count[] = __('SYSTEM'); - } - else - $count[] = agents_get_alias($row["id_agente"]) ; - } - - } - - $total = array_count_values($count); - - foreach ($total as $key => $total) { - if ($meta) { - $name = $key." (".$total.")"; - } - else { - $name = $key." (".$total.")"; - } - $data[$name] = $total; - } - - /* - if ($other_events > 0) { - $name = __('Other')." (".$other_events.")"; - $data[$name] = $other_events; - } - */ - - // Sort the data - arsort($data); - if($config["fixed_graph"] == false){ - $water_mark = array('file' => - $config['homedir'] . "/images/logo_vertical_water.png", - 'url' => ui_get_full_url("images/logo_vertical_water.png", false, false, false)); - } - - return pie3d_graph($config['flash_charts'], $data, $width, $height, - __('Others'), '', $water_mark, - $config['fontpath'], $config['font_size'], 1, 'bottom'); -} - /** * Print a pie graph with events data in 320x200 size *