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 new file mode 100755 index 0000000000..cfd537d67e --- /dev/null +++ b/pandora_server/util/load/generate_inventory_data.sh @@ -0,0 +1,66 @@ +#!/bin/bash +# (c) 2023 Pandora FMS + +if [ ! -e pandora_xml_stress.agents ] +then + echo "Error, cant find pandora_xml_stress.agets file" + exit +fi + +linux_inventory=1 +windows_inventory=1 + +# Variables +agent_count=30 + +data_in=/var/spool/pandora/data_in/ +description='Demo data Agent' +group='Servers' +current_date=`date +"%Y/%m/%d %H:%M:%S"` +current_utimestamp=`date +%s` + +if [ $linux_inventory -eq 1 ] ; then + + if [ ! -e templates/inventory_linux.template ]; then + echo "Error, cant find inventory linux template" + exit + fi + + echo "Enable linux invetory: adding invetory data to ${agent_count} linux agent" + + 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 )) + cat "templates/inventory_linux.template" \ + | sed -e "s/{{description}}/${description}/g" \ + -e "s/{{group}}/${group}/g" \ + -e "s/{{agent_name}}/${agent_name}/g" \ + -e "s|{{date}}|${current_date}|g" \ + -e "s|{{ip_address}}|${ip_add}|g" \ + -e "s|{{rand_number}}|${rand_number}|g" \ + > /${data_in}/${agent_name}.${current_utimestamp}.data + done +fi + +if [ $windows_inventory -eq 1 ]; then + if [ ! -e templates/inventory_windows.template ]; then + echo "Error, cant find inventory Windows template" + exit + fi + echo "Enable Windows invetory: adding invetory data to ${agent_count} Windows agent" + + 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 )) + cat "templates/inventory_windows.template" \ + | sed -e "s/{{description}}/${description}/g" \ + -e "s/{{group}}/${group}/g" \ + -e "s/{{agent_name}}/${agent_name}/g" \ + -e "s|{{date}}|${current_date}|g" \ + -e "s|{{rand_number}}|${rand_number}|g" \ + -e "s|{{ip_address}}|${ip_add}|g" \ + > /${data_in}/${agent_name}.${current_utimestamp}.data + done +fi \ No newline at end of file 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/pandora_server/util/load/templates/inventory_linux.template b/pandora_server/util/load/templates/inventory_linux.template new file mode 100644 index 0000000000..3e1cb25627 --- /dev/null +++ b/pandora_server/util/load/templates/inventory_linux.template @@ -0,0 +1,192 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pandora_server/util/load/templates/inventory_windows.template b/pandora_server/util/load/templates/inventory_windows.template new file mode 100644 index 0000000000..127ca1dfba --- /dev/null +++ b/pandora_server/util/load/templates/inventory_windows.template @@ -0,0 +1,257 @@ + + + + + + CPU + + + + + + + + + + + HD + + + + + + + + + Video + + + + + + + + + NIC + + + + + + + + + Monitors + + + + + + + + RAM + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Users + + + + + + + + product_ID + + + + + + + + + diff --git a/tentacle/tentacle_client b/tentacle/tentacle_client index ecc2da18bb..da917863d6 100755 --- a/tentacle/tentacle_client +++ b/tentacle/tentacle_client @@ -2,7 +2,7 @@ ################################################################################ # # Copyright (c) 2007-2008 Ramon Novoa -# Copyright (c) 2007-2023 Pandora FMS. +# Copyright (c) 2007-2023 Pandora FMS. # # tentacle_client.pl Tentacle Client. See https://pandorafms.com/docs/ for # protocol description.