Rewrote the ajax call 'get_agent_modules_json_for_multiple_agents' for to run with the agents cache in new metaconsole in 6 version.
This commit is contained in:
parent
33bd7be835
commit
3d46327f55
|
@ -37,7 +37,9 @@ $action = get_parameterBetweenListValues($action_name_parameter,
|
|||
array('new', 'save', 'edit', 'update', 'delete', 'multiple_delete'),
|
||||
'new');
|
||||
|
||||
$activeTab = get_parameterBetweenListValues('tab', array('data', 'list_elements', 'wizard', 'wizard_services', 'editor'), 'data');
|
||||
$activeTab = get_parameterBetweenListValues('tab',
|
||||
array('data', 'list_elements', 'wizard', 'wizard_services', 'editor'),
|
||||
'data');
|
||||
|
||||
// Visual console creation tab and actions
|
||||
if (empty($idVisualConsole)) {
|
||||
|
@ -348,8 +350,22 @@ switch ($activeTab) {
|
|||
// One item per agent
|
||||
if ($item_per_agent == 1) {
|
||||
$id_agents_result = array();
|
||||
foreach ($id_agents as $id_agent_key => $id_agent_id)
|
||||
$id_agents_result[] = $id_agent_id;
|
||||
foreach ($id_agents as $id_agent_key => $id_agent_id) {
|
||||
if (defined("METACONSOLE")) {
|
||||
$row = db_get_row_filter(
|
||||
'tmetaconsole_agent',
|
||||
array('id_tagente' => $id_agent_id));
|
||||
$id_server = $row['id_tmetaconsole_setup'];
|
||||
$id_agent_id = $row['id_tagente'];
|
||||
|
||||
$id_agents_result[] = array(
|
||||
'id_agent' => $id_agent_id,
|
||||
'id_server' => $id_server);
|
||||
}
|
||||
else {
|
||||
$id_agents_result[] = $id_agent_id;
|
||||
}
|
||||
}
|
||||
|
||||
$message .= visual_map_process_wizard_add_agents(
|
||||
$id_agents_result,
|
||||
|
@ -376,6 +392,8 @@ switch ($activeTab) {
|
|||
|
||||
}
|
||||
else {
|
||||
|
||||
|
||||
// One item per module
|
||||
if (empty($name_modules)) {
|
||||
$statusProcessInDB = array('flag' => true,
|
||||
|
@ -383,31 +401,54 @@ switch ($activeTab) {
|
|||
__('No modules selected'), '', true));
|
||||
}
|
||||
else {
|
||||
|
||||
|
||||
if (defined("METACONSOLE")) {
|
||||
$rows = db_get_all_rows_filter(
|
||||
'tmetaconsole_agent',
|
||||
array('id_tagente' => $id_agents));
|
||||
|
||||
$agents = array();
|
||||
foreach ($rows as $row) {
|
||||
$agents[$row['id_tmetaconsole_setup']][] =
|
||||
$row['id_tagente'];
|
||||
}
|
||||
}
|
||||
else {
|
||||
$agents[0] = $id_agents;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
foreach ($agents as $id_server => $id_agents) {
|
||||
|
||||
|
||||
|
||||
//Any module
|
||||
if ($name_modules[0] == '0') {
|
||||
$id_modules = array();
|
||||
|
||||
if ($id_server != 0) {
|
||||
foreach ($name_modules as $serial_data) {
|
||||
$modules_serial = explode(';', $serial_data);
|
||||
|
||||
foreach ($modules_serial as $data_serialized) {
|
||||
$data = explode('|', $data_serialized);
|
||||
$id_modules[] = $data[0];
|
||||
}
|
||||
if (metaconsole_connect(null, $id_server) != NOERR) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else {
|
||||
foreach ($id_agents as $id_agent) {
|
||||
$id_modulo = agents_get_modules($id_agent, array('id_agente_modulo'));
|
||||
if (empty($id_modulo)) $id_modulo = array();
|
||||
|
||||
foreach ($id_modulo as $id) {
|
||||
$id_modules[] = $id['id_agente_modulo'];
|
||||
}
|
||||
|
||||
foreach ($id_agents as $id_agent) {
|
||||
$id_modulo = agents_get_modules($id_agent, array('id_agente_modulo'));
|
||||
if (empty($id_modulo)) $id_modulo = array();
|
||||
|
||||
foreach ($id_modulo as $id) {
|
||||
$id_modules[] = $id['id_agente_modulo'];
|
||||
}
|
||||
}
|
||||
|
||||
if ($id_server != 0) {
|
||||
metaconsole_restore_db();
|
||||
}
|
||||
|
||||
|
||||
$message .= visual_map_process_wizard_add_modules(
|
||||
$id_modules,
|
||||
$image,
|
||||
|
@ -427,39 +468,45 @@ switch ($activeTab) {
|
|||
$id_server,
|
||||
$kind_relationship,
|
||||
$item_in_the_map);
|
||||
|
||||
|
||||
}
|
||||
else {
|
||||
$id_modules = array();
|
||||
|
||||
if ($id_server != 0) {
|
||||
foreach ($name_modules as $serial_data) {
|
||||
$modules_serial = explode(';', $serial_data);
|
||||
|
||||
foreach ($modules_serial as $data_serialized) {
|
||||
$data = explode('|', $data_serialized);
|
||||
$id_modules[] = $data[0];
|
||||
}
|
||||
if (metaconsole_connect(null, $id_server) != NOERR) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else {
|
||||
foreach ($name_modules as $mod) {
|
||||
foreach ($id_agents as $ag) {
|
||||
$id_module = agents_get_modules($ag,
|
||||
array('id_agente_modulo'),
|
||||
array('nombre' => $mod));
|
||||
|
||||
if (empty($id_module))
|
||||
continue;
|
||||
else {
|
||||
$id_module = reset($id_module);
|
||||
$id_module = $id_module['id_agente_modulo'];
|
||||
}
|
||||
|
||||
$id_modules[] = $id_module;
|
||||
|
||||
foreach ($name_modules as $mod) {
|
||||
|
||||
|
||||
|
||||
foreach ($id_agents as $ag) {
|
||||
|
||||
$id_module = agents_get_modules($ag,
|
||||
array('id_agente_modulo'),
|
||||
array('nombre' => $mod));
|
||||
|
||||
|
||||
|
||||
if (empty($id_module))
|
||||
continue;
|
||||
else {
|
||||
$id_module = reset($id_module);
|
||||
$id_module = $id_module['id_agente_modulo'];
|
||||
}
|
||||
|
||||
$id_modules[] = $id_module;
|
||||
}
|
||||
}
|
||||
|
||||
if ($id_server != 0) {
|
||||
metaconsole_restore_db();
|
||||
}
|
||||
|
||||
$message .= visual_map_process_wizard_add_modules(
|
||||
$id_modules,
|
||||
$image,
|
||||
|
@ -480,8 +527,12 @@ switch ($activeTab) {
|
|||
$kind_relationship,
|
||||
$item_in_the_map);
|
||||
}
|
||||
$statusProcessInDB = array('flag' => true, 'message' => $message);
|
||||
|
||||
|
||||
}
|
||||
|
||||
$statusProcessInDB = array(
|
||||
'flag' => true, 'message' => $message);
|
||||
}
|
||||
$action = 'edit';
|
||||
break;
|
||||
|
|
|
@ -25,15 +25,18 @@ if (empty($visualConsole)) {
|
|||
exit;
|
||||
}
|
||||
|
||||
$strict_user = db_get_value('strict_acl', 'tusuario', 'id_user', $config['id_user']);
|
||||
$strict_user = db_get_value('strict_acl', 'tusuario', 'id_user',
|
||||
$config['id_user']);
|
||||
|
||||
// ACL for the existing visual console
|
||||
// if (!isset($vconsole_read))
|
||||
// $vconsole_read = check_acl ($config['id_user'], $visualConsole['id_group'], "VR");
|
||||
if (!isset($vconsole_write))
|
||||
$vconsole_write = check_acl ($config['id_user'], $visualConsole['id_group'], "VW");
|
||||
$vconsole_write = check_acl(
|
||||
$config['id_user'], $visualConsole['id_group'], "VW");
|
||||
if (!isset($vconsole_manage))
|
||||
$vconsole_manage = check_acl ($config['id_user'], $visualConsole['id_group'], "VM");
|
||||
$vconsole_manage = check_acl(
|
||||
$config['id_user'], $visualConsole['id_group'], "VM");
|
||||
|
||||
if (!$vconsole_write && !$vconsole_manage) {
|
||||
db_pandora_audit("ACL Violation",
|
||||
|
@ -120,7 +123,8 @@ $table->data["staticgraph"][1] = html_print_select($images_list,
|
|||
$table->rowstyle["all_1"] = 'display: none;';
|
||||
$table->data["all_1"][0] = __('Range between elements (px)');
|
||||
$table->colspan["all_1"][1] = "3";
|
||||
$table->data["all_1"][1] = html_print_input_text('range', 50, '', 5, 5, true);
|
||||
$table->data["all_1"][1] = html_print_input_text('range', 50, '', 5, 5,
|
||||
true);
|
||||
|
||||
|
||||
$table->rowstyle["staticgraph_modulegraph"] = 'display: none;';
|
||||
|
@ -129,23 +133,27 @@ $table->colspan["staticgraph_modulegraph"][1] = "3";
|
|||
$table->data["staticgraph_modulegraph"][1] = __('Width').': ' .
|
||||
html_print_input_text ('width', 0, '', 5, 5, true);
|
||||
$table->data["staticgraph_modulegraph"][1] .= ' ' .
|
||||
__('Height').': '.html_print_input_text ('height', 0, '', 5, 5, true);
|
||||
__('Height') . ': ' .
|
||||
html_print_input_text('height', 0, '', 5, 5, true);
|
||||
|
||||
|
||||
$table->rowstyle["modulegraph_simplevalue"] = 'display: none;';
|
||||
$table->data["modulegraph_simplevalue"][0] = __('Period');
|
||||
$table->colspan["modulegraph_simplevalue"][1] = "3";
|
||||
$table->data["modulegraph_simplevalue"][1] =
|
||||
html_print_extended_select_for_time ('period', '', '', '', '', false, true);
|
||||
html_print_extended_select_for_time('period', '', '', '', '', false,
|
||||
true);
|
||||
|
||||
|
||||
$table->rowstyle["simplevalue"] = 'display: none;';
|
||||
$table->data["simplevalue"][0] = __('Process');
|
||||
$table->data["simplevalue"][1] = html_print_select (
|
||||
array (PROCESS_VALUE_MIN => __('Min value'),
|
||||
PROCESS_VALUE_MAX => __('Max value'),
|
||||
PROCESS_VALUE_AVG => __('Avg value')), 'process_value',
|
||||
PROCESS_VALUE_AVG, '', __('None'), PROCESS_VALUE_NONE, true);
|
||||
array (
|
||||
PROCESS_VALUE_MIN => __('Min value'),
|
||||
PROCESS_VALUE_MAX => __('Max value'),
|
||||
PROCESS_VALUE_AVG => __('Avg value')),
|
||||
'process_value', PROCESS_VALUE_AVG, '', __('None'),
|
||||
PROCESS_VALUE_NONE, true);
|
||||
|
||||
|
||||
$table->rowstyle["percentileitem_1"] = 'display: none;';
|
||||
|
@ -164,9 +172,11 @@ $table->rowstyle["percentileitem_3"] = 'display: none;';
|
|||
$table->data["percentileitem_3"][0] = __('Type');
|
||||
$table->data["percentileitem_3"][1] =
|
||||
html_print_radio_button_extended('type_percentile', 'percentile',
|
||||
('Percentile'), 'percentile', false, '', 'style="float: left;"', true) .
|
||||
('Percentile'), 'percentile', false, '', 'style="float: left;"',
|
||||
true) .
|
||||
html_print_radio_button_extended('type_percentile', 'bubble',
|
||||
('Bubble'), 'percentile', false, '', 'style="float: left;"', true);
|
||||
('Bubble'), 'percentile', false, '', 'style="float: left;"',
|
||||
true);
|
||||
|
||||
|
||||
$table->rowstyle["percentileitem_4"] = 'display: none;';
|
||||
|
@ -183,11 +193,12 @@ if (defined('METACONSOLE')) {
|
|||
$table->data["all_2"][0] = __('Servers');
|
||||
if ($strict_user)
|
||||
$table->data["all_2"][1] = html_print_select('','server_id',
|
||||
$server_id, 'metaconsole_init();', __('All'), '0', true);
|
||||
$server_id, 'metaconsole_init();', __('All'), '0', true);
|
||||
else
|
||||
$table->data["all_2"][1] = html_print_select_from_sql(
|
||||
'SELECT id, server_name FROM tmetaconsole_setup',
|
||||
'server_id', $server_id, 'metaconsole_init();', __('All'), '0', true);
|
||||
'SELECT id, server_name FROM tmetaconsole_setup',
|
||||
'server_id', $server_id, 'metaconsole_init();', __('All'),
|
||||
'0', true);
|
||||
}
|
||||
|
||||
|
||||
|
@ -204,10 +215,12 @@ $table->colspan["all_one_item_per_agent"][1] = "3";
|
|||
$table->data["all_one_item_per_agent"][1] = __('Yes') .
|
||||
' ' .
|
||||
html_print_radio_button_extended('item_per_agent', 1, '', '', false,
|
||||
'item_per_agent_change(1)', '', true).' ';
|
||||
'item_per_agent_change(1)', '', true) .
|
||||
' ';
|
||||
$table->data["all_one_item_per_agent"][1] .= __('No') .
|
||||
' ' . html_print_radio_button_extended(
|
||||
'item_per_agent', 0, '', 0, false, 'item_per_agent_change(0)', '', true);
|
||||
'item_per_agent', 0, '', 0, false, 'item_per_agent_change(0)',
|
||||
'', true);
|
||||
$table->data["all_one_item_per_agent"][1] .= html_print_input_hidden(
|
||||
'item_per_agent_test', 0, true);
|
||||
|
||||
|
@ -217,7 +230,9 @@ $table->data["all_4"][0] = __('Agents');
|
|||
|
||||
$agents_list = array();
|
||||
if (!defined('METACONSOLE'))
|
||||
$agents_list = agents_get_group_agents(0, false, "none", false, true);
|
||||
$agents_list = agents_get_group_agents(0, false, "none", false,
|
||||
true);
|
||||
|
||||
|
||||
$table->data["all_4"][1] = html_print_select($agents_list,
|
||||
'id_agents[]', 0, false, '', '', true, true);
|
||||
|
@ -281,7 +296,8 @@ else {
|
|||
}
|
||||
|
||||
if (defined("METACONSOLE")) {
|
||||
echo "<div class='title_tactical' style='margin-top: 15px; '>" . __('Wizard') . "</div>";
|
||||
echo "<div class='title_tactical' style='margin-top: 15px; '>" .
|
||||
__('Wizard') . "</div>";
|
||||
}
|
||||
|
||||
html_print_table ($table);
|
||||
|
@ -299,9 +315,12 @@ echo '</div>';
|
|||
echo '</form>';
|
||||
|
||||
//Trick for it have a traduct text for javascript.
|
||||
echo '<span id="any_text" style="display: none;">' . __('Any') . '</span>';
|
||||
echo '<span id="none_text" style="display: none;">' . __('None') . '</span>';
|
||||
echo '<span id="loading_text" style="display: none;">' . __('Loading...') . '</span>';
|
||||
echo '<span id="any_text" style="display: none;">' . __('Any') .
|
||||
'</span>';
|
||||
echo '<span id="none_text" style="display: none;">' . __('None') .
|
||||
'</span>';
|
||||
echo '<span id="loading_text" style="display: none;">' .
|
||||
__('Loading...') . '</span>';
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
|
||||
|
@ -360,12 +379,19 @@ $(document).ready (function () {
|
|||
if (isEmptyObject(data)) {
|
||||
var noneText = $("#none_text").html(); //Trick for catch the translate text.
|
||||
|
||||
$('#id_agents').append ($('<option></option>').html (noneText).attr ("None", "").attr('value', -1).attr('selected', true));
|
||||
$('#id_agents')
|
||||
.append($('<option></option>')
|
||||
.html(noneText)
|
||||
.attr("None", "")
|
||||
.attr('value', -1)
|
||||
.attr('selected', true));
|
||||
}
|
||||
else {
|
||||
jQuery.each (data, function (i, val) {
|
||||
s = js_html_entity_decode(val);
|
||||
$('#id_agents').append ($('<option></option>').html (s).attr("value", i));
|
||||
$('#id_agents')
|
||||
.append($('<option></option>')
|
||||
.html(s).attr("value", i));
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -476,11 +502,20 @@ function item_per_agent_change(itemPerAgent) {
|
|||
.attr('disabled', false);
|
||||
|
||||
$('#module').empty();
|
||||
$('#module').append ($('<option></option>').html (<?php echo "'" . __('None') . "'"; ?>).attr("value", -1));
|
||||
$('#module')
|
||||
.append($('<option></option>')
|
||||
.html (<?php echo "'" . __('None') . "'"; ?>)
|
||||
.attr("value", -1));
|
||||
$('#module').attr('disabled', true);
|
||||
$('#label_type').empty();
|
||||
$('#label_type').append ($('<option></option>').html (<?php echo "'" . __('Agent') . "'"; ?>).attr('value', 'agent').attr('selected', true));
|
||||
$('#label_type').append ($('<option></option>').html (<?php echo "'" . __('None') . "'"; ?>).attr('value', 'none'));
|
||||
$('#label_type')
|
||||
.append($('<option></option>')
|
||||
.html(<?php echo "'" . __('Agent') . "'"; ?>)
|
||||
.attr('value', 'agent').attr('selected', true));
|
||||
$('#label_type')
|
||||
.append($('<option></option>')
|
||||
.html(<?php echo "'" . __('None') . "'"; ?>)
|
||||
.attr('value', 'none'));
|
||||
|
||||
$('#hidden-item_per_agent_test').val(1);
|
||||
}
|
||||
|
@ -496,10 +531,23 @@ function item_per_agent_change(itemPerAgent) {
|
|||
$('#module').removeAttr('disabled');
|
||||
$('#hidden-item_per_agent_test').val(0);
|
||||
$('#label_type').empty();
|
||||
$('#label_type').append ($('<option></option>').html (<?php echo "'" . __('Agent') . "'"; ?>).attr('value', 'agent'));
|
||||
$('#label_type').append ($('<option></option>').html (<?php echo "'" . __('Agent - Module') . "'"; ?>).attr('value', 'agent_module').attr('selected', true));
|
||||
$('#label_type').append ($('<option></option>').html (<?php echo "'" . __('Module') . "'"; ?>).attr('value', 'module'));
|
||||
$('#label_type').append ($('<option></option>').html (<?php echo "'" . __('None') . "'"; ?>).attr('value', 'none'));
|
||||
$('#label_type')
|
||||
.append($('<option></option>')
|
||||
.html(<?php echo "'" . __('Agent') . "'"; ?>)
|
||||
.attr('value', 'agent'));
|
||||
$('#label_type')
|
||||
.append($('<option></option>')
|
||||
.html(<?php echo "'" . __('Agent - Module') . "'"; ?>)
|
||||
.attr('value', 'agent_module')
|
||||
.attr('selected', true));
|
||||
$('#label_type')
|
||||
.append($('<option></option>')
|
||||
.html(<?php echo "'" . __('Module') . "'"; ?>)
|
||||
.attr('value', 'module'));
|
||||
$('#label_type')
|
||||
.append($('<option></option>')
|
||||
.html(<?php echo "'" . __('None') . "'"; ?>)
|
||||
.attr('value', 'none'));
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,8 +43,9 @@ if ($get_agents_group) {
|
|||
if ($id_group != -1) {
|
||||
$filter = array();
|
||||
|
||||
if (defined('METACONSOLE'))
|
||||
if (defined('METACONSOLE')) {
|
||||
$filter['id_server'] = $id_server;
|
||||
}
|
||||
|
||||
$return = agents_get_group_agents($id_group, $filter, "none");
|
||||
}
|
||||
|
|
|
@ -32,6 +32,115 @@ $change_module_relation_updates = (bool) get_parameter('change_module_relation_u
|
|||
$get_id_tag = (bool) get_parameter('get_id_tag', 0);
|
||||
$list_modules = (bool) get_parameter('list_modules', 0);
|
||||
|
||||
$get_agent_modules_json_for_multiple_agents = (bool)get_parameter(
|
||||
"get_agent_modules_json_for_multiple_agents");
|
||||
|
||||
if ($get_agent_modules_json_for_multiple_agents) {
|
||||
$idAgents = (array)get_parameter('id_agent');
|
||||
$custom_condition = get_parameter('custom_condition', '');
|
||||
$selection_mode = get_parameter('selection_mode', 'common');
|
||||
$serialized = get_parameter('serialized', '');
|
||||
$id_server = (int)get_parameter('id_server', 0);
|
||||
$metaconsole_server_name = null;
|
||||
|
||||
$all = (string)get_parameter('all', 'all');
|
||||
switch ($all) {
|
||||
default:
|
||||
case 'all':
|
||||
$enabled = '1 = 1';
|
||||
break;
|
||||
case 'enabled':
|
||||
$enabled = 'disabled = 0';
|
||||
break;
|
||||
}
|
||||
|
||||
$result = array();
|
||||
|
||||
|
||||
if (defined("METACONSOLE")) {
|
||||
|
||||
$rows = db_get_all_rows_filter('tmetaconsole_agent',
|
||||
array("id_tagente" => $idAgents),
|
||||
array('id_agente', 'id_tmetaconsole_setup'));
|
||||
|
||||
$agents = array();
|
||||
foreach ($rows as $row) {
|
||||
$agents[$row['id_tmetaconsole_setup']][] =
|
||||
$row['id_agente'];
|
||||
}
|
||||
|
||||
foreach ($idAgents as $id_agent) {
|
||||
$id_tmetaconsole_setup = db_get_value_filter(
|
||||
'id_tmetaconsole_setup', 'tmetaconsole_agent',
|
||||
array("id_tagente" => $idAgents));
|
||||
|
||||
if (metaconsole_connect(null, $id_tmetaconsole_setup) != NOERR) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
|
||||
metaconsole_restore_db();
|
||||
}
|
||||
}
|
||||
else {
|
||||
$agents[0] = $idAgents;
|
||||
}
|
||||
|
||||
$result = array();
|
||||
foreach ($agents as $id_server => $agents) {
|
||||
if ($id_server) {
|
||||
if (metaconsole_connect(null, $id_server) != NOERR) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$sql = 'SELECT DISTINCT(nombre)
|
||||
FROM tagente_modulo t1
|
||||
WHERE ' . $enabled .
|
||||
io_safe_output($custom_condition) . '
|
||||
AND delete_pending = 0
|
||||
AND id_agente IN (' . implode(',', $idAgents) . ')';
|
||||
|
||||
if ($selection_mode == 'common') {
|
||||
$sql .= ' AND (
|
||||
SELECT count(nombre)
|
||||
FROM tagente_modulo t2
|
||||
WHERE delete_pending = 0 AND t1.nombre = t2.nombre
|
||||
AND id_agente IN (' . implode(',', $idAgents) . ')) = (' . count($idAgents) . ')';
|
||||
}
|
||||
|
||||
$sql .= ' ORDER BY nombre';
|
||||
|
||||
$nameModules = db_get_all_rows_sql($sql);
|
||||
|
||||
if ($nameModules == false) {
|
||||
$nameModules = array();
|
||||
}
|
||||
|
||||
$temp = array();
|
||||
foreach ($nameModules as $nameModule) {
|
||||
if (empty($serialized))
|
||||
$temp[io_safe_output($nameModule['nombre'])] =
|
||||
ui_print_truncate_text(
|
||||
io_safe_output($nameModule['nombre']), 'module_medium', false, true);
|
||||
else
|
||||
$temp[io_safe_output($nameModule['nombre']).'$*$'.implode('|', $idAgents)] = ui_print_truncate_text(io_safe_output($nameModule['nombre']), 'module_medium', false, true);
|
||||
}
|
||||
|
||||
if ($id_server) {
|
||||
metaconsole_restore_db();
|
||||
}
|
||||
|
||||
foreach ($temp as $i => $t) {
|
||||
$result[$i] = $t;
|
||||
}
|
||||
}
|
||||
|
||||
echo json_encode($result);
|
||||
return;
|
||||
}
|
||||
|
||||
if ($get_plugin_macros) {
|
||||
$id_plugin = get_parameter('id_plugin', 0);
|
||||
|
||||
|
|
|
@ -201,7 +201,7 @@ function agent_changed_by_multiple_agents (event, id_agent, selected) {
|
|||
|
||||
jQuery.post (homedir + '/ajax.php',
|
||||
{
|
||||
"page": "operation/agentes/ver_agente",
|
||||
"page": "include/ajax/module",
|
||||
"get_agent_modules_json_for_multiple_agents": 1,
|
||||
"id_agent[]": idAgents,
|
||||
"all": find_modules,
|
||||
|
|
|
@ -35,7 +35,6 @@ if (is_ajax ()) {
|
|||
$get_agent_modules_json = (bool) get_parameter ('get_agent_modules_json');
|
||||
$get_agent_status_tooltip = (bool) get_parameter ("get_agent_status_tooltip");
|
||||
$get_agents_group_json = (bool) get_parameter ("get_agents_group_json");
|
||||
$get_agent_modules_json_for_multiple_agents = (bool) get_parameter("get_agent_modules_json_for_multiple_agents");
|
||||
$get_agent_modules_alerts_json_for_multiple_agents = (bool) get_parameter("get_agent_modules_alerts_json_for_multiple_agents");
|
||||
$get_agents_json_for_multiple_modules = (bool) get_parameter("get_agents_json_for_multiple_modules");
|
||||
$get_agent_modules_json_for_multiple_agents_id = (bool) get_parameter("get_agent_modules_json_for_multiple_agents_id");
|
||||
|
@ -172,201 +171,6 @@ if (is_ajax ()) {
|
|||
return;
|
||||
}
|
||||
|
||||
if ($get_agent_modules_alerts_json_for_multiple_agents) {
|
||||
$idAgents = get_parameter('id_agent');
|
||||
$id_template = get_parameter('template');
|
||||
|
||||
$selection_mode = get_parameter('selection_mode','common');
|
||||
|
||||
$sql = 'SELECT DISTINCT(nombre)
|
||||
FROM tagente_modulo t1, talert_template_modules t2
|
||||
WHERE t2.id_agent_module = t1.id_agente_modulo
|
||||
AND delete_pending = 0
|
||||
AND id_alert_template = '.$id_template.'
|
||||
AND id_agente IN (' . implode(',', $idAgents) . ')';
|
||||
|
||||
if ($selection_mode == 'common') {
|
||||
$sql .= ' AND (
|
||||
SELECT count(nombre)
|
||||
FROM tagente_modulo t3, talert_template_modules t4
|
||||
WHERE t4.id_agent_module = t3.id_agente_modulo
|
||||
AND delete_pending = 0 AND t1.nombre = t3.nombre
|
||||
AND id_agente IN (' . implode(',', $idAgents) . ')
|
||||
AND id_alert_template = '.$id_template.') = (' . count($idAgents) . ')';
|
||||
}
|
||||
|
||||
$sql .= ' ORDER BY t1.nombre';
|
||||
|
||||
$nameModules = db_get_all_rows_sql($sql);
|
||||
|
||||
if ($nameModules == false) {
|
||||
$nameModules = array();
|
||||
}
|
||||
|
||||
$result = array();
|
||||
foreach($nameModules as $nameModule) {
|
||||
$result[] = io_safe_output($nameModule['nombre']);
|
||||
}
|
||||
|
||||
echo json_encode($result);
|
||||
return;
|
||||
}
|
||||
|
||||
if ($get_agent_modules_json_for_multiple_agents) {
|
||||
$idAgents = get_parameter('id_agent');
|
||||
$custom_condition = get_parameter('custom_condition', '');
|
||||
$selection_mode = get_parameter('selection_mode', 'common');
|
||||
$serialized = get_parameter('serialized', '');
|
||||
$id_server = (int)get_parameter('id_server', 0);
|
||||
$metaconsole_server_name = null;
|
||||
if ($id_server != 0) {
|
||||
$metaconsole_server_name = db_get_value('server_name',
|
||||
'tmetaconsole_setup', 'id', $id_server);
|
||||
}
|
||||
|
||||
$all = (string)get_parameter('all', 'all');
|
||||
switch ($all) {
|
||||
default:
|
||||
case 'all':
|
||||
$enabled = '1 = 1';
|
||||
break;
|
||||
case 'enabled':
|
||||
$enabled = 'disabled = 0';
|
||||
break;
|
||||
}
|
||||
|
||||
if ($config ['metaconsole'] == 1 and defined('METACONSOLE')) {
|
||||
$result = array();
|
||||
$nameModules = array();
|
||||
$temp = array();
|
||||
$first = true;
|
||||
$temp_element = array();
|
||||
$counter = 0;
|
||||
$first_elements = array();
|
||||
|
||||
foreach ($idAgents as $idA) {
|
||||
if (empty($metaconsole_server_name)) {
|
||||
if (strstr($idA, "|@_@|")) {
|
||||
$row = explode ('|@_@|', $idA);
|
||||
}
|
||||
else {
|
||||
$row = explode ('|', $idA);
|
||||
}
|
||||
$server_name = $row[0];
|
||||
$id_agent = $row [1];
|
||||
}
|
||||
else {
|
||||
$id_agent = $idA;
|
||||
$server_name = $metaconsole_server_name;
|
||||
}
|
||||
// New iteration
|
||||
$counter++;
|
||||
|
||||
//Metaconsole db connection
|
||||
$connection = metaconsole_get_connection($server_name);
|
||||
if (metaconsole_load_external_db($connection) != NOERR) {
|
||||
//ui_print_error_message ("Error connecting to ".$server_name);
|
||||
continue;
|
||||
}
|
||||
|
||||
//Get agent's modules
|
||||
$temp = agents_get_modules ($id_agent);
|
||||
|
||||
// Keep first element to search for common modules in next iterations
|
||||
if (empty($nameModules) && $first == true) {
|
||||
$first_elements = $temp;
|
||||
}
|
||||
|
||||
$temp = array_intersect($temp, $first_elements);
|
||||
|
||||
// Add elements to array
|
||||
if (!empty($temp)) {
|
||||
|
||||
// Add agent and server
|
||||
foreach ($temp as $element_key => $element_value) {
|
||||
|
||||
//$temp_element[$element_key . '|' . $id_agent . '|' . $server_name] = $element_value;
|
||||
if (!isset($temp_element[$element_value]) && $first)
|
||||
$temp_element[$element_value] = $element_key . '|' . $id_agent . '|' . $server_name;
|
||||
else if (isset($temp_element[$element_value]))
|
||||
$temp_element[$element_value] .= ';' . $element_key . '|' . $id_agent . '|' . $server_name;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
// If the result array is empty then there aren't common modules
|
||||
else if (!$first)
|
||||
unset($temp_element);
|
||||
|
||||
|
||||
// First iteration flag
|
||||
if (empty($nameModules) && $first == true)
|
||||
$first = false;
|
||||
|
||||
// In last iteration we have all elements agents-servers serialized and ready to be used
|
||||
if ($counter == count($idAgents)) {
|
||||
if (!empty($temp_element))
|
||||
|
||||
foreach ($temp_element as $temp_ele_key => $temp_ele_val) {
|
||||
$nameModules[$temp_ele_val] = $temp_ele_key;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//If there's only one agent selected, get out of this loop
|
||||
/*if (count($idAgents) <= 1) {
|
||||
//Restore db connection
|
||||
metaconsole_restore_db();
|
||||
break;
|
||||
}*/
|
||||
//$nameModules = array_intersect ($nameModules, $temp);
|
||||
|
||||
//Restore db connection
|
||||
metaconsole_restore_db();
|
||||
}
|
||||
|
||||
foreach ($nameModules as $nameModule_key => $nameModule_value) {
|
||||
$result[$nameModule_key] = ui_print_truncate_text(io_safe_output($nameModule_value), 'module_medium', false, true);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$sql = 'SELECT DISTINCT(nombre)
|
||||
FROM tagente_modulo t1
|
||||
WHERE ' . $enabled .
|
||||
io_safe_output($custom_condition) . '
|
||||
AND delete_pending = 0
|
||||
AND id_agente IN (' . implode(',', $idAgents) . ')';
|
||||
|
||||
if ($selection_mode == 'common') {
|
||||
$sql .= ' AND (
|
||||
SELECT count(nombre)
|
||||
FROM tagente_modulo t2
|
||||
WHERE delete_pending = 0 AND t1.nombre = t2.nombre
|
||||
AND id_agente IN (' . implode(',', $idAgents) . ')) = (' . count($idAgents) . ')';
|
||||
}
|
||||
|
||||
$sql .= ' ORDER BY nombre';
|
||||
|
||||
$nameModules = db_get_all_rows_sql($sql);
|
||||
|
||||
if ($nameModules == false) {
|
||||
$nameModules = array();
|
||||
}
|
||||
|
||||
$result = array();
|
||||
foreach ($nameModules as $nameModule) {
|
||||
if (empty($serialized))
|
||||
$result[io_safe_output($nameModule['nombre'])] =
|
||||
ui_print_truncate_text(
|
||||
io_safe_output($nameModule['nombre']), 'module_medium', false, true);
|
||||
else
|
||||
$result[io_safe_output($nameModule['nombre']).'$*$'.implode('|', $idAgents)] = ui_print_truncate_text(io_safe_output($nameModule['nombre']), 'module_medium', false, true);
|
||||
}
|
||||
}
|
||||
|
||||
echo json_encode($result);
|
||||
return;
|
||||
}
|
||||
|
||||
if ($get_agent_modules_json) {
|
||||
$id_agent = (int) get_parameter ('id_agent');
|
||||
|
|
Loading…
Reference in New Issue