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
package PandoraFMS::DataServer ;
##########################################################################
# Pandora FMS Data Server.
# Pandora FMS. the Flexible Monitoring System. http://www.pandorafms.org
##########################################################################
2020-11-27 13:52:35 +01:00
# Copyright (c) 2005-2021 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 Time::Local ;
2016-11-15 11:28:52 +01:00
use XML::Parser::Expat ;
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 XML::Simple ;
2020-01-28 20:15:53 +01:00
eval "use POSIX::strftime::GNU;1" if ( $^O =~ /win/i ) ;
2009-08-19 03:41:25 +02:00
use POSIX qw( setsid strftime ) ;
2018-08-08 09:07:18 +02:00
use IO::Uncompress::Unzip ;
2019-01-21 15:12:46 +01:00
use JSON qw( decode_json ) ;
use MIME::Base64 ;
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-01-04 10:42:24 +01:00
# Required for file names with accents
use Encode qw( decode ) ;
use Encode::Locale ( ) ;
2011-02-07 14:45:34 +01:00
# For Reverse Geocoding
use LWP::Simple ;
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 16:43:41 +02:00
use PandoraFMS::GIS ;
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 ;
2012-11-28 15:33:26 +01:00
my % Agents : shared ;
2013-08-01 11:54:21 +02:00
my $ Sem : shared ;
my $ TaskSem : shared ;
my $ AgentSem : shared ;
2019-09-02 15:24:21 +02:00
my $ XMLinSem : 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
########################################################################################
# Data Server class constructor.
########################################################################################
sub new ($$;$) {
my ( $ class , $ config , $ dbh ) = @ _ ;
return undef unless $ config - > { 'dataserver' } == 1 ;
2013-08-01 11:54:21 +02:00
# Initialize semaphores and queues
@ TaskQueue = ( ) ;
% PendingTasks = ( ) ;
% Agents = ( ) ;
$ Sem = Thread::Semaphore - > new ;
$ TaskSem = Thread::Semaphore - > new ( 0 ) ;
$ AgentSem = Thread::Semaphore - > new ( 1 ) ;
2019-09-02 15:24:21 +02:00
$ XMLinSem = Thread::Semaphore - > new ( 1 ) ;
2013-08-01 11:54:21 +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
2014-09-10 13:18:02 +02:00
my $ self = $ class - > SUPER:: new ( $ config , DATASERVER , \ & PandoraFMS::DataServer:: data_producer , \ & PandoraFMS::DataServer:: data_consumer , $ dbh ) ;
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
2016-11-15 11:28:52 +01:00
# Load external .enc files for XML::Parser.
2020-01-29 16:31:08 +01:00
if ( $ config - > { 'enc_dir' } ne '' ) {
2017-09-28 15:16:32 +02:00
push ( @ XML:: Parser:: Expat:: Encoding_Path , $ config - > { 'enc_dir' } ) ;
2020-01-29 16:31:08 +01:00
if ( $ XML:: Simple:: PREFERRED_PARSER eq 'XML::SAX::ExpatXS' ) {
push ( @ XML:: SAX:: ExpatXS:: Encoding:: Encoding_Path , $ config - > { 'enc_dir' } ) ;
}
2016-11-15 11:28:52 +01:00
}
2019-07-25 13:00:40 +02:00
if ( $ config - > { 'autocreate_group' } > 0 && ! defined ( get_group_name ( $ dbh , $ config - > { 'autocreate_group' } ) ) ) {
my $ msg = "Group id " . $ config - > { 'autocreate_group' } . " does not exist (check autocreate_group config token)." ;
logger ( $ config , $ msg , 3 ) ;
print_message ( $ config , $ msg , 1 ) ;
pandora_event ( $ config , $ msg , 0 , 0 , 0 , 0 , 0 , 'error' , 0 , $ dbh ) ;
}
2011-03-14 11:39:31 +01: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 ( ) ;
2018-05-17 16:12:44 +02:00
print_message ( $ pa_config , " [*] Starting " . $ pa_config - > { 'rb_product_name' } . " Data 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 - > { 'dataserver_threads' } ) ;
$ self - > SUPER:: run ( \ @ TaskQueue , \ % PendingTasks , $ Sem , $ TaskSem ) ;
}
###############################################################################
# Data producer.
###############################################################################
sub data_producer ($) {
my $ self = shift ;
2020-07-10 13:21:30 +02:00
my ( $ pa_config , $ dbh ) = ( $ self - > getConfig ( ) , $ self - > getDBH ( ) ) ;
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 ;
2010-07-27 19:12:17 +02:00
my @ files ;
2015-08-10 16:46:10 +02:00
my @ sorted ;
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-07-27 19:12:17 +02:00
# Open the incoming directory
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
opendir ( DIR , $ pa_config - > { 'incomingdir' } )
2011-03-14 11:39:31 +01:00
|| die "[FATAL] Cannot open Incoming data directory at " . $ pa_config - > { 'incomingdir' } . ": $!" ;
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-07-27 19:12:17 +02:00
# Do not read more than max_queue_files files
my $ file_count = 0 ;
while ( my $ file = readdir ( DIR ) ) {
2019-01-04 10:42:24 +01:00
$ file = Encode:: decode ( locale_fs = > $ file ) ;
2015-08-10 16:46:10 +02:00
2011-06-02 17:28:29 +02:00
# Data files must have the extension .data
2015-08-10 16:46:10 +02:00
next if ( $ file !~ /^.*[\._]\d+\.data$/ ) ;
2012-11-28 15:33:26 +01:00
2011-06-02 17:28:29 +02:00
# Do not queue more than max_queue_files files
2011-06-08 13:07:39 +02:00
if ( $ file_count >= $ pa_config - > { "max_queue_files" } ) {
2010-07-27 19:12:17 +02:00
last ;
}
2015-08-10 16:46:10 +02:00
push ( @ files , $ file ) ;
$ file_count + + ;
2010-07-27 19:12:17 +02:00
}
2010-07-22 13:00:37 +02:00
closedir ( DIR ) ;
2015-08-10 16:46:10 +02:00
# Sort the queue
2010-07-27 19:12:17 +02:00
{
2015-08-10 16:46:10 +02:00
# Temporarily disable warnings (some files may have been deleted)
2012-10-24 11:38:08 +02:00
no warnings ;
if ( $ pa_config - > { 'dataserver_lifo' } == 0 ) {
2015-08-11 12:19:09 +02:00
@ sorted = sort { - M $ pa_config - > { 'incomingdir' } . "/$b" <=> - M $ pa_config - > { 'incomingdir' } . "/$a" || $ a cmp $ b } ( @ files ) ;
2012-10-24 11:38:08 +02:00
} else {
2015-08-11 12:19:09 +02:00
@ sorted = sort { - M $ pa_config - > { 'incomingdir' } . "/$a" <=> - M $ pa_config - > { 'incomingdir' } . "/$b" || $ b cmp $ a } ( @ files ) ;
2012-10-24 11:38:08 +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
}
2015-08-10 16:46:10 +02:00
# Do not process more than one XML from the same agent at the same time
foreach my $ file ( @ sorted ) {
next if ( $ file !~ /^(.*)[\._]\d+\.data$/ ) ;
my $ agent_name = $ 1 ;
2020-07-10 13:21:30 +02:00
next if ( agent_lock ( $ pa_config , $ dbh , $ agent_name ) == 0 ) ;
2019-07-03 14:06:24 +02:00
2015-08-10 16:46:10 +02:00
push ( @ tasks , $ file ) ;
}
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 ) = @ _ ;
my ( $ pa_config , $ dbh ) = ( $ self - > getConfig ( ) , $ self - > getDBH ( ) ) ;
2012-11-28 15:33:26 +01:00
return unless ( $ task =~ /^(.*)[\._]\d+\.data$/ ) ;
my $ agent_name = $ 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
my $ file_name = $ pa_config - > { 'incomingdir' } ;
2010-09-20 19:01:27 +02:00
my $ xml_err ;
2019-09-02 15:24:21 +02:00
my $ error ;
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
# Fix path
$ file_name . = "/" unless ( substr ( $ file_name , - 1 , 1 ) eq '/' ) ;
$ file_name . = $ task ;
2010-07-26 13:51:49 +02:00
# Double check that the file exists
2012-11-28 15:33:26 +01:00
if ( ! - f $ file_name ) {
2019-07-03 14:06:24 +02:00
agent_unlock ( $ pa_config , $ agent_name ) ;
2015-07-22 10:37:23 +02:00
return ;
2012-11-28 15:33:26 +01:00
}
2010-07-26 13:51:49 +02:00
2010-10-13 17:15:06 +02:00
# Try to parse the XML 2 times, with a delay between tries of 2 seconds
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 $ xml_data ;
2010-10-13 17:15:06 +02:00
for ( 0 .. 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
eval {
2019-09-02 15:24:21 +02:00
local $ SIG { __DIE__ } ;
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
threads - > yield ;
2019-09-02 15:24:21 +02:00
# XML::SAX::ExpatXS is not thread safe.
if ( $ XML:: Simple:: PREFERRED_PARSER eq 'XML::SAX::ExpatXS' ) {
$ XMLinSem - > down ( ) ;
}
2019-08-07 13:43:13 +02:00
2009-06-02 13:19:27 +02:00
$ xml_data = XMLin ( $ file_name , forcearray = > 'module' ) ;
2019-09-02 15:24:21 +02:00
if ( $ XML:: Simple:: PREFERRED_PARSER eq 'XML::SAX::ExpatXS' ) {
$ XMLinSem - > up ( ) ;
}
2010-07-26 13:51:49 +02:00
} ;
2010-02-23 18:49:05 +01:00
2010-07-26 13:51:49 +02:00
# Invalid XML
2019-09-02 15:24:21 +02:00
if ( $@ ) {
$ error = 1 ;
if ( $ XML:: Simple:: PREFERRED_PARSER eq 'XML::SAX::ExpatXS' ) {
$ XMLinSem - > up ( ) ;
}
}
if ( $ error || ref ( $ xml_data ) ne 'HASH' ) {
2012-04-10 16:21:56 +02:00
if ( $@ ) {
$ xml_err = $@ ;
} else {
$ xml_err = "Invalid XML format." ;
}
2019-09-02 15:24:21 +02:00
logger ( $ pa_config , "Failed to parse $file_name $xml_err" , 3 ) ;
2010-10-13 17:15:06 +02:00
sleep ( 2 ) ;
2010-07-26 13:51:49 +02:00
next ;
}
2010-02-23 18:49:05 +01:00
2010-07-26 13:51:49 +02:00
# Ignore the timestamp in the XML and use the file timestamp instead
2020-05-26 13:56:39 +02:00
# If 1 => uses timestamp from received XML #5763.
2019-10-09 15:46:44 +02:00
$ xml_data - > { 'timestamp' } = strftime ( "%Y-%m-%d %H:%M:%S" , localtime ( ( stat ( $ file_name ) ) [ 9 ] ) ) if ( $ pa_config - > { 'use_xml_timestamp' } eq '0' || ! defined ( $ xml_data - > { 'timestamp' } ) ) ;
2009-08-24 20:25:42 +02:00
2011-03-14 11:39:31 +01:00
# Double check that the file exists
2012-11-28 15:33:26 +01:00
if ( ! - f $ file_name ) {
2019-07-03 14:06:24 +02:00
agent_unlock ( $ pa_config , $ agent_name ) ;
2015-07-22 10:37:23 +02:00
return ;
2012-11-28 15:33:26 +01:00
}
2010-10-13 17:15:06 +02:00
2010-07-26 13:51:49 +02:00
unlink ( $ file_name ) ;
2015-10-14 14:55:55 +02:00
if ( defined ( $ xml_data - > { 'server_name' } ) ) {
process_xml_server ( $ self - > getConfig ( ) , $ file_name , $ xml_data , $ self - > getDBH ( ) ) ;
2017-03-08 13:20:00 +01:00
} elsif ( defined ( $ xml_data - > { 'connection_source' } ) ) {
enterprise_hook ( 'process_xml_connections' , [ $ self - > getConfig ( ) , $ file_name , $ xml_data , $ self - > getDBH ( ) ] ) ;
2019-01-21 18:27:31 +01:00
} elsif ( defined ( $ xml_data - > { 'network_matrix' } ) ) {
process_xml_matrix_network (
$ self - > getConfig ( ) , $ xml_data , $ self - > getDBH ( )
) ;
2015-10-14 14:55:55 +02:00
} else {
process_xml_data ( $ self - > getConfig ( ) , $ file_name , $ xml_data , $ self - > getServerID ( ) , $ self - > getDBH ( ) ) ;
}
2019-07-03 14:06:24 +02:00
agent_unlock ( $ pa_config , $ agent_name ) ;
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 ;
}
rename ( $ file_name , $ file_name . '_BADXML' ) ;
2010-09-20 19:01:27 +02:00
pandora_event ( $ pa_config , "Unable to process XML data file '$file_name': $xml_err" , 0 , 0 , 0 , 0 , 0 , 'error' , 0 , $ dbh ) ;
2019-07-03 14:06:24 +02:00
agent_unlock ( $ pa_config , $ agent_name ) ;
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
}
###############################################################################
# Process XML data coming from an agent.
###############################################################################
2009-11-13 Ramon Novoa <rnovoa@artica.es>
* conf/pandora_server.conf: Updated configuration tokens.
* lib/PandoraFMS/SNMPServer.pm, lib/PandoraFMS/Config.pm,
lib/PandoraFMS/PluginServer.pm, lib/PandoraFMS/PredictionServer.pm,
lib/PandoraFMS/Core.pm, lib/PandoraFMS/ReconServer.pm,
lib/PandoraFMS/DataServer.pm, lib/PandoraFMS/NetworkServer.pm,
lib/PandoraFMS/Tools.pm, lib/PandoraFMS/WMIServer.pm,
bin/pandora_server: Standardized and improved logging.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2108 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-11-13 14:52:48 +01:00
sub process_xml_data ($$$$$) {
my ( $ pa_config , $ file_name , $ data , $ server_id , $ dbh ) = @ _ ;
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
2012-11-15 16:20:48 +01:00
my ( $ agent_name , $ agent_version , $ timestamp , $ interval , $ os_version , $ timezone_offset , $ custom_id , $ url_address ) =
2010-02-23 18:49:05 +01:00
( $ data - > { 'agent_name' } , $ data - > { 'version' } , $ data - > { 'timestamp' } ,
2012-11-15 16:20:48 +01:00
$ data - > { 'interval' } , $ data - > { 'os_version' } , $ data - > { 'timezone_offset' } ,
$ data - > { 'custom_id' } , $ data - > { 'url_address' } ) ;
2010-01-25 19:36:23 +01:00
2010-01-29 16:40:05 +01:00
# Timezone offset must be an integer beween -12 and +12
2017-02-02 12:38:45 +01:00
if ( ! defined ( $ timezone_offset ) || $ timezone_offset !~ /[-+]?\d+/ ) {
2013-03-01 15:27:52 +01:00
$ timezone_offset = 0 ;
2010-01-29 16:40:05 +01:00
}
2010-02-22 20:43:39 +01:00
2021-04-27 17:58:20 +02:00
# If set by server, do not use offset.
if ( $ pa_config - > { 'use_xml_timestamp' } eq '0' ) {
$ timezone_offset = 0 ;
}
2010-02-22 20:43:39 +01:00
# Parent Agent Name
2010-02-25 18:09:19 +01:00
my $ parent_id = 0 ; # Default value for unknown parent
2010-02-22 20:43:39 +01:00
my $ parent_agent_name = $ data - > { 'parent_agent_name' } ;
2013-11-13 13:09:28 +01:00
if ( defined ( $ parent_agent_name ) && $ parent_agent_name ne '' ) {
2011-03-14 11:39:31 +01:00
$ parent_id = get_agent_id ( $ dbh , $ parent_agent_name ) ;
2010-02-25 18:09:19 +01:00
if ( $ parent_id < 1 ) { # Unknown parent
$ parent_id = 0 ;
}
2010-03-04 10:24:52 +01:00
}
2016-06-03 11:58:13 +02:00
# Get agent mode
my $ agent_mode = 1 ; # Default value learning mode
$ agent_mode = $ data - > { 'agent_mode' } if ( defined ( $ data - > { 'agent_mode' } ) ) ;
2010-01-29 16:40:05 +01: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
# Unknown agent!
if ( ! defined ( $ agent_name ) || $ agent_name eq '' ) {
2009-11-13 Ramon Novoa <rnovoa@artica.es>
* conf/pandora_server.conf: Updated configuration tokens.
* lib/PandoraFMS/SNMPServer.pm, lib/PandoraFMS/Config.pm,
lib/PandoraFMS/PluginServer.pm, lib/PandoraFMS/PredictionServer.pm,
lib/PandoraFMS/Core.pm, lib/PandoraFMS/ReconServer.pm,
lib/PandoraFMS/DataServer.pm, lib/PandoraFMS/NetworkServer.pm,
lib/PandoraFMS/Tools.pm, lib/PandoraFMS/WMIServer.pm,
bin/pandora_server: Standardized and improved logging.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2108 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-11-13 14:52:48 +01:00
logger ( $ pa_config , "$file_name has data from an unnamed agent" , 3 ) ;
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 ;
}
2010-02-23 18:49:05 +01:00
2009-08-19 03:41:25 +02:00
# Get current datetime from system if value AUTO is coming in the XML
if ( $ data - > { 'timestamp' } =~ /AUTO/ ) {
$ timestamp = strftime ( "%Y/%m/%d %H:%M:%S" , localtime ( ) ) ;
}
2013-03-01 15:27:52 +01:00
# Apply an offset to the timestamp
elsif ( $ timezone_offset != 0 ) {
2010-01-21 15:58:38 +01:00
# Modify the timestamp with the timezone_offset
2013-03-01 15:27:52 +01:00
logger ( $ pa_config , "Applied a timezone offset of $timestamp to agent " . $ data - > { 'agent_name' } , 10 ) ;
# Calculate the start date to add the offset
my $ utimestamp = 0 ;
eval {
if ( $ timestamp =~ /(\d+)[\/|\-](\d+)[\/|\-](\d+) +(\d+):(\d+):(\d+)/ ) {
2020-01-02 15:46:27 +01:00
$ utimestamp = strftime ( "%s" , $ 6 , $ 5 , $ 4 , $ 3 , $ 2 - 1 , $ 1 - 1900 ) ;
2013-03-01 15:27:52 +01:00
}
} ;
# Apply the offset if there were no errors
if ( ! $@ && $ utimestamp != 0 ) {
$ timestamp = strftime ( "%Y-%m-%d %H:%M:%S" , localtime ( $ utimestamp + ( $ timezone_offset * 3600 ) ) ) ;
2010-01-29 16:40:05 +01:00
}
2010-01-21 15:58:38 +01:00
}
2010-02-23 18:49:05 +01:00
# Check some variables
$ interval = 300 if ( ! defined ( $ interval ) || $ interval eq '' ) ;
2017-09-11 17:46:56 +02:00
$ os_version = undef if ( ! defined ( $ os_version ) || $ os_version eq '' ) ;
2010-11-18 19:24:21 +01:00
# Get agent address from the XML if available
my $ address = '' ;
2013-04-17 12:49:47 +02:00
my @ address_list ;
if ( defined ( $ data - > { 'address' } ) && $ data - > { 'address' } ne '' ) {
@ address_list = split ( ',' , $ data - > { 'address' } ) ;
2010-02-23 18:49:05 +01:00
2013-04-17 12:49:47 +02:00
# Trim addresses
for ( my $ i = 0 ; $ i <= $# address_list ; $ i + + ) {
$ address_list [ $ i ] =~ s/^\s+|\s+$//g ;
}
# Save the first address as the main address
2017-07-10 12:20:23 +02:00
if ( defined ( $ address_list [ 0 ] ) ) {
$ address = $ address_list [ 0 ] ;
$ address =~ s/^\s+|\s+$//g ;
shift ( @ address_list ) ;
}
}
2013-04-17 12:49:47 +02:00
2016-06-03 11:58:13 +02:00
# A module with No-learn mode (modo = 0) creates its modules on database only when it is created
my $ new_agent = 0 ;
2010-02-23 18:49:05 +01:00
# Get agent 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
my $ agent_id = get_agent_id ( $ dbh , $ agent_name ) ;
2019-01-21 15:12:46 +01:00
my $ group_id = 0 ;
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
if ( $ agent_id < 1 ) {
if ( $ pa_config - > { 'autocreate' } == 0 ) {
logger ( $ pa_config , "ERROR: There is no agent defined with name $agent_name" , 3 ) ;
return ;
}
2009-08-04 18:19:15 +02:00
# Get OS, group and description
2013-03-26 17:13:15 +01:00
my $ os = pandora_get_os ( $ dbh , $ data - > { 'os_name' } ) ;
2019-07-25 13:00:40 +02:00
$ group_id = pandora_get_agent_group ( $ pa_config , $ dbh , $ agent_name , $ data - > { 'group' } , $ data - > { 'group_password' } ) ;
if ( $ group_id <= 0 ) {
pandora_event ( $ pa_config , "Unable to create agent '" . safe_output ( $ agent_name ) . "': No valid group found." , 0 , 0 , 0 , 0 , 0 , 'error' , 0 , $ dbh ) ;
logger ( $ pa_config , "Unable to create agent '" . safe_output ( $ agent_name ) . "': No valid group found." , 3 ) ;
2016-11-25 12:41:48 +01:00
return ;
}
2009-08-04 18:19:15 +02:00
my $ description = '' ;
$ description = $ data - > { 'description' } if ( defined ( $ data - > { 'description' } ) ) ;
2017-02-21 14:24:06 +01:00
my $ alias = ( defined ( $ data - > { 'agent_alias' } ) && $ data - > { 'agent_alias' } ne '' ) ? $ data - > { 'agent_alias' } : $ data - > { 'agent_name' } ;
2018-07-05 16:43:41 +02:00
my $ location = get_geoip_info ( $ pa_config , $ address ) ;
$ agent_id = pandora_create_agent ( $ pa_config , $ pa_config - > { 'servername' } , $ agent_name , $ address ,
$ group_id , $ parent_id , $ os ,
$ description , $ interval , $ dbh , $ timezone_offset ,
$ location - > { 'longitude' } , $ location - > { 'latitude' } , undef , undef ,
$ custom_id , $ url_address , $ agent_mode , $ alias
) ;
2009-11-10 13:25:10 +01:00
if ( ! defined ( $ agent_id ) ) {
return ;
}
2018-04-04 16:05:18 +02:00
# Update the secondary groups
enterprise_hook ( 'add_secondary_groups_name' , [ $ pa_config , $ dbh , $ agent_id , $ data - > { 'secondary_groups' } ] ) ;
2012-11-15 16:20:48 +01:00
2016-06-03 11:58:13 +02:00
# This agent is new.
$ new_agent = 1 ;
2013-04-17 12:49:47 +02:00
# Add the main address to the address list
if ( $ address ne '' ) {
pandora_add_agent_address ( $ pa_config , $ agent_id , $ agent_name , $ address , $ dbh ) ;
}
2012-11-15 16:20:48 +01:00
# Process custom fields
if ( defined ( $ data - > { 'custom_fields' } ) ) {
foreach my $ custom_fields ( @ { $ data - > { 'custom_fields' } } ) {
foreach my $ custom_field ( @ { $ custom_fields - > { 'field' } } ) {
my $ cf_name = get_tag_value ( $ custom_field , 'name' , '' ) ;
logger ( $ pa_config , "Processing custom field '" . $ cf_name . "'" , 10 ) ;
# Check if the custom field exists
my $ custom_field_info = get_db_single_row ( $ dbh , 'SELECT * FROM tagent_custom_fields WHERE name = ?' , safe_input ( $ cf_name ) ) ;
# If it exists add the value to the agent
if ( defined ( $ custom_field_info ) ) {
2019-01-15 18:22:55 +01:00
my $ cf_value = safe_input ( get_tag_value ( $ custom_field , 'value' , '' ) ) ;
2012-11-15 16:20:48 +01:00
my $ field_agent ;
$ field_agent - > { 'id_agent' } = $ agent_id ;
$ field_agent - > { 'id_field' } = $ custom_field_info - > { 'id_field' } ;
2019-01-15 18:22:55 +01:00
$ field_agent - > { 'description' } = $ cf_value ;
2012-11-15 16:20:48 +01:00
db_process_insert ( $ dbh , 'id_field' , 'tagent_custom_data' , $ field_agent ) ;
}
else {
logger ( $ pa_config , "The custom field '" . $ cf_name . "' does not exist. Discarded from XML" , 5 ) ;
}
}
}
}
2018-07-04 18:39:06 +02:00
if ( defined ( $ pa_config - > { 'autoconfigure_agents' } ) && $ pa_config - > { 'autoconfigure_agents' } == 1 ) {
# Update agent configuration once, before create agent - MetaConsole port to Node
enterprise_hook ( 'autoconfigure_agent' , [ $ pa_config , $ agent_name , $ agent_id , $ data , $ dbh ] ) ;
}
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
}
2021-09-27 10:07:23 +02:00
# Return if metaconsole, no further analysis.
return if ( PandoraFMS::Tools:: is_metaconsole ( $ pa_config ) ) ;
2013-02-07 18:01:10 +01:00
# Get the data of the agent, if fail return
2010-09-21 17:32:53 +02:00
my $ agent = get_db_single_row ( $ dbh , 'SELECT * FROM tagente WHERE id_agente = ?' , $ agent_id ) ;
if ( ! defined ( $ agent ) ) {
logger ( $ pa_config , "Error retrieving information for agent ID $agent_id" , 10 ) ;
2010-05-19 15:40:21 +02:00
return ;
}
2013-02-07 18:01:10 +01:00
# Check if agent is disabled and return if it's disabled. Disabled agents doesnt process data
# in order to avoid not only events, also possible invalid data coming from agents.
2016-06-03 11:58:13 +02:00
# But, if agent is in mode autodisable, put it enable and retrieve all data
if ( $ agent - > { 'disabled' } == 1 ) {
return unless ( $ agent - > { 'modo' } == 2 ) ;
logger ( $ pa_config , "Autodisable agent ID $agent_id is recovered to enable mode." , 10 ) ;
db_do ( $ dbh , 'UPDATE tagente SET disabled=0 WHERE id_agente=?' , $ agent_id ) ;
}
2010-09-21 17:32:53 +02:00
# Do not overwrite agent parameters if the agent is in normal mode
if ( $ agent - > { 'modo' } == 0 ) { ;
$ interval = $ agent - > { 'intervalo' } ;
$ os_version = $ agent - > { 'os_version' } ;
$ agent_version = $ agent - > { 'agent_version' } ;
$ timezone_offset = $ agent - > { 'timezone_offset' } ;
2013-02-07 18:01:10 +01:00
$ parent_id = $ agent - > { 'id_parent' } ;
2013-03-01 15:27:52 +01:00
}
# Learning mode
else {
2013-04-17 12:49:47 +02:00
# Update the main address
2010-11-18 19:24:21 +01:00
if ( $ address ne '' && $ address ne $ agent - > { 'direccion' } ) {
pandora_update_agent_address ( $ pa_config , $ agent_id , $ agent_name , $ address , $ dbh ) ;
2013-04-17 12:49:47 +02:00
pandora_add_agent_address ( $ pa_config , $ agent_id , $ agent_name , $ address , $ dbh ) ;
}
# Update additional addresses
foreach my $ address ( @ address_list ) {
pandora_add_agent_address ( $ pa_config , $ agent_id , $ agent_name , $ address , $ dbh ) ;
2010-11-18 19:24:21 +01:00
}
2013-02-07 18:01:10 +01:00
# Update parent if is allowed and is valid
2010-02-25 18:09:19 +01:00
if ( $ pa_config - > { 'update_parent' } == 1 && $ parent_id != 0 ) {
logger ( $ pa_config , "Updating agent $agent_name parent_id: $parent_id" , 5 ) ;
2010-02-24 16:25:56 +01:00
}
else {
2013-02-07 18:01:10 +01:00
$ parent_id = $ agent - > { 'id_parent' } ;
2010-02-24 16:25:56 +01:00
}
2013-02-28 16:38:23 +01:00
# Process custom fields for update
if ( defined ( $ data - > { 'custom_fields' } ) ) {
foreach my $ custom_fields ( @ { $ data - > { 'custom_fields' } } ) {
foreach my $ custom_field ( @ { $ custom_fields - > { 'field' } } ) {
my $ cf_name = get_tag_value ( $ custom_field , 'name' , '' ) ;
logger ( $ pa_config , "Processing custom field '" . $ cf_name . "'" , 10 ) ;
# Check if the custom field exists
my $ custom_field_info = get_db_single_row ( $ dbh , 'SELECT * FROM tagent_custom_fields WHERE name = ?' , safe_input ( $ cf_name ) ) ;
# If it exists add the value to the agent
if ( defined ( $ custom_field_info ) ) {
my $ custom_field_data = get_db_single_row ( $ dbh , 'SELECT * FROM tagent_custom_data WHERE id_field = ? AND id_agent = ?' ,
$ custom_field_info - > { "id_field" } , $ agent - > { "id_agente" } ) ;
2019-01-15 18:22:55 +01:00
my $ cf_value = safe_input ( get_tag_value ( $ custom_field , 'value' , '' ) ) ;
2013-02-28 16:38:23 +01:00
#If not defined we must create if defined just updated
if ( ! defined ( $ custom_field_data ) ) {
my $ field_agent ;
$ field_agent - > { 'id_agent' } = $ agent_id ;
$ field_agent - > { 'id_field' } = $ custom_field_info - > { 'id_field' } ;
2019-01-15 18:22:55 +01:00
$ field_agent - > { 'description' } = $ cf_value ;
2013-02-28 16:38:23 +01:00
db_process_insert ( $ dbh , 'id_field' , 'tagent_custom_data' , $ field_agent ) ;
} else {
db_update ( $ dbh , "UPDATE tagent_custom_data SET description = ? WHERE id_field = ? AND id_agent = ?" ,
2019-01-15 18:22:55 +01:00
$ cf_value , $ custom_field_info - > { "id_field" } , $ agent - > { 'id_agente' } ) ;
2013-02-28 16:38:23 +01:00
}
}
else {
logger ( $ pa_config , "The custom field '" . $ cf_name . "' does not exist. Discarded from XML" , 5 ) ;
}
}
}
}
2013-02-07 18:01:10 +01:00
}
# Update agent information
2013-03-01 15:27:52 +01:00
pandora_update_agent ( $ pa_config , $ timestamp , $ agent_id , $ os_version , $ agent_version , $ interval , $ dbh , $ timezone_offset , $ parent_id ) ;
# Update GIS data
if ( $ pa_config - > { 'activate_gis' } != 0 && $ agent - > { 'update_gis_data' } == 1 ) {
pandora_update_gis_data ( $ pa_config , $ dbh , $ agent_id , $ agent_name , $ data - > { 'longitude' } , $ data - > { 'latitude' } , $ data - > { 'altitude' } , $ data - > { 'position_description' } , $ timestamp ) ;
}
2013-02-07 18:01:10 +01:00
2013-03-01 15:27:52 +01:00
# Update keep alive modules
2009-04-23 17:33:25 +02:00
pandora_module_keep_alive ( $ pa_config , $ agent_id , $ agent_name , $ server_id , $ dbh ) ;
2011-06-28 17:41:13 +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
# Process modules
foreach my $ module_data ( @ { $ data - > { 'module' } } ) {
2009-06-02 13:19:27 +02:00
my $ module_name = get_tag_value ( $ module_data , 'name' , '' ) ;
2013-01-09 13:59:11 +01:00
# Clean module_name because sometimes due to errors or problems
# creating XMLs it could contain carriage returns and later they
# are a pain when you update module configuration because the name won't
# save the carriage return.
$ module_name =~ s/\r//g ;
$ module_name =~ s/\n//g ;
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
# Unnamed module
2009-06-02 13:19:27 +02:00
next if ( $ module_name eq '' ) ;
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
2009-06-02 13:19:27 +02:00
my $ module_type = get_tag_value ( $ module_data , 'type' , 'generic_data' ) ;
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-02-23 18:49:05 +01:00
# Single data
if ( ! defined ( $ module_data - > { 'datalist' } ) ) {
2009-06-02 13:19:27 +02:00
my $ data_timestamp = get_tag_value ( $ module_data , 'timestamp' , $ timestamp ) ;
2017-10-13 15:49:12 +02:00
process_module_data ( $ pa_config , $ module_data , $ server_id , $ agent , $ module_name , $ module_type , $ interval , $ data_timestamp , $ dbh , $ new_agent ) ;
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
next ;
}
# Data list
foreach my $ list ( @ { $ module_data - > { 'datalist' } } ) {
# Empty list
next unless defined ( $ list - > { 'data' } ) ;
foreach my $ data ( @ { $ list - > { 'data' } } ) {
# No value
next unless defined ( $ data - > { 'value' } ) ;
$ module_data - > { 'data' } = $ data - > { 'value' } ;
2014-01-08 16:46:44 +01:00
my $ data_timestamp = get_tag_value ( $ data , 'timestamp' , $ timestamp ) ;
2017-10-13 15:49:12 +02:00
process_module_data ( $ pa_config , $ module_data , $ server_id , $ agent , $ module_name ,
2016-06-03 11:58:13 +02:00
$ module_type , $ interval , $ data_timestamp , $ dbh , $ new_agent ) ;
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
}
}
}
2009-08-03 17:12:07 +02:00
2016-12-14 12:58:32 +01:00
# Link modules
foreach my $ module_data ( @ { $ data - > { 'module' } } ) {
my $ module_name = get_tag_value ( $ module_data , 'name' , '' ) ;
$ module_name =~ s/\r//g ;
$ module_name =~ s/\n//g ;
# Unnamed module
next if ( $ module_name eq '' ) ;
# No parent module defined
my $ parent_module_name = get_tag_value ( $ module_data , 'module_parent' , undef ) ;
2017-10-09 17:11:08 +02:00
my $ parent_module_unlink = get_tag_value ( $ module_data , 'module_parent_unlink' , undef ) ;
next if ( ( ! defined ( $ parent_module_name ) ) && ( ! defined ( $ parent_module_unlink ) ) ) ;
2016-12-14 12:58:32 +01:00
2017-10-09 17:11:08 +02:00
link_modules ( $ pa_config , $ dbh , $ agent_id , $ module_name , $ parent_module_name ) if ( defined ( $ parent_module_name ) && ( $ parent_module_name ne '' ) ) ;
unlink_modules ( $ pa_config , $ dbh , $ agent_id , $ module_name ) if ( defined ( $ parent_module_unlink ) && ( $ parent_module_unlink eq '1' ) ) ;
2016-12-14 12:58:32 +01:00
}
2017-10-09 17:11:08 +02:00
2009-08-03 17:12:07 +02:00
# Process inventory modules
2009-10-07 17:10:14 +02:00
enterprise_hook ( 'process_inventory_data' , [ $ pa_config , $ data , $ server_id , $ agent_name ,
2013-01-17 15:38:55 +01:00
$ interval , $ timestamp , $ dbh ] ) ;
# Process log modules
enterprise_hook ( 'process_log_data' , [ $ pa_config , $ data , $ server_id , $ agent_name ,
2010-02-23 18:49:05 +01:00
$ interval , $ timestamp , $ dbh ] ) ;
2018-08-08 09:07:18 +02:00
# Process snmptrapd modules
enterprise_hook ( 'process_snmptrap_data' , [ $ pa_config , $ data , $ server_id , $ dbh ] ) ;
2019-01-21 15:12:46 +01:00
# Process events
process_events_dataserver ( $ pa_config , $ data , $ agent_id , $ group_id , $ dbh ) ;
2019-01-29 18:15:59 +01:00
2019-11-21 18:21:46 +01:00
# Process discovery modules
2019-01-17 18:42:38 +01:00
enterprise_hook ( 'process_discovery_data' , [ $ pa_config , $ data , $ server_id , $ dbh ] ) ;
2019-11-21 18:21:46 +01:00
# Process command responses
enterprise_hook ( 'process_rcmd_report' , [ $ pa_config , $ data , $ server_id , $ dbh , $ agent_id , $ timestamp ] ) ;
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
}
##########################################################################
# Process module data, creating module if necessary.
##########################################################################
2016-06-03 11:58:13 +02:00
sub process_module_data ($$$$$$$$$$) {
2017-10-13 15:49:12 +02:00
my ( $ pa_config , $ data , $ server_id , $ agent ,
2010-02-23 18:49:05 +01:00
$ module_name , $ module_type , $ interval , $ timestamp ,
2016-06-03 11:58:13 +02:00
$ dbh , $ force_processing ) = @ _ ;
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
2009-04-23 17:33:25 +02:00
# Get agent data
2009-11-13 Ramon Novoa <rnovoa@artica.es>
* conf/pandora_server.conf: Updated configuration tokens.
* lib/PandoraFMS/SNMPServer.pm, lib/PandoraFMS/Config.pm,
lib/PandoraFMS/PluginServer.pm, lib/PandoraFMS/PredictionServer.pm,
lib/PandoraFMS/Core.pm, lib/PandoraFMS/ReconServer.pm,
lib/PandoraFMS/DataServer.pm, lib/PandoraFMS/NetworkServer.pm,
lib/PandoraFMS/Tools.pm, lib/PandoraFMS/WMIServer.pm,
bin/pandora_server: Standardized and improved logging.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2108 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-11-13 14:52:48 +01:00
if ( ! defined ( $ agent ) ) {
2017-10-13 15:49:12 +02:00
logger ( $ pa_config , "Invalid agent for module '$module_name'." , 3 ) ;
2009-11-13 Ramon Novoa <rnovoa@artica.es>
* conf/pandora_server.conf: Updated configuration tokens.
* lib/PandoraFMS/SNMPServer.pm, lib/PandoraFMS/Config.pm,
lib/PandoraFMS/PluginServer.pm, lib/PandoraFMS/PredictionServer.pm,
lib/PandoraFMS/Core.pm, lib/PandoraFMS/ReconServer.pm,
lib/PandoraFMS/DataServer.pm, lib/PandoraFMS/NetworkServer.pm,
lib/PandoraFMS/Tools.pm, lib/PandoraFMS/WMIServer.pm,
bin/pandora_server: Standardized and improved logging.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2108 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-11-13 14:52:48 +01:00
return ;
}
2017-10-13 15:49:12 +02:00
my $ agent_name = $ agent - > { 'nombre' } ;
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-09-20 19:01:27 +02:00
# Get module parameters, matching column names in tagente_modulo
my $ module_conf ;
2020-06-17 13:14:22 +02:00
# Extra usable fields but not supported at DB level.
my $ extra = { } ;
2011-08-10 18:58:26 +02:00
# Supported tags
my $ tags = { 'name' = > 0 , 'data' = > 0 , 'type' = > 0 , 'description' = > 0 , 'max' = > 0 ,
'min' = > 0 , 'descripcion' = > 0 , 'post_process' = > 0 , 'module_interval' = > 0 , 'min_critical' = > 0 ,
2011-08-24 13:41:27 +02:00
'max_critical' = > 0 , 'min_warning' = > 0 , 'max_warning' = > 0 , 'disabled' = > 0 , 'min_ff_event' = > 0 ,
2013-02-18 12:44:10 +01:00
'datalist' = > 0 , 'status' = > 0 , 'unit' = > 0 , 'timestamp' = > 0 , 'module_group' = > 0 , 'custom_id' = > '' ,
2012-11-13 13:31:14 +01:00
'str_warning' = > '' , 'str_critical' = > '' , 'critical_instructions' = > '' , 'warning_instructions' = > '' ,
'unknown_instructions' = > '' , 'tags' = > '' , 'critical_inverse' = > 0 , 'warning_inverse' = > 0 , 'quiet' = > 0 ,
2016-10-26 12:13:20 +02:00
'module_ff_interval' = > 0 , 'alert_template' = > '' , 'crontab' = > '' , 'min_ff_event_normal' = > 0 ,
2017-10-10 11:44:15 +02:00
'min_ff_event_warning' = > 0 , 'min_ff_event_critical' = > 0 , 'ff_timeout' = > 0 , 'each_ff' = > 0 , 'module_parent' = > 0 ,
2020-06-17 13:14:22 +02:00
'module_parent_unlink' = > 0 , 'cron_interval' = > 0 , 'ff_type' = > 0 , 'min_warning_forced' = > 0 , 'max_warning_forced' = > 0 ,
'min_critical_forced' = > 0 , 'max_critical_forced' = > 0 , 'str_warning_forced' = > 0 , 'str_critical_forced' = > 0
} ;
2014-07-25 15:15:24 +02:00
2011-08-10 18:58:26 +02:00
# Other tags will be saved here
$ module_conf - > { 'extended_info' } = '' ;
# Read tags
while ( my ( $ tag , $ value ) = each ( % { $ data } ) ) {
if ( defined ( $ tags - > { $ tag } ) ) {
2011-08-16 13:37:17 +02:00
$ module_conf - > { $ tag } = get_tag_value ( $ data , $ tag , '' ) ;
2011-08-10 18:58:26 +02:00
} else {
2011-08-16 13:37:17 +02:00
$ module_conf - > { 'extended_info' } . = "$tag: " . get_tag_value ( $ data , $ tag , '' ) . '<br/>' ;
2011-08-10 18:58:26 +02:00
}
2014-07-25 15:15:24 +02:00
}
2016-02-01 17:21:27 +01:00
# Reload alert_template to get all alerts like an array
$ module_conf - > { 'alert_template' } = get_tag_value ( $ data , 'alert_template' , '' , 1 ) ;
2011-08-10 18:58:26 +02:00
# Description XML tag and column name don't match
$ module_conf - > { 'descripcion' } = $ module_conf - > { 'description' } ;
2012-12-21 15:42:15 +01:00
$ module_conf - > { 'descripcion' } = '' unless defined ( $ module_conf - > { 'descripcion' } ) ;
2012-11-13 13:31:14 +01:00
delete $ module_conf - > { 'description' } ;
2010-09-20 19:01:27 +02:00
2012-11-13 13:31:14 +01:00
# Name XML tag and column name don't match
$ module_conf - > { 'nombre' } = safe_input ( $ module_name ) ;
2016-10-27 18:33:27 +02:00
# Check if module is 'Transactional subsystem status'
2017-02-09 10:15:50 +01:00
my $ enable_transactional_subsystem = 0 ;
2016-10-27 18:33:27 +02:00
if ( $ module_conf - > { 'name' } eq "Transactional subsystem status" ) {
2017-02-09 10:15:50 +01:00
$ enable_transactional_subsystem = 1 ;
2016-10-27 18:33:27 +02:00
}
2012-11-13 13:31:14 +01:00
delete $ module_conf - > { 'name' } ;
2014-07-25 15:15:24 +02:00
2010-09-20 19:01:27 +02:00
# Calculate the module interval in seconds
2018-02-20 18:31:08 +01:00
if ( defined ( $ module_conf - > { 'cron_interval' } ) ) {
$ module_conf - > { 'module_interval' } = $ module_conf - > { 'cron_interval' } ;
2018-03-13 13:03:44 +01:00
} elsif ( defined ( $ module_conf - > { 'module_interval' } ) ) {
$ module_conf - > { 'module_interval' } = $ interval * $ module_conf - > { 'module_interval' } ;
} else {
$ module_conf - > { 'module_interval' } = $ interval ;
2018-02-20 18:31:08 +01:00
}
2014-07-25 15:15:24 +02:00
2010-09-20 19:01:27 +02:00
# Allow , as a decimal separator
2011-02-23 11:50:00 +01:00
$ module_conf - > { 'post_process' } =~ s/,/./ if ( defined ( $ module_conf - > { 'post_process' } ) ) ;
2014-08-12 03:07:29 +02:00
# avoid NULL columns
$ module_conf - > { 'critical_instructions' } = '' unless defined ( $ module_conf - > { 'critical_instructions' } ) ;
$ module_conf - > { 'warning_instructions' } = '' unless defined ( $ module_conf - > { 'warning_instructions' } ) ;
$ module_conf - > { 'unknown_instructions' } = '' unless defined ( $ module_conf - > { 'unknown_instructions' } ) ;
$ module_conf - > { 'disabled_types_event' } = '' unless defined ( $ module_conf - > { 'disabled_types_event' } ) ;
$ module_conf - > { 'module_macros' } = '' unless defined ( $ module_conf - > { 'module_macros' } ) ;
2020-06-17 13:14:22 +02:00
# Extract extra fields.
foreach my $ pk ( keys % { $ module_conf } ) {
if ( $ pk =~ /_forced$/ ) {
$ extra - > { $ pk } = $ module_conf - > { $ pk } ;
delete $ module_conf - > { $ pk } ;
}
}
2009-04-23 17:33:25 +02:00
# Get module data or create it if it does not exist
2011-04-19 17:32:11 +02:00
my $ module = get_db_single_row ( $ dbh , 'SELECT * FROM tagente_modulo WHERE id_agente = ? AND ' . db_text ( 'nombre' ) . ' = ?' , $ agent - > { 'id_agente' } , safe_input ( $ module_name ) ) ;
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
if ( ! defined ( $ module ) ) {
2013-04-17 19:59:49 +02:00
2016-08-22 12:17:07 +02:00
# This part has a code commentary because it doesn't allow creating new modules on preexistent agents
2009-04-23 17:33:25 +02:00
# Do not auto create modules
2016-08-22 12:17:07 +02:00
#if ($pa_config->{'autocreate'} ne '1') {
# logger($pa_config, "Module '$module_name' not found for agent '$agent_name' and module auto-creation disabled.", 10);
# return;
#}
2014-07-25 15:15:24 +02:00
2016-06-03 11:58:13 +02:00
# Is the agent not learning?
if ( ( $ agent - > { 'modo' } == 0 ) && ! ( $ force_processing ) ) {
2009-11-13 Ramon Novoa <rnovoa@artica.es>
* conf/pandora_server.conf: Updated configuration tokens.
* lib/PandoraFMS/SNMPServer.pm, lib/PandoraFMS/Config.pm,
lib/PandoraFMS/PluginServer.pm, lib/PandoraFMS/PredictionServer.pm,
lib/PandoraFMS/Core.pm, lib/PandoraFMS/ReconServer.pm,
lib/PandoraFMS/DataServer.pm, lib/PandoraFMS/NetworkServer.pm,
lib/PandoraFMS/Tools.pm, lib/PandoraFMS/WMIServer.pm,
bin/pandora_server: Standardized and improved logging.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2108 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-11-13 14:52:48 +01:00
logger ( $ pa_config , "Learning mode disabled. Skipping module '$module_name' agent '$agent_name'." , 10 ) ;
return ;
}
2014-07-25 15:15:24 +02:00
2009-04-23 17:33:25 +02:00
# Get the module type
2012-11-13 13:31:14 +01:00
$ module_conf - > { 'id_tipo_modulo' } = get_module_id ( $ dbh , $ module_type ) ;
if ( $ module_conf - > { 'id_tipo_modulo' } <= 0 ) {
2009-11-13 Ramon Novoa <rnovoa@artica.es>
* conf/pandora_server.conf: Updated configuration tokens.
* lib/PandoraFMS/SNMPServer.pm, lib/PandoraFMS/Config.pm,
lib/PandoraFMS/PluginServer.pm, lib/PandoraFMS/PredictionServer.pm,
lib/PandoraFMS/Core.pm, lib/PandoraFMS/ReconServer.pm,
lib/PandoraFMS/DataServer.pm, lib/PandoraFMS/NetworkServer.pm,
lib/PandoraFMS/Tools.pm, lib/PandoraFMS/WMIServer.pm,
bin/pandora_server: Standardized and improved logging.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2108 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-11-13 14:52:48 +01:00
logger ( $ pa_config , "Invalid module type '$module_type' for module '$module_name' agent '$agent_name'." , 3 ) ;
return ;
}
2014-07-25 15:15:24 +02:00
2012-11-13 13:31:14 +01:00
# The group name has to be translated to a group ID
if ( defined $ module_conf - > { 'module_group' } ) {
2016-12-05 10:06:29 +01:00
my $ id_group_module = get_module_group_id ( $ dbh , $ module_conf - > { 'module_group' } ) ;
if ( $ id_group_module >= 0 ) {
$ module_conf - > { 'id_module_group' } = $ id_group_module ;
}
2012-11-13 13:31:14 +01:00
delete $ module_conf - > { 'module_group' } ;
}
2017-02-09 10:15:50 +01:00
if ( $ enable_transactional_subsystem == 1 ) {
# Defines current agent as transactional agent
pandora_mark_transactional_agent ( $ dbh , $ agent - > { 'id_agente' } ) ;
}
2014-07-25 15:15:24 +02:00
2012-11-13 13:31:14 +01:00
$ module_conf - > { 'id_modulo' } = 1 ;
$ module_conf - > { 'id_agente' } = $ agent - > { 'id_agente' } ;
2014-07-25 15:15:24 +02:00
2012-11-13 13:31:14 +01:00
my $ module_tags = undef ;
if ( defined ( $ module_conf - > { 'tags' } ) ) {
$ module_tags = $ module_conf - > { 'tags' } ;
delete $ module_conf - > { 'tags' } ;
}
2016-01-13 07:25:47 +01:00
my $ initial_alert_template = undef ;
if ( defined ( $ module_conf - > { 'alert_template' } ) ) {
$ initial_alert_template = $ module_conf - > { 'alert_template' } ;
delete $ module_conf - > { 'alert_template' } ;
}
2016-02-05 09:53:45 +01:00
if ( cron_check_syntax ( $ module_conf - > { 'crontab' } ) ) {
$ module_conf - > { 'cron_interval' } = $ module_conf - > { 'crontab' } ;
}
delete $ module_conf - > { 'crontab' } ;
2016-01-13 07:25:47 +01:00
2017-02-16 11:43:23 +01:00
# module_parent is a special case. It is not stored in the DB, but we will need it later.
my $ module_parent = $ module_conf - > { 'module_parent' } ;
delete $ module_conf - > { 'module_parent' } ;
2017-10-10 11:44:15 +02:00
# module_parent_unlink is a special case. It is not stored in the DB, but we will need it later.
my $ module_parent_unlink = $ module_conf - > { 'module_parent_unlink' } ;
delete $ module_conf - > { 'module_parent_unlink' } ;
2009-04-23 17:33:25 +02:00
# Create the module
2012-11-13 13:31:14 +01:00
my $ module_id = pandora_create_module_from_hash ( $ pa_config , $ module_conf , $ dbh ) ;
2014-07-25 15:15:24 +02:00
2017-02-16 11:43:23 +01:00
# Restore module_parent.
$ module_conf - > { 'module_parent' } = $ module_parent ;
2017-10-10 11:44:15 +02:00
# Restore module_parent_unlink.
$ module_conf - > { 'module_parent_unlink' } = $ module_parent_unlink ;
2011-04-19 17:32:11 +02:00
$ module = get_db_single_row ( $ dbh , 'SELECT * FROM tagente_modulo WHERE id_agente = ? AND ' . db_text ( 'nombre' ) . ' = ?' , $ agent - > { 'id_agente' } , safe_input ( $ module_name ) ) ;
2009-11-13 Ramon Novoa <rnovoa@artica.es>
* conf/pandora_server.conf: Updated configuration tokens.
* lib/PandoraFMS/SNMPServer.pm, lib/PandoraFMS/Config.pm,
lib/PandoraFMS/PluginServer.pm, lib/PandoraFMS/PredictionServer.pm,
lib/PandoraFMS/Core.pm, lib/PandoraFMS/ReconServer.pm,
lib/PandoraFMS/DataServer.pm, lib/PandoraFMS/NetworkServer.pm,
lib/PandoraFMS/Tools.pm, lib/PandoraFMS/WMIServer.pm,
bin/pandora_server: Standardized and improved logging.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2108 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-11-13 14:52:48 +01:00
if ( ! defined ( $ module ) ) {
logger ( $ pa_config , "Could not create module '$module_name' for agent '$agent_name'." , 3 ) ;
return ;
}
2011-02-23 11:50:00 +01:00
2012-11-13 13:31:14 +01:00
# Assign the tags on module if the specified tags exist
if ( defined ( $ module_tags ) ) {
logger ( $ pa_config , "Processing module tags '$module_tags' in module '$module_name' for agent '$agent_name'." , 10 ) ;
my @ module_tags = split ( /,/ , $ module_tags ) ;
for ( my $ i = 0 ; $ i <= $# module_tags ; $ i + + ) {
my $ tag_info = get_db_single_row ( $ dbh , 'SELECT * FROM ttag WHERE name = ?' , safe_input ( $ module_tags [ $ i ] ) ) ;
if ( defined ( $ tag_info ) ) {
my $ tag_module ;
$ tag_module - > { 'id_tag' } = $ tag_info - > { 'id_tag' } ;
$ tag_module - > { 'id_agente_modulo' } = $ module - > { 'id_agente_modulo' } ;
db_process_insert ( $ dbh , 'id_tag' , 'ttag_module' , $ tag_module ) ;
}
}
}
2016-01-13 07:25:47 +01:00
2016-02-01 17:21:27 +01:00
# Assign alert-templates if exist
2016-01-13 07:25:47 +01:00
if ( $ initial_alert_template ) {
2016-02-01 17:21:27 +01:00
foreach my $ individual_template ( @ { $ initial_alert_template } ) {
my $ id_alert_template = get_db_value ( $ dbh ,
'SELECT id FROM talert_templates WHERE talert_templates.name = ?' ,
safe_input ( $ individual_template ) ) ;
2016-01-13 07:25:47 +01:00
2016-02-01 17:21:27 +01:00
if ( defined ( $ id_alert_template ) ) {
pandora_create_template_module ( $ pa_config , $ dbh , $ module - > { 'id_agente_modulo' } , $ id_alert_template ) ;
}
2016-01-13 07:25:47 +01:00
}
}
2014-07-25 15:15:24 +02:00
}
else {
2011-04-19 17:32:11 +02:00
# Control NULL columns
$ module - > { 'descripcion' } = '' unless defined ( $ module - > { 'descripcion' } ) ;
2011-08-10 18:58:26 +02:00
$ module - > { 'extended_info' } = '' unless defined ( $ module - > { 'extended_info' } ) ;
2011-04-19 17:32:11 +02:00
2011-02-23 11:50:00 +01:00
# Set default values
$ module_conf - > { 'descripcion' } = $ module - > { 'descripcion' } unless defined ( $ module_conf - > { 'descripcion' } ) ;
2011-08-10 18:58:26 +02:00
$ module_conf - > { 'extended_info' } = $ module - > { 'extended_info' } unless defined ( $ module_conf - > { 'extended_info' } ) ;
2013-04-17 19:59:49 +02:00
$ module_conf - > { 'module_interval' } = $ module - > { 'module_interval' } unless defined ( $ module_conf - > { 'module_interval' } ) ;
2011-04-27 19:44:14 +02:00
}
2013-10-28 16:03:00 +01:00
# Check if the module is policy linked to update it or not
my $ policy_linked = 0 ;
if ( $ module - > { 'id_policy_module' } != 0 ) {
if ( $ module - > { 'policy_adopted' } == 0 || ( $ module - > { 'policy_adopted' } == 1 && $ module - > { 'policy_linked' } == 1 ) ) {
$ policy_linked = 1 ;
}
}
2011-05-23 15:13:34 +02:00
# Update module configuration if in learning mode and not a policy module
2016-06-03 11:58:13 +02:00
if ( ( ( $ agent - > { 'modo' } eq '1' ) || ( $ agent - > { 'modo' } eq '2' ) ) && $ policy_linked == 0 ) {
2020-06-17 13:14:22 +02:00
update_module_configuration (
$ pa_config ,
$ dbh ,
$ module ,
$ module_conf ,
$ extra
) ;
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
}
2014-07-25 15:15:24 +02:00
2009-10-16 13:26:22 +02:00
# Module disabled!
2009-11-13 Ramon Novoa <rnovoa@artica.es>
* conf/pandora_server.conf: Updated configuration tokens.
* lib/PandoraFMS/SNMPServer.pm, lib/PandoraFMS/Config.pm,
lib/PandoraFMS/PluginServer.pm, lib/PandoraFMS/PredictionServer.pm,
lib/PandoraFMS/Core.pm, lib/PandoraFMS/ReconServer.pm,
lib/PandoraFMS/DataServer.pm, lib/PandoraFMS/NetworkServer.pm,
lib/PandoraFMS/Tools.pm, lib/PandoraFMS/WMIServer.pm,
bin/pandora_server: Standardized and improved logging.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2108 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-11-13 14:52:48 +01:00
if ( $ module - > { 'disabled' } eq '1' ) {
logger ( $ pa_config , "Skipping disabled module '$module_name' agent '$agent_name'." , 10 ) ;
return ;
}
2014-07-25 15:15:24 +02:00
2009-04-23 17:33:25 +02:00
# Parse the timestamp and process the module
2009-11-13 Ramon Novoa <rnovoa@artica.es>
* conf/pandora_server.conf: Updated configuration tokens.
* lib/PandoraFMS/SNMPServer.pm, lib/PandoraFMS/Config.pm,
lib/PandoraFMS/PluginServer.pm, lib/PandoraFMS/PredictionServer.pm,
lib/PandoraFMS/Core.pm, lib/PandoraFMS/ReconServer.pm,
lib/PandoraFMS/DataServer.pm, lib/PandoraFMS/NetworkServer.pm,
lib/PandoraFMS/Tools.pm, lib/PandoraFMS/WMIServer.pm,
bin/pandora_server: Standardized and improved logging.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2108 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-11-13 14:52:48 +01:00
if ( $ timestamp !~ /(\d+)\/(\d+)\/(\d+) +(\d+):(\d+):(\d+)/ &&
2010-02-23 18:49:05 +01:00
$ timestamp !~ /(\d+)\-(\d+)\-(\d+) +(\d+):(\d+):(\d+)/ ) {
2009-11-13 Ramon Novoa <rnovoa@artica.es>
* conf/pandora_server.conf: Updated configuration tokens.
* lib/PandoraFMS/SNMPServer.pm, lib/PandoraFMS/Config.pm,
lib/PandoraFMS/PluginServer.pm, lib/PandoraFMS/PredictionServer.pm,
lib/PandoraFMS/Core.pm, lib/PandoraFMS/ReconServer.pm,
lib/PandoraFMS/DataServer.pm, lib/PandoraFMS/NetworkServer.pm,
lib/PandoraFMS/Tools.pm, lib/PandoraFMS/WMIServer.pm,
bin/pandora_server: Standardized and improved logging.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2108 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-11-13 14:52:48 +01:00
logger ( $ pa_config , "Invalid timestamp '$timestamp' from module '$module_name' agent '$agent_name'." , 3 ) ;
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
}
2010-02-22 21:18:37 +01:00
my $ utimestamp ;
2010-02-23 18:49:05 +01:00
eval {
2020-01-02 15:46:27 +01:00
$ utimestamp = strftime ( "%s" , $ 6 , $ 5 , $ 4 , $ 3 , $ 2 - 1 , $ 1 - 1900 ) ;
2010-02-23 18:49:05 +01:00
} ;
if ( $@ ) {
logger ( $ pa_config , "Invalid timestamp '$timestamp' from module '$module_name' agent '$agent_name'." , 3 ) ;
2010-09-20 19:01:27 +02:00
return ;
2010-02-23 18:49:05 +01:00
}
2010-02-15 14:07:52 +01:00
#my $value = get_tag_value ($data, 'data', '');
2010-09-20 19:01:27 +02:00
my $ data_object = get_module_data ( $ data , $ module_type ) ;
my $ extra_macros = get_macros_for_data ( $ data , $ module_type ) ;
2010-02-15 14:07:52 +01:00
2011-04-20 17:55:28 +02:00
# Get module status from XML data file if available
$ module - > { 'status' } = get_tag_value ( $ data , 'status' , undef ) ;
2010-08-12 14:42:56 +02:00
pandora_process_module ( $ pa_config , $ data_object , $ agent , $ module , $ module_type , $ timestamp , $ utimestamp , $ server_id , $ dbh , $ extra_macros ) ;
2010-02-15 14:07:52 +01:00
}
2010-09-20 19:01:27 +02:00
##########################################################################
# Retrieve module data from the XML tree.
##########################################################################
2010-02-15 14:07:52 +01:00
sub get_module_data ($$) {
2010-09-20 19:01:27 +02:00
my ( $ data , $ module_type ) = @ _ ;
2010-08-12 14:42:56 +02:00
my % data_object ;
2010-09-20 19:01:27 +02:00
# Log4x modules hava extended information
if ( $ module_type eq 'log4x' ) {
2010-02-15 14:07:52 +01:00
foreach my $ attr ( 'severity' , 'message' , 'stacktrace' ) {
2010-08-12 14:42:56 +02:00
$ data_object { $ attr } = get_tag_value ( $ data , $ attr , '' ) ;
2010-02-15 14:07:52 +01:00
}
} else {
2010-09-20 19:01:27 +02:00
$ data_object { 'data' } = get_tag_value ( $ data , 'data' , '' ) ;
2010-02-15 14:07:52 +01:00
}
2010-09-20 19:01:27 +02:00
2010-08-12 14:42:56 +02:00
return \ % data_object ;
2010-02-15 14:07:52 +01:00
}
2010-09-20 19:01:27 +02:00
##########################################################################
# Retrieve module data from the XML tree.
##########################################################################
2010-02-15 14:07:52 +01:00
sub get_macros_for_data ($$) {
2010-09-20 19:01:27 +02:00
my ( $ data , $ module_type ) = @ _ ;
2010-02-15 14:07:52 +01:00
my % macros ;
2010-09-20 19:01:27 +02:00
if ( $ module_type eq 'log4x' ) {
foreach my $ attr ( 'severity' , 'message' , 'stacktrace' ) {
$ macros { '_' . $ attr . '_' } = get_tag_value ( $ data , $ attr , '' ) ;
2010-02-15 14:07:52 +01:00
}
}
2010-02-23 18:49:05 +01:00
2010-02-15 14:07:52 +01:00
return \ % macros ;
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-09-20 19:01:27 +02:00
##########################################################################
# Update module configuration in tagente_modulo if necessary.
##########################################################################
2020-06-17 13:14:22 +02:00
sub update_module_configuration ($$$$$) {
my ( $ pa_config , $ dbh , $ module , $ module_conf , $ extra ) = @ _ ;
2010-09-20 19:01:27 +02:00
# Update if at least one of the configuration tokens has changed
2013-04-17 19:59:49 +02:00
foreach my $ conf_token ( 'descripcion' , 'extended_info' , 'module_interval' ) {
2011-04-27 19:44:14 +02:00
if ( $ module - > { $ conf_token } ne $ module_conf - > { $ conf_token } ) {
2012-04-19 20:47:57 +02:00
logger ( $ pa_config , "Updating configuration for module '" . safe_output ( $ module - > { 'nombre' } ) . "'." , 10 ) ;
2013-04-17 19:59:49 +02:00
db_do ( $ dbh , ' UPDATE tagente_modulo SET descripcion = ? , extended_info = ? , module_interval = ?
2012-11-13 13:31:14 +01:00
WHERE id_agente_modulo = ? ', $module_conf->{' descripcion '} eq ' ' ? $module->{' descripcion '} : $module_conf->{' descripcion ' } ,
2013-04-17 19:59:49 +02:00
$ module_conf - > { 'extended_info' } , $ module_conf - > { 'module_interval' } , $ module - > { 'id_agente_modulo' } ) ;
2011-10-28 13:02:35 +02:00
last ;
2011-04-27 19:44:14 +02:00
}
2010-09-20 19:01:27 +02:00
}
2011-10-28 13:02:35 +02:00
# Update module hash
2012-11-13 13:31:14 +01:00
$ module - > { 'extended_info' } = $ module_conf - > { 'extended_info' } if ( defined ( $ module_conf - > { 'extended_info' } ) ) ;
2011-10-28 13:02:35 +02:00
$ module - > { 'descripcion' } = ( $ module_conf - > { 'descripcion' } eq '' ) ? $ module - > { 'descripcion' } : $ module_conf - > { 'descripcion' } ;
2013-04-17 19:59:49 +02:00
$ module - > { 'module_interval' } = ( $ module_conf - > { 'module_interval' } eq '' ) ? $ module - > { 'module_interval' } : $ module_conf - > { 'module_interval' } ;
2020-06-17 13:14:22 +02:00
# Enterprise updates.
enterprise_hook ( 'update_module_fields' , [ $ dbh , $ pa_config , $ module , $ extra ] ) ;
2010-09-20 19:01:27 +02:00
}
2015-10-14 14:55:55 +02:00
###############################################################################
# Process XML data coming from a server.
###############################################################################
sub process_xml_server ($$$$) {
my ( $ pa_config , $ file_name , $ data , $ dbh ) = @ _ ;
my ( $ server_name , $ server_type , $ version , $ threads , $ modules ) = ( $ data - > { 'server_name' } , $ data - > { 'server_type' } , $ data - > { 'version' } , $ data - > { 'threads' } , $ data - > { 'modules' } ) ;
# Unknown server!
if ( ! defined ( $ server_name ) || $ server_name eq '' ) {
logger ( $ pa_config , "$file_name has data from an unnamed server" , 3 ) ;
return ;
}
logger ( $ pa_config , "Processing XML from server: $server_name" , 10 ) ;
# Set some default values
$ server_type = SATELLITESERVER unless defined ( $ server_type ) ;
$ modules = 0 unless defined ( $ modules ) ;
$ threads = 0 unless defined ( $ threads ) ;
$ version = '' unless defined ( $ version ) ;
# Update server information
2016-03-15 16:02:27 +01:00
pandora_update_server ( $ pa_config , $ dbh , $ data - > { 'server_name' } , 0 , 1 , $ server_type , $ threads , $ modules , $ version , $ data - > { 'keepalive' } ) ;
2015-10-14 14:55:55 +02:00
}
2016-12-14 12:58:32 +01:00
###############################################################################
# Link two modules
###############################################################################
sub link_modules {
my ( $ pa_config , $ dbh , $ agent_id , $ child_name , $ parent_name ) = @ _ ;
# Get the child module ID.
my $ child_id = get_agent_module_id ( $ dbh , $ child_name , $ agent_id ) ;
return unless ( $ child_id != - 1 ) ;
# Get the parent module ID.
my $ parent_id = get_agent_module_id ( $ dbh , $ parent_name , $ agent_id ) ;
return unless ( $ parent_id != - 1 ) ;
# Link them.
logger ( $ pa_config , "Linking module $child_name to module $parent_name for agent ID $agent_id" , 10 ) ;
db_do ( $ dbh , "UPDATE tagente_modulo SET parent_module_id = ? WHERE id_agente_modulo = ?" , $ parent_id , $ child_id ) ;
}
2017-10-09 17:11:08 +02:00
###############################################################################
# Unlink module from parent
###############################################################################
sub unlink_modules {
my ( $ pa_config , $ dbh , $ agent_id , $ child_name ) = @ _ ;
# Get the child module ID.
my $ child_id = get_agent_module_id ( $ dbh , $ child_name , $ agent_id ) ;
return unless ( $ child_id != - 1 ) ;
# Link them.
logger ( $ pa_config , "Unlinking parent from module $child_name agent ID $agent_id" , 10 ) ;
db_do ( $ dbh , "UPDATE tagente_modulo SET parent_module_id = 0 WHERE id_agente_modulo = ?" , $ child_id ) ;
}
2019-01-21 15:12:46 +01:00
##########################################################################
# Process events in the XML.
##########################################################################
sub process_events_dataserver {
my ( $ pa_config , $ data , $ agent_id , $ group_id , $ dbh ) = @ _ ;
2019-01-22 12:59:54 +01:00
return unless defined ( $ data - > { 'events' } - > [ 0 ] - > { 'event' } ) ;
2019-01-21 15:12:46 +01:00
2019-01-22 12:59:54 +01:00
foreach my $ event ( @ { $ data - > { 'events' } - > [ 0 ] - > { 'event' } } ) {
next unless defined ( $ event ) ;
2019-01-21 15:12:46 +01:00
# Try to decode the base64 inside
my $ event_info ;
eval {
2019-01-22 12:59:54 +01:00
$ event_info = decode_json ( decode_base64 ( $ event ) ) ;
2019-01-21 15:12:46 +01:00
} ;
if ( $@ ) {
2019-01-22 12:59:54 +01:00
logger ( $ pa_config , "Error processing base64 event data '$event'." , 5 ) ;
2019-01-21 15:12:46 +01:00
next ;
}
next unless defined ( $ event_info - > { 'data' } ) ;
pandora_event (
$ pa_config ,
$ event_info - > { 'data' } ,
$ group_id ,
$ agent_id ,
defined ( $ event_info - > { 'severity' } ) ? $ event_info - > { 'severity' } : 0 ,
0 ,
0 ,
'system' ,
0 ,
$ dbh
) ;
}
return ;
}
2019-01-21 18:27:31 +01:00
##########################################################################
# Process events in the XML.
##########################################################################
sub process_xml_matrix_network {
my ( $ pa_config , $ data , $ dbh ) = @ _ ;
my $ utimestamp = $ data - > { 'network_matrix' } - > [ 0 ] - > { 'utimestamp' } ;
my $ content = $ data - > { 'network_matrix' } - > [ 0 ] - > { 'content' } ;
return unless defined ( $ utimestamp ) && defined ( $ content ) ;
# Try to decode the base64 inside
my $ matrix_info ;
eval {
$ matrix_info = decode_json ( decode_base64 ( $ content ) ) ;
} ;
if ( $@ ) {
logger ( $ pa_config , "Error processing base64 matrix data '$content'." , 5 ) ;
return ;
}
foreach my $ source ( keys %$ matrix_info ) {
foreach my $ destination ( keys % { $ matrix_info - > { $ source } } ) {
my $ matrix_single_data = $ matrix_info - > { $ source } - > { $ destination } ;
$ matrix_single_data - > { 'source' } = $ source ;
$ matrix_single_data - > { 'destination' } = $ destination ;
$ matrix_single_data - > { 'utimestamp' } = $ utimestamp ;
eval {
db_process_insert ( $ dbh , 'id' , 'tnetwork_matrix' , $ matrix_single_data ) ;
} ;
if ( $@ ) {
logger ( $ pa_config , "Error inserted matrix data. Source: $source, destination: $destination, utimestamp: $utimestamp." , 5 ) ;
}
}
}
return ;
}
2019-07-03 14:06:24 +02:00
##########################################################################
# Get a lock on the given agent. Return 1 on success, 0 otherwise.
##########################################################################
sub agent_lock {
2020-07-10 13:21:30 +02:00
my ( $ pa_config , $ dbh , $ agent_name ) = @ _ ;
# Do not lock on LIFO mode if the agent already exist.
# get_agent_id will be called again from process_xml_data,
# so the should be no race conditions if the agent does
# not exist.
if ( $ pa_config - > { 'dataserver_lifo' } == 1 &&
get_agent_id ( $ dbh , $ agent_name ) > 0 ) {
return 1 ;
}
2019-07-03 14:06:24 +02:00
$ AgentSem - > down ( ) ;
if ( defined ( $ Agents { $ agent_name } ) ) {
$ AgentSem - > up ( ) ;
return 0 ;
}
$ Agents { $ agent_name } = 1 ;
$ AgentSem - > up ( ) ;
return 1 ;
}
##########################################################################
# Remove the lock on the given agent.
##########################################################################
sub agent_unlock {
my ( $ pa_config , $ agent_name ) = @ _ ;
$ AgentSem - > down ( ) ;
delete ( $ Agents { $ agent_name } ) ;
$ AgentSem - > up ( ) ;
}
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__