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 .= '