diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 37eb41ef03..cdf06ea724 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,23 @@ +2013-03-04 Sergio Martin + + * include/functions_alerts.php: Update the fired + counts on validate alerts function + + * include/functions_events.php + include/functions_reporting.php + include/javascript/jquery.pandora.js + include/functions_treeview.php + operation/tree.php + operation/agentes/estado_generalagente.php + operation/agentes/estado_agente.php + operation/search_agents.php: Improve and unify code + of the status counts in agents list, agent detail, + tree view and search views + + * ajax.php: Load the user language in the + ajax entry point. Until now the language was the + general! + 2013-03-01 Sergio Martin * include/functions_graph.php diff --git a/pandora_console/ajax.php b/pandora_console/ajax.php index 9c73c19ffc..86ddd62386 100644 --- a/pandora_console/ajax.php +++ b/pandora_console/ajax.php @@ -67,10 +67,20 @@ $isFunctionSkins = enterprise_include_once ('include/functions_skins.php'); if ($isFunctionSkins !== ENTERPRISE_NOT_HOOK) $config["relative_path"] = enterprise_hook('skins_set_image_skin_path',array($config['id_user'])); +// Load user language +$user_language = get_user_language ($config['id_user']); + +$l10n = NULL; +if (file_exists ('./include/languages/'.$user_language.'.mo')) { + $l10n = new gettext_reader (new CachedFileReader ('./include/languages/'.$user_language.'.mo')); + $l10n->load_tables(); +} + // Not cool way of know if we are executing from metaconsole or normal console if (strpos($_SERVER['HTTP_REFERER'], ENTERPRISE_DIR . '/meta/') !== false) define ('METACONSOLE', true); session_write_close (); + if (file_exists ($page)) { require_once ($page); } diff --git a/pandora_console/include/functions_alerts.php b/pandora_console/include/functions_alerts.php index 267378ca1d..0cad45908e 100644 --- a/pandora_console/include/functions_alerts.php +++ b/pandora_console/include/functions_alerts.php @@ -1157,6 +1157,9 @@ function alerts_validate_alert_agent_module ($id_alert_agent_module, $noACLs = f array ('times_fired' => 0, 'internal_counter' => 0), array ('id' => $id)); + + // Update fired alert count on the agent + db_process_sql(sprintf('UPDATE tagente SET fired_count=fired_count-1 WHERE id_agente = %d', $agent_id)); if ($result > 0) { events_create_event ("Manual validation of alert for ". diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index ecd0ef2591..aa4d8b1afd 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -693,38 +693,6 @@ function events_create_event ($event, $id_group, $id_agent, $status = 0, $id_use return (int) db_process_sql ($sql, "insert_id"); } -/** - * Print tiny statistics of an agent - * - * @param integer number of total modules - * @param integer number of normal modules - * @param integer number of critical modules - * @param integer number of warning modules - * @param integer number of unknown modules - * @param bool return or echo flag - * - */ -function events_tiny_stats ($total_modules, $normal_modules, $critical_modules, $warning_modules, $unknown_modules, $return = false) { - $out = '' . $total_modules; - if ($critical_modules > 0) - $out .= ' : ' . $critical_modules . ''; - if ($warning_modules > 0) - $out .= ' : ' . $warning_modules . ''; - if ($unknown_modules > 0) - $out .= ' : ' . $unknown_modules . ''; - if ($normal_modules > 0) - $out .= ' : ' . $normal_modules . ''; - - $out .= ''; - - if ($return) { - return $out; - } - else { - echo $out; - } -} - /** * Prints a small event table diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index eb92db89ff..6391816883 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -6607,4 +6607,105 @@ function reporting_get_count_events_validated ($filter, $period = 0, $filter_event_validated, $filter_event_critical, $filter_event_warning, $filter_event_no_validated); } + +/** + * Print tiny statistics of the status of one agent, group, etc. + * + * @param mixed Array with the counts of the total modules, normal modules, critical modules, warning modules, unknown modules and fired alerts + * @param bool return or echo flag + * + * @return string html formatted tiny stats of modules/alerts of an agent + */ +function reporting_tiny_stats ($counts_info, $return = false, $type = 'agent') { + $out = ''; + + // Depend the type of object, the stats will refer agents, modules... + switch($type) { + case 'agent': + $template_title['total_count'] = __('%d Total modules'); + $template_title['normal_count'] = __('%d Normal modules'); + $template_title['critical_count'] = __('%d Critical modules'); + $template_title['warning_count'] = __('%d Warning modules'); + $template_title['unknown_count'] = __('%d Unknown modules'); + $template_title['fired_count'] = __('%d Fired alerts'); + break; + default: + $template_title['total_count'] = __('%d Total agents'); + $template_title['normal_count'] = __('%d Normal agents'); + $template_title['critical_count'] = __('%d Critical agents'); + $template_title['warning_count'] = __('%d Warning agents'); + $template_title['unknown_count'] = __('%d Unknown agents'); + $template_title['fired_count'] = __('%d Fired agents'); + break; + } + + // Store the counts in a data structure to print hidden divs with titles + $stats = array(); + + if(isset($counts_info['total_count'])) { + $total_count = $counts_info['total_count']; + $stats[] = array('name' => 'total_count', 'count' => $total_count, 'title' => sprintf($template_title['total_count'], $total_count)); + } + + if(isset($counts_info['normal_count'])) { + $normal_count = $counts_info['normal_count']; + $stats[] = array('name' => 'normal_count', 'count' => $normal_count, 'title' => sprintf($template_title['normal_count'], $normal_count)); + } + + if(isset($counts_info['critical_count'])) { + $critical_count = $counts_info['critical_count']; + $stats[] = array('name' => 'critical_count', 'count' => $critical_count, 'title' => sprintf($template_title['critical_count'], $critical_count)); + } + + if(isset($counts_info['warning_count'])) { + $warning_count = $counts_info['warning_count']; + $stats[] = array('name' => 'warning_count', 'count' => $warning_count, 'title' => sprintf($template_title['warning_count'], $warning_count)); + } + + if(isset($counts_info['unknown_count'])) { + $unknown_count = $counts_info['unknown_count']; + $stats[] = array('name' => 'unknown_count', 'count' => $unknown_count, 'title' => sprintf($template_title['unknown_count'], $unknown_count)); + } + + if(isset($counts_info['fired_count'])) { + $fired_count = $counts_info['fired_count']; + $stats[] = array('name' => 'fired_count', 'count' => $fired_count, 'title' => sprintf($template_title['total_count'], $fired_count)); + } + + $uniq_id = uniqid(); + + foreach($stats as $stat) { + $params = array('id' => 'forced_title_' . $stat['name'] . '_' . $uniq_id, + 'class' => 'forced_title_layer', + 'content' => $stat['title'], + 'hidden' => true); + $out .= html_print_div($params, true); + } + + // If total count is less than 0, is an error. Never show negative numbers + if($total_count < 0) { + $total_count = 0; + } + + $out .= '' . '' . $total_count . ''; + if (isset($fired_count) && $fired_count > 0) + $out .= ' : ' . $fired_count . ''; + if (isset($critical_count) && $critical_count > 0) + $out .= ' : ' . $critical_count . ''; + if (isset($warning_counts) && $warning_count > 0) + $out .= ' : ' . $warning_count . ''; + if (isset($unknown_count) && $unknown_count > 0) + $out .= ' : ' . $unknown_count . ''; + if (isset($normal_count) && $normal_count > 0) + $out .= ' : ' . $normal_count . ''; + + $out .= ''; + + if ($return) { + return $out; + } + else { + echo $out; + } +} ?> diff --git a/pandora_console/include/functions_treeview.php b/pandora_console/include/functions_treeview.php index 928e27a84c..3a741e8b57 100755 --- a/pandora_console/include/functions_treeview.php +++ b/pandora_console/include/functions_treeview.php @@ -441,13 +441,20 @@ function treeview_printTree($type) { else { $id = $item['_id_']; } + echo ""; - echo $img . $item['_iconImg_'] ." " . __($item['_name_']) . ' ('. - ''.''.$item['_num_ok_'].''.''. - ' : '.$item['_num_critical_'].'' . - ' : '.$item['_num_warning_'].''. - ' : '.$item['_num_unknown_'].''.') '. ""; + echo $img . $item['_iconImg_'] ." " . __($item['_name_']) . ' ('; + + $counts_info = array('total_count' => $item['_num_ok_'] + $item['_num_critical_'] + $item['_num_warning_'] + $item['_num_unknown_'], + 'normal_count' => $item['_num_ok_'], + 'critical_count' => $item['_num_critical_'], + 'warning_count' => $item['_num_warning_'], + 'unknown_count' => $item['_num_unknown_']); + + reporting_tiny_stats($counts_info, false, $type); + + echo ') '. ""; echo "
"; echo "\n"; diff --git a/pandora_console/include/javascript/jquery.pandora.js b/pandora_console/include/javascript/jquery.pandora.js index 5c5940ff2f..bc745db54b 100644 --- a/pandora_console/include/javascript/jquery.pandora.js +++ b/pandora_console/include/javascript/jquery.pandora.js @@ -168,9 +168,13 @@ $(document).ready (function () { }); } + + forced_title_callback(); +}); +function forced_title_callback() { // Forced title code - $('IMG.forced_title').hover(function() { + $('.forced_title').hover(function() { /////////////////////////////////////////// // Get info of the image /////////////////////////////////////////// @@ -225,4 +229,4 @@ $(document).ready (function () { function () { $('#forced_title_layer').hide().empty(); }); -}); +} diff --git a/pandora_console/operation/agentes/estado_agente.php b/pandora_console/operation/agentes/estado_agente.php index d6b7f4f05f..8bae85aa6a 100644 --- a/pandora_console/operation/agentes/estado_agente.php +++ b/pandora_console/operation/agentes/estado_agente.php @@ -455,20 +455,7 @@ foreach ($agents as $agent) { $data[4] = ui_print_group_icon ($agent["id_grupo"], true); - $data[5] = ''; - $data[5] .= $agent["total_count"]; - - if ($agent["fired_count"] > 0) - $data[5] .= ' : ' . $agent["fired_count"] . ''; - if ($agent["critical_count"] > 0) - $data[5] .= ' : ' . $agent["critical_count"] . ''; - if ($agent["warning_count"] > 0) - $data[5] .= ' : ' . $agent["warning_count"] . ''; - if ($agent["unknown_count"] > 0) - $data[5] .= ' : ' . $agent["unknown_count"] . ''; - if ($agent["normal_count"] > 0) - $data[5] .= ' : ' . $agent["normal_count"] . ''; - $data[5] .= ''; + $data[5] = reporting_tiny_stats($agent, true); $data[6] = $status_img; diff --git a/pandora_console/operation/agentes/estado_generalagente.php b/pandora_console/operation/agentes/estado_generalagente.php index cdfed96805..fc008d2dad 100644 --- a/pandora_console/operation/agentes/estado_generalagente.php +++ b/pandora_console/operation/agentes/estado_generalagente.php @@ -77,7 +77,7 @@ $data[0] .= $agent_name; $status_img = agents_tree_view_status_img ($agent["critical_count"], $agent["warning_count"], $agent["unknown_count"]); -$data[1] = events_tiny_stats ($agent['total_count'], $agent['normal_count'], $agent['critical_count'], $agent['warning_count'], $agent['unknown_count'], true); +$data[1] = reporting_tiny_stats ($agent, true); $data[2] = str_replace('.png' ,'_ball.png', $status_img); $table_agent->data[] = $data; diff --git a/pandora_console/operation/search_agents.php b/pandora_console/operation/search_agents.php index e6bebd667a..39a89d5276 100755 --- a/pandora_console/operation/search_agents.php +++ b/pandora_console/operation/search_agents.php @@ -245,17 +245,14 @@ else { foreach ($agents as $agent) { $agent_info = reporting_get_agent_module_info ($agent["id_agente"]); - $modulesCell = ''. $agent_info["modules"] . ''; - if ($agent_info["monitor_alertsfired"] > 0) - $modulesCell .= ' : '.$agent_info["monitor_alertsfired"].''; - if ($agent_info["monitor_normal"] > 0) - $modulesCell .= ' : '.$agent_info["monitor_normal"].''; - if ($agent_info["monitor_warning"] > 0) - $modulesCell .= ' : '.$agent_info["monitor_warning"].''; - if ($agent_info["monitor_critical"] > 0) - $modulesCell .= ' : '.$agent_info["monitor_critical"].''; - if ($agent_info["monitor_unknown"] > 0) - $modulesCell .= ' : '.$agent_info["monitor_unknown"].''; + $counts_info = array('total_count' => $agent_info["modules"], + 'normal_count' => $agent_info["monitor_normal"], + 'critical_count' => $agent_info["monitor_critical"], + 'warning_count' => $agent_info["monitor_warning"], + 'unknown_count' => $agent_info["monitor_unknown"], + 'fired_count' => $agent_info["monitor_alertsfired"]); + + $modulesCell = reporting_tiny_stats($counts_info, true); if ($agent['disabled']) { $cellName = "" . ui_print_agent_name ($agent["id_agente"], true, "text-transform: uppercase;") . ui_print_help_tip(__('Disabled'), true) . ""; diff --git a/pandora_console/operation/tree.php b/pandora_console/operation/tree.php index 1461bcebf8..df9811132a 100644 --- a/pandora_console/operation/tree.php +++ b/pandora_console/operation/tree.php @@ -238,21 +238,7 @@ if (is_ajax ()) echo $row["nombre"]; - echo " ("; - echo ''; - echo $agent_info["modules"]; - echo ''; - if ($agent_info["monitor_alertsfired"] > 0) - echo ' : '.$agent_info["monitor_alertsfired"].''; - if ($agent_info["monitor_critical"] > 0) - echo ' : '.$agent_info["monitor_critical"].''; - if ($agent_info["monitor_warning"] > 0) - echo ' : '.$agent_info["monitor_warning"].''; - if ($agent_info["monitor_unknown"] > 0) - echo ' : '.$agent_info["monitor_unknown"].''; - if ($agent_info["monitor_normal"] > 0) - echo ' : '.$agent_info["monitor_normal"].''; - echo ")"; + echo " (" . reporting_tiny_stats($row, true) . ")"; if ($row['quiet']) { echo " "; @@ -687,6 +673,9 @@ treeview_printTree($activeTab); $('#tree_div'+id_father+'_'+type+'_'+div_id).attr('hiddendiv',0); $('#tree_div'+id_father+'_'+type+'_'+div_id).attr('loadDiv', 1); } + + // Refresh forced title callback to work with html code created dinamicly + forced_title_callback(); } }); }