2019-03-20 16:31:29 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Models\VisualConsole;
|
|
|
|
use Models\Model;
|
|
|
|
|
2019-03-25 16:37:36 +01:00
|
|
|
/**
|
|
|
|
* Model of a generic Visual Console Item.
|
|
|
|
*/
|
2019-03-20 16:31:29 +01:00
|
|
|
class Item extends Model
|
|
|
|
{
|
|
|
|
|
2019-03-25 16:37:36 +01:00
|
|
|
/**
|
2019-03-26 10:12:43 +01:00
|
|
|
* Used to decide wether to use information about the linked agent or not.
|
2019-03-25 16:37:36 +01:00
|
|
|
*
|
|
|
|
* @var boolean
|
|
|
|
*/
|
2019-03-26 10:12:43 +01:00
|
|
|
protected static $useLinkedAgent = false;
|
2019-03-20 16:31:29 +01:00
|
|
|
|
2019-03-21 17:47:10 +01:00
|
|
|
/**
|
2019-03-26 10:12:43 +01:00
|
|
|
* Used to decide wether to use information about the linked module or not.
|
2019-03-21 17:47:10 +01:00
|
|
|
*
|
2019-03-25 16:37:36 +01:00
|
|
|
* @var boolean
|
|
|
|
*/
|
2019-03-26 10:12:43 +01:00
|
|
|
protected static $useLinkedModule = false;
|
2019-03-25 16:37:36 +01:00
|
|
|
|
|
|
|
/**
|
2019-03-26 10:12:43 +01:00
|
|
|
* Used to decide wether to use information about
|
2019-03-25 16:37:36 +01:00
|
|
|
* the linked visual console or not.
|
|
|
|
*
|
|
|
|
* @var boolean
|
|
|
|
*/
|
2019-03-26 10:12:43 +01:00
|
|
|
protected static $useLinkedVisualConsole = false;
|
2019-03-25 16:37:36 +01:00
|
|
|
|
2019-04-03 12:07:48 +02:00
|
|
|
/**
|
|
|
|
* Used to decide wether to validate, extract and encode HTML output or not.
|
|
|
|
*
|
|
|
|
* @var boolean
|
|
|
|
*/
|
|
|
|
protected static $useHtmlOutput = false;
|
|
|
|
|
2019-03-25 16:37:36 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Validate the received data structure to ensure if we can extract the
|
|
|
|
* values required to build the model.
|
|
|
|
*
|
|
|
|
* @param array $data Input data.
|
2019-03-21 17:47:10 +01:00
|
|
|
*
|
|
|
|
* @return void
|
2019-03-25 16:37:36 +01:00
|
|
|
*
|
|
|
|
* @throws \InvalidArgumentException If any input value is considered
|
|
|
|
* invalid.
|
|
|
|
*
|
|
|
|
* @overrides Model::validateData.
|
2019-03-21 17:47:10 +01:00
|
|
|
*/
|
2019-03-20 16:31:29 +01:00
|
|
|
protected function validateData(array $data): void
|
|
|
|
{
|
|
|
|
if (isset($data['id']) === false
|
|
|
|
|| \is_numeric($data['id']) === false
|
|
|
|
) {
|
|
|
|
throw new \InvalidArgumentException(
|
|
|
|
'the Id property is required and should be integer'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($data['type']) === false
|
|
|
|
|| \is_numeric($data['type']) === false
|
|
|
|
) {
|
|
|
|
throw new \InvalidArgumentException(
|
|
|
|
'the Type property is required and should be integer'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($data['width']) === false
|
|
|
|
|| \is_numeric($data['width']) === false
|
|
|
|
|| $data['width'] < 0
|
|
|
|
) {
|
|
|
|
throw new \InvalidArgumentException(
|
2019-04-02 13:00:03 +02:00
|
|
|
'the width property is required and should be equal or greater than 0'
|
2019-03-20 16:31:29 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($data['height']) === false
|
|
|
|
|| \is_numeric($data['height']) === false
|
|
|
|
|| $data['height'] < 0
|
|
|
|
) {
|
|
|
|
throw new \InvalidArgumentException(
|
2019-04-02 13:00:03 +02:00
|
|
|
'the height property is required and should be equal or greater than 0'
|
2019-03-20 16:31:29 +01:00
|
|
|
);
|
|
|
|
}
|
2019-03-26 10:12:43 +01:00
|
|
|
|
|
|
|
// The item has a linked Visual Console.
|
|
|
|
if (static::$useLinkedVisualConsole === true) {
|
|
|
|
$linkedLayoutStatusType = static::notEmptyStringOr(
|
|
|
|
static::issetInArray(
|
|
|
|
$data,
|
|
|
|
[
|
|
|
|
'linkedLayoutStatusType',
|
|
|
|
'linked_layout_status_type',
|
|
|
|
]
|
|
|
|
),
|
|
|
|
null
|
|
|
|
);
|
|
|
|
|
|
|
|
// The types weight and service require extra data
|
|
|
|
// which should be validated.
|
|
|
|
if ($linkedLayoutStatusType === 'weight') {
|
|
|
|
$weight = static::parseIntOr(
|
|
|
|
static::issetInArray(
|
|
|
|
$data,
|
|
|
|
[
|
|
|
|
'linkedLayoutStatusTypeWeight',
|
|
|
|
'id_layout_linked_weight',
|
|
|
|
]
|
|
|
|
),
|
|
|
|
null
|
|
|
|
);
|
|
|
|
if ($weight === null || $weight < 0) {
|
|
|
|
throw new \InvalidArgumentException(
|
|
|
|
'the linked layout status weight property is required and should be greater than 0'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} else if ($linkedLayoutStatusType === 'service') {
|
|
|
|
$wThreshold = static::parseIntOr(
|
|
|
|
static::issetInArray(
|
|
|
|
$data,
|
|
|
|
[
|
|
|
|
'linkedLayoutStatusTypeWarningThreshold',
|
|
|
|
'linked_layout_status_as_service_warning',
|
|
|
|
]
|
|
|
|
),
|
|
|
|
null
|
|
|
|
);
|
|
|
|
if ($wThreshold === null || $wThreshold < 0) {
|
|
|
|
throw new \InvalidArgumentException(
|
|
|
|
'the linked layout status warning threshold property is required and should be greater than 0'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$cThreshold = static::parseIntOr(
|
|
|
|
static::issetInArray(
|
|
|
|
$data,
|
|
|
|
[
|
|
|
|
'linkedLayoutStatusTypeCriticalThreshold',
|
|
|
|
'linked_layout_status_as_service_critical',
|
|
|
|
]
|
|
|
|
),
|
|
|
|
null
|
|
|
|
);
|
|
|
|
if ($cThreshold === null || $cThreshold < 0) {
|
|
|
|
throw new \InvalidArgumentException(
|
|
|
|
'the linked layout status critical threshold property is required and should be greater than 0'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-04-03 12:07:48 +02:00
|
|
|
|
|
|
|
// The item uses HTML output.
|
|
|
|
if (static::$useHtmlOutput === true) {
|
2019-04-04 16:08:50 +02:00
|
|
|
if (static::notEmptyStringOr(static::issetInArray($data, ['encodedHtml']), null) === null
|
|
|
|
&& static::notEmptyStringOr(static::issetInArray($data, ['html']), null) === null
|
2019-04-03 12:07:48 +02:00
|
|
|
) {
|
|
|
|
throw new \InvalidArgumentException(
|
|
|
|
'the html property is required and should be a not empty string'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2019-03-20 16:31:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-21 17:47:10 +01:00
|
|
|
/**
|
2019-03-25 16:37:36 +01:00
|
|
|
* Returns a valid representation of the model.
|
|
|
|
*
|
|
|
|
* @param array $data Input data.
|
2019-03-21 17:47:10 +01:00
|
|
|
*
|
2019-03-25 16:37:36 +01:00
|
|
|
* @return array Data structure representing the model.
|
2019-03-21 17:47:10 +01:00
|
|
|
*
|
2019-03-25 16:37:36 +01:00
|
|
|
* @overrides Model::decode.
|
2019-03-21 17:47:10 +01:00
|
|
|
*/
|
2019-03-20 16:31:29 +01:00
|
|
|
protected function decode(array $data): array
|
|
|
|
{
|
2019-03-26 10:12:43 +01:00
|
|
|
$decodedData = [
|
2019-03-20 16:31:29 +01:00
|
|
|
'id' => (int) $data['id'],
|
|
|
|
'type' => (int) $data['type'],
|
2019-04-09 15:30:08 +02:00
|
|
|
'label' => static::extractLabel($data),
|
|
|
|
'labelPosition' => static::extractLabelPosition($data),
|
|
|
|
'isLinkEnabled' => static::extractIsLinkEnabled($data),
|
|
|
|
'isOnTop' => static::extractIsOnTop($data),
|
|
|
|
'parentId' => static::extractParentId($data),
|
|
|
|
'aclGroupId' => static::extractAclGroupId($data),
|
2019-03-20 16:31:29 +01:00
|
|
|
'width' => (int) $data['width'],
|
|
|
|
'height' => (int) $data['height'],
|
2019-04-09 15:30:08 +02:00
|
|
|
'x' => static::extractX($data),
|
|
|
|
'y' => static::extractY($data),
|
2019-03-20 16:31:29 +01:00
|
|
|
];
|
2019-03-26 10:12:43 +01:00
|
|
|
|
|
|
|
if (static::$useLinkedModule === true) {
|
|
|
|
$decodedData = array_merge(
|
|
|
|
$decodedData,
|
|
|
|
static::extractLinkedModule($data)
|
|
|
|
);
|
|
|
|
} else if (static::$useLinkedAgent === true) {
|
|
|
|
$decodedData = array_merge(
|
|
|
|
$decodedData,
|
|
|
|
static::extractLinkedAgent($data)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (static::$useLinkedVisualConsole === true) {
|
|
|
|
$decodedData = array_merge(
|
|
|
|
$decodedData,
|
|
|
|
static::extractLinkedVisualConsole($data)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-04-03 12:07:48 +02:00
|
|
|
if (static::$useHtmlOutput === true) {
|
|
|
|
$decodedData['encodedHtml'] = static::extractEncodedHtml($data);
|
|
|
|
}
|
|
|
|
|
2019-04-09 15:30:08 +02:00
|
|
|
// Conditionally add the item link.
|
|
|
|
if ($decodedData['isLinkEnabled'] === true) {
|
|
|
|
$decodedData['link'] = static::notEmptyStringOr(
|
|
|
|
static::issetInArray($data, ['link']),
|
|
|
|
null
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-03-26 10:12:43 +01:00
|
|
|
return $decodedData;
|
2019-03-20 16:31:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-21 17:47:10 +01:00
|
|
|
/**
|
2019-03-25 16:37:36 +01:00
|
|
|
* Extract x y axis value.
|
2019-03-21 17:47:10 +01:00
|
|
|
*
|
2019-03-25 16:37:36 +01:00
|
|
|
* @param array $data Unknown input data structure.
|
2019-03-21 17:47:10 +01:00
|
|
|
*
|
2019-03-25 16:37:36 +01:00
|
|
|
* @return integer Valid x axis position of the item.
|
2019-03-21 17:47:10 +01:00
|
|
|
*/
|
2019-04-09 15:30:08 +02:00
|
|
|
private static function extractX(array $data): int
|
2019-03-20 16:31:29 +01:00
|
|
|
{
|
2019-03-25 16:37:36 +01:00
|
|
|
return static::parseIntOr(
|
|
|
|
static::issetInArray($data, ['x', 'pos_x']),
|
|
|
|
0
|
|
|
|
);
|
2019-03-20 16:31:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-21 17:47:10 +01:00
|
|
|
/**
|
2019-03-25 16:37:36 +01:00
|
|
|
* Extract a y axis value.
|
2019-03-21 17:47:10 +01:00
|
|
|
*
|
2019-03-25 16:37:36 +01:00
|
|
|
* @param array $data Unknown input data structure.
|
2019-03-21 17:47:10 +01:00
|
|
|
*
|
2019-03-25 16:37:36 +01:00
|
|
|
* @return integer Valid y axis position of the item.
|
2019-03-21 17:47:10 +01:00
|
|
|
*/
|
2019-04-09 15:30:08 +02:00
|
|
|
private static function extractY(array $data): int
|
2019-03-20 16:31:29 +01:00
|
|
|
{
|
2019-03-25 16:37:36 +01:00
|
|
|
return static::parseIntOr(
|
|
|
|
static::issetInArray($data, ['y', 'pos_y']),
|
|
|
|
0
|
|
|
|
);
|
2019-03-20 16:31:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-21 17:47:10 +01:00
|
|
|
/**
|
2019-03-25 16:37:36 +01:00
|
|
|
* Extract a group Id (for ACL) value.
|
2019-03-21 17:47:10 +01:00
|
|
|
*
|
2019-03-25 16:37:36 +01:00
|
|
|
* @param array $data Unknown input data structure.
|
2019-03-21 17:47:10 +01:00
|
|
|
*
|
2019-03-25 16:37:36 +01:00
|
|
|
* @return integer Valid identifier of a group.
|
2019-03-21 17:47:10 +01:00
|
|
|
*/
|
2019-04-09 15:30:08 +02:00
|
|
|
private static function extractAclGroupId(array $data)
|
2019-03-20 16:31:29 +01:00
|
|
|
{
|
2019-03-25 16:37:36 +01:00
|
|
|
return static::parseIntOr(
|
|
|
|
static::issetInArray($data, ['id_group', 'aclGroupId']),
|
2019-03-20 16:31:29 +01:00
|
|
|
null
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-21 17:47:10 +01:00
|
|
|
/**
|
2019-03-25 16:37:36 +01:00
|
|
|
* Extract a parent Id value.
|
2019-03-21 17:47:10 +01:00
|
|
|
*
|
2019-03-25 16:37:36 +01:00
|
|
|
* @param array $data Unknown input data structure.
|
2019-03-21 17:47:10 +01:00
|
|
|
*
|
2019-03-25 16:37:36 +01:00
|
|
|
* @return integer Valid identifier of the item's parent.
|
2019-03-21 17:47:10 +01:00
|
|
|
*/
|
2019-04-09 15:30:08 +02:00
|
|
|
private static function extractParentId(array $data)
|
2019-03-20 16:31:29 +01:00
|
|
|
{
|
2019-03-25 16:37:36 +01:00
|
|
|
return static::parseIntOr(
|
|
|
|
static::issetInArray($data, ['parentId', 'parent_item']),
|
2019-03-20 16:31:29 +01:00
|
|
|
null
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-21 17:47:10 +01:00
|
|
|
/**
|
2019-03-25 16:37:36 +01:00
|
|
|
* Extract the "is on top" switch value.
|
2019-03-21 17:47:10 +01:00
|
|
|
*
|
2019-03-25 16:37:36 +01:00
|
|
|
* @param array $data Unknown input data structure.
|
2019-03-21 17:47:10 +01:00
|
|
|
*
|
2019-03-25 16:37:36 +01:00
|
|
|
* @return boolean If the item is on top or not.
|
2019-03-21 17:47:10 +01:00
|
|
|
*/
|
2019-04-09 15:30:08 +02:00
|
|
|
private static function extractIsOnTop(array $data): bool
|
2019-03-20 16:31:29 +01:00
|
|
|
{
|
2019-03-25 16:37:36 +01:00
|
|
|
return static::parseBool(
|
|
|
|
static::issetInArray($data, ['isOnTop', 'show_on_top'])
|
2019-03-20 16:31:29 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-21 17:47:10 +01:00
|
|
|
/**
|
2019-03-25 16:37:36 +01:00
|
|
|
* Extract the "is link enabled" switch value.
|
2019-03-21 17:47:10 +01:00
|
|
|
*
|
2019-03-25 16:37:36 +01:00
|
|
|
* @param array $data Unknown input data structure.
|
2019-03-21 17:47:10 +01:00
|
|
|
*
|
2019-03-25 16:37:36 +01:00
|
|
|
* @return boolean If the item has the link enabled or not.
|
2019-03-21 17:47:10 +01:00
|
|
|
*/
|
2019-04-09 15:30:08 +02:00
|
|
|
private static function extractIsLinkEnabled(array $data): bool
|
2019-03-20 16:31:29 +01:00
|
|
|
{
|
2019-03-25 16:37:36 +01:00
|
|
|
return static::parseBool(
|
|
|
|
static::issetInArray($data, ['isLinkEnabled', 'enable_link'])
|
2019-03-20 16:31:29 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-21 17:47:10 +01:00
|
|
|
/**
|
2019-03-25 16:37:36 +01:00
|
|
|
* Extract a label value.
|
2019-03-21 17:47:10 +01:00
|
|
|
*
|
2019-03-25 16:37:36 +01:00
|
|
|
* @param array $data Unknown input data structure.
|
2019-03-21 17:47:10 +01:00
|
|
|
*
|
2019-03-25 16:37:36 +01:00
|
|
|
* @return mixed String representing the label (not empty) or null.
|
2019-03-21 17:47:10 +01:00
|
|
|
*/
|
2019-04-09 15:30:08 +02:00
|
|
|
private static function extractLabel(array $data)
|
2019-03-20 16:31:29 +01:00
|
|
|
{
|
2019-03-26 09:48:50 +01:00
|
|
|
return static::notEmptyStringOr(
|
|
|
|
static::issetInArray($data, ['label']),
|
|
|
|
null
|
|
|
|
);
|
2019-03-20 16:31:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-21 17:47:10 +01:00
|
|
|
/**
|
2019-03-25 16:37:36 +01:00
|
|
|
* Extract a label position value.
|
2019-03-21 17:47:10 +01:00
|
|
|
*
|
2019-03-25 16:37:36 +01:00
|
|
|
* @param array $data Unknown input data structure.
|
2019-03-21 17:47:10 +01:00
|
|
|
*
|
2019-03-25 16:37:36 +01:00
|
|
|
* @return mixed One string of up|right|left|down. down by default.
|
2019-03-21 17:47:10 +01:00
|
|
|
*/
|
2019-04-09 15:30:08 +02:00
|
|
|
private static function extractLabelPosition(array $data): string
|
2019-03-20 16:31:29 +01:00
|
|
|
{
|
2019-03-25 16:37:36 +01:00
|
|
|
$labelPosition = static::notEmptyStringOr(
|
|
|
|
static::issetInArray($data, ['labelPosition', 'label_position']),
|
2019-03-20 16:31:29 +01:00
|
|
|
null
|
|
|
|
);
|
|
|
|
|
|
|
|
switch ($labelPosition) {
|
|
|
|
case 'up':
|
|
|
|
case 'right':
|
|
|
|
case 'left':
|
|
|
|
return $labelPosition;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return 'down';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-09 15:30:08 +02:00
|
|
|
/**
|
|
|
|
* Extract an agent Id value.
|
|
|
|
*
|
|
|
|
* @param array $data Unknown input data structure.
|
|
|
|
*
|
|
|
|
* @return integer Valid identifier of an agent.
|
|
|
|
*/
|
|
|
|
private static function extractAgentId(array $data)
|
|
|
|
{
|
|
|
|
return static::parseIntOr(
|
2019-04-09 16:06:59 +02:00
|
|
|
static::issetInArray($data, ['agentId', 'id_agent', 'id_agente']),
|
2019-04-09 15:30:08 +02:00
|
|
|
null
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Extract an module Id value.
|
|
|
|
*
|
|
|
|
* @param array $data Unknown input data structure.
|
|
|
|
*
|
|
|
|
* @return integer Valid identifier of a module.
|
|
|
|
*/
|
|
|
|
private static function extractModuleId(array $data)
|
|
|
|
{
|
|
|
|
return static::parseIntOr(
|
2019-04-09 16:06:59 +02:00
|
|
|
static::issetInArray(
|
|
|
|
$data,
|
|
|
|
[
|
|
|
|
'moduleId',
|
|
|
|
'id_agente_modulo',
|
|
|
|
'id_modulo',
|
|
|
|
]
|
|
|
|
),
|
2019-04-09 15:30:08 +02:00
|
|
|
null
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Extract an metaconsole node Id value.
|
|
|
|
*
|
|
|
|
* @param array $data Unknown input data structure.
|
|
|
|
*
|
|
|
|
* @return integer Valid identifier of a metaconsole node.
|
|
|
|
*/
|
|
|
|
private static function extractMetaconsoleId(array $data)
|
|
|
|
{
|
|
|
|
return static::parseIntOr(
|
|
|
|
static::issetInArray($data, ['metaconsoleId', 'id_metaconsole']),
|
|
|
|
null
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-25 16:37:36 +01:00
|
|
|
/**
|
|
|
|
* Extract the values of a linked agent.
|
|
|
|
*
|
|
|
|
* @param array $data Unknown input data structure.
|
|
|
|
*
|
2019-03-26 10:12:43 +01:00
|
|
|
* @return array Data structure of the linked agent info.
|
|
|
|
*
|
2019-03-25 16:37:36 +01:00
|
|
|
* @example [
|
2019-03-26 10:12:43 +01:00
|
|
|
* 'metaconsoleId' => 1,
|
|
|
|
* 'agentId' => 2,
|
|
|
|
* 'agentName' => 'Foo',
|
|
|
|
* ]
|
|
|
|
* @example [
|
|
|
|
* 'agentId' => 20,
|
|
|
|
* 'agentName' => 'Bar',
|
|
|
|
* ]
|
|
|
|
* @example [
|
|
|
|
* 'agentId' => null,
|
|
|
|
* 'agentName' => null,
|
2019-03-25 16:37:36 +01:00
|
|
|
* ]
|
|
|
|
*/
|
2019-04-03 10:27:22 +02:00
|
|
|
protected static function extractLinkedAgent(array $data): array
|
2019-03-25 16:37:36 +01:00
|
|
|
{
|
|
|
|
$agentData = [];
|
|
|
|
|
2019-04-17 15:58:07 +02:00
|
|
|
// We should add the metaconsole Id if we can.
|
2019-04-09 15:30:08 +02:00
|
|
|
$metaconsoleId = static::extractMetaconsoleId($data);
|
2019-04-17 15:58:07 +02:00
|
|
|
if ($metaconsoleId !== null && $metaconsoleId <= 0) {
|
|
|
|
$agentData['metaconsoleId'] = null;
|
2019-03-25 16:37:36 +01:00
|
|
|
}
|
|
|
|
|
2019-03-26 10:12:43 +01:00
|
|
|
// The agent Id should be a valid int or a null value.
|
2019-04-09 15:30:08 +02:00
|
|
|
$agentData['agentId'] = static::extractAgentId($data);
|
2019-03-25 16:37:36 +01:00
|
|
|
|
2019-03-26 10:12:43 +01:00
|
|
|
// The agent name should be a valid string or a null value.
|
2019-03-25 16:37:36 +01:00
|
|
|
$agentData['agentName'] = static::notEmptyStringOr(
|
|
|
|
static::issetInArray($data, ['agentName', 'agent_name']),
|
|
|
|
null
|
|
|
|
);
|
|
|
|
|
|
|
|
return $agentData;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Extract the values of a linked module.
|
|
|
|
*
|
|
|
|
* @param array $data Unknown input data structure.
|
|
|
|
*
|
2019-03-26 10:12:43 +01:00
|
|
|
* @return array Data structure of the linked module info.
|
|
|
|
*
|
2019-03-25 16:37:36 +01:00
|
|
|
* @example [
|
2019-03-26 10:12:43 +01:00
|
|
|
* 'metaconsoleId' => 1,
|
|
|
|
* 'agentId' => 2,
|
|
|
|
* 'agentName' => 'Foo',
|
|
|
|
* 'moduleId' => 1,
|
|
|
|
* 'moduleName' => 'cpu',
|
|
|
|
* ]
|
|
|
|
* @example [
|
|
|
|
* 'agentId' => 4,
|
|
|
|
* 'agentName' => 'Bar',
|
|
|
|
* 'moduleId' => null,
|
|
|
|
* 'moduleName' => null,
|
|
|
|
* ]
|
|
|
|
* @example [
|
|
|
|
* 'agentId' => null,
|
|
|
|
* 'agentName' => null,
|
|
|
|
* 'moduleId' => null,
|
|
|
|
* 'moduleName' => null,
|
2019-03-25 16:37:36 +01:00
|
|
|
* ]
|
|
|
|
*/
|
2019-04-03 10:27:22 +02:00
|
|
|
protected static function extractLinkedModule(array $data): array
|
2019-03-25 16:37:36 +01:00
|
|
|
{
|
|
|
|
// Initialize the data with the agent data and then expand it.
|
|
|
|
$moduleData = static::extractLinkedAgent($data);
|
|
|
|
|
2019-03-26 10:12:43 +01:00
|
|
|
// The module Id should be a valid int or a null value.
|
2019-04-09 15:30:08 +02:00
|
|
|
$moduleData['moduleId'] = static::extractModuleId($data);
|
2019-03-25 16:37:36 +01:00
|
|
|
|
2019-03-26 10:12:43 +01:00
|
|
|
// The module name should be a valid string or a null value.
|
2019-03-25 16:37:36 +01:00
|
|
|
$moduleData['moduleName'] = static::notEmptyStringOr(
|
|
|
|
static::issetInArray($data, ['moduleName', 'module_name']),
|
|
|
|
null
|
|
|
|
);
|
|
|
|
|
|
|
|
return $moduleData;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-25 12:32:06 +01:00
|
|
|
/**
|
2019-03-26 10:12:43 +01:00
|
|
|
* Extract the values of a linked visual console.
|
|
|
|
*
|
|
|
|
* @param array $data Unknown input data structure.
|
|
|
|
*
|
|
|
|
* @return array Data structure of the linked visual console info.
|
|
|
|
*
|
|
|
|
* @example [
|
|
|
|
* 'metaconsoleId' => 2,
|
|
|
|
* 'linkedLayoutId' => 12,
|
|
|
|
* 'linkedLayoutAgentId' => 48,
|
|
|
|
* 'linkedLayoutStatusType' => 'default',
|
|
|
|
* ]
|
|
|
|
* @example [
|
|
|
|
* 'linkedLayoutId' => 11,
|
|
|
|
* 'linkedLayoutAgentId' => null,
|
|
|
|
* 'linkedLayoutStatusType' => 'weight',
|
|
|
|
* 'linkedLayoutStatusTypeWeight' => 80,
|
|
|
|
* ]
|
|
|
|
* @example [
|
|
|
|
* 'metaconsoleId' => 2,
|
|
|
|
* 'linkedLayoutId' => 10,
|
|
|
|
* 'linkedLayoutAgentId' => 48,
|
|
|
|
* 'linkedLayoutStatusType' => 'service',
|
|
|
|
* 'linkedLayoutStatusTypeWarningThreshold' => 50,
|
|
|
|
* 'linkedLayoutStatusTypeCriticalThreshold' => 80,
|
|
|
|
* ]
|
|
|
|
*/
|
2019-04-09 15:30:08 +02:00
|
|
|
private static function extractLinkedVisualConsole(array $data): array
|
2019-03-26 10:12:43 +01:00
|
|
|
{
|
|
|
|
$vcData = [];
|
|
|
|
|
|
|
|
// We should add the metaconsole Id if we can. If not,
|
|
|
|
// it doesn't have to be into the structure.
|
2019-04-09 15:30:08 +02:00
|
|
|
$metaconsoleId = static::extractMetaconsoleId($data);
|
2019-03-26 10:12:43 +01:00
|
|
|
if ($metaconsoleId !== null) {
|
2019-04-09 15:30:08 +02:00
|
|
|
$vcData['metaconsoleId'] = $metaconsoleId;
|
2019-03-26 10:12:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// The linked vc Id should be a valid int or a null value.
|
|
|
|
$vcData['linkedLayoutId'] = static::parseIntOr(
|
|
|
|
static::issetInArray($data, ['linkedLayoutId', 'id_layout_linked']),
|
|
|
|
null
|
|
|
|
);
|
|
|
|
|
|
|
|
// The linked vc agent Id should be a valid int or a null value.
|
|
|
|
$vcData['linkedLayoutAgentId'] = static::parseIntOr(
|
|
|
|
static::issetInArray(
|
|
|
|
$data,
|
|
|
|
[
|
|
|
|
'linkedLayoutAgentId',
|
|
|
|
'linked_layout_node_id',
|
|
|
|
]
|
|
|
|
),
|
|
|
|
null
|
|
|
|
);
|
|
|
|
|
|
|
|
// The linked vc status type should be a enum value.
|
|
|
|
$linkedLayoutStatusType = static::notEmptyStringOr(
|
|
|
|
static::issetInArray(
|
|
|
|
$data,
|
|
|
|
[
|
|
|
|
'linkedLayoutStatusType',
|
|
|
|
'linked_layout_status_type',
|
|
|
|
]
|
|
|
|
),
|
|
|
|
null
|
|
|
|
);
|
|
|
|
|
|
|
|
// Extract data for the calculation of the linked visual console status.
|
|
|
|
switch ($linkedLayoutStatusType) {
|
|
|
|
case 'default':
|
|
|
|
default:
|
|
|
|
$vcData['linkedLayoutStatusType'] = 'default';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'weight':
|
|
|
|
$vcData['linkedLayoutStatusType'] = 'weight';
|
|
|
|
$vcData['linkedLayoutStatusTypeWeight'] = static::parseIntOr(
|
|
|
|
static::issetInArray(
|
|
|
|
$data,
|
|
|
|
[
|
|
|
|
'linkedLayoutStatusTypeWeight',
|
|
|
|
'id_layout_linked_weight',
|
|
|
|
]
|
|
|
|
),
|
|
|
|
0
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'service':
|
|
|
|
$vcData['linkedLayoutStatusType'] = 'service';
|
|
|
|
$vcData['linkedLayoutStatusTypeWarningThreshold'] = static::parseIntOr(
|
|
|
|
static::issetInArray(
|
|
|
|
$data,
|
|
|
|
[
|
|
|
|
'linkedLayoutStatusTypeWarningThreshold',
|
|
|
|
'linked_layout_status_as_service_warning',
|
|
|
|
]
|
|
|
|
),
|
|
|
|
0
|
|
|
|
);
|
|
|
|
$vcData['linkedLayoutStatusTypeCriticalThreshold'] = static::parseIntOr(
|
|
|
|
static::issetInArray(
|
|
|
|
$data,
|
|
|
|
[
|
|
|
|
'linkedLayoutStatusTypeCriticalThreshold',
|
|
|
|
'linked_layout_status_as_service_critical',
|
|
|
|
]
|
|
|
|
),
|
|
|
|
0
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $vcData;
|
|
|
|
}
|
2019-04-03 12:07:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Extract a encoded HTML representation of the item.
|
|
|
|
*
|
|
|
|
* @param array $data Unknown input data structure.
|
|
|
|
*
|
|
|
|
* @return string The HTML representation in base64 encoding.
|
|
|
|
*/
|
|
|
|
private static function extractEncodedHtml(array $data): string
|
|
|
|
{
|
|
|
|
if (isset($data['encodedHtml']) === true) {
|
|
|
|
return $data['encodedHtml'];
|
|
|
|
} else if (isset($data['html']) === true) {
|
|
|
|
return \base64_encode($data['html']);
|
|
|
|
}
|
|
|
|
|
|
|
|
return '';
|
|
|
|
}
|
2019-03-26 10:12:43 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fetch a vc item data structure from the database using a filter.
|
2019-03-25 12:32:06 +01:00
|
|
|
*
|
|
|
|
* @param array $filter Filter of the Visual Console Item.
|
|
|
|
*
|
|
|
|
* @return array The Visual Console Item data structure stored into the DB.
|
|
|
|
* @throws \Exception When the data cannot be retrieved from the DB.
|
|
|
|
*
|
|
|
|
* @override Model::fetchDataFromDB.
|
|
|
|
*/
|
|
|
|
protected static function fetchDataFromDB(array $filter): array
|
|
|
|
{
|
|
|
|
// Due to this DB call, this function cannot be unit tested without
|
|
|
|
// a proper mock.
|
|
|
|
$row = \db_get_row_filter('tlayout_data', $filter);
|
|
|
|
|
|
|
|
if ($row === false) {
|
|
|
|
throw new \Exception('error fetching the data from the DB');
|
|
|
|
}
|
|
|
|
|
2019-04-16 09:49:50 +02:00
|
|
|
// Load side libraries.
|
|
|
|
global $config;
|
|
|
|
include_once $config['homedir'].'/include/functions_io.php';
|
|
|
|
|
2019-04-17 12:49:42 +02:00
|
|
|
// Clean up to two levels of HTML entities.
|
|
|
|
$row = \io_safe_output(\io_safe_output($row));
|
2019-04-16 09:49:50 +02:00
|
|
|
|
2019-03-25 16:37:36 +01:00
|
|
|
/*
|
|
|
|
* Retrieve extra data.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// The linked module includes the agent data.
|
2019-03-26 10:12:43 +01:00
|
|
|
if (static::$useLinkedModule === true) {
|
2019-03-25 16:37:36 +01:00
|
|
|
$row = \array_merge($row, static::fetchModuleDataFromDB($row));
|
2019-03-26 10:12:43 +01:00
|
|
|
} else if (static::$useLinkedAgent === true) {
|
2019-03-25 16:37:36 +01:00
|
|
|
$row = \array_merge($row, static::fetchAgentDataFromDB($row));
|
|
|
|
}
|
|
|
|
|
2019-04-09 15:30:08 +02:00
|
|
|
// Build the item link if needed.
|
|
|
|
if (static::extractIsLinkEnabled($row) === true) {
|
|
|
|
$row['link'] = static::buildLink($row);
|
|
|
|
}
|
|
|
|
|
2019-03-25 12:32:06 +01:00
|
|
|
return $row;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-25 16:37:36 +01:00
|
|
|
/**
|
2019-03-26 10:12:43 +01:00
|
|
|
* Fetch a data structure of an agent from the database using the
|
2019-03-25 16:37:36 +01:00
|
|
|
* vs item's data.
|
|
|
|
*
|
|
|
|
* @param array $itemData Visual Console Item's data structure.
|
|
|
|
*
|
2019-03-26 10:12:43 +01:00
|
|
|
* @return array The agent data structure stored into the DB.
|
|
|
|
*
|
2019-03-25 16:37:36 +01:00
|
|
|
* @throws \InvalidArgumentException When the input agent Id is invalid.
|
|
|
|
* @throws \Exception When the data cannot be retrieved from the DB.
|
|
|
|
*/
|
|
|
|
protected static function fetchAgentDataFromDB(array $itemData): array
|
|
|
|
{
|
|
|
|
$agentData = [];
|
|
|
|
|
|
|
|
// We should add the metaconsole Id if we can.
|
2019-04-09 15:30:08 +02:00
|
|
|
$metaconsoleId = static::extractMetaconsoleId($itemData);
|
2019-03-25 16:37:36 +01:00
|
|
|
|
2019-04-09 15:30:08 +02:00
|
|
|
// Can't fetch an agent with an invalid Id.
|
|
|
|
$agentId = static::extractAgentId($itemData);
|
2019-03-25 16:37:36 +01:00
|
|
|
if ($agentId === null) {
|
2019-04-09 15:30:08 +02:00
|
|
|
throw new \InvalidArgumentException('invalid agent Id');
|
2019-03-25 16:37:36 +01:00
|
|
|
}
|
|
|
|
|
2019-04-17 15:39:55 +02:00
|
|
|
// Staticgraph don't need to have an agent.
|
|
|
|
if ($agentId === 0) {
|
|
|
|
return $agentData;
|
|
|
|
}
|
|
|
|
|
2019-04-09 15:30:08 +02:00
|
|
|
if (\is_metaconsole() && $metaconsoleId === null) {
|
|
|
|
throw new \InvalidArgumentException('missing metaconsole node Id');
|
|
|
|
}
|
|
|
|
|
|
|
|
$agentName = false;
|
|
|
|
|
|
|
|
if (\is_metaconsole()) {
|
|
|
|
$agentName = \db_get_value_filter(
|
|
|
|
'nombre',
|
|
|
|
'tmetaconsole_agent',
|
|
|
|
[
|
|
|
|
'id_agente' => $agentId,
|
|
|
|
'id_tmetaconsole_setup' => $metaconsoleId,
|
|
|
|
]
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$agentName = \db_get_value(
|
|
|
|
'nombre',
|
|
|
|
'tagente',
|
|
|
|
'id_agente',
|
|
|
|
$agentId
|
|
|
|
);
|
2019-03-25 16:37:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($agentName === false) {
|
2019-03-26 10:12:43 +01:00
|
|
|
throw new \Exception('error fetching the data from the DB');
|
2019-03-25 16:37:36 +01:00
|
|
|
}
|
|
|
|
|
2019-03-26 10:12:43 +01:00
|
|
|
// The agent name should be a valid string or a null value.
|
2019-03-25 16:37:36 +01:00
|
|
|
$agentData['agentName'] = $agentName;
|
|
|
|
|
|
|
|
return $agentData;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2019-03-26 10:12:43 +01:00
|
|
|
* Fetch a data structure of an module from the database using the
|
2019-03-25 16:37:36 +01:00
|
|
|
* vs item's data.
|
|
|
|
*
|
|
|
|
* @param array $itemData Visual Console Item's data structure.
|
|
|
|
*
|
2019-03-26 10:12:43 +01:00
|
|
|
* @return array The module data structure stored into the DB.
|
2019-03-25 16:37:36 +01:00
|
|
|
* @throws \InvalidArgumentException When the input module Id is invalid.
|
|
|
|
* @throws \Exception When the data cannot be retrieved from the DB.
|
|
|
|
*/
|
2019-04-09 15:30:08 +02:00
|
|
|
protected static function fetchModuleDataFromDB(array $itemData): array
|
|
|
|
{
|
2019-03-25 16:37:36 +01:00
|
|
|
// Initialize with the agent data.
|
|
|
|
$moduleData = static::fetchAgentDataFromDB($itemData);
|
|
|
|
|
|
|
|
// Can't fetch an module with a invalid Id.
|
2019-04-09 15:30:08 +02:00
|
|
|
$moduleId = static::extractModuleId($itemData);
|
2019-03-25 16:37:36 +01:00
|
|
|
if ($moduleId === null) {
|
|
|
|
throw new \InvalidArgumentException('invalid module Id');
|
|
|
|
}
|
|
|
|
|
2019-04-17 15:39:55 +02:00
|
|
|
// Staticgraph don't need to have a module.
|
|
|
|
if ($moduleId === 0) {
|
|
|
|
return $moduleData;
|
|
|
|
}
|
|
|
|
|
2019-04-09 15:30:08 +02:00
|
|
|
// We should add the metaconsole Id if we can.
|
|
|
|
$metaconsoleId = static::extractMetaconsoleId($itemData);
|
|
|
|
|
|
|
|
if (\is_metaconsole() && $metaconsoleId === null) {
|
|
|
|
throw new \InvalidArgumentException('missing metaconsole node Id');
|
|
|
|
}
|
|
|
|
|
|
|
|
$moduleName = false;
|
|
|
|
|
|
|
|
if (\is_metaconsole()) {
|
|
|
|
// Connect to node.
|
|
|
|
if (\metaconsole_connect(null, $metaconsoleId) !== NOERR) {
|
|
|
|
throw new \InvalidArgumentException(
|
|
|
|
'error connecting to the node'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$moduleName = \db_get_value_filter(
|
|
|
|
'nombre',
|
|
|
|
'tmetaconsole_agent',
|
|
|
|
[
|
|
|
|
'id_agente' => $agentId,
|
|
|
|
'id_tmetaconsole_setup' => $metaconsoleId,
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
// Restore connection.
|
|
|
|
\metaconsole_restore_db();
|
|
|
|
} else {
|
|
|
|
$moduleName = \db_get_value(
|
|
|
|
'nombre',
|
|
|
|
'tagente_modulo',
|
|
|
|
'id_agente_modulo',
|
|
|
|
$moduleId
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-03-25 16:37:36 +01:00
|
|
|
if ($moduleName === false) {
|
|
|
|
throw new \Exception('error fetching the data from the DB');
|
|
|
|
}
|
|
|
|
|
|
|
|
$moduleData['moduleName'] = $moduleName;
|
|
|
|
|
|
|
|
return $moduleData;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-09 15:30:08 +02:00
|
|
|
/**
|
|
|
|
* Generate a link to something related with the item.
|
|
|
|
*
|
|
|
|
* @param array $data Visual Console Item's data structure.
|
|
|
|
*
|
|
|
|
* @return mixed The link or a null value.
|
|
|
|
* @throws \Exception Not really. It's controlled.
|
|
|
|
*/
|
|
|
|
protected static function buildLink(array $data)
|
|
|
|
{
|
|
|
|
global $config;
|
|
|
|
|
|
|
|
$linkedVisualConsole = static::extractLinkedVisualConsole($data);
|
|
|
|
$linkedModule = static::extractLinkedModule($data);
|
|
|
|
$linkedAgent = static::extractLinkedAgent($data);
|
|
|
|
|
|
|
|
$baseUrl = $config['homeurl'].'index.php';
|
|
|
|
|
|
|
|
// TODO: There's a feature to get the link from the label.
|
|
|
|
if (static::$useLinkedVisualConsole === true
|
|
|
|
&& $linkedVisualConsole['linkedLayoutId'] !== null
|
|
|
|
&& $linkedVisualConsole['linkedLayoutId'] > 0
|
|
|
|
) {
|
|
|
|
// Linked Visual Console.
|
|
|
|
$vcId = $linkedVisualConsole['linkedLayoutId'];
|
|
|
|
// The layout can be from another node.
|
|
|
|
$metaconsoleId = $linkedVisualConsole['metaconsoleId'];
|
|
|
|
|
|
|
|
if (empty($metaconsoleId) === true && \is_metaconsole()) {
|
|
|
|
/*
|
|
|
|
* A Visual Console from this console.
|
|
|
|
* We are in a metaconsole.
|
|
|
|
*/
|
|
|
|
|
|
|
|
return $baseUrl.'?'.http_build_query(
|
|
|
|
[
|
|
|
|
'sec' => 'screen',
|
|
|
|
'sec2' => 'screens/screens',
|
|
|
|
'action' => 'visualmap',
|
|
|
|
'id_visualmap' => $vcId,
|
|
|
|
'pure' => (int) $config['pure'],
|
|
|
|
]
|
|
|
|
);
|
|
|
|
} else if (empty($metaconsoleId) === true && !\is_metaconsole()) {
|
|
|
|
/*
|
|
|
|
* A Visual Console from this console.
|
|
|
|
* We are in a regular console.
|
|
|
|
*/
|
|
|
|
|
|
|
|
return $baseUrl.'?'.http_build_query(
|
|
|
|
[
|
|
|
|
'sec' => 'network',
|
|
|
|
'sec2' => 'operation/visual_console/view',
|
|
|
|
'id' => $vcId,
|
|
|
|
'pure' => (int) $config['pure'],
|
|
|
|
]
|
|
|
|
);
|
2019-04-09 16:49:41 +02:00
|
|
|
} else if (\is_metaconsole() && can_user_access_node()) {
|
2019-04-09 15:30:08 +02:00
|
|
|
/*
|
|
|
|
* A Visual Console from a meta node.
|
|
|
|
* We are in a metaconsole.
|
|
|
|
*/
|
|
|
|
|
|
|
|
\enterprise_include_once(
|
|
|
|
'include/functions_metaconsole.php'
|
|
|
|
);
|
|
|
|
\enterprise_include_once(
|
|
|
|
'meta/include/functions_ui_meta.php'
|
|
|
|
);
|
|
|
|
try {
|
|
|
|
$node = \metaconsole_get_connection_by_id(
|
|
|
|
$metaconsoleId
|
|
|
|
);
|
|
|
|
return \ui_meta_get_node_url(
|
|
|
|
$node,
|
|
|
|
'network',
|
|
|
|
// TODO: Link to a public view.
|
|
|
|
'operation/visual_console/view',
|
|
|
|
[],
|
|
|
|
// No autologin from the public view.
|
|
|
|
!$config['public_view']
|
|
|
|
);
|
2019-04-09 16:35:58 +02:00
|
|
|
} catch (\Throwable $ignored) {
|
2019-04-09 15:30:08 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (static::$useLinkedModule === true
|
|
|
|
&& $linkedModule['moduleId'] !== null
|
|
|
|
&& $linkedModule['moduleId'] > 0
|
|
|
|
) {
|
|
|
|
// Module Id.
|
|
|
|
$moduleId = $linkedModule['moduleId'];
|
|
|
|
// The module can be from another node.
|
|
|
|
$metaconsoleId = $linkedModule['metaconsoleId'];
|
|
|
|
|
|
|
|
if (empty($metaconsoleId) === true) {
|
|
|
|
/*
|
|
|
|
* A module from this console.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Check if the module is from a service.
|
|
|
|
$serviceId = (int) \db_get_value_filter(
|
|
|
|
'custom_integer_1',
|
|
|
|
'tagente_modulo',
|
|
|
|
[
|
|
|
|
'id_agente_modulo' => $moduleId,
|
|
|
|
'prediction_module' => 1,
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
if (empty($serviceId) === false) {
|
|
|
|
// A service.
|
|
|
|
$queryParams = [
|
|
|
|
'sec' => 'services',
|
|
|
|
'sec2' => 'enterprise/operation/services/services',
|
|
|
|
'id_service' => $serviceId,
|
|
|
|
];
|
|
|
|
} else {
|
|
|
|
// A regular module.
|
|
|
|
$queryParams = [
|
|
|
|
'sec' => 'view',
|
|
|
|
'sec2' => 'operation/agentes/status_monitor',
|
|
|
|
'id_module' => $moduleId,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $baseUrl.'?'.http_build_query($queryParams);
|
2019-04-09 16:49:41 +02:00
|
|
|
} else if (\is_metaconsole() && can_user_access_node()) {
|
2019-04-09 15:30:08 +02:00
|
|
|
/*
|
|
|
|
* A module from a meta node.
|
|
|
|
* We are in a metaconsole.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// A Visual Console from a meta node.
|
|
|
|
\enterprise_include_once(
|
|
|
|
'include/functions_metaconsole.php'
|
|
|
|
);
|
|
|
|
\enterprise_include_once(
|
|
|
|
'meta/include/functions_ui_meta.php'
|
|
|
|
);
|
|
|
|
try {
|
|
|
|
$node = \metaconsole_get_connection_by_id(
|
|
|
|
$metaconsoleId
|
|
|
|
);
|
|
|
|
|
|
|
|
// Connect to node.
|
|
|
|
if (\metaconsole_connect($node) !== NOERR) {
|
|
|
|
// Will be catched below.
|
|
|
|
throw new \Exception(
|
|
|
|
'error connecting to the node'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the module is a service.
|
|
|
|
$serviceId = (int) \db_get_value_filter(
|
|
|
|
'custom_integer_1',
|
|
|
|
'tagente_modulo',
|
|
|
|
[
|
|
|
|
'id_agente_modulo' => $moduleId,
|
|
|
|
'prediction_module' => 1,
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
// Restore connection.
|
|
|
|
\metaconsole_restore_db();
|
|
|
|
|
|
|
|
if (empty($serviceId) === false) {
|
|
|
|
// A service.
|
|
|
|
return \ui_meta_get_node_url(
|
|
|
|
$node,
|
|
|
|
'services',
|
|
|
|
'enterprise/operation/services/services',
|
|
|
|
['id_service' => $serviceId],
|
|
|
|
// No autologin from the public view.
|
|
|
|
!$config['public_view']
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
// A regular module.
|
|
|
|
return \ui_meta_get_node_url(
|
|
|
|
$node,
|
|
|
|
'view',
|
|
|
|
'operation/agentes/status_monitor',
|
|
|
|
['id_module' => $moduleId],
|
|
|
|
// No autologin from the public view.
|
|
|
|
!$config['public_view']
|
|
|
|
);
|
|
|
|
}
|
2019-04-09 16:35:58 +02:00
|
|
|
} catch (\Throwable $ignored) {
|
2019-04-09 15:30:08 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (static::$useLinkedAgent === true
|
|
|
|
&& $linkedAgent['agentId'] !== null
|
|
|
|
&& $linkedAgent['agentId'] > 0
|
|
|
|
) {
|
|
|
|
// Linked agent.
|
|
|
|
// Agent Id.
|
|
|
|
$agentId = $linkedAgent['agentId'];
|
|
|
|
// The agent can be from another node.
|
|
|
|
$metaconsoleId = $linkedAgent['metaconsoleId'];
|
|
|
|
|
|
|
|
if (empty($metaconsoleId) === true) {
|
|
|
|
/*
|
|
|
|
* An agent from this console.
|
|
|
|
* We are in a regular console.
|
|
|
|
*/
|
|
|
|
|
|
|
|
return $baseUrl.'?'.http_build_query(
|
|
|
|
[
|
|
|
|
'sec' => 'estado',
|
|
|
|
'sec2' => 'operation/agentes/ver_agente',
|
|
|
|
'id_agente' => $agentId,
|
|
|
|
]
|
|
|
|
);
|
2019-04-09 16:49:41 +02:00
|
|
|
} else if (\is_metaconsole() && can_user_access_node()) {
|
2019-04-09 15:30:08 +02:00
|
|
|
/*
|
|
|
|
* An agent from a meta node.
|
|
|
|
* We are in a metaconsole.
|
|
|
|
*/
|
|
|
|
|
|
|
|
\enterprise_include_once(
|
|
|
|
'include/functions_metaconsole.php'
|
|
|
|
);
|
|
|
|
\enterprise_include_once(
|
|
|
|
'meta/include/functions_ui_meta.php'
|
|
|
|
);
|
|
|
|
try {
|
|
|
|
$node = \metaconsole_get_connection_by_id(
|
|
|
|
$metaconsoleId
|
|
|
|
);
|
|
|
|
return \ui_meta_get_node_url(
|
|
|
|
$node,
|
|
|
|
'estado',
|
|
|
|
'operation/agentes/ver_agente',
|
|
|
|
['id_agente' => $moduleId],
|
|
|
|
// No autologin from the public view.
|
|
|
|
!$config['public_view']
|
|
|
|
);
|
2019-04-09 16:35:58 +02:00
|
|
|
} catch (\Throwable $ignored) {
|
2019-04-09 15:30:08 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-20 16:31:29 +01:00
|
|
|
}
|