diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index f84a824b07..1b087a59a1 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,10 @@ +2009-12-14 Raul Mateos + + * lib/PandoraFMS/Core.pm: Changed spaces for tabs. + + * lib/PandoraFMS/Config.pm: Updated build to last change. Changed spaces + for tabs. + 2009-12-07 Raul Mateos * pandora_server_installer: Added variables and used in the code. diff --git a/pandora_server/lib/PandoraFMS/Config.pm b/pandora_server/lib/PandoraFMS/Config.pm index 61d14adb68..3bf3773c91 100644 --- a/pandora_server/lib/PandoraFMS/Config.pm +++ b/pandora_server/lib/PandoraFMS/Config.pm @@ -29,15 +29,15 @@ our @ISA = ("Exporter"); our %EXPORT_TAGS = ( 'all' => [ qw( ) ] ); our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); our @EXPORT = qw( - pandora_help_screen + pandora_help_screen pandora_init pandora_load_config - pandora_start_log - ); + pandora_start_log + ); # version: Defines actual version of Pandora Server for this module only my $pandora_version = "3.0RC3"; -my $pandora_build = "PS091119"; +my $pandora_build = "PS091205"; our $VERSION = $pandora_version." ".$pandora_build; # Setup hash @@ -52,12 +52,12 @@ my %pa_config; sub help_screen { print "\nSyntax: \n\n pandora_server [ options ] < fullpathname to configuration file (pandora_server.conf) > \n\n"; print "Following options are optional : \n"; - print " -v : Verbose mode activated. Writes more information in the logfile \n"; - print " -d : Debug mode activated. Writes extensive information in the logfile \n"; - print " -D : Daemon mode (runs in background)\n"; - print " -P : Store PID to file.\n"; - print " -q : Quiet startup \n"; - print " -h : This screen. Shows a little help screen \n"; + print " -v : Verbose mode activated. Writes more information in the logfile \n"; + print " -d : Debug mode activated. Writes extensive information in the logfile \n"; + print " -D : Daemon mode (runs in background)\n"; + print " -P : Store PID to file.\n"; + print " -q : Quiet startup \n"; + print " -h : This screen. Shows a little help screen \n"; print " \n"; exit; } @@ -90,27 +90,27 @@ sub pandora_init { my $ltotal=$#ARGV; my $ax; for ($ax=0;$ax<=$ltotal;$ax++){ - $parametro = $ARGV[$ax]; + $parametro = $ARGV[$ax]; if (($parametro =~ m/-h\z/i ) || ($parametro =~ m/help\z/i )) { - help_screen(); + help_screen(); } elsif ($parametro =~ m/-v\z/i) { - $pa_config->{"verbosity"}=5; + $pa_config->{"verbosity"}=5; } elsif ($parametro =~ m/^-P\z/i) { - $pa_config->{'PID'}= clean_blank($ARGV[$ax+1]); + $pa_config->{'PID'}= clean_blank($ARGV[$ax+1]); } elsif ($parametro =~ m/-d\z/) { - $pa_config->{"verbosity"}=10; + $pa_config->{"verbosity"}=10; } elsif ($parametro =~ m/-q\z/) { - $pa_config->{"quiet"}=1; + $pa_config->{"quiet"}=1; } elsif ($parametro =~ m/-D\z/) { - $pa_config->{"daemon"}=1; + $pa_config->{"daemon"}=1; } else { - ($pa_config->{"pandora_path"} = $parametro); + ($pa_config->{"pandora_path"} = $parametro); } } if ($pa_config->{"pandora_path"} eq ""){ @@ -238,17 +238,17 @@ sub pandora_load_config { # Check for UID0 if ($pa_config->{"quiet"} != 0){ - if ($> == 0){ - printf " [W] Not all Pandora FMS components need to be executed as root\n"; - printf " please consider starting it with a non-privileged user.\n"; - } + if ($> == 0){ + printf " [W] Not all Pandora FMS components need to be executed as root\n"; + printf " please consider starting it with a non-privileged user.\n"; + } } # Check for file if ( ! -e $archivo_cfg ) { printf "\n [ERROR] Cannot open configuration file at $archivo_cfg. \n"; printf " Please specify a valid Pandora FMS configuration file in command line. \n"; - print " Standard configuration file is at /etc/pandora/pandora_server.conf \n"; + print " Standard configuration file is at /etc/pandora/pandora_server.conf \n"; exit 1; } # Collect items from config file and put in an array @@ -273,14 +273,14 @@ sub pandora_load_config { # Has read setup file ok ? if ( $ltotal == 0 ) { - print "[ERROR] No valid setup tokens readed in $archivo_cfg "; - exit; + print "[ERROR] No valid setup tokens readed in $archivo_cfg "; + exit; } for ($ax=0;$ax<=$ltotal;$ax++){ - $parametro = $args[$ax]; + $parametro = $args[$ax]; - if ($parametro =~ m/^incomingdir\s(.*)/i) { + if ($parametro =~ m/^incomingdir\s(.*)/i) { $tbuf= clean_blank($1); if ($tbuf =~ m/^\.(.*)/){ $pa_config->{"incomingdir"} =$pa_config->{"basepath"}.$1; @@ -307,7 +307,7 @@ sub pandora_load_config { } } - # MTA setup (2.0) + # MTA setup (2.0) elsif ($parametro =~ m/^mta_user\s(.*)/i) { $pa_config->{'mta_user'}= clean_blank($1); } @@ -493,8 +493,8 @@ sub pandora_load_config { $pa_config->{'export_threads'}= clean_blank($1); } elsif ($parametro =~ m/^max_queue_files\s([0-9]*)/i) { - $pa_config->{'max_queue_files'}= clean_blank($1); - } + $pa_config->{'max_queue_files'}= clean_blank($1); + } elsif ($parametro =~ m/^agentaccess\s([0-1])/i) { $pa_config->{'agentaccess'}= clean_blank($1); } @@ -502,13 +502,13 @@ sub pandora_load_config { $pa_config->{'use_xml_timestamp'} = clean_blank($1); } elsif ($parametro =~ m/^restart_delay\s+(\d+)/i) { - $pa_config->{'restart_delay'} = clean_blank($1); + $pa_config->{'restart_delay'} = clean_blank($1); } elsif ($parametro =~ m/^auto_restart\s+(\d+)/i) { - $pa_config->{'auto_restart'} = clean_blank($1); + $pa_config->{'auto_restart'} = clean_blank($1); } elsif ($parametro =~ m/^restart\s+([0-1])/i) { - $pa_config->{'restart'} = clean_blank($1); + $pa_config->{'restart'} = clean_blank($1); } } # end of loop for parameter # @@ -525,11 +525,11 @@ sub pandora_load_config { print " [*] Server threshold ".$pa_config->{"server_threshold"}."\n"; } # Check for valid token token values - if (( $pa_config->{"dbuser"} eq "" ) || ( $pa_config->{"basepath"} eq "" ) || ( $pa_config->{"incomingdir"} eq "" ) || ( $pa_config->{"logfile"} eq "" ) || ( $pa_config->{"dbhost"} eq "") || ( $pa_config->{"pandora_master"} eq "") || ( $pa_config->{"dbpass"} eq "" ) ) { + if (( $pa_config->{"dbuser"} eq "" ) || ( $pa_config->{"basepath"} eq "" ) || ( $pa_config->{"incomingdir"} eq "" ) || ( $pa_config->{"logfile"} eq "" ) || ( $pa_config->{"dbhost"} eq "") || ( $pa_config->{"pandora_master"} eq "") || ( $pa_config->{"dbpass"} eq "" ) ) { print " [ERROR] Bad Config values. Be sure that $archivo_cfg is a valid setup file. \n\n"; exit; } - + if (($pa_config->{"quiet"} == 0) && ($pa_config->{"verbosity"} > 4)) { if ($pa_config->{"pandora_check"} == 1) { print " [*] MD5 Security enabled.\n"; diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index a9f5f7bb26..c6b141405a 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -83,22 +83,22 @@ sub pandora_generate_alerts ($$$$$$$) { # Get enabled alerts associated with this module my @alerts = get_db_rows ($dbh, 'SELECT talert_template_modules.id as id_template_module, - talert_template_modules.*, talert_templates.* - FROM talert_template_modules, talert_templates - WHERE talert_template_modules.id_alert_template = talert_templates.id - AND id_agent_module = ? AND disabled = 0', $module->{'id_agente_modulo'}); + talert_template_modules.*, talert_templates.* + FROM talert_template_modules, talert_templates + WHERE talert_template_modules.id_alert_template = talert_templates.id + AND id_agent_module = ? AND disabled = 0', $module->{'id_agente_modulo'}); foreach my $alert (@alerts) { my $rc = pandora_evaluate_alert($pa_config, $agent, $data, $status, $alert, - $utimestamp, $dbh); + $utimestamp, $dbh); pandora_process_alert ($pa_config, $data, $agent, $module, - $alert, $rc, $dbh); - + $alert, $rc, $dbh); + # Evaluate compound alerts even if the alert status did not change in # case the compound alert does not recover pandora_generate_compound_alerts ($pa_config, $data, $status, $agent, $module, - $alert, $utimestamp, $dbh) + $alert, $utimestamp, $dbh) } } @@ -112,7 +112,7 @@ sub pandora_generate_alerts ($$$$$$$) { # 5 Reset internal counter (alert not fired, interval elapsed). ########################################################################## sub pandora_evaluate_alert ($$$$$$$) { - my ($pa_config, $agent, $data, $last_status, $alert, $utimestamp, $dbh) = @_; + my ($pa_config, $agent, $data, $last_status, $alert, $utimestamp, $dbh) = @_; logger ($pa_config, "Evaluating alert '" . $alert->{'name'} . "' for agent '" . $agent->{'nombre'} . "'.", 10); @@ -128,7 +128,7 @@ sub pandora_evaluate_alert ($$$$$$$) { # Check time slot my $time = sprintf ("%.2d:%.2d:%.2d", $hour, $min, $sec); return 1 if (($alert->{'time_to'} ne $alert->{'time_from'}) && - (($time ge $alert->{'time_to'}) || ($time le $alert->{'time_from'}))); + (($time ge $alert->{'time_to'}) || ($time le $alert->{'time_from'}))); # Check time threshold my $limit_utimestamp = $alert->{'last_reference'} + $alert->{'time_threshold'}; @@ -161,10 +161,10 @@ sub pandora_evaluate_alert ($$$$$$$) { if ($alert->{'type'} eq "max_min") { if ($alert->{'matches_value'} == 1) { return $status if ($data <= $alert->{'min_value'} || - $data >= $alert->{'max_value'}); + $data >= $alert->{'max_value'}); } else { return $status if ($data >= $alert->{'min_value'} && - $data <= $alert->{'max_value'}); + $data <= $alert->{'max_value'}); } } @@ -188,7 +188,7 @@ sub pandora_evaluate_alert ($$$$$$$) { # Check min and max alert limits return 2 if (($alert->{'internal_counter'} < $alert->{'min_alerts'}) || - ($alert->{'times_fired'} >= $alert->{'max_alerts'})); + ($alert->{'times_fired'} >= $alert->{'max_alerts'})); return 0; #Launch the alert } @@ -217,9 +217,9 @@ sub pandora_process_alert ($$$$$$$) { # Generate an event pandora_event ($pa_config, "Alert ceased (" . - $alert->{'name'} . ")", $agent->{'id_grupo'}, - $agent->{'id_agente'}, $alert->{'priority'}, $id, $alert->{'id_agent_module'}, - "alert_ceased", $dbh); + $alert->{'name'} . ")", $agent->{'id_grupo'}, + $agent->{'id_agente'}, $alert->{'priority'}, $id, $alert->{'id_agent_module'}, + "alert_ceased", $dbh); return; } @@ -246,7 +246,7 @@ sub pandora_process_alert ($$$$$$$) { # Do we have to start a new interval? my $new_interval = ($alert->{'internal_counter'} == 0) ? - ', last_reference = ' . $utimestamp : ''; + ', last_reference = ' . $utimestamp : ''; # Increment internal counter if ($rc == 2) { @@ -256,8 +256,8 @@ sub pandora_process_alert ($$$$$$$) { # Do not increment times_fired, but set it in case the alert was reset db_do($dbh, 'UPDATE ' . $table . ' SET times_fired = ?, - internal_counter = ? ' . $new_interval . ' WHERE id = ?', - $alert->{'times_fired'}, $alert->{'internal_counter'}, $id); + internal_counter = ? ' . $new_interval . ' WHERE id = ?', + $alert->{'times_fired'}, $alert->{'internal_counter'}, $id); return; } @@ -270,8 +270,8 @@ sub pandora_process_alert ($$$$$$$) { $alert->{'internal_counter'} += 1; db_do($dbh, 'UPDATE ' . $table . ' SET times_fired = ?, - last_fired = ?, internal_counter = ? ' . $new_interval . ' WHERE id = ?', - $alert->{'times_fired'}, $utimestamp, $alert->{'internal_counter'}, $id); + last_fired = ?, internal_counter = ? ' . $new_interval . ' WHERE id = ?', + $alert->{'times_fired'}, $utimestamp, $alert->{'internal_counter'}, $id); pandora_execute_alert ($pa_config, $data, $agent, $module, $alert, 1, $dbh); return; } @@ -291,13 +291,13 @@ sub pandora_evaluate_compound_alert ($$$$) { # Get all the alerts associated with this compound alert my @compound_alerts = get_db_rows ($dbh, 'SELECT id_alert_template_module, operation FROM talert_compound_elements - WHERE id_alert_compound = ? ORDER BY `order`', $id); + WHERE id_alert_compound = ? ORDER BY `order`', $id); foreach my $compound_alert (@compound_alerts) { # Get alert data if enabled my $times_fired = get_db_value ($dbh, "SELECT times_fired FROM talert_template_modules WHERE id = ? - AND disabled = 0", $compound_alert->{'id_alert_template_module'}); + AND disabled = 0", $compound_alert->{'id_alert_template_module'}); next unless defined ($times_fired); # Check whether the alert was fired @@ -341,8 +341,8 @@ sub pandora_generate_compound_alerts ($$$$$$$$) { # Get all compound alerts that depend on this alert my @elements = get_db_rows ($dbh, 'SELECT id_alert_compound FROM talert_compound_elements - WHERE id_alert_template_module = ?', - $alert->{'id_template_module'}); + WHERE id_alert_template_module = ?', + $alert->{'id_template_module'}); foreach my $element (@elements) { @@ -352,10 +352,10 @@ sub pandora_generate_compound_alerts ($$$$$$$$) { # Evaluate the alert my $rc = pandora_evaluate_alert ($pa_config, $agent, $data, $status, $compound_alert, - $utimestamp, $dbh); + $utimestamp, $dbh); pandora_process_alert ($pa_config, $data, $agent, $module, - $compound_alert, $rc, $dbh); + $compound_alert, $rc, $dbh); } } @@ -364,7 +364,7 @@ sub pandora_generate_compound_alerts ($$$$$$$$) { ########################################################################## sub pandora_execute_alert ($$$$$$$) { my ($pa_config, $data, $agent, $module, - $alert, $alert_mode, $dbh) = @_; + $alert, $alert_mode, $dbh) = @_; logger ($pa_config, "Executing alert '" . $alert->{'name'} . "' for module '" . $module->{'nombre'} . "'.", 10); @@ -374,29 +374,30 @@ sub pandora_execute_alert ($$$$$$$) { # Simple alert if (defined ($alert->{'id_template_module'})) { @actions = get_db_rows ($dbh, 'SELECT * FROM talert_template_module_actions, talert_actions, talert_commands - WHERE talert_template_module_actions.id_alert_action = talert_actions.id - AND talert_actions.id_alert_command = talert_commands.id - AND talert_template_module_actions.id_alert_template_module = ? - AND ((fires_min = 0 AND fires_max = 0) - OR (? >= fires_min AND ? <= fires_max))', - $alert->{'id_template_module'}, $alert->{'times_fired'}, $alert->{'times_fired'}); + WHERE talert_template_module_actions.id_alert_action = talert_actions.id + AND talert_actions.id_alert_command = talert_commands.id + AND talert_template_module_actions.id_alert_template_module = ? + AND ((fires_min = 0 AND fires_max = 0) + OR (? >= fires_min AND ? <= fires_max))', + $alert->{'id_template_module'}, $alert->{'times_fired'}, $alert->{'times_fired'}); # Get default action if ($#actions < 0) { @actions = get_db_rows ($dbh, 'SELECT * FROM talert_actions, talert_commands - WHERE talert_actions.id = ? - AND talert_actions.id_alert_command = talert_commands.id', - $alert->{'id_alert_action'}, ); + WHERE talert_actions.id = ? + AND talert_actions.id_alert_command = talert_commands.id', + $alert->{'id_alert_action'}, ); } } # Compound alert else { @actions = get_db_rows ($dbh, 'SELECT * FROM talert_compound_actions, talert_actions, talert_commands - WHERE talert_compound_actions.id_alert_action = talert_actions.id - AND talert_actions.id_alert_command = talert_commands.id - AND talert_compound_actions.id_alert_compound = ? - AND ((fires_min = 0 AND fires_max = 0) - OR (? >= fires_min AND ? <= fires_max))', $alert->{'id'}, $alert->{'times_fired'}, $alert->{'times_fired'}); + WHERE talert_compound_actions.id_alert_action = talert_actions.id + AND talert_actions.id_alert_command = talert_commands.id + AND talert_compound_actions.id_alert_compound = ? + AND ((fires_min = 0 AND fires_max = 0) + OR (? >= fires_min AND ? <= fires_max))', + $alert->{'id'}, $alert->{'times_fired'}, $alert->{'times_fired'}); } # No actions defined @@ -414,8 +415,8 @@ sub pandora_execute_alert ($$$$$$$) { my ($text, $event) = ($alert_mode == 0) ? ('recovered', 'alert_recovered') : ('fired', 'alert_fired'); pandora_event ($pa_config, "Alert $text (" . $alert->{'name'} . ") assigned to (". $module->{'nombre'} .")", - $agent->{'id_grupo'}, $agent->{'id_agente'}, $alert->{'priority'}, (defined ($alert->{'id_template_module'})) ? $alert->{'id_template_module'} : 0, - $alert->{'id_agent_module'}, $event, $dbh); + $agent->{'id_grupo'}, $agent->{'id_agente'}, $alert->{'priority'}, (defined ($alert->{'id_template_module'})) ? $alert->{'id_template_module'} : 0, + $alert->{'id_agent_module'}, $event, $dbh); } ########################################################################## @@ -423,13 +424,13 @@ sub pandora_execute_alert ($$$$$$$) { ########################################################################## sub pandora_execute_action ($$$$$$$$) { my ($pa_config, $data, $agent, $alert, - $alert_mode, $action, $module, $dbh) = @_; + $alert_mode, $action, $module, $dbh) = @_; logger($pa_config, "Executing action '" . $action->{'name'} . "' for alert '". $alert->{'name'} . "' agent '" . (defined ($agent) ? $agent->{'nombre'} : 'N/A') . "'.", 10); - my $field1 = $action->{'field1'} ne "" ? $action->{'field1'} : $alert->{'field1'}; - my $field2 = $action->{'field2'} ne "" ? $action->{'field2'} : $alert->{'field2'}; - my $field3 = $action->{'field3'} ne "" ? $action->{'field3'} : $alert->{'field3'}; + my $field1 = $action->{'field1'} ne "" ? $action->{'field1'} : $alert->{'field1'}; + my $field2 = $action->{'field2'} ne "" ? $action->{'field2'} : $alert->{'field2'}; + my $field3 = $action->{'field3'} ne "" ? $action->{'field3'} : $alert->{'field3'}; # Recovery fields, thanks to Kato Atsushi if ($alert_mode == 0){ @@ -446,23 +447,23 @@ sub pandora_execute_action ($$$$$$$$) { # Alert macros my %macros = (_field1_ => $field1, - _field2_ => $field2, - _field3_ => $field3, - _agent_ => (defined ($agent)) ? $agent->{'nombre'} : '', - _agentdescription_ => (defined ($agent)) ? $agent->{'comentarios'} : '', - _agentgroup_ => (defined ($agent)) ? get_group_name ($dbh, $agent->{'id_grupo'}) : '', - _address_ => (defined ($agent)) ? $agent->{'direccion'} : '', - _timestamp_ => strftime ("%Y-%m-%d %H:%M:%S", localtime()), - _data_ => $data, - _alert_name_ => $alert->{'name'}, - _alert_description_ => $alert->{'description'}, - _alert_threshold_ => $alert->{'time_threshold'}, - _alert_times_fired_ => $alert->{'times_fired'}, - _alert_priority_ => $alert->{'priority'}, - _module_ => (defined ($module)) ? $module->{'nombre'} : '', - _moduledescription_ => (defined ($module)) ? $module->{'descripcion'} : '', - _id_agent_ => (defined ($module)) ? $module->{'id_agente'} : '', - _id_alert_ => $alert->{'id'} + _field2_ => $field2, + _field3_ => $field3, + _agent_ => (defined ($agent)) ? $agent->{'nombre'} : '', + _agentdescription_ => (defined ($agent)) ? $agent->{'comentarios'} : '', + _agentgroup_ => (defined ($agent)) ? get_group_name ($dbh, $agent->{'id_grupo'}) : '', + _address_ => (defined ($agent)) ? $agent->{'direccion'} : '', + _timestamp_ => strftime ("%Y-%m-%d %H:%M:%S", localtime()), + _data_ => $data, + _alert_name_ => $alert->{'name'}, + _alert_description_ => $alert->{'description'}, + _alert_threshold_ => $alert->{'time_threshold'}, + _alert_times_fired_ => $alert->{'times_fired'}, + _alert_priority_ => $alert->{'priority'}, + _module_ => (defined ($module)) ? $module->{'nombre'} : '', + _moduledescription_ => (defined ($module)) ? $module->{'descripcion'} : '', + _id_agent_ => (defined ($module)) ? $module->{'id_agente'} : '', + _id_alert_ => $alert->{'id'} ); @@ -524,7 +525,7 @@ sub pandora_access_update ($$$) { ########################################################################## sub pandora_process_module ($$$$$$$$$) { my ($pa_config, $data, $agent, $module, $module_type, - $timestamp, $utimestamp, $server_id, $dbh) = @_; + $timestamp, $utimestamp, $server_id, $dbh) = @_; logger($pa_config, "Processing module '" . $module->{'nombre'} . "' for agent " . (defined ($agent) ? "'" . $agent->{'nombre'} . "'" : 'ID ' . $module->{'id_agente'}) . ".", 10); @@ -580,8 +581,8 @@ sub pandora_process_module ($$$$$$$$$) { #Update module status my $current_utimestamp = time (); my ($status_changes, $last_status) = ($status != $agent_status->{'estado'}) ? - (0, $agent_status->{'estado'}) : - ($agent_status->{'status_changes'} + 1, $agent_status->{'last_status'}); + (0, $agent_status->{'estado'}) : + ($agent_status->{'status_changes'} + 1, $agent_status->{'last_status'}); # Generate events if ($status_changes == $module->{'min_ff_event'} + 1) { @@ -598,14 +599,14 @@ sub pandora_process_module ($$$$$$$$$) { return; } - my $last_try = ($1 == 0) ? 0 : timelocal($6, $5, $4, $3, $2 - 1, $1 - 1900); + my $last_try = ($1 == 0) ? 0 : timelocal($6, $5, $4, $3, $2 - 1, $1 - 1900); my $save = ($module->{'history_data'} == 1 && ($agent_status->{'datos'} ne $processed_data || $last_try < (time() - 86400))) ? 1 : 0; db_do ($dbh, 'UPDATE tagente_estado SET datos = ?, estado = ?, last_status = ?, status_changes = ?, utimestamp = ?, timestamp = ?, - id_agente = ?, current_interval = ?, running_by = ?, last_execution_try = ?, last_try = ? - WHERE id_agente_modulo = ?', $processed_data, $status, $last_status, $status_changes, - $current_utimestamp, $timestamp, $module->{'id_agente'}, $module->{'module_interval'}, $server_id, - $utimestamp, ($save == 1) ? $timestamp : $agent_status->{'last_try'}, $module->{'id_agente_modulo'}); + id_agente = ?, current_interval = ?, running_by = ?, last_execution_try = ?, last_try = ? + WHERE id_agente_modulo = ?', $processed_data, $status, $last_status, $status_changes, + $current_utimestamp, $timestamp, $module->{'id_agente'}, $module->{'module_interval'}, $server_id, + $utimestamp, ($save == 1) ? $timestamp : $agent_status->{'last_try'}, $module->{'id_agente_modulo'}); # Save module data if ($save == 1) { @@ -669,8 +670,8 @@ sub pandora_reset_server ($$) { ########################################################################## sub pandora_update_server ($$$$$;$$) { my ($pa_config, $dbh, $server_name, $status, - $server_type, $num_threads, $queue_size) = @_; - + $server_type, $num_threads, $queue_size) = @_; + $num_threads = 0 unless defined ($num_threads); $queue_size = 0 unless defined ($queue_size); @@ -680,11 +681,11 @@ sub pandora_update_server ($$$$$;$$) { # Create an entry in tserver if (! defined ($server)){ my $server_id = db_insert ($dbh, 'INSERT INTO tserver (`name`, `server_type`, `description`, `version`, `threads`, `queued_modules`) - VALUES (?, ?, ?, ?, ?, ?)', $server_name, $server_type, - 'Autocreated at startup', $pa_config->{'version'} . ' (P) ' . $pa_config->{'build'}, $num_threads, $queue_size); + VALUES (?, ?, ?, ?, ?, ?)', $server_name, $server_type, + 'Autocreated at startup', $pa_config->{'version'} . ' (P) ' . $pa_config->{'build'}, $num_threads, $queue_size); $server = get_db_single_row ($dbh, 'SELECT * FROM tserver - WHERE id_server = ?', - $server_id); + WHERE id_server = ?', + $server_id); if (! defined ($server)) { logger($pa_config, "Server '" . $pa_config->{'servername'} . "' not found.", 3); return; @@ -696,13 +697,13 @@ sub pandora_update_server ($$$$$;$$) { my $version = $pa_config->{'version'} . ' (P) ' . $pa_config->{'build'}; db_do ($dbh, 'UPDATE tserver SET status = ?, keepalive = ?, master = ?, laststart = ?, version = ?, threads = ?, queued_modules = ? - WHERE id_server = ?', - $status, $timestamp, $pa_config->{'pandora_master'}, $timestamp, $version, $num_threads, $queue_size, $server->{'id_server'}); + WHERE id_server = ?', + $status, $timestamp, $pa_config->{'pandora_master'}, $timestamp, $version, $num_threads, $queue_size, $server->{'id_server'}); return; } db_do ($dbh, 'UPDATE tserver SET status = ?, keepalive = ?, master = ?, threads = ?, queued_modules = ? - WHERE id_server = ?', $status, $timestamp, $pa_config->{'pandora_master'}, $num_threads, $queue_size, $server->{'id_server'}); + WHERE id_server = ?', $status, $timestamp, $pa_config->{'pandora_master'}, $num_threads, $queue_size, $server->{'id_server'}); } ########################################################################## @@ -710,7 +711,7 @@ sub pandora_update_server ($$$$$;$$) { ########################################################################## sub pandora_update_agent ($$$$$$$) { my ($pa_config, $agent_timestamp, $agent_id, $os_version, - $agent_version, $agent_interval, $dbh) = @_; + $agent_version, $agent_interval, $dbh) = @_; my $timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime()); @@ -719,12 +720,12 @@ sub pandora_update_agent ($$$$$$$) { # No update for interval field (some old agents don't support it) if ($agent_interval == -1){ db_do($dbh, 'UPDATE tagente SET agent_version = ?, ultimo_contacto_remoto = ?, ultimo_contacto = ?, os_version = ? WHERE id_agente = ?', - $agent_version, $agent_timestamp, $timestamp, $os_version, $agent_id); + $agent_version, $agent_timestamp, $timestamp, $os_version, $agent_id); return; } db_do ($dbh, 'UPDATE tagente SET intervalo = ?, agent_version = ?, ultimo_contacto_remoto = ?, ultimo_contacto = ?, os_version = ? WHERE id_agente = ?', - $agent_interval, $agent_version, $agent_timestamp, $timestamp, $os_version, $agent_id); + $agent_interval, $agent_version, $agent_timestamp, $timestamp, $os_version, $agent_id); } ########################################################################## @@ -747,12 +748,12 @@ sub pandora_module_keep_alive ($$$$$) { ########################################################################## sub pandora_create_incident ($$$$$$$$) { my ($pa_config, $dbh, $title, $text, - $priority, $status, $origin, $id_group) = @_; + $priority, $status, $origin, $id_group) = @_; logger($pa_config, "Creating incident '$text' source '$origin'.", 8); db_do($dbh, 'INSERT INTO tincidencia (`inicio`, `titulo`, `descripcion`, `origen`, `estado`, `prioridad`, `id_grupo`) - VALUES (NOW(), ?, ?, ?, ?, ?, ?)', $title, $text, $origin, $status, $priority, $id_group); + VALUES (NOW(), ?, ?, ?, ?, ?, ?)', $title, $text, $origin, $status, $priority, $id_group); } @@ -769,8 +770,8 @@ sub pandora_audit ($$$$$) { my $timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime($utimestamp)); db_insert($dbh, 'INSERT INTO tsesion (`ID_usuario`, `IP_origen`, `accion`, `fecha`, `descripcion`, `utimestamp`) - VALUES (?, ?, ?, ?, ?, ?)', - 'SYSTEM', $name, $action , $timestamp , $description , $utimestamp); + VALUES (?, ?, ?, ?, ?, ?)', + 'SYSTEM', $name, $action , $timestamp , $description , $utimestamp); db_disconnect($dbh) if ($disconnect == 1); } @@ -781,7 +782,7 @@ sub pandora_audit ($$$$$) { ########################################################################## sub pandora_create_module ($$$$$$$$$$) { my ($pa_config, $agent_id, $module_type_id, $module_name, $max, - $min, $post_process, $description, $interval, $dbh) = @_; + $min, $post_process, $description, $interval, $dbh) = @_; logger($pa_config, "Creating module '$module_name' for agent ID $agent_id.", 10); @@ -792,7 +793,7 @@ sub pandora_create_module ($$$$$$$$$$) { $description = 'N/A' if ($description eq ''); my $module_id = db_insert($dbh, 'INSERT INTO tagente_modulo (`id_agente`, `id_tipo_modulo`, `nombre`, `max`, `min`, `post_process`, `descripcion`, `module_interval`, `id_modulo`) - VALUES (?, ?, ?, ?, ?, ?, ?, ?, 1)', $agent_id, $module_type_id, $module_name, $max, $min, $post_process, $description, $interval); + VALUES (?, ?, ?, ?, ?, ?, ?, ?, 1)', $agent_id, $module_type_id, $module_name, $max, $min, $post_process, $description, $interval); db_do ($dbh, 'INSERT INTO tagente_estado (`id_agente_modulo`, `id_agente`, `last_try`) VALUES (?, ?, \'0000-00-00 00:00:00\')', $module_id, $agent_id); return $module_id; } @@ -802,7 +803,7 @@ sub pandora_create_module ($$$$$$$$$$) { ########################################################################## sub pandora_create_agent ($$$$$$$$$$) { my ($pa_config, $server_name, $agent_name, $address, - $address_id, $group_id, $parent_id, $os_id, + $address_id, $group_id, $parent_id, $os_id, $description, $dbh) = @_; logger ($pa_config, "Server '$server_name' creating agent '$agent_name' address '$address'.", 10); @@ -810,7 +811,7 @@ sub pandora_create_agent ($$$$$$$$$$) { $description = "Created by $server_name" unless ($description ne ''); my $agent_id = db_insert ($dbh, 'INSERT INTO tagente (`nombre`, `direccion`, `comentarios`, `id_grupo`, `id_os`, `server_name`, `intervalo`, `id_parent`, `modo`) - VALUES (?, ?, ?, ?, ?, ?, 300, ?, 1)', $agent_name, $address, $description, $group_id, $os_id, $server_name, $parent_id); + VALUES (?, ?, ?, ?, ?, ?, 300, ?, 1)', $agent_name, $address, $description, $group_id, $os_id, $server_name, $parent_id); pandora_event ($pa_config, "Agent '$agent_name' created by $server_name", $pa_config->{'autocreate_group'}, $agent_id, 2, 0, 0, 'new_agent', $dbh); return $agent_id; @@ -830,7 +831,7 @@ sub pandora_event (%$$$$$$$$) { $id_agentmodule = 0 unless defined ($id_agentmodule); db_do ($dbh, 'INSERT INTO tevento (`id_agente`, `id_grupo`, `evento`, `timestamp`, `estado`, `utimestamp`, `event_type`, `id_agentmodule`, `id_alert_am`, `criticity`) - VALUES (?, ?, ?, ?, 0, ?, ?, ?, ?, ?)', $id_agente, $id_grupo, $evento, $timestamp, $utimestamp, $event_type, $id_agentmodule, $id_alert_am, $severity); + VALUES (?, ?, ?, ?, 0, ?, ?, ?, ?, ?)', $id_agente, $id_grupo, $evento, $timestamp, $utimestamp, $event_type, $id_agentmodule, $id_alert_am, $severity); } ########################################################################## @@ -843,7 +844,7 @@ sub pandora_update_module_on_error ($$$) { # Update last_execution_try db_do ($dbh, 'UPDATE tagente_estado SET last_execution_try = ? - WHERE id_agente_modulo = ?', time (), $id_agent_module); + WHERE id_agente_modulo = ?', time (), $id_agent_module); } ########################################################################## @@ -854,10 +855,10 @@ sub pandora_exec_forced_alerts { # Get alerts marked for forced execution (even disabled alerts) my @alerts = get_db_rows ($dbh, 'SELECT talert_template_modules.id as id_template_module, - talert_template_modules.*, talert_templates.* - FROM talert_template_modules, talert_templates - WHERE talert_template_modules.id_alert_template = talert_templates.id - AND force_execution = 1'); + talert_template_modules.*, talert_templates.* + FROM talert_template_modules, talert_templates + WHERE talert_template_modules.id_alert_template = talert_templates.id + AND force_execution = 1'); foreach my $alert (@alerts) { # Get the agent and module associated with the alert @@ -886,15 +887,15 @@ sub pandora_module_keep_alive_nd { my ($pa_config, $dbh) = @_; my @modules = get_db_rows ($dbh, 'SELECT tagente_modulo.* - FROM tagente_modulo, tagente_estado, tagente - WHERE tagente.id_agente = tagente_estado.id_agente - AND tagente.disabled = 0 - AND tagente_modulo.id_tipo_modulo = 100 - AND tagente_modulo.disabled = 0 - AND tagente_estado.datos = 1 - AND tagente_estado.estado = 0 - AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo - AND ( tagente_estado.utimestamp + (tagente.intervalo * 2) < UNIX_TIMESTAMP())'); + FROM tagente_modulo, tagente_estado, tagente + WHERE tagente.id_agente = tagente_estado.id_agente + AND tagente.disabled = 0 + AND tagente_modulo.id_tipo_modulo = 100 + AND tagente_modulo.disabled = 0 + AND tagente_estado.datos = 1 + AND tagente_estado.estado = 0 + AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo + AND ( tagente_estado.utimestamp + (tagente.intervalo * 2) < UNIX_TIMESTAMP())'); foreach my $module (@modules) { logger($pa_config, "Updating keep_alive module for module '" . $module->{'nombre'} . "' agent ID " . $module->{'id_agente'} . " (agent without data).", 10); @@ -907,7 +908,7 @@ sub pandora_module_keep_alive_nd { ########################################################################## sub pandora_evaluate_snmp_alerts ($$$$$$$$) { my ($pa_config, $trap_id, $trap_agent, $trap_oid, - $trap_oid_text, $trap_custom_oid, $trap_custom_value, $dbh) = @_; + $trap_oid_text, $trap_custom_oid, $trap_custom_value, $dbh) = @_; # Get all SNMP alerts my @snmp_alerts = get_db_rows ($dbh, 'SELECT * FROM talert_snmp'); @@ -919,7 +920,7 @@ sub pandora_evaluate_snmp_alerts ($$$$$$$$) { my ($fire_alert, $alert_data) = (0, ''); my ($times_fired, $internal_counter, $alert_type) = - ($alert->{'times_fired'}, $alert->{'internal_counter'}, $alert->{'alert_type'}); + ($alert->{'times_fired'}, $alert->{'internal_counter'}, $alert->{'alert_type'}); # OID my $oid = $alert->{'oid'}; @@ -976,37 +977,37 @@ sub pandora_evaluate_snmp_alerts ($$$$$$$$) { my %agent = ( 'nombre' => $trap_agent, - 'direccion' => $trap_agent, + 'direccion' => $trap_agent, ); # Execute alert my $action = get_db_single_row ($dbh, 'SELECT * - FROM talert_actions, talert_commands - WHERE talert_actions.id_alert_command = talert_commands.id - AND talert_actions.id = ?', $alert->{'id_alert'}); + FROM talert_actions, talert_commands + WHERE talert_actions.id_alert_command = talert_commands.id + AND talert_actions.id = ?', $alert->{'id_alert'}); - my $trap_rcv_full = $trap_oid . " " . $trap_custom_oid . " " . $trap_custom_value; + my $trap_rcv_full = $trap_oid . " " . $trap_custom_oid . " " . $trap_custom_value; pandora_execute_action ($pa_config, $trap_rcv_full, \%agent, \%alert, 1, $action, undef, $dbh) if (defined ($action)); # Generate an event pandora_event ($pa_config, "SNMP alert fired (" . $alert->{'description'} . ")", - 0, 0, $alert->{'priority'}, 0, 0, 'alert_fired', $dbh); + 0, 0, $alert->{'priority'}, 0, 0, 'alert_fired', $dbh); # Update alert status db_do ($dbh, 'UPDATE talert_snmp SET times_fired = ?, last_fired = ?, internal_counter = ? WHERE id_as = ?', - $times_fired, $timestamp, $internal_counter, $alert->{'id_as'}); + $times_fired, $timestamp, $internal_counter, $alert->{'id_as'}); db_do ($dbh, 'UPDATE ttrap SET alerted = 1, priority = ? WHERE id_trap = ?', - $alert->{'priority'}, $trap_id); + $alert->{'priority'}, $trap_id); } else { $internal_counter++; if ($internal_counter < $min_alerts){ # Now update the new value for times_fired & last_fired if we are below min limit for triggering this alert db_do ($dbh, 'UPDATE talert_snmp SET internal_counter = ?, times_fired = ?, last_fired = ? WHERE id_as = ?', - $internal_counter, $times_fired, $timestamp, $alert->{'id_as'}); + $internal_counter, $times_fired, $timestamp, $alert->{'id_as'}); } else { db_do ($dbh, 'UPDATE talert_snmp SET times_fired = ?, internal_counter = ? WHERE id_as = ?', - $times_fired, $internal_counter, $alert->{'id_as'}); + $times_fired, $internal_counter, $alert->{'id_as'}); } } } @@ -1050,13 +1051,13 @@ sub pandora_ping_latency ($$) { # Search string for macros and substitutes them with their values. ########################################################################## sub subst_alert_macros ($$) { - my ($string, $macros) = @_; + my ($string, $macros) = @_; - while ((my $macro, my $value) = each (%{$macros})) { - $string =~ s/($macro)/$value/ig; - } + while ((my $macro, my $value) = each (%{$macros})) { + $string =~ s/($macro)/$value/ig; + } - return $string; + return $string; } ########################################################################## @@ -1084,7 +1085,7 @@ sub process_data ($$$$$) { # Out of bounds return undef if (($module->{'max'} != $module->{'min'}) && - ($data > $module->{'max'} || $data < $module->{'min'})); + ($data > $module->{'max'} || $data < $module->{'min'})); # Process INC modules if ($module_type =~ m/_inc$/) { @@ -1155,19 +1156,19 @@ sub get_module_status ($$) { } if ($module_type =~ m/keep_alive/ && ($critical_min eq $critical_max)) { - ($critical_min, $critical_max) = (0, 1); - } + ($critical_min, $critical_max) = (0, 1); + } # Critical if ($critical_min ne $critical_max) { - return 1 if ($data >= $critical_min && $data < $critical_max); + return 1 if ($data >= $critical_min && $data < $critical_max); return 1 if ($data >= $critical_min && $critical_max < $critical_min); } # Warning if ($warning_min ne $warning_max) { - return 2 if ($data >= $warning_min && $data < $warning_max); - return 2 if ($data >= $warning_min && $warning_max < $warning_min); + return 2 if ($data >= $warning_min && $data < $warning_max); + return 2 if ($data >= $warning_min && $warning_max < $warning_min); } # Normal @@ -1257,11 +1258,11 @@ sub pandora_inhibit_alerts ($$$) { # Are any of the parent's critical alerts fired? my $count = get_db_value ($dbh, 'SELECT COUNT(*) FROM tagente_modulo, talert_template_modules, talert_templates - WHERE tagente_modulo.id_agente = ? - AND tagente_modulo.id_agente_modulo = talert_template_modules.id_agent_module - AND talert_template_modules.id_alert_template = talert_templates.id - AND talert_template_modules.times_fired > 0 - AND talert_templates.priority = 4', $agent->{'id_parent'}); + WHERE tagente_modulo.id_agente = ? + AND tagente_modulo.id_agente_modulo = talert_template_modules.id_agent_module + AND talert_template_modules.id_alert_template = talert_templates.id + AND talert_template_modules.times_fired > 0 + AND talert_templates.priority = 4', $agent->{'id_parent'}); return 1 if ($count > 0); # Are any of the parent's critical compound alerts fired?