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 = __('Color tabs modules'); // Name. if (empty($this->name) === true) { $this->name = 'single_graph'; } // This forces at least a first configuration. $this->configurationRequired = false; if (empty($this->values['moduleGroupedMeterGraphs']) === 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['agentsGroupedMeterGraphs'] = []; if (isset($decoder['agentsGroupedMeterGraphs']) === true) { if (isset($decoder['agentsGroupedMeterGraphs'][0]) === true && empty($decoder['agentsGroupedMeterGraphs']) === false ) { $values['agentsGroupedMeterGraphs'] = explode( ',', $decoder['agentsGroupedMeterGraphs'][0] ); } } if (isset($decoder['selectionGroupedMeterGraphs']) === true) { $values['selectionGroupedMeterGraphs'] = $decoder['selectionGroupedMeterGraphs']; } $values['moduleGroupedMeterGraphs'] = []; if (isset($decoder['moduleGroupedMeterGraphs']) === true) { if (empty($decoder['moduleGroupedMeterGraphs']) === false) { $values['moduleGroupedMeterGraphs'] = $decoder['moduleGroupedMeterGraphs']; } } if (isset($decoder['formatData']) === true) { $values['formatData'] = $decoder['formatData']; } if (isset($decoder['manualThresholds']) === true) { $values['manualThresholds'] = $decoder['manualThresholds']; } $values['label'] = 'module'; if (isset($decoder['label']) === true) { $values['label'] = $decoder['label']; } $values['min_value'] = null; if (isset($decoder['min_value']) === true) { $values['min_value'] = $decoder['min_value']; } $values['max_value'] = null; if (isset($decoder['max_value']) === true) { $values['max_value'] = $decoder['max_value']; } $values['min_critical'] = null; if (isset($decoder['min_critical']) === true) { $values['min_critical'] = $decoder['min_critical']; } $values['max_critical'] = null; if (isset($decoder['max_critical']) === true) { $values['max_critical'] = $decoder['max_critical']; } $values['min_warning'] = null; if (isset($decoder['min_warning']) === true) { $values['min_warning'] = $decoder['min_warning']; } $values['max_warning'] = null; if (isset($decoder['max_warning']) === true) { $values['max_warning'] = $decoder['max_warning']; } if (isset($decoder['fontColor']) === true) { $values['fontColor'] = $decoder['fontColor']; } 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(); $blocks = [ 'row1', 'row2', ]; $inputs['blocks'] = $blocks; foreach ($inputs as $kInput => $vInput) { $inputs['inputs']['row1'][] = $vInput; } if (empty($values['fontColor']) === true) { $values['fontColor'] = '#2c3e50'; } $inputs['inputs']['row1'][] = [ 'label' => __('Font color'), 'arguments' => [ 'wrapper' => 'div', 'name' => 'fontColor', 'type' => 'color', 'value' => $values['fontColor'], 'return' => true, ], ]; // Format Data. $inputs['inputs']['row1'][] = [ 'label' => __('Format Data'), 'arguments' => [ 'name' => 'formatData', 'id' => 'formatData', 'type' => 'switch', 'value' => $values['formatData'], ], ]; $inputs['inputs']['row1'][] = [ 'class' => 'dashboard-input-threshold', 'direct' => 1, 'block_content' => [ [ 'label' => __('Values'), 'arguments' => [], ], [ 'label' => __('Min'), 'arguments' => [ 'name' => 'min_value', 'id' => 'min_value', 'type' => 'number', 'value' => $values['min_value'], ], ], [ 'label' => __('Max'), 'arguments' => [ 'name' => 'max_value', 'id' => 'max_value', 'type' => 'number', 'value' => $values['max_value'], ], ], ], ]; // Format Data. $inputs['inputs']['row1'][] = [ 'label' => __('Manual thresholds'), 'arguments' => [ 'name' => 'manualThresholds', 'id' => 'manualThresholds', 'type' => 'switch', 'value' => $values['manualThresholds'], 'onchange' => 'showManualThresholds(this)', ], ]; $class_invisible = ''; if ((bool) $values['manualThresholds'] !== true) { $class_invisible = 'invisible_important'; } $inputs['inputs']['row1'][] = [ 'class' => 'dashboard-input-threshold dashboard-input-threshold-warning '.$class_invisible, 'direct' => 1, 'block_content' => [ [ 'label' => __('Warning threshold'), 'arguments' => [], ], [ 'label' => __('Min'), 'arguments' => [ 'name' => 'min_warning', 'id' => 'min_warning', 'type' => 'number', 'value' => $values['min_warning'], ], ], [ 'label' => __('Max'), 'arguments' => [ 'name' => 'max_warning', 'id' => 'max_warning', 'type' => 'number', 'value' => $values['max_warning'], ], ], ], ]; $inputs['inputs']['row1'][] = [ 'class' => 'dashboard-input-threshold dashboard-input-threshold-critical '.$class_invisible, 'direct' => 1, 'block_content' => [ [ 'label' => __('Critical threshold'), 'arguments' => [], ], [ 'label' => __('Min'), 'arguments' => [ 'name' => 'min_critical', 'id' => 'min_critical', 'type' => 'number', 'value' => $values['min_critical'], ], ], [ 'label' => __('Max'), 'arguments' => [ 'name' => 'max_critical', 'id' => 'max_critical', 'type' => 'number', 'value' => $values['max_critical'], ], ], ], ]; // Type Label. $fields = [ 'module' => __('Module'), 'agent' => __('Agent'), 'agent_module' => __('Agent / module'), ]; $inputs['inputs']['row2'][] = [ 'label' => __('Label'), 'arguments' => [ 'type' => 'select', 'fields' => $fields, 'name' => 'label', 'selected' => $values['label'], 'return' => true, ], ]; $inputs['inputs']['row2'][] = [ 'arguments' => [ 'type' => 'select_multiple_modules_filtered_select2', 'agent_values' => agents_get_agents_selected(0), 'agent_name' => 'agentsGroupedMeterGraphs[]', 'agent_ids' => $values['agentsGroupedMeterGraphs'], 'selectionModules' => $values['selectionGroupedMeterGraphs'], 'selectionModulesNameId' => 'selectionGroupedMeterGraphs', 'modules_ids' => $values['moduleGroupedMeterGraphs'], 'modules_name' => 'moduleGroupedMeterGraphs[]', 'notStringModules' => true, ], ]; return $inputs; } /** * Get Post for widget. * * @return array */ public function getPost():array { // Retrieve global - common inputs. $values = parent::getPost(); $values['agentsGroupedMeterGraphs'] = \get_parameter( 'agentsGroupedMeterGraphs', [] ); $values['selectionGroupedMeterGraphs'] = \get_parameter( 'selectionGroupedMeterGraphs', 0 ); $values['moduleGroupedMeterGraphs'] = \get_parameter( 'moduleGroupedMeterGraphs' ); $agColor = []; if (isset($values['agentsGroupedMeterGraphs'][0]) === true && empty($values['agentsGroupedMeterGraphs'][0]) === false ) { $agColor = explode(',', $values['agentsGroupedMeterGraphs'][0]); } $agModule = []; if (isset($values['moduleGroupedMeterGraphs'][0]) === true && empty($values['moduleGroupedMeterGraphs'][0]) === false ) { $agModule = explode(',', $values['moduleGroupedMeterGraphs'][0]); } $values['moduleGroupedMeterGraphs'] = get_same_modules_all( $agColor, $agModule ); $values['formatData'] = \get_parameter_switch('formatData', 0); $values['fontColor'] = \get_parameter('fontColor', '#2c3e50'); $values['label'] = \get_parameter('label', 'module'); $values['min_value'] = \get_parameter('min_value', null); $values['max_value'] = \get_parameter('max_value', null); $values['manualThresholds'] = \get_parameter_switch('manualThresholds', 0); $values['min_critical'] = \get_parameter('min_critical', null); $values['max_critical'] = \get_parameter('max_critical', null); $values['min_warning'] = \get_parameter('min_warning', null); $values['max_warning'] = \get_parameter('max_warning', null); return $values; } /** * Draw widget. * * @return string; */ public function load() { $this->size = parent::getSize(); $this->boxNumber = ceil(($this->size['width'] * 0.65) / self::RATIO_WITH_BOX); $output = ''; if (is_metaconsole() === true) { $modules_nodes = array_reduce( $this->values['moduleGroupedMeterGraphs'], 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['moduleGroupedMeterGraphs'] ); } if ($modules !== false && empty($modules) === false && is_array($modules) === true ) { if (count($modules) > self::MAX_MODULES) { $output .= '