2010-12-09 Sergio Martin <sergio.martin@artica.es>

* lib/PandoraFMS/Core.pm
	util/pandora_manage.pl
	util/pandora_sync_db.pl: Added agents and modules
	existence checks on source and destination in 
	sync db script. Added messages in execution time



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@3656 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
zarzuelo 2010-12-09 15:42:58 +00:00
parent 9d6d77ad5e
commit 5dd5ca54b5
4 changed files with 90 additions and 59 deletions

View File

@ -1,3 +1,11 @@
2010-12-09 Sergio Martin <sergio.martin@artica.es>
* lib/PandoraFMS/Core.pm
util/pandora_manage.pl
util/pandora_sync_db.pl: Added agents and modules
existence checks on source and destination in
sync db script. Added messages in execution time
2010-12-09 Sergio Martin <sergio.martin@artica.es>
* util/recon_scripts/snmpdevices.pl: Fixed a typo from the

View File

@ -132,6 +132,8 @@ our @EXPORT = qw(
pandora_create_incident
pandora_create_module
pandora_create_module_from_hash
pandora_delete_agent
pandora_delete_module
pandora_evaluate_alert
pandora_evaluate_compound_alert
pandora_evaluate_snmp_alerts
@ -1118,6 +1120,27 @@ sub pandora_create_module ($$$$$$$$$$) {
return $module_id;
}
##########################################################################
## Delete a module given its id.
##########################################################################
sub pandora_delete_module ($$) {
my ($dbh, $module_id) = @_;
# Delete Graphs, layouts & reports
db_do ($dbh, 'DELETE FROM tgraph_source WHERE id_agent_module = ?', $module_id);
db_do ($dbh, 'DELETE FROM tlayout_data WHERE id_agente_modulo = ?', $module_id);
db_do ($dbh, 'DELETE FROM treport_content WHERE id_agent_module = ?', $module_id);
# Delete the module state
db_do ($dbh, 'DELETE FROM tagente_estado WHERE id_agente_modulo = ?', $module_id);
# Delete templates asociated to the module
db_do ($dbh, 'DELETE FROM talert_template_modules WHERE id_agent_module = ?', $module_id);
# Set pending delete the module
db_do ($dbh, 'UPDATE tagente_modulo SET disabled = 1, delete_pending = 1 WHERE id_agente_modulo = ?', $module_id);
}
##########################################################################
## Create an agent module from hash
##########################################################################
@ -1193,6 +1216,42 @@ sub pandora_create_agent ($$$$$$$$$$;$$$$$) {
return $agent_id;
}
##########################################################################
## Delete an agent given its id.
##########################################################################
sub pandora_delete_agent ($$;$) {
my ($dbh, $agent_id, $conf) = @_;
my $agent_name = get_agent_name($dbh, $agent_id);
# Delete from all their policies
enterprise_hook('pandora_delete_agent_from_policies', [$agent_id, $dbh]);
# Delete the agent
db_do ($dbh, 'DELETE FROM tagente WHERE id_agente = ?', $agent_id);
# Delete agent access data
db_do ($dbh, 'DELETE FROM tagent_access WHERE id_agent = ?', $agent_id);
# Delete addresses
db_do ($dbh, 'DELETE FROM taddress_agent WHERE id_ag = ?', $agent_id);
my @modules = get_db_rows ($dbh, 'SELECT * FROM tagente_modulo WHERE id_agente = ?', $agent_id);
if(defined $conf) {
# Delete the conf files
if (-e $conf->{incomingdir}.'/conf/'.md5($agent_name).'.conf') {
unlink($conf->{incomingdir}.'/conf/'.md5($agent_name).'.conf');
}
if (-e $conf->{incomingdir}.'/md5/'.md5($agent_name).'.md5') {
unlink($conf->{incomingdir}.'/md5/'.md5($agent_name).'.md5');
}
}
foreach my $module (@modules) {
pandora_delete_module ($dbh, $module->{'id_agente_modulo'});
}
}
##########################################################################
=head2 C<< pandora_event (I<$pa_config>, I<$evento>, I<$id_grupo>, I<$id_agente>, I<$severity>, I<$id_alert_am>, I<$id_agentmodule>, I<$event_type>, I<$event_status>, I<$dbh>) >>

View File

@ -174,61 +174,6 @@ sub pandora_manage_init ($) {
help_screen () if ($conf->{'pandora_path'} =~ m/--*h\w*\z/i );
}
##########################################################################
## Delete a module given its id.
##########################################################################
sub pandora_delete_module ($$) {
my ($dbh, $module_id) = @_;
# Delete Graphs, layouts & reports
db_do ($dbh, 'DELETE FROM tgraph_source WHERE id_agent_module = ?', $module_id);
db_do ($dbh, 'DELETE FROM tlayout_data WHERE id_agente_modulo = ?', $module_id);
db_do ($dbh, 'DELETE FROM treport_content WHERE id_agent_module = ?', $module_id);
# Delete the module state
db_do ($dbh, 'DELETE FROM tagente_estado WHERE id_agente_modulo = ?', $module_id);
# Delete templates asociated to the module
db_do ($dbh, 'DELETE FROM talert_template_modules WHERE id_agent_module = ?', $module_id);
# Set pending delete the module
db_do ($dbh, 'UPDATE tagente_modulo SET disabled = 1, delete_pending = 1 WHERE id_agente_modulo = ?', $module_id);
}
##########################################################################
## Delete an agent given its id.
##########################################################################
sub pandora_delete_agent ($$$) {
my ($dbh, $agent_id, $conf) = @_;
my $agent_name = get_agent_name($dbh, $agent_id);
# Delete from all their policies
enterprise_hook('pandora_delete_agent_from_policies', [$agent_id, $dbh]);
# Delete the agent
db_do ($dbh, 'DELETE FROM tagente WHERE id_agente = ?', $agent_id);
# Delete agent access data
db_do ($dbh, 'DELETE FROM tagent_access WHERE id_agent = ?', $agent_id);
# Delete addresses
db_do ($dbh, 'DELETE FROM taddress_agent WHERE id_ag = ?', $agent_id);
my @modules = get_db_rows ($dbh, 'SELECT * FROM tagente_modulo WHERE id_agente = ?', $agent_id);
# Delete the conf files
if (-e $conf->{incomingdir}.'/conf/'.md5($agent_name).'.conf') {
unlink($conf->{incomingdir}.'/conf/'.md5($agent_name).'.conf');
}
if (-e $conf->{incomingdir}.'/md5/'.md5($agent_name).'.md5') {
unlink($conf->{incomingdir}.'/md5/'.md5($agent_name).'.md5');
}
foreach my $module (@modules) {
pandora_delete_module ($dbh, $module->{'id_agente_modulo'});
}
}
##########################################################################
## Create a template module.
##########################################################################

View File

@ -58,11 +58,30 @@ my $dbh_dest = db_connect ('mysql', $conf{'dbname_dest'}, $conf{'dbhost_dest'},
my $history_dbh = ($conf{'_history_db_enabled'} eq '1') ? db_connect ('mysql', $conf{'_history_db_name'},
$conf{'_history_db_host'}, '3306', $conf{'_history_db_user'}, $conf{'_history_db_pass'}) : undef;
# Build the comparation arrays (the id_agents must be compare first, doesnt touch)
print "\n[*] Preparing agents correlation.\n";
# Build the comparison arrays (the id_agents must be compare first)
my $id_agent_comparation = enterprise_hook('sync_compare_id_agents', [$dbh_source, $dbh_dest, \$errors_agents]);
my @id_agent_comparation = @{$id_agent_comparation};
print "\n[*] Checking destination agents missed on source.\n";
my $agents_deleted = enterprise_hook('sync_delete_dst_missed_agents', [$dbh_source, $dbh_dest, \$errors_agents]);
print "\n[*] $agents_deleted agents deleted on destination.\n" unless $agents_deleted == 0;
print "\n[*] Preparing modules correlation.\n";
my $id_agentmodule_comparation = enterprise_hook('sync_compare_id_agent_modules', [$dbh_source, $dbh_dest, $id_agent_comparation, \$errors_modules]);
my @id_agentmodule_comparation = @{$id_agentmodule_comparation};
print "\n[*] Checking destination modules missed on source.\n";
my $modules_deleted = enterprise_hook('sync_delete_dst_missed_agent_modules', [$dbh_source, $dbh_dest, $id_agent_comparation, \$errors_modules]);
print "\n[*] $modules_deleted modules deleted on destination.\n" unless $modules_deleted == 0;
print "\n[*] Preparing servers correlation.\n";
my $id_server_export_comparation = enterprise_hook('sync_compare_id_server_export', [$dbh_source, $dbh_dest, \$errors_exportservers]);
my @id_server_export_comparation = @{$id_server_export_comparation};
my $id_server_comparation = enterprise_hook('sync_compare_id_server', [$dbh_source, $dbh_dest, \$errors_servers]);
@ -215,14 +234,14 @@ sub pandora_sync_main ($$$) {
print "\n[*] Nothing to do. Exiting !\n\n";
}
else {
print "\n[W] $errors errors in synchronization.\n\n";
print "\n[W] $errors errors fixed in synchronization.\n\n";
print "Summary: \n";
if($errors_agents > 0) {
print "- $errors_agents Agents unsynchronized.\n";
print "- $errors_agents Agents unsynchronized fixed.\n";
}
if($errors_modules > 0) {
print "- $errors_modules Modules unsynchronized.\n";
print "- $errors_modules Modules unsynchronized fixed.\n";
}
if($errors_servers > 0) {
print "- $errors_servers Servers unsynchronized.\n";