diff --git a/pandora_console/install.php b/pandora_console/install.php deleted file mode 100644 index 336ee13671..0000000000 --- a/pandora_console/install.php +++ /dev/null @@ -1,1348 +0,0 @@ - - - - - Pandora FMS - Installation Wizard - - - - - - - - - - - - - - - - - - -
- -
- - - -'; - echo " $label "; - echo ''; - if (!extension_loaded($ext)) { - echo "incomplete"; - return 1; - } else { - echo "checked"; - return 0; - } - - echo ''; -} - -/** - * Check if file exist and print a - * new row in the table with the result - * - * @param string $file File. - * @param string $label Label file. - * - * @return integer status - */ -function check_exists($file, $label) -{ - echo ''; - echo " $label "; - echo ''; - if (!file_exists($file)) { - echo " incomplete"; - return 1; - } else { - echo " checked"; - return 0; - } - - echo ''; -} - - -/** - * Check variable ok and return row - * with 'checked' if is 1 or 'incomplete' if is 0 - * - * @param integer $ok Status. - * @param string $label Label to show. - * - * @return integer status - */ -function check_generic($ok, $label) -{ - echo ''; - if ($ok == 0) { - echo " $label "; - echo ''; - echo " incomplete"; - echo ''; - echo ''; - return 1; - } else { - echo " $label "; - echo ''; - echo " checked"; - echo ''; - echo ''; - return 0; - } -} - - -/** - * Check if path is writable and print a - * new row in the table with the result. - * - * @param string $fullpath Path folder or file. - * @param string $label Label to show. - * - * @return integer status - */ -function check_writable($fullpath, $label) -{ - echo ''; - if (file_exists($fullpath)) { - if (is_writable($fullpath)) { - echo " $label "; - echo ''; - echo ''; - echo "checked"; - echo ''; - echo ''; - return 0; - } else { - echo " $label "; - echo ''; - echo ''; - echo "incomplete"; - echo ''; - echo ''; - return 1; - } - } else { - echo " $label "; - echo ''; - echo "incomplete"; - echo ''; - echo ''; - return 1; - } -} - - -/** - * Check if $var is equal to $value and - * print result in a row. - * - * @param string $var Variable. - * @param string $value Value to check. - * @param string $label Label to show. - * @param integer $mode Mode. - * - * @return integer status - */ -function check_variable($var, $value, $label, $mode) -{ - echo ''; - echo " $label "; - echo ''; - if ($mode == 1) { - if ($var >= $value) { - echo "checked"; - return 0; - } else { - echo "incomplete"; - return 1; - } - } else if ($var == $value) { - echo "checked"; - return 0; - } else { - echo "incomplete"; - return 1; - } - - echo ''; -} - - -function parse_mysql_dump($url) -{ - if (file_exists($url)) { - $file_content = file($url); - $query = ''; - foreach ($file_content as $sql_line) { - if (trim($sql_line) != '' && strpos($sql_line, '-- ') === false) { - $query .= $sql_line; - if (preg_match("/;[\040]*\$/", $sql_line)) { - if (!$result = mysql_query($query)) { - echo mysql_error(); - // Uncomment for debug - echo "
$query
"; - return 0; - } - - $query = ''; - } - } - } - - return 1; - } else { - return 0; - } -} - - -/** - * Parse sql to script dump, execute it - * and return if exist error. - * - * @param object $connection Connection sql. - * @param string $url Path file sql script. - * - * @return integer status - */ -function parse_mysqli_dump($connection, $url) -{ - if (file_exists($url)) { - $file_content = file($url); - $query = ''; - foreach ($file_content as $sql_line) { - if (trim($sql_line) != '' && strpos($sql_line, '-- ') === false) { - $query .= $sql_line; - if (preg_match("/;[\040]*\$/", $sql_line)) { - if (!$result = mysqli_query($connection, $query)) { - if (mysqli_error($connection)) { - return mysqli_error($connection).'
'.$query.'
'; - } - - return 0; - } - - $query = ''; - } - } - } - - return 1; - } else { - return 0; - } -} - - -/** - * Generate a random password - * - * Admits a huge mount of ASCII chars. - * - * @param integer $size Size of the password returned. - * - * @return string $output - */ -function random_name(int $size) -{ - $output = ''; - - // Range pair of ASCII position for allow A-Z, a-z, 0-9 and special chars. - $rangeSeed = [ - '48:57', - '65:90', - '97:122', - '40:47', - ]; - - // Size of the password must be over range seed count. - $size = ($size >= count($rangeSeed)) ? $size : count($rangeSeed); - - $auxIndex = 0; - for ($i = 0; $i < $size; $i++) { - $tmpSeedValues = explode(':', $rangeSeed[$auxIndex]); - $output = $output.chr(rand($tmpSeedValues[1], $tmpSeedValues[0])); - $auxIndex++; - if ($auxIndex >= 4) { - $auxIndex = 0; - } - } - - // Remix the string for strong the password. - return str_shuffle($output); -} - - -/** - * Print the header installation - * - * @param integer $step Number of step. - * - * @return string Html output. - */ -function print_logo_status($step) -{ - global $banner; - - $header = ' -
-

