From 70b3ac67dd875d485fc283e84b8fb316cc721c32 Mon Sep 17 00:00:00 2001 From: Ramon Novoa Date: Fri, 1 Aug 2008 11:41:59 +0000 Subject: [PATCH] 2008-08-01 Ramon Novoa * bin/pandora_wmi: Removed the timeout mechanism. * bin/pandora_plugin: Removed the timeout mechanism. pandora_exec is used instead. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@996 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_server/ChangeLog | 6 +++ pandora_server/bin/pandora_plugin | 37 +++++++++--------- pandora_server/bin/pandora_wmi | 63 ++++++++++++------------------- 3 files changed, 51 insertions(+), 55 deletions(-) diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index 02dd26be0b..7bb462eb31 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,9 @@ +2008-08-01 Ramon Novoa + + * bin/pandora_wmi: Removed the timeout mechanism. + * bin/pandora_plugin: Removed the timeout mechanism. pandora_exec is + used instead. + 2008-07-31 Ramon Novoa * util/pandora_exec: Added to repository. Perl script to control diff --git a/pandora_server/bin/pandora_plugin b/pandora_server/bin/pandora_plugin index a8df4584b3..0fb477f02d 100755 --- a/pandora_server/bin/pandora_plugin +++ b/pandora_server/bin/pandora_plugin @@ -28,6 +28,7 @@ use Date::Manip; # Needed to manipulate DateTime formats of input, output use Time::Local; # DateTime basic manipulation use threads; use threads::shared; +use HTML::Entities; # Pandora Modules use PandoraFMS::Config; @@ -54,6 +55,13 @@ $SIG{'INT'} = 'pandora_shutdown'; # Inicio del bucle principal de programa pandora_init(\%pa_config, "Pandora FMS Plugin Server"); +# Check for pandora_exec +my $pandora_exec = "pandora_exec"; +if (system("$pandora_exec > /dev/null 2>&1") != 256) { + print " [E] $pandora_exec not found.\n\n"; + exit; +} + # Read config file for Global variables pandora_loadconfig (\%pa_config, 4); @@ -330,28 +338,23 @@ sub exec_plugin_module { if ($agent_module->{'plugin_parameter'} ne "") { $plugin_command = $plugin_command . " ". $agent_module->{'plugin_parameter'}; } + + $plugin_command = decode_entities($plugin_command); + logger ($pa_config, "Executing AM # $id_am plugin command '$plugin_command'", 9); # Final command line execution is stored at "plugin_command" - eval { - alarm ($timeout); - $module_data = `$plugin_command`; - alarm(0); # Cancel the pending alarm if plugin call returns alive - $module_result = 0; # If comes here, this is a successfull exec - }; - # Timeout - if ($@ =~ /PANDORA PLUGIN SERVER TIMED OUT/) { - logger ($pa_config, "[ERROR] Plugin Task for module ".$agent_module->{'id_agente_modulo'}." causes a system timeout in exec", 1); - logger ($pa_config, "Executing plugin command '$plugin_command'", 9); - - # General error, not timed-out - } elsif ($module_result == 1) { - logger ($pa_config, "[ERROR] Plugin Task for module ".$agent_module->{'id_agente_modulo'}." causes an unknown system error", 1); - logger ($pa_config, "[ERROR] $@", 1); + $module_data = `$pandora_exec $timeout $plugin_command`; + if ($module_data eq "") { + $module_result = 1; + } else { + $module_result = 0; } - sub timed_out { - die "PANDORA PLUGIN SERVER TIMED OUT"; + # Error + if ($module_result == 1) { + logger ($pa_config, "[ERROR] Plugin Task for module ".$agent_module->{'id_agente_modulo'}." causes an unknown system error", 1); + logger ($pa_config, "[ERROR] $@", 1); } # Get current timestamp diff --git a/pandora_server/bin/pandora_wmi b/pandora_server/bin/pandora_wmi index a23824cb06..d891b8ec29 100755 --- a/pandora_server/bin/pandora_wmi +++ b/pandora_server/bin/pandora_wmi @@ -351,54 +351,41 @@ sub exec_wmi_module { $wmi_command .= " \"". $wmi_query . "\""; logger ($pa_config, "Executing AM # $id_am WMI command '$wmi_command'", 9); - eval { - alarm ($timeout); - $module_data = `$wmi_command`; - my @data = split("\n", $module_data); - my @data2 = split(/\|/, $data[2]); # get third line (containing data) + $module_data = `$wmi_command`; + my @data = split("\n", $module_data); + my @data2 = split(/\|/, $data[2]); # get third line (containing data) - # Take a specific field number from returned data. It uses tcp_port - # field from tagente_module table. + # Take a specific field number from returned data. It uses tcp_port + # field from tagente_module table. - $module_data = $data2[$agent_module -> {'tcp_port'}]; - alarm(0); # Cancel the pending alarm if plugin call returns alive + $module_data = $data2[$agent_module -> {'tcp_port'}]; - # Look for errors - if ($module_data =~ /ERROR/) { - $module_result = 1; + # Look for errors + if ($module_data =~ /ERROR/) { + $module_result = 1; + } else { + $module_result = 0; # If comes here, this is a successfull exec + } + + # Special word to know is something is OK or not, + # for example "Running". Defined by user in console. It uses snmp_community + # field from tagente_modulo. + + if ($agent_module -> {'snmp_community'} ne ""){ + my $temp_filter1 = $agent_module -> {'snmp_community'}; + if ($module_data =~ /$temp_filter1/){ + $module_data = 1; } else { - $module_result = 0; # If comes here, this is a successfull exec + $module_data = 0; } + } - # Special word to know is something is OK or not, - # for example "Running". Defined by user in console. It uses snmp_community - # field from tagente_modulo. - - if ($agent_module -> {'snmp_community'} ne ""){ - my $temp_filter1 = $agent_module -> {'snmp_community'}; - if ($module_data =~ /$temp_filter1/){ - $module_data = 1; - } else { - $module_data = 0; - } - } - }; - - # Timeout - if ($@ =~ /PANDORA WMI SERVER TIMED OUT/) { - logger ($pa_config, "[ERROR] WMI Task for module ".$agent_module->{'id_agente_modulo'}." causes a system timeout in exec", 1); - logger ($pa_config, "Executing WMI command '$wmi_command'", 9); - - # General error, not timed-out - } elsif ($module_result == 1) { + # Error + if ($module_result == 1) { logger ($pa_config, "[ERROR] Plugin Task for module ".$agent_module->{'id_agente_modulo'}." causes an unknown system error", 1); logger ($pa_config, "[ERROR] $@", 1); } - sub timed_out { - die "PANDORA WMI SERVER TIMED OUT"; - } - # Get current timestamp my $timestamp = &UnixDate("today","%Y-%m-%d %H:%M:%S"); my $utimestamp = &UnixDate("today","%s");