2007-08-02 19:53:07 +02:00
package PandoraFMS::DB ;
##########################################################################
2008-07-22 17:52:34 +02:00
# Database Package
# Pandora FMS. the Flexible Monitoring System. http://www.pandorafms.org
2007-08-02 19:53:07 +02:00
##########################################################################
2011-03-14 11:39:31 +01:00
# Copyright (c) 2005-2011 Artica Soluciones Tecnologicas S.L
2007-08-02 19:53:07 +02:00
#
2008-02-20 03:09:36 +01:00
# This program is free software; you can redistribute it and/or
2009-01-12 03:44:39 +01:00
# modify it under the terms of the GNU Lesser General Public License
2008-02-20 03:09:36 +01:00
# 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.
2007-08-02 19:53:07 +02:00
##########################################################################
2009-01-16 12:22:56 +01:00
use strict ;
2007-08-02 19:53:07 +02:00
use warnings ;
use DBI ;
2012-07-24 15:23:27 +02:00
use PandoraFMS::Tools ;
#use Data::Dumper;
2007-08-02 19:53:07 +02:00
require Exporter ;
our @ ISA = ( "Exporter" ) ;
our % EXPORT_TAGS = ( 'all' = > [ qw( ) ] ) ;
our @ EXPORT_OK = ( @ { $ EXPORT_TAGS { 'all' } } ) ;
2011-06-28 12:04:45 +02:00
our @ EXPORT = qw(
add_address
add_new_address_agent
2011-12-01 17:11:42 +01:00
db_concat
2009-04-14 Ramon Novoa <rnovoa@artica.es>
* pandora_ctl, pandora_network, pandora_wmi, pandora_plugin,
pandora_prediction, bin/pandora_wmi, bin/pandora_plugin,
bin/pandora_prediction, bin/pandora_snmpconsole, bin/pandora_recon,
bin/pandora_network, pandora_recon, pandora_snmpconsole: Deleted
from repository. Old server code and startup scripts.
* Makefile.PL, pandora_server_installer, lib/PandoraFMS/Config.pm
lib/PandoraFMS/DB.pm, lib/PandoraFMS/Tools.pm, bin/pandora_server,
pandora_package_installer, pandora_server: Updated to work with the
new code, removed unneeded dependencies, fixed some bugs etc.
* lib/PandoraFMS/SNMPServer.pm, lib/PandoraFMS/PluginServer.pm,
lib/PandoraFMS/ProducerConsumerServer.pm, lib/PandoraFMS/Server.pm,
lib/PandoraFMS/PredictionServer.pm, lib/PandoraFMS/Core.pm,
lib/PandoraFMS/ReconServer.pm, lib/PandoraFMS/DataServer.pm,
lib/PandoraFMS/NetworkServer.pm, lib/PandoraFMS/WMIServer.pm: Added
to repository. New server code.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1620 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-04-14 21:13:16 +02:00
db_connect
2015-07-22 15:36:46 +02:00
db_delete_limit
2009-04-14 Ramon Novoa <rnovoa@artica.es>
* pandora_ctl, pandora_network, pandora_wmi, pandora_plugin,
pandora_prediction, bin/pandora_wmi, bin/pandora_plugin,
bin/pandora_prediction, bin/pandora_snmpconsole, bin/pandora_recon,
bin/pandora_network, pandora_recon, pandora_snmpconsole: Deleted
from repository. Old server code and startup scripts.
* Makefile.PL, pandora_server_installer, lib/PandoraFMS/Config.pm
lib/PandoraFMS/DB.pm, lib/PandoraFMS/Tools.pm, bin/pandora_server,
pandora_package_installer, pandora_server: Updated to work with the
new code, removed unneeded dependencies, fixed some bugs etc.
* lib/PandoraFMS/SNMPServer.pm, lib/PandoraFMS/PluginServer.pm,
lib/PandoraFMS/ProducerConsumerServer.pm, lib/PandoraFMS/Server.pm,
lib/PandoraFMS/PredictionServer.pm, lib/PandoraFMS/Core.pm,
lib/PandoraFMS/ReconServer.pm, lib/PandoraFMS/DataServer.pm,
lib/PandoraFMS/NetworkServer.pm, lib/PandoraFMS/WMIServer.pm: Added
to repository. New server code.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1620 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-04-14 21:13:16 +02:00
db_disconnect
2009-01-15 13:51:26 +01:00
db_do
2013-05-07 17:38:11 +02:00
db_get_lock
2011-04-13 Ramon Novoa <rnovoa@artica.es>
* lib/PandoraFMS/SNMPServer.pm,
lib/PandoraFMS/Config.pm,
lib/PandoraFMS/NetworkServer.pm,
lib/PandoraFMS/WMIServer.pm,
lib/PandoraFMS/PluginServer.pm,
lib/PandoraFMS/DB.pm,
lib/PandoraFMS/ProducerConsumerServer.pm,
lib/PandoraFMS/PredictionServer.pm,
lib/PandoraFMS/Core.pm,
lib/PandoraFMS/ReconServer.pm,
bin/pandora_server,
util/pandora_db.pl,
util/pandora_manage.pl,
util/recon_scripts/snmpdevices.pl: Adding support for PostgreSQL and
Oracle (not complete).
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4213 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2011-04-13 18:28:59 +02:00
db_insert
2013-03-01 15:27:52 +01:00
db_insert_get_values
2010-09-23 10:16:44 +02:00
db_process_insert
2010-11-04 18:35:37 +01:00
db_process_update
2013-05-07 17:38:11 +02:00
db_release_lock
2011-04-13 Ramon Novoa <rnovoa@artica.es>
* lib/PandoraFMS/SNMPServer.pm,
lib/PandoraFMS/Config.pm,
lib/PandoraFMS/NetworkServer.pm,
lib/PandoraFMS/WMIServer.pm,
lib/PandoraFMS/PluginServer.pm,
lib/PandoraFMS/DB.pm,
lib/PandoraFMS/ProducerConsumerServer.pm,
lib/PandoraFMS/PredictionServer.pm,
lib/PandoraFMS/Core.pm,
lib/PandoraFMS/ReconServer.pm,
bin/pandora_server,
util/pandora_db.pl,
util/pandora_manage.pl,
util/recon_scripts/snmpdevices.pl: Adding support for PostgreSQL and
Oracle (not complete).
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4213 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2011-04-13 18:28:59 +02:00
db_string
2011-04-18 18:42:18 +02:00
db_text
2010-10-21 16:26:46 +02:00
db_update
2013-03-01 15:27:52 +01:00
db_update_get_values
2010-05-25 18:23:07 +02:00
get_action_id
2011-06-28 12:04:45 +02:00
get_addr_id
2012-04-12 12:04:35 +02:00
get_agent_addr_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
get_agent_id
2011-05-12 13:11:37 +02:00
get_agent_address
2017-06-12 14:34:03 +02:00
get_agent_alias
2011-06-10 14:50:56 +02:00
get_agent_group
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
get_agent_name
2010-05-25 15:43:25 +02:00
get_agent_module_id
2011-05-09 11:42:01 +02:00
get_alert_template_module_id
2011-06-08 13:07:39 +02:00
get_alert_template_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
get_db_rows
2015-06-08 18:32:49 +02:00
get_db_rows_limit
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
get_db_single_row
get_db_value
2015-05-05 11:20:41 +02:00
get_db_value_limit
2012-12-13 18:07:23 +01:00
get_first_server_name
2010-05-25 15:43:25 +02:00
get_group_id
2009-11-04 18:49:42 +01:00
get_group_name
2011-05-23 13:55:08 +02:00
get_module_agent_id
2010-10-18 18:21:13 +02:00
get_module_group_id
2011-10-06 04:46:55 +02:00
get_module_group_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
get_module_id
2010-05-25 15:43:25 +02:00
get_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
get_nc_profile_name
2010-05-25 13:56:37 +02:00
get_os_id
2017-03-17 09:37:10 +01:00
get_os_name
2010-10-18 18:21:13 +02:00
get_plugin_id
2010-05-26 11:54:21 +02:00
get_profile_id
2012-05-10 14:18:43 +02:00
get_priority_name
2010-05-25 15:43:25 +02:00
get_server_id
2015-03-26 13:41:07 +01:00
get_tag_id
get_group_name
2010-05-25 15:16:34 +02:00
get_template_id
get_template_module_id
2012-01-04 16:09:02 +01:00
get_user_disabled
2012-01-05 13:11:03 +01:00
get_user_exists
2015-03-26 13:41:07 +01:00
get_user_profile_id
2011-06-28 17:41:13 +02:00
is_agent_address
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
is_group_disabled
2012-07-24 15:23:27 +02:00
get_agent_status
get_agent_modules
get_agentmodule_status
2013-09-12 10:16:35 +02:00
get_agentmodule_status_str
2012-07-27 11:05:16 +02:00
get_agentmodule_data
2013-03-01 15:27:52 +01:00
$ RDBMS
$ RDBMS_QUOTE
2014-07-25 15:15:24 +02:00
$ RDBMS_QUOTE_STRING
2008-03-13 19:33:44 +01:00
) ;
2007-08-02 19:53:07 +02:00
2013-03-01 15:27:52 +01:00
# Relational database management system in use
our $ RDBMS = '' ;
2014-07-25 15:15:24 +02:00
# For fields, character used to quote reserved words in the current RDBMS
2013-03-01 15:27:52 +01:00
our $ RDBMS_QUOTE = '' ;
2014-07-25 15:15:24 +02:00
# For strings, Character used to quote in the current RDBMS
our $ RDBMS_QUOTE_STRING = '' ;
2008-04-16 13:03:03 +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
## Connect to the DB.
2008-04-16 13:03:03 +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
sub db_connect ($$$$$$) {
my ( $ rdbms , $ db_name , $ db_host , $ db_port , $ db_user , $ db_pass ) = @ _ ;
2012-07-24 15:23:27 +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
if ( $ rdbms eq 'mysql' ) {
2011-04-13 Ramon Novoa <rnovoa@artica.es>
* lib/PandoraFMS/SNMPServer.pm,
lib/PandoraFMS/Config.pm,
lib/PandoraFMS/NetworkServer.pm,
lib/PandoraFMS/WMIServer.pm,
lib/PandoraFMS/PluginServer.pm,
lib/PandoraFMS/DB.pm,
lib/PandoraFMS/ProducerConsumerServer.pm,
lib/PandoraFMS/PredictionServer.pm,
lib/PandoraFMS/Core.pm,
lib/PandoraFMS/ReconServer.pm,
bin/pandora_server,
util/pandora_db.pl,
util/pandora_manage.pl,
util/recon_scripts/snmpdevices.pl: Adding support for PostgreSQL and
Oracle (not complete).
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4213 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2011-04-13 18:28:59 +02:00
$ RDBMS = 'mysql' ;
2013-03-01 15:27:52 +01:00
$ RDBMS_QUOTE = '`' ;
2014-07-25 15:15:24 +02:00
$ RDBMS_QUOTE_STRING = '"' ;
2009-05-04 14:16:52 +02:00
# Connect to MySQL
2012-04-20 05:56:09 +02:00
my $ dbh = DBI - > connect ( "DBI:mysql:$db_name:$db_host:$db_port" , $ db_user , $ db_pass , { RaiseError = > 1 , AutoCommit = > 1 } ) ;
2009-05-04 14:16:52 +02:00
return undef unless defined ( $ dbh ) ;
# Enable auto reconnect
$ dbh - > { 'mysql_auto_reconnect' } = 1 ;
2012-07-24 15:23:27 +02:00
2011-04-10 03:18:01 +02:00
# Enable character semantics
$ dbh - > { 'mysql_enable_utf8' } = 1 ;
2012-07-24 15:23:27 +02:00
2016-07-01 15:44:55 +02:00
# Tell the server to return UTF-8 strings.
$ dbh - > do ( "SET NAMES 'utf8';" ) if ( $^O eq 'MSWin32' ) ;
2011-04-13 Ramon Novoa <rnovoa@artica.es>
* lib/PandoraFMS/SNMPServer.pm,
lib/PandoraFMS/Config.pm,
lib/PandoraFMS/NetworkServer.pm,
lib/PandoraFMS/WMIServer.pm,
lib/PandoraFMS/PluginServer.pm,
lib/PandoraFMS/DB.pm,
lib/PandoraFMS/ProducerConsumerServer.pm,
lib/PandoraFMS/PredictionServer.pm,
lib/PandoraFMS/Core.pm,
lib/PandoraFMS/ReconServer.pm,
bin/pandora_server,
util/pandora_db.pl,
util/pandora_manage.pl,
util/recon_scripts/snmpdevices.pl: Adding support for PostgreSQL and
Oracle (not complete).
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4213 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2011-04-13 18:28:59 +02:00
return $ dbh ;
2012-07-24 15:23:27 +02:00
}
elsif ( $ rdbms eq 'postgresql' ) {
2011-04-13 Ramon Novoa <rnovoa@artica.es>
* lib/PandoraFMS/SNMPServer.pm,
lib/PandoraFMS/Config.pm,
lib/PandoraFMS/NetworkServer.pm,
lib/PandoraFMS/WMIServer.pm,
lib/PandoraFMS/PluginServer.pm,
lib/PandoraFMS/DB.pm,
lib/PandoraFMS/ProducerConsumerServer.pm,
lib/PandoraFMS/PredictionServer.pm,
lib/PandoraFMS/Core.pm,
lib/PandoraFMS/ReconServer.pm,
bin/pandora_server,
util/pandora_db.pl,
util/pandora_manage.pl,
util/recon_scripts/snmpdevices.pl: Adding support for PostgreSQL and
Oracle (not complete).
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4213 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2011-04-13 18:28:59 +02:00
$ RDBMS = 'postgresql' ;
2013-03-01 15:27:52 +01:00
$ RDBMS_QUOTE = '"' ;
2014-07-25 15:15:24 +02:00
$ RDBMS_QUOTE_STRING = "'" ;
2011-04-13 Ramon Novoa <rnovoa@artica.es>
* lib/PandoraFMS/SNMPServer.pm,
lib/PandoraFMS/Config.pm,
lib/PandoraFMS/NetworkServer.pm,
lib/PandoraFMS/WMIServer.pm,
lib/PandoraFMS/PluginServer.pm,
lib/PandoraFMS/DB.pm,
lib/PandoraFMS/ProducerConsumerServer.pm,
lib/PandoraFMS/PredictionServer.pm,
lib/PandoraFMS/Core.pm,
lib/PandoraFMS/ReconServer.pm,
bin/pandora_server,
util/pandora_db.pl,
util/pandora_manage.pl,
util/recon_scripts/snmpdevices.pl: Adding support for PostgreSQL and
Oracle (not complete).
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4213 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2011-04-13 18:28:59 +02:00
# Connect to PostgreSQL
2012-04-20 05:56:09 +02:00
my $ dbh = DBI - > connect ( "DBI:Pg:dbname=$db_name;host=$db_host;port=$db_port" , $ db_user , $ db_pass , { RaiseError = > 1 , AutoCommit = > 1 } ) ;
2011-04-13 Ramon Novoa <rnovoa@artica.es>
* lib/PandoraFMS/SNMPServer.pm,
lib/PandoraFMS/Config.pm,
lib/PandoraFMS/NetworkServer.pm,
lib/PandoraFMS/WMIServer.pm,
lib/PandoraFMS/PluginServer.pm,
lib/PandoraFMS/DB.pm,
lib/PandoraFMS/ProducerConsumerServer.pm,
lib/PandoraFMS/PredictionServer.pm,
lib/PandoraFMS/Core.pm,
lib/PandoraFMS/ReconServer.pm,
bin/pandora_server,
util/pandora_db.pl,
util/pandora_manage.pl,
util/recon_scripts/snmpdevices.pl: Adding support for PostgreSQL and
Oracle (not complete).
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4213 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2011-04-13 18:28:59 +02:00
return undef unless defined ( $ dbh ) ;
2011-04-18 18:42:18 +02:00
return $ dbh ;
2014-07-25 15:15:24 +02:00
}
elsif ( $ rdbms eq 'oracle' ) {
2011-04-18 18:42:18 +02:00
$ RDBMS = 'oracle' ;
2013-03-01 15:27:52 +01:00
$ RDBMS_QUOTE = '"' ;
2015-04-30 10:51:47 +02:00
$ RDBMS_QUOTE_STRING = '\'' ;
2011-04-18 18:42:18 +02:00
# Connect to Oracle
2015-05-05 11:20:41 +02:00
my $ dbh = DBI - > connect ( "DBI:Oracle:dbname=$db_name;host=$db_host;port=$db_port;sid=$db_name" , $ db_user , $ db_pass , { RaiseError = > 1 , AutoCommit = > 1 } ) ;
2011-04-18 18:42:18 +02:00
return undef unless defined ( $ dbh ) ;
# Set date format
$ dbh - > do ( "ALTER SESSION SET NLS_TIMESTAMP_FORMAT='YYYY-MM-DD HH24:MI:SS'" ) ;
2016-01-19 09:58:48 +01:00
$ dbh - > do ( "ALTER SESSION SET NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS'" ) ;
2011-04-19 17:32:11 +02:00
$ dbh - > do ( "ALTER SESSION SET NLS_NUMERIC_CHARACTERS='.,'" ) ;
2015-05-12 18:19:08 +02:00
# Configuration to avoid errors when working with CLOB columns
$ dbh - > { 'LongReadLen' } = 66000 ;
$ dbh - > { 'LongTruncOk' } = 1 ;
2009-05-04 14:16:52 +02:00
return $ dbh ;
2009-01-15 13:51:26 +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
return undef ;
2008-04-16 13:03:03 +02:00
}
2012-07-25 17:14:36 +02:00
########################################################################
2009-04-14 Ramon Novoa <rnovoa@artica.es>
* pandora_ctl, pandora_network, pandora_wmi, pandora_plugin,
pandora_prediction, bin/pandora_wmi, bin/pandora_plugin,
bin/pandora_prediction, bin/pandora_snmpconsole, bin/pandora_recon,
bin/pandora_network, pandora_recon, pandora_snmpconsole: Deleted
from repository. Old server code and startup scripts.
* Makefile.PL, pandora_server_installer, lib/PandoraFMS/Config.pm
lib/PandoraFMS/DB.pm, lib/PandoraFMS/Tools.pm, bin/pandora_server,
pandora_package_installer, pandora_server: Updated to work with the
new code, removed unneeded dependencies, fixed some bugs etc.
* lib/PandoraFMS/SNMPServer.pm, lib/PandoraFMS/PluginServer.pm,
lib/PandoraFMS/ProducerConsumerServer.pm, lib/PandoraFMS/Server.pm,
lib/PandoraFMS/PredictionServer.pm, lib/PandoraFMS/Core.pm,
lib/PandoraFMS/ReconServer.pm, lib/PandoraFMS/DataServer.pm,
lib/PandoraFMS/NetworkServer.pm, lib/PandoraFMS/WMIServer.pm: Added
to repository. New server code.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1620 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-04-14 21:13:16 +02:00
## Disconnect from the DB.
2012-07-25 17:14:36 +02:00
########################################################################
2009-04-14 Ramon Novoa <rnovoa@artica.es>
* pandora_ctl, pandora_network, pandora_wmi, pandora_plugin,
pandora_prediction, bin/pandora_wmi, bin/pandora_plugin,
bin/pandora_prediction, bin/pandora_snmpconsole, bin/pandora_recon,
bin/pandora_network, pandora_recon, pandora_snmpconsole: Deleted
from repository. Old server code and startup scripts.
* Makefile.PL, pandora_server_installer, lib/PandoraFMS/Config.pm
lib/PandoraFMS/DB.pm, lib/PandoraFMS/Tools.pm, bin/pandora_server,
pandora_package_installer, pandora_server: Updated to work with the
new code, removed unneeded dependencies, fixed some bugs etc.
* lib/PandoraFMS/SNMPServer.pm, lib/PandoraFMS/PluginServer.pm,
lib/PandoraFMS/ProducerConsumerServer.pm, lib/PandoraFMS/Server.pm,
lib/PandoraFMS/PredictionServer.pm, lib/PandoraFMS/Core.pm,
lib/PandoraFMS/ReconServer.pm, lib/PandoraFMS/DataServer.pm,
lib/PandoraFMS/NetworkServer.pm, lib/PandoraFMS/WMIServer.pm: Added
to repository. New server code.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1620 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-04-14 21:13:16 +02:00
sub db_disconnect ($) {
my $ dbh = shift ;
2008-04-16 13:03:03 +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
$ dbh - > disconnect ( ) ;
2007-08-02 19:53:07 +02:00
}
2012-07-25 17:14:36 +02:00
########################################################################
2010-05-25 18:23:07 +02:00
## Return action ID given the action name.
2012-07-25 17:14:36 +02:00
########################################################################
2010-05-25 18:23:07 +02:00
sub get_action_id ($$) {
my ( $ dbh , $ action_name ) = @ _ ;
my $ rc = get_db_value ( $ dbh , "SELECT id FROM talert_actions WHERE name = ?" , $ action_name ) ;
return defined ( $ rc ) ? $ rc : - 1 ;
}
2012-07-25 17:14:36 +02:00
########################################################################
2009-04-14 Ramon Novoa <rnovoa@artica.es>
* pandora_ctl, pandora_network, pandora_wmi, pandora_plugin,
pandora_prediction, bin/pandora_wmi, bin/pandora_plugin,
bin/pandora_prediction, bin/pandora_snmpconsole, bin/pandora_recon,
bin/pandora_network, pandora_recon, pandora_snmpconsole: Deleted
from repository. Old server code and startup scripts.
* Makefile.PL, pandora_server_installer, lib/PandoraFMS/Config.pm
lib/PandoraFMS/DB.pm, lib/PandoraFMS/Tools.pm, bin/pandora_server,
pandora_package_installer, pandora_server: Updated to work with the
new code, removed unneeded dependencies, fixed some bugs etc.
* lib/PandoraFMS/SNMPServer.pm, lib/PandoraFMS/PluginServer.pm,
lib/PandoraFMS/ProducerConsumerServer.pm, lib/PandoraFMS/Server.pm,
lib/PandoraFMS/PredictionServer.pm, lib/PandoraFMS/Core.pm,
lib/PandoraFMS/ReconServer.pm, lib/PandoraFMS/DataServer.pm,
lib/PandoraFMS/NetworkServer.pm, lib/PandoraFMS/WMIServer.pm: Added
to repository. New server code.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1620 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-04-14 21:13:16 +02:00
## Return agent ID given the agent name.
2012-07-25 17:14:36 +02:00
########################################################################
2009-04-14 Ramon Novoa <rnovoa@artica.es>
* pandora_ctl, pandora_network, pandora_wmi, pandora_plugin,
pandora_prediction, bin/pandora_wmi, bin/pandora_plugin,
bin/pandora_prediction, bin/pandora_snmpconsole, bin/pandora_recon,
bin/pandora_network, pandora_recon, pandora_snmpconsole: Deleted
from repository. Old server code and startup scripts.
* Makefile.PL, pandora_server_installer, lib/PandoraFMS/Config.pm
lib/PandoraFMS/DB.pm, lib/PandoraFMS/Tools.pm, bin/pandora_server,
pandora_package_installer, pandora_server: Updated to work with the
new code, removed unneeded dependencies, fixed some bugs etc.
* lib/PandoraFMS/SNMPServer.pm, lib/PandoraFMS/PluginServer.pm,
lib/PandoraFMS/ProducerConsumerServer.pm, lib/PandoraFMS/Server.pm,
lib/PandoraFMS/PredictionServer.pm, lib/PandoraFMS/Core.pm,
lib/PandoraFMS/ReconServer.pm, lib/PandoraFMS/DataServer.pm,
lib/PandoraFMS/NetworkServer.pm, lib/PandoraFMS/WMIServer.pm: Added
to repository. New server code.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1620 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-04-14 21:13:16 +02:00
sub get_agent_id ($$) {
my ( $ dbh , $ agent_name ) = @ _ ;
2008-03-27 18:38:10 +01:00
2010-11-02 18:26:34 +01:00
my $ rc = get_db_value ( $ dbh , "SELECT id_agente FROM tagente WHERE nombre = ? OR direccion = ?" , safe_input ( $ agent_name ) , $ 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 defined ( $ rc ) ? $ rc : - 1 ;
2008-03-27 18:38:10 +01:00
}
2012-07-25 17:14:36 +02:00
########################################################################
2009-04-14 Ramon Novoa <rnovoa@artica.es>
* pandora_ctl, pandora_network, pandora_wmi, pandora_plugin,
pandora_prediction, bin/pandora_wmi, bin/pandora_plugin,
bin/pandora_prediction, bin/pandora_snmpconsole, bin/pandora_recon,
bin/pandora_network, pandora_recon, pandora_snmpconsole: Deleted
from repository. Old server code and startup scripts.
* Makefile.PL, pandora_server_installer, lib/PandoraFMS/Config.pm
lib/PandoraFMS/DB.pm, lib/PandoraFMS/Tools.pm, bin/pandora_server,
pandora_package_installer, pandora_server: Updated to work with the
new code, removed unneeded dependencies, fixed some bugs etc.
* lib/PandoraFMS/SNMPServer.pm, lib/PandoraFMS/PluginServer.pm,
lib/PandoraFMS/ProducerConsumerServer.pm, lib/PandoraFMS/Server.pm,
lib/PandoraFMS/PredictionServer.pm, lib/PandoraFMS/Core.pm,
lib/PandoraFMS/ReconServer.pm, lib/PandoraFMS/DataServer.pm,
lib/PandoraFMS/NetworkServer.pm, lib/PandoraFMS/WMIServer.pm: Added
to repository. New server code.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1620 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-04-14 21:13:16 +02:00
## Return server ID given the name of server.
2012-07-25 17:14:36 +02:00
########################################################################
2009-04-14 Ramon Novoa <rnovoa@artica.es>
* pandora_ctl, pandora_network, pandora_wmi, pandora_plugin,
pandora_prediction, bin/pandora_wmi, bin/pandora_plugin,
bin/pandora_prediction, bin/pandora_snmpconsole, bin/pandora_recon,
bin/pandora_network, pandora_recon, pandora_snmpconsole: Deleted
from repository. Old server code and startup scripts.
* Makefile.PL, pandora_server_installer, lib/PandoraFMS/Config.pm
lib/PandoraFMS/DB.pm, lib/PandoraFMS/Tools.pm, bin/pandora_server,
pandora_package_installer, pandora_server: Updated to work with the
new code, removed unneeded dependencies, fixed some bugs etc.
* lib/PandoraFMS/SNMPServer.pm, lib/PandoraFMS/PluginServer.pm,
lib/PandoraFMS/ProducerConsumerServer.pm, lib/PandoraFMS/Server.pm,
lib/PandoraFMS/PredictionServer.pm, lib/PandoraFMS/Core.pm,
lib/PandoraFMS/ReconServer.pm, lib/PandoraFMS/DataServer.pm,
lib/PandoraFMS/NetworkServer.pm, lib/PandoraFMS/WMIServer.pm: Added
to repository. New server code.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1620 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-04-14 21:13:16 +02:00
sub get_server_id ($$$) {
my ( $ dbh , $ server_name , $ server_type ) = @ _ ;
2008-03-27 18:38:10 +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
my $ rc = get_db_value ( $ dbh , " SELECT id_server FROM tserver
2017-06-13 12:42:21 +02:00
WHERE BINARY name = ? AND server_type = ? " ,
2010-12-27 23:39:02 +01:00
$ server_name , $ server_type ) ;
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 defined ( $ rc ) ? $ rc : - 1 ;
2008-03-27 18:38:10 +01:00
}
2015-03-26 13:41:07 +01:00
########################################################################
## Return the ID of a tag given the tag name.
########################################################################
sub get_tag_id ($$) {
my ( $ dbh , $ tag_name ) = @ _ ;
my $ rc = get_db_value ( $ dbh , " SELECT id_tag FROM ttag
WHERE name = ? " ,
safe_input ( $ tag_name ) ) ;
return defined ( $ rc ) ? $ rc : - 1 ;
}
2012-12-13 18:07:23 +01:00
########################################################################
## Return the first enabled server name found.
########################################################################
sub get_first_server_name ($) {
my ( $ dbh ) = @ _ ;
my $ rc = get_db_value ( $ dbh , "SELECT name FROM tserver" ) ;
return defined ( $ rc ) ? $ rc : "" ;
}
2012-07-25 17:14:36 +02:00
########################################################################
2010-05-25 13:56:37 +02:00
## Return group ID given the group name.
2012-07-25 17:14:36 +02:00
########################################################################
2010-05-25 13:56:37 +02:00
sub get_group_id ($$) {
my ( $ dbh , $ group_name ) = @ _ ;
2011-05-03 16:24:51 +02:00
my $ rc = get_db_value ( $ dbh , 'SELECT id_grupo FROM tgrupo WHERE ' . db_text ( 'nombre' ) . ' = ?' , safe_input ( $ group_name ) ) ;
2010-05-25 13:56:37 +02:00
return defined ( $ rc ) ? $ rc : - 1 ;
}
2012-07-25 17:14:36 +02:00
########################################################################
2010-05-25 13:56:37 +02:00
## Return OS ID given the OS name.
2012-07-25 17:14:36 +02:00
########################################################################
2010-05-25 13:56:37 +02:00
sub get_os_id ($$) {
my ( $ dbh , $ os_name ) = @ _ ;
my $ rc = get_db_value ( $ dbh , "SELECT id_os FROM tconfig_os WHERE name = ?" , $ os_name ) ;
return defined ( $ rc ) ? $ rc : - 1 ;
}
2017-03-17 09:37:10 +01:00
########################################################################
## Return OS name given the OS id.
########################################################################
sub get_os_name ($$) {
my ( $ dbh , $ os_id ) = @ _ ;
my $ rc = get_db_value ( $ dbh , "SELECT name FROM tconfig_os WHERE id_os = ?" , $ os_id ) ;
return defined ( $ rc ) ? $ rc : - 1 ;
}
2011-06-10 14:50:56 +02:00
##########################################################################
## SUB get_agent_name (agent_id)
## Return agent group id, given "agent_id"
##########################################################################
sub get_agent_group ($$) {
my ( $ dbh , $ agent_id ) = @ _ ;
2012-07-24 15:23:27 +02:00
my $ group_id = get_db_value ( $ dbh , " SELECT id_grupo
FROM tagente
WHERE id_agente = ? " , $ agent_id ) ;
2011-06-10 14:50:56 +02:00
return 0 unless defined ( $ group_id ) ;
return $ group_id ;
}
2012-07-24 15:23:27 +02:00
########################################################################
2011-05-12 13:11:37 +02:00
## SUB get_agent_name (agent_id)
## Return agent name, given "agent_id"
2012-07-24 15:23:27 +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
sub get_agent_name ($$) {
my ( $ dbh , $ agent_id ) = @ _ ;
2008-10-20 12:43:21 +02:00
2012-07-24 15:23:27 +02:00
return get_db_value ( $ dbh , " SELECT nombre
FROM tagente
WHERE id_agente = ? " , $ agent_id ) ;
2007-08-02 19:53:07 +02:00
}
2017-06-12 14:34:03 +02:00
########################################################################
## SUB get_agent_alias (agent_id)
## Return agent alias, given "agent_id"
########################################################################
sub get_agent_alias ($$) {
my ( $ dbh , $ agent_id ) = @ _ ;
return get_db_value ( $ dbh , " SELECT alias
FROM tagente
WHERE id_agente = ? " , $ agent_id ) ;
}
2012-07-24 15:23:27 +02:00
########################################################################
## SUB agents_get_modules (agent_id, fields, filters)
## Return the list of modules, given "agent_id"
########################################################################
sub get_agent_modules ($$$$$) {
my ( $ pa_config , $ dbh , $ agent_id , $ fields , $ filters ) = @ _ ;
my $ str_filter = '' ;
2012-07-29 02:24:35 +02:00
foreach my $ key ( keys %$ filters ) {
2012-07-24 15:23:27 +02:00
$ str_filter . = ' AND ' . $ key . " = " . $ filters - > { $ key } ;
}
my @ rows = get_db_rows ( $ dbh , " SELECT *
FROM tagente_modulo
WHERE id_agente = ? " . $ str_filter , $ agent_id ) ;
return @ rows ;
}
########################################################################
2012-07-27 11:05:16 +02:00
## SUB get_agentmodule_data (id_agent_module, period, date)
## Return The data for module in a period of time.
########################################################################
sub get_agentmodule_data ($$$$$) {
my ( $ pa_config , $ dbh , $ id_agent_module , $ period , $ date ) = @ _ ;
if ( $ date < 1 ) {
# Get current timestamp
$ date = time ( ) ;
}
my $ datelimit = $ date - $ period ;
my @ rows = get_db_rows ( $ dbh ,
" SELECT datos AS data , utimestamp
FROM tagente_datos
WHERE id_agente_modulo = ?
AND utimestamp > ? AND utimestamp <= ?
ORDER BY utimestamp ASC " ,
$ id_agent_module , $ datelimit , $ date ) ;
#logger($pa_config, "SELECT datos AS data, utimestamp
# FROM tagente_datos
# WHERE id_agente_modulo = " . $id_agent_module . "
# AND utimestamp > " . $datelimit . " AND utimestamp <= " . $date . "
# ORDER BY utimestamp ASC", 1);
return @ rows ;
}
########################################################################
2012-07-24 15:23:27 +02:00
## SUB get_agentmodule_status (agent_module_id)
## Return agent module status. given "agent_module_id"
########################################################################
sub get_agentmodule_status ($$$) {
my ( $ pa_config , $ dbh , $ agent_module_id ) = @ _ ;
my $ status = get_db_value ( $ dbh , ' SELECT estado
FROM tagente_estado
WHERE id_agente_modulo = ? ' , $ agent_module_id ) ;
return $ status ;
}
2013-09-12 10:16:35 +02:00
########################################################################
## Return the status of an agent module as a string.
########################################################################
sub get_agentmodule_status_str ($$$) {
my ( $ pa_config , $ dbh , $ agent_module_id ) = @ _ ;
my $ status = get_db_value ( $ dbh , ' SELECT estado
FROM tagente_estado
WHERE id_agente_modulo = ? ' , $ agent_module_id ) ;
return 'Normal' if ( $ status == 0 ) ;
return 'Critical' if ( $ status == 1 ) ;
return 'Warning' if ( $ status == 2 ) ;
return 'Unknown' if ( $ status == 3 ) ;
return 'Not init' if ( $ status == 4 ) ;
return 'N/A' ;
}
2012-07-24 15:23:27 +02:00
########################################################################
## SUB get_get_status (agent_id)
## Return agent status, given "agent_id"
########################################################################
sub get_agent_status ($$$) {
my ( $ pa_config , $ dbh , $ agent_id ) = @ _ ;
my @ modules = get_agent_modules ( $ pa_config , $ dbh ,
$ agent_id , 'id_agente_modulo' , { 'disabled' = > 0 } ) ;
#logger($pa_config, Dumper(@modules), 5);
# The status are:
# 3 -> AGENT_MODULE_STATUS_UNKNOW
# 4 -> AGENT_MODULE_STATUS_CRITICAL_ALERT
# 1 -> AGENT_MODULE_STATUS_CRITICAL_BAD
# 2 -> AGENT_MODULE_STATUS_WARNING
# 0 -> AGENT_MODULE_STATUS_NORMAL
my $ module_status = 3 ;
my $ modules_async = 0 ;
foreach my $ module ( @ modules ) {
my $ m_status = get_agentmodule_status ( $ pa_config , $ dbh ,
$ module - > { 'id_agente_modulo' } ) ;
#This is the order to check
# AGENT_MODULE_STATUS_CRITICAL_ALERT
# AGENT_MODULE_STATUS_CRITICAL_BAD
# AGENT_MODULE_STATUS_WARNING
2013-11-25 23:03:07 +01:00
# AGENT_MODULE_STATUS_UNKNOWN
2012-07-24 15:23:27 +02:00
# AGENT_MODULE_STATUS_NORMAL
if ( $ m_status == 4 ) {
$ module_status = 4 ;
}
elsif ( $ module_status != 4 ) {
if ( $ m_status == 1 ) {
$ module_status = 1 ;
}
elsif ( $ module_status != 1 ) {
if ( $ m_status == 2 ) {
$ module_status = 2 ;
}
2013-11-25 23:03:07 +01:00
elsif ( $ module_status != 2 ) {
2012-07-24 15:23:27 +02:00
if ( $ m_status == 0 ) {
$ module_status = 0 ;
}
}
}
}
my $ module_type = get_db_value ( $ dbh , ' SELECT id_tipo_modulo
FROM tagente_modulo
WHERE id_agente_modulo = ? ', $module->{' id_agente_modulo ' } ) ;
if ( ( $ module_type >= 21 && $ module_type <= 23 ) ||
$ module_type == 100 ) {
$ modules_async + + ;
}
}
my $ count_modules = scalar ( @ modules ) ;
# If all the modules are asynchronous or keep alive, the group cannot be unknown
if ( $ modules_async < $ count_modules ) {
my $ last_contact = get_db_value ( $ dbh ,
' SELECT ( UNIX_TIMESTAMP ( ultimo_contacto ) + ( intervalo * 2 ) ) AS last_contact
FROM tagente WHERE id_agente = ? ' , $ agent_id ) ;
if ( $ last_contact < time ( ) ) {
return 3 ;
}
}
return $ module_status ;
}
########################################################################
2011-05-23 13:55:08 +02:00
## SUB get_module_agent_id (agent_module_id)
## Return agent id, given "agent_module_id"
2012-07-24 15:23:27 +02:00
########################################################################
2011-05-23 13:55:08 +02:00
sub get_module_agent_id ($$) {
my ( $ dbh , $ agent_module_id ) = @ _ ;
return get_db_value ( $ dbh , "SELECT id_agente FROM tagente_modulo WHERE id_agente_modulo = ?" , $ agent_module_id ) ;
}
2012-07-24 15:23:27 +02:00
########################################################################
2011-05-12 13:11:37 +02:00
## SUB get_agent_address (id_agente)
## Return agent address, given "agent_id"
2012-07-24 15:23:27 +02:00
########################################################################
2011-05-12 13:11:37 +02:00
sub get_agent_address ($$) {
my ( $ dbh , $ agent_id ) = @ _ ;
return get_db_value ( $ dbh , "SELECT direccion FROM tagente WHERE id_agente = ?" , $ agent_id ) ;
}
2012-07-24 15:23:27 +02:00
########################################################################
2010-02-15 14:07:52 +01:00
## SUB get_module_name(module_id)
## Return the module name, given "module_id"
2012-07-24 15:23:27 +02:00
########################################################################
2010-02-15 14:07:52 +01:00
sub get_module_name ($$) {
my ( $ dbh , $ module_id ) = @ _ ;
return get_db_value ( $ dbh , "SELECT nombre FROM tagente_modulo WHERE id_agente_modulo = ?" , $ module_id ) ;
}
2012-07-24 15:23:27 +02:00
########################################################################
2010-05-25 13:56:37 +02:00
## Return module id given the module name and agent id.
2012-07-24 15:23:27 +02:00
########################################################################
2010-05-25 13:56:37 +02:00
sub get_agent_module_id ($$$) {
my ( $ dbh , $ module_name , $ agent_id ) = @ _ ;
2012-01-16 15:55:55 +01:00
my $ rc = get_db_value ( $ dbh , "SELECT id_agente_modulo FROM tagente_modulo WHERE delete_pending = 0 AND nombre = ? AND id_agente = ?" , safe_input ( $ module_name ) , $ agent_id ) ;
2010-05-25 13:56:37 +02:00
return defined ( $ rc ) ? $ rc : - 1 ;
}
2010-05-25 15:16:34 +02:00
##########################################################################
## Return template id given the template name.
##########################################################################
sub get_template_id ($$) {
my ( $ dbh , $ template_name ) = @ _ ;
2016-01-18 17:01:37 +01:00
my $ field ;
if ( $ RDBMS eq 'oracle' ) {
$ field = "to_char(name)" ;
}
else {
$ field = "name" ;
}
my $ rc = get_db_value ( $ dbh , "SELECT id FROM talert_templates WHERE $field = ?" , safe_input ( $ template_name ) ) ;
2010-05-25 15:16:34 +02:00
return defined ( $ rc ) ? $ rc : - 1 ;
}
##########################################################################
## Return the module template id given the module id and the template id.
##########################################################################
sub get_template_module_id ($$$) {
my ( $ dbh , $ module_id , $ template_id ) = @ _ ;
my $ rc = get_db_value ( $ dbh , "SELECT id FROM talert_template_modules WHERE id_agent_module = ? AND id_alert_template = ?" , $ module_id , $ template_id ) ;
return defined ( $ rc ) ? $ rc : - 1 ;
}
2007-08-02 19:53:07 +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
## Returns true if the given group is disabled, false otherwise.
2007-08-02 19:53:07 +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
sub is_group_disabled ($$) {
my ( $ dbh , $ group_id ) = @ _ ;
2012-07-24 15:23:27 +02:00
2009-04-14 Ramon Novoa <rnovoa@artica.es>
* pandora_ctl, pandora_network, pandora_wmi, pandora_plugin,
pandora_prediction, bin/pandora_wmi, bin/pandora_plugin,
bin/pandora_prediction, bin/pandora_snmpconsole, bin/pandora_recon,
bin/pandora_network, pandora_recon, pandora_snmpconsole: Deleted
from repository. Old server code and startup scripts.
* Makefile.PL, pandora_server_installer, lib/PandoraFMS/Config.pm
lib/PandoraFMS/DB.pm, lib/PandoraFMS/Tools.pm, bin/pandora_server,
pandora_package_installer, pandora_server: Updated to work with the
new code, removed unneeded dependencies, fixed some bugs etc.
* lib/PandoraFMS/SNMPServer.pm, lib/PandoraFMS/PluginServer.pm,
lib/PandoraFMS/ProducerConsumerServer.pm, lib/PandoraFMS/Server.pm,
lib/PandoraFMS/PredictionServer.pm, lib/PandoraFMS/Core.pm,
lib/PandoraFMS/ReconServer.pm, lib/PandoraFMS/DataServer.pm,
lib/PandoraFMS/NetworkServer.pm, lib/PandoraFMS/WMIServer.pm: Added
to repository. New server code.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1620 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-04-14 21:13:16 +02:00
return get_db_value ( $ dbh , "SELECT disabled FROM tgrupo WHERE id_grupo = ?" , $ group_id ) ;
2007-08-02 19:53:07 +02:00
}
##########################################################################
2009-04-14 Ramon Novoa <rnovoa@artica.es>
* pandora_ctl, pandora_network, pandora_wmi, pandora_plugin,
pandora_prediction, bin/pandora_wmi, bin/pandora_plugin,
bin/pandora_prediction, bin/pandora_snmpconsole, bin/pandora_recon,
bin/pandora_network, pandora_recon, pandora_snmpconsole: Deleted
from repository. Old server code and startup scripts.
* Makefile.PL, pandora_server_installer, lib/PandoraFMS/Config.pm
lib/PandoraFMS/DB.pm, lib/PandoraFMS/Tools.pm, bin/pandora_server,
pandora_package_installer, pandora_server: Updated to work with the
new code, removed unneeded dependencies, fixed some bugs etc.
* lib/PandoraFMS/SNMPServer.pm, lib/PandoraFMS/PluginServer.pm,
lib/PandoraFMS/ProducerConsumerServer.pm, lib/PandoraFMS/Server.pm,
lib/PandoraFMS/PredictionServer.pm, lib/PandoraFMS/Core.pm,
lib/PandoraFMS/ReconServer.pm, lib/PandoraFMS/DataServer.pm,
lib/PandoraFMS/NetworkServer.pm, lib/PandoraFMS/WMIServer.pm: Added
to repository. New server code.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1620 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-04-14 21:13:16 +02:00
## Return module ID given the module name.
2007-08-02 19:53:07 +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
sub get_module_id ($$) {
my ( $ dbh , $ module_name ) = @ _ ;
2012-07-24 15:23:27 +02:00
2010-11-02 18:26:34 +01:00
my $ rc = get_db_value ( $ dbh , "SELECT id_tipo FROM ttipo_modulo WHERE nombre = ?" , 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
return defined ( $ rc ) ? $ rc : - 1 ;
}
2007-08-02 19:53:07 +02:00
2012-01-04 16:09:02 +01:00
##########################################################################
## Return disabled bit frin a user.
##########################################################################
sub get_user_disabled ($$) {
my ( $ dbh , $ user_id ) = @ _ ;
2012-07-24 15:23:27 +02:00
2012-01-04 16:09:02 +01:00
my $ rc = get_db_value ( $ dbh , "SELECT disabled FROM tusuario WHERE id_user = ?" , safe_input ( $ user_id ) ) ;
return defined ( $ rc ) ? $ rc : - 1 ;
}
2012-01-05 13:11:03 +01:00
##########################################################################
## Return 1 if user exists or -1 if not
##########################################################################
sub get_user_exists ($$) {
my ( $ dbh , $ user_id ) = @ _ ;
2012-07-24 15:23:27 +02:00
2012-01-05 13:11:03 +01:00
my $ rc = get_db_value ( $ dbh , "SELECT id_user FROM tusuario WHERE id_user = ?" , safe_input ( $ user_id ) ) ;
return defined ( $ rc ) ? 1 : - 1 ;
}
2010-10-18 18:21:13 +02:00
##########################################################################
## Return plugin ID given the plugin name.
##########################################################################
sub get_plugin_id ($$) {
my ( $ dbh , $ plugin_name ) = @ _ ;
2012-07-24 15:23:27 +02:00
2010-11-02 18:26:34 +01:00
my $ rc = get_db_value ( $ dbh , "SELECT id FROM tplugin WHERE name = ?" , safe_input ( $ plugin_name ) ) ;
2010-10-18 18:21:13 +02:00
return defined ( $ rc ) ? $ rc : - 1 ;
}
##########################################################################
## Return module group ID given the module group name.
##########################################################################
sub get_module_group_id ($$) {
my ( $ dbh , $ module_group_name ) = @ _ ;
2012-07-24 15:23:27 +02:00
if ( ! defined ( $ module_group_name ) || $ module_group_name eq '' ) {
2010-10-18 18:21:13 +02:00
return 0 ;
}
2010-11-02 18:26:34 +01:00
my $ rc = get_db_value ( $ dbh , "SELECT id_mg FROM tmodule_group WHERE name = ?" , safe_input ( $ module_group_name ) ) ;
2010-10-18 18:21:13 +02:00
return defined ( $ rc ) ? $ rc : - 1 ;
}
2011-10-06 04:46:55 +02:00
##########################################################################
## Return module group name given the module group id.
##########################################################################
sub get_module_group_name ($$) {
my ( $ dbh , $ module_group_id ) = @ _ ;
2012-07-24 15:23:27 +02:00
2011-10-06 04:46:55 +02:00
return get_db_value ( $ dbh , "SELECT name FROM tmodule_group WHERE id_mg = ?" , $ module_group_id ) ;
}
2007-08-02 19:53:07 +02:00
##########################################################################
2009-11-04 18:49:42 +01:00
## Return a network component's profile name given its ID.
2007-08-02 19:53:07 +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
sub get_nc_profile_name ($$) {
my ( $ dbh , $ nc_id ) = @ _ ;
2009-03-04 18:15:39 +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
return get_db_value ( $ dbh , "SELECT * FROM tnetwork_profile WHERE id_np = ?" , $ nc_id ) ;
2007-08-02 19:53:07 +02:00
}
2010-05-26 11:54:21 +02:00
##########################################################################
2015-03-26 13:41:07 +01:00
## Return user profile ID given the user id, group id and profile id.
##########################################################################
sub get_user_profile_id ($$$$) {
my ( $ dbh , $ user_id , $ profile_id , $ group_id ) = @ _ ;
my $ rc = get_db_value ( $ dbh , " SELECT id_up FROM tusuario_perfil
WHERE id_usuario = ?
AND id_perfil = ?
AND id_grupo = ? " ,
safe_input ( $ user_id ) ,
$ profile_id ,
$ group_id ) ;
return defined ( $ rc ) ? $ rc : - 1 ;
}
2010-05-26 11:54:21 +02:00
##########################################################################
## Return profile ID given the profile name.
##########################################################################
sub get_profile_id ($$) {
my ( $ dbh , $ profile_name ) = @ _ ;
2012-07-24 15:23:27 +02:00
2010-11-02 18:26:34 +01:00
my $ rc = get_db_value ( $ dbh , "SELECT id_perfil FROM tperfil WHERE name = ?" , safe_input ( $ profile_name ) ) ;
2010-05-26 11:54:21 +02:00
return defined ( $ rc ) ? $ rc : - 1 ;
}
2009-11-04 18:49:42 +01:00
##########################################################################
## Return a group's name given its ID.
##########################################################################
sub get_group_name ($$) {
my ( $ dbh , $ group_id ) = @ _ ;
return get_db_value ( $ dbh , "SELECT nombre FROM tgrupo WHERE id_grupo = ?" , $ group_id ) ;
}
2012-07-24 15:23:27 +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
## Get a single column returned by an SQL query as a hash reference.
2012-07-24 15:23:27 +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
sub get_db_value ($$;@) {
2012-07-24 15:23:27 +02:00
my ( $ dbh , $ query , @ values ) = @ _ ;
# Cache statements
my $ sth = $ dbh - > prepare_cached ( $ query ) ;
$ sth - > execute ( @ values ) ;
# Save returned rows
while ( my $ row = $ sth - > fetchrow_arrayref ( ) ) {
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
$ sth - > finish ( ) ;
2012-07-24 15:23:27 +02:00
return defined ( $ row - > [ 0 ] ) ? $ row - > [ 0 ] : undef ;
}
$ sth - > finish ( ) ;
return undef ;
2007-08-02 19:53:07 +02:00
}
2015-05-05 11:20:41 +02:00
########################################################################
## Get a single column returned by an SQL query with a LIMIT statement
## as a hash reference.
########################################################################
sub get_db_value_limit ($$$;@) {
my ( $ dbh , $ query , $ limit , @ values ) = @ _ ;
# Cache statements
my $ sth ;
if ( $ RDBMS ne 'oracle' ) {
2015-07-22 15:36:46 +02:00
$ sth = $ dbh - > prepare_cached ( $ query . ' LIMIT ' . int ( $ limit ) ) ;
2015-05-05 11:20:41 +02:00
} else {
2015-07-22 15:36:46 +02:00
$ sth = $ dbh - > prepare_cached ( 'SELECT * FROM (' . $ query . ') WHERE ROWNUM <= ' . int ( $ limit ) ) ;
2015-05-05 11:20:41 +02:00
}
$ sth - > execute ( @ values ) ;
# Save returned rows
while ( my $ row = $ sth - > fetchrow_arrayref ( ) ) {
$ sth - > finish ( ) ;
return defined ( $ row - > [ 0 ] ) ? $ row - > [ 0 ] : undef ;
}
$ sth - > finish ( ) ;
return undef ;
}
2007-08-02 19:53:07 +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
## Get a single row returned by an SQL query as a hash reference. Returns
## -1 on error.
2007-08-02 19:53:07 +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
sub get_db_single_row ($$;@) {
2012-07-24 15:23:27 +02:00
my ( $ dbh , $ query , @ values ) = @ _ ;
#my @rows;
# Cache statements
my $ sth = $ dbh - > prepare_cached ( $ query ) ;
$ sth - > execute ( @ values ) ;
# Save returned rows
while ( my $ row = $ sth - > fetchrow_hashref ( ) ) {
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
$ sth - > finish ( ) ;
2012-07-24 15:23:27 +02:00
return { map { lc ( $ _ ) = > $ row - > { $ _ } } keys ( % { $ row } ) } if ( $ RDBMS eq 'oracle' ) ;
return $ row ;
}
$ sth - > finish ( ) ;
return undef ;
2007-08-02 19:53:07 +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
## Get all rows returned by an SQL query as a hash reference array.
2007-08-02 19:53:07 +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
sub get_db_rows ($$;@) {
2012-07-24 15:23:27 +02:00
my ( $ dbh , $ query , @ values ) = @ _ ;
my @ rows ;
# Cache statements
my $ sth = $ dbh - > prepare_cached ( $ query ) ;
$ sth - > execute ( @ values ) ;
# Save returned rows
while ( my $ row = $ sth - > fetchrow_hashref ( ) ) {
if ( $ RDBMS eq 'oracle' ) {
push ( @ rows , { map { lc ( $ _ ) = > $ row - > { $ _ } } keys ( % { $ row } ) } ) ;
2007-08-02 19:53:07 +02:00
}
2012-07-24 15:23:27 +02:00
else {
push ( @ rows , $ row ) ;
}
}
$ sth - > finish ( ) ;
return @ rows ;
2007-08-02 19:53:07 +02:00
}
2015-06-08 18:32:49 +02:00
########################################################################
## Get all rows (with a limit clause) returned by an SQL query
## as a hash reference array.
########################################################################
sub get_db_rows_limit ($$$;@) {
my ( $ dbh , $ query , $ limit , @ values ) = @ _ ;
my @ rows ;
# Cache statements
my $ sth ;
if ( $ RDBMS ne 'oracle' ) {
$ sth = $ dbh - > prepare_cached ( $ query . ' LIMIT ' . $ limit ) ;
} else {
$ sth = $ dbh - > prepare_cached ( 'SELECT * FROM (' . $ query . ') WHERE ROWNUM <= ' . $ limit ) ;
}
$ sth - > execute ( @ values ) ;
# Save returned rows
while ( my $ row = $ sth - > fetchrow_hashref ( ) ) {
if ( $ RDBMS eq 'oracle' ) {
push ( @ rows , { map { lc ( $ _ ) = > $ row - > { $ _ } } keys ( % { $ row } ) } ) ;
}
else {
push ( @ rows , $ row ) ;
}
}
$ sth - > finish ( ) ;
return @ rows ;
}
2015-07-22 15:36:46 +02:00
##########################################################################
## SQL delete with a LIMIT clause.
##########################################################################
sub db_delete_limit ($$$$;@) {
my ( $ dbh , $ from , $ where , $ limit , @ values ) = @ _ ;
my $ sth ;
# MySQL
if ( $ RDBMS eq 'mysql' ) {
$ sth = $ dbh - > prepare_cached ( "DELETE FROM $from WHERE $where LIMIT " . int ( $ limit ) ) ;
}
# PostgreSQL
elsif ( $ RDBMS eq 'postgresql' ) {
$ sth = $ dbh - > prepare_cached ( "DELETE FROM $from WHERE $where LIMIT " . int ( $ limit ) ) ;
}
# Oracle
elsif ( $ RDBMS eq 'oracle' ) {
$ sth = $ dbh - > prepare_cached ( "DELETE FROM (SELECT * FROM $from WHERE $where) WHERE ROWNUM <= " . int ( $ limit ) ) ;
}
$ sth - > execute ( @ values ) ;
}
2007-08-02 19:53:07 +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
## SQL insert. Returns the ID of the inserted row.
2007-08-02 19:53:07 +02:00
##########################################################################
2011-04-13 Ramon Novoa <rnovoa@artica.es>
* lib/PandoraFMS/SNMPServer.pm,
lib/PandoraFMS/Config.pm,
lib/PandoraFMS/NetworkServer.pm,
lib/PandoraFMS/WMIServer.pm,
lib/PandoraFMS/PluginServer.pm,
lib/PandoraFMS/DB.pm,
lib/PandoraFMS/ProducerConsumerServer.pm,
lib/PandoraFMS/PredictionServer.pm,
lib/PandoraFMS/Core.pm,
lib/PandoraFMS/ReconServer.pm,
bin/pandora_server,
util/pandora_db.pl,
util/pandora_manage.pl,
util/recon_scripts/snmpdevices.pl: Adding support for PostgreSQL and
Oracle (not complete).
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4213 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2011-04-13 18:28:59 +02:00
sub db_insert ($$$;@) {
my ( $ dbh , $ index , $ query , @ values ) = @ _ ;
my $ insert_id = undef ;
2012-07-24 15:23:27 +02:00
2014-07-25 15:15:24 +02:00
2011-04-13 Ramon Novoa <rnovoa@artica.es>
* lib/PandoraFMS/SNMPServer.pm,
lib/PandoraFMS/Config.pm,
lib/PandoraFMS/NetworkServer.pm,
lib/PandoraFMS/WMIServer.pm,
lib/PandoraFMS/PluginServer.pm,
lib/PandoraFMS/DB.pm,
lib/PandoraFMS/ProducerConsumerServer.pm,
lib/PandoraFMS/PredictionServer.pm,
lib/PandoraFMS/Core.pm,
lib/PandoraFMS/ReconServer.pm,
bin/pandora_server,
util/pandora_db.pl,
util/pandora_manage.pl,
util/recon_scripts/snmpdevices.pl: Adding support for PostgreSQL and
Oracle (not complete).
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4213 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2011-04-13 18:28:59 +02:00
# MySQL
if ( $ RDBMS eq 'mysql' ) {
$ dbh - > do ( $ query , undef , @ values ) ;
$ insert_id = $ dbh - > { 'mysql_insertid' } ;
}
# PostgreSQL
elsif ( $ RDBMS eq 'postgresql' ) {
2013-03-01 15:27:52 +01:00
$ insert_id = get_db_value ( $ dbh , $ query . ' RETURNING ' . $ RDBMS_QUOTE . $ index . $ RDBMS_QUOTE , @ values ) ;
2011-04-18 18:42:18 +02:00
}
# Oracle
elsif ( $ RDBMS eq 'oracle' ) {
2013-03-01 15:27:52 +01:00
my $ sth = $ dbh - > prepare ( $ query . ' RETURNING ' . $ RDBMS_QUOTE . ( uc ( $ index ) ) . $ RDBMS_QUOTE . ' INTO ?' ) ;
2011-04-18 18:42:18 +02:00
for ( my $ i = 0 ; $ i <= $# values ; $ i + + ) {
$ sth - > bind_param ( $ i + 1 , $ values [ $ i ] ) ;
}
$ sth - > bind_param_inout ( $# values + 2 , \ $ insert_id , 99 ) ;
$ sth - > execute ( ) ;
2011-04-13 Ramon Novoa <rnovoa@artica.es>
* lib/PandoraFMS/SNMPServer.pm,
lib/PandoraFMS/Config.pm,
lib/PandoraFMS/NetworkServer.pm,
lib/PandoraFMS/WMIServer.pm,
lib/PandoraFMS/PluginServer.pm,
lib/PandoraFMS/DB.pm,
lib/PandoraFMS/ProducerConsumerServer.pm,
lib/PandoraFMS/PredictionServer.pm,
lib/PandoraFMS/Core.pm,
lib/PandoraFMS/ReconServer.pm,
bin/pandora_server,
util/pandora_db.pl,
util/pandora_manage.pl,
util/recon_scripts/snmpdevices.pl: Adding support for PostgreSQL and
Oracle (not complete).
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4213 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2011-04-13 18:28:59 +02:00
}
2012-07-24 15:23:27 +02:00
2011-04-13 Ramon Novoa <rnovoa@artica.es>
* lib/PandoraFMS/SNMPServer.pm,
lib/PandoraFMS/Config.pm,
lib/PandoraFMS/NetworkServer.pm,
lib/PandoraFMS/WMIServer.pm,
lib/PandoraFMS/PluginServer.pm,
lib/PandoraFMS/DB.pm,
lib/PandoraFMS/ProducerConsumerServer.pm,
lib/PandoraFMS/PredictionServer.pm,
lib/PandoraFMS/Core.pm,
lib/PandoraFMS/ReconServer.pm,
bin/pandora_server,
util/pandora_db.pl,
util/pandora_manage.pl,
util/recon_scripts/snmpdevices.pl: Adding support for PostgreSQL and
Oracle (not complete).
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4213 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2011-04-13 18:28:59 +02:00
return $ insert_id ;
2007-08-02 19:53:07 +02:00
}
2010-10-21 16:26:46 +02:00
##########################################################################
## SQL update. Returns the number of updated rows.
##########################################################################
sub db_update ($$;@) {
my ( $ dbh , $ query , @ values ) = @ _ ;
my $ rows = $ dbh - > do ( $ query , undef , @ values ) ;
return $ rows ;
}
2011-05-09 11:42:01 +02:00
##########################################################################
## Return alert template-module ID given the module and template ids.
##########################################################################
sub get_alert_template_module_id ($$$) {
my ( $ dbh , $ id_module , $ id_template ) = @ _ ;
2012-07-24 15:23:27 +02:00
2011-05-09 11:42:01 +02:00
my $ rc = get_db_value ( $ dbh , "SELECT id FROM talert_template_modules WHERE id_agent_module = ? AND id_alert_template = ?" , $ id_module , $ id_template ) ;
return defined ( $ rc ) ? $ rc : - 1 ;
}
2014-07-25 15:15:24 +02:00
########################################################################
2010-09-23 10:16:44 +02:00
## SQL insert. Returns the ID of the inserted row.
2014-07-25 15:15:24 +02:00
########################################################################
2011-04-13 Ramon Novoa <rnovoa@artica.es>
* lib/PandoraFMS/SNMPServer.pm,
lib/PandoraFMS/Config.pm,
lib/PandoraFMS/NetworkServer.pm,
lib/PandoraFMS/WMIServer.pm,
lib/PandoraFMS/PluginServer.pm,
lib/PandoraFMS/DB.pm,
lib/PandoraFMS/ProducerConsumerServer.pm,
lib/PandoraFMS/PredictionServer.pm,
lib/PandoraFMS/Core.pm,
lib/PandoraFMS/ReconServer.pm,
bin/pandora_server,
util/pandora_db.pl,
util/pandora_manage.pl,
util/recon_scripts/snmpdevices.pl: Adding support for PostgreSQL and
Oracle (not complete).
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4213 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2011-04-13 18:28:59 +02:00
sub db_process_insert ($$$$;@) {
my ( $ dbh , $ index , $ table , $ parameters , @ values ) = @ _ ;
2012-07-24 15:23:27 +02:00
2010-09-23 10:16:44 +02:00
my @ columns_array = keys %$ parameters ;
my @ values_array = values %$ parameters ;
2012-07-24 15:23:27 +02:00
if ( ! defined ( $ table ) || $# columns_array == - 1 ) {
2010-09-23 10:16:44 +02:00
return - 1 ;
exit ;
}
2010-11-04 18:35:37 +01:00
# Generate the '?' simbols to the Query like '(?,?,?,?,?)'
my $ wildcards = '' ;
2010-09-23 13:29:08 +02:00
for ( my $ i = 0 ; $ i <= $# values_array ; $ i + + ) {
2012-07-24 15:23:27 +02:00
if ( ! defined ( $ values_array [ $ i ] ) ) {
2010-09-23 13:29:08 +02:00
$ values_array [ $ i ] = '' ;
}
2012-07-24 15:23:27 +02:00
if ( $ i > 0 && $ i <= $# values_array ) {
2010-11-04 18:35:37 +01:00
$ wildcards = $ wildcards . ',' ;
}
$ wildcards = $ wildcards . '?' ;
2012-07-24 15:23:27 +02:00
}
2010-11-04 18:35:37 +01:00
$ wildcards = '(' . $ wildcards . ')' ;
2012-07-24 15:23:27 +02:00
2015-10-09 12:38:15 +02:00
# Escape column names that are reserved words
for ( my $ i = 0 ; $ i < scalar ( @ columns_array ) ; $ i + + ) {
if ( $ columns_array [ $ i ] eq 'interval' ) {
$ columns_array [ $ i ] = "${RDBMS_QUOTE}interval${RDBMS_QUOTE}" ;
}
}
2015-05-05 15:34:03 +02:00
my $ columns_string = join ( ',' , @ columns_array ) ;
2014-07-25 15:15:24 +02:00
my $ res = db_insert ( $ dbh ,
$ index ,
2015-05-05 15:34:03 +02:00
"INSERT INTO $table ($columns_string) VALUES " . $ wildcards , @ values_array ) ;
2010-11-04 18:35:37 +01:00
2012-07-24 15:23:27 +02:00
2010-11-04 18:35:37 +01:00
return $ res ;
}
2012-07-25 17:14:36 +02:00
########################################################################
2010-11-04 18:35:37 +01:00
## SQL update.
2012-07-25 17:14:36 +02:00
########################################################################
2015-04-06 15:26:26 +02:00
sub db_process_update ($$$$) {
my ( $ dbh , $ table , $ parameters , $ conditions ) = @ _ ;
2012-07-24 15:23:27 +02:00
2010-11-04 18:35:37 +01:00
my @ columns_array = keys %$ parameters ;
my @ values_array = values %$ parameters ;
2015-04-06 15:26:26 +02:00
my @ where_columns = keys %$ conditions ;
my @ where_values = values %$ conditions ;
2012-07-24 15:23:27 +02:00
2015-04-06 15:26:26 +02:00
if ( ! defined ( $ table ) || $# columns_array == - 1 || $# where_columns == - 1 ) {
2010-11-04 18:35:37 +01:00
return - 1 ;
exit ;
}
2010-09-23 10:16:44 +02:00
2015-04-06 15:26:26 +02:00
# VALUES...
2010-11-04 18:35:37 +01:00
my $ fields = '' ;
2012-07-25 17:14:36 +02:00
for ( my $ i = 0 ; $ i <= $# values_array ; $ i + + ) {
2012-07-24 15:23:27 +02:00
if ( ! defined ( $ values_array [ $ i ] ) ) {
2010-11-04 18:35:37 +01:00
$ values_array [ $ i ] = '' ;
}
2012-07-24 15:23:27 +02:00
if ( $ i > 0 && $ i <= $# values_array ) {
2010-11-04 18:35:37 +01:00
$ fields = $ fields . ',' ;
}
2015-06-08 18:32:49 +02:00
# Avoid the use of quotes on the column names in oracle, cause the quotes
# force the engine to be case sensitive and the column names created without
# quotes are stores in uppercase.
# The quotes should be introduced manually for every item created with it.
if ( $ RDBMS eq 'oracle' ) {
$ fields = $ fields . " " . $ columns_array [ $ i ] . " = ?" ;
}
else {
$ fields = $ fields . " " . $ RDBMS_QUOTE . "$columns_array[$i]" . $ RDBMS_QUOTE . " = ?" ;
}
2012-07-24 15:23:27 +02:00
}
2015-04-06 15:26:26 +02:00
# WHERE...
my $ where = '' ;
for ( my $ i = 0 ; $ i <= $# where_columns ; $ i + + ) {
if ( ! defined ( $ where_values [ $ i ] ) ) {
$ where_values [ $ i ] = '' ;
}
if ( $ i > 0 && $ i <= $# where_values ) {
$ where = $ where . ' AND ' ;
}
2015-06-08 18:32:49 +02:00
# Avoid the use of quotes on the column names in oracle, cause the quotes
# force the engine to be case sensitive and the column names created without
# quotes are stores in uppercase.
# The quotes should be introduced manually for every item created with it.
if ( $ RDBMS eq 'oracle' ) {
$ where = $ where . " " . $ where_columns [ $ i ] . " = ?" ;
}
else {
$ where = $ where . " " . $ RDBMS_QUOTE . "$where_columns[$i]" . $ RDBMS_QUOTE . " = ?" ;
}
2015-04-06 15:26:26 +02:00
}
2012-07-25 17:14:36 +02:00
my $ res = db_update ( $ dbh , " UPDATE $ table
SET $ fields
2015-04-06 15:26:26 +02:00
WHERE $ where " , @ values_array , @ where_values ) ;
2012-07-24 15:23:27 +02:00
2010-11-04 18:35:37 +01:00
return $ res ;
2010-09-23 10:16:44 +02:00
}
2014-07-25 15:15:24 +02:00
########################################################################
2011-06-28 12:04:45 +02:00
# Add the given address to taddress.
2014-07-25 15:15:24 +02:00
########################################################################
2011-06-28 12:04:45 +02:00
sub add_address ($$) {
my ( $ dbh , $ ip_address ) = @ _ ;
2014-07-25 15:15:24 +02:00
2011-06-28 12:04:45 +02:00
return db_insert ( $ dbh , 'id_a' , 'INSERT INTO taddress (ip) VALUES (?)' , $ ip_address ) ;
}
2014-07-25 15:15:24 +02:00
########################################################################
2011-06-28 12:04:45 +02:00
# Assign the new address to the agent
2014-07-25 15:15:24 +02:00
########################################################################
2011-06-28 12:04:45 +02:00
sub add_new_address_agent ($$$) {
my ( $ dbh , $ addr_id , $ agent_id ) = @ _ ;
2015-05-05 15:34:03 +02:00
db_do ( $ dbh , ' INSERT INTO taddress_agent ( id_a , id_agent )
VALUES ( ? , ? ) ' , $ addr_id , $ agent_id ) ;
2011-06-28 12:04:45 +02:00
}
2014-07-25 15:15:24 +02:00
########################################################################
2011-06-28 12:04:45 +02:00
# Return the ID of the given address, -1 if it does not exist.
2014-07-25 15:15:24 +02:00
########################################################################
2011-06-28 12:04:45 +02:00
sub get_addr_id ($$) {
my ( $ dbh , $ addr ) = @ _ ;
2012-07-24 15:23:27 +02:00
my $ addr_id = get_db_value ( $ dbh ,
' SELECT id_a
FROM taddress
WHERE ip = ? ' , $ addr ) ;
2011-06-28 12:04:45 +02:00
return ( defined ( $ addr_id ) ? $ addr_id : - 1 ) ;
}
2012-04-12 12:04:35 +02:00
##########################################################################
# Return the agent address ID for the given agent ID and address ID, -1 if
# it does not exist.
##########################################################################
sub get_agent_addr_id ($$$) {
my ( $ dbh , $ addr_id , $ agent_id ) = @ _ ;
2012-07-24 15:23:27 +02:00
my $ agent_addr_id = get_db_value ( $ dbh ,
' SELECT id_ag
FROM taddress_agent
WHERE id_a = ?
AND id_agent = ? ' , $ addr_id , $ agent_id ) ;
2012-07-25 17:14:36 +02:00
2012-04-12 12:04:35 +02:00
return ( defined ( $ agent_addr_id ) ? $ agent_addr_id : - 1 ) ;
}
2012-07-25 17:14:36 +02:00
########################################################################
2009-04-14 Ramon Novoa <rnovoa@artica.es>
* pandora_ctl, pandora_network, pandora_wmi, pandora_plugin,
pandora_prediction, bin/pandora_wmi, bin/pandora_plugin,
bin/pandora_prediction, bin/pandora_snmpconsole, bin/pandora_recon,
bin/pandora_network, pandora_recon, pandora_snmpconsole: Deleted
from repository. Old server code and startup scripts.
* Makefile.PL, pandora_server_installer, lib/PandoraFMS/Config.pm
lib/PandoraFMS/DB.pm, lib/PandoraFMS/Tools.pm, bin/pandora_server,
pandora_package_installer, pandora_server: Updated to work with the
new code, removed unneeded dependencies, fixed some bugs etc.
* lib/PandoraFMS/SNMPServer.pm, lib/PandoraFMS/PluginServer.pm,
lib/PandoraFMS/ProducerConsumerServer.pm, lib/PandoraFMS/Server.pm,
lib/PandoraFMS/PredictionServer.pm, lib/PandoraFMS/Core.pm,
lib/PandoraFMS/ReconServer.pm, lib/PandoraFMS/DataServer.pm,
lib/PandoraFMS/NetworkServer.pm, lib/PandoraFMS/WMIServer.pm: Added
to repository. New server code.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1620 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-04-14 21:13:16 +02:00
## Generic SQL sentence.
2012-07-25 17:14:36 +02:00
########################################################################
2009-04-14 Ramon Novoa <rnovoa@artica.es>
* pandora_ctl, pandora_network, pandora_wmi, pandora_plugin,
pandora_prediction, bin/pandora_wmi, bin/pandora_plugin,
bin/pandora_prediction, bin/pandora_snmpconsole, bin/pandora_recon,
bin/pandora_network, pandora_recon, pandora_snmpconsole: Deleted
from repository. Old server code and startup scripts.
* Makefile.PL, pandora_server_installer, lib/PandoraFMS/Config.pm
lib/PandoraFMS/DB.pm, lib/PandoraFMS/Tools.pm, bin/pandora_server,
pandora_package_installer, pandora_server: Updated to work with the
new code, removed unneeded dependencies, fixed some bugs etc.
* lib/PandoraFMS/SNMPServer.pm, lib/PandoraFMS/PluginServer.pm,
lib/PandoraFMS/ProducerConsumerServer.pm, lib/PandoraFMS/Server.pm,
lib/PandoraFMS/PredictionServer.pm, lib/PandoraFMS/Core.pm,
lib/PandoraFMS/ReconServer.pm, lib/PandoraFMS/DataServer.pm,
lib/PandoraFMS/NetworkServer.pm, lib/PandoraFMS/WMIServer.pm: Added
to repository. New server code.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1620 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-04-14 21:13:16 +02:00
sub db_do ($$;@) {
my ( $ dbh , $ query , @ values ) = @ _ ;
2012-07-24 15:23:27 +02:00
2010-02-15 14:07:52 +01:00
#DBI->trace( 3, '/tmp/dbitrace.log' );
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
$ dbh - > do ( $ query , undef , @ values ) ;
2009-02-11 19:21:24 +01:00
}
2012-07-25 17:14:36 +02:00
########################################################################
2011-06-28 17:41:13 +02:00
# Return the ID of the taddress agent with the given IP.
2012-07-25 17:14:36 +02:00
########################################################################
2011-06-28 17:41:13 +02:00
sub is_agent_address ($$$) {
my ( $ dbh , $ id_agent , $ id_addr ) = @ _ ;
2012-07-24 15:23:27 +02:00
my $ id_ag = get_db_value ( $ dbh , ' SELECT id_ag
FROM taddress_agent
WHERE id_a = ?
AND id_agent = ? ' , $ id_addr , $ id_agent ) ;
2011-06-28 17:41:13 +02:00
return ( defined ( $ id_ag ) ) ? $ id_ag : 0 ;
}
2014-07-25 15:15:24 +02:00
########################################################################
2011-04-13 Ramon Novoa <rnovoa@artica.es>
* lib/PandoraFMS/SNMPServer.pm,
lib/PandoraFMS/Config.pm,
lib/PandoraFMS/NetworkServer.pm,
lib/PandoraFMS/WMIServer.pm,
lib/PandoraFMS/PluginServer.pm,
lib/PandoraFMS/DB.pm,
lib/PandoraFMS/ProducerConsumerServer.pm,
lib/PandoraFMS/PredictionServer.pm,
lib/PandoraFMS/Core.pm,
lib/PandoraFMS/ReconServer.pm,
bin/pandora_server,
util/pandora_db.pl,
util/pandora_manage.pl,
util/recon_scripts/snmpdevices.pl: Adding support for PostgreSQL and
Oracle (not complete).
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4213 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2011-04-13 18:28:59 +02:00
## Quote the given string.
2014-07-25 15:15:24 +02:00
########################################################################
2011-04-13 Ramon Novoa <rnovoa@artica.es>
* lib/PandoraFMS/SNMPServer.pm,
lib/PandoraFMS/Config.pm,
lib/PandoraFMS/NetworkServer.pm,
lib/PandoraFMS/WMIServer.pm,
lib/PandoraFMS/PluginServer.pm,
lib/PandoraFMS/DB.pm,
lib/PandoraFMS/ProducerConsumerServer.pm,
lib/PandoraFMS/PredictionServer.pm,
lib/PandoraFMS/Core.pm,
lib/PandoraFMS/ReconServer.pm,
bin/pandora_server,
util/pandora_db.pl,
util/pandora_manage.pl,
util/recon_scripts/snmpdevices.pl: Adding support for PostgreSQL and
Oracle (not complete).
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4213 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2011-04-13 18:28:59 +02:00
sub db_string ($) {
my $ string = shift ;
# MySQL and PostgreSQL
2011-04-18 18:42:18 +02:00
#return "'" . $string . "'" if ($RDBMS eq 'mysql' || $RDBMS eq 'postgresql' || $RDBMS eq 'oracle');
return "'" . $ string . "'" ;
}
2012-07-25 17:14:36 +02:00
########################################################################
2011-04-18 18:42:18 +02:00
## Convert TEXT to string when necessary
2012-07-25 17:14:36 +02:00
########################################################################
2011-04-18 18:42:18 +02:00
sub db_text ($) {
my $ string = shift ;
#return $string;
return " dbms_lob.substr(" . $ string . ", 4000, 1)" if ( $ RDBMS eq 'oracle' ) ;
2011-04-13 Ramon Novoa <rnovoa@artica.es>
* lib/PandoraFMS/SNMPServer.pm,
lib/PandoraFMS/Config.pm,
lib/PandoraFMS/NetworkServer.pm,
lib/PandoraFMS/WMIServer.pm,
lib/PandoraFMS/PluginServer.pm,
lib/PandoraFMS/DB.pm,
lib/PandoraFMS/ProducerConsumerServer.pm,
lib/PandoraFMS/PredictionServer.pm,
lib/PandoraFMS/Core.pm,
lib/PandoraFMS/ReconServer.pm,
bin/pandora_server,
util/pandora_db.pl,
util/pandora_manage.pl,
util/recon_scripts/snmpdevices.pl: Adding support for PostgreSQL and
Oracle (not complete).
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4213 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2011-04-13 18:28:59 +02:00
return $ string ;
}
2012-07-25 17:14:36 +02:00
########################################################################
2011-06-08 13:07:39 +02:00
## SUB get_alert_template_name(alert_id)
## Return the alert template name, given "alert_id"
2012-07-25 17:14:36 +02:00
########################################################################
2011-06-08 13:07:39 +02:00
sub get_alert_template_name ($$) {
my ( $ dbh , $ alert_id ) = @ _ ;
2014-07-25 15:15:24 +02:00
return get_db_value ( $ dbh , " SELECT name
FROM talert_templates , talert_template_modules
WHERE talert_templates . id = talert_template_modules . id_alert_template
AND talert_template_modules . id = ? " , $ alert_id ) ;
2011-06-08 13:07:39 +02:00
}
2012-07-25 17:14:36 +02:00
########################################################################
2011-12-01 17:11:42 +01:00
## Concat two strings
2012-07-25 17:14:36 +02:00
########################################################################
2011-12-01 17:11:42 +01:00
sub db_concat ($$) {
my ( $ element1 , $ element2 ) = @ _ ;
2012-07-24 15:23:27 +02:00
return " " . $ element1 . " || ' ' || " . $ element2 . " " if ( $ RDBMS eq 'oracle' or $ RDBMS eq 'postgresql' ) ;
2014-07-28 18:24:40 +02:00
return " concat(" . $ element1 . ", ' '," . $ element2 . ") " ;
2011-12-01 17:11:42 +01:00
}
2012-07-25 17:14:36 +02:00
########################################################################
2012-05-10 14:18:43 +02:00
## Get priority/severity name from the associated ID
2012-07-25 17:14:36 +02:00
########################################################################
2012-05-10 14:18:43 +02:00
sub get_priority_name ($) {
my ( $ priority_id ) = @ _ ;
2012-07-24 15:23:27 +02:00
if ( $ priority_id == 0 ) {
2012-05-10 14:18:43 +02:00
return 'Maintenance' ;
}
2012-07-24 15:23:27 +02:00
elsif ( $ priority_id == 1 ) {
2012-05-10 14:18:43 +02:00
return 'Informational' ;
}
2012-07-24 15:23:27 +02:00
elsif ( $ priority_id == 2 ) {
2012-05-10 14:18:43 +02:00
return 'Normal' ;
}
2012-07-24 15:23:27 +02:00
elsif ( $ priority_id == 3 ) {
2012-05-10 14:18:43 +02:00
return 'Warning' ;
}
2012-07-24 15:23:27 +02:00
elsif ( $ priority_id == 4 ) {
2012-05-10 14:18:43 +02:00
return 'Critical' ;
}
2012-07-24 15:23:27 +02:00
elsif ( $ priority_id == 5 ) {
2012-05-10 14:18:43 +02:00
return 'Minor' ;
}
2012-07-24 15:23:27 +02:00
elsif ( $ priority_id == 6 ) {
2012-05-10 14:18:43 +02:00
return 'Major' ;
}
return '' ;
}
2013-03-01 15:27:52 +01:00
########################################################################
## Get the set string and array of values to perform un update from a hash.
########################################################################
sub db_update_get_values ($) {
my ( $ set_ref ) = @ _ ;
2014-07-25 15:15:24 +02:00
2013-03-01 15:27:52 +01:00
my $ set = '' ;
my @ values ;
while ( my ( $ key , $ value ) = each ( % { $ set_ref } ) ) {
2014-07-25 15:15:24 +02:00
# Not value for the given column
next if ( ! defined ( $ value ) ) ;
$ set . = "$key = ?," ;
push ( @ values , $ value ) ;
2013-03-01 15:27:52 +01:00
}
2014-07-25 15:15:24 +02:00
2013-03-01 15:27:52 +01:00
# Remove the last ,
chop ( $ set ) ;
return ( $ set , \ @ values ) ;
}
########################################################################
## Get the string and array of values to perform an insert from a hash.
########################################################################
sub db_insert_get_values ($) {
my ( $ insert_ref ) = @ _ ;
2014-07-25 15:15:24 +02:00
2013-03-01 15:27:52 +01:00
my $ columns = '(' ;
my @ values ;
while ( my ( $ key , $ value ) = each ( % { $ insert_ref } ) ) {
2014-07-25 15:15:24 +02:00
# Not value for the given column
next if ( ! defined ( $ value ) ) ;
2015-05-05 15:34:03 +02:00
$ columns . = $ key . "," ;
2014-07-25 15:15:24 +02:00
push ( @ values , $ value ) ;
2013-03-01 15:27:52 +01:00
}
2014-07-25 15:15:24 +02:00
2013-03-01 15:27:52 +01:00
# Remove the last , and close the parentheses
chop ( $ columns ) ;
$ columns . = ')' ;
2014-07-25 15:15:24 +02:00
# No columns
2013-03-01 15:27:52 +01:00
if ( $ columns eq '()' ) {
return ;
}
2014-07-25 15:15:24 +02:00
2013-03-01 15:27:52 +01:00
# Add placeholders for the values
$ columns . = ' VALUES (' . ( "?," x ( $# values + 1 ) ) ;
2014-07-25 15:15:24 +02:00
2013-03-01 15:27:52 +01:00
# Remove the last , and close the parentheses
chop ( $ columns ) ;
$ columns . = ')' ;
2014-07-25 15:15:24 +02:00
2013-03-01 15:27:52 +01:00
return ( $ columns , \ @ values ) ;
}
2013-05-07 17:38:11 +02:00
########################################################################
## Try to obtain the given lock.
########################################################################
sub db_get_lock ($$;$) {
my ( $ dbh , $ lock_name , $ lock_timeout ) = @ _ ;
2015-07-22 15:36:46 +02:00
# Only supported in MySQL.
return 1 unless ( $ RDBMS eq 'mysql' ) ;
2013-05-07 17:38:11 +02:00
# Set a default lock timeout of 1 second
$ lock_timeout = 1 if ( ! defined ( $ lock_timeout ) ) ;
# Attempt to get the lock!
my $ sth = $ dbh - > prepare ( 'SELECT GET_LOCK(?, ?)' ) ;
$ sth - > execute ( $ lock_name , $ lock_timeout ) ;
my ( $ lock ) = $ sth - > fetchrow ;
2014-07-25 15:15:24 +02:00
2013-05-07 17:38:11 +02:00
# Something went wrong
return 0 if ( ! defined ( $ lock ) ) ;
return $ lock ;
}
########################################################################
## Release the given lock.
########################################################################
sub db_release_lock ($$) {
my ( $ dbh , $ lock_name ) = @ _ ;
2015-07-22 15:36:46 +02:00
# Only supported in MySQL.
return unless ( $ RDBMS eq 'mysql' ) ;
2013-05-07 17:38:11 +02:00
my $ sth = $ dbh - > prepare ( 'SELECT RELEASE_LOCK(?)' ) ;
$ sth - > execute ( $ lock_name ) ;
my ( $ lock ) = $ sth - > fetchrow ;
}
2007-08-02 19:53:07 +02:00
# End of function declaration
# End of defined Code
1 ;
__END__