From 4aff58545db19e4ebcb20a0e2065bd84ab728ce9 Mon Sep 17 00:00:00 2001 From: slerena Date: Wed, 10 Feb 2010 17:32:10 +0000 Subject: [PATCH] 2010-02-10 Sancho Lerena * bin/pandora_server: Better error management, avoiding to show Enterprise loading errors, and showing in console critical errors, helping to identify silly errors like DB credentials, etc. Added usage of pandora_get_sharedconfig() to get configuration from DB. * Config.pm: Updated build. Added pandora_get_sharedconfig(). Force three config tokens to be readed from DB, using default values if cannot be readen from database (agentaccess, realtimestat and stats_interval). * Core.pm: Added new parameter to pandora_event() to pass status of the event (validated, not validated). Implemented auto-validation of low priority events: normal/ok events will be always shown as autovalidated, and warning and normal events will be validated with critical events, and when a module is restored (normal/ok), all it's warning/critical pending events will be validated. Fixed also bug with FF Threshold who doesnt' trigger events until FF + 1 instead FF value. * Server.pm, NetworkServer.pm, Dataserver.pm, ReconServer.pm: Raise event with status 0 (non validated) by default. * NetworkServer.pm: Implemented support for SNMP v3. * util/pandora_db.pm: Very important upgrade to this script. Now will delete all huge tables (tagente_datos, tagente_datos_string and tagent_acccess) using several independent blocks (by default 100) avoiding mysql locks which happen in the past. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2341 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_server/ChangeLog | 33 ++++ pandora_server/bin/pandora_server | 34 +++- pandora_server/conf/pandora_server.conf | 2 +- pandora_server/lib/PandoraFMS/Config.pm | 58 +++++-- pandora_server/lib/PandoraFMS/Core.pm | 46 ++++-- pandora_server/lib/PandoraFMS/DataServer.pm | 2 +- .../lib/PandoraFMS/NetworkServer.pm | 149 +++++++++++------- pandora_server/lib/PandoraFMS/ReconServer.pm | 2 +- pandora_server/lib/PandoraFMS/Server.pm | 6 +- pandora_server/util/pandora_db.pl | 80 +++++----- 10 files changed, 289 insertions(+), 123 deletions(-) diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index a420ba2f32..85d3539f74 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,36 @@ +2010-02-10 Sancho Lerena + + * bin/pandora_server: Better error management, avoiding to show Enterprise + loading errors, and showing in console critical errors, helping to identify + silly errors like DB credentials, etc. + Added usage of pandora_get_sharedconfig() to get configuration from DB. + + * Config.pm: Updated build. Added pandora_get_sharedconfig(). Force three + config tokens to be readed from DB, using default values if cannot be readen + from database (agentaccess, realtimestat and stats_interval). + + * Core.pm: Added new parameter to pandora_event() to pass status of the + event (validated, not validated). Implemented auto-validation of low + priority events: normal/ok events will be always shown as autovalidated, and + warning and normal events will be validated with critical events, and when + a module is restored (normal/ok), all it's warning/critical pending events + will be validated. + + Fixed also bug with FF Threshold who doesnt' trigger events until FF + 1 + instead FF value. + + * Server.pm, + NetworkServer.pm, + Dataserver.pm, + ReconServer.pm: Raise event with status 0 (non validated) by default. + + * NetworkServer.pm: Implemented support for SNMP v3. + + * util/pandora_db.pm: Very important upgrade to this script. Now will + delete all huge tables (tagente_datos, tagente_datos_string and + tagent_acccess) using several independent blocks (by default 100) avoiding + mysql locks which happen in the past. + 2010-02-08 Sancho Lerena * util/pandora_db.pl: Script upgrade to purge data in several steps diff --git a/pandora_server/bin/pandora_server b/pandora_server/bin/pandora_server index 83e16156c6..cce4e3ae2d 100755 --- a/pandora_server/bin/pandora_server +++ b/pandora_server/bin/pandora_server @@ -68,6 +68,10 @@ sub pandora_startup () { $DBH = db_connect ('mysql', $Config{'dbname'}, $Config{'dbhost'}, 3306, $Config{'dbuser'}, $Config{'dbpass'}); + # Grab config tokens shared with the console and not in the .conf + + pandora_get_sharedconfig (\%Config, $DBH); + pandora_audit (\%Config, 'Pandora FMS Server Daemon starting', 'SYSTEM', 'System', $DBH); # Load servers @@ -119,12 +123,32 @@ sub pandora_restart () { ######################################################################################## sub pandora_crash () { - logger (\%Config, 'Pandora FMS Server \'' . $Config{'servername'} . '\' unhandled error.', 1); - #print_message (\%Config, '[E] Unhandled error in "' . $Config{'servername'} . "\". See more information in logfiles at '/var/log/pandora' \n", 0); - + my $full_error = ""; + my $show_error = 0; + + # Avoid show messages about enterprise library loading failurem, VERY + # confussing. + foreach my $error_line (@_) { - logger (\%Config, '[E] \'' . $Config{'servername'} . "': $error_line", 1); - #print_message (\%Config, "[E] $error_line \n", 0); + if ($error_line !~ m/Enterprise/i){ + logger (\%Config, '[E] \'' . $Config{'servername'} . "': $error_line", 1); + } else { + $show_error = 1; + } + $full_error .= $error_line; + } + + if ($show_error == 1){ + logger (\%Config, 'Pandora FMS Server \'' . $Config{'servername'} . '\' unhandled error.', 1); + } + + # It's interesting show by console problems, not only in logs. This helps + # to solve stupid problems like Database credential problems for example + + if ($full_error !~ m/Enterprise/i) { + print_message (\%Config, ' [E] Unhandled error in "' . $Config{'servername'} . "\". See more information in logfiles at '/var/log/pandora' \n", 0); + print_message (\%Config, " Error description:\n", 0); + print_message (\%Config, $full_error, 0); } } diff --git a/pandora_server/conf/pandora_server.conf b/pandora_server/conf/pandora_server.conf index 2c4cb3a9bc..d63f2234e8 100755 --- a/pandora_server/conf/pandora_server.conf +++ b/pandora_server/conf/pandora_server.conf @@ -237,6 +237,6 @@ max_queue_files 250 # Flag to activate GIS (positional infomration for agents and maps) by default it is desactivated # activate_gis 0 - # Radius of the Error in meters to consider two gis locations as the same location. # location_error 50 + diff --git a/pandora_server/lib/PandoraFMS/Config.pm b/pandora_server/lib/PandoraFMS/Config.pm index 5a48572a09..327cf13310 100644 --- a/pandora_server/lib/PandoraFMS/Config.pm +++ b/pandora_server/lib/PandoraFMS/Config.pm @@ -33,11 +33,12 @@ our @EXPORT = qw( pandora_init pandora_load_config pandora_start_log + pandora_get_sharedconfig ); # version: Defines actual version of Pandora Server for this module only -my $pandora_version = "3.0"; -my $pandora_build = "091216"; +my $pandora_version = "3.1-dev"; +my $pandora_build = "100209"; our $VERSION = $pandora_version." ".$pandora_build; # Setup hash @@ -120,6 +121,41 @@ sub pandora_init { } } +########################################################################## +# Read some config tokens from database set by the console +########################################################################## + +sub pandora_get_sharedconfig ($$) { + my $pa_config = $_[0]; + my $dbh = $_[1]; + + my $temp; + + # Agentaccess option + + $temp = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'agentaccess'"); + if (defined($temp)) { + $pa_config->{"agentaccess"} = $temp; + } + + # Realtimestats 0 disabled, 1 enabled. + # Master servers will generate all the information (global tactical stats). + # and each server will generate it's own server stats (lag, etc). + + $temp = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'realtimestats'"); + if (defined($temp)) { + $pa_config->{"realtimestats"} = $temp; + } + + # Stats_interval option + + $temp = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'stats_interval'"); + if (defined($temp)) { + $pa_config->{"stats_interval"} = $temp; + } + +} + ########################################################################## # Read external configuration file ########################################################################## @@ -187,7 +223,6 @@ sub pandora_load_config { $pa_config->{"web_threads"} = 1; # 3.0 $pa_config->{"activate_gis"} = 0; # 3.1 $pa_config->{"location_error"} = 50; # 3.1 - $pa_config->{"max_queue_files"} = 250; # Internal MTA for alerts, each server need its own config. @@ -223,9 +258,6 @@ sub pandora_load_config { $pa_config->{'mcast_change_group'} = ''; $pa_config->{'mcast_change_port'} = ''; - # Update tagent_access - $pa_config->{"agentaccess"} = 1; - # Ignore the timestamp in the XML and use the file timestamp instead $pa_config->{'use_xml_timestamp'} = 0; @@ -238,6 +270,17 @@ sub pandora_load_config { # Restart server on error $pa_config->{'restart'} = 0; + + # ------------------------------------------------------------------------- + # This values are not stored in .conf files. + # This values should be stored in database, not in .conf files! + # Default values are set here because if they are not present in config DB + # don't get an error later. + $pa_config->{"realtimestats"} = 0; + $pa_config->{"stats_interval"} = 300; + $pa_config->{"agentaccess"} = 1; + # ------------------------------------------------------------------------- + # Check for UID0 if ($pa_config->{"quiet"} != 0){ if ($> == 0){ @@ -497,9 +540,6 @@ sub pandora_load_config { elsif ($parametro =~ m/^max_queue_files\s([0-9]*)/i) { $pa_config->{'max_queue_files'}= clean_blank($1); } - elsif ($parametro =~ m/^agentaccess\s([0-1])/i) { - $pa_config->{'agentaccess'}= clean_blank($1); - } elsif ($parametro =~ m/^use_xml_timestamp\s([0-1])/i) { $pa_config->{'use_xml_timestamp'} = clean_blank($1); } diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 165000afe1..a488365b0c 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -219,7 +219,7 @@ sub pandora_process_alert ($$$$$$$) { 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_ceased", 0, $dbh); return; } @@ -416,7 +416,7 @@ sub pandora_execute_alert ($$$$$$$) { 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); + $alert->{'id_agent_module'}, $event, 0, $dbh); } ########################################################################## @@ -585,7 +585,7 @@ sub pandora_process_module ($$$$$$$$$) { ($agent_status->{'status_changes'} + 1, $agent_status->{'last_status'}); # Generate events - if ($status_changes == $module->{'min_ff_event'} + 1) { + if ($status_changes == $module->{'min_ff_event'}) { generate_status_event ($pa_config, $processed_data, $agent, $module, $status, $last_status, $dbh); } @@ -629,7 +629,7 @@ sub pandora_planned_downtime ($$) { logger($pa_config, "Starting planned downtime '" . $downtime->{'name'} . "'.", 10); db_do($dbh, 'UPDATE tplanned_downtime SET executed = 1 WHERE id = ?', $downtime->{'id'}); - pandora_event ($pa_config, "Server ".$pa_config->{'servername'}." started planned downtime: ".$downtime->{'description'}, 0, 0, 1, 0, 0, 'system', $dbh); + pandora_event ($pa_config, "Server ".$pa_config->{'servername'}." started planned downtime: ".$downtime->{'description'}, 0, 0, 1, 0, 0, 'system', 0, $dbh); my @downtime_agents = get_db_rows($dbh, 'SELECT * FROM tplanned_downtime_agents WHERE id_downtime = ' . $downtime->{'id'}); @@ -646,7 +646,7 @@ sub pandora_planned_downtime ($$) { db_do($dbh, 'UPDATE tplanned_downtime SET executed = 0 WHERE id = ?', $downtime->{'id'}); - pandora_event ($pa_config, 'Server ' . $pa_config->{'servername'} . ' stopped planned downtime: ' . $downtime->{'description'}, 0, 0, 1, 0, 0, 'system', $dbh); + pandora_event ($pa_config, 'Server ' . $pa_config->{'servername'} . ' stopped planned downtime: ' . $downtime->{'description'}, 0, 0, 1, 0, 0, 'system', 0, $dbh); my @downtime_agents = get_db_rows($dbh, 'SELECT * FROM tplanned_downtime_agents WHERE id_downtime = ' . $downtime->{'id'}); @@ -916,7 +916,7 @@ sub pandora_create_agent ($$$$$$$$$$$;$$$$) { logger ($pa_config, "Server '$server_name' CREATED agent '$agent_name' address '$address'.", 10); # FIXME: use $group_id instead of $pa_config->{'autocreate_group'} ???? - pandora_event ($pa_config, "Agent [$agent_name] created by $server_name", $pa_config->{'autocreate_group'}, $agent_id, 2, 0, 0, 'new_agent', $dbh); + pandora_event ($pa_config, "Agent [$agent_name] created by $server_name", $pa_config->{'autocreate_group'}, $agent_id, 2, 0, 0, 'new_agent', 0, $dbh); return $agent_id; } @@ -925,7 +925,7 @@ sub pandora_create_agent ($$$$$$$$$$$;$$$$) { ########################################################################## sub pandora_event (%$$$$$$$$) { my ($pa_config, $evento, $id_grupo, $id_agente, $severity, - $id_alert_am, $id_agentmodule, $event_type, $dbh) = @_; + $id_alert_am, $id_agentmodule, $event_type, $event_status, $dbh) = @_; logger($pa_config, "Generating event '$evento' for agent ID $id_agente module ID $id_agentmodule.", 10); @@ -934,7 +934,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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', $id_agente, $id_grupo, $evento, $timestamp, $event_status, $utimestamp, $event_type, $id_agentmodule, $id_alert_am, $severity); } ########################################################################## @@ -1094,7 +1094,7 @@ sub pandora_evaluate_snmp_alerts ($$$$$$$$) { # 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', 0, $dbh); # Update alert status db_do ($dbh, 'UPDATE talert_snmp SET times_fired = ?, last_fired = ?, internal_counter = ? WHERE id_as = ?', @@ -1278,6 +1278,20 @@ sub get_module_status ($$) { return 0; } +########################################################################## +# Validate event. +# This validates all events pending to ACK for the same id_agent_module +########################################################################## +sub pandora_validate_event (%$$) { + my ($pa_config, $id_agentmodule, $dbh) = @_; + if (!defined($id_agentmodule)){ + return; + } + + logger($pa_config, "Validating events for id_agentmodule #$id_agentmodule", 10); + db_do ($dbh, 'UPDATE tevento SET estado = 1 WHERE estado = 0 AND id_agentmodule = '.$id_agentmodule); +} + ########################################################################## # Generates an event according to the change of status of a module. ########################################################################## @@ -1286,6 +1300,9 @@ sub generate_status_event ($$$$$$$) { my ($event_type, $severity); my $description = "Module " . $module->{'nombre'} . " ($data) is "; + # Mark as "validated" any previous event for this module + pandora_validate_event ($pa_config, $module->{'id_agente_modulo'}, $dbh); + # Normal if ($status == 0) { ($event_type, $severity) = ('going_down_normal', 2); @@ -1320,8 +1337,15 @@ sub generate_status_event ($$$$$$$) { } # Generate the event - pandora_event ($pa_config, $description, $agent->{'id_grupo'}, $module->{'id_agente'}, - $severity, 0, $module->{'id_agente_modulo'}, $event_type, $dbh); + if ($status != 0){ + pandora_event ($pa_config, $description, $agent->{'id_grupo'}, $module->{'id_agente'}, + $severity, 0, $module->{'id_agente_modulo'}, $event_type, 0, $dbh); + } else { + # Self validate this event if has "normal" status + pandora_event ($pa_config, $description, $agent->{'id_grupo'}, $module->{'id_agente'}, + $severity, 0, $module->{'id_agente_modulo'}, $event_type, 1, $dbh); + } + } ########################################################################## diff --git a/pandora_server/lib/PandoraFMS/DataServer.pm b/pandora_server/lib/PandoraFMS/DataServer.pm index 06105c97be..90a6dfd6dd 100644 --- a/pandora_server/lib/PandoraFMS/DataServer.pm +++ b/pandora_server/lib/PandoraFMS/DataServer.pm @@ -144,7 +144,7 @@ sub data_consumer ($$) { } rename($file_name, $file_name . '_BADXML'); - pandora_event ($pa_config, "Unable to process XML data file ($file_name)", 0, 0, 0, 0, 0, 'error', $dbh); + pandora_event ($pa_config, "Unable to process XML data file ($file_name)", 0, 0, 0, 0, 0, 'error', 0, $dbh); } ############################################################################### diff --git a/pandora_server/lib/PandoraFMS/NetworkServer.pm b/pandora_server/lib/PandoraFMS/NetworkServer.pm index 502bd019b8..5ee1e6bf2f 100644 --- a/pandora_server/lib/PandoraFMS/NetworkServer.pm +++ b/pandora_server/lib/PandoraFMS/NetworkServer.pm @@ -240,37 +240,75 @@ next_pair: } ########################################################################## -# SUB pandora_query_snmp (pa_config, oid, community, target, version, error, dbh) +# SUB pandora_query_snmp (pa_config, module) # Makes a call to SNMP modules to get a value, ########################################################################## -sub pandora_query_snmp (%$$$$$) { - my $pa_config = $_[0]; - my $snmp_oid = $_[1]; - my $snmp_community =$_[2]; - my $snmp_target = $_[3]; - my $snmp_version = $_[4]; - # $_[5] contains error var. +sub pandora_query_snmp (%$) { + my $pa_config = $_[0]; + my $module = $_[1]; + + my $snmp_version = $module->{"tcp_send"}; # (1, 2, 2c or 3) + my $snmp3_privacy_method = $module->{"custom_string_1"}; # DES/AES + my $snmp3_privacy_pass = $module->{"custom_string_2"}; + my $snmp3_security_level = $module->{"custom_string_3"}; # noAuthNoPriv|authNoPriv|authPriv + my $snmp3_auth_user = $module->{"plugin_user"}; + my $snmp3_auth_pass = $module->{"plugin_pass"}; + my $snmp3_auth_method = $module->{"plugin_parameter"}; #MD5/SHA1 + my $snmp_community = $module->{"snmp_community"}; + my $snmp_target = $module->{"ip_target"}; + my $snmp_oid = $module->{"snmp_oid"}; + + my $snmp_timeout = $pa_config->{"snmp_timeout"}; + my $snmp_retries = $pa_config->{'snmp_checks'}; + + my $module_result = 1; # by default error + my $module_data = 0; + my $output; # Command output + + # If not defined, always snmp v1 (standard) if ($snmp_version ne '1' && $snmp_version ne '2' && $snmp_version ne '2c' && $snmp_version ne '3') { $snmp_version = '1'; } - my $snmp_timeout = $pa_config->{"snmp_timeout"}; - my $snmp_retries = $pa_config->{'snmp_checks'}; - - # TODO: Alternative version if command is not available or user select a new switch - # with "use internal SNMP" option. At this moment, due to locks() external snmp is much faster - - $_[5] = 0; my $snmpget_cmd = $pa_config->{"snmpget"}; - my $output = ""; - $output = `$snmpget_cmd -v $snmp_version -r $snmp_retries -t $snmp_timeout -OUevqt -c $snmp_community $snmp_target $snmp_oid 2>/dev/null`; - if ($output eq ""){ - $_[5] = 1; + + # SNMP v1, v2 and v2c call + if ($snmp_version ne '3'){ + + $output = `$snmpget_cmd -v $snmp_version -r $snmp_retries -t $snmp_timeout -OUevqt -c $snmp_community $snmp_target $snmp_oid 2>/dev/null`; + if ($output ne ""){ + $module_result = 0; + $module_data = $output; + } + } else { + + # SNMP v3 has a very different command syntax + + my $snmp3_extra = ""; + my $snmp3_execution; + + # SNMP v3 authentication only + if ($snmp3_security_level eq "authNoPriv"){ + $snmp3_extra = " -a $snmp3_auth_method -u $snmp3_auth_user -A $snmp3_auth_pass "; + } + + # SNMP v3 privacy AND authentication + if ($snmp3_security_level eq "authPriv"){ + $snmp3_extra = " -a $snmp3_auth_method -u $snmp3_auth_user -A $snmp3_auth_pass -x $snmp3_privacy_method -X $snmp3_privacy_pass "; + } + + $snmp3_execution = "$snmpget_cmd -v $snmp_version -r $snmp_retries -t $snmp_timeout -OUevqt -l $snmp3_security_level $snmp3_extra $snmp_target $snmp_oid 2>/dev/null"; + + $output = `$snmp3_execution`; + if ($output ne ""){ + $module_result = 0; + $module_data = $output; + } } - return $output; + return ($module_data, $module_result); } ########################################################################## @@ -308,43 +346,45 @@ sub exec_network_module ($$$$) { if ((defined($ip_target)) && ($ip_target)) { + # ------------------------------------------------------- # ICMP Modules - # ------------ - if ($id_tipo_modulo == 6){ # ICMP (Connectivity only: Boolean) - $module_data = pandora_ping ($pa_config, $ip_target); - $module_result = 0; # Successful - } elsif ($id_tipo_modulo == 7){ # ICMP (data for latency in ms) - $module_data = pandora_ping_latency ($pa_config, $ip_target); + # ------------------------------------------------------- + + if ($id_tipo_modulo == 6){ # ICMP (Connectivity only: Boolean) + $module_data = pandora_ping ($pa_config, $ip_target); $module_result = 0; # Successful - # SNMP Modules (Proc=18, inc, data, string) - # ------------ - } elsif (($id_tipo_modulo == 15) || ($id_tipo_modulo == 18) || ($id_tipo_modulo == 16) || ($id_tipo_modulo == 17)) { # SNMP module - if ((defined($snmp_oid)) && ($snmp_oid ne "") && (defined($snmp_community)) && ($snmp_community ne "")) { # Port check - $temp2 = pandora_query_snmp ($pa_config, $snmp_oid, $snmp_community, $ip_target, $tcp_send, $error); - } else { - $error = 1 - } - if ($error == 0) { # A correct SNMP Query - $module_result = 0; + } + elsif ($id_tipo_modulo == 7){ # ICMP (data for latency in ms) + $module_data = pandora_ping_latency ($pa_config, $ip_target); + $module_result = 0; # Successful + } + + # ------------------------------------------------------- + # SNMP Modules (Proc=18, inc, data, string) + # ------------------------------------------------------- + + elsif (($id_tipo_modulo == 15) || + ($id_tipo_modulo == 18) || + ($id_tipo_modulo == 16) || + ($id_tipo_modulo == 17)) { + + ($module_data, $module_result) = pandora_query_snmp ($pa_config, $module); + + if ($module_result == 0) { # A correct SNMP Query # SNMP_DATA_PROC if ($id_tipo_modulo == 18){ #snmp_data_proc # RFC1213-MIB where it says that: SYNTAX INTEGER { up(1), down(2), testing(3), # unknown(4), dormant(5), notPresent(6), lowerLayerDown(7) } - if ($temp2 != 1){ # up state is 1, down state in SNMP is 2 .... - $temp2 = 0; + if ($module_data != 1){ # up state is 1, down state in SNMP is 2 .... + $module_data = 0; } - $module_data = $temp2; } # SNMP_DATA and SNMP_DATA_INC elsif (($id_tipo_modulo == 15) || ($id_tipo_modulo == 16) ){ - if (!is_numeric($temp2)){ + if (!is_numeric($module_data)){ $module_result = 1; - } else { - $module_data = $temp2; } - } else { # String SNMP - $module_data = $temp2; - } + } } else { # Failed SNMP-GET $module_data = 0; if ($id_tipo_modulo == 18){ # snmp_proc @@ -352,16 +392,19 @@ sub exec_network_module ($$$$) { # this is a fail monitor if ($pa_config->{"snmp_proc_deadresponse"} eq "1"){ $module_result = 0; - } else { - $module_result = 1; - } - } else { - $module_result = 1; # No data, cannot connect - } + $module_data = 0; + } + } } + } + + # ------------------------------------------------------- # TCP Module - # ---------- - } elsif (($id_tipo_modulo == 8) || ($id_tipo_modulo == 9) || ($id_tipo_modulo == 10) || ($id_tipo_modulo == 11)) { # TCP Module + # ------------------------------------------------------- + elsif (($id_tipo_modulo == 8) || + ($id_tipo_modulo == 9) || + ($id_tipo_modulo == 10) || + ($id_tipo_modulo == 11)) { # TCP Module if ((defined($tcp_port)) && ($tcp_port < 65536) && ($tcp_port > 0)) { # Port check pandora_query_tcp ($pa_config, $tcp_port, $ip_target, \$module_result, \$module_data, $tcp_send, $tcp_rcv, $id_tipo_modulo); } else { diff --git a/pandora_server/lib/PandoraFMS/ReconServer.pm b/pandora_server/lib/PandoraFMS/ReconServer.pm index d62b2c8819..b4fe0f6bf6 100644 --- a/pandora_server/lib/PandoraFMS/ReconServer.pm +++ b/pandora_server/lib/PandoraFMS/ReconServer.pm @@ -177,7 +177,7 @@ sub data_consumer ($$) { # Generate an event pandora_event ($pa_config, "[RECON] New host [$host_name] detected on network [" . $task->{'subnet'} . ']', - $task->{'id_group'}, $agent_id, 2, 0, 0, 'recon_host_detected', $dbh); + $task->{'id_group'}, $agent_id, 2, 0, 0, 'recon_host_detected', 0, $dbh); } # Create an incident diff --git a/pandora_server/lib/PandoraFMS/Server.pm b/pandora_server/lib/PandoraFMS/Server.pm index 95d44fe15e..b9176cfaf9 100644 --- a/pandora_server/lib/PandoraFMS/Server.pm +++ b/pandora_server/lib/PandoraFMS/Server.pm @@ -219,7 +219,7 @@ sub upEvent ($) { return unless defined ($self->{'_dbh'}); pandora_event ($self->{'_pa_config'}, $self->{'_pa_config'}->{'servername'} . $ServerTypes[$self->{'_server_type'}] . ' going UP', - 0, 0, 3, 0, 0, 'system', $self->{'_dbh'}); + 0, 0, 3, 0, 0, 'system', 0, $self->{'_dbh'}); } ######################################################################################## @@ -231,7 +231,7 @@ sub downEvent ($) { return unless defined ($self->{'_dbh'}); pandora_event ($self->{'_pa_config'}, $self->{'_pa_config'}->{'servername'} . $ServerTypes[$self->{'_server_type'}] . ' going DOWN', - 0, 0, 4, 0, 0, 'system', $self->{'_dbh'}); + 0, 0, 4, 0, 0, 'system', 0, $self->{'_dbh'}); } ######################################################################################## @@ -244,7 +244,7 @@ sub restartEvent ($$) { eval { pandora_event ($self->{'_pa_config'}, $self->{'_pa_config'}->{'servername'} . $ServerTypes[$self->{'_server_type'}] . " RESTARTING" . (defined ($msg) ? " ($msg)" : ''), - 0, 0, 4, 0, 0, 'system', $self->{'_dbh'}); + 0, 0, 4, 0, 0, 'system', 0, $self->{'_dbh'}); }; } diff --git a/pandora_server/util/pandora_db.pl b/pandora_server/util/pandora_db.pl index 0cb68d037f..453ab78d2a 100755 --- a/pandora_server/util/pandora_db.pl +++ b/pandora_server/util/pandora_db.pl @@ -19,14 +19,14 @@ # Includes list use strict; -use Time::Local; # DateTime basic manipulation +use Time::Local; # DateTime basic manipulation use DBI; # DB interface with MySQL use PandoraFMS::Tools; use PandoraFMS::DB; use POSIX qw(strftime); # version: define current version -my $version = "3.0 PS100203"; +my $version = "3.1 PS100209"; # Pandora server configuration my %conf; @@ -83,26 +83,10 @@ sub pandora_purgedb ($$) { my $total_time; my $purge_steps; - print "[PURGE] Deleting old event data (More than " . $conf->{'_days_purge'} . " days)... \n"; - $dbh->do("DELETE FROM tevento WHERE utimestamp < '$ulimit_timestamp'"); - - - print "[PURGE] Delete pending deleted modules (data table)...\n"; - $dbh->do ("DELETE FROM tagente_datos WHERE id_agente_modulo IN (SELECT id_agente_modulo FROM tagente_modulo WHERE delete_pending = 1)"); - - print "[PURGE] Delete pending deleted modules (data string table)...\n"; - $dbh->do ("DELETE FROM tagente_datos_string WHERE id_agente_modulo IN (SELECT id_agente_modulo FROM tagente_modulo WHERE delete_pending = 1)"); - - print "[PURGE] Delete pending deleted modules (data inc table)...\n"; - $dbh->do ("DELETE FROM tagente_datos_inc WHERE id_agente_modulo IN (SELECT id_agente_modulo FROM tagente_modulo WHERE delete_pending = 1)"); - - print "[PURGE] Delete pending deleted modules (status, module table)...\n"; - $dbh->do ("DELETE FROM tagente_estado WHERE id_agente_modulo IN (SELECT id_agente_modulo FROM tagente_modulo WHERE delete_pending = 1)"); - $dbh->do ("DELETE FROM tagente_modulo WHERE delete_pending = 1"); - print "[PURGE] Deleting old data... \n"; - # This could be very timing consuming, so make this operation in $BIG_OPERATION_STEP steps (50 fixed by default) + # This could be very timing consuming, so make this operation in $BIG_OPERATION_STEP + # steps (100 fixed by default) # Starting from the oldest record on the table $first_mark = get_db_value ($dbh, 'SELECT utimestamp FROM tagente_datos ORDER BY utimestamp ASC LIMIT 1'); @@ -111,29 +95,47 @@ sub pandora_purgedb ($$) { for (my $ax = 1; $ax <= $BIG_OPERATION_STEP; $ax++){ - $dbh->do ("DELETE FROM tagente_datos WHERE utimestamp < ". ($first_mark + ($purge_steps * $ax)) . " AND utimestamp > ". $first_mark ); - $dbh->do ("DELETE FROM tagente_datos_string WHERE utimestamp < ". ($first_mark + ($purge_steps * $ax)) . " AND utimestamp > ". $first_mark ); - + db_do ($dbh, "DELETE FROM tagente_datos WHERE utimestamp < ". ($first_mark + ($purge_steps * $ax)) . " AND utimestamp > ". $first_mark ); + db_do ($dbh, "DELETE FROM tagente_datos_string WHERE utimestamp < ". ($first_mark + ($purge_steps * $ax)) . " AND utimestamp > ". $first_mark ); + print "[PURGE] Data deletion Progress %$ax .. \n"; } + print "[PURGE] Deleting old event data (More than " . $conf->{'_days_purge'} . " days)... \n"; + db_do($dbh, "DELETE FROM tevento WHERE utimestamp < '$ulimit_timestamp'"); + + print "[PURGE] Delete pending deleted modules (data table)...\n"; + + my @deleted_modules = get_db_rows ($dbh, 'SELECT id_agente_modulo FROM tagente_modulo WHERE delete_pending = 1'); + + foreach my $module (@deleted_modules) { + print " Deleting data for module " . $module->{'id_agente_modulo'} . "\n"; + db_do ($dbh, "DELETE FROM tagente_datos WHERE id_agente_modulo = ?", $module->{'id_agente_modulo'}); + db_do ($dbh, "DELETE FROM tagente_datos_string WHERE id_agente_modulo = ?", $module->{'id_agente_modulo'}); + db_do ($dbh, "DELETE FROM tagente_datos_inc WHERE id_agente_modulo = ?", $module->{'id_agente_modulo'}); + + } + + print "[PURGE] Delete pending deleted modules (status, module table)...\n"; + db_do ($dbh, "DELETE FROM tagente_estado WHERE id_agente_modulo IN (SELECT id_agente_modulo FROM tagente_modulo WHERE delete_pending = 1)"); + db_do ($dbh, "DELETE FROM tagente_modulo WHERE delete_pending = 1"); + print "[PURGE] Delete old session data \n"; - $dbh->do ("DELETE FROM tsesion WHERE utimestamp < $ulimit_timestamp"); + db_do ($dbh, "DELETE FROM tsesion WHERE utimestamp < $ulimit_timestamp"); print "[PURGE] Delete old data from SNMP Traps \n"; - $dbh->do ("DELETE FROM ttrap WHERE timestamp < '$limit_timestamp'"); + db_do ($dbh, "DELETE FROM ttrap WHERE timestamp < '$limit_timestamp'"); print "[PURGE] Deleting old access data (More than 24hr) \n"; - #$dbh->do("DELETE FROM tagent_access WHERE utimestamp < '$ulimit_access_timestamp'"); $first_mark = get_db_value ($dbh, 'SELECT utimestamp FROM tagent_access ORDER BY utimestamp ASC LIMIT 1'); - $total_time = $ulimit_access_timestamp - $first_mark; - $purge_steps = int( $total_time / $BIG_OPERATION_STEP); - + $total_time = $ulimit_access_timestamp - $first_mark; + $purge_steps = int( $total_time / $BIG_OPERATION_STEP); + for (my $ax = 1; $ax <= $BIG_OPERATION_STEP; $ax++){ - $dbh->do ("DELETE FROM tagent_access WHERE utimestamp < ". ( $first_mark + ($purge_steps * $ax)) . " AND utimestamp > ". $first_mark); - print "[PURGE] Agent access deletion progress %$ax .. \n"; - } + db_do ($dbh, "DELETE FROM tagent_access WHERE utimestamp < ". ( $first_mark + ($purge_steps * $ax)) . " AND utimestamp > ". $first_mark); + print "[PURGE] Agent access deletion progress %$ax .. \n"; + } } @@ -386,19 +388,19 @@ sub pandoradb_main ($$$) { print "Starting at ". strftime ("%Y-%m-%d %H:%M:%S", localtime()) . "\n"; - # Move old data to the history DB - if (defined ($history_dbh)) { - undef ($history_dbh) unless defined (enterprise_hook ('pandora_historydb', [$dbh, $history_dbh, $conf->{'_history_db_days'}, $conf->{'_history_db_step'}, $conf->{'_history_db_delay'}])); - } - # Purge pandora_purgedb ($conf, $dbh); # Consistency check pandora_checkdb_consistency ($dbh); - # Compact - if ($conf->{'_onlypurge'} == 0) { + # Move old data to the history DB + if (defined ($history_dbh)) { + undef ($history_dbh) unless defined (enterprise_hook ('pandora_historydb', [$dbh, $history_dbh, $conf->{'_history_db_days'}, $conf->{'_history_db_step'}, $conf->{'_history_db_delay'}])); + } + + # Compact on if enable and DaysCompact are below DaysPurge + if (($conf->{'_onlypurge'} == 0) && ($conf->{'_days_compact'} < $conf->{'_days_purge'})) { pandora_compactdb ($conf, defined ($history_dbh) ? $history_dbh : $dbh); }