From e923c9f5e01fecb10d0766064950d75d44421088 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Thu, 26 Mar 2020 14:33:56 +0100 Subject: [PATCH] minor fixes --- .../lib/PandoraFMS/DiscoveryServer.pm | 71 ++++++------------- pandora_server/lib/PandoraFMS/Recon/Base.pm | 11 +++ 2 files changed, 33 insertions(+), 49 deletions(-) diff --git a/pandora_server/lib/PandoraFMS/DiscoveryServer.pm b/pandora_server/lib/PandoraFMS/DiscoveryServer.pm index 3214e011e9..bdfe445f15 100644 --- a/pandora_server/lib/PandoraFMS/DiscoveryServer.pm +++ b/pandora_server/lib/PandoraFMS/DiscoveryServer.pm @@ -757,10 +757,8 @@ sub PandoraFMS::Recon::Base::create_wmi_modules { # Add modules to the agent if it responds to WMI. return unless ($self->wmi_responds($target)); - my $auth = $self->wmi_credentials($target); - - # Register agent. - $self->add_agent($target); + my $key = $self->wmi_credentials_key($target); + my $creds = $self->call('get_credentials', $key); # Add modules. # CPU. @@ -769,12 +767,13 @@ sub PandoraFMS::Recon::Base::create_wmi_modules { $self->add_module( $target, { - 'target' => $target, - 'query' => "SELECT LoadPercentage FROM Win32_Processor WHERE DeviceId='$cpu'", - 'auth' => $auth, - 'column' => 1, + 'ip_target' => $target, + 'snmp_oid' => "SELECT LoadPercentage FROM Win32_Processor WHERE DeviceId=\'$cpu\'", + 'plugin_user' => $creds->{'username'}, + 'plugin_pass' => $creds->{'password'}, + 'tcp_port' => 1, 'name' => "CPU Load $cpu", - 'description' => safe_input("Load for $cpu (%)"), + 'descripcion' => safe_input("Load for $cpu (%)"), 'id_tipo_modulo' => 1, 'id_modulo' => 6, 'unit' => '%', @@ -788,12 +787,13 @@ sub PandoraFMS::Recon::Base::create_wmi_modules { $self->add_module( $target, { - 'target' => $target, - 'query' => "SELECT FreePhysicalMemory, TotalVisibleMemorySize FROM Win32_OperatingSystem", - 'auth' => $auth, - 'column' => 0, + 'ip_target' => $target, + 'snmp_oid' => "SELECT FreePhysicalMemory, TotalVisibleMemorySize FROM Win32_OperatingSystem", + 'plugin_user' => $creds->{'username'}, + 'plugin_pass' => $creds->{'password'}, + 'tcp_port' => 0, 'name' => 'FreeMemory', - 'description' => safe_input('Free memory'), + 'descripcion' => safe_input('Free memory'), 'id_tipo_modulo' => 1, 'id_modulo' => 6, 'unit' => 'KB', @@ -807,12 +807,13 @@ sub PandoraFMS::Recon::Base::create_wmi_modules { $self->add_module( $target, { - 'target' => $target, - 'query' => "SELECT FreeSpace FROM Win32_LogicalDisk WHERE DeviceID='$unit'", - 'auth' => $auth, - 'column' => 1, + 'ip_target' => $target, + 'snmp_oid' => "SELECT FreeSpace FROM Win32_LogicalDisk WHERE DeviceID='$unit'", + 'plugin_user' => $creds->{'username'}, + 'plugin_pass' => $creds->{'password'}, + 'tcp_port' => 1, 'name' => "FreeDisk $unit", - 'description' => safe_input('Available disk space in kilobytes'), + 'descripcion' => safe_input('Available disk space in kilobytes'), 'id_tipo_modulo' => 1, 'id_modulo' => 6, 'unit' => 'KB', @@ -1089,6 +1090,7 @@ sub PandoraFMS::Recon::Base::report_scanned_agents($) { # Create module - Direct. my $name = $module->{'name'}; delete $module->{'name'}; + delete $module->{'description'}; $agentmodule_id = pandora_create_module_from_hash( $self->{'pa_config'}, { @@ -1104,7 +1106,7 @@ sub PandoraFMS::Recon::Base::report_scanned_agents($) { ); $module->{'name'} = $name; - + $module->{'description'} = safe_output($description); } # Restore. @@ -1501,35 +1503,6 @@ sub PandoraFMS::Recon::Base::set_parent($$$) { } -################################################################################ -# Create a WMI module for the given agent. -################################################################################ -sub PandoraFMS::Recon::Base::wmi_module { - my ($self, $agent_id, $target, $wmi_query, $wmi_auth, $column, - $module_name, $module_description, $module_type, $unit) = @_; - - # Check whether the module already exists. - my $module_id = get_agent_module_id($self->{'dbh'}, $module_name, $agent_id); - return if ($module_id > 0); - - my ($user, $pass) = ($wmi_auth ne '') ? split('%', $wmi_auth) : (undef, undef); - my %module = ( - 'descripcion' => safe_input($module_description), - 'id_agente' => $agent_id, - 'id_modulo' => 6, - 'id_tipo_modulo' => get_module_id($self->{'dbh'}, $module_type), - 'ip_target' => $target, - 'nombre' => safe_input($module_name), - 'plugin_pass' => defined($pass) ? $pass : '', - 'plugin_user' => defined($user) ? $user : '', - 'snmp_oid' => $wmi_query, - 'tcp_port' => $column, - 'unit' => defined($unit) ? $unit : '' - ); - - pandora_create_module_from_hash($self->{'pa_config'}, \%module, $self->{'dbh'}); -} - ################################################################################ # Update recon task status. ################################################################################ diff --git a/pandora_server/lib/PandoraFMS/Recon/Base.pm b/pandora_server/lib/PandoraFMS/Recon/Base.pm index 3ae1182b0e..9bf4e8e536 100644 --- a/pandora_server/lib/PandoraFMS/Recon/Base.pm +++ b/pandora_server/lib/PandoraFMS/Recon/Base.pm @@ -2135,6 +2135,15 @@ sub wmi_credentials { return $self->{'wmi_auth'}{$target}; } +################################################################################ +# Returns the credentials KEY with which the host responds to WMI queries or +# undef if it does not respond to WMI. +################################################################################ +sub wmi_credentials_key { + my ($self, $target) = @_; + return $self->{'wmi_auth_key'}{$target}; +} + ################################################################################ # Calculate WMI credentials for target, 1 if calculated, undef if cannot # connect to target. Credentials could be empty (-N) @@ -2148,6 +2157,7 @@ sub wmi_credentials_calculation { if ($rs == WMI_OK) { $self->{'wmi_auth'}{$target} = ''; + $self->{'wmi_auth_key'}{$target} = ''; return 1; } @@ -2171,6 +2181,7 @@ sub wmi_credentials_calculation { if ($rs == WMI_OK) { $self->{'wmi_auth'}{$target} = $auth; + $self->{'wmi_auth_key'}{$target} = $key_index; $self->{'wmi'}{$target} = 1; $self->{'summary'}->{'WMI'} += 1; $self->call('message', "[".$target."] WMI available.", 10);