diff --git a/pandora_console/include/lib/Dashboard/Widget.php b/pandora_console/include/lib/Dashboard/Widget.php index 245c9f0481..b9e9971507 100644 --- a/pandora_console/include/lib/Dashboard/Widget.php +++ b/pandora_console/include/lib/Dashboard/Widget.php @@ -424,6 +424,7 @@ class Widget case 'ModulesByStatus': case 'AvgSumMaxMinModule': case 'BasicChart': + case 'AgentHive': $className .= '\\'.$name; break; diff --git a/pandora_console/include/lib/Dashboard/Widgets/AgentHive.php b/pandora_console/include/lib/Dashboard/Widgets/AgentHive.php new file mode 100644 index 0000000000..7e734ce24b --- /dev/null +++ b/pandora_console/include/lib/Dashboard/Widgets/AgentHive.php @@ -0,0 +1,514 @@ +width = $width; + + // Height. + $this->height = $height; + + // Grid Width. + $this->gridWidth = $gridWidth; + + // Cell Id. + $this->cellId = $cellId; + + // Options. + $this->values = $this->decoders($this->getOptionsWidget()); + + // Page. + $this->page = basename(__FILE__); + + // ClassName. + $class = new \ReflectionClass($this); + $this->className = $class->getShortName(); + + // Title. + $this->title = __('Agent hive'); + + // Name. + if (empty($this->name) === true) { + $this->name = 'AgentHive'; + } + + // This forces at least a first configuration. + $this->configurationRequired = false; + if (empty($this->values['groups']) === true) { + $this->configurationRequired = true; + } + } + + + /** + * Decoders hack for retrocompability. + * + * @param array $decoder Values. + * + * @return array Returns the values ​​with the correct key. + */ + public function decoders(array $decoder): array + { + $values = []; + // Retrieve global - common inputs. + $values = parent::decoders($decoder); + + if (isset($decoder['groups']) === true) { + $values['groups'] = $decoder['groups']; + } + + return $values; + } + + + /** + * Generates inputs for form (specific). + * + * @return array Of inputs. + * + * @throws Exception On error. + */ + public function getFormInputs(): array + { + $values = $this->values; + + // Retrieve global - common inputs. + $inputs = parent::getFormInputs(); + + // Filters. + $inputs[] = [ + 'label' => __('Groups'), + 'id' => 'li_groups', + 'arguments' => [ + 'type' => 'select_groups', + 'name' => 'groups[]', + 'returnAllGroup' => false, + 'privilege' => 'AR', + 'selected' => explode(',', $values['groups'][0]), + 'return' => true, + 'multiple' => true, + 'required' => true, + ], + ]; + + return $inputs; + } + + + /** + * Get Post for widget. + * + * @return array + */ + public function getPost(): array + { + // Retrieve global - common inputs. + $values = parent::getPost(); + + $values['groups'] = \get_parameter('groups', 0); + + return $values; + } + + + /** + * Draw widget. + * + * @return string; + */ + public function load() + { + global $config; + + $groups = $this->values['groups']; + $groups = explode(',', $groups[0]); + + $user_groups = array_keys( + users_get_groups( + false, + 'AR', + false, + false, + $groups + ) + ); + + foreach ($groups as $key => $group) { + if (in_array($group, $user_groups) === false) { + unset($groups[$key]); + } + } + + $table = 'tagente'; + if (is_metaconsole()) { + $table = 'tmetaconsole_agent'; + } + + $sql = sprintf( + 'SELECT * FROM %s WHERE id_grupo IN('.implode(',', $groups).')', + $table + ); + $all_agents = db_get_all_rows_sql($sql); + + $output = ''; + $output .= '
'; + foreach ($all_agents as $agent) { + $output .= $this->drawSquare($agent); + } + + $output .= '
'; + + $output .= ''; + + return $output; + } + + + /** + * Draw square agent. + * + * @param array $data Info agent. + * + * @return string Output. + */ + private function drawSquare(array $data): string + { + global $config; + + $id = (is_metaconsole() === true) + ? $data['id_tagente'] + : $data['id_agente']; + + $status = agents_get_status_from_counts($data); + switch ($status) { + case 1: + case 4: + case 100: + // Critical (BAD or ALERT). + $color = '#e63c52'; + break; + + case 0: + case 300: + // Normal (OK). + $color = '#82b92e'; + break; + + case 2: + case 200: + // Warning. + $color = '#f3b200'; + break; + + case 5: + // Not init. + $color = '#4a83f3'; + break; + + default: + // Default is Grey (Other). + $color = '#b2b2b2'; + break; + } + + $style_contact = 'flex-grow: 9; font-size: 8pt; display: flex; + justify-content: start;align-items: start; color: #9FA5B1; font-weight: 600;'; + // Last contact. + $lastContactDate = ui_print_timestamp( + $data['ultimo_contacto'], + true, + ['style' => $style_contact] + ); + + // Url. + $console_url = ui_get_full_url('/'); + if (is_metaconsole()) { + $server = metaconsole_get_servers($data['id_tmetaconsole_setup']); + $console_url = $server['server_url'].'/'; + } + + $url_view = $console_url.'index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente='.$id; + $url_manage = $console_url.'index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&id_agente='.$id; + + $output = '
'; + $output .= ''; + $output .= '
'; + $output .= '
'; + // Last contact and img. + $output .= ''; + + // OS and alias. + $output .= '
'; + $output .= ui_print_os_icon( + $data['id_os'], + false, + true, + true, + false, + false, + false, + ['style' => 'margin-right: 5px;'] + ); + $output .= ui_print_truncate_text( + ucfirst(io_safe_output($data['alias'])), + 12, + false, + true, + true, + '…', + 'font-size: 11pt;color: #14524f; + font-weight: 600;text-align: left', + ); + + $output .= '
'; + + // OS description. + $output .= html_print_div( + [ + 'content' => (empty($data['os_version']) === true) + ? get_os_name((int) $data['id_os']) + : $data['os_version'], + 'style' => 'font-size: 6pt; display: + flex;justify-content: start;align-items: start; + color: #9FA5B1; font-weight: 600;margin-bottom: 5px', + ], + true + ); + + // Description. + $output .= html_print_div( + [ + 'content' => ui_print_truncate_text( + io_safe_output($data['comentarios']), + 38, + false, + true, + true, + '…', + ), + 'style' => 'text-align: left;min-height: 42px; + font-size: 8pt;max-height: 42px; margin-bottom: 10px', + ], + true + ); + + // IP. + $output .= html_print_div( + [ + 'content' => $data['direccion'], + 'style' => 'font-size: 10pt;color: #14524f; + font-weight: 600; text-align: left', + ], + true + ); + $output .= '
'; + $output .= '
'; + + return $output; + + } + + + /** + * Get description. + * + * @return string. + */ + public static function getDescription() + { + return __('Agents hive'); + } + + + /** + * Get Name. + * + * @return string. + */ + public static function getName() + { + return 'AgentHive'; + } + + + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => (is_metaconsole() === true) ? 700 : 600, + 'height' => 610, + ]; + + return $size; + } + + +} diff --git a/pandora_console/include/styles/dashboards.css b/pandora_console/include/styles/dashboards.css index 908f673997..61c5235911 100644 --- a/pandora_console/include/styles/dashboards.css +++ b/pandora_console/include/styles/dashboards.css @@ -654,6 +654,59 @@ form.modal-dashboard font-style: italic; } +.widget-agent-hive-square { + flex: 1; + display: flex; + flex-direction: row; + justify-content: center; + align-items: start; + min-width: 150px; + max-width: 150px; + min-height: 150px; + max-height: 150px; + margin: 8px; + padding: 5px; + border: 1px solid #eceef2; + border-radius: 5px; + cursor: pointer; +} + +.widget-agent-hive-square-status { + width: 3%; + height: 100%; + margin-left: 4%; + margin-right: 3%; + border-radius: 15px; +} + +.widget-agent-hive-square-info { + width: 90%; + height: 100%; + display: flex; + flex-direction: column; +} + +.widget-agent-hive-square-info-header { + width: 100%; + display: flex; + flex-direction: row; + margin-bottom: 10px; +} + +.widget-agent-hive-square-info-body { + width: 100%; + display: flex; + flex-direction: row; +} + +.span-alias { + font-size: 13pt; + justify-content: start; + align-items: start; + color: #14524f; + font-weight: 600; +} + .container-histograms { min-width: 400px; }