From cea110e2092cb6af96cfd501f335173005241a84 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Wed, 2 Feb 2022 13:37:45 +0100 Subject: [PATCH 1/8] Alert server improved --- pandora_console/extras/mr/52.sql | 6 ++ pandora_console/pandoradb.sql | 13 ++-- pandora_server/lib/PandoraFMS/AlertServer.pm | 77 ++++++++++---------- pandora_server/lib/PandoraFMS/Core.pm | 31 ++++---- pandora_server/lib/PandoraFMS/Tools.pm | 8 +- 5 files changed, 70 insertions(+), 65 deletions(-) diff --git a/pandora_console/extras/mr/52.sql b/pandora_console/extras/mr/52.sql index bde9fd57c3..3cae8d9ce9 100644 --- a/pandora_console/extras/mr/52.sql +++ b/pandora_console/extras/mr/52.sql @@ -3,4 +3,10 @@ ALTER TABLE `tpolicy_queue` MODIFY COLUMN `progress` int(10) NOT NULL default '0 CREATE INDEX `IDX_tservice_element` ON `tservice_element`(`id_service`,`id_agente_modulo`); ALTER TABLE tevent_response ADD COLUMN display_command tinyint(1) default 0; +ALTER TABLE `talert_execution_queue` + DROP COLUMN `id_alert_template_module`, + DROP COLUMN `alert_mode`, + DROP COLUMN `extra_macros`, + MODIFY COLUMN `data` LONGTEXT; + COMMIT; \ No newline at end of file diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index 8c9618d3b3..d1c396dd3e 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -603,14 +603,11 @@ CREATE TABLE IF NOT EXISTS `talert_special_days` ( -- Table `talert_execution_queue` -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `talert_execution_queue` ( - `id` int(10) unsigned NOT NULL auto_increment, - `id_alert_template_module` int(10) unsigned NOT NULL, - `alert_mode` tinyint(1) NOT NULL, - `data` mediumtext NOT NULL, - `extra_macros` text, - `utimestamp` bigint(20) NOT NULL default '0', - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; + `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, + `data` LONGTEXT, + `utimestamp` BIGINT NOT NULL DEFAULT 0, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; -- ----------------------------------------------------- -- Table `tattachment` diff --git a/pandora_server/lib/PandoraFMS/AlertServer.pm b/pandora_server/lib/PandoraFMS/AlertServer.pm index 01cd255c64..8173ffcc7b 100644 --- a/pandora_server/lib/PandoraFMS/AlertServer.pm +++ b/pandora_server/lib/PandoraFMS/AlertServer.pm @@ -1,8 +1,8 @@ package PandoraFMS::AlertServer; -########################################################################## +################################################################################ # Pandora FMS Alert Server. # Pandora FMS. the Flexible Monitoring System. http://www.pandorafms.org -########################################################################## +################################################################################ # Copyright (c) 2005-2021 Artica Soluciones Tecnologicas S.L # # This program is free software; you can redistribute it and/or @@ -15,7 +15,7 @@ package PandoraFMS::AlertServer; # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -########################################################################## +################################################################################ use strict; use warnings; @@ -24,6 +24,7 @@ use threads; use threads::shared; use Thread::Semaphore; +use MIME::Base64; use JSON; use POSIX qw(strftime); @@ -47,9 +48,9 @@ my $AlertSem :shared; my %Alerts :shared; my $EventRef :shared = 0; -######################################################################################## +################################################################################ # Alert Server class constructor. -######################################################################################## +################################################################################ sub new ($$$) { my ($class, $config, $dbh) = @_; @@ -69,9 +70,9 @@ sub new ($$$) { return $self; } -############################################################################### +################################################################################ # Run. -############################################################################### +################################################################################ sub run ($) { my $self = shift; my $pa_config = $self->getConfig (); @@ -81,9 +82,9 @@ sub run ($) { $self->SUPER::run (\@TaskQueue, \%PendingTasks, $Sem, $TaskSem); } -############################################################################### +################################################################################ # Data producer. -############################################################################### +################################################################################ sub data_producer ($) { my $self = shift; my ($pa_config, $dbh) = ($self->getConfig (), $self->getDBH ()); @@ -120,14 +121,16 @@ sub data_producer ($) { return @tasks; } -############################################################################### +################################################################################ # Data consumer. -############################################################################### +################################################################################ sub data_consumer ($$) { my ($self, $task_id) = @_; my ($pa_config, $dbh) = ($self->getConfig (), $self->getDBH ()); eval {{ + local $SIG{__DIE__}; + # Get the alert from the queue. my $task = get_db_single_row ($dbh, 'SELECT * FROM talert_execution_queue WHERE id = ?', $task_id); if (! defined ($task)) { @@ -135,42 +138,40 @@ sub data_consumer ($$) { last 0; } - # Get the alert data. - my $alert = get_db_single_row ($dbh, 'SELECT talert_template_modules.id as id_template_module, - talert_template_modules.*, talert_templates.* - FROM talert_template_modules, talert_templates - WHERE talert_template_modules.id_alert_template = talert_templates.id - AND talert_template_modules.id = ?', $task->{'id_alert_template_module'}); - if (! defined ($alert)) { - logger($pa_config, "Alert ID " . $task->{'id_alert_template_module'} . " not found.", 10); - last; + my $args = PandoraFMS::Tools::p_decode_json( + $pa_config, + decode_base64($task->{'data'}) + ); + + if (ref $args ne "ARRAY") { + die ('Invalid alert queued'); } - # Get the agent and module associated with the alert - my $module = get_db_single_row ($dbh, 'SELECT * FROM tagente_modulo WHERE id_agente_modulo = ?', $alert->{'id_agent_module'}); - if (! defined ($module)) { - logger($pa_config, "Module ID " . $alert->{'id_agent_module'} . " not found for alert ID " . $alert->{'id_template_module'} . ".", 10); - last; - } - my $agent = get_db_single_row ($dbh, 'SELECT * FROM tagente WHERE id_agente = ?', $module->{'id_agente'}); - if (! defined ($agent)) { - logger($pa_config, "Agent ID " . $module->{'id_agente'} . " not found for module ID " . $module->{'id_agente_modulo'} . " alert ID " . $alert->{'id_template_module'} . ".", 10); - last; - } + my @args = @{$args}; - # Execute the alert. - pandora_execute_alert ($pa_config, $task->{'data'}, $agent, $module, $alert, $task->{'alert_mode'}, - $dbh, strftime ("%Y-%m-%d %H:%M:%S", localtime()), 0, decode_json($task->{'extra_macros'})); + # You cannot code a DBI object into JSON, use current. + my $execution_args = [ + $pa_config, + @args[0..4], + $dbh, + @args[5..$#args] + ]; + + # Execute. + PandoraFMS::Core::pandora_execute_alert(@$execution_args); }}; + if ($@) { + logger ($pa_config,"[ERROR] Executing alert ".$@, 0); + } # Remove the alert from the queue and unlock. db_do($dbh, 'DELETE FROM talert_execution_queue WHERE id=?', $task_id); alert_unlock($pa_config, $task_id); } -########################################################################## +################################################################################ # Get a lock on the given alert. Return 1 on success, 0 otherwise. -########################################################################## +################################################################################ sub alert_lock { my ($pa_config, $alert, $locked_alerts) = @_; @@ -186,9 +187,9 @@ sub alert_lock { return 1; } -########################################################################## +################################################################################ # Remove the lock on the given alert. -########################################################################## +################################################################################ sub alert_unlock { my ($pa_config, $alert) = @_; diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 3136055549..55b5f4cc3a 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -760,10 +760,12 @@ sub pandora_process_alert ($$$$$$$$;$$) { db_do($dbh, 'UPDATE talert_template_module_actions SET last_execution = 0 WHERE id_alert_template_module = ?', $id); } - if ($pa_config->{'alertserver'} == 1 && defined ($alert->{'id_template_module'})) { - pandora_queue_alert($pa_config, $dbh, $data, $alert, 0, $extra_macros); + if ($pa_config->{'alertserver'} == 1) { + pandora_queue_alert($pa_config, $dbh, [$data, $agent, $module, + $alert, 0, $timestamp, 0, $extra_macros, $is_correlated_alert]); } else { - pandora_execute_alert ($pa_config, $data, $agent, $module, $alert, 0, $dbh, $timestamp, 0, $extra_macros, $is_correlated_alert); + pandora_execute_alert ($pa_config, $data, $agent, $module, $alert, 0, $dbh, + $timestamp, 0, $extra_macros, $is_correlated_alert); } return; } @@ -804,8 +806,9 @@ sub pandora_process_alert ($$$$$$$$;$$) { last_fired = ?, internal_counter = ? ' . $new_interval . ' WHERE id = ?', $alert->{'times_fired'}, $utimestamp, $alert->{'internal_counter'}, $id); - if ($pa_config->{'alertserver'} == 1 && defined ($alert->{'id_template_module'})) { - pandora_queue_alert($pa_config, $dbh, $data, $alert, 1, $extra_macros); + if ($pa_config->{'alertserver'} == 1) { + pandora_queue_alert($pa_config, $dbh, [$data, $agent, $module, + $alert, 1, $timestamp, 0, $extra_macros, $is_correlated_alert]); } else { pandora_execute_alert ($pa_config, $data, $agent, $module, $alert, 1, $dbh, $timestamp, 0, $extra_macros, $is_correlated_alert); @@ -821,7 +824,7 @@ Execute the given alert. =cut ########################################################################## -sub pandora_execute_alert ($$$$$$$$$;$$) { +sub pandora_execute_alert { my ($pa_config, $data, $agent, $module, $alert, $alert_mode, $dbh, $timestamp, $forced_alert, $extra_macros, $is_correlated_alert) = @_; @@ -1065,17 +1068,15 @@ Queue the given alert for execution. =cut ########################################################################## -sub pandora_queue_alert ($$$$$;$) { - my ($pa_config, $dbh, $data, $alert, $alert_mode, $extra_macros) = @_; - my $json_macros = '{}'; +sub pandora_queue_alert ($$$) { + my ($pa_config, $dbh, $arguments) = @_; - eval { - local $SIG{__DIE__}; - $json_macros = encode_json($extra_macros); - }; + my $json_arguments = PandoraFMS::Tools::p_encode_json($pa_config, $arguments); - db_do ($dbh, "INSERT INTO talert_execution_queue (id_alert_template_module, data, alert_mode, extra_macros, utimestamp) - VALUES (?, ?, ?, ?, ?)", $alert->{'id_template_module'}, $data, $alert_mode, $json_macros, time()); + $json_arguments = encode_base64($json_arguments); + + db_do ($dbh, "INSERT INTO talert_execution_queue (data, utimestamp) + VALUES (?, ?)", $json_arguments, time()); } ########################################################################## diff --git a/pandora_server/lib/PandoraFMS/Tools.pm b/pandora_server/lib/PandoraFMS/Tools.pm index bcffd78034..d68f4e4050 100755 --- a/pandora_server/lib/PandoraFMS/Tools.pm +++ b/pandora_server/lib/PandoraFMS/Tools.pm @@ -1130,9 +1130,9 @@ sub enterprise_hook ($$) { my $output = eval { &$func (@args); }; # Discomment to debug. - if ($@) { - print STDERR $@; - } + #if ($@) { + # print STDERR $@; + #} # Check for errors #return undef if ($@); @@ -2640,7 +2640,7 @@ sub p_encode_json { }; if ($@){ if (defined($data)) { - logger($pa_config, 'Failed to encode data: '.$@, 5); + logger($pa_config, 'Failed to encode data: '.$@, 1); } } From 7b9790fa367c31441e3a90a3906acd14e5162329 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Wed, 2 Feb 2022 13:40:28 +0100 Subject: [PATCH 2/8] mig 6->7 alert_execution_Queue --- .../extras/pandoradb_migrate_6.0_to_7.0.mysql.sql | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql index 32c5c65123..f8ebdcc3e2 100644 --- a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql +++ b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql @@ -4120,14 +4120,11 @@ ALTER TABLE `tperfil` ADD COLUMN `network_config_management`tinyint(1) NOT NULL -- Table `talert_execution_queue` -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `talert_execution_queue` ( - `id` int(10) unsigned NOT NULL auto_increment, - `id_alert_template_module` int(10) unsigned NOT NULL, - `alert_mode` tinyint(1) NOT NULL, - `data` mediumtext NOT NULL, - `extra_macros` text, - `utimestamp` bigint(20) NOT NULL default '0', - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; + `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, + `data` LONGTEXT, + `utimestamp` BIGINT NOT NULL DEFAULT 0, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; UPDATE `tlanguage` SET `name` = 'Deutsch' WHERE `id_language` = 'de'; From 8cbd45bd0aa7b3dbe54c332046ed51da68c3384e Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Wed, 2 Feb 2022 14:02:32 +0100 Subject: [PATCH 3/8] errata in main cicd (open) --- .gitlab-ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d9f41def67..37ea97ac94 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -3,4 +3,5 @@ variables: test: script: - - docker run --rm -h pandorafms -t -v "$CI_PROJECT_DIR:/tmp/pandorafms" pandorafms/pandorafms-base /tmp/pandorafms/tests/test.sh + - docker pull pandorafms/pandorafms-base:centos7 + - docker run --rm -h pandorafms -t -v "$CI_PROJECT_DIR:/tmp/pandorafms" pandorafms/pandorafms-base:centos7 /tmp/pandorafms/tests/test.sh From 944dd2843c5385dccbb65c6d71fdb43660f3b4dd Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Wed, 2 Feb 2022 14:04:11 +0100 Subject: [PATCH 4/8] old image --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 37ea97ac94..5128200eed 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -3,5 +3,5 @@ variables: test: script: - - docker pull pandorafms/pandorafms-base:centos7 - - docker run --rm -h pandorafms -t -v "$CI_PROJECT_DIR:/tmp/pandorafms" pandorafms/pandorafms-base:centos7 /tmp/pandorafms/tests/test.sh + - docker pull pandorafms/pandorafms-base:centos6 + - docker run --rm -h pandorafms -t -v "$CI_PROJECT_DIR:/tmp/pandorafms" pandorafms/pandorafms-base:centos6 /tmp/pandorafms/tests/test.sh From 83a9c0867cb6b9e8ac28615004b395ec5c31ac68 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Wed, 2 Feb 2022 14:17:44 +0100 Subject: [PATCH 5/8] CHANGE UTF8 => UTF8MB4, isssues with old iamges --- pandora_console/pandoradb.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index d1c396dd3e..6a76d4114d 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -607,7 +607,7 @@ CREATE TABLE IF NOT EXISTS `talert_execution_queue` ( `data` LONGTEXT, `utimestamp` BIGINT NOT NULL DEFAULT 0, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; +) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- ----------------------------------------------------- -- Table `tattachment` From b3aa0a51ee4be37663dfb1613522db5237aa4df2 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Wed, 16 Feb 2022 10:20:40 +0100 Subject: [PATCH 6/8] Uptaded testing --- .gitlab-ci.yml | 21 +++++++++- tests/test.sh | 93 +++++++++++++++++++++++++++++++++++++++++++- tests/test_legacy.sh | 64 ++++++++++++++++++++++++++++++ 3 files changed, 174 insertions(+), 4 deletions(-) create mode 100755 tests/test_legacy.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5128200eed..0f2ec608b4 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,7 +1,24 @@ variables: GIT_STRATEGY: clone + REBRANDING: pandora test: script: - - docker pull pandorafms/pandorafms-base:centos6 - - docker run --rm -h pandorafms -t -v "$CI_PROJECT_DIR:/tmp/pandorafms" pandorafms/pandorafms-base:centos6 /tmp/pandorafms/tests/test.sh + - if [ ! -e $CI_PROJECT_DIR/pandora_server/bin/${REBRANDING}_server ]; then cp $CI_PROJECT_DIR/pandora_server/bin/pandora_server $CI_PROJECT_DIR/pandora_server/bin/${REBRANDING}_server ; fi + - if [ ! -e $CI_PROJECT_DIR/pandora_server/util/${REBRANDING}_ha.pl ]; then cp $CI_PROJECT_DIR/pandora_server/util/pandora_ha.pl $CI_PROJECT_DIR/pandora_server/util/${REBRANDING}_ha.pl ; fi + - if [ ! -e $CI_PROJECT_DIR/pandora_agents/unix/${REBRANDING}_agent ]; then cp $CI_PROJECT_DIR/pandora_agents/unix/pandora_agent $CI_PROJECT_DIR/pandora_agents/unix/${REBRANDING}_agent ; fi + - sed -i "s/pandora/$REBRANDING/g" $CI_PROJECT_DIR/pandora_agents/unix/${REBRANDING}_agent + - if [ ! -e $CI_PROJECT_DIR/pandora_agents/unix/${REBRANDING}_agent_exec ]; then cp $CI_PROJECT_DIR/pandora_agents/unix/pandora_agent_exec $CI_PROJECT_DIR/pandora_agents/unix/${REBRANDING}_agent_exec ; fi + - if [ ! -e $CI_PROJECT_DIR/pandora_agents/unix/${REBRANDING}_revent ]; then cp $CI_PROJECT_DIR/pandora_agents/unix/pandora_revent $CI_PROJECT_DIR/pandora_agents/unix/${REBRANDING}_revent ; fi + - if [ ! -e $CI_PROJECT_DIR/pandora_agents/unix/${REBRANDING}_agent_logrotate ]; then cp $CI_PROJECT_DIR/pandora_agents/unix/pandora_agent_logrotate $CI_PROJECT_DIR/pandora_agents/unix/${REBRANDING}_agent_logrotate ; fi + - sed -i "s/_PRODUCT_/$REBRANDING/g" $CI_PROJECT_DIR/pandora_server/Makefile.PL + - sed -i "s/TENTACLE_USER=\"pandora\"/TENTACLE_USER=\"$REBRANDING\"/g" $CI_PROJECT_DIR/pandora_server/util/tentacle_serverd + - docker run --rm -e REBRANDING="$REBRANDING" -h pandorafms -t -v "$CI_PROJECT_DIR:/tmp/pandorafms" pandorafms/pandorafms-base:rocky8.5 /tmp/pandorafms/tests/test.sh + +test_php_legacy: + stage: test + before_script: + - df -h | grep instaladores | awk '{print $NF}' |xargs umount >/dev/null 2>&1 || true + script: + - docker pull pandorafms/pandorafms-base:centos7 + - docker run --rm -h pandorafms -t -v "$CI_PROJECT_DIR:/tmp/pandorafms" pandorafms/pandorafms-base:centos7 /tmp/pandorafms/tests/test_legacy.sh diff --git a/tests/test.sh b/tests/test.sh index cffa8d1c36..926bb5ec53 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -17,9 +17,98 @@ function check { } # Start the required services. -service mysqld start && /usr/bin/mysqladmin -u root password 'pandora' +rm -rf /var/lib/mysql/* && sudo -u mysql mysqld --initialize-insecure && mysqld --user=mysql --sql-mode="" --daemonize=ON && /usr/bin/mysqladmin -u root password 'pandora' check "Starting the MySQL Server" $? -service httpd start + +# PHP FPM +# Customize php.ini +echo "php_value[error_reporting] = E_ALL & ~E_DEPRECATED & ~E_NOTICE & ~E_USER_WARNING" >> /etc/php-fpm.d/www.conf +echo "php_value[max_execution_time] = 0" >> /etc/php-fpm.d/www.conf +echo "php_value[max_input_time] = -1" >> /etc/php-fpm.d/www.conf +echo "php_value[upload_max_filesize] = 800M" >> /etc/php-fpm.d/www.conf +echo "php_value[post_max_size] = 800M" >> /etc/php-fpm.d/www.conf +echo "php_value[memory_limit] = -1" >> /etc/php-fpm.d/www.conf + +# Customize php handling. +cat </etc/httpd/conf.d/php.conf +# +# The following lines prevent .user.ini files from being viewed by Web clients. +# + + + Require all denied + + + Order allow,deny + Deny from all + Satisfy All + + + +# +# Allow php to handle Multiviews +# +AddType text/html .php + +# +# Add index.php to the list of files that will be served as directory +# indexes. +# +DirectoryIndex index.php + +# mod_php options + + # + # Cause the PHP interpreter to handle files with a .php extension. + # + + SetHandler application/x-httpd-php + + + # + # Uncomment the following lines to allow PHP to pretty-print .phps + # files as PHP source code: + # + # + # SetHandler application/x-httpd-php-source + # + + # + # Apache specific PHP configuration options + # those can be override in each configured vhost + # + php_value session.save_handler "files" + php_value session.save_path "/var/lib/php/session" + php_value soap.wsdl_cache_dir "/var/lib/php/wsdlcache" + + #php_value opcache.file_cache "/var/lib/php/opcache" + + +# Redirect to local php-fpm if mod_php (5 or 7) is not available + + + + # Enable http authorization headers + SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=$1 + + ProxySet timeout=1200 + + + + SetHandler "proxy:fcgi://localhost" + + + + + + +EO_F + +mkdir -p /run/php-fpm/ 2>/dev/null +/usr/sbin/php-fpm +check "Starting PHP-FPM" $? + +httpd check "Starting the Apache Web Server" $? # Install the Pandora FMS Console. diff --git a/tests/test_legacy.sh b/tests/test_legacy.sh new file mode 100755 index 0000000000..7770622fe2 --- /dev/null +++ b/tests/test_legacy.sh @@ -0,0 +1,64 @@ +#!/bin/bash +SOURCE_DIR="/tmp/pandorafms" + +################################################ +# Check the exit status of the last run command. +# Exits if it different from 0. +################################################ +function check { + MESSAGE=$1 + RC=$2 + if [ $RC == 0 ]; then + echo ">$MESSAGE... [OK]" + else + echo ">$MESSAGE... [ERR $RC]" + exit 1 + fi +} + +# Start the required services. +rm -rf /var/lib/mysql/* && sudo -u mysql mysqld --initialize-insecure && mysqld --user=mysql --sql-mode="" --daemonize=ON && /usr/bin/mysqladmin -u root password 'pandora' +check "Starting the MySQL Server" $? +httpd -k start +check "Starting the Apache Web Server" $? + +# Install the Pandora FMS Console. +cd /tmp/pandorafms/pandora_console && chmod +x pandora_console_install && yes | ./pandora_console_install --install +check "Installing the Pandora FMS Console" $? + +# Create the Pandora FMS database. +cd /tmp/pandorafms/tests && chmod +x install_console.py && python install_console.py +check "Creating the Pandora FMS Database" $? + +# Build and install the Pandora FMS Server. +cd /tmp/pandorafms/pandora_server && perl Makefile.PL && make # Do not run make test now. Some tests need files created by pandora_server_installer. +check "Building the Pandora FMS Server" $? +cd /tmp/pandorafms/pandora_server && chmod +x pandora_server_installer && ./pandora_server_installer --install +check "Installing the Pandora FMS Server" $? +sed -i -e 's/^dbuser.*/dbuser root/' /etc/pandora/pandora_server.conf +cd /tmp/pandorafms/pandora_server && make test +check "Running tests for the Pandora FMS Server" $? + +# Install the Pandora FMS Agent. +cd /tmp/pandorafms/pandora_agents/unix && chmod +x pandora_agent_installer && ./pandora_agent_installer --install +check "Installing the Pandora FMS Agent" $? + +# Start Pandora FMS services. +service tentacle_serverd start +check "Starting the Tentacle Server" $? +service pandora_server start +check "Starting the Pandora FMS Server" $? +service pandora_agent_daemon start +check "Starting the Pandora FMS Agent" $? + +# Disable the initial wizards. +echo "UPDATE tconfig SET value='1' WHERE token='initial_wizard'" | mysql -u root -ppandora -Dpandora +echo "UPDATE tconfig SET value='1' WHERE token='instance_registered'" | mysql -u root -ppandora -Dpandora +echo "INSERT INTO tconfig (token, value) VALUES ('skip_login_help_dialog', '1')" | mysql -u root -ppandora -Dpandora +echo "UPDATE tusuario SET middlename='1'" | mysql -u root -ppandora -Dpandora + +# Run console tests. +#cd /tmp/pandorafms/tests && chmod +x run_console_tests.py && ./run_console_tests.py +#check "Running tests for the Pandora FMS Console" $? + +exit 0 From ba7660c330f8cea4cb7b840ffb142a5d6eb712f3 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Wed, 16 Feb 2022 10:33:02 +0100 Subject: [PATCH 7/8] Uptaded testing --- tests/install_console.py | 46 ++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/tests/install_console.py b/tests/install_console.py index ca594bf17e..66d1c6de0c 100755 --- a/tests/install_console.py +++ b/tests/install_console.py @@ -1,35 +1,45 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # Script to install the Pandora FMS Console. import os +import sys from pyvirtualdisplay import Display from selenium import webdriver +from selenium.common.exceptions import NoSuchElementException # Are we running headless? if ('DISPLAY' not in os.environ): display = Display(visible=0, size=(1920, 1080)) display.start() -# Go to the installation page. browser = webdriver.Firefox(timeout=15) -browser.implicitly_wait(5) -browser.get('http://localhost/pandora_console/install.php') -assert("Pandora FMS - Installation Wizard" in browser.title) -# Accept the license agreement. -browser.find_element_by_xpath("//*[@id='step11']").click() -browser.find_element_by_xpath("//*[@id='btn_accept']").click() +try: + # Go to the installation page. + browser.implicitly_wait(5) + browser.get('http://localhost/pandora_console/install.php') + assert("Pandora FMS - Installation Wizard" in browser.title) -# Fill-in the configuration form. -browser.find_element_by_xpath("//*[@id='step3']").click() -browser.find_element_by_name("pass").send_keys("pandora") -browser.find_element_by_xpath("//*[@id='step4']").click() + # Accept the license agreement. + browser.find_element_by_xpath("//*[@id='step11']").click() + browser.find_element_by_xpath("//*[@id='btn_accept']").click() -# Complete the installation. -browser.implicitly_wait(300) # The installation is going to take a long time. -browser.find_element_by_xpath("//*[@id='step5']").click() -browser.implicitly_wait(5) -assert("Installation complete" in browser.page_source) -browser.find_element_by_name("rn_file").click() + # Fill-in the configuration form. + browser.find_element_by_xpath("//*[@id='step3']").click() + browser.find_element_by_name("pass").send_keys("pandora") + browser.find_element_by_xpath("//*[@id='step4']").click() + + # Complete the installation. + browser.implicitly_wait(900) # The installation is going to take a long time. + browser.find_element_by_xpath("//*[@id='step5']").click() + browser.implicitly_wait(5) + assert("Installation complete" in browser.page_source) + browser.find_element_by_name("rn_file").click() +except AssertionError as error: + print("Error " + str(error) + ":\n" + browser.page_source) + sys.exit(1) +except NoSuchElementException as error: + print("Error " + str(error) + ":\n" + browser.page_source) + sys.exit(1) # Clean-up browser.quit() From a6f8da46aed373ae2ed156d8c204307dfa6bc90f Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Wed, 16 Feb 2022 10:42:20 +0100 Subject: [PATCH 8/8] Uptaded testing --- .gitlab-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0f2ec608b4..ea329e2e57 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -13,6 +13,7 @@ test: - if [ ! -e $CI_PROJECT_DIR/pandora_agents/unix/${REBRANDING}_agent_logrotate ]; then cp $CI_PROJECT_DIR/pandora_agents/unix/pandora_agent_logrotate $CI_PROJECT_DIR/pandora_agents/unix/${REBRANDING}_agent_logrotate ; fi - sed -i "s/_PRODUCT_/$REBRANDING/g" $CI_PROJECT_DIR/pandora_server/Makefile.PL - sed -i "s/TENTACLE_USER=\"pandora\"/TENTACLE_USER=\"$REBRANDING\"/g" $CI_PROJECT_DIR/pandora_server/util/tentacle_serverd + - docker pull pandorafms/pandorafms-base:rocky8.5 - docker run --rm -e REBRANDING="$REBRANDING" -h pandorafms -t -v "$CI_PROJECT_DIR:/tmp/pandorafms" pandorafms/pandorafms-base:rocky8.5 /tmp/pandorafms/tests/test.sh test_php_legacy: