mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-31 01:35:36 +02:00
Clean deleted agents and modules from dashboards, reports, etc
This commit is contained in:
parent
40ea25eeea
commit
7a3da419bd
@ -764,47 +764,51 @@ sub pandora_checkdb_integrity {
|
|||||||
# Delete orphan data form deleted agents.
|
# Delete orphan data form deleted agents.
|
||||||
my @agents_ids = get_db_rows ($dbh, 'SELECT id_agente, alias FROM tagente');
|
my @agents_ids = get_db_rows ($dbh, 'SELECT id_agente, alias FROM tagente');
|
||||||
my $agents_id = '0';
|
my $agents_id = '0';
|
||||||
my $agents_alias;
|
|
||||||
foreach my $id (@agents_ids) {
|
foreach my $id (@agents_ids) {
|
||||||
$agents_id .= ','.$id->{'id_agente'};
|
$agents_id .= ','.$id->{'id_agente'};
|
||||||
$agents_alias .= ','.$id->{'alias'};
|
|
||||||
}
|
}
|
||||||
if(defined($agents_id) && $agents_id ne '0') {
|
if(defined($agents_id) && $agents_id ne '0') {
|
||||||
# Delete orphan data from visual console.
|
# Delete orphan data from visual console.
|
||||||
|
log_message ('INTEGRITY', "Deleting orphan visual console items.");
|
||||||
db_do ($dbh, 'DELETE FROM tlayout_data WHERE id_agent NOT IN (?)', $agents_id);
|
db_do ($dbh, 'DELETE FROM tlayout_data WHERE id_agent NOT IN (?)', $agents_id);
|
||||||
|
db_do ($dbh, 'DELETE FROM tlayout_data WHERE id_agente_modulo NOT IN (SELECT id_agente_modulo FROM tagente_modulo)');
|
||||||
|
|
||||||
# Clearl orphan data from dashboards
|
# Clearl orphan data from dashboards
|
||||||
|
log_message ('INTEGRITY', "Deleting orphan dahsboard items.");
|
||||||
my $where_condition;
|
my $where_condition;
|
||||||
my $index ;
|
|
||||||
foreach my $agent_id (@agents_ids) {
|
foreach my $agent_id (@agents_ids) {
|
||||||
$where_condition .= 'options NOT LIKE ("%\\"agentid\\":\\"'.$agent_id->{'id_agente'}.'\\"%")';
|
$where_condition .= 'options NOT LIKE ("%\\"agentid\\":\\"'.$agent_id->{'id_agente'}.'\\"%")';
|
||||||
if($agent_id == @agents_ids[-1]) {
|
if($agent_id == $agents_ids[-1]) {
|
||||||
last;
|
last;
|
||||||
}
|
}
|
||||||
$where_condition .= ' AND ';
|
$where_condition .= ' AND ';
|
||||||
}
|
}
|
||||||
|
|
||||||
db_do ($dbh, 'UPDATE twidget_dashboard set options = NULL WHERE '.$where_condition);
|
db_do ($dbh, 'UPDATE twidget_dashboard set options = NULL WHERE '.$where_condition);
|
||||||
|
|
||||||
# Delete orphan report items.
|
$where_condition = '';
|
||||||
db_do ($dbh, 'DELETE FROM treport_content WHERE id_agent != 0 AND id_agent NOT IN (?)', $agents_id);
|
my @modules = get_db_rows($dbh, 'SELECT id_agente_modulo FROM tagente_modulo');
|
||||||
|
foreach my $id_agente_modulo (@modules) {
|
||||||
|
print Dumper($id_agente_modulo);
|
||||||
|
$where_condition .= 'options NOT LIKE ("%\\"moduleId\\":\\"'.$id_agente_modulo->{'id_agente_modulo'}.'\\"%")';
|
||||||
|
if($id_agente_modulo == $modules[-1]) {
|
||||||
|
last;
|
||||||
|
}
|
||||||
|
$where_condition .= ' AND ';
|
||||||
|
}
|
||||||
|
|
||||||
# Delete orphan tevent alert rules
|
db_do ($dbh, 'UPDATE twidget_dashboard set options = NULL WHERE '.$where_condition);
|
||||||
db_do ($dbh, 'DELETE FROM tevent_rule WHERE agent IS NOT NULL AND agent != "" AND agent NOT IN (?) AND operator_agent = ?', $agents_alias, '==');
|
|
||||||
db_do ($dbh, 'DELETE FROM tevent_rule WHERE log_agent IS NOT NULL AND log_agent != "" AND log_agent NOT IN (?) AND operator_log_agent = ?', $agents_alias, '==');
|
|
||||||
|
|
||||||
# Delete orphan data from favorite agents
|
# Delete orphan data from favorite agents
|
||||||
|
log_message ('INTEGRITY', "Deleting orphan favories items.");
|
||||||
db_do ($dbh, 'DELETE FROM tfavmenu_user WHERE section = "Agents" AND id_element NOT IN (?)', $agents_id);
|
db_do ($dbh, 'DELETE FROM tfavmenu_user WHERE section = "Agents" AND id_element NOT IN (?)', $agents_id);
|
||||||
|
|
||||||
# Delete orphan data from tservices.
|
|
||||||
db_do ($dbh, 'DELETE FROM tservice_element WHERE id_agent NOT IN (?)', $agents_id);
|
|
||||||
|
|
||||||
# Delete orphan data from gis maps
|
# Delete orphan data from gis maps
|
||||||
|
log_message ('INTEGRITY', "Deleting orphan GIS data.");
|
||||||
db_do ($dbh, 'DELETE FROM tgis_data_history WHERE tagente_id_agente NOT IN (?)', $agents_id);
|
db_do ($dbh, 'DELETE FROM tgis_data_history WHERE tagente_id_agente NOT IN (?)', $agents_id);
|
||||||
|
|
||||||
# Delete agents from policies
|
|
||||||
db_do ($dbh, 'DELETE FROM tpolicy_agents WHERE id_agent NOT IN (?)', $agents_id);
|
|
||||||
|
|
||||||
# Delete orphan tnetwork maps data
|
# Delete orphan tnetwork maps data
|
||||||
|
log_message ('INTEGRITY', "Deleting orphan networkmaps data.");
|
||||||
db_do ($dbh, 'DELETE FROM titem WHERE source_data NOT IN (?)', $agents_id);
|
db_do ($dbh, 'DELETE FROM titem WHERE source_data NOT IN (?)', $agents_id);
|
||||||
db_do ($dbh, 'DELETE FROM trel_item WHERE id_parent_source_data NOT IN (?) OR id_child_source_data NOT IN (?)', $agents_id, $agents_id);
|
db_do ($dbh, 'DELETE FROM trel_item WHERE id_parent_source_data NOT IN (?) OR id_child_source_data NOT IN (?)', $agents_id, $agents_id);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user