Visual Console Refactor: added the ability to connect to the metaconsole's node to a pair of models

Former-commit-id: b798747314a3ce92a2428114cda19ffa6063e3cf
This commit is contained in:
Alejandro Gallardo Escobar 2019-04-04 19:26:10 +02:00
parent 0f8c275ed1
commit 4a3eaca1cd
2 changed files with 57 additions and 2 deletions

View File

@ -176,15 +176,33 @@ final class SimpleValue extends Item
global $config;
include_once $config['homedir'].'/include/functions_graph.php';
// Get the linked agent and module Ids.
// Get the linked module Id.
$linkedModule = static::extractLinkedModule($data);
$moduleId = static::parseIntOr($linkedModule['moduleId'], null);
$metaconsoleId = static::parseIntOr(
$linkedModule['metaconsoleId'],
null
);
if ($moduleId === null) {
throw new \InvalidArgumentException('missing module Id');
}
// TODO: Connect to a metaconsole node?
// Maybe connect to node.
$nodeConnected = false;
if (\is_metaconsole() === true && $metaconsoleId !== null) {
$nodeConnected = \metaconsole_connect(
null,
$metaconsoleId
) === NOERR;
if ($nodeConnected === false) {
throw new \InvalidArgumentException(
'error connecting to the node'
);
}
}
// Get the formatted value.
$value = \visual_map_get_simple_value(
$data['type'],
@ -192,6 +210,11 @@ final class SimpleValue extends Item
static::extractPeriod($data)
);
// Restore connection.
if ($nodeConnected === true) {
\metaconsole_restore_db();
}
// Some modules are image based. Extract the base64 image if needed.
$matches = [];
if (\preg_match('/src=\"(data:image.*)"/', $value, $matches) === 1) {

View File

@ -147,9 +147,41 @@ final class StaticGraph extends Item
global $config;
include_once $config['homedir'].'/include/functions_visual_map.php';
// Get the linked module Id.
$linkedModule = static::extractLinkedModule($data);
$moduleId = static::parseIntOr($linkedModule['moduleId'], null);
$metaconsoleId = static::parseIntOr(
$linkedModule['metaconsoleId'],
null
);
if ($moduleId === null) {
throw new \InvalidArgumentException('missing module Id');
}
// Maybe connect to node.
$nodeConnected = false;
if (\is_metaconsole() === true && $metaconsoleId !== null) {
$nodeConnected = \metaconsole_connect(
null,
$metaconsoleId
) === NOERR;
if ($nodeConnected === false) {
throw new \InvalidArgumentException(
'error connecting to the node'
);
}
}
// Get the img src.
$data['statusImageSrc'] = \visual_map_get_image_status_element($data);
// Restore connection.
if ($nodeConnected === true) {
\metaconsole_restore_db();
}
return $data;
}