fixes VC in MC

This commit is contained in:
fbsanchez 2021-02-02 18:40:55 +01:00
parent 000f8d4b66
commit 906ac7f13f
6 changed files with 150 additions and 95 deletions

View File

@ -281,8 +281,6 @@ function load_modal(settings) {
data: formdata, data: formdata,
dataType: settings.onsubmit.dataType, dataType: settings.onsubmit.dataType,
success: function(data) { success: function(data) {
console.log("successsssssssssssss");
console.log(data);
if (settings.ajax_callback != undefined) { if (settings.ajax_callback != undefined) {
if (settings.idMsgCallback != undefined) { if (settings.idMsgCallback != undefined) {
settings.ajax_callback(data, settings.idMsgCallback); settings.ajax_callback(data, settings.idMsgCallback);

View File

@ -9,6 +9,10 @@ if (!is_ajax()) {
require_once $config['homedir'].'/vendor/autoload.php'; require_once $config['homedir'].'/vendor/autoload.php';
// Require also some stuff from Pandora FMS.
enterprise_include('include/functions_metaconsole.php');
use Models\VisualConsole\Container as VisualConsole; use Models\VisualConsole\Container as VisualConsole;
use Models\VisualConsole\View as Viewer; use Models\VisualConsole\View as Viewer;
use Models\VisualConsole\Item as Item; use Models\VisualConsole\Item as Item;
@ -121,6 +125,7 @@ if ($getVisualConsole === true) {
} catch (Throwable $e) { } catch (Throwable $e) {
// Bad params. // Bad params.
http_response_code(400); http_response_code(400);
hd($e);
return; return;
} }

View File

@ -484,6 +484,7 @@ final class Container extends Model
$item = $class::fromDB($row); $item = $class::fromDB($row);
} catch (\Throwable $e) { } catch (\Throwable $e) {
// TODO: Log this? // TODO: Log this?
error_log(obhd($e));
} }
return $item; return $item;

View File

@ -491,6 +491,7 @@ final class NetworkLink extends Model
* @param array $data Input data. * @param array $data Input data.
* *
* @return string JSON encoded results to be stored in DB. * @return string JSON encoded results to be stored in DB.
* @throws \Exception If cannot connect to node if needed.
*/ */
private static function buildLabels(array $data) private static function buildLabels(array $data)
{ {
@ -513,120 +514,166 @@ final class NetworkLink extends Model
* *
*/ */
if (isset($links['start']) === true) { try {
$linkedStart = $links['start']['id']; if (isset($links['start']) === true) {
if (is_numeric($links['start']['id_agente_modulo']) === true $linkedStart = $links['start']['id'];
&& $links['start']['id_agente_modulo'] > 0 if (is_numeric($links['start']['id_agente_modulo']) === true
) { && $links['start']['id_agente_modulo'] > 0
$module = new \PandoraFMS\Module( ) {
(int) $links['start']['id_agente_modulo'] if (isset($links['start']['id_metaconsole']) === true
); && (bool) is_metaconsole() === true
) {
$cnn = \enterprise_hook(
'metaconsole_get_connection_by_id',
[ $links['start']['id_metaconsole'] ]
);
if ((bool) $module->isInterfaceModule() === true) { if (\enterprise_hook('metaconsole_connect', [$cnn]) !== NOERR) {
$interface_name = $module->getInterfaceName(); throw new \Exception(__('Failed to connect to node'));
$interface = array_shift( }
$module->agent()->getInterfaces( }
[$interface_name]
) $module = new \PandoraFMS\Module(
(int) $links['start']['id_agente_modulo']
); );
$outOctets = 0; if ((bool) $module->isInterfaceModule() === true) {
$inOctets = 0; $interface_name = $module->getInterfaceName();
$unitIn = ''; $interface = array_shift(
$unitOut = ''; $module->agent()->getInterfaces(
[$interface_name]
)
);
if (isset($interface['ifOutOctets']) === true) {
$outOctets = $interface['ifOutOctets']->lastValue();
$unitOut = $interface['ifOutOctets']->unit();
} else if (isset($interface['ifHCOutOctets']) === true) {
$outOctets = $interface['ifHCOutOctets']->lastValue();
$unitOut = $interface['ifHCOutOctets']->unit();
}
if (isset($interface['ifInOctets']) === true) {
$inOctets = $interface['ifInOctets']->lastValue();
$unitIn = $interface['ifInOctets']->unit();
} else if (isset($interface['ifHCInOctets']) === true) {
$inOctets = $interface['ifHCInOctets']->lastValue();
$unitIn = $interface['ifHCInOctets']->unit();
}
if (empty($outOctets) === true) {
$outOctets = 0; $outOctets = 0;
}
if (empty($inOctets) === true) {
$inOctets = 0; $inOctets = 0;
$unitIn = '';
$unitOut = '';
if (isset($interface['ifOutOctets']) === true) {
$outOctets = $interface['ifOutOctets']->lastValue();
$unitOut = $interface['ifOutOctets']->unit();
} else if (isset($interface['ifHCOutOctets']) === true) {
$outOctets = $interface['ifHCOutOctets']->lastValue();
$unitOut = $interface['ifHCOutOctets']->unit();
}
if (isset($interface['ifInOctets']) === true) {
$inOctets = $interface['ifInOctets']->lastValue();
$unitIn = $interface['ifInOctets']->unit();
} else if (isset($interface['ifHCInOctets']) === true) {
$inOctets = $interface['ifHCInOctets']->lastValue();
$unitIn = $interface['ifHCInOctets']->unit();
}
if (empty($outOctets) === true) {
$outOctets = 0;
}
if (empty($inOctets) === true) {
$inOctets = 0;
}
$outOctets = sprintf('%0.3f %s', $outOctets, $unitOut);
$inOctets = sprintf('%0.3f %s', $inOctets, $unitIn);
$labelStart = $interface_name;
$labelStart .= ' (in): '.$inOctets;
$labelStart .= '<br>'.$interface_name;
$labelStart .= ' (out): '.$outOctets;
} }
$outOctets = sprintf('%0.3f %s', $outOctets, $unitOut); if (isset($links['start']['id_metaconsole']) === true
$inOctets = sprintf('%0.3f %s', $inOctets, $unitIn); && (bool) is_metaconsole() === true
) {
$labelStart = $interface_name; \enterprise_hook('metaconsole_restore_db');
$labelStart .= ' (in): '.$inOctets; }
$labelStart .= '<br>'.$interface_name;
$labelStart .= ' (out): '.$outOctets;
} }
} }
} catch (\Exception $e) {
$labelStart = $e->getMessage();
} }
if (isset($links['end']) === true) { try {
$linkedEnd = $links['end']['id']; if (isset($links['end']) === true) {
if (is_numeric($links['end']['id_agente_modulo']) === true $linkedEnd = $links['end']['id'];
&& $links['end']['id_agente_modulo'] > 0 if (is_numeric($links['end']['id_agente_modulo']) === true
) { && $links['end']['id_agente_modulo'] > 0
$module = new \PandoraFMS\Module( ) {
(int) $links['end']['id_agente_modulo'] if (isset($links['end']['id_metaconsole']) === true
); && (bool) is_metaconsole() === true
) {
$cnn = \enterprise_hook(
'metaconsole_get_connection_by_id',
[$links['end']['id_metaconsole']]
);
if ((bool) $module->isInterfaceModule() === true) { if (\enterprise_hook('metaconsole_connect', [$cnn]) !== NOERR) {
$interface_name = $module->getInterfaceName(); throw new \Exception(__('Failed to connect to node'));
$interface = array_shift( }
$module->agent()->getInterfaces( }
[$interface_name]
) $module = new \PandoraFMS\Module(
(int) $links['end']['id_agente_modulo']
); );
$outOctets = 0; if ((bool) $module->isInterfaceModule() === true) {
$inOctets = 0; $interface_name = $module->getInterfaceName();
$unitIn = ''; $interface = array_shift(
$unitOut = ''; $module->agent()->getInterfaces(
[$interface_name]
)
);
if (isset($interface['ifOutOctets']) === true) {
$outOctets = $interface['ifOutOctets']->lastValue();
$unitOut = $interface['ifOutOctets']->unit();
} else if (isset($interface['ifHCOutOctets']) === true) {
$outOctets = $interface['ifHCOutOctets']->lastValue();
$unitOut = $interface['ifHCOutOctets']->unit();
}
if (isset($interface['ifInOctets']) === true) {
$inOctets = $interface['ifInOctets']->lastValue();
$unitIn = $interface['ifInOctets']->unit();
} else if (isset($interface['ifHCInOctets']) === true) {
$inOctets = $interface['ifHCInOctets']->lastValue();
$unitIn = $interface['ifHCInOctets']->unit();
}
if (empty($outOctets) === true) {
$outOctets = 0; $outOctets = 0;
}
if (empty($inOctets) === true) {
$inOctets = 0; $inOctets = 0;
$unitIn = '';
$unitOut = '';
if (isset($interface['ifOutOctets']) === true) {
$outOctets = $interface['ifOutOctets']->lastValue();
$unitOut = $interface['ifOutOctets']->unit();
} else if (isset($interface['ifHCOutOctets']) === true) {
$outOctets = $interface['ifHCOutOctets']->lastValue();
$unitOut = $interface['ifHCOutOctets']->unit();
}
if (isset($interface['ifInOctets']) === true) {
$inOctets = $interface['ifInOctets']->lastValue();
$unitIn = $interface['ifInOctets']->unit();
} else if (isset($interface['ifHCInOctets']) === true) {
$inOctets = $interface['ifHCInOctets']->lastValue();
$unitIn = $interface['ifHCInOctets']->unit();
}
if (empty($outOctets) === true) {
$outOctets = 0;
}
if (empty($inOctets) === true) {
$inOctets = 0;
}
$outOctets = sprintf('%0.3f %s', $outOctets, $unitOut);
$inOctets = sprintf('%0.3f %s', $inOctets, $unitIn);
$labelEnd = $interface_name;
$labelEnd .= ' (in): '.$inOctets;
$labelEnd .= '<br>'.$interface_name;
$labelEnd .= ' (out): '.$outOctets;
} }
$outOctets = sprintf('%0.3f %s', $outOctets, $unitOut); if (isset($links['end']['id_metaconsole']) === true
$inOctets = sprintf('%0.3f %s', $inOctets, $unitIn); && (bool) is_metaconsole() === true
) {
$labelEnd = $interface_name; \enterprise_hook('metaconsole_restore_db');
$labelEnd .= ' (in): '.$inOctets; }
$labelEnd .= '<br>'.$interface_name;
$labelEnd .= ' (out): '.$outOctets;
} }
} }
} catch (\Exception $e) {
$labelEnd = $e->getMessage();
} }
return json_encode( return json_encode(

File diff suppressed because one or more lines are too long

View File

@ -870,6 +870,9 @@ export default class VisualConsole {
/** /**
* Create line elements which connect the elements with their parents. * Create line elements which connect the elements with their parents.
*
* When itemId is being moved, overwrite position of the 'parent' or 'child'
* endpoints of the line, using X and Y values.
*/ */
public buildRelations(itemId?: number, x?: number, y?: number): void { public buildRelations(itemId?: number, x?: number, y?: number): void {
// Clear relations. // Clear relations.
@ -892,6 +895,7 @@ export default class VisualConsole {
this.addRelationLine(parent, child); this.addRelationLine(parent, child);
} }
} else { } else {
// No movements default behaviour.
this.addRelationLine(parent, child); this.addRelationLine(parent, child);
} }
} }