width = $width; // Height. $this->height = $height; // Grid Width. $this->gridWidth = $gridWidth; // Cell Id. $this->cellId = $cellId; // Options. $this->values = $this->decoders($this->getOptionsWidget()); // Positions. $this->position = $this->getPositionWidget(); // Page. $this->page = basename(__FILE__); // ClassName. $class = new \ReflectionClass($this); $this->className = $class->getShortName(); // Title. $this->title = __('Block histogram'); // Name. if (empty($this->name) === true) { $this->name = 'single_graph'; } // This forces at least a first configuration. $this->configurationRequired = false; if (empty($this->values['moduleBlockHistogram']) === true) { $this->configurationRequired = true; } $this->overflow_scrollbars = false; } /** * 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); $values['agentsBlockHistogram'] = []; if (isset($decoder['agentsBlockHistogram']) === true) { if (isset($decoder['agentsBlockHistogram'][0]) === true && empty($decoder['agentsBlockHistogram']) === false ) { $values['agentsBlockHistogram'] = explode( ',', $decoder['agentsBlockHistogram'][0] ); } } if (isset($decoder['selectionBlockHistogram']) === true) { $values['selectionBlockHistogram'] = $decoder['selectionBlockHistogram']; } $values['moduleBlockHistogram'] = []; if (isset($decoder['moduleBlockHistogram']) === true) { if (empty($decoder['moduleBlockHistogram']) === false) { $values['moduleBlockHistogram'] = $decoder['moduleBlockHistogram']; } } if (isset($decoder['period']) === true) { $values['period'] = $decoder['period']; } if (isset($decoder['fontColor']) === true) { $values['fontColor'] = $decoder['fontColor']; } $values['label'] = 'module'; if (isset($decoder['label']) === true) { $values['label'] = $decoder['label']; } 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(); // Default values. if (isset($values['period']) === false) { $values['period'] = SECONDS_1DAY; } if (empty($values['fontColor']) === true) { $values['fontColor'] = '#2c3e50'; } $inputs[] = [ 'label' => __('Font color'), 'arguments' => [ 'wrapper' => 'div', 'name' => 'fontColor', 'type' => 'color', 'value' => $values['fontColor'], 'return' => true, ], ]; // Type Label. $fields = [ 'module' => __('Module'), 'agent' => __('Agent'), 'agent_module' => __('Agent / module'), ]; $inputs[] = [ 'label' => __('Label'), 'arguments' => [ 'type' => 'select', 'fields' => $fields, 'name' => 'label', 'selected' => $values['label'], 'return' => true, ], ]; // Periodicity. $inputs[] = [ 'label' => __('Interval'), 'arguments' => [ 'name' => 'period', 'type' => 'interval', 'value' => $values['period'], 'nothing' => __('None'), 'nothing_value' => 0, 'style_icon' => 'flex-grow: 0', 'script' => 'check_period_warning(this, \''.__('Warning').'\', \''.__('Displaying items with extended historical data can have an impact on system performance. We do not recommend that you use intervals longer than 30 days, especially if you combine several of them in a report, dashboard or visual console.').'\')', 'script_input' => 'check_period_warning_manual(\'period\', \''.__('Warning').'\', \''.__('Displaying items with extended historical data can have an impact on system performance. We do not recommend that you use intervals longer than 30 days, especially if you combine several of them in a report, dashboard or visual console.').'\')', ], ]; $inputs[] = [ 'arguments' => [ 'type' => 'select_multiple_modules_filtered_select2', 'agent_values' => agents_get_agents_selected(0), 'agent_name' => 'agentsBlockHistogram[]', 'agent_ids' => $values['agentsBlockHistogram'], 'selectionModules' => $values['selectionBlockHistogram'], 'selectionModulesNameId' => 'selectionBlockHistogram', 'modules_ids' => $values['moduleBlockHistogram'], 'modules_name' => 'moduleBlockHistogram[]', ], ]; return $inputs; } /** * Get Post for widget. * * @return array */ public function getPost():array { // Retrieve global - common inputs. $values = parent::getPost(); $values['agentsBlockHistogram'] = \get_parameter( 'agentsBlockHistogram', [] ); $values['selectionBlockHistogram'] = \get_parameter( 'selectionBlockHistogram', 0 ); $values['moduleBlockHistogram'] = \get_parameter( 'moduleBlockHistogram' ); $agColor = []; if (isset($values['agentsBlockHistogram'][0]) === true && empty($values['agentsBlockHistogram'][0]) === false ) { $agColor = explode(',', $values['agentsBlockHistogram'][0]); } $agModule = []; if (isset($values['moduleBlockHistogram'][0]) === true && empty($values['moduleBlockHistogram'][0]) === false ) { $agModule = explode(',', $values['moduleBlockHistogram'][0]); } $values['moduleBlockHistogram'] = get_same_modules_all( $agColor, $agModule ); $values['period'] = \get_parameter('period', 0); $values['fontColor'] = \get_parameter('fontColor', '#2c3e50'); $values['label'] = \get_parameter('label', 'agent'); return $values; } /** * Draw widget. * * @return string; */ public function load() { global $config; $size = parent::getSize(); $output = ''; if (is_metaconsole() === true) { $modules_nodes = array_reduce( $this->values['moduleBlockHistogram'], function ($carry, $item) { $explode = explode('|', $item); $carry[$explode[0]][] = $explode[1]; return $carry; }, [] ); $modules = []; foreach ($modules_nodes as $n => $mod) { try { $node = new Node((int) $n); $node->connect(); $node_mods = $this->getInfoModules($mod); if (empty($node_mods) === false) { foreach ($node_mods as $value) { $value['id_node'] = $n; $value['server_name'] = $node->toArray()['server_name']; $modules[] = $value; } } $node->disconnect(); } catch (\Exception $e) { // Unexistent agent. $node->disconnect(); } } } else { $modules = $this->getInfoModules( $this->values['moduleBlockHistogram'] ); } if ($modules !== false && empty($modules) === false) { $total_modules = count($modules); $output .= '