diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index ceebcbe4e0..d0a30301ad 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,13 @@ +2009-05-27 Esteban Sanchez + + * include/functions_db.php: return_status_agent() renamed to + get_agent_status(). Improved get_agentmodule_status() documentation + and code. + + * include/functions_visual_map.php: Styles correction. Use a switch + instead of many ifs. Fixed get_layout_status() so the bad values have + preference. Fixes #2787197. + 2009-05-25 Esteban Sanchez * godmode/modules/manage_network_components.php: Fixed a typo on diff --git a/pandora_console/include/functions_db.php b/pandora_console/include/functions_db.php index a24aad7856..86175e5ac5 100644 --- a/pandora_console/include/functions_db.php +++ b/pandora_console/include/functions_db.php @@ -2089,19 +2089,21 @@ function format_array_to_where_clause_sql ($values, $join = 'AND', $prefix = fal } /** - * Get the status of an alert assigned to an agent module. + * Get the status of an agent module. * * @param int Id agent module to check. * - * @return bool True if there were alerts fired. + * @return int Module status. Value 4 means that some alerts assigned to the + * module were fired. */ function get_agentmodule_status ($id_agentmodule = 0) { - $status = get_db_value ('estado', 'tagente_estado', 'id_agente_modulo', $id_agentmodule); - $times_fired = get_db_value ('SUM(times_fired)', 'talert_template_modules', 'id_agent_module', $id_agentmodule); if ($times_fired > 0) { return 4; // Alert } + + $status = get_db_value ('estado', 'tagente_estado', 'id_agente_modulo', $id_agentmodule); + return $status; } @@ -2112,14 +2114,14 @@ function get_agentmodule_status ($id_agentmodule = 0) { * * @return int Worst status of an agent for all of its modules */ -function return_status_agent ($id_agent = 0) { +function get_agent_status ($id_agent = 0) { $status = get_db_sql ("SELECT MAX(estado) - FROM tagente_estado, tagente_modulo - WHERE tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo - AND tagente_modulo.disabled = 0 - AND tagente_modulo.delete_pending = 0 - AND tagente_modulo.id_agente = $id_agent"); - + FROM tagente_estado, tagente_modulo + WHERE tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo + AND tagente_modulo.disabled = 0 + AND tagente_modulo.delete_pending = 0 + AND tagente_modulo.id_agente = $id_agent"); + // TODO: Check any alert for that agent who has recept alerts fired return $status; diff --git a/pandora_console/include/functions_visual_map.php b/pandora_console/include/functions_visual_map.php index 43992b9485..2c5654b154 100644 --- a/pandora_console/include/functions_visual_map.php +++ b/pandora_console/include/functions_visual_map.php @@ -17,7 +17,6 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - /** * Prints visual map * @@ -36,11 +35,10 @@ function print_pandora_visual_map ($id_layout, $show_links = true, $draw_lines = if ($layout_datas !== false) { foreach ($layout_datas as $layout_data) { // Linked to other layout ?? - Only if not module defined - if ($layout_data['id_layout_linked'] != 0) { + if ($layout_data['id_layout_linked'] != 0) { $status = get_layout_status ($layout_data['id_layout_linked']); $status_parent = 3; } else { - // Status for a simple module if ($layout_data['id_agente_modulo'] != 0) { $id_agent = get_db_value ("id_agente", "tagente_estado", "id_agente_modulo", $layout_data['id_agente_modulo']); @@ -51,7 +49,6 @@ function print_pandora_visual_map ($id_layout, $show_links = true, $draw_lines = $status_parent = 3; else $status_parent = get_agentmodule_status ($id_agent_module_parent); - // Status for a whole agent } elseif ($layout_data['id_agent'] != 0) { $id_agent = $layout_data['id_agent']; @@ -86,26 +83,23 @@ function print_pandora_visual_map ($id_layout, $show_links = true, $draw_lines = elseif ($status == 4) // Alert $z_index = 4; else - $z_index = 1; // Print BAD over good + $z_index = 1; // Print BAD over good // Draw image echo '
'; - if (!isset($id_agent)) + if (!isset ($id_agent)) $id_agent = 0; if ($show_links) { - - // Link to an agent if (($id_agent > 0) && ($layout_data['id_layout_linked'] == "" || $layout_data['id_layout_linked'] == 0)) { + // Link to an agent echo ''; - - // Link to a map - } elseif ($layout_data['id_layout_linked']>0){ + } elseif ($layout_data['id_layout_linked'] > 0) { + // Link to a map echo ''; - - // A void object - } else { + } else { + // A void object echo ''; } } @@ -152,19 +146,17 @@ function print_pandora_visual_map ($id_layout, $show_links = true, $draw_lines = echo "
"; } - // SIMPLE DATA VALIE (type = 2) - if ($layout_data['type'] == 2){ - - echo '
'; - echo ''.$layout_data['label']. ' '; - echo get_db_sql ('SELECT datos FROM tagente_estado WHERE id_agente_modulo = '.$layout_data['id_agente_modulo']); - echo '
'; - } - - // Percentile bar (type = 3) - if ($layout_data['type'] == 3){ - - echo '
'; + // SIMPLE DATA VALUE (type = 2) + switch ($layout_data['type']) { + case 2: + echo '
'; + echo ''.$layout_data['label']. ' '; + echo get_db_value ('datos', 'tagente_estado', 'id_agente_modulo', $layout_data['id_agente_modulo']); + echo '
'; + break; + case 3: + // Percentile bar (type = 3) + echo '
'; $valor = get_db_sql ('SELECT datos FROM tagente_estado WHERE id_agente_modulo = '.$layout_data['id_agente_modulo']); $width = $layout_data['width']; if ( $layout_data['height'] > 0) @@ -177,12 +169,9 @@ function print_pandora_visual_map ($id_layout, $show_links = true, $draw_lines = echo ""; echo '
'; - - } - // SINGLE GRAPH (type = 1) - if ($layout_data['type'] == 1) { // single graph - - // Draw image + break; + case 1; + // SINGLE GRAPH (type = 1) echo '
"; - + } // Line, not implemented in editor + /* } elseif ($layout_data['type'] == 2) { $line['id'] = $layout_data['id']; $line['x'] = $layout_data['pos_x']; @@ -205,6 +195,7 @@ function print_pandora_visual_map ($id_layout, $show_links = true, $draw_lines = $line['color'] = $layout_data['label_color']; array_push ($lines, $line); } + */ // Get parent relationship - Create line data if ($layout_data["parent_item"] != "" && $layout_data["parent_item"] != 0) { @@ -216,6 +207,7 @@ function print_pandora_visual_map ($id_layout, $show_links = true, $draw_lines = } } } + if ($draw_lines) { /* If you want lines in the map, call using Javascript: draw_lines (lines, id_div); @@ -301,7 +293,7 @@ function get_layout_status ($id_layout = 0) { $sql = sprintf ('SELECT id_agente_modulo, parent_item, id_layout_linked, id_agent FROM `tlayout_data` WHERE `id_layout` = %d', $id_layout); - $result = get_db_all_rows_filter ('tlayout_data', array ('id' => $id_layout), + $result = get_db_all_rows_filter ('tlayout_data', array ('id_layout' => $id_layout), array ('id_agente_modulo', 'parent_item', 'id_layout_linked', 'id_agent')); if ($result === false) return 0; @@ -309,24 +301,21 @@ function get_layout_status ($id_layout = 0) { foreach ($result as $rownum => $data) { // Other Layout (Recursive!) if (($data["id_layout_linked"] != 0) && ($data["id_agente_modulo"] == 0)) { - $temp_status = get_layout_status ($data["id_layout_linked"]); - if ($temp_status > $temp_total) { - $temp_total = $temp_status; - } - + $status = get_layout_status ($data["id_layout_linked"]); // Module } elseif ($data["id_agente_modulo"] != 0) { - $temp_status = get_agentmodule_status ($data["id_agente_modulo"]); - if ($temp_status > $temp_total) - $temp_total = $temp_status; - + $status = get_agentmodule_status ($data["id_agente_modulo"]); // Agent } else { - $temp_status = get_agentmodule_status ($data["id_agent"]); - if ($temp_status > $temp_total) - $temp_total = $temp_status; + $status = get_agent_status ($data["id_agent"]); } + + if ($status == 0) + return 0; + if ($status > $temp_total) + $temp_total = $status; } + return $temp_total; } ?>