From 35820d07ac87edceeacfc5caa6a1af4a8f5c00c4 Mon Sep 17 00:00:00 2001 From: Ramon Novoa Date: Tue, 4 Nov 2008 11:33:07 +0000 Subject: [PATCH] 2008-11-04 Ramon Novoa * lib/PandoraFMS/Config.pm, lib/PandoraFMS/DB.pm, lib/PandoraFMS/Tools.pm, bin/pandora_snmpconsole: Added support for enterprise version features. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1214 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_server/ChangeLog | 8 ++++++ pandora_server/bin/pandora_snmpconsole | 4 ++- pandora_server/lib/PandoraFMS/Config.pm | 7 +++++ pandora_server/lib/PandoraFMS/DB.pm | 8 ++++++ pandora_server/lib/PandoraFMS/Tools.pm | 36 +++++++++++++++++++++++++ 5 files changed, 62 insertions(+), 1 deletion(-) diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index cf935c6916..eac551beed 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,11 @@ +2008-11-04 Ramon Novoa + + * lib/PandoraFMS/Config.pm, + lib/PandoraFMS/DB.pm, + lib/PandoraFMS/Tools.pm, + bin/pandora_snmpconsole: Added support for enterprise version + features. + 2008-10-30 Sancho Lerena * lib/PandoraFMS/DB.pm: Some people reports problems with diff --git a/pandora_server/bin/pandora_snmpconsole b/pandora_server/bin/pandora_snmpconsole index aa467afdb8..2e8750f5d8 100755 --- a/pandora_server/bin/pandora_snmpconsole +++ b/pandora_server/bin/pandora_snmpconsole @@ -30,6 +30,7 @@ use Time::HiRes; # For high precission timedate functions (Net::Ping) use PandoraFMS::Config; use PandoraFMS::Tools; use PandoraFMS::DB; +PandoraFMS::Tools::enterprise_load (); # FLUSH in each IO (only for debug, very slooow) # ENABLED in DEBUGMODE @@ -117,7 +118,7 @@ sub pandora_snmptrapd { # open database, only ONCE. We pass reference to DBI handler ($dbh) to all subprocess my $dbh = DBI->connect("DBI:mysql:$pa_config->{'dbname'}:$pa_config->{'dbhost'}:3306",$pa_config->{'dbuser'}, $pa_config->{'dbpass'}, { RaiseError => 1, AutoCommit => 1 }); - my $trap2agent = get_db_value ("value", "tconfig", "token", "trap2agent", $dbh); + my $trap2agent = PandoraFMS::Tools::enterprise_hook('snmp_get_trap2module', [$dbh]); # Main loop for reading file while ( 1 ){ @@ -168,6 +169,7 @@ sub pandora_snmptrapd { logger ($pa_config, "[ERROR] Cannot access to database while updating SNMP Trap data",0); logger ($pa_config, "[ERROR] SQL Errorcode: $@", 2); } + PandoraFMS::Tools::enterprise_hook ('snmp_trap2agent', [defined($trap2agent) ? $trap2agent : 0, $pa_config, $source, $oid, $value, $custom_oid, $custom_value, $timestamp, $dbh]); } } sleep ($pa_config{'server_threshold'}); diff --git a/pandora_server/lib/PandoraFMS/Config.pm b/pandora_server/lib/PandoraFMS/Config.pm index afccab7e11..c558dcfb92 100644 --- a/pandora_server/lib/PandoraFMS/Config.pm +++ b/pandora_server/lib/PandoraFMS/Config.pm @@ -163,6 +163,7 @@ sub pandora_loadconfig { $pa_config->{"pluginserver"} = 0; # Introduced on 2.0 $pa_config->{"predictionserver"} = 0; # Introduced on 2.0 $pa_config->{"exportserver"} = 0; # 2.0 + $pa_config->{"inventoryserver"} = 0; # 2.1 $pa_config->{"servermode"} = ""; $pa_config->{'snmp_logfile'} = "/var/log/pandora_snmptrap.log"; $pa_config->{"network_threads"} = 5; # Fixed default @@ -183,6 +184,7 @@ sub pandora_loadconfig { $pa_config->{"wmi_timeout"} = 5; # Introduced on 2.0 $pa_config->{"compound_max_depth"} = 5; # Maximum nested compound alert depth. Not in config file. $pa_config->{"dataserver_threads"} = 3; # Introduced on 2.0 + $pa_config->{"inventory_threads"} = 5; # 2.1 # Internal MTA for alerts, each server need its own config. $pa_config->{"mta_address"} = '127.0.0.1'; # Introduced on 2.0 @@ -501,6 +503,11 @@ sub pandora_loadconfig { print " [*] You are running Pandora FMS Export Server. \n"; $parametro ="Pandora FMS Export Server"; $pa_config->{"servermode"}="_Export"; + } + if ($opmode == 8){ + print " [*] You are running Pandora FMS Inventory Server. \n"; + $parametro ="Pandora FMS Inventory Server"; + $pa_config->{"servermode"}="_Inventory"; } if ($pa_config->{"pandora_check"} == 1) { print " [*] MD5 Security enabled.\n"; diff --git a/pandora_server/lib/PandoraFMS/DB.pm b/pandora_server/lib/PandoraFMS/DB.pm index 8829810c3e..134741601c 100644 --- a/pandora_server/lib/PandoraFMS/DB.pm +++ b/pandora_server/lib/PandoraFMS/DB.pm @@ -1428,6 +1428,8 @@ sub pandora_updateserver (%$$$) { $pandorasuffix = "_WMI"; } elsif ($opmode == 7){ $pandorasuffix = "_Export"; + } elsif ($opmode == 8){ + $pandorasuffix = "_Inventory"; } else { logger ($pa_config, "Error: received a unknown server type. Aborting startup.",0); print (" [ERROR] Received a unknown server type. Aborting startup \n\n"); @@ -1476,6 +1478,8 @@ sub pandora_updateserver (%$$$) { $sql_update = "wmi_server = 1"; } elsif ($opmode == 7) { $sql_update = "export_server = 1"; + } elsif ($opmode == 8) { + $sql_update = "inventory_server = 1"; } $sql_update = "UPDATE tserver SET $sql_update $sql_update_post , status = $status, keepalive = '$timestamp', master = $pa_config->{'pandora_master'} WHERE id_server = $id_server"; @@ -2251,6 +2255,10 @@ sub export_module_data { my $tagente_modulo = get_db_free_row ("SELECT id_export, id_agente_modulo FROM tagente_modulo WHERE id_agente = " . $id_agent . " AND nombre = '" . $module_name . "'", $dbh); + if ($tagente_modulo eq '-1') { + return; + } + my $id_export = $tagente_modulo->{'id_export'}; my $id_agente_modulo = $tagente_modulo->{'id_agente_modulo'}; if ($id_export < 1) { diff --git a/pandora_server/lib/PandoraFMS/Tools.pm b/pandora_server/lib/PandoraFMS/Tools.pm index 404fad6f33..cac7e477fe 100644 --- a/pandora_server/lib/PandoraFMS/Tools.pm +++ b/pandora_server/lib/PandoraFMS/Tools.pm @@ -314,6 +314,42 @@ sub float_equal { return sprintf("%.${dp}g", $A) eq sprintf("%.${dp}g", $B); } +########################################################################## +# sub enterprise_load () +# Tries to load the PandoraEnterprise module. Must be called once before +# enterprise_hook (). +########################################################################## +sub enterprise_load () { + eval { require PandoraFMS::Enterprise; }; +} + +########################################################################## +# sub enterprise_hook ($function_name, \@arguments) +# Tries to call a PandoraEnterprise function. Returns undef if unsuccessful. +########################################################################## +sub enterprise_hook ($$) { + my $func = $_[0]; + my @args = @{$_[1]}; + my $output; + + # Temporarily disable strict refs + no strict 'refs'; + + # Prepend the package name + $func = 'PandoraFMS::Enterprise::' . $func; + + # Try to call the function + $output = eval { &$func (@args); }; + + # Check for errors + if ($@) { + return undef; + } + else { + return $output; + } +} + # End of function declaration # End of defined Code