diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 525ace40bc..b929ed4e6a 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,15 @@ +2013-05-06 Miguel de Dios <miguel.dedios@artica.es> + + * operation/agentes/group_view.php, godmode/groups/group_list.php, + include/functions_groups.php: added pagination to groups views. + + PENDING TASK: #346 + + * include/functions_component_groups.php: cleaned source code style. + + * include/functions.php: added function "is_array_empty" for + deepers arrays. + 2013-05-06 Sergio Martin <sergio.martin@artica.es> * include/help/en/help_module_interval_factor.php diff --git a/pandora_console/godmode/groups/group_list.php b/pandora_console/godmode/groups/group_list.php index 8efa8c579d..cf4f44d8e3 100644 --- a/pandora_console/godmode/groups/group_list.php +++ b/pandora_console/godmode/groups/group_list.php @@ -248,6 +248,13 @@ db_clean_cache(); $groups = users_get_groups_tree ($config['id_user'], "AR", true); $table->width = '98%'; +echo '<br />'; +echo '<form method="post" action="index.php?sec='.$sec.'&sec2=godmode/groups/configure_group&pure='.$pure.'">'; +echo '<div class="action-buttons" style="width: '.$table->width.'">'; +html_print_submit_button (__('Create group'), 'crt', false, 'class="sub next"'); +echo '</div>'; +echo '</form>'; + if (!empty($groups)) { $table->head = array (); $table->head[0] = __('Name'); @@ -263,6 +270,49 @@ if (!empty($groups)) { $iterator = 0; + + $all_group = $groups[0]; + $groups = array_slice($groups, 1); + //Set the content of page of groups + $offset = (int)get_parameter('offset', 0); + $count_visible_groups = 0; + $count_visible_groups_block = 0; + $stop_count_block = false; + $count = 0; + $start = 0; + $stop = 0; + //$offset = $offset - $offset / $config['block_size']; + foreach ($groups as $group) { + if (((int)$group['parent']) == 0) { + $count_visible_groups++; + if (!$stop_count_block) + $count_visible_groups_block++; + } + + if (($count_visible_groups - 1) == ($offset) ) { + $stop_count_block = true; + $start = $count; + } + + // -1 for in the all pages is added all group + if (($count_visible_groups - 1) == ($offset + ($config['block_size'] - 1))) { + $stop_count_block = true; + $stop = $count; + } + + $count++; + } + if ($stop == 0) { + $stop = $start + $config['block_size']; + } + + // 1 for to add all group + ui_pagination($count_visible_groups + 1, false, 0, $config['block_size'] - 1); + + + $groups = array_slice($groups, $start, ($stop - $start)); + $groups = array_merge(array($all_group), $groups); + foreach ($groups as $id_group => $group) { if ($group['deep'] == 0) { $table->rowstyle[$iterator] = ''; @@ -364,6 +414,8 @@ if (!empty($groups)) { } html_print_table ($table); + + ui_pagination($count_visible_groups + 1, false, 0, $config['block_size'] - 1); } else { echo "<div class='nf'>".__('There are no defined groups')."</div>"; diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index e4366cdfa2..63a81b64f8 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -1746,4 +1746,20 @@ function set_js_value($name, $value) { html_print_div(array('id' => 'php_to_js_value_' . $name, 'content' => $value, 'hidden' => true)); } + +function is_array_empty($InputVariable) +{ + $Result = true; + + if (is_array($InputVariable) && count($InputVariable) > 0) { + foreach ($InputVariable as $Value) { + $Result = $Result && is_array_empty($Value); + } + } + else { + $Result = empty($InputVariable); + } + + return $Result; +} ?> diff --git a/pandora_console/include/functions_component_groups.php b/pandora_console/include/functions_component_groups.php index c32a9a8dd6..6f539e1d48 100644 --- a/pandora_console/include/functions_component_groups.php +++ b/pandora_console/include/functions_component_groups.php @@ -30,7 +30,7 @@ */ function component_groups_get_groups_tree_recursive($groups, $parent = 0, $deep = 0) { $return = array(); - + foreach ($groups as $key => $group) { if ($group['parent'] == $parent) { $group['deep'] = $deep; diff --git a/pandora_console/include/functions_groups.php b/pandora_console/include/functions_groups.php index fba2dbed7d..94ef09ed15 100644 --- a/pandora_console/include/functions_groups.php +++ b/pandora_console/include/functions_groups.php @@ -25,7 +25,7 @@ require_once ($config['homedir'].'/include/functions_users.php'); */ function groups_check_used($idGroup) { global $config; - + $return = array(); $return['return'] = false; $return['tables'] = array(); @@ -53,7 +53,7 @@ function groups_check_used($idGroup) { $numRows = db_get_num_rows('SELECT * FROM talert_actions WHERE id_group = ' . $idGroup); break; } - + if ($numRows > 0) { $return['return'] = true; $return['tables'][] = __('Alert Actions'); @@ -68,7 +68,7 @@ function groups_check_used($idGroup) { $numRows = db_get_num_rows('SELECT * FROM talert_templates WHERE id_group = ' . $idGroup); break; } - + if ($numRows > 0) { $return['return'] = true; $return['tables'][] = __('Alert Templates'); @@ -87,10 +87,10 @@ function groups_check_used($idGroup) { $return['return'] = true; $return['tables'][] = __('Recon task'); } - + switch ($config["dbtype"]) { case "mysql": - case "postgresql": + case "postgresql": $numRows = db_get_num_rows('SELECT * FROM tgraph WHERE id_group = ' . $idGroup . ';'); break; case "oracle": @@ -125,7 +125,7 @@ function groups_check_used($idGroup) { $numRows = db_get_num_rows('SELECT * FROM tlayout WHERE id_group = ' . $idGroup); break; } - + if ($numRows > 0) { $return['return'] = true; $return['tables'][] = __('Layout visual console'); @@ -236,9 +236,9 @@ function groups_get_childrens($parent, $groups = null) { if (empty($groups)) { $groups = db_get_all_rows_in_table('tgrupo'); } - + $return = array(); - + foreach ($groups as $key => $group) { if ($group['id_grupo'] == 0) { continue; @@ -247,7 +247,7 @@ function groups_get_childrens($parent, $groups = null) { $return = $return + array($group['id_grupo'] => $group) + groups_get_childrens($group['id_grupo'], $groups); } } - + return $return; } @@ -262,9 +262,9 @@ function groups_get_parents($parent, $onlyPropagate = false, $groups = null) { if (empty($groups)) { $groups = db_get_all_rows_in_table('tgrupo'); } - + $return = array(); - + foreach ($groups as $key => $group) { if ($group['id_grupo'] == 0) { continue; @@ -274,7 +274,7 @@ function groups_get_parents($parent, $onlyPropagate = false, $groups = null) { $return = $return + array($group['id_grupo'] => $group) + groups_get_parents($group['parent'], $onlyPropagate, $groups); } } - + return $return; } @@ -309,14 +309,14 @@ function groups_safe_acl ($id_user, $id_groups, $access) { elseif (!is_array ($id_groups)) { return array (); } - + foreach ($id_groups as $group) { //Check ACL. If it doesn't match, remove the group if (!check_acl ($id_user, $group, $access)) { unset ($id_groups[$group]); } } - + return $id_groups; } @@ -343,9 +343,9 @@ function groups_is_all_group($idGroups) { $arrayGroups = array($idGroups); else $arrayGroups = $idGroups; - + $groupsDB = db_get_all_rows_in_table ('tgrupo'); - + $returnVar = true; foreach ($groupsDB as $group) { if (!in_array($group['id_grupo'], $arrayGroups)) { @@ -372,7 +372,7 @@ function groups_get_icon ($id_group) { $icon = (string) db_get_value ('icon', 'tgrupo', 'id_grupo', (int) $id_group); if ($icon == '') { - $icon = 'without_group'; + $icon = 'without_group'; } return $icon; @@ -388,14 +388,14 @@ function groups_get_icon ($id_group) { */ function groups_get_all($groupWithAgents = false) { global $config; - + $sql = 'SELECT id_grupo, nombre FROM tgrupo'; - + global $config; - + if ($groupWithAgents) $sql .= ' WHERE id_grupo IN (SELECT id_grupo FROM tagente GROUP BY id_grupo)'; - + switch ($config['dbtype']) { case "mysql": case "postgresql": @@ -405,9 +405,9 @@ function groups_get_all($groupWithAgents = false) { $sql .= ' ORDER BY dbms_lob.substr(nombre,4000,1) DESC'; break; } - + $rows = db_get_all_rows_sql ($sql); - + if($rows === false) { $rows = array(); } @@ -417,7 +417,7 @@ function groups_get_all($groupWithAgents = false) { if (check_acl ($config['id_user'], $row["id_grupo"], "AR")) $return[$row['id_grupo']] = $row['nombre']; } - + return $return; } @@ -785,6 +785,21 @@ function groups_get_group_row_data($id_group, $group_all, $group, &$printed_grou return $rows; } +function groups_get_groups_with_agent($id_user = false, $privilege = "AR", $returnAllGroup = true, $returnAllColumns = false, $id_groups = null, $keys_field = 'id_grupo') { + $groups = users_get_groups($id_user, $privilege, $returnAllGroup, $returnAllColumns, $id_groups, $keys_field); + + $return = array(); + foreach ($groups as $group) { + $data = reporting_get_group_stats($group['id_grupo']); + + if ($data["total_agents"] != 0) { + $return[] = $group; + } + } + + return $return; +} + /** * Print a row in the groups view (Recursive function) * @@ -797,6 +812,9 @@ function groups_get_group_row_data($id_group, $group_all, $group, &$printed_grou function groups_get_group_row($id_group, $group_all, $group, &$printed_groups) { global $config; + if ($id_group < 0) + return; + if (isset($printed_groups[$id_group])) { return; } @@ -804,9 +822,6 @@ function groups_get_group_row($id_group, $group_all, $group, &$printed_groups) { // Store printed group to not print it again $printed_groups[$id_group] = 1; - if ($id_group < 0) - return; - // Get stats for this group $data = reporting_get_group_stats($id_group); @@ -833,6 +848,8 @@ function groups_get_group_row($id_group, $group_all, $group, &$printed_groups) { $group_class = 'group_view_normal'; } + ob_start(); + echo "<tr style='height: 35px;'>"; // Group name @@ -863,11 +880,13 @@ function groups_get_group_row($id_group, $group_all, $group, &$printed_groups) { $data["total_agents"]; if ($id_group != 0) { - $data["total_agents"] = db_get_sql ("SELECT COUNT(id_agente) FROM tagente + $data["total_agents"] = db_get_sql ("SELECT COUNT(id_agente) + FROM tagente WHERE id_grupo = $id_group AND disabled = 0"); } else { - $data["total_agents"] = db_get_sql ("SELECT COUNT(id_agente) FROM tagente + $data["total_agents"] = db_get_sql ("SELECT COUNT(id_agente) + FROM tagente WHERE disabled = 0"); } @@ -913,8 +932,8 @@ function groups_get_group_row($id_group, $group_all, $group, &$printed_groups) { else { echo "<td class='$group_class'></td>"; } - - + + // Monitors OK echo "<td class='group_view_data_ok $group_class opacity_cell' style='font-weight: bold; font-size: 18px; text-align: center;'>"; if ($data["monitor_ok"] > 0) { @@ -967,10 +986,22 @@ function groups_get_group_row($id_group, $group_all, $group, &$printed_groups) { echo "</tr>"; + $row[$id_group] = ob_get_clean(); + + foreach($group['childs'] as $child) { - groups_get_group_row($child, $group_all, $group_all[$child], $printed_groups); + if (array_key_exists($child, $group_all)) { + $row_child = groups_get_group_row($child, $group_all, $group_all[$child], $printed_groups); + + if (!is_array_empty($row_child)) { + $row = $row + $row_child; + } + } } + + return $row; } + /** * Gets a group by id_group * diff --git a/pandora_console/operation/agentes/group_view.php b/pandora_console/operation/agentes/group_view.php index 1c48aa73fb..2e86b0c173 100644 --- a/pandora_console/operation/agentes/group_view.php +++ b/pandora_console/operation/agentes/group_view.php @@ -85,28 +85,44 @@ $counter = 1; $agents = agents_get_group_agents(array_keys($groups)); +$offset = (int)get_parameter('offset', 0); + if (count($agents) > 0) { + $groups_get_groups_with_agent = groups_get_groups_with_agent($config['id_user'], "AR", true, true); + ui_pagination(count($groups_get_groups_with_agent)); + echo '<table cellpadding="0" cellspacing="0" style="margin-top:10px;" class="groupsview" border="0" width="98%">'; echo "<tr>"; - echo "<th width='25%' class='first opacity_cell'>".__("Group")."</th>"; + echo "<th width='25%' class='first opacity_cell'>" . __("Group") . "</th>"; echo "<th style='min-width:26px;'></th>"; - echo "<th width='10%' class='opacity_cell'>".__("Agents")."</th>"; - echo "<th width='10%'>".__("Agent unknown")."</th>"; - echo "<th width='10%' class='opacity_cell'>".__("Unknown")."</th>"; - echo "<th width='10%'>".__("Not Init")."</th>"; - echo "<th width='10%' class='opacity_cell'>".__("Normal")."</th>"; - echo "<th width='10%'>".__("Warning")."</th>"; - echo "<th width='10%' class='opacity_cell'>".__("Critical")."</th>"; - echo "<th width='10%' class='last' style='min-width: 100px'>".__("Alert fired")."</th>"; + echo "<th width='10%' class='opacity_cell'>" . __("Agents") . "</th>"; + echo "<th width='10%'>" . __("Agent unknown") . "</th>"; + echo "<th width='10%' class='opacity_cell'>" . __("Unknown") . "</th>"; + echo "<th width='10%'>" . __("Not Init") . "</th>"; + echo "<th width='10%' class='opacity_cell'>" . __("Normal") . "</th>"; + echo "<th width='10%'>" . __("Warning") . "</th>"; + echo "<th width='10%' class='opacity_cell'>" . __("Critical") . "</th>"; + echo "<th width='10%' class='last' style='min-width: 100px'>" . __("Alert fired") . "</th>"; $printed_groups = array(); // For each valid group for this user, take data from agent and modules + $table_rows = array(); foreach ($groups as $id_group => $group) { - groups_get_group_row($id_group, $groups, $group, $printed_groups); + $rows = groups_get_group_row($id_group, $groups, $group, $printed_groups); + if (!is_array_empty($rows)) { + $table_rows += $rows; + } + } + + $table_rows = array_slice($table_rows, $offset, $config['block_size']); + foreach($table_rows as $row) { + echo $row; } echo "</table>"; + + ui_pagination(count($groups_get_groups_with_agent)); } else { echo "<div class='nf'>" . __('There are no defined agents') .