2019-02-13 14:56:10 +01:00
package PandoraFMS::DiscoveryServer ;
2009-04-14 Ramon Novoa <rnovoa@artica.es>
* pandora_ctl, pandora_network, pandora_wmi, pandora_plugin,
pandora_prediction, bin/pandora_wmi, bin/pandora_plugin,
bin/pandora_prediction, bin/pandora_snmpconsole, bin/pandora_recon,
bin/pandora_network, pandora_recon, pandora_snmpconsole: Deleted
from repository. Old server code and startup scripts.
* Makefile.PL, pandora_server_installer, lib/PandoraFMS/Config.pm
lib/PandoraFMS/DB.pm, lib/PandoraFMS/Tools.pm, bin/pandora_server,
pandora_package_installer, pandora_server: Updated to work with the
new code, removed unneeded dependencies, fixed some bugs etc.
* lib/PandoraFMS/SNMPServer.pm, lib/PandoraFMS/PluginServer.pm,
lib/PandoraFMS/ProducerConsumerServer.pm, lib/PandoraFMS/Server.pm,
lib/PandoraFMS/PredictionServer.pm, lib/PandoraFMS/Core.pm,
lib/PandoraFMS/ReconServer.pm, lib/PandoraFMS/DataServer.pm,
lib/PandoraFMS/NetworkServer.pm, lib/PandoraFMS/WMIServer.pm: Added
to repository. New server code.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1620 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-04-14 21:13:16 +02:00
##########################################################################
2019-02-13 14:56:10 +01:00
# Pandora FMS Discovery Server.
2009-04-14 Ramon Novoa <rnovoa@artica.es>
* pandora_ctl, pandora_network, pandora_wmi, pandora_plugin,
pandora_prediction, bin/pandora_wmi, bin/pandora_plugin,
bin/pandora_prediction, bin/pandora_snmpconsole, bin/pandora_recon,
bin/pandora_network, pandora_recon, pandora_snmpconsole: Deleted
from repository. Old server code and startup scripts.
* Makefile.PL, pandora_server_installer, lib/PandoraFMS/Config.pm
lib/PandoraFMS/DB.pm, lib/PandoraFMS/Tools.pm, bin/pandora_server,
pandora_package_installer, pandora_server: Updated to work with the
new code, removed unneeded dependencies, fixed some bugs etc.
* lib/PandoraFMS/SNMPServer.pm, lib/PandoraFMS/PluginServer.pm,
lib/PandoraFMS/ProducerConsumerServer.pm, lib/PandoraFMS/Server.pm,
lib/PandoraFMS/PredictionServer.pm, lib/PandoraFMS/Core.pm,
lib/PandoraFMS/ReconServer.pm, lib/PandoraFMS/DataServer.pm,
lib/PandoraFMS/NetworkServer.pm, lib/PandoraFMS/WMIServer.pm: Added
to repository. New server code.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1620 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-04-14 21:13:16 +02:00
# Pandora FMS. the Flexible Monitoring System. http://www.pandorafms.org
##########################################################################
2009-06-08 17:12:32 +02:00
# Copyright (c) 2005-2009 Artica Soluciones Tecnologicas S.L
2009-04-14 Ramon Novoa <rnovoa@artica.es>
* pandora_ctl, pandora_network, pandora_wmi, pandora_plugin,
pandora_prediction, bin/pandora_wmi, bin/pandora_plugin,
bin/pandora_prediction, bin/pandora_snmpconsole, bin/pandora_recon,
bin/pandora_network, pandora_recon, pandora_snmpconsole: Deleted
from repository. Old server code and startup scripts.
* Makefile.PL, pandora_server_installer, lib/PandoraFMS/Config.pm
lib/PandoraFMS/DB.pm, lib/PandoraFMS/Tools.pm, bin/pandora_server,
pandora_package_installer, pandora_server: Updated to work with the
new code, removed unneeded dependencies, fixed some bugs etc.
* lib/PandoraFMS/SNMPServer.pm, lib/PandoraFMS/PluginServer.pm,
lib/PandoraFMS/ProducerConsumerServer.pm, lib/PandoraFMS/Server.pm,
lib/PandoraFMS/PredictionServer.pm, lib/PandoraFMS/Core.pm,
lib/PandoraFMS/ReconServer.pm, lib/PandoraFMS/DataServer.pm,
lib/PandoraFMS/NetworkServer.pm, lib/PandoraFMS/WMIServer.pm: Added
to repository. New server code.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1620 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-04-14 21:13:16 +02:00
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public License
# as published by the Free Software Foundation; version 2
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
##########################################################################
use strict ;
use warnings ;
use threads ;
use threads::shared ;
use Thread::Semaphore ;
use IO::Socket::INET ;
2009-04-20 11:44:24 +02:00
use POSIX qw( strftime ceil ) ;
2014-04-22 11:22:08 +02:00
use JSON qw( decode_json encode_json ) ;
2014-05-08 07:12:08 +02:00
use Encode qw( encode_utf8 ) ;
2009-04-14 Ramon Novoa <rnovoa@artica.es>
* pandora_ctl, pandora_network, pandora_wmi, pandora_plugin,
pandora_prediction, bin/pandora_wmi, bin/pandora_plugin,
bin/pandora_prediction, bin/pandora_snmpconsole, bin/pandora_recon,
bin/pandora_network, pandora_recon, pandora_snmpconsole: Deleted
from repository. Old server code and startup scripts.
* Makefile.PL, pandora_server_installer, lib/PandoraFMS/Config.pm
lib/PandoraFMS/DB.pm, lib/PandoraFMS/Tools.pm, bin/pandora_server,
pandora_package_installer, pandora_server: Updated to work with the
new code, removed unneeded dependencies, fixed some bugs etc.
* lib/PandoraFMS/SNMPServer.pm, lib/PandoraFMS/PluginServer.pm,
lib/PandoraFMS/ProducerConsumerServer.pm, lib/PandoraFMS/Server.pm,
lib/PandoraFMS/PredictionServer.pm, lib/PandoraFMS/Core.pm,
lib/PandoraFMS/ReconServer.pm, lib/PandoraFMS/DataServer.pm,
lib/PandoraFMS/NetworkServer.pm, lib/PandoraFMS/WMIServer.pm: Added
to repository. New server code.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1620 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-04-14 21:13:16 +02:00
2010-05-19 Ramon Novoa <rnovoa@artica.es>
* lib/PandoraFMS/SNMPServer.pm, lib/PandoraFMS/Config.pm,
lib/PandoraFMS/Server.pm, lib/PandoraFMS/NetworkServer.pm,
lib/PandoraFMS/GIS.pm, lib/PandoraFMS/WMIServer.pm,
lib/PandoraFMS/PluginServer.pm, lib/PandoraFMS/ProducerConsumerServer.pm,
lib/PandoraFMS/PredictionServer.pm, lib/PandoraFMS/Core.pm,
lib/PandoraFMS/ReconServer.pm, lib/PandoraFMS/DataServer.pm,
bin/pandora_server, util/pandora_db.pl, util/gpx2pandora_agent_data.pl,
util/pandora_manage.pl, util/pandora_dbstress.pl: Added the default library path
used by RPM and DEB packages.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2755 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2010-05-19 18:59:00 +02:00
# Default lib dir for RPM and DEB packages
use lib '/usr/lib/perl5' ;
2009-04-14 Ramon Novoa <rnovoa@artica.es>
* pandora_ctl, pandora_network, pandora_wmi, pandora_plugin,
pandora_prediction, bin/pandora_wmi, bin/pandora_plugin,
bin/pandora_prediction, bin/pandora_snmpconsole, bin/pandora_recon,
bin/pandora_network, pandora_recon, pandora_snmpconsole: Deleted
from repository. Old server code and startup scripts.
* Makefile.PL, pandora_server_installer, lib/PandoraFMS/Config.pm
lib/PandoraFMS/DB.pm, lib/PandoraFMS/Tools.pm, bin/pandora_server,
pandora_package_installer, pandora_server: Updated to work with the
new code, removed unneeded dependencies, fixed some bugs etc.
* lib/PandoraFMS/SNMPServer.pm, lib/PandoraFMS/PluginServer.pm,
lib/PandoraFMS/ProducerConsumerServer.pm, lib/PandoraFMS/Server.pm,
lib/PandoraFMS/PredictionServer.pm, lib/PandoraFMS/Core.pm,
lib/PandoraFMS/ReconServer.pm, lib/PandoraFMS/DataServer.pm,
lib/PandoraFMS/NetworkServer.pm, lib/PandoraFMS/WMIServer.pm: Added
to repository. New server code.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1620 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-04-14 21:13:16 +02:00
use PandoraFMS::Tools ;
use PandoraFMS::DB ;
use PandoraFMS::Core ;
use PandoraFMS::ProducerConsumerServer ;
2018-07-05 15:01:23 +02:00
use PandoraFMS::GIS ;
2017-03-13 11:13:45 +01:00
use PandoraFMS::Recon::Base ;
2009-04-14 Ramon Novoa <rnovoa@artica.es>
* pandora_ctl, pandora_network, pandora_wmi, pandora_plugin,
pandora_prediction, bin/pandora_wmi, bin/pandora_plugin,
bin/pandora_prediction, bin/pandora_snmpconsole, bin/pandora_recon,
bin/pandora_network, pandora_recon, pandora_snmpconsole: Deleted
from repository. Old server code and startup scripts.
* Makefile.PL, pandora_server_installer, lib/PandoraFMS/Config.pm
lib/PandoraFMS/DB.pm, lib/PandoraFMS/Tools.pm, bin/pandora_server,
pandora_package_installer, pandora_server: Updated to work with the
new code, removed unneeded dependencies, fixed some bugs etc.
* lib/PandoraFMS/SNMPServer.pm, lib/PandoraFMS/PluginServer.pm,
lib/PandoraFMS/ProducerConsumerServer.pm, lib/PandoraFMS/Server.pm,
lib/PandoraFMS/PredictionServer.pm, lib/PandoraFMS/Core.pm,
lib/PandoraFMS/ReconServer.pm, lib/PandoraFMS/DataServer.pm,
lib/PandoraFMS/NetworkServer.pm, lib/PandoraFMS/WMIServer.pm: Added
to repository. New server code.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1620 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-04-14 21:13:16 +02:00
2011-08-24 20:07:59 +02:00
# Patched Nmap::Parser. See http://search.cpan.org/dist/Nmap-Parser/.
use PandoraFMS::NmapParser ;
2009-04-14 Ramon Novoa <rnovoa@artica.es>
* pandora_ctl, pandora_network, pandora_wmi, pandora_plugin,
pandora_prediction, bin/pandora_wmi, bin/pandora_plugin,
bin/pandora_prediction, bin/pandora_snmpconsole, bin/pandora_recon,
bin/pandora_network, pandora_recon, pandora_snmpconsole: Deleted
from repository. Old server code and startup scripts.
* Makefile.PL, pandora_server_installer, lib/PandoraFMS/Config.pm
lib/PandoraFMS/DB.pm, lib/PandoraFMS/Tools.pm, bin/pandora_server,
pandora_package_installer, pandora_server: Updated to work with the
new code, removed unneeded dependencies, fixed some bugs etc.
* lib/PandoraFMS/SNMPServer.pm, lib/PandoraFMS/PluginServer.pm,
lib/PandoraFMS/ProducerConsumerServer.pm, lib/PandoraFMS/Server.pm,
lib/PandoraFMS/PredictionServer.pm, lib/PandoraFMS/Core.pm,
lib/PandoraFMS/ReconServer.pm, lib/PandoraFMS/DataServer.pm,
lib/PandoraFMS/NetworkServer.pm, lib/PandoraFMS/WMIServer.pm: Added
to repository. New server code.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1620 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-04-14 21:13:16 +02:00
# Inherits from PandoraFMS::ProducerConsumerServer
our @ ISA = qw( PandoraFMS::ProducerConsumerServer ) ;
# Global variables
my @ TaskQueue : shared ;
my % PendingTasks : shared ;
2013-08-01 11:54:21 +02:00
my $ Sem : shared ;
my $ TaskSem : shared ;
2009-04-14 Ramon Novoa <rnovoa@artica.es>
* pandora_ctl, pandora_network, pandora_wmi, pandora_plugin,
pandora_prediction, bin/pandora_wmi, bin/pandora_plugin,
bin/pandora_prediction, bin/pandora_snmpconsole, bin/pandora_recon,
bin/pandora_network, pandora_recon, pandora_snmpconsole: Deleted
from repository. Old server code and startup scripts.
* Makefile.PL, pandora_server_installer, lib/PandoraFMS/Config.pm
lib/PandoraFMS/DB.pm, lib/PandoraFMS/Tools.pm, bin/pandora_server,
pandora_package_installer, pandora_server: Updated to work with the
new code, removed unneeded dependencies, fixed some bugs etc.
* lib/PandoraFMS/SNMPServer.pm, lib/PandoraFMS/PluginServer.pm,
lib/PandoraFMS/ProducerConsumerServer.pm, lib/PandoraFMS/Server.pm,
lib/PandoraFMS/PredictionServer.pm, lib/PandoraFMS/Core.pm,
lib/PandoraFMS/ReconServer.pm, lib/PandoraFMS/DataServer.pm,
lib/PandoraFMS/NetworkServer.pm, lib/PandoraFMS/WMIServer.pm: Added
to repository. New server code.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1620 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-04-14 21:13:16 +02:00
2017-03-08 13:20:00 +01:00
# IDs from tconfig_os.
use constant OS_OTHER = > 10 ;
use constant OS_ROUTER = > 17 ;
use constant OS_SWITCH = > 18 ;
2009-04-14 Ramon Novoa <rnovoa@artica.es>
* pandora_ctl, pandora_network, pandora_wmi, pandora_plugin,
pandora_prediction, bin/pandora_wmi, bin/pandora_plugin,
bin/pandora_prediction, bin/pandora_snmpconsole, bin/pandora_recon,
bin/pandora_network, pandora_recon, pandora_snmpconsole: Deleted
from repository. Old server code and startup scripts.
* Makefile.PL, pandora_server_installer, lib/PandoraFMS/Config.pm
lib/PandoraFMS/DB.pm, lib/PandoraFMS/Tools.pm, bin/pandora_server,
pandora_package_installer, pandora_server: Updated to work with the
new code, removed unneeded dependencies, fixed some bugs etc.
* lib/PandoraFMS/SNMPServer.pm, lib/PandoraFMS/PluginServer.pm,
lib/PandoraFMS/ProducerConsumerServer.pm, lib/PandoraFMS/Server.pm,
lib/PandoraFMS/PredictionServer.pm, lib/PandoraFMS/Core.pm,
lib/PandoraFMS/ReconServer.pm, lib/PandoraFMS/DataServer.pm,
lib/PandoraFMS/NetworkServer.pm, lib/PandoraFMS/WMIServer.pm: Added
to repository. New server code.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1620 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-04-14 21:13:16 +02:00
########################################################################################
2019-02-13 14:56:10 +01:00
# Discovery Server class constructor.
2009-04-14 Ramon Novoa <rnovoa@artica.es>
* pandora_ctl, pandora_network, pandora_wmi, pandora_plugin,
pandora_prediction, bin/pandora_wmi, bin/pandora_plugin,
bin/pandora_prediction, bin/pandora_snmpconsole, bin/pandora_recon,
bin/pandora_network, pandora_recon, pandora_snmpconsole: Deleted
from repository. Old server code and startup scripts.
* Makefile.PL, pandora_server_installer, lib/PandoraFMS/Config.pm
lib/PandoraFMS/DB.pm, lib/PandoraFMS/Tools.pm, bin/pandora_server,
pandora_package_installer, pandora_server: Updated to work with the
new code, removed unneeded dependencies, fixed some bugs etc.
* lib/PandoraFMS/SNMPServer.pm, lib/PandoraFMS/PluginServer.pm,
lib/PandoraFMS/ProducerConsumerServer.pm, lib/PandoraFMS/Server.pm,
lib/PandoraFMS/PredictionServer.pm, lib/PandoraFMS/Core.pm,
lib/PandoraFMS/ReconServer.pm, lib/PandoraFMS/DataServer.pm,
lib/PandoraFMS/NetworkServer.pm, lib/PandoraFMS/WMIServer.pm: Added
to repository. New server code.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1620 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-04-14 21:13:16 +02:00
########################################################################################
sub new ($$$$$$) {
my ( $ class , $ config , $ dbh ) = @ _ ;
2012-06-12 14:34:51 +02:00
2019-02-13 14:56:10 +01:00
return undef unless $ config - > { 'reconserver' } == 1 || $ config - > { 'discoveryserver' } == 1 ;
2012-06-12 14:34:51 +02:00
2011-07-01 14:38:54 +02:00
if ( ! - e $ config - > { 'nmap' } ) {
2019-02-13 14:56:10 +01:00
logger ( $ config , ' [E] ' . $ config - > { 'nmap' } . " needed by " . $ config - > { 'rb_product_name' } . " Discovery Server not found." , 1 ) ;
print_message ( $ config , ' [E] ' . $ config - > { 'nmap' } . " needed by " . $ config - > { 'rb_product_name' } . " Discovery Server not found." , 1 ) ;
2011-07-01 14:38:54 +02:00
return undef ;
}
2013-08-01 11:54:21 +02:00
# Initialize semaphores and queues
@ TaskQueue = ( ) ;
% PendingTasks = ( ) ;
$ Sem = Thread::Semaphore - > new ;
$ TaskSem = Thread::Semaphore - > new ( 0 ) ;
2011-07-01 14:38:54 +02:00
2017-10-16 15:52:00 +02:00
# Restart automatic recon tasks.
db_do ( $ dbh , 'UPDATE trecon_task SET utimestamp = 0 WHERE id_recon_server = ? AND status <> -1 AND interval_sweep > 0' ,
2019-02-13 14:56:10 +01:00
get_server_id ( $ dbh , $ config - > { 'servername' } , DISCOVERYSERVER ) ) ;
2017-10-16 15:52:00 +02:00
# Reset (but do not restart) manual recon tasks.
db_do ( $ dbh , 'UPDATE trecon_task SET status = -1 WHERE id_recon_server = ? AND status <> -1 AND interval_sweep = 0' ,
2019-02-13 14:56:10 +01:00
get_server_id ( $ dbh , $ config - > { 'servername' } , DISCOVERYSERVER ) ) ;
2016-10-27 15:31:51 +02:00
2009-04-14 Ramon Novoa <rnovoa@artica.es>
* pandora_ctl, pandora_network, pandora_wmi, pandora_plugin,
pandora_prediction, bin/pandora_wmi, bin/pandora_plugin,
bin/pandora_prediction, bin/pandora_snmpconsole, bin/pandora_recon,
bin/pandora_network, pandora_recon, pandora_snmpconsole: Deleted
from repository. Old server code and startup scripts.
* Makefile.PL, pandora_server_installer, lib/PandoraFMS/Config.pm
lib/PandoraFMS/DB.pm, lib/PandoraFMS/Tools.pm, bin/pandora_server,
pandora_package_installer, pandora_server: Updated to work with the
new code, removed unneeded dependencies, fixed some bugs etc.
* lib/PandoraFMS/SNMPServer.pm, lib/PandoraFMS/PluginServer.pm,
lib/PandoraFMS/ProducerConsumerServer.pm, lib/PandoraFMS/Server.pm,
lib/PandoraFMS/PredictionServer.pm, lib/PandoraFMS/Core.pm,
lib/PandoraFMS/ReconServer.pm, lib/PandoraFMS/DataServer.pm,
lib/PandoraFMS/NetworkServer.pm, lib/PandoraFMS/WMIServer.pm: Added
to repository. New server code.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1620 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-04-14 21:13:16 +02:00
# Call the constructor of the parent class
2019-02-13 14:56:10 +01:00
my $ self = $ class - > SUPER:: new ( $ config , DISCOVERYSERVER , \ & PandoraFMS::DiscoveryServer:: data_producer , \ & PandoraFMS::DiscoveryServer:: data_consumer , $ dbh ) ;
2012-06-12 14:34:51 +02:00
bless $ self , $ class ;
return $ self ;
2009-04-14 Ramon Novoa <rnovoa@artica.es>
* pandora_ctl, pandora_network, pandora_wmi, pandora_plugin,
pandora_prediction, bin/pandora_wmi, bin/pandora_plugin,
bin/pandora_prediction, bin/pandora_snmpconsole, bin/pandora_recon,
bin/pandora_network, pandora_recon, pandora_snmpconsole: Deleted
from repository. Old server code and startup scripts.
* Makefile.PL, pandora_server_installer, lib/PandoraFMS/Config.pm
lib/PandoraFMS/DB.pm, lib/PandoraFMS/Tools.pm, bin/pandora_server,
pandora_package_installer, pandora_server: Updated to work with the
new code, removed unneeded dependencies, fixed some bugs etc.
* lib/PandoraFMS/SNMPServer.pm, lib/PandoraFMS/PluginServer.pm,
lib/PandoraFMS/ProducerConsumerServer.pm, lib/PandoraFMS/Server.pm,
lib/PandoraFMS/PredictionServer.pm, lib/PandoraFMS/Core.pm,
lib/PandoraFMS/ReconServer.pm, lib/PandoraFMS/DataServer.pm,
lib/PandoraFMS/NetworkServer.pm, lib/PandoraFMS/WMIServer.pm: Added
to repository. New server code.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1620 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-04-14 21:13:16 +02:00
}
###############################################################################
# Run.
###############################################################################
sub run ($) {
my $ self = shift ;
my $ pa_config = $ self - > getConfig ( ) ;
2012-06-12 14:34:51 +02:00
2019-02-13 14:56:10 +01:00
print_message ( $ pa_config , " [*] Starting " . $ pa_config - > { 'rb_product_name' } . " Discovery Server." , 1 ) ;
2009-04-14 Ramon Novoa <rnovoa@artica.es>
* pandora_ctl, pandora_network, pandora_wmi, pandora_plugin,
pandora_prediction, bin/pandora_wmi, bin/pandora_plugin,
bin/pandora_prediction, bin/pandora_snmpconsole, bin/pandora_recon,
bin/pandora_network, pandora_recon, pandora_snmpconsole: Deleted
from repository. Old server code and startup scripts.
* Makefile.PL, pandora_server_installer, lib/PandoraFMS/Config.pm
lib/PandoraFMS/DB.pm, lib/PandoraFMS/Tools.pm, bin/pandora_server,
pandora_package_installer, pandora_server: Updated to work with the
new code, removed unneeded dependencies, fixed some bugs etc.
* lib/PandoraFMS/SNMPServer.pm, lib/PandoraFMS/PluginServer.pm,
lib/PandoraFMS/ProducerConsumerServer.pm, lib/PandoraFMS/Server.pm,
lib/PandoraFMS/PredictionServer.pm, lib/PandoraFMS/Core.pm,
lib/PandoraFMS/ReconServer.pm, lib/PandoraFMS/DataServer.pm,
lib/PandoraFMS/NetworkServer.pm, lib/PandoraFMS/WMIServer.pm: Added
to repository. New server code.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1620 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-04-14 21:13:16 +02:00
$ self - > setNumThreads ( $ pa_config - > { 'recon_threads' } ) ;
$ self - > SUPER:: run ( \ @ TaskQueue , \ % PendingTasks , $ Sem , $ TaskSem ) ;
}
###############################################################################
# Data producer.
###############################################################################
sub data_producer ($) {
my $ self = shift ;
my ( $ pa_config , $ dbh ) = ( $ self - > getConfig ( ) , $ self - > getDBH ( ) ) ;
2012-06-12 14:34:51 +02:00
2009-04-14 Ramon Novoa <rnovoa@artica.es>
* pandora_ctl, pandora_network, pandora_wmi, pandora_plugin,
pandora_prediction, bin/pandora_wmi, bin/pandora_plugin,
bin/pandora_prediction, bin/pandora_snmpconsole, bin/pandora_recon,
bin/pandora_network, pandora_recon, pandora_snmpconsole: Deleted
from repository. Old server code and startup scripts.
* Makefile.PL, pandora_server_installer, lib/PandoraFMS/Config.pm
lib/PandoraFMS/DB.pm, lib/PandoraFMS/Tools.pm, bin/pandora_server,
pandora_package_installer, pandora_server: Updated to work with the
new code, removed unneeded dependencies, fixed some bugs etc.
* lib/PandoraFMS/SNMPServer.pm, lib/PandoraFMS/PluginServer.pm,
lib/PandoraFMS/ProducerConsumerServer.pm, lib/PandoraFMS/Server.pm,
lib/PandoraFMS/PredictionServer.pm, lib/PandoraFMS/Core.pm,
lib/PandoraFMS/ReconServer.pm, lib/PandoraFMS/DataServer.pm,
lib/PandoraFMS/NetworkServer.pm, lib/PandoraFMS/WMIServer.pm: Added
to repository. New server code.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1620 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-04-14 21:13:16 +02:00
my @ tasks ;
2012-06-12 14:34:51 +02:00
2009-04-14 Ramon Novoa <rnovoa@artica.es>
* pandora_ctl, pandora_network, pandora_wmi, pandora_plugin,
pandora_prediction, bin/pandora_wmi, bin/pandora_plugin,
bin/pandora_prediction, bin/pandora_snmpconsole, bin/pandora_recon,
bin/pandora_network, pandora_recon, pandora_snmpconsole: Deleted
from repository. Old server code and startup scripts.
* Makefile.PL, pandora_server_installer, lib/PandoraFMS/Config.pm
lib/PandoraFMS/DB.pm, lib/PandoraFMS/Tools.pm, bin/pandora_server,
pandora_package_installer, pandora_server: Updated to work with the
new code, removed unneeded dependencies, fixed some bugs etc.
* lib/PandoraFMS/SNMPServer.pm, lib/PandoraFMS/PluginServer.pm,
lib/PandoraFMS/ProducerConsumerServer.pm, lib/PandoraFMS/Server.pm,
lib/PandoraFMS/PredictionServer.pm, lib/PandoraFMS/Core.pm,
lib/PandoraFMS/ReconServer.pm, lib/PandoraFMS/DataServer.pm,
lib/PandoraFMS/NetworkServer.pm, lib/PandoraFMS/WMIServer.pm: Added
to repository. New server code.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1620 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-04-14 21:13:16 +02:00
my $ server_id = get_server_id ( $ dbh , $ pa_config - > { 'servername' } , $ self - > getServerType ( ) ) ;
return @ tasks unless defined ( $ server_id ) ;
2012-06-12 14:34:51 +02:00
2011-04-13 16:59:18 +02:00
# Manual tasks have interval_sweep = 0
# Manual tasks are "forced" like the other, setting the utimestamp to 1
# By default, after create a tasks it takes the utimestamp to 0
# Status -1 means "done".
2012-06-12 14:34:51 +02:00
2009-04-14 Ramon Novoa <rnovoa@artica.es>
* pandora_ctl, pandora_network, pandora_wmi, pandora_plugin,
pandora_prediction, bin/pandora_wmi, bin/pandora_plugin,
bin/pandora_prediction, bin/pandora_snmpconsole, bin/pandora_recon,
bin/pandora_network, pandora_recon, pandora_snmpconsole: Deleted
from repository. Old server code and startup scripts.
* Makefile.PL, pandora_server_installer, lib/PandoraFMS/Config.pm
lib/PandoraFMS/DB.pm, lib/PandoraFMS/Tools.pm, bin/pandora_server,
pandora_package_installer, pandora_server: Updated to work with the
new code, removed unneeded dependencies, fixed some bugs etc.
* lib/PandoraFMS/SNMPServer.pm, lib/PandoraFMS/PluginServer.pm,
lib/PandoraFMS/ProducerConsumerServer.pm, lib/PandoraFMS/Server.pm,
lib/PandoraFMS/PredictionServer.pm, lib/PandoraFMS/Core.pm,
lib/PandoraFMS/ReconServer.pm, lib/PandoraFMS/DataServer.pm,
lib/PandoraFMS/NetworkServer.pm, lib/PandoraFMS/WMIServer.pm: Added
to repository. New server code.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1620 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-04-14 21:13:16 +02:00
my @ rows = get_db_rows ( $ dbh , ' SELECT * FROM trecon_task
2019-02-13 14:56:10 +01:00
WHERE id_recon_server = ?
AND disabled = 0
AND ( ( utimestamp = 0 AND interval_sweep != 0 OR status = 1 )
OR ( status = - 1 AND interval_sweep > 0 AND ( utimestamp + interval_sweep ) < UNIX_TIMESTAMP ( ) ) ) ' , $ server_id ) ;
2009-04-14 Ramon Novoa <rnovoa@artica.es>
* pandora_ctl, pandora_network, pandora_wmi, pandora_plugin,
pandora_prediction, bin/pandora_wmi, bin/pandora_plugin,
bin/pandora_prediction, bin/pandora_snmpconsole, bin/pandora_recon,
bin/pandora_network, pandora_recon, pandora_snmpconsole: Deleted
from repository. Old server code and startup scripts.
* Makefile.PL, pandora_server_installer, lib/PandoraFMS/Config.pm
lib/PandoraFMS/DB.pm, lib/PandoraFMS/Tools.pm, bin/pandora_server,
pandora_package_installer, pandora_server: Updated to work with the
new code, removed unneeded dependencies, fixed some bugs etc.
* lib/PandoraFMS/SNMPServer.pm, lib/PandoraFMS/PluginServer.pm,
lib/PandoraFMS/ProducerConsumerServer.pm, lib/PandoraFMS/Server.pm,
lib/PandoraFMS/PredictionServer.pm, lib/PandoraFMS/Core.pm,
lib/PandoraFMS/ReconServer.pm, lib/PandoraFMS/DataServer.pm,
lib/PandoraFMS/NetworkServer.pm, lib/PandoraFMS/WMIServer.pm: Added
to repository. New server code.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1620 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-04-14 21:13:16 +02:00
foreach my $ row ( @ rows ) {
2012-06-12 14:34:51 +02:00
2009-04-14 Ramon Novoa <rnovoa@artica.es>
* pandora_ctl, pandora_network, pandora_wmi, pandora_plugin,
pandora_prediction, bin/pandora_wmi, bin/pandora_plugin,
bin/pandora_prediction, bin/pandora_snmpconsole, bin/pandora_recon,
bin/pandora_network, pandora_recon, pandora_snmpconsole: Deleted
from repository. Old server code and startup scripts.
* Makefile.PL, pandora_server_installer, lib/PandoraFMS/Config.pm
lib/PandoraFMS/DB.pm, lib/PandoraFMS/Tools.pm, bin/pandora_server,
pandora_package_installer, pandora_server: Updated to work with the
new code, removed unneeded dependencies, fixed some bugs etc.
* lib/PandoraFMS/SNMPServer.pm, lib/PandoraFMS/PluginServer.pm,
lib/PandoraFMS/ProducerConsumerServer.pm, lib/PandoraFMS/Server.pm,
lib/PandoraFMS/PredictionServer.pm, lib/PandoraFMS/Core.pm,
lib/PandoraFMS/ReconServer.pm, lib/PandoraFMS/DataServer.pm,
lib/PandoraFMS/NetworkServer.pm, lib/PandoraFMS/WMIServer.pm: Added
to repository. New server code.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1620 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-04-14 21:13:16 +02:00
# Update task status
2009-04-20 11:44:24 +02:00
update_recon_task ( $ dbh , $ row - > { 'id_rt' } , 1 ) ;
2012-06-12 14:34:51 +02:00
2009-04-14 Ramon Novoa <rnovoa@artica.es>
* pandora_ctl, pandora_network, pandora_wmi, pandora_plugin,
pandora_prediction, bin/pandora_wmi, bin/pandora_plugin,
bin/pandora_prediction, bin/pandora_snmpconsole, bin/pandora_recon,
bin/pandora_network, pandora_recon, pandora_snmpconsole: Deleted
from repository. Old server code and startup scripts.
* Makefile.PL, pandora_server_installer, lib/PandoraFMS/Config.pm
lib/PandoraFMS/DB.pm, lib/PandoraFMS/Tools.pm, bin/pandora_server,
pandora_package_installer, pandora_server: Updated to work with the
new code, removed unneeded dependencies, fixed some bugs etc.
* lib/PandoraFMS/SNMPServer.pm, lib/PandoraFMS/PluginServer.pm,
lib/PandoraFMS/ProducerConsumerServer.pm, lib/PandoraFMS/Server.pm,
lib/PandoraFMS/PredictionServer.pm, lib/PandoraFMS/Core.pm,
lib/PandoraFMS/ReconServer.pm, lib/PandoraFMS/DataServer.pm,
lib/PandoraFMS/NetworkServer.pm, lib/PandoraFMS/WMIServer.pm: Added
to repository. New server code.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1620 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-04-14 21:13:16 +02:00
push ( @ tasks , $ row - > { 'id_rt' } ) ;
}
2012-06-12 14:34:51 +02:00
2009-04-14 Ramon Novoa <rnovoa@artica.es>
* pandora_ctl, pandora_network, pandora_wmi, pandora_plugin,
pandora_prediction, bin/pandora_wmi, bin/pandora_plugin,
bin/pandora_prediction, bin/pandora_snmpconsole, bin/pandora_recon,
bin/pandora_network, pandora_recon, pandora_snmpconsole: Deleted
from repository. Old server code and startup scripts.
* Makefile.PL, pandora_server_installer, lib/PandoraFMS/Config.pm
lib/PandoraFMS/DB.pm, lib/PandoraFMS/Tools.pm, bin/pandora_server,
pandora_package_installer, pandora_server: Updated to work with the
new code, removed unneeded dependencies, fixed some bugs etc.
* lib/PandoraFMS/SNMPServer.pm, lib/PandoraFMS/PluginServer.pm,
lib/PandoraFMS/ProducerConsumerServer.pm, lib/PandoraFMS/Server.pm,
lib/PandoraFMS/PredictionServer.pm, lib/PandoraFMS/Core.pm,
lib/PandoraFMS/ReconServer.pm, lib/PandoraFMS/DataServer.pm,
lib/PandoraFMS/NetworkServer.pm, lib/PandoraFMS/WMIServer.pm: Added
to repository. New server code.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1620 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-04-14 21:13:16 +02:00
return @ tasks ;
}
###############################################################################
# Data consumer.
###############################################################################
sub data_consumer ($$) {
my ( $ self , $ task_id ) = @ _ ;
my ( $ pa_config , $ dbh ) = ( $ self - > getConfig ( ) , $ self - > getDBH ( ) ) ;
# Get recon task data
my $ task = get_db_single_row ( $ dbh , 'SELECT * FROM trecon_task WHERE id_rt = ?' , $ task_id ) ;
return - 1 unless defined ( $ task ) ;
2011-04-13 16:59:18 +02:00
2010-10-15 15:00:25 +02:00
# Is it a recon script?
2011-07-01 14:38:54 +02:00
if ( defined ( $ task - > { 'id_recon_script' } ) && ( $ task - > { 'id_recon_script' } != 0 ) ) {
2011-05-07 21:29:29 +02:00
exec_recon_script ( $ pa_config , $ dbh , $ task ) ;
return ;
2013-06-06 20:33:38 +02:00
} else {
logger ( $ pa_config , 'Starting recon task for net ' . $ task - > { 'subnet' } . '.' , 10 ) ;
2010-10-15 15:00:25 +02:00
}
2011-08-24 20:07:59 +02:00
eval {
2017-03-14 08:27:44 +01:00
my @ subnets = split ( /,/ , safe_output ( $ task - > { 'subnet' } ) ) ;
my @ communities = split ( /,/ , safe_output ( $ task - > { 'snmp_community' } ) ) ;
2019-02-13 14:56:10 +01:00
my @ auth_strings = ( ) ;
if ( defined ( $ task - > { 'auth_strings' } ) ) {
@ auth_strings = split ( /,/ , safe_output ( $ task - > { 'auth_strings' } ) ) ;
}
2017-03-08 13:20:00 +01:00
2019-02-18 19:50:13 +01:00
my $ main_event = pandora_event ( $ pa_config , "[Discovery] Execution summary" , $ task - > { 'id_group' } , 0 , 0 , 0 , 0 , 'system' , 0 , $ dbh ) ;
2017-03-13 11:13:45 +01:00
my $ recon = new PandoraFMS::Recon:: Base (
2017-03-08 13:20:00 +01:00
communities = > \ @ communities ,
dbh = > $ dbh ,
group_id = > $ task - > { 'id_group' } ,
id_os = > $ task - > { 'id_os' } ,
id_network_profile = > $ task - > { 'id_network_profile' } ,
os_detection = > $ task - > { 'os_detect' } ,
parent_detection = > $ task - > { 'parent_detection' } ,
parent_recursion = > $ task - > { 'parent_recursion' } ,
pa_config = > $ pa_config ,
recon_ports = > $ task - > { 'recon_ports' } ,
resolve_names = > $ task - > { 'resolve_names' } ,
2018-09-17 14:36:52 +02:00
snmp_auth_user = > $ task - > { 'snmp_auth_user' } ,
snmp_auth_pass = > $ task - > { 'snmp_auth_pass' } ,
snmp_auth_method = > $ task - > { 'snmp_auth_method' } ,
snmp_checks = > $ task - > { 'snmp_checks' } ,
2017-03-23 14:33:06 +01:00
snmp_enabled = > $ task - > { 'snmp_enabled' } ,
2018-09-17 14:36:52 +02:00
snmp_privacy_method = > $ task - > { 'snmp_privacy_method' } ,
snmp_privacy_pass = > $ task - > { 'snmp_privacy_pass' } ,
snmp_security_level = > $ task - > { 'snmp_security_level' } ,
snmp_timeout = > $ task - > { 'snmp_timeout' } ,
snmp_version = > $ task - > { 'snmp_version' } ,
2017-03-08 13:20:00 +01:00
subnets = > \ @ subnets ,
2017-03-10 12:04:35 +01:00
task_id = > $ task - > { 'id_rt' } ,
2017-03-23 14:33:06 +01:00
vlan_cache_enabled = > $ task - > { 'vlan_enabled' } ,
2019-02-13 14:56:10 +01:00
wmi_enabled = > $ task - > { 'wmi_enabled' } ,
auth_strings_array = > \ @ auth_strings ,
2019-02-18 19:50:13 +01:00
autoconfiguration_enabled = > $ task - > { 'autoconfiguration_enabled' } ,
main_event_id = > $ main_event ,
2017-03-08 13:20:00 +01:00
% { $ pa_config }
) ;
$ recon - > scan ( ) ;
2011-08-24 20:07:59 +02:00
} ;
if ( $@ ) {
2009-04-16 20:19:39 +02:00
update_recon_task ( $ dbh , $ task_id , - 1 ) ;
2011-07-01 14:38:54 +02:00
return ;
2009-04-14 Ramon Novoa <rnovoa@artica.es>
* pandora_ctl, pandora_network, pandora_wmi, pandora_plugin,
pandora_prediction, bin/pandora_wmi, bin/pandora_plugin,
bin/pandora_prediction, bin/pandora_snmpconsole, bin/pandora_recon,
bin/pandora_network, pandora_recon, pandora_snmpconsole: Deleted
from repository. Old server code and startup scripts.
* Makefile.PL, pandora_server_installer, lib/PandoraFMS/Config.pm
lib/PandoraFMS/DB.pm, lib/PandoraFMS/Tools.pm, bin/pandora_server,
pandora_package_installer, pandora_server: Updated to work with the
new code, removed unneeded dependencies, fixed some bugs etc.
* lib/PandoraFMS/SNMPServer.pm, lib/PandoraFMS/PluginServer.pm,
lib/PandoraFMS/ProducerConsumerServer.pm, lib/PandoraFMS/Server.pm,
lib/PandoraFMS/PredictionServer.pm, lib/PandoraFMS/Core.pm,
lib/PandoraFMS/ReconServer.pm, lib/PandoraFMS/DataServer.pm,
lib/PandoraFMS/NetworkServer.pm, lib/PandoraFMS/WMIServer.pm: Added
to repository. New server code.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1620 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-04-14 21:13:16 +02:00
}
}
##########################################################################
# Update recon task status.
##########################################################################
2009-04-16 20:19:39 +02:00
sub update_recon_task ($$$) {
my ( $ dbh , $ id_task , $ status ) = @ _ ;
2012-06-12 14:34:51 +02:00
2009-04-14 Ramon Novoa <rnovoa@artica.es>
* pandora_ctl, pandora_network, pandora_wmi, pandora_plugin,
pandora_prediction, bin/pandora_wmi, bin/pandora_plugin,
bin/pandora_prediction, bin/pandora_snmpconsole, bin/pandora_recon,
bin/pandora_network, pandora_recon, pandora_snmpconsole: Deleted
from repository. Old server code and startup scripts.
* Makefile.PL, pandora_server_installer, lib/PandoraFMS/Config.pm
lib/PandoraFMS/DB.pm, lib/PandoraFMS/Tools.pm, bin/pandora_server,
pandora_package_installer, pandora_server: Updated to work with the
new code, removed unneeded dependencies, fixed some bugs etc.
* lib/PandoraFMS/SNMPServer.pm, lib/PandoraFMS/PluginServer.pm,
lib/PandoraFMS/ProducerConsumerServer.pm, lib/PandoraFMS/Server.pm,
lib/PandoraFMS/PredictionServer.pm, lib/PandoraFMS/Core.pm,
lib/PandoraFMS/ReconServer.pm, lib/PandoraFMS/DataServer.pm,
lib/PandoraFMS/NetworkServer.pm, lib/PandoraFMS/WMIServer.pm: Added
to repository. New server code.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1620 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-04-14 21:13:16 +02:00
db_do ( $ dbh , 'UPDATE trecon_task SET utimestamp = ?, status = ? WHERE id_rt = ?' , time ( ) , $ status , $ id_task ) ;
2011-08-13 04:38:36 +02:00
}
2009-04-14 Ramon Novoa <rnovoa@artica.es>
* pandora_ctl, pandora_network, pandora_wmi, pandora_plugin,
pandora_prediction, bin/pandora_wmi, bin/pandora_plugin,
bin/pandora_prediction, bin/pandora_snmpconsole, bin/pandora_recon,
bin/pandora_network, pandora_recon, pandora_snmpconsole: Deleted
from repository. Old server code and startup scripts.
* Makefile.PL, pandora_server_installer, lib/PandoraFMS/Config.pm
lib/PandoraFMS/DB.pm, lib/PandoraFMS/Tools.pm, bin/pandora_server,
pandora_package_installer, pandora_server: Updated to work with the
new code, removed unneeded dependencies, fixed some bugs etc.
* lib/PandoraFMS/SNMPServer.pm, lib/PandoraFMS/PluginServer.pm,
lib/PandoraFMS/ProducerConsumerServer.pm, lib/PandoraFMS/Server.pm,
lib/PandoraFMS/PredictionServer.pm, lib/PandoraFMS/Core.pm,
lib/PandoraFMS/ReconServer.pm, lib/PandoraFMS/DataServer.pm,
lib/PandoraFMS/NetworkServer.pm, lib/PandoraFMS/WMIServer.pm: Added
to repository. New server code.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1620 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-04-14 21:13:16 +02:00
2010-10-15 15:00:25 +02:00
##########################################################################
# Executes recon scripts
##########################################################################
sub exec_recon_script ($$$) {
my ( $ pa_config , $ dbh , $ task ) = @ _ ;
# Get recon plugin data
my $ script = get_db_single_row ( $ dbh , 'SELECT * FROM trecon_script WHERE id_recon_script = ?' , $ task - > { 'id_recon_script' } ) ;
return - 1 unless defined ( $ script ) ;
2012-06-12 14:34:51 +02:00
2010-12-02 11:01:04 +01:00
logger ( $ pa_config , 'Executing recon script ' . safe_output ( $ script - > { 'name' } ) , 10 ) ;
2012-06-12 14:34:51 +02:00
2010-11-29 17:24:25 +01:00
my $ command = safe_output ( $ script - > { 'script' } ) ;
2014-04-22 11:22:08 +02:00
my $ macros = safe_output ( $ task - > { 'macros' } ) ;
2014-05-08 07:12:08 +02:00
# \r and \n should be escaped for decode_json().
$ macros =~ s/\n/\\n/g ;
$ macros =~ s/\r/\\r/g ;
my $ decoded_macros = decode_json ( encode_utf8 ( $ macros ) ) ;
2014-04-22 11:22:08 +02:00
my $ macros_parameters = '' ;
# Add module macros as parameter
if ( ref ( $ decoded_macros ) eq "HASH" ) {
2014-05-28 16:54:02 +02:00
# Convert the hash to a sorted array
my @ sorted_macros ;
2014-04-22 11:22:08 +02:00
while ( my ( $ i , $ m ) = each ( % { $ decoded_macros } ) ) {
2014-05-28 16:54:02 +02:00
$ sorted_macros [ $ i ] = $ m ;
}
# Remove the 0 position
shift @ sorted_macros ;
foreach my $ m ( @ sorted_macros ) {
2014-04-22 11:22:08 +02:00
$ macros_parameters = $ macros_parameters . ' "' . $ m - > { "value" } . '"' ;
}
}
2012-06-12 14:34:51 +02:00
2013-06-06 20:33:38 +02:00
if ( - x $ command ) {
2014-04-22 11:22:08 +02:00
`$command $task->{'id_rt'} $task->{'id_group'} $task->{'create_incident'} $macros_parameters` ;
2013-06-06 20:33:38 +02:00
} else {
logger ( $ pa_config , "Cannot execute recon task command $command." ) ;
}
2012-06-12 14:34:51 +02:00
2016-11-02 13:10:32 +01:00
# Only update the timestamp in case something went wrong. The script should set the status.
db_do ( $ dbh , 'UPDATE trecon_task SET utimestamp = ? WHERE id_rt = ?' , time ( ) , $ task - > { 'id_rt' } ) ;
2012-06-12 14:34:51 +02:00
2014-05-05 16:57:10 +02:00
logger ( $ pa_config , 'Done executing recon script ' . safe_output ( $ script - > { 'name' } ) , 10 ) ;
2010-10-15 15:00:25 +02:00
return 0 ;
}
2017-03-08 13:20:00 +01:00
##########################################################################
# Guess the OS using xprobe2 or nmap.
##########################################################################
2017-03-13 11:13:45 +01:00
sub PandoraFMS ::Recon::Base::guess_os($$) {
2017-03-08 13:20:00 +01:00
my ( $ self , $ device ) = @ _ ;
# OS detection disabled. Use the device type.
if ( $ self - > { 'os_detection' } == 0 ) {
my $ device_type = $ self - > get_device_type ( $ device ) ;
2017-03-23 14:33:06 +01:00
return OS_OTHER unless defined ( $ device_type ) ;
2017-03-08 13:20:00 +01:00
return OS_ROUTER if ( $ device_type eq 'router' ) ;
return OS_SWITCH if ( $ device_type eq 'switch' ) ;
return OS_OTHER ;
}
# Use xprobe2 if available
if ( - e $ self - > { pa_config } - > { xprobe2 } ) {
my $ output = `"$self->{pa_config}->{xprobe2}" $device 2>$DEVNULL | grep 'Running OS' | head -1` ;
return OS_OTHER if ( $? != 0 ) ;
return pandora_get_os ( $ self - > { 'dbh' } , $ output ) ;
}
# Use nmap by default
if ( - e $ self - > { pa_config } - > { nmap } ) {
my $ output = `"$self->{pa_config}->{nmap}" -F -O $device 2>$DEVNULL | grep 'Aggressive OS guesses'` ;
return OS_OTHER if ( $? != 0 ) ;
return pandora_get_os ( $ self - > { 'dbh' } , $ output ) ;
}
return OS_OTHER ;
}
##############################################################################
# Returns the number of open ports from the given list.
##############################################################################
2017-03-13 11:13:45 +01:00
sub PandoraFMS ::Recon::Base::tcp_scan ($$) {
2017-03-08 13:20:00 +01:00
my ( $ self , $ host ) = @ _ ;
my $ open_ports = `"$self->{pa_config}->{nmap}" -p$self->{recon_ports} $host | grep open | wc -l` ;
return $ open_ports ;
}
##########################################################################
# Create network profile modules for the given agent.
##########################################################################
2017-03-13 11:13:45 +01:00
sub PandoraFMS ::Recon::Base::create_network_profile_modules($$$) {
2017-03-08 13:20:00 +01:00
my ( $ self , $ agent_id , $ device ) = @ _ ;
return unless ( $ self - > { 'id_network_profile' } > 0 ) ;
# Get network components associated to the network profile.
my @ np_components = get_db_rows ( $ self - > { 'dbh' } , 'SELECT * FROM tnetwork_profile_component WHERE id_np = ?' , $ self - > { 'id_network_profile' } ) ;
foreach my $ np_component ( @ np_components ) {
# Get network component data
my $ component = get_db_single_row ( $ self - > { 'dbh' } , 'SELECT * FROM tnetwork_component WHERE id_nc = ?' , $ np_component - > { 'id_nc' } ) ;
if ( ! defined ( $ component ) ) {
$ self - > call ( 'message' , "Network component ID " . $ np_component - > { 'id_nc' } . " not found." , 5 ) ;
next ;
}
2018-09-17 14:36:52 +02:00
2017-03-08 13:20:00 +01:00
# Use snmp_community from network task instead the component snmp_community
$ component - > { 'snmp_community' } = safe_output ( $ self - > get_community ( $ device ) ) ;
2018-09-17 14:36:52 +02:00
$ component - > { 'tcp_send' } = $ self - > { 'snmp_version' } ;
$ component - > { 'custom_string_1' } = $ self - > { 'snmp_privacy_method' } ;
$ component - > { 'custom_string_2' } = $ self - > { 'snmp_privacy_pass' } ;
$ component - > { 'custom_string_3' } = $ self - > { 'snmp_security_level' } ;
$ component - > { 'plugin_parameter' } = $ self - > { 'snmp_auth_method' } ;
$ component - > { 'plugin_user' } = $ self - > { 'snmp_auth_user' } ;
$ component - > { 'plugin_pass' } = $ self - > { 'snmp_auth_pass' } ;
2017-03-08 13:20:00 +01:00
pandora_create_module_from_network_component ( $ self - > { 'pa_config' } , $ component , $ agent_id , $ self - > { 'dbh' } ) ;
}
}
##########################################################################
# Connect the given devices in the Pandora FMS database.
##########################################################################
2017-03-13 11:13:45 +01:00
sub PandoraFMS ::Recon::Base::connect_agents($$$$$) {
2017-03-08 13:20:00 +01:00
my ( $ self , $ dev_1 , $ if_1 , $ dev_2 , $ if_2 ) = @ _ ;
# Get the agent for the first device.
my $ agent_1 = get_agent_from_addr ( $ self - > { 'dbh' } , $ dev_1 ) ;
if ( ! defined ( $ agent_1 ) ) {
$ agent_1 = get_agent_from_name ( $ self - > { 'dbh' } , $ dev_1 ) ;
}
return unless defined ( $ agent_1 ) ;
# Get the agent for the second device.
my $ agent_2 = get_agent_from_addr ( $ self - > { 'dbh' } , $ dev_2 ) ;
if ( ! defined ( $ agent_2 ) ) {
$ agent_2 = get_agent_from_name ( $ self - > { 'dbh' } , $ dev_2 ) ;
}
return unless defined ( $ agent_2 ) ;
2017-03-23 14:33:06 +01:00
# Use ping modules by default.
$ if_1 = 'ping' if ( $ if_1 eq '' ) ;
$ if_2 = 'ping' if ( $ if_2 eq '' ) ;
2017-03-08 13:20:00 +01:00
# Check whether the modules exists.
2017-03-23 14:33:06 +01:00
my $ module_name_1 = $ if_1 eq 'ping' ? 'ping' : "${if_1}_ifOperStatus" ;
my $ module_name_2 = $ if_2 eq 'ping' ? 'ping' : "${if_2}_ifOperStatus" ;
2017-03-08 13:20:00 +01:00
my $ module_id_1 = get_agent_module_id ( $ self - > { 'dbh' } , $ module_name_1 , $ agent_1 - > { 'id_agente' } ) ;
if ( $ module_id_1 <= 0 ) {
$ self - > call ( 'message' , "ERROR: Module " . safe_output ( $ module_name_1 ) . " does not exist for agent $dev_1." , 5 ) ;
return ;
}
my $ module_id_2 = get_agent_module_id ( $ self - > { 'dbh' } , $ module_name_2 , $ agent_2 - > { 'id_agente' } ) ;
if ( $ module_id_2 <= 0 ) {
$ self - > call ( 'message' , "ERROR: Module " . safe_output ( $ module_name_2 ) . " does not exist for agent $dev_2." , 5 ) ;
return ;
}
# Connect the modules if they are not already connected.
my $ connection_id = get_db_value ( $ self - > { 'dbh' } , 'SELECT id FROM tmodule_relationship WHERE (module_a = ? AND module_b = ?) OR (module_b = ? AND module_a = ?)' , $ module_id_1 , $ module_id_2 , $ module_id_1 , $ module_id_2 ) ;
if ( ! defined ( $ connection_id ) ) {
db_do ( $ self - > { 'dbh' } , 'INSERT INTO tmodule_relationship (`module_a`, `module_b`, `id_rt`) VALUES(?, ?, ?)' , $ module_id_1 , $ module_id_2 , $ self - > { 'task_id' } ) ;
}
}
##########################################################################
# Create an agent for the given device. Returns the ID of the new (or
# existing) agent, undef on error.
##########################################################################
2017-03-13 11:13:45 +01:00
sub PandoraFMS ::Recon::Base::create_agent($$) {
2017-03-08 13:20:00 +01:00
my ( $ self , $ device ) = @ _ ;
my @ agents = get_db_rows ( $ self - > { 'dbh' } ,
' SELECT * FROM taddress , taddress_agent , tagente
WHERE tagente . id_agente = taddress_agent . id_agent
AND taddress_agent . id_a = taddress . id_a
AND ip = ? ' , $ device
) ;
# Does the host already exist?
my $ agent ;
foreach my $ candidate ( @ agents ) {
$ agent = { map { $ _ } %$ candidate } ; # copy contents, do not use shallow copy
# exclude $device itself, because it handle corner case when target includes NAT
my @ registered = map { $ _ - > { ip } } get_db_rows ( $ self - > { 'dbh' } ,
' SELECT ip FROM taddress , taddress_agent , tagente
WHERE tagente . id_agente = taddress_agent . id_agent
AND taddress_agent . id_a = taddress . id_a
AND tagente . id_agente = ?
AND taddress . ip != ? ' , $ agent - > { id_agente } , $ device
) ;
foreach my $ ip_addr ( @ registered ) {
my @ matched = grep { $ _ =~ /^$ip_addr$/ } $ self - > get_addresses ( $ device ) ;
if ( scalar ( @ matched ) == 0 ) {
$ agent = undef ;
last ;
}
}
last if ( defined ( $ agent ) ) ; # exit loop if match all ip_addr
}
if ( ! defined ( $ agent ) ) {
$ agent = get_agent_from_name ( $ self - > { 'dbh' } , $ device ) ;
}
my ( $ agent_id , $ agent_learning ) ;
if ( ! defined ( $ agent ) ) {
# Resolve hostnames.
my $ host_name = $ self - > { 'resolve_names' } == 1 ? gethostbyaddr ( inet_aton ( $ device ) , AF_INET ) : $ device ;
$ host_name = $ device unless defined ( $ host_name ) ;
# Guess the OS.
my $ id_os = $ self - > guess_os ( $ device ) ;
# Are we filtering hosts by OS?
return if ( $ self - > { 'id_os' } > 0 && $ id_os != $ self - > { 'id_os' } ) ;
# Are we filtering hosts by TCP port?
return if ( $ self - > { 'recon_ports' } ne '' && $ self - > tcp_scan ( $ device ) == 0 ) ;
2018-07-05 16:43:41 +02:00
my $ location = get_geoip_info ( $ self - > { 'pa_config' } , $ device ) ;
$ agent_id = pandora_create_agent ( $ self - > { 'pa_config' } , $ self - > { 'pa_config' } - > { 'servername' } , $ host_name , $ device ,
$ self - > { 'group_id' } , 0 , $ id_os ,
'' , 300 , $ self - > { 'dbh' } , undef ,
$ location - > { 'longitude' } , $ location - > { 'latitude' }
) ;
2017-03-08 13:20:00 +01:00
return undef unless defined ( $ agent_id ) and ( $ agent_id > 0 ) ;
2019-02-18 14:00:55 +01:00
# Autoconfigure agent
if ( defined ( $ self - > { 'autoconfiguration_enabled' } ) && $ self - > { 'autoconfiguration_enabled' } == 1 ) {
my $ agent_data = PandoraFMS::DB:: get_db_single_row ( $ self - > { 'dbh' } , 'SELECT * FROM tagente WHERE id_agente = ?' , $ agent_id ) ;
# Update agent configuration once, after create agent.
2019-02-19 10:37:09 +01:00
enterprise_hook ( 'autoconfigure_agent' , [ $ self - > { 'pa_config' } , $ host_name , $ agent_id , $ agent_data , $ self - > { 'dbh' } , 1 ] ) ;
2019-02-18 19:50:13 +01:00
}
if ( defined ( $ self - > { 'main_event_id' } ) ) {
my $ addresses_str = join ( ',' , safe_output ( $ self - > get_addresses ( $ device ) ) ) ;
pandora_extended_event (
$ self - > { 'pa_config' } , $ self - > { 'dbh' } , $ self - > { 'main_event_id' } ,
"[Discovery] New " . safe_output ( $ self - > get_device_type ( $ device ) ) . " found " . $ host_name . " (" . $ addresses_str . ") Agent $agent_id."
) ;
2019-02-18 14:00:55 +01:00
}
2017-03-08 13:20:00 +01:00
$ agent_learning = 1 ;
# Create network profile modules for the agent
$ self - > create_network_profile_modules ( $ agent_id , $ device ) ;
}
else {
$ agent_id = $ agent - > { 'id_agente' } ;
$ agent_learning = $ agent - > { 'modo' } ;
}
# Do not create any modules if the agent is not in learning mode.
return unless ( $ agent_learning == 1 ) ;
# Add found IP addresses to the agent.
foreach my $ ip_addr ( $ self - > get_addresses ( $ device ) ) {
my $ addr_id = get_addr_id ( $ self - > { 'dbh' } , $ ip_addr ) ;
$ addr_id = add_address ( $ self - > { 'dbh' } , $ ip_addr ) unless ( $ addr_id > 0 ) ;
next unless ( $ addr_id > 0 ) ;
# Assign the new address to the agent
my $ agent_addr_id = get_agent_addr_id ( $ self - > { 'dbh' } , $ addr_id , $ agent_id ) ;
if ( $ agent_addr_id <= 0 ) {
db_do ( $ self - > { 'dbh' } , ' INSERT INTO taddress_agent ( `id_a` , `id_agent` )
VALUES ( ? , ? ) ' , $ addr_id , $ agent_id ) ;
}
}
# Create a ping module.
my $ module_id = get_agent_module_id ( $ self - > { 'dbh' } , "ping" , $ agent_id ) ;
if ( $ module_id <= 0 ) {
my % module = ( 'id_tipo_modulo' = > 6 ,
'id_modulo' = > 2 ,
'nombre' = > "ping" ,
'descripcion' = > '' ,
'id_agente' = > $ agent_id ,
'ip_target' = > $ device ) ;
pandora_create_module_from_hash ( $ self - > { 'pa_config' } , \ % module , $ self - > { 'dbh' } ) ;
}
# Add interfaces to the agent if it responds to SNMP.
2018-09-17 14:36:52 +02:00
return $ agent_id unless ( $ self - > is_snmp_discovered ( $ device ) ) ;
2017-03-08 13:20:00 +01:00
my $ community = $ self - > get_community ( $ device ) ;
2017-03-13 11:13:45 +01:00
my @ output = $ self - > snmp_get_value_array ( $ device , $ PandoraFMS:: Recon:: Base:: IFINDEX ) ;
2017-03-08 13:20:00 +01:00
foreach my $ if_index ( @ output ) {
next unless ( $ if_index =~ /^[0-9]+$/ ) ;
# Check the status of the interface.
if ( $ self - > { 'all_ifaces' } == 0 ) {
2017-03-13 11:13:45 +01:00
my $ if_status = $ self - > snmp_get_value ( $ device , "$PandoraFMS::Recon::Base::IFOPERSTATUS.$if_index" ) ;
2017-03-08 13:20:00 +01:00
next unless $ if_status == 1 ;
}
# Fill the module description with the IP and MAC addresses.
my $ mac = $ self - > get_if_mac ( $ device , $ if_index ) ;
my $ ip = $ self - > get_if_ip ( $ device , $ if_index ) ;
my $ if_desc = ( $ mac ne '' ? "MAC $mac " : '' ) . ( $ ip ne '' ? "IP $ip" : '' ) ;
# Get the name of the network interface.
2017-03-13 11:13:45 +01:00
my $ if_name = $ self - > snmp_get_value ( $ device , "$PandoraFMS::Recon::Base::IFNAME.$if_index" ) ;
2017-03-08 13:20:00 +01:00
$ if_name = "if$if_index" unless defined ( $ if_name ) ;
$ if_name =~ s/"//g ;
# Check whether the module already exists.
my $ module_id = get_agent_module_id ( $ self - > { 'dbh' } , "${if_name}_ifOperStatus" , $ agent_id ) ;
next if ( $ module_id > 0 && ! $ agent_learning ) ;
# Encode problematic characters.
$ if_name = safe_input ( $ if_name ) ;
$ if_desc = safe_input ( $ if_desc ) ;
# Interface status module.
$ module_id = get_agent_module_id ( $ self - > { 'dbh' } , "${if_name}_ifOperStatus" , $ agent_id ) ;
if ( $ module_id <= 0 ) {
my % module = ( 'id_tipo_modulo' = > 18 ,
'id_modulo' = > 2 ,
'nombre' = > "${if_name}_ifOperStatus" ,
'descripcion' = > $ if_desc ,
'id_agente' = > $ agent_id ,
'ip_target' = > $ device ,
2018-09-17 14:36:52 +02:00
'tcp_send' = > $ self - > { 'snmp_version' } ,
'custom_string_1' = > $ self - > { 'snmp_privacy_method' } ,
'custom_string_2' = > $ self - > { 'snmp_privacy_pass' } ,
'custom_string_3' = > $ self - > { 'snmp_security_level' } ,
'plugin_parameter' = > $ self - > { 'snmp_auth_method' } ,
'plugin_user' = > $ self - > { 'snmp_auth_user' } ,
'plugin_pass' = > $ self - > { 'snmp_auth_pass' } ,
2017-03-08 13:20:00 +01:00
'snmp_community' = > $ community ,
2017-03-13 11:13:45 +01:00
'snmp_oid' = > "$PandoraFMS::Recon::Base::IFOPERSTATUS.$if_index"
2017-03-08 13:20:00 +01:00
) ;
pandora_create_module_from_hash ( $ self - > { 'pa_config' } , \ % module , $ self - > { 'dbh' } ) ;
} else {
my % module = (
'descripcion' = > $ if_desc ,
'ip_target' = > $ device ,
'snmp_community' = > $ community ,
2018-09-17 14:36:52 +02:00
'tcp_send' = > $ self - > { 'snmp_version' } ,
'custom_string_1' = > $ self - > { 'snmp_privacy_method' } ,
'custom_string_2' = > $ self - > { 'snmp_privacy_pass' } ,
'custom_string_3' = > $ self - > { 'snmp_security_level' } ,
'plugin_parameter' = > $ self - > { 'snmp_auth_method' } ,
'plugin_user' = > $ self - > { 'snmp_auth_user' } ,
'plugin_pass' = > $ self - > { 'snmp_auth_pass' } ,
'tcp_send' = > $ self - > { 'snmp_version' } ,
2017-03-08 13:20:00 +01:00
) ;
pandora_update_module_from_hash ( $ self - > { 'pa_config' } , \ % module , 'id_agente_modulo' , $ module_id , $ self - > { 'dbh' } ) ;
}
# Incoming traffic module.
2017-03-15 08:46:11 +01:00
my $ if_hc_in_octets = $ self - > snmp_get_value ( $ device , "$PandoraFMS::Recon::Base::IFHCINOCTECTS.$if_index" ) ;
if ( defined ( $ if_hc_in_octets ) ) {
$ module_id = get_agent_module_id ( $ self - > { 'dbh' } , "${if_name}_ifHCInOctets" , $ agent_id ) ;
if ( $ module_id <= 0 ) {
my % module = ( 'id_tipo_modulo' = > 16 ,
'id_modulo' = > 2 ,
'nombre' = > "${if_name}_ifHCInOctets" ,
'descripcion' = > 'The total number of octets received on the interface, including framing characters. This object is a 64-bit version of ifInOctets.' ,
'id_agente' = > $ agent_id ,
'ip_target' = > $ device ,
2018-09-17 14:36:52 +02:00
'tcp_send' = > $ self - > { 'snmp_version' } ,
'custom_string_1' = > $ self - > { 'snmp_privacy_method' } ,
'custom_string_2' = > $ self - > { 'snmp_privacy_pass' } ,
'custom_string_3' = > $ self - > { 'snmp_security_level' } ,
'plugin_parameter' = > $ self - > { 'snmp_auth_method' } ,
'plugin_user' = > $ self - > { 'snmp_auth_user' } ,
'plugin_pass' = > $ self - > { 'snmp_auth_pass' } ,
2017-03-15 08:46:11 +01:00
'snmp_community' = > $ community ,
'snmp_oid' = > "$PandoraFMS::Recon::Base::IFHCINOCTECTS.$if_index" ) ;
pandora_create_module_from_hash ( $ self - > { 'pa_config' } , \ % module , $ self - > { 'dbh' } ) ;
} else {
my % module = (
'ip_target' = > $ device ,
'snmp_community' = > $ community ,
2018-09-17 14:36:52 +02:00
'tcp_send' = > $ self - > { 'snmp_version' } ,
'custom_string_1' = > $ self - > { 'snmp_privacy_method' } ,
'custom_string_2' = > $ self - > { 'snmp_privacy_pass' } ,
'custom_string_3' = > $ self - > { 'snmp_security_level' } ,
'plugin_parameter' = > $ self - > { 'snmp_auth_method' } ,
'plugin_user' = > $ self - > { 'snmp_auth_user' } ,
'plugin_pass' = > $ self - > { 'snmp_auth_pass' } ,
2017-03-15 08:46:11 +01:00
) ;
pandora_update_module_from_hash ( $ self - > { 'pa_config' } , \ % module , 'id_agente_modulo' , $ module_id , $ self - > { 'dbh' } ) ;
}
}
# ifInOctets
2018-10-29 12:09:35 +01:00
elsif ( defined ( $ self - > snmp_get_value ( $ device , "$PandoraFMS::Recon::Base::IFINOCTECTS.$if_index" ) ) ) {
2017-03-15 08:46:11 +01:00
$ module_id = get_agent_module_id ( $ self - > { 'dbh' } , "${if_name}_ifInOctets" , $ agent_id ) ;
if ( $ module_id <= 0 ) {
my % module = ( 'id_tipo_modulo' = > 16 ,
'id_modulo' = > 2 ,
'nombre' = > "${if_name}_ifInOctets" ,
'descripcion' = > 'The total number of octets received on the interface, including framing characters.' ,
'id_agente' = > $ agent_id ,
'ip_target' = > $ device ,
2018-09-17 14:36:52 +02:00
'tcp_send' = > $ self - > { 'snmp_version' } ,
'custom_string_1' = > $ self - > { 'snmp_privacy_method' } ,
'custom_string_2' = > $ self - > { 'snmp_privacy_pass' } ,
'custom_string_3' = > $ self - > { 'snmp_security_level' } ,
'plugin_parameter' = > $ self - > { 'snmp_auth_method' } ,
'plugin_user' = > $ self - > { 'snmp_auth_user' } ,
'plugin_pass' = > $ self - > { 'snmp_auth_pass' } ,
2017-03-15 08:46:11 +01:00
'snmp_community' = > $ community ,
'snmp_oid' = > "$PandoraFMS::Recon::Base::IFINOCTECTS.$if_index" ) ;
pandora_create_module_from_hash ( $ self - > { 'pa_config' } , \ % module , $ self - > { 'dbh' } ) ;
} else {
my % module = (
'ip_target' = > $ device ,
'snmp_community' = > $ community ,
2018-09-17 14:36:52 +02:00
'tcp_send' = > $ self - > { 'snmp_version' } ,
'custom_string_1' = > $ self - > { 'snmp_privacy_method' } ,
'custom_string_2' = > $ self - > { 'snmp_privacy_pass' } ,
'custom_string_3' = > $ self - > { 'snmp_security_level' } ,
'plugin_parameter' = > $ self - > { 'snmp_auth_method' } ,
'plugin_user' = > $ self - > { 'snmp_auth_user' } ,
'plugin_pass' = > $ self - > { 'snmp_auth_pass' } ,
2017-03-15 08:46:11 +01:00
) ;
pandora_update_module_from_hash ( $ self - > { 'pa_config' } , \ % module , 'id_agente_modulo' , $ module_id , $ self - > { 'dbh' } ) ;
}
2017-03-08 13:20:00 +01:00
}
# Outgoing traffic module.
2017-03-15 08:46:11 +01:00
my $ if_hc_out_octets = $ self - > snmp_get_value ( $ device , "$PandoraFMS::Recon::Base::IFHCOUTOCTECTS.$if_index" ) ;
if ( defined ( $ if_hc_out_octets ) ) {
$ module_id = get_agent_module_id ( $ self - > { 'dbh' } , "${if_name}_ifHCOutOctets" , $ agent_id ) ;
if ( $ module_id <= 0 ) {
my % module = ( 'id_tipo_modulo' = > 16 ,
'id_modulo' = > 2 ,
'nombre' = > "${if_name}_ifHCOutOctets" ,
'descripcion' = > 'The total number of octets received on the interface, including framing characters. This object is a 64-bit version of ifOutOctets.' ,
'id_agente' = > $ agent_id ,
'ip_target' = > $ device ,
2018-09-17 14:36:52 +02:00
'tcp_send' = > $ self - > { 'snmp_version' } ,
'custom_string_1' = > $ self - > { 'snmp_privacy_method' } ,
'custom_string_2' = > $ self - > { 'snmp_privacy_pass' } ,
'custom_string_3' = > $ self - > { 'snmp_security_level' } ,
'plugin_parameter' = > $ self - > { 'snmp_auth_method' } ,
'plugin_user' = > $ self - > { 'snmp_auth_user' } ,
'plugin_pass' = > $ self - > { 'snmp_auth_pass' } ,
2017-03-15 08:46:11 +01:00
'snmp_community' = > $ community ,
'snmp_oid' = > "$PandoraFMS::Recon::Base::IFHCOUTOCTECTS.$if_index" ) ;
pandora_create_module_from_hash ( $ self - > { 'pa_config' } , \ % module , $ self - > { 'dbh' } ) ;
} else {
my % module = (
'ip_target' = > $ device ,
'snmp_community' = > $ community ,
2018-09-17 14:36:52 +02:00
'tcp_send' = > $ self - > { 'snmp_version' } ,
'tcp_send' = > $ self - > { 'snmp_version' } ,
'custom_string_1' = > $ self - > { 'snmp_privacy_method' } ,
'custom_string_2' = > $ self - > { 'snmp_privacy_pass' } ,
'custom_string_3' = > $ self - > { 'snmp_security_level' } ,
'plugin_parameter' = > $ self - > { 'snmp_auth_method' } ,
'plugin_user' = > $ self - > { 'snmp_auth_user' } ,
'plugin_pass' = > $ self - > { 'snmp_auth_pass' } ,
2017-03-15 08:46:11 +01:00
) ;
pandora_update_module_from_hash ( $ self - > { 'pa_config' } , \ % module , 'id_agente_modulo' , $ module_id , $ self - > { 'dbh' } ) ;
}
}
# ifOutOctets
2018-10-29 12:09:35 +01:00
elsif ( defined ( $ self - > snmp_get_value ( $ device , "$PandoraFMS::Recon::Base::IFOUTOCTECTS.$if_index" ) ) ) {
2017-03-15 08:46:11 +01:00
$ module_id = get_agent_module_id ( $ self - > { 'dbh' } , "${if_name}_ifOutOctets" , $ agent_id ) ;
if ( $ module_id <= 0 ) {
my % module = ( 'id_tipo_modulo' = > 16 ,
'id_modulo' = > 2 ,
'nombre' = > "${if_name}_ifOutOctets" ,
'descripcion' = > 'The total number of octets received on the interface, including framing characters.' ,
'id_agente' = > $ agent_id ,
'ip_target' = > $ device ,
2018-09-17 14:36:52 +02:00
'tcp_send' = > $ self - > { 'snmp_version' } ,
'custom_string_1' = > $ self - > { 'snmp_privacy_method' } ,
'custom_string_2' = > $ self - > { 'snmp_privacy_pass' } ,
'custom_string_3' = > $ self - > { 'snmp_security_level' } ,
'plugin_parameter' = > $ self - > { 'snmp_auth_method' } ,
'plugin_user' = > $ self - > { 'snmp_auth_user' } ,
'plugin_pass' = > $ self - > { 'snmp_auth_pass' } ,
2017-03-15 08:46:11 +01:00
'snmp_community' = > $ community ,
'snmp_oid' = > "$PandoraFMS::Recon::Base::IFOUTOCTECTS.$if_index" ) ;
pandora_create_module_from_hash ( $ self - > { 'pa_config' } , \ % module , $ self - > { 'dbh' } ) ;
} else {
my % module = (
'ip_target' = > $ device ,
'snmp_community' = > $ community ,
2018-09-17 14:36:52 +02:00
'tcp_send' = > $ self - > { 'snmp_version' } ,
'tcp_send' = > $ self - > { 'snmp_version' } ,
'custom_string_1' = > $ self - > { 'snmp_privacy_method' } ,
'custom_string_2' = > $ self - > { 'snmp_privacy_pass' } ,
'custom_string_3' = > $ self - > { 'snmp_security_level' } ,
'plugin_parameter' = > $ self - > { 'snmp_auth_method' } ,
'plugin_user' = > $ self - > { 'snmp_auth_user' } ,
'plugin_pass' = > $ self - > { 'snmp_auth_pass' } ,
2017-03-15 08:46:11 +01:00
) ;
pandora_update_module_from_hash ( $ self - > { 'pa_config' } , \ % module , 'id_agente_modulo' , $ module_id , $ self - > { 'dbh' } ) ;
}
2017-03-08 13:20:00 +01:00
}
}
return $ agent_id ;
}
##########################################################################
# Delete already existing connections.
##########################################################################
2017-03-13 11:13:45 +01:00
sub PandoraFMS ::Recon::Base::delete_connections($) {
2017-03-08 13:20:00 +01:00
my ( $ self ) = @ _ ;
$ self - > call ( 'message' , "Deleting connections..." , 10 ) ;
db_do ( $ self - > { 'dbh' } , 'DELETE FROM tmodule_relationship WHERE id_rt=?' , $ self - > { 'task_id' } ) ;
}
#######################################################################
# Print log messages.
#######################################################################
2017-03-13 11:13:45 +01:00
sub PandoraFMS ::Recon::Base::message($$$) {
2017-03-08 13:20:00 +01:00
my ( $ self , $ message , $ verbosity ) = @ _ ;
logger ( $ self - > { 'pa_config' } , "[Recon task " . $ self - > { 'task_id' } . "] $message" , $ verbosity ) ;
}
##########################################################################
# Connect the given hosts to its parent.
##########################################################################
2017-03-13 11:13:45 +01:00
sub PandoraFMS ::Recon::Base::set_parent($$$) {
2017-03-08 13:20:00 +01:00
my ( $ self , $ host , $ parent ) = @ _ ;
return unless ( $ self - > { 'parent_detection' } == 1 ) ;
# Get the agent for the host.
my $ agent = get_agent_from_addr ( $ self - > { 'dbh' } , $ host ) ;
if ( ! defined ( $ agent ) ) {
$ agent = get_agent_from_name ( $ self - > { 'dbh' } , $ host ) ;
}
return unless defined ( $ agent ) ;
# Check if the parent agent exists.
my $ agent_parent = get_agent_from_addr ( $ self - > { 'dbh' } , $ parent ) ;
if ( ! defined ( $ agent_parent ) ) {
$ agent_parent = get_agent_from_name ( $ self - > { 'dbh' } , $ parent ) ;
}
2017-03-23 14:33:06 +01:00
return unless ( defined ( $ agent_parent ) ) ;
2017-03-08 13:20:00 +01:00
2017-03-23 14:33:06 +01:00
# Is the agent in learning mode?
return unless ( $ agent_parent - > { 'modo' } == 1 ) ;
2017-03-08 13:20:00 +01:00
# Connect the host to its parent.
2017-03-23 14:33:06 +01:00
db_do ( $ self - > { 'dbh' } , 'UPDATE tagente SET id_parent=? WHERE id_agente=?' , $ agent_parent - > { 'id_agente' } , $ agent - > { 'id_agente' } ) ;
2017-03-08 13:20:00 +01:00
}
2019-02-13 14:56:10 +01:00
##########################################################################
# 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' } ) ;
}
2017-03-08 13:20:00 +01:00
##########################################################################
# Update recon task status.
##########################################################################
2017-03-13 11:13:45 +01:00
sub PandoraFMS ::Recon::Base::update_progress ($$) {
2017-03-08 13:20:00 +01:00
my ( $ self , $ progress ) = @ _ ;
db_do ( $ self - > { 'dbh' } , 'UPDATE trecon_task SET utimestamp = ?, status = ? WHERE id_rt = ?' , time ( ) , $ progress , $ self - > { 'task_id' } ) ;
}
2009-04-14 Ramon Novoa <rnovoa@artica.es>
* pandora_ctl, pandora_network, pandora_wmi, pandora_plugin,
pandora_prediction, bin/pandora_wmi, bin/pandora_plugin,
bin/pandora_prediction, bin/pandora_snmpconsole, bin/pandora_recon,
bin/pandora_network, pandora_recon, pandora_snmpconsole: Deleted
from repository. Old server code and startup scripts.
* Makefile.PL, pandora_server_installer, lib/PandoraFMS/Config.pm
lib/PandoraFMS/DB.pm, lib/PandoraFMS/Tools.pm, bin/pandora_server,
pandora_package_installer, pandora_server: Updated to work with the
new code, removed unneeded dependencies, fixed some bugs etc.
* lib/PandoraFMS/SNMPServer.pm, lib/PandoraFMS/PluginServer.pm,
lib/PandoraFMS/ProducerConsumerServer.pm, lib/PandoraFMS/Server.pm,
lib/PandoraFMS/PredictionServer.pm, lib/PandoraFMS/Core.pm,
lib/PandoraFMS/ReconServer.pm, lib/PandoraFMS/DataServer.pm,
lib/PandoraFMS/NetworkServer.pm, lib/PandoraFMS/WMIServer.pm: Added
to repository. New server code.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1620 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-04-14 21:13:16 +02:00
1 ;
__END__