From 3e3f4d67837b421a3ada013a23c4213d2daafcb2 Mon Sep 17 00:00:00 2001 From: slerena Date: Wed, 19 May 2010 13:40:21 +0000 Subject: [PATCH] 2010-05-19 Sancho Lerena * lib/PandoraFMS/DataServer.pm: XML data files coming from a disabled agent are now discarded. * util/pandora_manage.pl: Added CLI mode to disable/enable agents from a given group. This will help admins to implement recurrent downtime periods. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2751 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_server/ChangeLog | 8 +++ pandora_server/lib/PandoraFMS/DataServer.pm | 8 +++ pandora_server/util/pandora_manage.pl | 72 +++++++++++++++++---- 3 files changed, 75 insertions(+), 13 deletions(-) diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index 0801b7ec1b..e26550ad5a 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,11 @@ +2010-05-19 Sancho Lerena + + * lib/PandoraFMS/DataServer.pm: XML data files coming from a disabled + agent are now discarded. + + * util/pandora_manage.pl: Added CLI mode to disable/enable agents from + a given group. This will help admins to implement recurrent downtime periods. + 2010-05-18 Sancho Lerena * pandora_server_upgrade: Fixed a check on pandora_db.pl script in cron. diff --git a/pandora_server/lib/PandoraFMS/DataServer.pm b/pandora_server/lib/PandoraFMS/DataServer.pm index ca3999222d..9c33b97c04 100644 --- a/pandora_server/lib/PandoraFMS/DataServer.pm +++ b/pandora_server/lib/PandoraFMS/DataServer.pm @@ -276,6 +276,14 @@ sub process_xml_data ($$$$$) { } $AgentSem->up (); + # Check if agent is disabled and return if it's disabled. Disabled agents doesnt process data + # in order to avoid not only events, also possible invalid data coming from agents. + + my $agent_disabled = get_db_value ($dbh, 'SELECT disabled FROM tagente WHERE id_agente = ?', $agent_id); + if (defined ($agent_disabled) && $agent_disabled == 1){ + return; + } + if ($valid_position_data == 1 && $pa_config->{'activate_gis'} != 0) { if (!defined($parent_agent_name)){ $parent_agent_name = ""; diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index 56cce1057c..e2f356e6dd 100755 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -18,7 +18,7 @@ use PandoraFMS::DB; use POSIX qw(strftime); # version: define current version -my $version = "3.1 PS100321"; +my $version = "3.1 PS100519"; # Pandora server configuration my %conf; @@ -97,6 +97,32 @@ sub pandora_disable_eacl ($$$) { exit; } +# Disable a entire group +############################################################################### +sub pandora_disable_group ($$$$) { + my ($conf, $dbh, $mode, $group) = @_; + + + if ($mode == 0){ # Disable + print "[INFO] Disabling group $group\n\n"; + if ($group == 1){ + db_do ($dbh, "UPDATE tagente SET disabled = 1"); + } + else { + db_do ($dbh, "UPDATE tagente SET disabled = 1 WHERE id_grupo = $group"); + } + } else { + print "[INFO] Enabling group $group\n\n"; + if ($group == 1){ + db_do ($dbh, "UPDATE tagente SET disabled = 0"); + } + else { + db_do ($dbh, "UPDATE tagente SET disabled = 0 WHERE id_grupo = $group"); + } + } + exit; +} + ############################################################################## # Read external configuration file. @@ -136,8 +162,8 @@ sub pandora_init ($) { # Load config file from command line help_screen () if ($#ARGV < 0); - - $conf->{'_pandora_path'} = $ARGV[0]; + + $conf->{'_pandora_path'} = $ARGV[0]; help_screen () if ($conf->{'_pandora_path'} eq ''); } @@ -147,13 +173,15 @@ sub pandora_init ($) { # Print a help screen and exit. ############################################################################## sub help_screen{ - print "Usage: $0 [options] \n"; + print "Usage: $0 [options] \n\n"; print "Available options:\n\n"; print "\t--disable_alerts Disable alerts in all groups.\n"; print "\t--enable_alerts Enable alerts in all groups\n"; print "\t--disable_eacl Disable enterprise ACL system\n"; print "\t--enable_eacl Enable enterprise ACL system\n"; - print "\n"; + print "\t--disable_group Disable agents from an entire group (Use group 1 for all)\n"; + print "\t--enable_group Enable agents from an entire group (1 for all) \n"; + print "\n"; exit; } @@ -163,24 +191,42 @@ sub help_screen{ sub pandora_manage_main ($$$) { my ($conf, $dbh, $history_dbh) = @_; - # If there are not valid parameters - foreach my $param (@ARGV) { - + my @args = @ARGV; + my $param; + my $ltotal=$#args; + my $ax; + + # Has read setup file ok ? + if ( $ltotal == 0 ) { + print "[ERROR] No valid arguments"; + help_screen(); + exit; + } + + for ($ax=0;$ax<=$ltotal;$ax++){ + $param = $args[$ax]; + # help! help_screen () if ($param =~ m/--*h\w*\z/i ); if ($param =~ m/--disable_alerts\z/i) { - pandora_disable_alerts ($conf, $dbh, 0); - } + pandora_disable_alerts ($conf, $dbh, 0); + } elsif ($param =~ m/--enable_alerts\z/i) { - pandora_disable_alerts ($conf, $dbh, 1); + pandora_disable_alerts ($conf, $dbh, 1); } elsif ($param =~ m/--disable_eacl\z/i) { - pandora_disable_eacl ($conf, $dbh, 0); + pandora_disable_eacl ($conf, $dbh, 0); } elsif ($param =~ m/--enable_eacl\z/i) { - pandora_disable_eacl ($conf, $dbh, 1); + pandora_disable_eacl ($conf, $dbh, 1); } + elsif ($param =~ m/--disable_group/i) { + pandora_disable_group ($conf, $dbh, 0, $args[$ax+1]); + } + elsif ($param =~ m/--enable_group/i) { + pandora_disable_group ($conf, $dbh, 1, $args[$ax+1]); + } } print "[W] Nothing to do. Exiting !\n\n";