bulk operations agents in meta #8290

This commit is contained in:
Daniel Barbero Martin 2022-01-24 16:57:42 +01:00
parent 2fccdd12cb
commit 83970932ce
3 changed files with 50 additions and 21 deletions

View File

@ -26,6 +26,9 @@
* ============================================================================ * ============================================================================
*/ */
use PandoraFMS\Agent;
use PandoraFMS\Enterprise\Metaconsole\Node;
// Begin. // Begin.
check_login(); check_login();
@ -63,15 +66,32 @@ function process_manage_delete($id_agents)
$count_deleted = 0; $count_deleted = 0;
$agent_id_restore = 0; $agent_id_restore = 0;
hd('borrando');
hd($id_agents);
foreach ($id_agents as $id_agent) { foreach ($id_agents as $id_agent) {
hd($id_agent); if (is_metaconsole() === true) {
// TODO:XXX. $array_id = explode('|', $id_agent);
// $success = agents_delete_agent($id_agent); try {
$node = new Node((int) $array_id[0]);
$node->connect();
$agent = new Agent((int) $array_id[1]);
$success = $agent->delete();
$node->disconnect();
} catch (\Exception $e) {
// Unexistent agent.
$success = false; $success = false;
$node->disconnect();
}
} else {
try {
$agent = new Agent($id_agent);
$success = $agent->delete();
} catch (\Exception $e) {
// Unexistent agent.
$success = false;
}
}
if ($success === false) { if ($success === false) {
$agent_id_restore = $id_agent; $agent_id_restore = $id_agent;
break; break;
@ -255,16 +275,19 @@ $table->data[3][0] = __('Agents');
$table->data[3][0] .= '<span id="agent_loading" class="invisible">'; $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] .= html_print_image('images/spinner.png', true);
$table->data[3][0] .= '</span>'; $table->data[3][0] .= '</span>';
$table->data[3][1] = html_print_select(
agents_get_group_agents( $agents = agents_get_group_agents(
array_keys(users_get_groups($config['id_user'], 'AW', false)), array_keys(users_get_groups($config['id_user'], 'AW', false)),
false, ['disabled' => 2],
'none', 'none',
false, false,
false, false,
is_metaconsole(), is_metaconsole(),
'|' '|'
), );
$table->data[3][1] = html_print_select(
$agents,
'id_agents[]', 'id_agents[]',
0, 0,
false, false,
@ -294,7 +317,7 @@ if (is_metaconsole() === true) {
$url = 'index.php?sec=advanced&sec2=advanced/massive_operations&tab=massive_agents&pure=0&option=delete_agents'; $url = 'index.php?sec=advanced&sec2=advanced/massive_operations&tab=massive_agents&pure=0&option=delete_agents';
} }
echo '<form method="post" id="from_agents" action="'.$url.'">'; echo '<form method="post" id="form_agent" action="'.$url.'">';
html_print_table($table); html_print_table($table);
if (is_metaconsole() === true || is_management_allowed() === true) { if (is_metaconsole() === true || is_management_allowed() === true) {

View File

@ -479,7 +479,7 @@ $table->data[2][0] .= html_print_image('images/spinner.png', true);
$table->data[2][0] .= '</span>'; $table->data[2][0] .= '</span>';
$all_agents = agents_get_group_agents( $all_agents = agents_get_group_agents(
array_keys(users_get_groups($config['id_user'], 'AW', false)), array_keys(users_get_groups($config['id_user'], 'AW', false)),
false, ['disabled' => 2],
'none' 'none'
); );

View File

@ -590,15 +590,19 @@ class Agent extends Entity
/** /**
* Delete agent from db. * Delete agent from db.
* *
* @return void * @return boolean
*/ */
public function delete() public function delete()
{ {
// This function also mark modules for deletion. // This function also mark modules for deletion.
\agents_delete_agent( $res = (bool) \agents_delete_agent(
$this->fields['id_agente'] $this->fields['id_agente']
); );
if ($res === false) {
return false;
}
// Delete modules. // Delete modules.
if ($this->modules !== null) { if ($this->modules !== null) {
foreach ($this->modules as $module) { foreach ($this->modules as $module) {
@ -608,6 +612,8 @@ class Agent extends Entity
unset($this->fields); unset($this->fields);
unset($this->modules); unset($this->modules);
return $res;
} }