bulk operations agents in meta #8290

This commit is contained in:
Daniel Barbero Martin 2022-01-21 11:49:30 +01:00
parent 4e7afa7d0b
commit 7c2000c34d
5 changed files with 138 additions and 118 deletions

View File

@ -113,6 +113,9 @@ if (is_ajax() === true) {
'|'
);
$force_serialized = (bool) get_parameter('force_serialized', false);
$nodes = (array) get_parameter('nodes', []);
hd($nodes, true);
if ((bool) check_acl($config['id_user'], $id_group, 'AR') === false) {
db_pandora_audit(
@ -154,6 +157,10 @@ if (is_ajax() === true) {
$filter[$_sql_post] = '1';
}
if (is_metaconsole() === true && empty($nodes) === false) {
$filter['id_server'] = $nodes;
}
$id_groups_get_agents = $id_group;
if ($id_group == 0 && $privilege != '') {
$groups = users_get_groups($config['id_user'], $privilege, false);

View File

@ -45,24 +45,27 @@ require_once $config['homedir'].'/include/functions_users.php';
require_once $config['homedir'].'/include/functions_massive_operations.php';
/**
* Bulk operations Delete.
*
* @param array $id_agents Agents to delete.
*
* @return boolean
*/
function process_manage_delete($id_agents)
{
if (empty($id_agents)) {
if (empty($id_agents) === true) {
ui_print_error_message(__('No agents selected'));
return false;
}
$id_agents = (array) $id_agents;
$copy_modules = (bool) get_parameter('copy_modules');
$copy_alerts = (bool) get_parameter('copy_alerts');
$error = false;
$count_deleted = 0;
$agent_id_restore = 0;
foreach ($id_agents as $id_agent) {
$success = agents_delete_agent($id_agent);
if (! $success) {
if (!$success) {
$agent_id_restore = $id_agent;
break;
}
@ -70,7 +73,7 @@ function process_manage_delete($id_agents)
$count_deleted++;
}
if (! $success) {
if (!$success) {
ui_print_error_message(
sprintf(
__('There was an error deleting the agent, the operation has been cancelled Could not delete agent %s'),
@ -97,7 +100,6 @@ function process_manage_delete($id_agents)
$id_group = (int) get_parameter('id_group');
$id_agents = get_parameter('id_agents');
$recursion = get_parameter('recursion');
$delete = (bool) get_parameter_post('delete');
if ($delete === true) {
@ -135,14 +137,12 @@ if (is_metaconsole() === false && is_management_allowed() === false) {
\ui_print_warning_message(
__(
'This node is configured with centralized mode. All alert calendar information is read only. Go to %s to manage it.',
'This node is configured with centralized mode. Bulk operations is read only. Go to %s to manage it.',
$url_link
)
);
}
// $groups = users_get_groups();
$table = new stdClass;
$table->id = 'delete_table';
$table->class = 'databox filters';
@ -226,24 +226,44 @@ if (is_metaconsole() === true) {
$table->data[2][2] = __('Node');
$table->data[2][3] = html_print_select(
$server_fields,
'node',
'nodes[]',
0,
false,
'',
__('All'),
0,
'',
true,
true,
true,
'',
false,
'min-width: 500px; max-width: 500px; max-height: 100px',
false,
false,
false,
'',
false,
false,
false,
false,
true,
true,
true
);
}
$table->data[3][0] = __('Agents');
$table->data[3][0] .= '<span id="agent_loading" class="invisible">';
$table->data[3][0] .= html_print_image('images/spinner.png', true);
$table->data[3][0] .= '</span>';
$table->data[3][1] = html_print_select(
agents_get_agents_selected(
array_keys(users_get_groups($config['id_user'], 'AW', false))
agents_get_group_agents(
array_keys(users_get_groups($config['id_user'], 'AW', false)),
false,
'none',
false,
false,
is_metaconsole(),
'|'
),
'id_agents[]',
0,
@ -291,6 +311,10 @@ ui_require_jquery_file('pandora.controls');
<script type="text/javascript">
$(document).ready (function () {
// Check Metaconsole.
var metaconsole = '<?php echo (is_metaconsole() === true) ? 1 : 0; ?>';
// Listeners.
var recursion;
$("#checkbox-recursion").click(function () {
recursion = this.checked ? 1 : 0;
@ -298,12 +322,23 @@ ui_require_jquery_file('pandora.controls');
});
var disabled;
$("#disabled").click(function () {
$("#disabled").change(function () {
disabled = this.value;
$("#id_group").trigger("change");
});
$("#id_group").pandoraSelectGroupAgent ({
var nodes;
$("#nodes").change(function () {
nodes = $("#nodes").val();
$("#id_group").trigger("change");
});
$("#status_agents").change(function() {
$("#id_group").trigger("change");
});
// Build data.
var data = {
status_agents: function () {
return $("#status_agents").val();
},
@ -314,15 +349,18 @@ ui_require_jquery_file('pandora.controls');
},
disabled: function() {
return disabled;
}
});
},
}
$("#status_agents").change(function() {
$("#id_group").trigger("change");
});
if (metaconsole == 1) {
data.serialized = true;
data.serialized_separator = '|';
data.nodes = function() {
return nodes;
};
}
disabled = 2;
//$("#id_group").trigger("change");
// Change agents.
$("#id_group").pandoraSelectGroupAgent(data);
});
</script>

View File

@ -56,7 +56,7 @@ if (is_ajax()) {
$name = agents_get_name($id_agent);
$agent_md5 = md5($name);
if (file_exists($config['remote_config'].'/md5/'.$agent_md5.'.md5')) {
$cont ++;
$cont++;
}
}
@ -468,12 +468,13 @@ $table->data[1][3] = html_print_select(
__('All'),
2,
true,
false,
true,
'',
'',
'',
'',
false,
'width:30%;'
);
$table->data[2][0] = __('Agents');
$table->data[2][0] .= '<span id="agent_loading" class="invisible">';
$table->data[2][0] .= html_print_image('images/spinner.png', true);
@ -940,16 +941,13 @@ $(document).ready (function () {
return false;
}
});
var disabled;
$("#disabled").click(function () {
disabled = this.value;
$("#id_group").trigger("change");
$("#disabled").change(function () {
disabled = this.value;
$("#id_group").trigger("change");
});
$('#id_agents').on('change', function() {
var idAgents = Array();
jQuery.each ($("#id_agents option:selected"), function (i, val) {

View File

@ -1217,6 +1217,15 @@ function agents_get_group_agents(
}
}
if ((isset($search['disabled']) === true
&& $search['disabled'] === 2)
|| (isset($filter['disabled']) === true
&& $filter['disabled'] === 2)
) {
unset($search['disabled']);
unset($filter['disabled']);
}
if (isset($search['all_agents'])) {
unset($search['all_agents']);
}
@ -1309,17 +1318,20 @@ function agents_get_group_agents(
}
}
if (is_metaconsole() && isset($search['id_server'])) {
$filter['id_tmetaconsole_setup'] = $search['id_server'];
if (is_metaconsole() === true
&& isset($search['id_server']) === true
&& empty($search['id_server']) === false
) {
$filter['ta.id_tmetaconsole_setup'] = $search['id_server'];
if ($filter['id_tmetaconsole_setup'] == 0) {
// All nodes.
unset($filter['id_tmetaconsole_setup']);
}
unset($search['id_server']);
}
unset($search['id_server']);
if (!$add_alert_bulk_op) {
// Add the rest of the filter from the search array.
foreach ($search as $key => $value) {
@ -1332,7 +1344,7 @@ function agents_get_group_agents(
$filter['order'] = 'alias';
if (is_metaconsole()) {
if (is_metaconsole() === true) {
$table_name = 'tmetaconsole_agent ta LEFT JOIN tmetaconsole_agent_secondary_group tasg ON ta.id_agente = tasg.id_agent';
if ($meta_fields === true) {
@ -1357,6 +1369,10 @@ function agents_get_group_agents(
];
}
hd($table_name, true);
hd($filter, true);
hd($fields, true);
$result = db_get_all_rows_filter($table_name, $filter, $fields);
if ($result === false) {

View File

@ -21,7 +21,8 @@
disabled: disabled || false,
privilege: "",
serialized: false,
serialized_separator: ""
serialized_separator: "",
nodes: []
};
/* public methods */
@ -67,79 +68,39 @@
add_alert_bulk_op: config.add_alert_bulk_op,
privilege: config.privilege,
// Add a key prefix to avoid auto sorting in js object conversion
keys_prefix: "_"
keys_prefix: "_",
serialized: config.serialized,
serialized_separator: config.serialized_separator,
nodes:
typeof config.nodes === "function"
? config.nodes()
: config.disabled
};
if (opts["disabled"] == 1 || opts["disabled"] == 0) {
jQuery.post(
"ajax.php",
opts,
function(data) {
jQuery.each(data, function(id, value) {
// Remove keys_prefix from the index.
id = id.substring(1);
if (id !== "keycount") {
config.callbackPre();
var option = $("<option></option>")
.attr("value", id)
.html(value);
config.callbackPost(id, value, option);
$(config.agentSelect).append(option);
}
});
$(config.loading).hide();
$select.enable();
config.callbackAfter();
},
"json"
);
} else {
opts["disabled"] = 0;
jQuery.post(
"ajax.php",
opts,
function(data) {
jQuery.each(data, function(id, value) {
// Remove keys_prefix from the index
id = id.substring(1);
if (id !== "keycount") {
config.callbackPre();
var option = $("<option></option>")
.attr("value", id)
.html(value);
config.callbackPost(id, value, option);
$(config.agentSelect).append(option);
}
});
$(config.loading).hide();
$select.enable();
config.callbackAfter();
},
"json"
);
opts["disabled"] = 1;
jQuery.post(
"ajax.php",
opts,
function(data) {
jQuery.each(data, function(id, value) {
// Remove keys_prefix from the index
id = id.substring(1);
if (id !== "keycount") {
config.callbackPre();
var option = $("<option></option>")
.attr("value", id)
.html(value);
config.callbackPost(id, value, option);
$(config.agentSelect).append(option);
}
});
$(config.loading).hide();
$select.enable();
config.callbackAfter();
},
"json"
);
}
console.log(opts);
jQuery.post(
"ajax.php",
opts,
function(data) {
jQuery.each(data, function(id, value) {
// Remove keys_prefix from the index.
id = id.substring(1);
if (id !== "keycount") {
config.callbackPre();
var option = $("<option></option>")
.attr("value", id)
.html(value);
config.callbackPost(id, value, option);
$(config.agentSelect).append(option);
}
});
$(config.loading).hide();
$select.enable();
config.callbackAfter();
},
"json"
);
});
});
};