diff --git a/pandora_console/include/rest-api/models/VisualConsole/Item.php b/pandora_console/include/rest-api/models/VisualConsole/Item.php index b5ec513c31..c0c478c947 100644 --- a/pandora_console/include/rest-api/models/VisualConsole/Item.php +++ b/pandora_console/include/rest-api/models/VisualConsole/Item.php @@ -70,7 +70,7 @@ class Item extends Model || $data['width'] < 0 ) { throw new \InvalidArgumentException( - 'the width property is required and should be greater than 0' + 'the width property is required and should be equal or greater than 0' ); } @@ -79,7 +79,7 @@ class Item extends Model || $data['height'] < 0 ) { throw new \InvalidArgumentException( - 'the height property is required and should be greater than 0' + 'the height property is required and should be equal or greater than 0' ); } @@ -357,7 +357,7 @@ class Item extends Model * 'agentName' => null, * ] */ - private function extractLinkedAgent(array $data): array + protected function extractLinkedAgent(array $data): array { $agentData = []; @@ -420,7 +420,7 @@ class Item extends Model * 'moduleName' => null, * ] */ - private function extractLinkedModule(array $data): array + protected function extractLinkedModule(array $data): array { // Initialize the data with the agent data and then expand it. $moduleData = static::extractLinkedAgent($data); diff --git a/pandora_console/include/rest-api/models/VisualConsole/Items/EventsHistory.php b/pandora_console/include/rest-api/models/VisualConsole/Items/EventsHistory.php index bde91d979d..b38d359d9b 100644 --- a/pandora_console/include/rest-api/models/VisualConsole/Items/EventsHistory.php +++ b/pandora_console/include/rest-api/models/VisualConsole/Items/EventsHistory.php @@ -4,22 +4,13 @@ declare(strict_types=1); namespace Models\VisualConsole\Items; use Models\VisualConsole\Item; -use Models\Model; /** - * Model of a group item of the Visual Console. + * Model of a events history item of the Visual Console. */ final class EventsHistory extends Item { - /** - * Used to enable the fetching, validation and extraction of information - * about the linked visual console. - * - * @var boolean - */ - protected static $useLinkedVisualConsole = true; - /** * Used to enable the fetching, validation and extraction of information * about the linked module. @@ -28,6 +19,14 @@ final class EventsHistory extends Item */ protected static $useLinkedModule = true; + /** + * Used to enable the fetching, validation and extraction of information + * about the linked visual console. + * + * @var boolean + */ + protected static $useLinkedVisualConsole = true; + /** * Returns a valid representation of the model. @@ -43,45 +42,70 @@ final class EventsHistory extends Item $return = parent::decode($data); $return['type'] = AUTO_SLA_GRAPH; $return['maxTime'] = $this->extractMaxTime($data); - $return['data'] = $this->extractData($data); + $return['encodedHtml'] = $this->extractEncodedHtml($data); return $return; } /** - * Extract the value of maxTime and - * return a integer or null. + * Extract a graph period value. * * @param array $data Unknown input data structure. * - * @return mixed + * @return mixed The time in seconds of the graph period or null. */ private function extractMaxTime(array $data) { - $maxTime = Model::parseIntOr( - Model::issetInArray($data, ['maxTime', 'period']), + return static::parseIntOr( + static::issetInArray($data, ['maxTime', 'period']), null ); - return $maxTime; } /** - * Extract the value of data and - * return an array. + * Extract a encoded HTML representation of the item. * * @param array $data Unknown input data structure. * - * @return array + * @return string The HTML representation in base64 encoding. + * @throws \InvalidArgumentException When an agent Id cannot be found. */ - private function extractData(array $data): array + private function extractEncodedHtml(array $data): string { - $array = []; - if (isset($data['data']) && \is_array($data['data'])) { - $array = $data['data']; + if (isset($data['encodedHtml']) === true) { + return $data['encodedHtml']; + } else if (isset($data['html']) === true) { + return \base64_encode($data['html']); } - return $array; + // Load side libraries. + global $config; + include_once $config['homedir'].'/include/functions_graph.php'; + + // Get the linked agent and module Ids. + $linkedModule = $this->extractLinkedModule($data); + $agentId = static::parseIntOr($linkedModule['agentId'], null); + $moduleId = static::parseIntOr($linkedModule['moduleId'], null); + + if ($agentId === null) { + throw new \InvalidArgumentException('missing agent Id'); + } + + // Use the same HTML output as the old VC. + $html = '