diff --git a/pandora_console/include/lib/Dashboard/Widgets/agent_module.php b/pandora_console/include/lib/Dashboard/Widgets/agent_module.php index 84b3a08675..6bb1bf4e37 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/agent_module.php +++ b/pandora_console/include/lib/Dashboard/Widgets/agent_module.php @@ -27,6 +27,8 @@ */ namespace PandoraFMS\Dashboard; +use PandoraFMS\Agent; +use PandoraFMS\Module; /** * Agent module Widgets. @@ -324,7 +326,7 @@ class AgentModuleWidget extends Widget } foreach ($agents as $agent) { - if (!users_access_to_agent($agent['id_agente'])) { + if (users_access_to_agent($agent['id_agente']) === false) { continue; } @@ -343,8 +345,10 @@ class AgentModuleWidget extends Widget foreach ($modules_by_name as $module) { $row['modules'][$module['name']] = null; foreach ($module['id'] as $module_id) { - if (array_key_exists($module_id, $agent_modules)) { - $row['modules'][$module['name']] = modules_get_agentmodule_status($module_id); + if (array_key_exists($module_id, $agent_modules) === true) { + $row['modules'][$module['name']] = modules_get_agentmodule_status( + $module_id + ); break; } } @@ -361,12 +365,16 @@ class AgentModuleWidget extends Widget * Draw table Agent/Module. * * @param array $visualData Data for draw. + * @param array $allModules Data for th draw. * * @return string Html output. */ - private function generateViewAgentModule(array $visualData):string - { - $table_data = '
"; + if (in_array($module_name, $allModules) === true) { + $style = 'background-color: transparent;'; + $table_data .= " | "; $table_data .= ' | '; } else { continue; } } else { - $table_data .= ""; + $style = 'text-align: center;'; + $style .= ' background-color: transparent;'; + $table_data .= " | "; switch ($module) { case AGENT_STATUS_NORMAL: $table_data .= \ui_print_status_image( @@ -592,70 +590,49 @@ class AgentModuleWidget extends Widget return $output; } - if (isset($this->values['mAgents']) === true - && empty($this->values['mAgents']) === false - ) { - $sql = sprintf( - 'SELECT id_agente,nombre,alias - FROM tagente - WHERE id_agente IN (%s) - ORDER BY id_agente', - $this->values['mAgents'] - ); - $agents = db_get_all_rows_sql($sql); - if ($agents === false) { - $agents = []; + // Estract info all modules selected. + $target_modules = explode(',', $this->values['mModules']); + $all_modules = Module::search( + ['id_agente_modulo' => $target_modules] + ); + $reduceAllModules = array_reduce( + $all_modules, + function ($carry, $item) { + $carry[$item->name()] = null; + return $carry; } + ); - $modules = false; - if (isset($this->values['mModules']) === true - && empty($this->values['mModules']) === false - ) { - $sql = sprintf( - 'SELECT nombre - FROM tagente_modulo - WHERE id_agente_modulo IN (%s)', - $this->values['mModules'] + \ksort($reduceAllModules); + + $visualData = []; + // Estract info agents selected. + $target_agents = explode(',', $this->values['mAgents']); + foreach ($target_agents as $agent_id) { + try { + $agent = new Agent($agent_id); + $visualData[$agent_id]['agent_status'] = $agent->lastStatus(); + $visualData[$agent_id]['agent_name'] = $agent->name(); + $visualData[$agent_id]['agent_alias'] = $agent->alias(); + + $modules = $agent->searchModules( + ['id_agente_modulo' => $target_modules] ); - $arrayNames = db_get_all_rows_sql($sql); - $names = array_reduce( - $arrayNames, - function ($carry, $item) { - $carry[] = $item['nombre']; - return $carry; - } - ); - - $sql = sprintf( - 'SELECT id_agente_modulo,nombre - FROM tagente_modulo - WHERE id_agente IN (%s) - AND nombre IN ("%s") - AND delete_pending = 0 - ORDER BY nombre', - $this->values['mAgents'], - implode('","', $names) - ); - - $modules = index_array( - db_get_all_rows_sql($sql), - 'id_agente_modulo', - 'nombre' - ); + $visualData[$agent_id]['modules'] = $reduceAllModules; + foreach ($modules as $module) { + $visualData[$agent_id]['modules'][$module->name()] = $module->getStatus()->estado(); + } + } catch (Exception $e) { + echo 'Error: '.$e->getMessage(); } - - if ($modules === false) { - $modules = []; - } - } else { - $agents = []; - $modules = []; } - $visualData = $this->generateDataAgentModule($agents, $modules); - - $output = $this->generateViewAgentModule($visualData); + $allModules = array_keys($reduceAllModules); + $output = $this->generateViewAgentModule( + $visualData, + $allModules + ); return $output; } diff --git a/pandora_console/include/styles/dashboards.css b/pandora_console/include/styles/dashboards.css index bbbf993112..70c41dd643 100644 --- a/pandora_console/include/styles/dashboards.css +++ b/pandora_console/include/styles/dashboards.css @@ -407,6 +407,10 @@ table.group_modules_status_box tr td span a { text-align: center; } +table.widget_agent_module tbody tr td { + padding: 5px; +} + .container-center .widget-histogram-chart .flot-text .flot-x-axis div { white-space: nowrap; } |