diff --git a/extras/deploy-scripts/pandora_agent_deploy.sh b/extras/deploy-scripts/pandora_agent_deploy.sh new file mode 100644 index 0000000000..cb58e4092b --- /dev/null +++ b/extras/deploy-scripts/pandora_agent_deploy.sh @@ -0,0 +1,168 @@ +#!/bin/bash + +#export PANDORA_SERVER_IP='newdemos.artica.es' && curl -sSL http://firefly.artica.es/projects/pandora_deploy_agent.sh | bash + +# define variables +PANDORA_AGENT_CONF=/etc/pandora/pandora_agent.conf +S_VERSION='2021012801' +LOGFILE="/tmp/pandora-agent-deploy-$(date +%F).log" + +# Ansi color code variables +red="\e[0;91m" +green="\e[0;92m" +bold="\e[1m" +cyan="\e[0;36m" +yellow="\e[0;33m" +reset="\e[0m" + +# Functions + +execute_cmd () { + local cmd="$1" + local msg="$2" + + echo -e "${cyan}$msg...${reset}" + $cmd &>> $LOGFILE + if [ $? -ne 0 ]; then + echo -e "${red}Fail${reset}" + [[ $3 ]] && echo "$3 " + echo "Error installing Pandora FMS Agent for detailed error please check log: $LOGFILE" + rm -rf $HOME/pandora_deploy_tmp &>> $LOGFILE + exit 1 + else + echo -e "\e[1A\e ${cyan}$msg...${reset} ${green}OK${reset}" + return 0 + fi +} + +check_cmd_status () { + if [ $? -ne 0 ]; then + echo -e "${red}Fail${reset}" + [ "$1" ] && echo "$1" + echo "Error installing Pandora FMS Agent for detailed error please check log: $LOGFILE" + rm -rf $HOME/pandora_deploy_tmp/*.rpm* &>> $LOGFILE + exit 1 + else + echo -e "${green}OK${reset}" + return 0 + fi +} + +check_repo_connection () { + execute_cmd "ping -c 2 8.8.8.8" "Checking internet connection" + execute_cmd "ping -c 2 firefly.artica.es" "Checking Community repo" +} + +check_root_permissions () { + echo -en "${cyan}Checking root account... ${reset}" + if [ "$(whoami)" != "root" ]; then + echo -e "${red}Fail${reset}" + echo "Please use a root account or sudo for installing PandoraFMS" + echo "Error installing Pandora FMS for detailed error please check log: $LOGFILE" + exit 1 + + else + echo -e "${green}OK${reset}" + fi +} + +install_autodiscover () { + local arch=$1 + wget https://pandorafms.com/library/wp-content/uploads/2020/04/autodiscover-linux.zip + unzip autodiscover-linux.zip + chmod +x $arch/autodiscover + mv -f $arch/autodiscover /etc/pandora/plugins/autodiscover +} + +## Main +echo "Starting PandoraFMS Agent deployment ver. $S_VERSION" + +execute_cmd "[ $PANDORA_SERVER_IP ]" 'Check Server IP Address' 'Please define env variable PANDORA_SERVER_IP' + +# Check OS. +OS=$([[ $(grep '^ID_LIKE=' /etc/os-release) ]] && grep ^ID_LIKE= /etc/os-release | cut -d '=' -f2 | tr -d '"' || grep ^ID= /etc/os-release | cut -d '=' -f2 | tr -d '"') + +[[ $OS == 'rhel fedora' ]] && OS_RELEASE=$OS +[[ $OS == 'debian' ]] && OS_RELEASE=$OS + +# initialice logfile +execute_cmd "echo 'Starting community deployment' > $LOGFILE" "All installer activity is logged on $LOGFILE" +echo "Community installer version: $S_VERSION" >> $LOGFILE + +# Pre checks +echo -en "${cyan}Checking compatible OS... ${reset}" +[[ $OS_RELEASE ]] +check_cmd_status "Error not compatible OS, $OS" + +# Root permisions +check_root_permissions + +# Connectivity +check_repo_connection + +# Execute tools check +execute_cmd "grep --version" 'Checking needed tools: grep' +execute_cmd "sed --version" 'Checking needed tools: sed' + +# Creating working directory +rm -rf $HOME/pandora_deploy_tmp/ &>> $LOGFILE +mkdir $HOME/pandora_deploy_tmp &>> $LOGFILE +execute_cmd "cd $HOME/pandora_deploy_tmp" "Moving to workspace: $HOME/pandora_deploy_tmp" + +# Downloading and installing packages + +if [[ $OS_RELEASE == 'rhel fedora' ]]; then + yum install -y perl wget curl perl-Sys-Syslog unzip &>> $LOGFILE + echo -e "${cyan}Instaling agent dependencies...${reset}" ${green}OK${reset} + + yum install -y http://firefly.artica.es/pandorafms/latest/RHEL_CentOS/pandorafms_agent_unix-7.0NG.noarch.rpm &>> $LOGFILE + echo -e "${cyan}Instaling Pandora FMS agent...${reset}" ${green}OK${reset} +fi + +if [[ $OS_RELEASE == 'debian' ]]; then + execute_cmd "apt update" 'Updating repos' + execute_cmd "apt install -y perl wget curl unzip procps python3 python3-pip" 'Instaling agent dependencies' + execute_cmd 'wget http://firefly.artica.es/pandorafms/latest/Debian_Ubuntu/pandorafms.agent_unix_7.0NG.deb' 'Downloading Pandora FMS agent dependencies' + execute_cmd 'apt install -y ./pandorafms.agent_unix_7.0NG.deb' 'Installing Pandora FMS agent' +fi + +# Configuring Agente + +[[ $PANDORA_SERVER_IP ]] && sed -i "s/^server_ip.*$/server_ip $PANDORA_SERVER_IP/g" $PANDORA_AGENT_CONF +[[ $PANDORA_REMOTE_CONFIG ]] && sed -i "s/^remote_config.*$/remote_config $PANDORA_REMOTE_CONFIG/g" $PANDORA_AGENT_CONF +[[ $PANDORA_GROUP ]] && sed -i "s/^group.*$/group $PANDORA_GROUP/g" $PANDORA_AGENT_CONF +[[ $PANDORA_DEBUG ]] && sed -i "s/^debug.*$/debug $PANDORA_DEBUG/g" $PANDORA_AGENT_CONF +[[ $PANDORA_AGENT_NAME ]] && sed -i "s/^#agent_name.*$/agent_name $PANDORA_AGENT_NAME/g" $PANDORA_AGENT_CONF +[[ $PANDORA_AGENT_ALIAS ]] && sed -i "s/^#agent_alias.*$/agent_alias $PANDORA_AGENT_ALIAS/g" $PANDORA_AGENT_CONF +[[ $PANDORA_SECONDARY_GROUPS ]] && sed -i "s/^# secondary_groups.*$/secondary_groups $PANDORA_SECONDARY_GROUPS/g" $PANDORA_AGENT_CONF +[[ $TIMEZONE ]] && ln -sfn /usr/share/zoneinfo/$TIMEZONE /etc/localtime + + +#installing autodiscover + +arch=$(uname -m) +case $arch in + + x86_64) + execute_cmd 'install_autodiscover x86_64' "installing service autodiscover on $arch" 'Error unable to install autodiscovery' + ;; + + x86) + execute_cmd 'install_autodiscover x84' "installing service autodiscover on $arch" 'Error unable to install autodiscovery' + ;; + + armv7l) + echo -e "${cyan}Skiping autodiscover installation arch $arch not suported${reset}" + ;; + + *) + echo -e "${yellow}Skiping autodiscover installation arch $arch not suported${reset}" + ;; +esac + +#Starting pandora agent daemon. +execute_cmd '/etc/init.d/pandora_agent_daemon restart' 'Starting Pandora Agent' +cd +execute_cmd 'rm -rf $HOME/pandora_deploy_tmp' 'Cleaning up temporay files' + +echo -e "${green}PandoraFMS Agent installed and running, sending data to: $PANDORA_SERVER_IP${reset}" \ No newline at end of file diff --git a/pandora_agents/unix/DEBIAN/control b/pandora_agents/unix/DEBIAN/control index 092348f5cb..e7789654f0 100644 --- a/pandora_agents/unix/DEBIAN/control +++ b/pandora_agents/unix/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-agent-unix -Version: 7.0NG.753-210415 +Version: 7.0NG.753-210419 Architecture: all Priority: optional Section: admin diff --git a/pandora_agents/unix/DEBIAN/make_deb_package.sh b/pandora_agents/unix/DEBIAN/make_deb_package.sh index f85da39764..7aa48a8295 100644 --- a/pandora_agents/unix/DEBIAN/make_deb_package.sh +++ b/pandora_agents/unix/DEBIAN/make_deb_package.sh @@ -14,7 +14,7 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -pandora_version="7.0NG.753-210415" +pandora_version="7.0NG.753-210419" echo "Test if you has the tools for to make the packages." whereis dpkg-deb | cut -d":" -f2 | grep dpkg-deb > /dev/null diff --git a/pandora_agents/unix/pandora_agent b/pandora_agents/unix/pandora_agent index 8ba4c19f8a..9d502de306 100755 --- a/pandora_agents/unix/pandora_agent +++ b/pandora_agents/unix/pandora_agent @@ -1015,7 +1015,7 @@ my $Sem = undef; my $ThreadSem = undef; use constant AGENT_VERSION => '7.0NG.753'; -use constant AGENT_BUILD => '210415'; +use constant AGENT_BUILD => '210419'; # Agent log default file size maximum and instances use constant DEFAULT_MAX_LOG_SIZE => 600000; diff --git a/pandora_agents/unix/pandora_agent.redhat.spec b/pandora_agents/unix/pandora_agent.redhat.spec index 5bb5168e74..6ac114a1da 100644 --- a/pandora_agents/unix/pandora_agent.redhat.spec +++ b/pandora_agents/unix/pandora_agent.redhat.spec @@ -3,7 +3,7 @@ # %define name pandorafms_agent_unix %define version 7.0NG.753 -%define release 210415 +%define release 210419 Summary: Pandora FMS Linux agent, PERL version Name: %{name} diff --git a/pandora_agents/unix/pandora_agent.spec b/pandora_agents/unix/pandora_agent.spec index 1bc2e0a0a1..4baacc6b6c 100644 --- a/pandora_agents/unix/pandora_agent.spec +++ b/pandora_agents/unix/pandora_agent.spec @@ -3,7 +3,7 @@ # %define name pandorafms_agent_unix %define version 7.0NG.753 -%define release 210415 +%define release 210419 Summary: Pandora FMS Linux agent, PERL version Name: %{name} diff --git a/pandora_agents/unix/pandora_agent_installer b/pandora_agents/unix/pandora_agent_installer index 240a646ac6..6c715d6c47 100755 --- a/pandora_agents/unix/pandora_agent_installer +++ b/pandora_agents/unix/pandora_agent_installer @@ -10,7 +10,7 @@ # ********************************************************************** PI_VERSION="7.0NG.753" -PI_BUILD="210415" +PI_BUILD="210419" OS_NAME=`uname -s` FORCE=0 diff --git a/pandora_agents/win32/installer/pandora.mpi b/pandora_agents/win32/installer/pandora.mpi index 43b3793fb3..822343050f 100644 --- a/pandora_agents/win32/installer/pandora.mpi +++ b/pandora_agents/win32/installer/pandora.mpi @@ -186,7 +186,7 @@ UpgradeApplicationID {} Version -{210415} +{210419} ViewReadme {Yes} diff --git a/pandora_agents/win32/pandora.cc b/pandora_agents/win32/pandora.cc index ef49d178ca..2731c1b7e9 100644 --- a/pandora_agents/win32/pandora.cc +++ b/pandora_agents/win32/pandora.cc @@ -30,7 +30,7 @@ using namespace Pandora; using namespace Pandora_Strutils; #define PATH_SIZE _MAX_PATH+1 -#define PANDORA_VERSION ("7.0NG.753(Build 210415)") +#define PANDORA_VERSION ("7.0NG.753(Build 210419)") string pandora_path; string pandora_dir; diff --git a/pandora_agents/win32/versioninfo.rc b/pandora_agents/win32/versioninfo.rc index 7cac310f11..4981a970f7 100644 --- a/pandora_agents/win32/versioninfo.rc +++ b/pandora_agents/win32/versioninfo.rc @@ -11,7 +11,7 @@ BEGIN VALUE "LegalCopyright", "Artica ST" VALUE "OriginalFilename", "PandoraAgent.exe" VALUE "ProductName", "Pandora FMS Windows Agent" - VALUE "ProductVersion", "(7.0NG.753(Build 210415))" + VALUE "ProductVersion", "(7.0NG.753(Build 210419))" VALUE "FileVersion", "1.0.0.0" END END diff --git a/pandora_console/DEBIAN/control b/pandora_console/DEBIAN/control index 533ccc5147..d9fbc2f5dd 100644 --- a/pandora_console/DEBIAN/control +++ b/pandora_console/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-console -Version: 7.0NG.753-210415 +Version: 7.0NG.753-210419 Architecture: all Priority: optional Section: admin diff --git a/pandora_console/DEBIAN/make_deb_package.sh b/pandora_console/DEBIAN/make_deb_package.sh index 4d11da420a..63f9fa4fe7 100644 --- a/pandora_console/DEBIAN/make_deb_package.sh +++ b/pandora_console/DEBIAN/make_deb_package.sh @@ -14,7 +14,7 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -pandora_version="7.0NG.753-210415" +pandora_version="7.0NG.753-210419" package_pear=0 package_pandora=1 diff --git a/pandora_console/extras/mr/46.sql b/pandora_console/extras/mr/46.sql index 2d0c2a8a84..833e1a7a49 100644 --- a/pandora_console/extras/mr/46.sql +++ b/pandora_console/extras/mr/46.sql @@ -1,5 +1,6 @@ START TRANSACTION; +ALTER TABLE `tgrupo` ADD COLUMN `max_agents` int(10) NOT NULL DEFAULT 0; ALTER TABLE `tagent_custom_fields` MODIFY COLUMN `combo_values` TEXT NOT NULL DEFAULT ''; ALTER TABLE `treport_content` MODIFY `external_source` MEDIUMTEXT; ALTER TABLE `treport_content_template` MODIFY `external_source` MEDIUMTEXT; 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 b0d6a00048..bfb3d93c8d 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 @@ -2869,6 +2869,12 @@ UPDATE twidget SET description='Show a visual console' WHERE class_name='MapsMad UPDATE twidget SET description='Clock' WHERE class_name='ClockWidget'; UPDATE twidget SET description='Group status' WHERE class_name='SystemGroupStatusWidget'; +-- +-- Modifies tgrupo table. +-- + +ALTER TABLE tgrupo ADD COLUMN max_agents int(10) NOT NULL DEFAULT 0; + -- ---------------------------------------------------------------------- -- Table `tnode_relations` -- ---------------------------------------------------------------------- diff --git a/pandora_console/godmode/agentes/configurar_agente.php b/pandora_console/godmode/agentes/configurar_agente.php index 63b9e03131..6440ce70e0 100644 --- a/pandora_console/godmode/agentes/configurar_agente.php +++ b/pandora_console/godmode/agentes/configurar_agente.php @@ -37,6 +37,8 @@ require_once $config['homedir'].'/include/functions_cron.php'; ui_require_javascript_file('encode_decode_base64'); ui_require_css_file('agent_manager'); +use PandoraFMS\Event; + check_login(); // Get tab parameter to check ACL in each tabs. @@ -229,6 +231,9 @@ if ($create_agent) { if ($alias == '') { $agent_creation_error = __('No agent alias specified'); $agent_created_ok = 0; + } else if (group_allow_more_agents($grupo, true, 'create') === false) { + $agent_creation_error = __('Agent cannot be created due to the maximum agent limit for this group'); + $agent_created_ok = 0; } else { if ($alias_as_name) { $sql = 'SELECT nombre FROM tagente WHERE nombre = "'.$alias.'"'; @@ -1034,6 +1039,8 @@ if ($update_agent) { if ($grupo <= 0) { ui_print_error_message(__('The group id %d is incorrect.', $grupo)); + } else if (group_allow_more_agents($grupo, true, 'update') === false) { + ui_print_error_message(__('Agent cannot be updated due to the maximum agent limit for this group')); } else if ($exists_ip) { ui_print_error_message(__('Duplicate main IP address')); } else { diff --git a/pandora_console/godmode/groups/configure_group.php b/pandora_console/godmode/groups/configure_group.php index 0d45f381e4..b06ae97b25 100644 --- a/pandora_console/godmode/groups/configure_group.php +++ b/pandora_console/godmode/groups/configure_group.php @@ -1,16 +1,32 @@ '; @@ -224,6 +242,10 @@ $i++; // $table->data[10][0] = __('Skin'); // $table->data[10][1] = skins_print_select($config['id_user'], 'skin', $skin, '', __('None'), 0, true); // } +$table->data[$i][0] = __('Max agents allowed').' '.ui_print_help_tip(__('Set the maximum of agents allowed for this group. 0 is unlimited.'), true); +$table->data[$i][1] = html_print_input_text('max_agents', $max_agents, '', 10, 255, true); +$i++; + if (defined('METACONSOLE')) { $sec = 'advanced'; } else { @@ -241,6 +263,7 @@ if (isset($config['metaconsole_node_id']) && $config['metaconsole_node_id'] > 0) echo '