Pandora FMS OpenSource Installer - '.$banner.' -

-
- 1 -
- 2 -
- 3 -
- 4 -
- 5 -
- 6 - -
-
- '; - - return $header; -} - - -/** - * This function adjusts path settings in pandora db for FreeBSD. - * All packages and configuration files except operating system's base files - * are installed under /usr/local in FreeBSD. So, path settings in pandora db - * for some programs should be changed from the Linux default. - * - * @param string $engine Type of engine. - * @param object $connection Connection database. - * - * @return integer Status. - */ -function adjust_paths_for_freebsd($engine, $connection=false) -{ - $adjust_sql = [ - "update trecon_script set script = REPLACE(script,'/usr/share','/usr/local/share');", - "update tconfig set value = REPLACE(value,'/usr/bin','/usr/local/bin') where token='netflow_daemon' OR token='netflow_nfdump' OR token='netflow_nfexpire';", - "update talert_commands set command = REPLACE(command,'/usr/bin','/usr/local/bin');", - "update talert_commands set command = REPLACE(command,'/usr/share', '/usr/local/share');", - "update tplugin set execute = REPLACE(execute,'/usr/share','/usr/local/share');", - "update tevent_response set target = REPLACE(target,'/usr/share','/usr/local/share');", - "insert into tconfig (token, value) VALUES ('graphviz_bin_dir', '/usr/local/bin');", - ]; - - for ($i = 0; $i < count($adjust_sql); $i++) { - switch ($engine) { - case 'mysql': - $result = mysql_query($adjust_sql[$i]); - break; - - case 'mysqli': - $result = mysqli_query($connection, $adjust_sql[$i]); - break; - - case 'oracle': - // Delete the last semicolon from current query - $query = substr($adjust_sql[$i], 0, (strlen($adjust_sql[$i]) - 1)); - $sql = oci_parse($connection, $query); - $result = oci_execute($sql); - break; - - case 'pgsql': - pg_send_query($connection, $adjust_sql[$i]); - $result = pg_get_result($connection); - break; - } - - if (!$result) { - return 0; - } - } - - return 1; -} - - -/** - * Print all step 1 - * - * @return void - */ -function install_step1() -{ - echo " -
-
- ".print_logo_status(1, 6)." -
-
-
-

Welcome to Pandora FMS installation Wizard

-

This wizard helps you to quick install Pandora FMS console and main database in your system. - In four steps, this installer will check all dependencies and will create your configuration, ready to use.

-

For more information, please refer to documentation →

- "; - if (file_exists('include/config.php')) { - echo "
You already have a config.php file. - Configuration and database would be overwritten if you continued.
"; - } - - echo '
'; - echo ''; - $writable = check_writable('include', './include is writable'); - if (file_exists('include/config.php')) { - $writable += check_writable('include/config.php', 'include/config.php is writable'); - } - - echo '
'; - - echo "
This installer will overwrite and destroy - your existing Pandora FMS configuration and Database. Before continue, - please be sure that you have no valuable Pandora FMS data in your Database.
-
"; - - if ($writable !== 0) { - echo "
You need to setup permissions to be able to write in ./include directory
"; - } - - echo '
'; - - echo "
"; - echo " -
-
-
-
-
-
-
-
-
-
-
-
-
-
'; -} - - -/** - * Print license content - * - * @return void - */ -function install_step1_licence() -{ - echo " -
-
- ".print_logo_status(2, 6)." -
-

GPL2 Licence terms agreement

-

Pandora FMS is an OpenSource software project licensed under the GPL2 licence. Pandora FMS includes, as well, another software also licensed under LGPL and BSD licenses. Before continue, you must accept the licence terms.. -

For more information, please refer to our website at https://pandorafms.com/community/ and contact us if you have any kind of question about the usage of Pandora FMS

-

If you dont accept the licence terms, please, close your browser and delete Pandora FMS files.

- "; - - if (!file_exists('COPYING')) { - echo "
Licence file 'COPYING' is not present in your distribution. This means you have some 'partial' Pandora FMS distribution. We cannot continue without accepting the licence file."; - echo '
'; - } else { - echo "'; - echo '

'; - } - - echo '

'; - - echo "
-
-
'; -} - - -/** - * Print all step 2 - * - * @return void - */ -function install_step2() -{ - echo " -
-
- ".print_logo_status(3, 6)." -
"; - echo '

Checking software dependencies

'; - echo ' -
-
- '; - $res = 0; - $res += check_variable(phpversion(), '7.0', 'PHP version >= 7.0', 1); - $res += check_extension('gd', 'PHP GD extension'); - $res += check_extension('ldap', 'PHP LDAP extension'); - $res += check_extension('snmp', 'PHP SNMP extension'); - $res += check_extension('session', 'PHP session extension'); - $res += check_extension('gettext', 'PHP gettext extension'); - $res += check_extension('mbstring', 'PHP Multibyte String'); - $res += check_extension('zip', 'PHP Zip'); - $res += check_extension('zlib', 'PHP Zlib extension'); - $res += check_extension('json', 'PHP json extension'); - $res += check_extension('curl', 'CURL (Client URL Library)'); - $res += check_extension('filter', 'PHP filter extension'); - $res += check_extension('calendar', 'PHP calendar extension'); - if (PHP_OS == 'FreeBSD') { - $res += check_exists('/usr/local/bin/twopi', 'Graphviz Binary'); - } else if (PHP_OS == 'NetBSD') { - $res += check_exists('/usr/pkg/bin/twopi', 'Graphviz Binary'); - } else if (substr(PHP_OS, 0, 3) == 'WIN') { - $res += check_exists("..\\..\\..\\Graphviz\\bin\\twopi.exe", 'Graphviz Binary'); - } else { - $res += check_exists('/usr/bin/twopi', 'Graphviz Binary'); - } - - echo ''; - check_extension('mysqli', 'PHP MySQL(mysqli) extension'); - echo '
'; - echo "DB Engines"; - echo ''; - echo '
'; - if ($res > 0) { - echo "
-
You have some incomplete - dependencies. Please correct them or this installer - will not be able to finish your installation. -
-
- Remember, if you install any PHP module to comply - with these dependences, you need to restart - your HTTP/Apache server after it to use the new - modules. -
-
"; - } - - echo '
'; - echo "
-
-
'; -} - - -/** - * Print all step 3 - * - * @return void - */ -function install_step3() -{ - $options = []; - if (extension_loaded('mysql')) { - $options['mysql'] = 'MySQL'; - } - - if (extension_loaded('mysqli')) { - $options['mysqli'] = 'MySQL(mysqli)'; - } - - $error = false; - if (empty($options)) { - $error = true; - } - - echo " -
-
- ".print_logo_status(4, 6)." -
-
-
-

Environment and database setup

-

- This wizard will create your Pandora FMS database, - and populate it with all the data needed to run for the first time. -

-

- You need a privileged user to create database schema, this is usually root user. - Information about root user will not be used or stored anymore. -

-

- You can also deploy the scheme into an existing Database. - In this case you need a privileged Database user and password of that instance. -

-

- Now, please, complete all details to configure your database and environment setup. -

-
- This installer will overwrite and destroy your existing - Pandora FMS configuration and Database. Before continue, - please be sure that you have no valuable Pandora FMS data in your Database. -

-
"; - if ($error) { - echo "
- You haven't a any DB engine with PHP. Please check the previous step to DB engine dependencies. -
"; - } - - if (extension_loaded('oci8')) { - echo "
For Oracle installation an existing Database with a privileged user is needed.
"; - } - - echo '
'; - echo '
'; - if (!$error) { - echo "
"; - } - - echo ""; - - if (!$error) { - echo ' - - - - - - - "; - - // the field dbgrant is only shown when the DB host is different from 127.0.0.1 or localhost - echo " - - "; - - echo " - - "; - echo " - - - "; - - echo " - - "; - - echo '
'; - echo '

DB Engine

'; - - echo ''; - - echo ''; - - echo '
'; - echo '

Installation in

'; - - echo ''; - - echo ''; - } - - echo "
-

DB User with privileges

- -
-

DB Password for this user

- -
-

DB Hostname

- -
-

DB Name (pandora by default)

- -
-

Full path to HTTP publication directory

-

For example /var/www/pandora_console/

- -
-

URL path to Pandora FMS Console

-

For example '/pandora_console'

- -
- -

Drop Database if exists

-
'; - - echo '
'; - - echo '
'; - echo '
'; - echo "
- '; -} - - -/** - * Print all step 4 - * - * @return void - */ -function install_step4() -{ - $pandora_config = 'include/config.php'; - - if ((! isset($_POST['user'])) || (! isset($_POST['dbname'])) || (! isset($_POST['host'])) - || (! isset($_POST['pass'])) || (!isset($_POST['engine'])) || (! isset($_POST['db_action'])) - ) { - $dbpassword = ''; - $dbuser = ''; - $dbhost = ''; - $dbname = ''; - $engine = ''; - $dbaction = ''; - $dbgrant = ''; - } else { - $engine = $_POST['engine']; - $dbpassword = $_POST['pass']; - $dbuser = $_POST['user']; - $dbhost = $_POST['host']; - $dbaction = $_POST['db_action']; - if (isset($_POST['dbgrant']) && $_POST['dbgrant'] != '') { - $dbgrant = $_POST['dbgrant']; - } else { - $dbgrant = $_SERVER['SERVER_ADDR']; - } - - if (isset($_POST['drop'])) { - $dbdrop = $_POST['drop']; - } else { - $dbdrop = 0; - } - - $dbname = $_POST['dbname']; - if (isset($_POST['url'])) { - $url = $_POST['url']; - } else { - $url = 'http://localhost'; - } - - if (isset($_POST['path'])) { - $path = $_POST['path']; - $path = str_replace('\\', '/', $path); - // Windows compatibility - } else { - $path = '/var/www'; - } - } - - $everything_ok = 0; - $step1 = 0; - $step2 = 0; - $step3 = 0; - $step4 = 0; - $step5 = 0; - $step6 = 0; - $step7 = 0; - $errors = []; - echo " -
-
- ".print_logo_status(5, 6)." -
-
-
- "; - switch ($engine) { - case 'mysql': - if (! mysql_connect($dbhost, $dbuser, $dbpassword)) { - check_generic(0, 'Connection with Database'); - } else { - check_generic(1, 'Connection with Database'); - - // Drop database if needed and don't want to install over an existing DB - if ($dbdrop == 1) { - mysql_query("DROP DATABASE IF EXISTS `$dbname`"); - } - - // Create schema - if ($dbaction == 'db_new' || $dbdrop == 1) { - $step1 = mysql_query("CREATE DATABASE `$dbname`"); - check_generic($step1, "Creating database '$dbname'"); - } else { - $step1 = 1; - } - - if ($step1 == 1) { - $step2 = mysql_select_db($dbname); - check_generic($step2, "Opening database '$dbname'"); - - $step3 = parse_mysql_dump('pandoradb.sql'); - - if ($step3 !== 0 && $step3 !== 1) { - $errors[] = $step3; - $step3 = 0; - } - - check_generic($step3, 'Creating schema'); - $step4 = parse_mysql_dump('pandoradb_data.sql'); - - if ($step4 !== 0 && $step4 !== 1) { - $errors[] = $step4; - $step4 = 0; - } - - check_generic($step4, 'Populating database'); - if (PHP_OS == 'FreeBSD') { - $step_freebsd = adjust_paths_for_freebsd($engine); - check_generic($step_freebsd, 'Adjusting paths in database for FreeBSD'); - } - - $random_password = random_name(8); - $host = $dbhost; - // set default granted origin to the origin of the queries - if (($dbhost != 'localhost') && ($dbhost != '127.0.0.1')) { - $host = $dbgrant; - // if the granted origin is different from local machine, set the valid origin - } - - $step5 = mysql_query( - "GRANT ALL PRIVILEGES ON `$dbname`.* to pandora@$host - IDENTIFIED BY '".$random_password."'" - ); - mysql_query('FLUSH PRIVILEGES'); - check_generic($step5, "Established privileges for user pandora. A new random password has been generated: $random_password

Please write it down, you will need to setup your Pandora FMS server, editing the /etc/pandora/pandora_server.conf file

"); - - $step6 = is_writable('include'); - check_generic($step6, "Write permissions to save config file in './include'"); - - $cfgin = fopen('include/config.inc.php', 'r'); - $cfgout = fopen($pandora_config, 'w'); - $config_contents = fread($cfgin, filesize('include/config.inc.php')); - $dbtype = 'mysql'; - $config_new = ''; - $step7 = fputs($cfgout, $config_new); - $step7 = ($step7 + fputs($cfgout, $config_contents)); - if ($step7 > 0) { - $step7 = 1; - } - - fclose($cfgin); - fclose($cfgout); - chmod($pandora_config, 0600); - check_generic($step7, "Created new config file at '".$pandora_config."'"); - } - } - - if (($step7 + $step6 + $step5 + $step4 + $step3 + $step2 + $step1) == 7) { - $everything_ok = 1; - } - break; - - case 'mysqli': - $connection = mysqli_connect($dbhost, $dbuser, $dbpassword); - if (mysqli_connect_error() > 0) { - check_generic(0, 'Connection with Database'); - } else { - check_generic(1, 'Connection with Database'); - - // Drop database if needed and don't want to install over an existing DB - if ($dbdrop == 1) { - mysqli_query($connection, "DROP DATABASE IF EXISTS `$dbname`"); - } - - // Create schema - if ($dbaction == 'db_new' || $dbdrop == 1) { - $step1 = mysqli_query($connection, "CREATE DATABASE `$dbname`"); - check_generic($step1, "Creating database '$dbname'"); - } else { - $step1 = 1; - } - - if ($step1 == 1) { - $step2 = mysqli_select_db($connection, $dbname); - check_generic($step2, "Opening database '$dbname'"); - - $step3 = parse_mysqli_dump($connection, 'pandoradb.sql'); - if ($step3 !== 0 && $step3 !== 1) { - $errors[] = $step3; - $step3 = 0; - } - - check_generic($step3, 'Creating schema'); - - $step4 = parse_mysqli_dump($connection, 'pandoradb_data.sql'); - - if ($step4 !== 0 && $step4 !== 1) { - $errors[] = $step4; - $step4 = 0; - } - - check_generic($step4, 'Populating database'); - if (PHP_OS == 'FreeBSD') { - $step_freebsd = adjust_paths_for_freebsd($engine, $connection); - check_generic($step_freebsd, 'Adjusting paths in database for FreeBSD'); - } - - $random_password = random_name(8); - $host = $dbhost; - // set default granted origin to the origin of the queries - if (($dbhost != 'localhost') && ($dbhost != '127.0.0.1')) { - $host = $dbgrant; - // if the granted origin is different from local machine, set the valid origin - } - - $step5 = mysqli_query( - $connection, - "CREATE USER IF NOT EXISTS pandora@$host" - ); - - mysqli_query( - $connection, - "SET PASSWORD FOR 'pandora'@'".$host."' = '".$random_password."'" - ); - - $step5 |= mysqli_query( - $connection, - "GRANT ALL PRIVILEGES ON `$dbname`.* to pandora@$host" - ); - mysqli_query($connection, 'FLUSH PRIVILEGES'); - check_generic($step5, "Established privileges for user pandora. A new random password has been generated: $random_password

Please write it down, you will need to setup your Pandora FMS server, editing the /etc/pandora/pandora_server.conf file

"); - - $step6 = is_writable('include'); - check_generic($step6, "Write permissions to save config file in './include'"); - - $cfgin = fopen('include/config.inc.php', 'r'); - $cfgout = fopen($pandora_config, 'w'); - $config_contents = fread($cfgin, filesize('include/config.inc.php')); - $dbtype = 'mysql'; - $config_new = ''; - $step7 = fputs($cfgout, $config_new); - $step7 = ($step7 + fputs($cfgout, $config_contents)); - if ($step7 > 0) { - $step7 = 1; - } - - fclose($cfgin); - fclose($cfgout); - chmod($pandora_config, 0600); - check_generic($step7, "Created new config file at '".$pandora_config."'"); - } - } - - if (($step7 + $step6 + $step5 + $step4 + $step3 + $step2 + $step1) == 7) { - $everything_ok = 1; - } - break; - } - - echo '
'; - echo '
'; - echo '
'; - echo "

Creating database and default configuration file

"; - if ($everything_ok !== 1) { - $info = ''; - - if (!empty($errors)) { - foreach ($errors as $key => $err) { - $info .= '
'.$err.'
'; - } - - $info .= "
If you use MySQL 8 make sure to include the - following parameter in your installation's my.cnf configuration file
- sql_mode=\"\"
"; - } - - $info .= "
There were some problems. - Installation was not completed. -

Please correct failures before trying again. - All database "; - - if ($engine == 'oracle') { - $info .= 'objects '; - } else { - $info .= 'schemes '; - } - - $info .= 'created in this step have been dropped.

-
'; - echo $info; - - switch ($engine) { - case 'mysql': - if (mysql_error() != '') { - echo "
".mysql_error().'.
'; - echo "
If you use MySQL 8 make sure to include the - following parameter in your installation's my.cnf configuration file
- sql_mode=\"\"
"; - } - - if ($step1 == 1) { - mysql_query("DROP DATABASE $dbname"); - } - break; - - case 'mysqli': - if ($connection && mysqli_error($connection) != '') { - echo "
".mysqli_error($connection).'.
'; - echo "
If you use MySQL 8 make sure to include the - following parameter in your installation's my.cnf configuration file
- sql_mode=\"\"
"; - } - - if ($step1 == 1) { - mysqli_query($connection, "DROP DATABASE $dbname"); - } - break; - } - } - - echo '
'; - echo '
'; - echo '
'; - echo " -
-
'; -} - - -/** - * Print all step 5 - * - * @return void - */ -function install_step5() -{ - echo " -
-
- ".print_logo_status(6, 6)." -
-

Installation complete

-

For security, you now must manually delete this installer - ('install.php') file before trying to access to your Pandora FMS console. -

You should also install Pandora FMS Servers before trying to monitor anything; - please read documentation on how to install it.

-

Default user is 'admin' with password 'pandora', - please change it both as soon as possible.

-

Don't forget to check https://pandorafms.com - for updates. -

Select if you want to rename 'install.php'.

-
- - -
-

-
-
-
- -
-
"; -} diff --git a/pandora_server/util/load/README.MD b/pandora_server/util/load/README.MD index d042cb1503..c7556e3a07 100644 --- a/pandora_server/util/load/README.MD +++ b/pandora_server/util/load/README.MD @@ -1,7 +1,38 @@ -### Purpose of this toolkit +## Purpose of this toolkit This directory contains configuration files and small scripts to generate an environment with simulated data for testing purposes. +### Quik start +To add monitoring data, inventory, groups and users to a pandorafms environment automatically Just execute: +``` +/usr/share/pandora_server/util/load/install_load_data.sh +``` + +This command will creates: +- 30 Agents with inventory linux +- 30 Agents whith inventory Windows +- 300 Agents +- 44 Groups +- 34 Users + +Will randonly add users to groups and move agents to groups. +Creates a cronjob to generate agent data each 5 min and inventory data once a day. + +_note: make sure you have a licence with at least 300 agents or modify the /usr/share/pandora_server/util/load/pandora_xml_stress.agents to use max your licence limit agent amount before execute_ + +## Toolset description. +Here we describe the specific use for all the toolset the `install_load_data.sh` used automatically, to be used individualy if its needed + +### Generation of inventory agents +The script will use th file pandora_xml_stress.agents take by default the first 30 listed agents and add linux inventory and the last 30 listed agents and add windows inventory. +This will generate xml data using the templates on `templates` folder. + +to run it, execute +``` +cd pandorafms/pandora_server/util/load +./generate_inventory_data.sh +``` + ### Generation of XML files to simulate agent load There is a tool that comes configured with Pandora FMS to generate test data (pandora_xml_stress) and that generates XML. It has different options and in this directory is provided a configuration file and all the dictionaries and additional files to generate data of 300 agents, with pseudo-random names (like for example "7fb8a1a734c24cc22a5c75eb"). @@ -9,18 +40,18 @@ There is a tool that comes configured with Pandora FMS to generate test data (pa These agents are defined in the "pandora_xml_stress.agents" file. If you want less agents, you can delete elements in this file. To execute the XML generation manually from the code repository: - +``` cd pandorafms/pandora_server/util/load perl ../pandora_xml_stress.pl pandora_xml_stress.conf - +``` This will generate 300 XML in the /var/spool/pandora/data_in directory. If you create a scheduled execution of this command every 5 minutes (e.g. through cron), keep in mind that if the PandoraFMS server stops, it could have hundreds of thousands of XML files pending to be processed. Create /etc/cron.d/pandora_stress with this content: - +``` */5 * * * * root - +``` ### Generation of groups and users @@ -31,6 +62,7 @@ On the other hand, it will also create a series of groups, taking as source the Finally, it will take all the agents available in Pandora FMS and it will distribute them in an equal and random way among the available groups. You should only run it once: - +``` cd pandorafms/pandora_server/util/load ./create_userandgroups.sh +``` \ No newline at end of file diff --git a/pandora_server/util/load/create_usersandgroups.sh b/pandora_server/util/load/create_usersandgroups.sh old mode 100644 new mode 100755 index 36534bbf0b..418efa322d --- a/pandora_server/util/load/create_usersandgroups.sh +++ b/pandora_server/util/load/create_usersandgroups.sh @@ -35,7 +35,7 @@ done TOTAL_GROUPS=`cat groupnames.txt | wc -l` for username in `cat usernames.txt` do - RAN=`echo $RANDOM % $TOTAL_GROUPS + 1 | bc` + RAN=`echo $(($RANDOM % $TOTAL_GROUPS + 1))` GROUP_NAME=`cat groupnames.txt | tail -$RAN | head -1` /usr/share/pandora_server/util/pandora_manage.pl /etc/pandora/pandora_server.conf --add_profile $username "Operator (Read)" $GROUP_NAME @@ -45,7 +45,7 @@ done TOTAL_GROUPS=`cat groupnames.txt | wc -l` for agentname in `/usr/share/pandora_server/util/pandora_manage.pl /etc/pandora/pandora_server.conf --get_agents | cut -f 2 -d ","` do - RAN=`echo $RANDOM % $TOTAL_GROUPS + 1 | bc` + RAN=`echo $(($RANDOM % $TOTAL_GROUPS + 1))` GROUP_NAME=`cat groupnames.txt | tail -$RAN | head -1` /usr/share/pandora_server/util/pandora_manage.pl /etc/pandora/pandora_server.conf --update_agent $agentname group_name $GROUP_NAME done diff --git a/pandora_server/util/load/generate_inventory_data.sh b/pandora_server/util/load/generate_inventory_data.sh index b91ac24af7..cfd537d67e 100755 --- a/pandora_server/util/load/generate_inventory_data.sh +++ b/pandora_server/util/load/generate_inventory_data.sh @@ -11,7 +11,7 @@ linux_inventory=1 windows_inventory=1 # Variables -agent_count=5 +agent_count=30 data_in=/var/spool/pandora/data_in/ description='Demo data Agent' @@ -28,7 +28,7 @@ if [ $linux_inventory -eq 1 ] ; then echo "Enable linux invetory: adding invetory data to ${agent_count} linux agent" - for agent_name in $(cat pandora_xml_stress.agents | head ${agent_conunt}); do + for agent_name in $(cat pandora_xml_stress.agents | head -n ${agent_count}); do echo " - Adding invetory data to ${agent_name} linux agent" ip_add="10.0.0.$(( RANDOM % 255 + 1 ))" rand_number=$(( RANDOM % 10 + 1 )) @@ -50,7 +50,7 @@ if [ $windows_inventory -eq 1 ]; then fi echo "Enable Windows invetory: adding invetory data to ${agent_count} Windows agent" - for agent_name in $(cat pandora_xml_stress.agents | tail ${agent_conunt}); do + for agent_name in $(cat pandora_xml_stress.agents | tail -n ${agent_count}); do echo " - Adding invetory data to ${agent_name} windows agent" ip_add="172.16.5.$(( RANDOM % 255 + 1 ))" rand_number=$(( RANDOM % 100 + 1 )) diff --git a/pandora_server/util/load/install_load_data.sh b/pandora_server/util/load/install_load_data.sh new file mode 100755 index 0000000000..b2bcdfa18f --- /dev/null +++ b/pandora_server/util/load/install_load_data.sh @@ -0,0 +1,55 @@ +#!/bin/bash +# (c) 2023 Pandora FMS +# This script is used to install a set of tools to load data automatically +# by default it will creates a set of users, groups and agents +# then set a cronjob to insert fake monitoring data to agents each 5 min +# and inventory data once a day. + +PREFIX='' + +# Moving directory +init_dir=$(pwd) +# Get the directory where the script is located +script_dir="$(dirname "$0")" +# Change the working directory to the script's directory +cd "$script_dir" || exit 1 + +# Check needed file exists +echo ' [INFO] Checking file requirements:' +if [ -f $PREFIX/usr/share/pandora_server/util/pandora_xml_stress.pl ] && \ + [ -f $(pwd)/pandora_xml_stress.agents ] && \ + [ -f $(pwd)/pandora_xml_stress.conf ] && \ + [ -f $(pwd)/create_usersandgroups.sh ] && \ + [ -f $(pwd)/generate_inventory_data.sh ] && \ + [ -f $(pwd)/templates/inventory_linux.template ] && \ + [ -f $(pwd)/templates/inventory_windows.template] && \ + [ -f $(pwd)/pandora_xml_stress_module_source.txt ]; then + echo ' [INFO] All file exist, continue' +else + echo ' [ERROR] Missing files, please check.' && exit -1 +fi +# Create a set of users and grups +echo ' [INFO] Creating demo users and groups:' +$(pwd)/generate_inventory_data.sh +echo ' [INFO] Waiting for inventory agents to be created:' +while [ $(ls $PREFIX/var/spool/pandora/data_in/ | wc -l) -ge 10 ]; do + sleep 2 + echo -ne . +done +# Load init monitoring data +echo ' [INFO] Creating demo agent data:' +perl $PREFIX/usr/share/pandora_server/util/pandora_xml_stress.pl $(pwd)/pandora_xml_stress.conf || echo ' [ERROR] Generating agent data cant be completed' +echo ' [INFO] Waiting for agents to be created:' +while [ $(ls $PREFIX/var/spool/pandora/data_in/ | wc -l) -ge 10 ]; do + sleep 2 + echo -ne . +done +# Create a set of users and grups +echo ' [INFO] Creating demo users and groups:' +$(pwd)/create_usersandgroups.sh +# Set cronjobs in /etc/crotab +echo ' [INFO] Adding data and inventory data to cronjob' +echo "*/5 * * * * root cd $(pwd) && perl $PREFIX/usr/share/pandora_server/util/pandora_xml_stress.pl $(pwd)/pandora_xml_stress.conf " >> /etc/crontab +echo "0 0 * * * root cd $(pwd) && $(pwd)/generate_inventory_data.sh" >> /etc/crontab +# Get back init directory +cd $init_dir \ No newline at end of file diff --git a/pandora_server/util/load/pandora_xml_stress.log b/pandora_server/util/load/pandora_xml_stress.log new file mode 100644 index 0000000000..35a677d1a6 --- /dev/null +++ b/pandora_server/util/load/pandora_xml_stress.log @@ -0,0 +1,24 @@ +[1692774345] Generating XML data files for 300 agents from 2023-08-23 09:05:45 to 2023-08-23 09:05:45 interval 300. +[1692774345] Total agents: 300 + Total modules: 3600 (12 per agent) + Total XML: 300 (6964 per second) +[1692774481] Generating XML data files for 300 agents from 2023-08-23 09:08:01 to 2023-08-23 09:08:01 interval 300. +[1692774481] Total agents: 300 + Total modules: 3600 (12 per agent) + Total XML: 300 (6996 per second) +[1692775236] Generating XML data files for 300 agents from 2023-08-23 09:20:36 to 2023-08-23 09:20:36 interval 300. +[1692775236] Total agents: 300 + Total modules: 3600 (12 per agent) + Total XML: 300 (7036 per second) +[1692775282] Generating XML data files for 300 agents from 2023-08-23 09:21:22 to 2023-08-23 09:21:22 interval 300. +[1692775282] Total agents: 300 + Total modules: 3600 (12 per agent) + Total XML: 300 (6935 per second) +[1692775320] Generating XML data files for 300 agents from 2023-08-23 09:22:00 to 2023-08-23 09:22:00 interval 300. +[1692775320] Total agents: 300 + Total modules: 3600 (12 per agent) + Total XML: 300 (6921 per second) +[1692775629] Generating XML data files for 300 agents from 2023-08-23 09:27:09 to 2023-08-23 09:27:09 interval 300. +[1692775629] Total agents: 300 + Total modules: 3600 (12 per agent) + Total XML: 300 (6927 per second) diff --git a/tentacle/tentacle_client b/tentacle/tentacle_client index ecc2da18bb..d90d21f344 100755 --- a/tentacle/tentacle_client +++ b/tentacle/tentacle_client @@ -1095,7 +1095,7 @@ Protocol description and more info at: L<< https://pandorafms.com/manual/en/docu =head1 COPYRIGHT -Copyright (c) 2005-2023 Pandora FMS. +Copyright (c) 2005-2010 Artica Soluciones Tecnologicas S.L =cut