diff --git a/pandora_agents/pc/AIX/pandora_agent.conf b/pandora_agents/pc/AIX/pandora_agent.conf index 4fff860931..f3657d3a7a 100644 --- a/pandora_agents/pc/AIX/pandora_agent.conf +++ b/pandora_agents/pc/AIX/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.739, AIX version +# Version 7.0NG.740, AIX version # Licensed under GPL license v2, # Copyright (c) 2003-2010 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/pc/FreeBSD/pandora_agent.conf b/pandora_agents/pc/FreeBSD/pandora_agent.conf index f33b304a7c..95fd1090ad 100644 --- a/pandora_agents/pc/FreeBSD/pandora_agent.conf +++ b/pandora_agents/pc/FreeBSD/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.739, FreeBSD Version +# Version 7.0NG.740, FreeBSD Version # Licensed under GPL license v2, # Copyright (c) 2003-2010 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/pc/HP-UX/pandora_agent.conf b/pandora_agents/pc/HP-UX/pandora_agent.conf index 1d627fc222..04122feb30 100644 --- a/pandora_agents/pc/HP-UX/pandora_agent.conf +++ b/pandora_agents/pc/HP-UX/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.739, HP-UX Version +# Version 7.0NG.740, HP-UX Version # Licensed under GPL license v2, # Copyright (c) 2003-2009 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/pc/Linux/pandora_agent.conf b/pandora_agents/pc/Linux/pandora_agent.conf index 9501fa5222..b083e7f3aa 100644 --- a/pandora_agents/pc/Linux/pandora_agent.conf +++ b/pandora_agents/pc/Linux/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.739, GNU/Linux +# Version 7.0NG.740, GNU/Linux # Licensed under GPL license v2, # Copyright (c) 2003-2009 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/pc/NT4/pandora_agent.conf b/pandora_agents/pc/NT4/pandora_agent.conf index bdd4bcf425..4bb88c5b4e 100644 --- a/pandora_agents/pc/NT4/pandora_agent.conf +++ b/pandora_agents/pc/NT4/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.739, GNU/Linux +# Version 7.0NG.740, GNU/Linux # Licensed under GPL license v2, # Copyright (c) 2003-2009 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/pc/SunOS/pandora_agent.conf b/pandora_agents/pc/SunOS/pandora_agent.conf index f80f403dd8..a90b7227ca 100644 --- a/pandora_agents/pc/SunOS/pandora_agent.conf +++ b/pandora_agents/pc/SunOS/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.739, Solaris Version +# Version 7.0NG.740, Solaris Version # Licensed under GPL license v2, # Copyright (c) 2003-2009 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/pc/Win32/pandora_agent.conf b/pandora_agents/pc/Win32/pandora_agent.conf index 86bfede9d7..d750898b70 100644 --- a/pandora_agents/pc/Win32/pandora_agent.conf +++ b/pandora_agents/pc/Win32/pandora_agent.conf @@ -1,6 +1,6 @@ # Base config file for Pandora FMS Windows Agent # (c) 2006-2010 Artica Soluciones Tecnologicas -# Version 7.0NG.739 +# Version 7.0NG.740 # This program is Free Software, you can redistribute it and/or modify it # under the terms of the GNU General Public Licence as published by the Free Software diff --git a/pandora_agents/shellscript/aix/pandora_agent.conf b/pandora_agents/shellscript/aix/pandora_agent.conf index aa65eb24d9..6a663d6331 100644 --- a/pandora_agents/shellscript/aix/pandora_agent.conf +++ b/pandora_agents/shellscript/aix/pandora_agent.conf @@ -1,6 +1,6 @@ # Fichero de configuracion base de agentes de Pandora # Base config file for Pandora agents -# Version 7.0NG.739, AIX version +# Version 7.0NG.740, AIX version # General Parameters # ================== diff --git a/pandora_agents/shellscript/bsd-ipso/pandora_agent.conf b/pandora_agents/shellscript/bsd-ipso/pandora_agent.conf index 7c225fea1c..99e4c62462 100644 --- a/pandora_agents/shellscript/bsd-ipso/pandora_agent.conf +++ b/pandora_agents/shellscript/bsd-ipso/pandora_agent.conf @@ -1,6 +1,6 @@ # Fichero de configuracion base de agentes de Pandora # Base config file for Pandora agents -# Version 7.0NG.739 +# Version 7.0NG.740 # FreeBSD/IPSO version # Licenced under GPL licence, 2003-2007 Sancho Lerena diff --git a/pandora_agents/shellscript/hp-ux/pandora_agent.conf b/pandora_agents/shellscript/hp-ux/pandora_agent.conf index 06bd17ed45..7a9d2c4347 100644 --- a/pandora_agents/shellscript/hp-ux/pandora_agent.conf +++ b/pandora_agents/shellscript/hp-ux/pandora_agent.conf @@ -1,6 +1,6 @@ # Fichero de configuracion base de agentes de Pandora # Base config file for Pandora agents -# Version 7.0NG.739, HPUX Version +# Version 7.0NG.740, HPUX Version # General Parameters # ================== diff --git a/pandora_agents/shellscript/linux/pandora_agent.conf b/pandora_agents/shellscript/linux/pandora_agent.conf index 54b0e06dbf..a55d96a952 100644 --- a/pandora_agents/shellscript/linux/pandora_agent.conf +++ b/pandora_agents/shellscript/linux/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.739 +# Version 7.0NG.740 # Licensed under GPL license v2, # (c) 2003-2010 Artica Soluciones Tecnologicas # please visit http://pandora.sourceforge.net diff --git a/pandora_agents/shellscript/mac_osx/pandora_agent.conf b/pandora_agents/shellscript/mac_osx/pandora_agent.conf index f5205f4d16..a24a24d16e 100644 --- a/pandora_agents/shellscript/mac_osx/pandora_agent.conf +++ b/pandora_agents/shellscript/mac_osx/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.739 +# Version 7.0NG.740 # Licensed under GPL license v2, # (c) 2003-2009 Artica Soluciones Tecnologicas # please visit http://pandora.sourceforge.net diff --git a/pandora_agents/shellscript/openWRT/pandora_agent.conf b/pandora_agents/shellscript/openWRT/pandora_agent.conf index 7d6a12d62b..74d515cb4e 100644 --- a/pandora_agents/shellscript/openWRT/pandora_agent.conf +++ b/pandora_agents/shellscript/openWRT/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.739 +# Version 7.0NG.740 # Licensed under GPL license v2, # please visit http://pandora.sourceforge.net diff --git a/pandora_agents/shellscript/solaris/pandora_agent.conf b/pandora_agents/shellscript/solaris/pandora_agent.conf index cbae89b0b5..dc915ef18e 100644 --- a/pandora_agents/shellscript/solaris/pandora_agent.conf +++ b/pandora_agents/shellscript/solaris/pandora_agent.conf @@ -1,6 +1,6 @@ # Fichero de configuracion base de agentes de Pandora # Base config file for Pandora agents -# Version 7.0NG.739, Solaris version +# Version 7.0NG.740, Solaris version # General Parameters # ================== diff --git a/pandora_agents/unix/AIX/pandora_agent.conf b/pandora_agents/unix/AIX/pandora_agent.conf index 7f2791b05f..de7e97911b 100644 --- a/pandora_agents/unix/AIX/pandora_agent.conf +++ b/pandora_agents/unix/AIX/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.739, AIX version +# Version 7.0NG.740, AIX version # Licensed under GPL license v2, # Copyright (c) 2003-2010 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/unix/DEBIAN/control b/pandora_agents/unix/DEBIAN/control index dce71a69e6..ce165fde19 100644 --- a/pandora_agents/unix/DEBIAN/control +++ b/pandora_agents/unix/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-agent-unix -Version: 7.0NG.739-191010 +Version: 7.0NG.740-191029 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 2bb60b6dc0..a4a8dce448 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.739-191010" +pandora_version="7.0NG.740-191029" 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/Darwin/pandora_agent.conf b/pandora_agents/unix/Darwin/pandora_agent.conf index 7f403ae687..34dd1bf4fc 100644 --- a/pandora_agents/unix/Darwin/pandora_agent.conf +++ b/pandora_agents/unix/Darwin/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.739, GNU/Linux +# Version 7.0NG.740, GNU/Linux # Licensed under GPL license v2, # Copyright (c) 2003-2012 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/unix/FreeBSD/pandora_agent.conf b/pandora_agents/unix/FreeBSD/pandora_agent.conf index 2871669f88..e4ad74ffe7 100644 --- a/pandora_agents/unix/FreeBSD/pandora_agent.conf +++ b/pandora_agents/unix/FreeBSD/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.739, FreeBSD Version +# Version 7.0NG.740, FreeBSD Version # Licensed under GPL license v2, # Copyright (c) 2003-2016 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/unix/HP-UX/pandora_agent.conf b/pandora_agents/unix/HP-UX/pandora_agent.conf index 1fcbc17977..e55445fe13 100644 --- a/pandora_agents/unix/HP-UX/pandora_agent.conf +++ b/pandora_agents/unix/HP-UX/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.739, HP-UX Version +# Version 7.0NG.740, HP-UX Version # Licensed under GPL license v2, # Copyright (c) 2003-2009 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/unix/Linux/pandora_agent.conf b/pandora_agents/unix/Linux/pandora_agent.conf index 938565241d..54ace6a811 100644 --- a/pandora_agents/unix/Linux/pandora_agent.conf +++ b/pandora_agents/unix/Linux/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.739, GNU/Linux +# Version 7.0NG.740, GNU/Linux # Licensed under GPL license v2, # Copyright (c) 2003-2014 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/unix/NT4/pandora_agent.conf b/pandora_agents/unix/NT4/pandora_agent.conf index f9a2b10b93..94e32e8056 100644 --- a/pandora_agents/unix/NT4/pandora_agent.conf +++ b/pandora_agents/unix/NT4/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.739, GNU/Linux +# Version 7.0NG.740, GNU/Linux # Licensed under GPL license v2, # Copyright (c) 2003-2009 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/unix/NetBSD/pandora_agent.conf b/pandora_agents/unix/NetBSD/pandora_agent.conf index 2f108c2011..71e7d14192 100644 --- a/pandora_agents/unix/NetBSD/pandora_agent.conf +++ b/pandora_agents/unix/NetBSD/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.739, NetBSD Version +# Version 7.0NG.740, NetBSD Version # Licensed under GPL license v2, # Copyright (c) 2003-2010 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/unix/SunOS/pandora_agent.conf b/pandora_agents/unix/SunOS/pandora_agent.conf index 47f17aae0f..cc89dee501 100644 --- a/pandora_agents/unix/SunOS/pandora_agent.conf +++ b/pandora_agents/unix/SunOS/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.739, Solaris Version +# Version 7.0NG.740, Solaris Version # Licensed under GPL license v2, # Copyright (c) 2003-2009 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/unix/pandora_agent b/pandora_agents/unix/pandora_agent index 938c2a118b..4bbac522b1 100755 --- a/pandora_agents/unix/pandora_agent +++ b/pandora_agents/unix/pandora_agent @@ -41,8 +41,8 @@ my $Sem = undef; # Semaphore used to control the number of threads my $ThreadSem = undef; -use constant AGENT_VERSION => '7.0NG.739'; -use constant AGENT_BUILD => '191010'; +use constant AGENT_VERSION => '7.0NG.740'; +use constant AGENT_BUILD => '191029'; # 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 84b91f0312..79f2310c11 100644 --- a/pandora_agents/unix/pandora_agent.redhat.spec +++ b/pandora_agents/unix/pandora_agent.redhat.spec @@ -2,8 +2,8 @@ #Pandora FMS Linux Agent # %define name pandorafms_agent_unix -%define version 7.0NG.739 -%define release 191010 +%define version 7.0NG.740 +%define release 191029 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 d2d7d171b6..392fa174ce 100644 --- a/pandora_agents/unix/pandora_agent.spec +++ b/pandora_agents/unix/pandora_agent.spec @@ -2,8 +2,8 @@ #Pandora FMS Linux Agent # %define name pandorafms_agent_unix -%define version 7.0NG.739 -%define release 191010 +%define version 7.0NG.740 +%define release 191029 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 2af109b6ef..cc4b78b51c 100755 --- a/pandora_agents/unix/pandora_agent_installer +++ b/pandora_agents/unix/pandora_agent_installer @@ -9,8 +9,8 @@ # Please see http://www.pandorafms.org. This code is licensed under GPL 2.0 license. # ********************************************************************** -PI_VERSION="7.0NG.739" -PI_BUILD="191010" +PI_VERSION="7.0NG.740" +PI_BUILD="191029" OS_NAME=`uname -s` FORCE=0 diff --git a/pandora_agents/win32/bin/pandora_agent.conf b/pandora_agents/win32/bin/pandora_agent.conf index d6bf2f9005..79660e5b5d 100644 --- a/pandora_agents/win32/bin/pandora_agent.conf +++ b/pandora_agents/win32/bin/pandora_agent.conf @@ -1,6 +1,6 @@ # Base config file for Pandora FMS Windows Agent # (c) 2006-2017 Artica Soluciones Tecnologicas -# Version 7.0NG.739 +# Version 7.0NG.740 # This program is Free Software, you can redistribute it and/or modify it # under the terms of the GNU General Public Licence as published by the Free Software diff --git a/pandora_agents/win32/installer/pandora.mpi b/pandora_agents/win32/installer/pandora.mpi index 90fd039fcb..730edbe5de 100644 --- a/pandora_agents/win32/installer/pandora.mpi +++ b/pandora_agents/win32/installer/pandora.mpi @@ -3,7 +3,7 @@ AllowLanguageSelection {Yes} AppName -{Pandora FMS Windows Agent v7.0NG.739} +{Pandora FMS Windows Agent v7.0NG.740} ApplicationID {17E3D2CF-CA02-406B-8A80-9D31C17BD08F} @@ -186,7 +186,7 @@ UpgradeApplicationID {} Version -{191010} +{191029} ViewReadme {Yes} diff --git a/pandora_agents/win32/pandora.cc b/pandora_agents/win32/pandora.cc index dfaad586fc..823b486b0e 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.739(Build 191010)") +#define PANDORA_VERSION ("7.0NG.740(Build 191029)") string pandora_path; string pandora_dir; diff --git a/pandora_agents/win32/versioninfo.rc b/pandora_agents/win32/versioninfo.rc index cbcc247ca4..d714543482 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.739(Build 191010))" + VALUE "ProductVersion", "(7.0NG.740(Build 191029))" VALUE "FileVersion", "1.0.0.0" END END diff --git a/pandora_console/DEBIAN/control b/pandora_console/DEBIAN/control index 498016fd27..cab514f37e 100644 --- a/pandora_console/DEBIAN/control +++ b/pandora_console/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-console -Version: 7.0NG.739-191010 +Version: 7.0NG.740-191029 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 bb0f6fe253..64140d02ad 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.739-191010" +pandora_version="7.0NG.740-191029" package_pear=0 package_pandora=1 diff --git a/pandora_console/godmode/agentes/agent_manager.php b/pandora_console/godmode/agentes/agent_manager.php index 6ee2343fc0..d6b9448576 100644 --- a/pandora_console/godmode/agentes/agent_manager.php +++ b/pandora_console/godmode/agentes/agent_manager.php @@ -765,7 +765,7 @@ $table_adv_agent_icon .= html_print_select( ).''; if ($config['activate_gis']) { - $table_adv_gis = '

'.__('Ignore new GIS data:').'

'; + $table_adv_gis = '

'.__('Update new GIS data:').'

'; if ($new_agent) { $update_gis_data = true; } diff --git a/pandora_console/godmode/agentes/module_manager.php b/pandora_console/godmode/agentes/module_manager.php index 6ad5267c0e..b7b1d296ec 100644 --- a/pandora_console/godmode/agentes/module_manager.php +++ b/pandora_console/godmode/agentes/module_manager.php @@ -842,7 +842,9 @@ foreach ($modules as $module) { $module['str_warning'], $module['max_critical'], $module['min_critical'], - $module['str_critical'] + $module['str_critical'], + $module['warning_inverse'], + $module['critical_inverse'] ); } else { $data[7] = ''; diff --git a/pandora_console/godmode/massive/massive_edit_agents.php b/pandora_console/godmode/massive/massive_edit_agents.php index 0126aa93f9..83001be810 100755 --- a/pandora_console/godmode/massive/massive_edit_agents.php +++ b/pandora_console/godmode/massive/massive_edit_agents.php @@ -59,8 +59,10 @@ if ($update_agents) { $values['id_grupo'] = get_parameter('group'); } - if (get_parameter('interval', 0) != 0) { - $values['intervalo'] = get_parameter('interval'); + if (!(get_parameter('interval_select') == -1 && empty(get_parameter('interval_text')))) { + if (get_parameter('interval', 0) != 0) { + $values['intervalo'] = get_parameter('interval'); + } } if (get_parameter('id_os', '') != -1) { @@ -523,7 +525,7 @@ $table->data[1][1] = html_print_select_groups(false, 'AR', false, 'group', $grou $table->data[2][0] = __('Interval'); -$table->data[2][1] = html_print_extended_select_for_time('interval', 0, '', __('No change'), '0', 10, true, 'width: 150px'); +$table->data[2][1] = html_print_extended_select_for_time('interval', 0, '', __('No change'), '0', 10, true, 'width: 150px', false); $table->data[3][0] = __('OS'); $table->data[3][1] = html_print_select_from_sql( diff --git a/pandora_console/godmode/reporting/graph_container.php b/pandora_console/godmode/reporting/graph_container.php index ccc3b6dde6..3b87fc63e3 100644 --- a/pandora_console/godmode/reporting/graph_container.php +++ b/pandora_console/godmode/reporting/graph_container.php @@ -16,10 +16,10 @@ global $config; // Check user credentials check_login(); -if (! check_acl($config['id_user'], 0, 'RR')) { +if (! check_acl($config['id_user'], 0, 'RR') || enterprise_installed() === false) { db_pandora_audit( 'ACL Violation', - 'Trying to access Inventory Module Management' + 'Trying to access Graph container' ); include 'general/noaccess.php'; return; diff --git a/pandora_console/godmode/reporting/graphs.php b/pandora_console/godmode/reporting/graphs.php index fd8d3cff84..1fba644037 100644 --- a/pandora_console/godmode/reporting/graphs.php +++ b/pandora_console/godmode/reporting/graphs.php @@ -71,10 +71,12 @@ switch ($activeTab) { break; } -$buttons['graph_container'] = [ - 'active' => false, - 'text' => ''.html_print_image('images/graph-container.png', true, ['title' => __('Graphs containers')]).'', -]; +if ($enterpriseEnable) { + $buttons['graph_container'] = [ + 'active' => false, + 'text' => ''.html_print_image('images/graph-container.png', true, ['title' => __('Graphs containers')]).'', + ]; +} $delete_graph = (bool) get_parameter('delete_graph'); $view_graph = (bool) get_parameter('view_graph'); diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index ccdb829f9c..b59dbc2ee5 100755 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -240,7 +240,7 @@ switch ($action) { $hide_notinit_agents = $style['hide_notinit_agents']; $dyn_height = $style['dyn_height']; $type = $item['type']; - $name = $item['name']; + $name = $style['name_label']; switch ($type) { case 'event_report_log': diff --git a/pandora_console/godmode/reporting/reporting_builder.list_items.php b/pandora_console/godmode/reporting/reporting_builder.list_items.php index 4eaeeed45b..1b7d3b4df6 100755 --- a/pandora_console/godmode/reporting/reporting_builder.list_items.php +++ b/pandora_console/godmode/reporting/reporting_builder.list_items.php @@ -1,18 +1,34 @@ data[0][1] .= html_print_select($modules, 'module_filter', $moduleFilter, '', __('All'), 0, true); $table->data[0][2] = __('Type'); $table->data[0][2] .= html_print_select($types, 'type_filter', $typeFilter, '', __('All'), 0, true); - // $table->data[1][2] = $table->data[1][3] = ''; $form = '
'; $form .= html_print_table($table, true); $form .= '
'; @@ -265,13 +291,6 @@ if ($moduleFilter != 0) { $where .= ' AND id_agent_module = '.$moduleFilter; } -// Filter report items created from metaconsole in normal console list and the opposite -if (defined('METACONSOLE') and $config['metaconsole'] == 1) { - $where .= ' AND ((server_name IS NOT NULL AND length(server_name) != 0) '.'OR '.$type_escaped.' IN (\'general\', \'SLA\', \'exception\', \'availability\', \'availability_graph\', \'top_n\',\'SLA_monthly\',\'SLA_weekly\',\'SLA_hourly\',\'text\'))'; -} else { - $where .= ' AND ((server_name IS NULL OR length(server_name) = 0) '.'OR '.$type_escaped.' IN (\'general\', \'SLA\', \'exception\', \'availability\', \'top_n\'))'; -} - switch ($config['dbtype']) { case 'mysql': $items = db_get_all_rows_sql( @@ -306,13 +325,17 @@ switch ($config['dbtype']) { 'AND', false ); - // Delete rnum row generated by oracle_recode_query() function + // Delete rnum row generated by oracle_recode_query() function. if ($items !== false) { for ($i = 0; $i < count($items); $i++) { unset($items[$i]['rnum']); } } break; + + default: + // Default. + break; } $countItems = db_get_sql( @@ -421,29 +444,30 @@ foreach ($items as $item) { $row[1] = get_report_name($item['type']); - if ($item['type'] == 'custom_graph') { - $custom_graph_name = db_get_row_sql('select name from tgraph where id_graph = '.$item['id_gs']); - $row[1] = get_report_name($item['type']).' ('.$custom_graph_name['name'].')'; - } - $server_name = $item['server_name']; - if (($config['metaconsole'] == 1) && ($server_name != '') && defined('METACONSOLE')) { + if (is_metaconsole()) { $connection = metaconsole_get_connection($server_name); if (metaconsole_load_external_db($connection) != NOERR) { // ui_print_error_message ("Error connecting to ".$server_name); } } + if ($item['type'] == 'custom_graph') { + $custom_graph_name = db_get_row_sql('SELECT name FROM tgraph WHERE id_graph = '.$item['id_gs']); + $row[1] = get_report_name($item['type']).' ('.$custom_graph_name['name'].')'; + } + + if ($item['id_agent'] == 0) { $is_inventory_item = $item['type'] == 'inventory' || $item['type'] == 'inventory_changes'; - // Due to SLA or top N or general report items + // Due to SLA or top N or general report items. if (!$is_inventory_item && ($item['id_agent_module'] == '' || $item['id_agent_module'] == 0)) { $row[2] = ''; $row[3] = ''; } else { - // The inventory items have the agents and modules in json format in the field external_source + // The inventory items have the agents and modules in json format in the field external_source. if ($is_inventory_item) { $external_source = json_decode($item['external_source'], true); $agents = $external_source['id_agents']; @@ -522,7 +546,7 @@ foreach ($items as $item) { $table->data[] = $row; $count++; - // Restore db connection + // Restore db connection. if (($config['metaconsole'] == 1) && ($server_name != '') && defined('METACONSOLE')) { metaconsole_restore_db(); } diff --git a/pandora_console/godmode/reporting/reporting_builder.php b/pandora_console/godmode/reporting/reporting_builder.php index 45993ec38e..40ce45b5bb 100755 --- a/pandora_console/godmode/reporting/reporting_builder.php +++ b/pandora_console/godmode/reporting/reporting_builder.php @@ -3144,17 +3144,19 @@ if ($enterpriseEnable && defined('METACONSOLE')) { break; } - ui_print_page_header( - $textReportName, - 'images/op_reporting.png', - false, - $helpers, - false, - $buttons, - false, - '', - 60 - ); + if ($action !== 'update' && !is_metaconsole()) { + ui_print_page_header( + $textReportName, + 'images/op_reporting.png', + false, + $helpers, + false, + $buttons, + false, + '', + 60 + ); + } } if ($resultOperationDB !== null) { @@ -3176,6 +3178,26 @@ if ($resultOperationDB !== null) { __('Successfull action'), __('Unsuccessful action

'.$err) ); + + if ($action == 'update') { + $buttons[$activeTab]['active'] = false; + $activeTab = 'list_items'; + $buttons[$activeTab]['active'] = true; + + if (!is_metaconsole()) { + ui_print_page_header( + $textReportName, + 'images/op_reporting.png', + false, + $helpers, + false, + $buttons, + false, + '', + 60 + ); + } + } } switch ($activeTab) { diff --git a/pandora_console/godmode/servers/plugin.php b/pandora_console/godmode/servers/plugin.php index 3eb385332c..79fcfc61a2 100644 --- a/pandora_console/godmode/servers/plugin.php +++ b/pandora_console/godmode/servers/plugin.php @@ -928,10 +928,10 @@ if (($create != '') || ($view != '')) { $other['plugin_type'] = $plugin_meta['plugin_type']; $other['macros'] = urlencode($plugin_meta['macros']); $other['parameters'] = urlencode($plugin_meta['parameters']); - $other = implode('%7C', $other); + $other = implode('%7E', $other); $auth_token = json_decode($value['auth_token']); - $url = $value['server_url'].'include/api.php?op=set&op2=push_plugin'.'&id='.$pluginid.'&other_mode=url_encode_separator_%7C&other='.$other."&apipass=$auth_token->api_password"."&user=$auth_token->console_user&pass=$auth_token->console_password"; + $url = $value['server_url'].'include/api.php?op=set&op2=push_plugin'.'&id='.$pluginid.'&other_mode=url_encode_separator_%7E&other='.$other."&apipass=$auth_token->api_password"."&user=$auth_token->console_user&pass=$auth_token->console_password"; $file_path = realpath($plugin_meta['execute']); $post = ''; if (file_exists($file_path)) { diff --git a/pandora_console/godmode/users/configure_profile.php b/pandora_console/godmode/users/configure_profile.php index 418add8aa8..8c69c0e0a9 100644 --- a/pandora_console/godmode/users/configure_profile.php +++ b/pandora_console/godmode/users/configure_profile.php @@ -18,7 +18,7 @@ check_login(); enterprise_hook('open_meta_frame'); -if (! check_acl($config['id_user'], 0, 'PM')) { +if (! check_acl($config['id_user'], 0, 'UM')) { db_pandora_audit( 'ACL Violation', 'Trying to access Profile Management' @@ -320,24 +320,29 @@ if ($id_profile || $new_profile) { $table->data['IM'] = $row; $table->data[] = '
'; + $disable_option = 'javascript: return false;'; + if (check_acl($config['id_user'], 0, 'PM') || users_is_admin()) { + $disable_option = ''; + } + // Users $row = []; $row['name'] = __('Manage users'); - $row['input'] = html_print_checkbox('user_management', 1, $user_management, true); + $row['input'] = html_print_checkbox('user_management', 1, $user_management, true, false, $disable_option); $table->data['UM'] = $row; $table->data[] = '
'; // DB $row = []; $row['name'] = __('Manage database'); - $row['input'] = html_print_checkbox('db_management', 1, $db_management, true); + $row['input'] = html_print_checkbox('db_management', 1, $db_management, true, false, $disable_option); $table->data['DM'] = $row; $table->data[] = '
'; // Pandora $row = []; $row['name'] = __('%s management', get_product_name()); - $row['input'] = html_print_checkbox('pandora_management', 1, $pandora_management, true); + $row['input'] = html_print_checkbox('pandora_management', 1, $pandora_management, true, false, $disable_option); $table->data['PM'] = $row; $table->data[] = '
'; @@ -359,3 +364,18 @@ if ($id_profile || $new_profile) { } enterprise_hook('close_meta_frame'); + +?> + + diff --git a/pandora_console/godmode/users/profile_list.php b/pandora_console/godmode/users/profile_list.php index da77dffd9f..a87323f0f8 100644 --- a/pandora_console/godmode/users/profile_list.php +++ b/pandora_console/godmode/users/profile_list.php @@ -362,7 +362,10 @@ foreach ($profiles as $profile) { $data['PM'] = ($profile['pandora_management'] ? $img : ''); $table->cellclass[]['operations'] = 'action_buttons'; $data['operations'] = ''.html_print_image('images/config.png', true, ['title' => __('Edit')]).''; - $data['operations'] .= ''.html_print_image('images/cross.png', true).''; + if (check_acl($config['id_user'], 0, 'PM') || users_is_admin()) { + $data['operations'] .= ''.html_print_image('images/cross.png', true).''; + } + array_push($table->data, $data); } diff --git a/pandora_console/godmode/users/user_list.php b/pandora_console/godmode/users/user_list.php index 4e8cfbb2c1..6a02f4bb57 100644 --- a/pandora_console/godmode/users/user_list.php +++ b/pandora_console/godmode/users/user_list.php @@ -420,7 +420,9 @@ else { $u = get_user_info($key); $g = users_get_groups($key, 'AR', $u['is_admin']); $result = array_intersect($g, $own_groups); - if (!$usr['is_admin'] && !empty($result)) { + + // Show users without profile too. + if (!$usr['is_admin'] && !empty($result) || (!$usr['is_admin'] && db_get_all_rows_field_filter('tusuario_perfil', 'id_usuario', $usr['id_user']) === false)) { $info[$key] = $usr; } diff --git a/pandora_console/include/ajax/module.php b/pandora_console/include/ajax/module.php index e34d287da5..bf528cbaca 100755 --- a/pandora_console/include/ajax/module.php +++ b/pandora_console/include/ajax/module.php @@ -1113,7 +1113,7 @@ if (check_login()) { } if ($module['id_tipo_modulo'] != 25) { - $data[6] = ui_print_module_warn_value($module['max_warning'], $module['min_warning'], $module['str_warning'], $module['max_critical'], $module['min_critical'], $module['str_critical']); + $data[6] = ui_print_module_warn_value($module['max_warning'], $module['min_warning'], $module['str_warning'], $module['max_critical'], $module['min_critical'], $module['str_critical'], $module['warning_inverse'], $module['critical_inverse']); } else { $data[6] = ''; } diff --git a/pandora_console/include/api.php b/pandora_console/include/api.php index e4977bb614..f263350685 100644 --- a/pandora_console/include/api.php +++ b/pandora_console/include/api.php @@ -1,15 +1,32 @@ 'api_password'])); +$apiPassword = io_output_password( + db_get_value_filter( + 'value', + 'tconfig', + ['token' => 'api_password'] + ) +); $correctLogin = false; $no_login_msg = ''; -// Clean unwanted output +// Clean unwanted output. ob_clean(); // READ THIS: // Special call without checks to retrieve version and build of the Pandora FMS // This info is avalable from the web console without login -// Don't change the format, it is parsed by applications -switch ($info) { - case 'version': - if (!$config['MR']) { - $config['MR'] = 0; - } - - echo 'Pandora FMS '.$pandora_version.' - '.$build_version.' MR'.$config['MR']; +// Don't change the format, it is parsed by applications. +if ($info == 'version') { + if (!$config['MR']) { + $config['MR'] = 0; + } + echo 'Pandora FMS '.$pandora_version.' - '.$build_version.' MR'.$config['MR']; exit; } @@ -68,14 +89,19 @@ if (isInACL($ipOrigin)) { if (empty($apiPassword) || (!empty($apiPassword) && $api_password === $apiPassword)) { $user_in_db = process_user_login($user, $password, true); if ($user_in_db !== false) { + $config['id_usuario'] = $user_in_db; + // Compat. $config['id_user'] = $user_in_db; $correctLogin = true; if (session_status() === PHP_SESSION_NONE) { session_start(); + $_SESSION = []; } $_SESSION['id_usuario'] = $user; + + config_prepare_session(); session_write_close(); } else { $no_login_msg = 'Incorrect user credentials'; @@ -84,7 +110,7 @@ if (isInACL($ipOrigin)) { $no_login_msg = 'Incorrect given API password'; } } else { - $no_login_msg = "IP $ipOrigin is not in ACL list"; + $no_login_msg = 'IP '.$ipOrigin.' is not in ACL list'; } if ($correctLogin) { @@ -93,11 +119,14 @@ if ($correctLogin) { } else { $function_name = ''; - // Check if is an extension function and get the function name + // Check if is an extension function and get the function name. if ($op2 == 'extension') { - $extension_api_url = $config['homedir'].'/'.EXTENSIONS_DIR."/$ext_name/$ext_name.api.php"; - // The extension API file must exist and the extension must be enabled - if (file_exists($extension_api_url) && !in_array($ext_name, extensions_get_disabled_extensions())) { + $extension_api_url = $config['homedir'].'/'.EXTENSIONS_DIR.'/'.$ext_name.'/'.$ext_name.'.api.php'; + // The extension API file must exist and the extension must be + // enabled. + if (file_exists($extension_api_url) + && !in_array($ext_name, extensions_get_disabled_extensions()) + ) { include_once $extension_api_url; $function_name = 'apiextension_'.$op.'_'.$ext_function; } @@ -107,16 +136,19 @@ if ($correctLogin) { if ($op == 'set' && $id) { switch ($op2) { case 'update_agent': - case 'add_module_in_conf': case 'update_module_in_conf': case 'delete_module_in_conf': - - $id_os = db_get_value_sql('select id_os from tagente where id_agente = '.$id); - - if ($id_os == 100) { - returnError('not_allowed_operation_cluster', $returnType); - return false; + $agent = agents_locate_agent($id); + if ($agent !== false) { + $id_os = $agent['id_os']; + if ($id_os == 100) { + returnError( + 'not_allowed_operation_cluster', + $returnType + ); + return false; + } } break; @@ -127,12 +159,16 @@ if ($correctLogin) { case 'create_snmp_module': case 'delete_module': case 'delete_agent': - - $id_os = db_get_value_sql('select id_os from tagente where nombre = "'.$id.'"'); - - if ($id_os == 100) { - returnError('not_allowed_operation_cluster', $returnType); - return false; + $agent = agents_locate_agent($id); + if ($agent !== false) { + $id_os = $agent['id_os']; + if ($id_os == 100) { + returnError( + 'not_allowed_operation_cluster', + $returnType + ); + return false; + } } break; @@ -141,60 +177,98 @@ if ($correctLogin) { case 'update_data_module': case 'update_snmp_module': - $id_os = db_get_value_sql('select id_os from tagente where id_agente = (select id_agente from tagente_modulo where id_agente_modulo ='.$id.')'); + $id_os = db_get_value_sql( + sprintf( + 'SELECT id_os + FROM tagente + WHERE id_agente = ( + SELECT id_agente + FROM tagente_modulo + WHERE id_agente_modulo = %d + )', + $id + ) + ); + if ($id_os == 100) { - returnError('not_allowed_operation_cluster', $returnType); + returnError( + 'not_allowed_operation_cluster', + $returnType + ); return false; } break; case 'delete_user_permission': - if ($user_db === '') { - returnError(__('User or group not specified'), __('User, group not specified')); + returnError( + __('User or group not specified'), + __('User, group not specified') + ); return; } - $id_os = api_set_delete_user_profiles($thrash1, $thrash2, $other, $returnType); + $id_os = api_set_delete_user_profiles( + $thrash1, + $thrash2, + $other, + $returnType + ); if ($id_os != 100) { return; } if ($id_os == false) { - returnError('not_allowed_operation_cluster', $returnType); + returnError( + 'not_allowed_operation_cluster', + $returnType + ); return false; } break; case 'add_permission_user_to_group': - - if ($user_db == null || $group_db == null || $id_up == null) { - returnError(__('User, group or profile not specified'), __('User, group or profile status not specified')); + if ($user_db == null + || $group_db == null + || $id_up == null + ) { + returnError( + __('User, group or profile not specified'), + __('User, group or profile status not specified') + ); return; } - $id_os = api_set_add_permission_user_to_group($thrash1, $thrash2, $other, $returnType); + $id_os = api_set_add_permission_user_to_group( + $thrash1, + $thrash2, + $other, + $returnType + ); if ($id_os != 100) { return; } if ($id_os == false) { - returnError('not_allowed_operation_cluster', $returnType); + returnError( + 'not_allowed_operation_cluster', + $returnType + ); return false; } break; default: - - // break; + // Ignore. + break; } } } - // Check if the function exists + // Check if the function exists. if (function_exists($function_name)) { if (!DEBUG) { error_reporting(0); @@ -205,18 +279,37 @@ if ($correctLogin) { ini_set('display_errors', 1); } - call_user_func($function_name, $id, $id2, $other, $returnType, $user_in_db); + call_user_func( + $function_name, + $id, + $id2, + $other, + $returnType, + $user_in_db + ); } else { returnError('no_exist_operation', $returnType); } } } else { - // TODO: Implement a new switch in config to enable / disable - // ACL auth failure: if enabled and have lots of traffic can produce millions - // of records and a considerable OVERHEAD in the system :( - // db_pandora_audit("API access Failed", $no_login_msg, $user, $ipOrigin); + /* + * //TODO: Implement a new switch in config to enable / disable + * ACL auth failure: if enabled and have lots of traffic can produce + * millions of records and a considerable OVERHEAD in the system :( + * db_pandora_audit("API access Failed", $no_login_msg, $user, $ipOrigin); + */ + sleep(15); - // Protection on DoS attacks + // Protection on DoS attacks. echo 'auth error'; } + +// Logout. +if (session_status() === PHP_SESSION_ACTIVE) { + $_SESSION = []; + // Could give a warning if no session file is created. Ignore. + @session_destroy(); + header_remove('Set-Cookie'); + setcookie(session_name(), $_COOKIE[session_name()], (time() - 4800), '/'); +} diff --git a/pandora_console/include/chart_generator.php b/pandora_console/include/chart_generator.php index 2ae768d4fe..0d1d138ae6 100644 --- a/pandora_console/include/chart_generator.php +++ b/pandora_console/include/chart_generator.php @@ -1,22 +1,39 @@ + + $_REQUEST['session_id']]); +if (check_login(false) === false) { + // Error handler. + ?> + + + + + Access denied + + + + + + + + +

Access is not granted

+ + + + + '; - echo ''; - ui_print_error_message(__('There was a problem connecting with the node')); - echo ''; - echo ''; + ?> + + + + + + load_tables(); } @@ -85,16 +161,18 @@ if (file_exists('languages/'.$user_language.'.mo')) { '; switch ($type_graph_pdf) { @@ -208,25 +286,12 @@ if (file_exists('languages/'.$user_language.'.mo')) { break; default: - // code... + // Code... break; } echo '
'; - + echoPhantomCallback(); ?> - - - diff --git a/pandora_console/include/config_process.php b/pandora_console/include/config_process.php index 25b2b0b7ae..484f8dd138 100644 --- a/pandora_console/include/config_process.php +++ b/pandora_console/include/config_process.php @@ -20,8 +20,8 @@ /** * Pandora build version and version */ -$build_version = 'PC191010'; -$pandora_version = 'v7.0NG.739'; +$build_version = 'PC191029'; +$pandora_version = 'v7.0NG.740'; // Do not overwrite default timezone set if defined. $script_tz = @date_default_timezone_get(); diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index 899add9ec0..5aa1020214 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -401,10 +401,11 @@ function api_get_groups($thrash1, $thrash2, $other, $returnType, $user_in_db) function api_get_agent_module_name_last_value($agentName, $moduleName, $other=';', $returnType) { $idAgent = agents_get_agent_id($agentName); + $sql = sprintf( 'SELECT id_agente_modulo - FROM tagente_modulo - WHERE id_agente = %d AND nombre LIKE "%s"', + FROM tagente_modulo + WHERE id_agente = %d AND nombre LIKE "%s"', $idAgent, $moduleName ); @@ -418,8 +419,8 @@ function api_get_agent_module_name_last_value_alias($alias, $moduleName, $other= { $sql = sprintf( 'SELECT tagente_modulo.id_agente_modulo FROM tagente_modulo - INNER JOIN tagente ON tagente_modulo.id_agente = tagente.id_agente - WHERE tagente.alias LIKE "%s" AND tagente_modulo.nombre LIKE "%s"', + INNER JOIN tagente ON tagente_modulo.id_agente = tagente.id_agente + WHERE tagente.alias LIKE "%s" AND tagente_modulo.nombre LIKE "%s"', $alias, $moduleName ); @@ -444,8 +445,8 @@ function api_get_module_last_value($idAgentModule, $trash1, $other=';', $returnT $sql = sprintf( 'SELECT datos - FROM tagente_estado - WHERE id_agente_modulo = %d', + FROM tagente_estado + WHERE id_agente_modulo = %d', $idAgentModule ); $value = db_get_value_sql($sql); @@ -892,9 +893,9 @@ function api_get_tree_agents($trash1, $trahs2, $other, $returnType) $id_group = $group['group_id']; $agents = db_get_all_rows_sql( "SELECT id_agente AS agent_id, id_grupo AS agent_id_group , alias $agent_additional_columns - FROM tagente ta LEFT JOIN tagent_secondary_group tasg - ON ta.id_agente = tasg.id_agent - WHERE ta.id_grupo = $id_group OR tasg.id_group = $id_group" + FROM tagente ta LEFT JOIN tagent_secondary_group tasg + ON ta.id_agente = tasg.id_agent + WHERE ta.id_grupo = $id_group OR tasg.id_group = $id_group" ); if ($agents === false) { $agents = []; @@ -916,13 +917,13 @@ function api_get_tree_agents($trash1, $trahs2, $other, $returnType) $modules = db_get_all_rows_sql( 'SELECT * - FROM (SELECT id_agente_modulo as module_id_agent_modulo '.$module_additional_columns.' - FROM tagente_modulo - WHERE id_agente = '.$agent['agent_id'].') t1 - INNER JOIN (SELECT id_agente_modulo as module_id_agent_modulo '.$estado_additional_columns.' - FROM tagente_estado - WHERE id_agente = '.$agent['agent_id'].') t2 - ON t1.module_id_agent_modulo = t2.module_id_agent_modulo' + FROM (SELECT id_agente_modulo as module_id_agent_modulo '.$module_additional_columns.' + FROM tagente_modulo + WHERE id_agente = '.$agent['agent_id'].') t1 + INNER JOIN (SELECT id_agente_modulo as module_id_agent_modulo '.$estado_additional_columns.' + FROM tagente_estado + WHERE id_agente = '.$agent['agent_id'].') t2 + ON t1.module_id_agent_modulo = t2.module_id_agent_modulo' ); if ($modules === false) { @@ -947,16 +948,16 @@ function api_get_tree_agents($trash1, $trahs2, $other, $returnType) $alerts = db_get_all_rows_sql( 'SELECT t1.id_agent_module as alert_id_agent_module '.$alert_additional_columns.' - FROM (SELECT * FROM talert_template_modules - WHERE id_agent_module = '.$module['module_id_agent_modulo'].') t1 - INNER JOIN talert_templates t2 - ON t1.id_alert_template = t2.id - LEFT JOIN talert_template_module_actions t3 - ON t1.id = t3.id_alert_template_module - LEFT JOIN talert_actions t4 - ON t3.id_alert_action = t4.id - LEFT JOIN talert_commands t5 - ON t4.id_alert_command = t5.id' + FROM (SELECT * FROM talert_template_modules + WHERE id_agent_module = '.$module['module_id_agent_modulo'].') t1 + INNER JOIN talert_templates t2 + ON t1.id_alert_template = t2.id + LEFT JOIN talert_template_module_actions t3 + ON t1.id = t3.id_alert_template_module + LEFT JOIN talert_actions t4 + ON t3.id_alert_action = t4.id + LEFT JOIN talert_commands t5 + ON t4.id_alert_command = t5.id' ); if ($alerts === false) { @@ -1141,8 +1142,8 @@ function api_get_module_properties_by_alias($alias, $module_name, $other, $retur $sql = sprintf( 'SELECT tagente_modulo.id_agente_modulo, tagente.id_agente FROM tagente_modulo - INNER JOIN tagente ON tagente_modulo.id_agente = tagente.id_agente - WHERE tagente.alias LIKE "%s" AND tagente_modulo.nombre LIKE "%s"', + INNER JOIN tagente ON tagente_modulo.id_agente = tagente.id_agente + WHERE tagente.alias LIKE "%s" AND tagente_modulo.nombre LIKE "%s"', $alias, $module_name ); @@ -1258,13 +1259,13 @@ function get_module_properties($id_module, $fields, $separator, $returnType, $re $returnVar = []; $modules = db_get_all_rows_sql( 'SELECT * - FROM (SELECT id_agente_modulo as module_id_agent_modulo '.$module_additional_columns.' - FROM tagente_modulo - WHERE id_agente_modulo = '.$id_module.') t1 - INNER JOIN (SELECT id_agente_modulo as module_id_agent_modulo '.$estado_additional_columns.' - FROM tagente_estado - WHERE id_agente_modulo = '.$id_module.') t2 - ON t1.module_id_agent_modulo = t2.module_id_agent_modulo' + FROM (SELECT id_agente_modulo as module_id_agent_modulo '.$module_additional_columns.' + FROM tagente_modulo + WHERE id_agente_modulo = '.$id_module.') t1 + INNER JOIN (SELECT id_agente_modulo as module_id_agent_modulo '.$estado_additional_columns.' + FROM tagente_estado + WHERE id_agente_modulo = '.$id_module.') t2 + ON t1.module_id_agent_modulo = t2.module_id_agent_modulo' ); if ($modules === false) { @@ -1328,8 +1329,8 @@ function api_set_update_agent($id_agent, $thrash2, $other, $thrash3) if ($cascadeProtection == 1) { if (($idParent != 0) && (db_get_value_sql( 'SELECT id_agente_modulo - FROM tagente_modulo - WHERE id_agente = '.$idParent.' AND id_agente_modulo = '.$cascadeProtectionModule + FROM tagente_modulo + WHERE id_agente = '.$idParent.' AND id_agente_modulo = '.$cascadeProtectionModule ) === false) ) { returnError('parent_agent_not_exist', 'Is not a parent module to do cascade protection.'); @@ -1368,7 +1369,7 @@ function api_set_update_agent($id_agent, $thrash2, $other, $thrash3) ); $tpolicy_group_old = db_get_all_rows_sql( 'SELECT id_policy FROM tpolicy_groups - WHERE id_group = '.$values_old['id_grupo'] + WHERE id_group = '.$values_old['id_grupo'] ); $return = db_process_sql_update( @@ -1413,7 +1414,7 @@ function api_set_update_agent($id_agent, $thrash2, $other, $thrash3) foreach ($tpolicy_group_old as $key => $value) { $tpolicy_agents_old = db_get_sql( 'SELECT * FROM tpolicy_agents - WHERE id_policy = '.$value['id_policy'].' AND id_agent = '.$id_agent + WHERE id_policy = '.$value['id_policy'].' AND id_agent = '.$id_agent ); if ($tpolicy_agents_old) { @@ -1431,14 +1432,14 @@ function api_set_update_agent($id_agent, $thrash2, $other, $thrash3) $tpolicy_group = db_get_all_rows_sql( 'SELECT id_policy FROM tpolicy_groups - WHERE id_group = '.$idGroup + WHERE id_group = '.$idGroup ); if ($tpolicy_group) { foreach ($tpolicy_group as $key => $value) { $tpolicy_agents = db_get_sql( 'SELECT * FROM tpolicy_agents - WHERE id_policy = '.$value['id_policy'].' AND id_agent ='.$id_agent + WHERE id_policy = '.$value['id_policy'].' AND id_agent ='.$id_agent ); if (!$tpolicy_agents) { @@ -1492,7 +1493,7 @@ function api_set_new_agent($thrash1, $thrash2, $other, $thrash3) global $config; if (!check_acl($config['id_user'], 0, 'AW')) { - returnError('forbidden', 'string'); + returnError('forbidden', 'you havent got permissions to do this'); return; } @@ -1500,127 +1501,101 @@ function api_set_new_agent($thrash1, $thrash2, $other, $thrash3) return; } - $alias = $other['data'][0]; - $ip = $other['data'][1]; - $idParent = $other['data'][2]; - $idGroup = $other['data'][3]; - $cascadeProtection = $other['data'][4]; - $cascadeProtectionModule = $other['data'][5]; - $intervalSeconds = $other['data'][6]; - $idOS = $other['data'][7]; - // $idServer = $other['data'][7]; - $nameServer = $other['data'][8]; - $customId = $other['data'][9]; - $learningMode = $other['data'][10]; - $disabled = $other['data'][11]; - $description = $other['data'][12]; - $alias_as_name = $other['data'][13]; + $alias = io_safe_input(trim(preg_replace('/[\/\\\|%#&$]/', '', $other['data'][0]))); + $direccion_agente = io_safe_input($other['data'][1]); + $nombre_agente = hash('sha256', $direccion_agente.'|'.$direccion_agente.'|'.time().'|'.sprintf('%04d', rand(0, 10000))); + $id_parent = (int) $other['data'][2]; + $grupo = (int) $other['data'][3]; + $cascade_protection = (int) $other['data'][4]; + $cascade_protection_module = (int) $other['data'][5]; + $intervalo = (string) $other['data'][6]; + $id_os = (int) $other['data'][7]; + $server_name = (string) $other['data'][8]; + $custom_id = (string) $other['data'][9]; + $modo = (int) $other['data'][10]; + $disabled = (int) $other['data'][11]; + $comentarios = (string) $other['data'][12]; + $alias_as_name = (int) $other['data'][13]; + $update_module_count = (int) $config['metaconsole_agent_cache'] == 1; - if ($alias_as_name && !empty($alias)) { - $name = $alias; - } else { - $name = hash('sha256', $alias.'|'.$direccion_agente.'|'.time().'|'.sprintf('%04d', rand(0, 10000))); - if (empty($alias)) { - $alias = $name; - } - } - - if ($cascadeProtection == 1) { - if (($idParent != 0) && (db_get_value_sql( + if ($cascade_protection == 1) { + if (($id_parent != 0) && (db_get_value_sql( 'SELECT id_agente_modulo - FROM tagente_modulo - WHERE id_agente = '.$idParent.' AND id_agente_modulo = '.$cascadeProtectionModule + FROM tagente_modulo + WHERE id_agente = '.$id_parent.' AND id_agente_modulo = '.$cascade_protection_module ) === false) ) { returnError('parent_agent_not_exist', 'Is not a parent module to do cascade protection.'); + return; } } else { $cascadeProtectionModule = 0; } - switch ($config['dbtype']) { - case 'mysql': - $sql1 = 'SELECT name - FROM tserver WHERE BINARY name LIKE "'.$nameServer.'"'; - break; + $server_name = db_get_value_sql('SELECT name FROM tserver WHERE BINARY name LIKE "'.$server_name.'"'); - case 'postgresql': - case 'oracle': - $sql1 = 'SELECT name - FROM tserver WHERE name LIKE \''.$nameServer.'\''; - break; - } - - $nameServer = db_get_value_sql($sql1); - - // Check ACL group - if (!check_acl($config['id_user'], $idGroup, 'AW')) { - returnError('forbidden', 'string'); - return; - } - - // Check selected parent - if ($idParent != 0) { - $parentCheck = agents_check_access_agent($idParent); - if ($parentCheck === null) { - returnError('parent_agent_not_exist', __('The agent parent don`t exist.')); - return; - } - - if ($parentCheck === false) { - returnError('parent_agent_forbidden', __('The user cannot access to parent agent.')); - return; - } - } - - if (agents_get_agent_id($name)) { + // Check if agent exists (BUG WC-50518-2). + if ($alias == '' && $alias_as_name === 0) { + returnError('alias_not_specified', 'No agent alias specified'); + } else if (agents_get_agent_id($name)) { returnError('agent_name_exist', 'The name of agent yet exist in DB.'); - } else if (db_get_value_sql( - 'SELECT id_grupo - FROM tgrupo - WHERE id_grupo = '.$idGroup - ) === false - ) { + } else if (db_get_value_sql('SELECT id_grupo FROM tgrupo WHERE id_grupo = '.$grupo) === false) { returnError('id_grupo_not_exist', 'The group don`t exist.'); - } else if (db_get_value_sql( - 'SELECT id_os - FROM tconfig_os - WHERE id_os = '.$idOS - ) === false - ) { + } else if (db_get_value_sql('SELECT id_os FROM tconfig_os WHERE id_os = '.$id_os) === false) { returnError('id_os_not_exist', 'The OS don`t exist.'); - } else if (db_get_value_sql($sql1) === false) { + } else if ($server_name === false) { returnError('server_not_exist', 'The '.get_product_name().' Server don`t exist.'); } else { - $idAgente = db_process_sql_insert( - 'tagente', - [ - 'nombre' => $name, - 'alias' => $alias, - 'direccion' => $ip, - 'id_grupo' => $idGroup, - 'intervalo' => $intervalSeconds, - 'comentarios' => $description, - 'modo' => $learningMode, - 'id_os' => $idOS, - 'disabled' => $disabled, - 'cascade_protection' => $cascadeProtection, - 'cascade_protection_module' => $cascadeProtectionModule, - 'server_name' => $nameServer, - 'id_parent' => $idParent, - 'custom_id' => $customId, - ] - ); - - if (!empty($idAgente) && !empty($ip)) { - // register ip for this agent in 'taddress' - agents_add_address($idAgente, $ip); + if ($alias_as_name === 1) { + $exists_alias = db_get_row_sql('SELECT nombre FROM tagente WHERE nombre = "'.$alias.'"'); + $nombre_agente = $alias; } - if ($idGroup && !empty($idAgente)) { + if ($direccion_agente != '') { + $exists_ip = db_get_row_sql('SELECT direccion FROM tagente WHERE direccion = "'.$direccion_agente.'"'); + } + + if (!$exists_alias && !$exists_ip) { + $id_agente = db_process_sql_insert( + 'tagente', + [ + 'nombre' => $nombre_agente, + 'alias' => $alias, + 'alias_as_name' => $alias_as_name, + 'direccion' => $direccion_agente, + 'id_grupo' => $grupo, + 'intervalo' => $intervalo, + 'comentarios' => $comentarios, + 'modo' => $modo, + 'id_os' => $id_os, + 'disabled' => $disabled, + 'cascade_protection' => $cascade_protection, + 'cascade_protection_module' => $cascade_protection_module, + 'server_name' => $server_name, + 'id_parent' => $id_parent, + 'custom_id' => $custom_id, + 'os_version' => '', + 'agent_version' => '', + 'timezone_offset' => 0, + 'icon_path' => '', + 'url_address' => '', + 'update_module_count' => $update_module_count, + ] + ); + enterprise_hook('update_agent', [$id_agente]); + } else { + $id_agente = false; + } + + if ($id_agente !== false) { + // Create address for this agent in taddress. + if ($direccion_agente != '') { + agents_add_address($id_agente, $direccion_agente); + } + $tpolicy_group_old = db_get_all_rows_sql( 'SELECT id_policy FROM tpolicy_groups - WHERE id_group = '.$idGroup + WHERE id_group = '.$grupo ); if ($tpolicy_group_old) { @@ -1629,18 +1604,54 @@ function api_set_new_agent($thrash1, $thrash2, $other, $thrash3) 'tpolicy_agents', [ 'id_policy' => $old_group['id_policy'], - 'id_agent' => $idAgente, + 'id_agent' => $id_agente, ] ); } } + + $info = '{"Name":"'.$nombre_agente.'", + "IP":"'.$direccion_agente.'", + "Group":"'.$grupo.'", + "Interval":"'.$intervalo.'", + "Comments":"'.$comentarios.'", + "Mode":"'.$modo.'", + "ID_parent:":"'.$id_parent.'", + "Server":"'.$server_name.'", + "ID os":"'.$id_os.'", + "Disabled":"'.$disabled.'", + "Custom ID":"'.$custom_id.'", + "Cascade protection":"'.$cascade_protection.'", + "Cascade protection module":"'.$cascade_protection_module.'"}'; + + $unsafe_alias = io_safe_output($alias); + db_pandora_audit( + 'Agent management', + 'Created agent '.$unsafe_alias, + false, + true, + $info + ); + } else { + $id_agente = 0; + + if ($exists_alias) { + $agent_creation_error = __('Could not be created, because name already exists'); + } else if ($exists_ip) { + $agent_creation_error = __('Could not be created, because IP already exists'); + } else { + $agent_creation_error = __('Could not be created for unknown reason'); + } + + returnError('generic error', $agent_creation_error); + return; } returnData( 'string', [ 'type' => 'string', - 'data' => $idAgente, + 'data' => $id_agente, ] ); } @@ -1803,17 +1814,23 @@ function api_get_custom_field_id($t1, $t2, $other, $returnType) /** - * Delete a agent with the name pass as parameter. + * Delete an agent with the name as parameter. * * @param string $id Name of agent to delete. * @param $thrash1 Don't use. * @param $thrast2 Don't use. * @param $thrash3 Don't use. */ -function api_set_delete_agent($id, $thrash1, $thrast2, $thrash3) +function api_set_delete_agent($id, $thrash1, $other, $thrash3) { global $config; + $agent_by_alias = false; + + if ($other['data'][0] === '1') { + $agent_by_alias = true; + } + if (is_metaconsole()) { if (!check_acl($config['id_user'], 0, 'PM')) { returnError('forbidden', 'string'); @@ -1822,8 +1839,8 @@ function api_set_delete_agent($id, $thrash1, $thrast2, $thrash3) $servers = db_get_all_rows_sql( 'SELECT * - FROM tmetaconsole_setup - WHERE disabled = 0' + FROM tmetaconsole_setup + WHERE disabled = 0' ); if ($servers === false) { @@ -1832,19 +1849,47 @@ function api_set_delete_agent($id, $thrash1, $thrast2, $thrash3) foreach ($servers as $server) { if (metaconsole_connect($server) == NOERR) { - $idAgent[0] = agents_get_agent_id($id, true); + if ($other['data'][0] === '1') { + $idAgent[0] = agents_get_agent_id_by_alias($id); + } else { + $idAgent[0] = agents_get_agent_id($id, true); + } + if ($idAgent[0]) { $result = agents_delete_agent($idAgent, true); } + + metaconsole_restore_db(); } } } else { - $idAgent = agents_get_agent_id($id); - if (!util_api_check_agent_and_print_error($idAgent, 'string', 'AD')) { - return; + if ($agent_by_alias) { + $idsAgents = agents_get_agent_id_by_alias(io_safe_input($id)); + } else { + $idAgent = agents_get_agent_id($id, true); } - $result = agents_delete_agent($idAgent, true); + if (!$agent_by_alias) { + if (!util_api_check_agent_and_print_error($idAgent, 'string', 'AD')) { + return; + } + } + + if ($agent_by_alias) { + foreach ($idsAgents as $id) { + if (!util_api_check_agent_and_print_error($id['id_agente'], 'string', 'AD')) { + continue; + } + + $result = agents_delete_agent($id['id_agente'], true); + + if (!$result) { + break; + } + } + } else { + $result = agents_delete_agent($idAgent, true); + } } if (!$result) { @@ -1931,20 +1976,20 @@ function api_get_all_agents($thrash1, $thrash2, $other, $returnType) // Filter by state if (defined('METACONSOLE')) { $sql = "SELECT id_agente, alias, direccion, comentarios, - tconfig_os.name, url_address, nombre - FROM tconfig_os, tmetaconsole_agent - LEFT JOIN tagent_secondary_group - ON tmetaconsole_agent.id_agente = tagent_secondary_group.id_agent - WHERE tmetaconsole_agent.id_os = tconfig_os.id_os - AND disabled = 0 $where AND $groups"; + tconfig_os.name, url_address, nombre + FROM tconfig_os, tmetaconsole_agent + LEFT JOIN tagent_secondary_group + ON tmetaconsole_agent.id_agente = tagent_secondary_group.id_agent + WHERE tmetaconsole_agent.id_os = tconfig_os.id_os + AND disabled = 0 $where AND $groups"; } else { $sql = "SELECT id_agente, alias, direccion, comentarios, - tconfig_os.name, url_address, nombre - FROM tconfig_os, tagente - LEFT JOIN tagent_secondary_group - ON tagente.id_agente = tagent_secondary_group.id_agent - WHERE tagente.id_os = tconfig_os.id_os - AND disabled = 0 $where AND $groups"; + tconfig_os.name, url_address, nombre + FROM tconfig_os, tagente + LEFT JOIN tagent_secondary_group + ON tagente.id_agente = tagent_secondary_group.id_agent + WHERE tagente.id_os = tconfig_os.id_os + AND disabled = 0 $where AND $groups"; } $all_agents = db_get_all_rows_sql($sql); @@ -2068,9 +2113,9 @@ function api_get_agent_modules($thrash1, $thrash2, $other, $thrash3) $sql = sprintf( 'SELECT id_agente, id_agente_modulo, nombre - FROM tagente_modulo - WHERE id_agente = %d AND disabled = 0 - AND delete_pending = 0', + FROM tagente_modulo + WHERE id_agente = %d AND disabled = 0 + AND delete_pending = 0', $other['data'][0] ); @@ -2417,9 +2462,9 @@ function api_get_module_id($id, $thrash1, $name, $thrash3) $sql = sprintf( 'SELECT id_agente_modulo - FROM tagente_modulo WHERE id_agente = %d - AND nombre = "%s" AND disabled = 0 - AND delete_pending = 0', + FROM tagente_modulo WHERE id_agente = %d + AND nombre = "%s" AND disabled = 0 + AND delete_pending = 0', $id, $name['data'] ); @@ -2459,10 +2504,10 @@ function api_get_group_agent($thrash1, $thrash2, $other, $thrash3) $sql = sprintf( 'SELECT groups.nombre nombre - FROM tagente agents, tgrupo groups - WHERE id_agente = %d AND agents.disabled = 0 - AND groups.disabled = 0 - AND agents.id_grupo = groups.id_grupo', + FROM tagente agents, tgrupo groups + WHERE id_agente = %d AND agents.disabled = 0 + AND groups.disabled = 0 + AND agents.id_grupo = groups.id_grupo', $other['data'][0] ); @@ -2501,8 +2546,8 @@ function api_get_group_agent_by_name($thrash1, $thrash2, $other, $thrash3) if (is_metaconsole()) { $servers = db_get_all_rows_sql( 'SELECT * - FROM tmetaconsole_setup - WHERE disabled = 0' + FROM tmetaconsole_setup + WHERE disabled = 0' ); if ($servers === false) { @@ -2516,9 +2561,9 @@ function api_get_group_agent_by_name($thrash1, $thrash2, $other, $thrash3) if ($agent_id) { $sql = sprintf( 'SELECT groups.nombre nombre - FROM tagente agents, tgrupo groups - WHERE id_agente = %d - AND agents.id_grupo = groups.id_grupo', + FROM tagente agents, tgrupo groups + WHERE id_agente = %d + AND agents.id_grupo = groups.id_grupo', $agent_id ); $group_server_names = db_get_all_rows_sql($sql); @@ -2541,9 +2586,9 @@ function api_get_group_agent_by_name($thrash1, $thrash2, $other, $thrash3) $sql = sprintf( 'SELECT groups.nombre nombre - FROM tagente agents, tgrupo groups - WHERE id_agente = %d - AND agents.id_grupo = groups.id_grupo', + FROM tagente agents, tgrupo groups + WHERE id_agente = %d + AND agents.id_grupo = groups.id_grupo', $agent_id ); $group_names = db_get_all_rows_sql($sql); @@ -2593,8 +2638,8 @@ function api_get_group_agent_by_alias($thrash1, $thrash2, $other, $thrash3) if (is_metaconsole()) { $servers = db_get_all_rows_sql( 'SELECT * - FROM tmetaconsole_setup - WHERE disabled = 0' + FROM tmetaconsole_setup + WHERE disabled = 0' ); if ($servers === false) { @@ -2609,9 +2654,9 @@ function api_get_group_agent_by_alias($thrash1, $thrash2, $other, $thrash3) foreach ($agent_id as &$id) { $sql = sprintf( 'SELECT groups.nombre nombre - FROM tagente agents, tgrupo groups - WHERE id_agente = %d - AND agents.id_grupo = groups.id_grupo', + FROM tagente agents, tgrupo groups + WHERE id_agente = %d + AND agents.id_grupo = groups.id_grupo', $id['id_agente'] ); $group_server_names = db_get_all_rows_sql($sql); @@ -2637,9 +2682,9 @@ function api_get_group_agent_by_alias($thrash1, $thrash2, $other, $thrash3) $sql = sprintf( 'SELECT groups.nombre nombre - FROM tagente agents, tgrupo groups - WHERE id_agente = %d - AND agents.id_grupo = groups.id_grupo', + FROM tagente agents, tgrupo groups + WHERE id_agente = %d + AND agents.id_grupo = groups.id_grupo', $id['id_agente'] ); $group_name = db_get_all_rows_sql($sql); @@ -2682,8 +2727,8 @@ function api_get_locate_agent($id, $thrash1, $thrash2, $thrash3) $servers = db_get_all_rows_sql( 'SELECT * - FROM tmetaconsole_setup - WHERE disabled = 0' + FROM tmetaconsole_setup + WHERE disabled = 0' ); if ($servers === false) { @@ -2740,8 +2785,8 @@ function api_get_id_group_agent_by_name($thrash1, $thrash2, $other, $thrash3) if (is_metaconsole()) { $servers = db_get_all_rows_sql( 'SELECT * - FROM tmetaconsole_setup - WHERE disabled = 0' + FROM tmetaconsole_setup + WHERE disabled = 0' ); if ($servers === false) { @@ -2755,9 +2800,9 @@ function api_get_id_group_agent_by_name($thrash1, $thrash2, $other, $thrash3) if ($agent_id) { $sql = sprintf( 'SELECT groups.id_grupo id_group - FROM tagente agents, tgrupo groups - WHERE id_agente = %d - AND agents.id_grupo = groups.id_grupo', + FROM tagente agents, tgrupo groups + WHERE id_agente = %d + AND agents.id_grupo = groups.id_grupo', $agent_id ); $group_server_names = db_get_all_rows_sql($sql); @@ -2781,9 +2826,9 @@ function api_get_id_group_agent_by_name($thrash1, $thrash2, $other, $thrash3) $sql = sprintf( 'SELECT groups.id_grupo id_group - FROM tagente agents, tgrupo groups - WHERE id_agente = %d - AND agents.id_grupo = groups.id_grupo', + FROM tagente agents, tgrupo groups + WHERE id_agente = %d + AND agents.id_grupo = groups.id_grupo', $agent_id ); $group_names = db_get_all_rows_sql($sql); @@ -2833,8 +2878,8 @@ function api_get_id_group_agent_by_alias($thrash1, $thrash2, $other, $thrash3) if (is_metaconsole()) { $servers = db_get_all_rows_sql( 'SELECT * - FROM tmetaconsole_setup - WHERE disabled = 0' + FROM tmetaconsole_setup + WHERE disabled = 0' ); if ($servers === false) { @@ -2849,9 +2894,9 @@ function api_get_id_group_agent_by_alias($thrash1, $thrash2, $other, $thrash3) foreach ($agent_id as &$id) { $sql = sprintf( 'SELECT groups.id_grupo id_group - FROM tagente agents, tgrupo groups - WHERE id_agente = %d - AND agents.id_grupo = groups.id_grupo', + FROM tagente agents, tgrupo groups + WHERE id_agente = %d + AND agents.id_grupo = groups.id_grupo', $id['id_agente'] ); $group_server_names = db_get_all_rows_sql($sql); @@ -2877,9 +2922,9 @@ function api_get_id_group_agent_by_alias($thrash1, $thrash2, $other, $thrash3) $sql = sprintf( 'SELECT groups.id_grupo id_group - FROM tagente agents, tgrupo groups - WHERE id_agente = %d - AND agents.id_grupo = groups.id_grupo', + FROM tagente agents, tgrupo groups + WHERE id_agente = %d + AND agents.id_grupo = groups.id_grupo', $id['id_agente'] ); $group_name = db_get_all_rows_sql($sql); @@ -2937,8 +2982,8 @@ function api_get_policies($thrash1, $thrash2, $other, $thrash3) $sql = sprintf( 'SELECT policy.id, name, id_agent - FROM tpolicies AS policy, tpolicy_agents AS pol_agents - WHERE policy.id = pol_agents.id_policy %s AND id_group IN (%s)', + FROM tpolicies AS policy, tpolicy_agents AS pol_agents + WHERE policy.id = pol_agents.id_policy %s AND id_group IN (%s)', $where, $user_groups ); @@ -3036,12 +3081,22 @@ function api_set_create_network_module($id, $thrash1, $other, $thrash3) return; } - $agentName = $id; + $agent_by_alias = false; - $idAgent = agents_get_agent_id($agentName); + if ($other['data'][30] === '1') { + $agent_by_alias = true; + } - if (!util_api_check_agent_and_print_error($idAgent, 'string', 'AW')) { - return; + if ($agent_by_alias) { + $idsAgents = agents_get_agent_id_by_alias($id); + } else { + $idAgent = agents_get_agent_id($id); + } + + if (!$agent_by_alias) { + if (!util_api_check_agent_and_print_error($idAgent, 'string', 'AW')) { + return; + } } if ($other['data'][2] < 6 or $other['data'][2] > 18) { @@ -3059,7 +3114,6 @@ function api_set_create_network_module($id, $thrash1, $other, $thrash3) $disabled_types_event = json_encode($disabled_types_event); $values = [ - 'id_agente' => $idAgent, 'disabled' => $other['data'][1], 'id_tipo_modulo' => $other['data'][2], 'id_module_group' => $other['data'][3], @@ -3102,7 +3156,27 @@ function api_set_create_network_module($id, $thrash1, $other, $thrash3) // Column 'module_macros' cannot be null } - $idModule = modules_create_agent_module($idAgent, $name, $values, true); + if ($agent_by_alias) { + $agents_affected = 0; + + foreach ($idsAgents as $id) { + if (!util_api_check_agent_and_print_error($id['id_agente'], 'string', 'AW')) { + continue; + } + + $idModule = modules_create_agent_module($id['id_agente'], $name, $values, true); + + if (!is_error($idModule)) { + $agents_affected++; + } + } + + returnData('string', ['type' => 'string', 'data' => $agents_affected.' agents affected']); + + return; + } else { + $idModule = modules_create_agent_module($idAgent, $name, $values, true); + } if (is_error($idModule)) { // TODO: Improve the error returning more info @@ -3270,17 +3344,27 @@ function api_set_create_plugin_module($id, $thrash1, $other, $thrash3) return; } - $agentName = $id; - if ($other['data'][22] == '') { returnError('error_create_plugin_module', __('Error in creation plugin module. Id_plugin cannot be left blank.')); return; } - $idAgent = agents_get_agent_id($agentName); + $agent_by_alias = false; - if (!util_api_check_agent_and_print_error($idAgent, 'string', 'AW')) { - return; + if ($other['data'][36] === '1') { + $agent_by_alias = true; + } + + if ($agent_by_alias) { + $idsAgents = agents_get_agent_id_by_alias($id); + } else { + $idAgent = agents_get_agent_id($id); + } + + if (!$agent_by_alias) { + if (!util_api_check_agent_and_print_error($idAgent, 'string', 'AW')) { + return; + } } $disabled_types_event = []; @@ -3290,7 +3374,6 @@ function api_set_create_plugin_module($id, $thrash1, $other, $thrash3) $name = $other['data'][0]; $values = [ - 'id_agente' => $idAgent, 'disabled' => $other['data'][1], 'id_tipo_modulo' => $other['data'][2], 'id_module_group' => $other['data'][3], @@ -3338,7 +3421,27 @@ function api_set_create_plugin_module($id, $thrash1, $other, $thrash3) // Column 'module_macros' cannot be null } - $idModule = modules_create_agent_module($idAgent, $name, $values, true); + if ($agent_by_alias) { + $agents_affected = 0; + + foreach ($idsAgents as $id) { + if (!util_api_check_agent_and_print_error($id['id_agente'], 'string', 'AW')) { + continue; + } + + $idModule = modules_create_agent_module($id['id_agente'], $name, $values, true); + + if (!is_error($idModule)) { + $agents_affected++; + } + } + + returnData('string', ['type' => 'string', 'data' => $agents_affected.' agents affected']); + + return; + } else { + $idModule = modules_create_agent_module($idAgent, $name, $values, true); + } if (is_error($idModule)) { // TODO: Improve the error returning more info @@ -3499,17 +3602,27 @@ function api_set_create_data_module($id, $thrash1, $other, $thrash3) return; } - $agentName = $id; - if ($other['data'][0] == '') { returnError('error_create_data_module', __('Error in creation data module. Module_name cannot be left blank.')); return; } - $idAgent = agents_get_agent_id($agentName); + $agent_by_alias = false; - if (!util_api_check_agent_and_print_error($idAgent, 'string', 'AW')) { - return; + if ($other['data'][27] === '1') { + $agent_by_alias = true; + } + + if ($agent_by_alias) { + $idsAgents = agents_get_agent_id_by_alias($id); + } else { + $idAgent = agents_get_agent_id($id); + } + + if (!$agent_by_alias) { + if (!util_api_check_agent_and_print_error($idAgent, 'string', 'AW')) { + return; + } } $name = $other['data'][0]; @@ -3519,7 +3632,6 @@ function api_set_create_data_module($id, $thrash1, $other, $thrash3) $disabled_types_event = json_encode($disabled_types_event); $values = [ - 'id_agente' => $idAgent, 'disabled' => $other['data'][1], 'id_tipo_modulo' => $other['data'][2], 'descripcion' => $other['data'][3], @@ -3558,7 +3670,27 @@ function api_set_create_data_module($id, $thrash1, $other, $thrash3) // Column 'module_macros' cannot be null } - $idModule = modules_create_agent_module($idAgent, $name, $values, true); + if ($agent_by_alias) { + $agents_affected = 0; + + foreach ($idsAgents as $id) { + if (!util_api_check_agent_and_print_error($id['id_agente'], 'string', 'AW')) { + continue; + } + + $idModule = modules_create_agent_module($id['id_agente'], $name, $values, true); + + if (!is_error($idModule)) { + $agents_affected++; + } + } + + returnData('string', ['type' => 'string', 'data' => $agents_affected.' agents affected']); + + return; + } else { + $idModule = modules_create_agent_module($idAgent, $name, $values, true); + } if (is_error($idModule)) { // TODO: Improve the error returning more info @@ -3583,7 +3715,7 @@ function api_set_create_data_module($id, $thrash1, $other, $thrash3) * * @param $thrash3 Don't use */ -function api_set_create_synthetic_module($id, $thrash1, $other, $thrash3) +function api_set_create_synthetic_module($id, $agent_by_alias, $other, $thrash3) { if (defined('METACONSOLE')) { return; @@ -3591,8 +3723,6 @@ function api_set_create_synthetic_module($id, $thrash1, $other, $thrash3) global $config; - $agentName = $id; - io_safe_input_array($other); if ($other['data'][0] == '') { @@ -3600,15 +3730,34 @@ function api_set_create_synthetic_module($id, $thrash1, $other, $thrash3) return; } - $idAgent = agents_get_agent_id(io_safe_output($agentName), true); + if ($agent_by_alias == '1') { + $ids_agents = agents_get_agent_id_by_alias(io_safe_output($id)); - if (!util_api_check_agent_and_print_error($idAgent, 'string', 'AW')) { - return; + foreach ($ids_agents as $id) { + if (!util_api_check_agent_and_print_error($id['id_agente'], 'string', 'AW')) { + return; + } + } + } else { + $idAgent = agents_get_agent_id(io_safe_output($id), true); + + if (!util_api_check_agent_and_print_error($idAgent, 'string', 'AW')) { + return; + } } - if (!$idAgent) { - returnError('error_create_data_module', __('Error in creation synthetic module. Agent name doesn\'t exist.')); - return; + if ($agent_by_alias) { + foreach ($ids_agents as $id) { + if (!$id['id_agente']) { + returnError('error_create_data_module', __('Error in creation synthetic module. Agent name doesn\'t exist.')); + return; + } + } + } else { + if (!$idAgent) { + returnError('error_create_data_module', __('Error in creation synthetic module. Agent name doesn\'t exist.')); + return; + } } $name = io_safe_output($other['data'][0]); @@ -3616,7 +3765,6 @@ function api_set_create_synthetic_module($id, $thrash1, $other, $thrash3) $id_tipo_modulo = db_get_row_sql("SELECT id_tipo FROM ttipo_modulo WHERE nombre = 'generic_data'"); $values = [ - 'id_agente' => $idAgent, 'id_modulo' => 5, 'custom_integer_1' => 0, 'custom_integer_2' => 0, @@ -3629,151 +3777,312 @@ function api_set_create_synthetic_module($id, $thrash1, $other, $thrash3) // Column 'descripcion' cannot be null } - $idModule = modules_create_agent_module($idAgent, $name, $values, true); + if ($agent_by_alias) { + foreach ($ids_agents as $id) { + $idAgent = $id['id_agente']; - if (is_error($idModule)) { - // TODO: Improve the error returning more info - returnError('error_create_data_module', __('Error in creation data module.')); - } else { - $synthetic_type = $other['data'][1]; - unset($other['data'][0]); - unset($other['data'][1]); + $idModule = modules_create_agent_module($idAgent, $name, $values, true); - $filterdata = []; - foreach ($other['data'] as $data) { - $data = str_replace(['ADD', 'SUB', 'MUL', 'DIV'], ['+', '-', '*', '/'], $data); - $split_data = explode(';', $data); + if (is_error($idModule)) { + // TODO: Improve the error returning more info + returnError('error_create_data_module', __('Error in creation data module.')); + } else { + $synthetic_type = $other['data'][1]; + unset($other['data'][0]); + unset($other['data'][1]); - if (preg_match('/[x\/+*-]/', $split_data[0]) && strlen($split_data[0]) == 1) { - if (preg_match('/[\/|+|*|-]/', $split_data[0]) && $synthetic_type === 'average') { - returnError('', "[ERROR] With this type: $synthetic_type only be allow use this operator: 'x' \n\n"); + $filterdata = []; + foreach ($other['data'] as $data) { + $data = str_replace(['ADD', 'SUB', 'MUL', 'DIV'], ['+', '-', '*', '/'], $data); + $data = io_safe_output($data); + // Double safe output is necessary. + $split_data = explode(';', io_safe_output($data)); + + if (preg_match('/[x\/+*-]/', $split_data[0]) && strlen($split_data[0]) == 1) { + if (preg_match('/[\/|+|*|-]/', $split_data[0]) && $synthetic_type === 'average') { + returnError('', "[ERROR] With this type: $synthetic_type only be allow use this operator: 'x' \n\n"); + } + + $operator = strtolower($split_data[0]); + $data_module = [ + '', + $operator, + $split_data[1], + ]; + + $text_data = implode('_', $data_module); + array_push($filterdata, $text_data); + } else { + if (count($split_data) == 2) { + $idAgent = agents_get_agent_id($split_data[0], true); + $data_module = [ + $idAgent, + '', + $split_data[1], + ]; + $text_data = implode('_', $data_module); + array_push($filterdata, $text_data); + } else { + if (strlen($split_data[1]) > 1 && $synthetic_type != 'average') { + returnError('', "[ERROR] You can only use +, -, *, / or x, and you use this: @split_data[1] \n\n"); + return; + } + + if (preg_match('/[\/|+|*|-]/', $split_data[1]) && $synthetic_type === 'average') { + returnError('', "[ERROR] With this type: $synthetic_type only be allow use this operator: 'x' \n\n"); + return; + } + + $idAgent = agents_get_agent_id(io_safe_output($split_data[0]), true); + $operator = strtolower($split_data[1]); + $data_module = [ + $idAgent, + $operator, + $split_data[2], + ]; + $text_data = implode('_', $data_module); + array_push($filterdata, $text_data); + } + } } - $operator = strtolower($split_data[0]); - $data_module = [ - '', - $operator, - $split_data[1], - ]; + $serialize_ops = implode(',', $filterdata); - $text_data = implode('_', $data_module); - array_push($filterdata, $text_data); - } else { - if (count($split_data) == 2) { - $idAgent = agents_get_agent_id(io_safe_output($split_data[0]), true); - $data_module = [ - $idAgent, - '', - $split_data[1], - ]; - $text_data = implode('_', $data_module); - array_push($filterdata, $text_data); + // modules_create_synthetic_operations + $synthetic = enterprise_hook( + 'modules_create_synthetic_operations', + [ + $idModule, + $serialize_ops, + ] + ); + + if ($synthetic === ENTERPRISE_NOT_HOOK) { + returnError('error_synthetic_modules', 'Error Synthetic modules.'); + db_process_sql_delete( + 'tagente_modulo', + ['id_agente_modulo' => $idModule] + ); + + return; } else { - if (strlen($split_data[1]) > 1 && $synthetic_type != 'average') { - returnError('', "[ERROR] You can only use +, -, *, / or x, and you use this: @split_data[1] \n\n"); - return; + $status = AGENT_MODULE_STATUS_NO_DATA; + switch ($config['dbtype']) { + case 'mysql': + $result = db_process_sql_insert( + 'tagente_estado', + [ + 'id_agente_modulo' => $idModule, + 'datos' => 0, + 'timestamp' => '01-01-1970 00:00:00', + 'estado' => $status, + 'id_agente' => (int) $idAgent, + 'utimestamp' => 0, + 'status_changes' => 0, + 'last_status' => $status, + 'last_known_status' => $status, + ] + ); + break; + + case 'postgresql': + $result = db_process_sql_insert( + 'tagente_estado', + [ + 'id_agente_modulo' => $idModule, + 'datos' => 0, + 'timestamp' => null, + 'estado' => $status, + 'id_agente' => (int) $idAgent, + 'utimestamp' => 0, + 'status_changes' => 0, + 'last_status' => $status, + 'last_known_status' => $status, + ] + ); + break; + + case 'oracle': + $result = db_process_sql_insert( + 'tagente_estado', + [ + 'id_agente_modulo' => $idModule, + 'datos' => 0, + 'timestamp' => '#to_date(\'1970-01-01 00:00:00\', \'YYYY-MM-DD HH24:MI:SS\')', + 'estado' => $status, + 'id_agente' => (int) $idAgent, + 'utimestamp' => 0, + 'status_changes' => 0, + 'last_status' => $status, + 'last_known_status' => $status, + ] + ); + break; } - if (preg_match('/[\/|+|*|-]/', $split_data[1]) && $synthetic_type === 'average') { - returnError('', "[ERROR] With this type: $synthetic_type only be allow use this operator: 'x' \n\n"); - return; + if ($result === false) { + db_process_sql_delete( + 'tagente_modulo', + ['id_agente_modulo' => $idModule] + ); + returnError('error_synthetic_modules', 'Error Synthetic modules.'); + } else { + db_process_sql('UPDATE tagente SET total_count=total_count+1, notinit_count=notinit_count+1 WHERE id_agente='.(int) $idAgent); + returnData('string', ['type' => 'string', 'data' => __('Synthetic module created ID: '.$idModule)]); } - - $idAgent = agents_get_agent_id(io_safe_output($split_data[0]), true); - $operator = strtolower($split_data[1]); - $data_module = [ - $idAgent, - $operator, - $split_data[2], - ]; - $text_data = implode('_', $data_module); - array_push($filterdata, $text_data); } } } + } else { + $idModule = modules_create_agent_module($idAgent, $name, $values, true); - $serialize_ops = implode(',', $filterdata); - - // modules_create_synthetic_operations - $synthetic = enterprise_hook( - 'modules_create_synthetic_operations', - [ - $idModule, - $serialize_ops, - ] - ); - - if ($synthetic === ENTERPRISE_NOT_HOOK) { - returnError('error_synthetic_modules', 'Error Synthetic modules.'); - db_process_sql_delete( - 'tagente_modulo', - ['id_agente_modulo' => $idModule] - ); - return; + if (is_error($idModule)) { + // TODO: Improve the error returning more info + returnError('error_create_data_module', __('Error in creation data module.')); } else { - $status = AGENT_MODULE_STATUS_NO_DATA; - switch ($config['dbtype']) { - case 'mysql': - $result = db_process_sql_insert( - 'tagente_estado', - [ - 'id_agente_modulo' => $idModule, - 'datos' => 0, - 'timestamp' => '01-01-1970 00:00:00', - 'estado' => $status, - 'id_agente' => (int) $idAgent, - 'utimestamp' => 0, - 'status_changes' => 0, - 'last_status' => $status, - 'last_known_status' => $status, - ] - ); - break; + $synthetic_type = $other['data'][1]; + unset($other['data'][0]); + unset($other['data'][1]); - case 'postgresql': - $result = db_process_sql_insert( - 'tagente_estado', - [ - 'id_agente_modulo' => $idModule, - 'datos' => 0, - 'timestamp' => null, - 'estado' => $status, - 'id_agente' => (int) $idAgent, - 'utimestamp' => 0, - 'status_changes' => 0, - 'last_status' => $status, - 'last_known_status' => $status, - ] - ); - break; + $filterdata = []; + foreach ($other['data'] as $data) { + $data = str_replace(['ADD', 'SUB', 'MUL', 'DIV'], ['+', '-', '*', '/'], $data); + $data = io_safe_output($data); + // Double safe output is necessary. + $split_data = explode(';', io_safe_output($data)); - case 'oracle': - $result = db_process_sql_insert( - 'tagente_estado', - [ - 'id_agente_modulo' => $idModule, - 'datos' => 0, - 'timestamp' => '#to_date(\'1970-01-01 00:00:00\', \'YYYY-MM-DD HH24:MI:SS\')', - 'estado' => $status, - 'id_agente' => (int) $idAgent, - 'utimestamp' => 0, - 'status_changes' => 0, - 'last_status' => $status, - 'last_known_status' => $status, - ] - ); - break; + if (preg_match('/[x\/+*-]/', $split_data[0]) && strlen($split_data[0]) == 1) { + if (preg_match('/[\/|+|*|-]/', $split_data[0]) && $synthetic_type === 'average') { + returnError('', "[ERROR] With this type: $synthetic_type only be allow use this operator: 'x' \n\n"); + } + + $operator = strtolower($split_data[0]); + $data_module = [ + '', + $operator, + $split_data[1], + ]; + + $text_data = implode('_', $data_module); + array_push($filterdata, $text_data); + } else { + if (count($split_data) == 2) { + $idAgent = agents_get_agent_id($split_data[0], true); + $data_module = [ + $idAgent, + '', + $split_data[1], + ]; + $text_data = implode('_', $data_module); + array_push($filterdata, $text_data); + } else { + if (strlen($split_data[1]) > 1 && $synthetic_type != 'average') { + returnError('', "[ERROR] You can only use +, -, *, / or x, and you use this: @split_data[1] \n\n"); + return; + } + + if (preg_match('/[\/|+|*|-]/', $split_data[1]) && $synthetic_type === 'average') { + returnError('', "[ERROR] With this type: $synthetic_type only be allow use this operator: 'x' \n\n"); + return; + } + + $idAgent = agents_get_agent_id(io_safe_output($split_data[0]), true); + $operator = strtolower($split_data[1]); + $data_module = [ + $idAgent, + $operator, + $split_data[2], + ]; + $text_data = implode('_', $data_module); + array_push($filterdata, $text_data); + } + } } - if ($result === false) { + $serialize_ops = implode(',', $filterdata); + + // modules_create_synthetic_operations + $synthetic = enterprise_hook( + 'modules_create_synthetic_operations', + [ + $idModule, + $serialize_ops, + ] + ); + + if ($synthetic === ENTERPRISE_NOT_HOOK) { + returnError('error_synthetic_modules', 'Error Synthetic modules.'); db_process_sql_delete( 'tagente_modulo', ['id_agente_modulo' => $idModule] ); - returnError('error_synthetic_modules', 'Error Synthetic modules.'); + + return; } else { - db_process_sql('UPDATE tagente SET total_count=total_count+1, notinit_count=notinit_count+1 WHERE id_agente='.(int) $idAgent); - returnData('string', ['type' => 'string', 'data' => __('Synthetic module created ID: '.$idModule)]); + $status = AGENT_MODULE_STATUS_NO_DATA; + switch ($config['dbtype']) { + case 'mysql': + $result = db_process_sql_insert( + 'tagente_estado', + [ + 'id_agente_modulo' => $idModule, + 'datos' => 0, + 'timestamp' => '01-01-1970 00:00:00', + 'estado' => $status, + 'id_agente' => (int) $idAgent, + 'utimestamp' => 0, + 'status_changes' => 0, + 'last_status' => $status, + 'last_known_status' => $status, + ] + ); + break; + + case 'postgresql': + $result = db_process_sql_insert( + 'tagente_estado', + [ + 'id_agente_modulo' => $idModule, + 'datos' => 0, + 'timestamp' => null, + 'estado' => $status, + 'id_agente' => (int) $idAgent, + 'utimestamp' => 0, + 'status_changes' => 0, + 'last_status' => $status, + 'last_known_status' => $status, + ] + ); + break; + + case 'oracle': + $result = db_process_sql_insert( + 'tagente_estado', + [ + 'id_agente_modulo' => $idModule, + 'datos' => 0, + 'timestamp' => '#to_date(\'1970-01-01 00:00:00\', \'YYYY-MM-DD HH24:MI:SS\')', + 'estado' => $status, + 'id_agente' => (int) $idAgent, + 'utimestamp' => 0, + 'status_changes' => 0, + 'last_status' => $status, + 'last_known_status' => $status, + ] + ); + break; + } + + if ($result === false) { + db_process_sql_delete( + 'tagente_modulo', + ['id_agente_modulo' => $idModule] + ); + returnError('error_synthetic_modules', 'Error Synthetic modules.'); + } else { + db_process_sql('UPDATE tagente SET total_count=total_count+1, notinit_count=notinit_count+1 WHERE id_agente='.(int) $idAgent); + returnData('string', ['type' => 'string', 'data' => __('Synthetic module created ID: '.$idModule)]); + } } } } @@ -3923,8 +4232,6 @@ function api_set_create_snmp_module($id, $thrash1, $other, $thrash3) return; } - $agentName = $id; - if ($other['data'][0] == '') { returnError('error_create_snmp_module', __('Error in creation SNMP module. Module_name cannot be left blank.')); return; @@ -3935,10 +4242,22 @@ function api_set_create_snmp_module($id, $thrash1, $other, $thrash3) return; } - $idAgent = agents_get_agent_id($agentName); + $agent_by_alias = false; - if (!util_api_check_agent_and_print_error($idAgent, 'string', 'AW')) { - return; + if ($other['data'][35] === '1') { + $agent_by_alias = true; + } + + if ($agent_by_alias) { + $idsAgents = agents_get_agent_id_by_alias($id); + } else { + $idAgent = agents_get_agent_id($id); + } + + if (!$agent_by_alias) { + if (!util_api_check_agent_and_print_error($idAgent, 'string', 'AW')) { + return; + } } $name = $other['data'][0]; @@ -3965,7 +4284,6 @@ function api_set_create_snmp_module($id, $thrash1, $other, $thrash3) } $values = [ - 'id_agente' => $idAgent, 'disabled' => $other['data'][1], 'id_tipo_modulo' => $other['data'][2], 'id_module_group' => $other['data'][3], @@ -4003,7 +4321,6 @@ function api_set_create_snmp_module($id, $thrash1, $other, $thrash3) ]; } else { $values = [ - 'id_agente' => $idAgent, 'disabled' => $other['data'][1], 'id_tipo_modulo' => $other['data'][2], 'id_module_group' => $other['data'][3], @@ -4040,7 +4357,27 @@ function api_set_create_snmp_module($id, $thrash1, $other, $thrash3) // Column 'descripcion' cannot be null } - $idModule = modules_create_agent_module($idAgent, $name, $values, true); + if ($agent_by_alias) { + $agents_affected = 0; + + foreach ($idsAgents as $id) { + if (!util_api_check_agent_and_print_error($id['id_agente'], 'string', 'AW')) { + continue; + } + + $idModule = modules_create_agent_module($id['id_agente'], $name, $values, true); + + if (!is_error($idModule)) { + $agents_affected++; + } + } + + returnData('string', ['type' => 'string', 'data' => $agents_affected.' agents affected']); + + return; + } else { + $idModule = modules_create_agent_module($idAgent, $name, $values, true); + } if (is_error($idModule)) { // TODO: Improve the error returning more info @@ -4743,9 +5080,9 @@ function api_get_module_value_all_agents($id, $thrash1, $other, $thrash2) $sql = sprintf( "SELECT agent.id_agente, agent.alias, module_state.datos, agent.nombre - FROM tagente agent LEFT JOIN tagent_secondary_group tasg ON agent.id_agente = tasg.id_agent, tagente_modulo module, tagente_estado module_state - WHERE agent.id_agente = module.id_agente AND module.id_agente_modulo=module_state.id_agente_modulo AND module.nombre = '%s' - AND %s", + FROM tagente agent LEFT JOIN tagent_secondary_group tasg ON agent.id_agente = tasg.id_agent, tagente_modulo module, tagente_estado module_state + WHERE agent.id_agente = module.id_agente AND module.id_agente_modulo=module_state.id_agente_modulo AND module.nombre = '%s' + AND %s", $id, $groups ); @@ -5372,20 +5709,48 @@ function api_get_plugins($thrash1, $thrash2, $other, $thrash3) * @param $thrash1 Don't use * @param $thrash2 Don't use */ -function api_set_create_network_module_from_component($agent_name, $component_name, $thrash1, $thrash2) +function api_set_create_network_module_from_component($agent_name, $component_name, $other, $thrash2) { if (defined('METACONSOLE')) { return; } - $agent_id = agents_get_agent_id($agent_name); - if (!util_api_check_agent_and_print_error($agent_id, 'string', 'AW')) { - return; + $agent_by_alias = false; + + if ($other['data'][0] === '1') { + $agent_by_alias = true; } - if (!$agent_id) { - returnError('error_network_module_from_component', __('Error creating module from network component. Agent doesn\'t exist.')); - return; + if ($agent_by_alias) { + $ids_agents = agents_get_agent_id_by_alias($agent_name); + } else { + $agent_id = agents_get_agent_id($agent_name); + } + + if ($agent_by_alias) { + foreach ($ids_agents as $id) { + if (!util_api_check_agent_and_print_error($id['id_agente'], 'string', 'AW')) { + return; + } + } + } else { + if (!util_api_check_agent_and_print_error($agent_id, 'string', 'AW')) { + return; + } + } + + if ($agent_by_alias) { + foreach ($ids_agents as $id) { + if (!$id['id_agente']) { + returnError('error_network_module_from_component', __('Error creating module from network component. Agent doesn\'t exist.')); + return; + } + } + } else { + if (!$agent_id) { + returnError('error_network_module_from_component', __('Error creating module from network component. Agent doesn\'t exist.')); + return; + } } $component = db_get_row('tnetwork_component', 'name', $component_name); @@ -5406,14 +5771,29 @@ function api_set_create_network_module_from_component($agent_name, $component_na $component['ip_target'] = agents_get_address($agent_id); // Create module - $module_id = modules_create_agent_module($agent_id, $component_name, $component, true); + if ($agent_by_alias) { + $agents_affected = 0; - if (!$module_id) { - returnError('error_network_module_from_component', __('Error creating module from network component. Error creating module.')); + foreach ($ids_agents as $id) { + $module_id = modules_create_agent_module($id['id_agente'], $component_name, $component, true); + + if ($module_id) { + $agents_affected++; + } + } + + returnData('string', ['type' => 'string', 'data' => __('%d agents affected', $agents_affected)]); return; - } + } else { + $module_id = modules_create_agent_module($agent_id, $component_name, $component, true); - return $module_id; + if (!$module_id) { + returnError('error_network_module_from_component', __('Error creating module from network component. Error creating module.')); + return; + } + + return $module_id; + } } @@ -5552,7 +5932,7 @@ function api_set_delete_module_template($id, $thrash1, $other, $thrash3) /** - * Delete an module assigned to a template. And return a message with the result of the operation. + * Delete a module assigned to a template and return a message with the result of the operation. * * @param $id Agent Name * @param $id2 Alert Template Name @@ -5573,11 +5953,6 @@ function api_set_delete_module_template_by_names($id, $id2, $other, $trash1) $result = 0; - if ($other['type'] != 'string') { - returnError('error_parameter', 'Error in the parameters.'); - return; - } - if (! check_acl($config['id_user'], 0, 'AD') && ! check_acl($config['id_user'], 0, 'LM') ) { @@ -5585,10 +5960,26 @@ function api_set_delete_module_template_by_names($id, $id2, $other, $trash1) return; } - $idAgent = agents_get_agent_id($id); + $agent_by_alias = false; - if (!util_api_check_agent_and_print_error($idAgent, 'string', 'AD')) { - return; + if ($other['data'][1] === '1') { + $agent_by_alias = true; + } + + if ($agent_by_alias) { + $idsAgents = agents_get_agent_id_by_alias($id); + + foreach ($idsAgents as $id) { + if (!util_api_check_agent_and_print_error($id['id_agente'], 'string', 'AD')) { + return; + } + } + } else { + $idAgent = agents_get_agent_id($id); + + if (!util_api_check_agent_and_print_error($idAgent, 'string', 'AD')) { + return; + } } $row = db_get_row_filter('talert_templates', ['name' => $id2]); @@ -5601,25 +5992,50 @@ function api_set_delete_module_template_by_names($id, $id2, $other, $trash1) $idTemplate = $row['id']; $idActionTemplate = $row['id_alert_action']; - $idAgentModule = db_get_value_filter('id_agente_modulo', 'tagente_modulo', ['id_agente' => $idAgent, 'nombre' => $other['data']]); + $delete_count = 0; - if ($idAgentModule === false) { - returnError('error_parameter', 'Error in the parameters.'); - return; - } + if ($agent_by_alias) { + foreach ($idsAgents as $id) { + $idAgentModule = db_get_value_filter('id_agente_modulo', 'tagente_modulo', ['id_agente' => $id['id_agente'], 'nombre' => $other['data'][0]]); - $values = [ - 'id_agent_module' => $idAgentModule, - 'id_alert_template' => $idTemplate, - ]; + if ($idAgentModule === false) { + continue; + } - $result = db_process_sql_delete('talert_template_modules', $values); + $values = [ + 'id_agent_module' => $idAgentModule, + 'id_alert_template' => $idTemplate, + ]; - if ($result == 0) { - // TODO: Improve the error returning more info - returnError('error_delete_module_template_by_name', __('Error deleting module template.')); + $result = db_process_sql_delete('talert_template_modules', $values); + + if ($result != 0) { + $delete_count++; + } + } + + returnError('error_delete_module_template_by_name', __('Module template has been deleted in %d agents.', $delete_count)); } else { - returnData('string', ['type' => 'string', 'data' => __('Correct deleting of module template.')]); + $idAgentModule = db_get_value_filter('id_agente_modulo', 'tagente_modulo', ['id_agente' => $idAgent, 'nombre' => $other['data'][0]]); + + if ($idAgentModule === false) { + returnError('error_parameter', 'Error in the parameters1.'); + return; + } + + $values = [ + 'id_agent_module' => $idAgentModule, + 'id_alert_template' => $idTemplate, + ]; + + $result = db_process_sql_delete('talert_template_modules', $values); + + if ($result == 0) { + // TODO: Improve the error returning more info + returnError('error_delete_module_template_by_name', __('Error deleting module template.')); + } else { + returnData('string', ['type' => 'string', 'data' => __('Correct deleting of module template.')]); + } } } @@ -5662,15 +6078,15 @@ function api_set_validate_all_alerts($id, $thrash1, $other, $thrash3) $sql = sprintf( ' - SELECT talert_template_modules.id - FROM talert_template_modules - INNER JOIN tagente_modulo t2 - ON talert_template_modules.id_agent_module = t2.id_agente_modulo - INNER JOIN tagente t3 - ON t2.id_agente = t3.id_agente - INNER JOIN talert_templates t4 - ON talert_template_modules.id_alert_template = t4.id - WHERE t3.id_agente in (%s)', + SELECT talert_template_modules.id + FROM talert_template_modules + INNER JOIN tagente_modulo t2 + ON talert_template_modules.id_agent_module = t2.id_agente_modulo + INNER JOIN tagente t3 + ON t2.id_agente = t3.id_agente + INNER JOIN talert_templates t4 + ON talert_template_modules.id_alert_template = t4.id + WHERE t3.id_agente in (%s)', $agents_string ); @@ -5758,9 +6174,9 @@ function api_set_validate_all_policy_alerts($id, $thrash1, $other, $thrash3) if (count($result_pol_alerts) != 0) { $sql = sprintf( ' - SELECT id - FROM talert_template_modules - WHERE id_policy_alerts IN (%s)', + SELECT id + FROM talert_template_modules + WHERE id_policy_alerts IN (%s)', $id_pol_alerts ); @@ -6215,9 +6631,8 @@ function api_set_planned_downtimes_created($id, $thrash1, $other, $thrash3) return; } - $date_from = strtotime(html_entity_decode($other['data'][1])); - $date_to = strtotime(html_entity_decode($other['data'][2])); - + $date_from = strtotime(html_entity_decode($other['data'][1].' '.$other['data'][11])); + $date_to = strtotime(html_entity_decode($other['data'][2].' '.$other['data'][12])); $values = []; $values['name'] = $id; $values = [ @@ -7645,8 +8060,8 @@ function api_set_create_group($id, $thrash1, $other, $thrash3) if (defined('METACONSOLE')) { $servers = db_get_all_rows_sql( 'SELECT * - FROM tmetaconsole_setup - WHERE disabled = 0' + FROM tmetaconsole_setup + WHERE disabled = 0' ); if ($servers === false) { @@ -7935,10 +8350,10 @@ function api_get_module_data($id, $thrash1, $other, $returnType) $sql = sprintf( 'SELECT utimestamp, datos - FROM tagente_datos - WHERE id_agente_modulo = %d AND utimestamp > %d - AND utimestamp < %d - ORDER BY utimestamp DESC', + FROM tagente_datos + WHERE id_agente_modulo = %d AND utimestamp > %d + AND utimestamp < %d + ORDER BY utimestamp DESC', $id, $date_start, $date_end @@ -7947,17 +8362,17 @@ function api_get_module_data($id, $thrash1, $other, $returnType) if ($periodSeconds == null) { $sql = sprintf( 'SELECT utimestamp, datos - FROM tagente_datos - WHERE id_agente_modulo = %d - ORDER BY utimestamp DESC', + FROM tagente_datos + WHERE id_agente_modulo = %d + ORDER BY utimestamp DESC', $id ); } else { $sql = sprintf( 'SELECT utimestamp, datos - FROM tagente_datos - WHERE id_agente_modulo = %d AND utimestamp > %d - ORDER BY utimestamp DESC', + FROM tagente_datos + WHERE id_agente_modulo = %d AND utimestamp > %d + ORDER BY utimestamp DESC', $id, (get_system_time() - $periodSeconds) ); @@ -8276,7 +8691,7 @@ function api_set_enable_disable_user($id, $thrash2, $other, $thrash3) } -function otherParameter2Filter($other, $return_as_array=false) +function otherParameter2Filter($other, $return_as_array=false, $use_agent_name=false) { $filter = []; @@ -8284,14 +8699,28 @@ function otherParameter2Filter($other, $return_as_array=false) $filter['criticity'] = $other['data'][1]; } - $idAgent = null; if (isset($other['data'][2]) && $other['data'][2] != '') { - $idAgents = agents_get_agent_id_by_alias($other['data'][2]); + if ($use_agent_name === false) { + $idAgents = agents_get_agent_id_by_alias($other['data'][2]); - if (!empty($idAgent)) { - $filter[] = 'id_agente IN ('.explode(',', $idAgents).')'; + if (!empty($idAgents)) { + $idAgent = []; + foreach ($idAgents as $key => $value) { + $idAgent[] .= $value['id_agente']; + } + + $filter[] = 'id_agente IN ('.implode(',', $idAgent).')'; + } else { + $filter['sql'] = '1=0'; + } } else { - $filter['sql'] = '1=0'; + $idAgent = agents_get_agent_id($other['data'][2]); + + if (!empty($idAgent)) { + $filter[] = 'id_agente = '.$idAgent; + } else { + $filter['sql'] = '1=0'; + } } } @@ -8302,9 +8731,21 @@ function otherParameter2Filter($other, $return_as_array=false) $filterModule['id_agente'] = $idAgent; } - $idAgentModulo = db_get_value_filter('id_agente_modulo', 'tagente_modulo', $filterModule); - if ($idAgentModulo !== false) { - $filter['id_agentmodule'] = $idAgentModulo; + $idAgentModulo = db_get_all_rows_filter('tagente_modulo', $filterModule, 'id_agente_modulo'); + + if (!empty($idAgentModulo)) { + $id_agentmodule = []; + foreach ($idAgentModulo as $key => $value) { + $id_agentmodule[] .= $value['id_agente_modulo']; + } + + $idAgentModulo = $id_agentmodule; + if ($idAgentModulo !== false) { + $filter['id_agentmodule'] = $idAgentModulo; + } + } else { + // If the module doesn't exist or doesn't exist in that agent. + $filter['sql'] = '1=0'; } } @@ -8393,13 +8834,11 @@ function otherParameter2Filter($other, $return_as_array=false) if ($other['data'][12] == 'more_criticity') { $filter['more_criticity'] = true; } - } else { } } else { if ($return_as_array) { $filter['total'] = false; $filter['more_criticity'] = false; - } else { } } @@ -8407,7 +8846,7 @@ function otherParameter2Filter($other, $return_as_array=false) if ($return_as_array) { $filter['id_group'] = $other['data'][13]; } else { - $filterString .= ' AND id_grupo ='.$other['data'][13]; + $filterString .= ' AND id_grupo = '.$other['data'][13]; } } @@ -8427,7 +8866,7 @@ function otherParameter2Filter($other, $return_as_array=false) if ($event_type == 'not_normal') { $filterString .= " AND ( event_type LIKE '%warning%' - OR event_type LIKE '%critical%' OR event_type LIKE '%unknown%' ) "; + OR event_type LIKE '%critical%' OR event_type LIKE '%unknown%' ) "; } else { $filterString .= ' AND event_type LIKE "%'.$event_type.'%"'; } @@ -8463,48 +8902,91 @@ function api_set_new_alert_template($id, $id2, $other, $trash1) } if ($other['type'] == 'string') { - returnError('error_parameter', 'Error in the parameters.'); + returnError('error_parameter', 'Error in the parameters0.'); return; } else if ($other['type'] == 'array') { - $idAgent = agents_get_agent_id($id); + $agent_by_alias = false; - if (!util_api_check_agent_and_print_error($idAgent, 'string', 'AW')) { - return; + if ($other['data'][1] === '1') { + $agent_by_alias = true; + } + + if ($agent_by_alias) { + $idsAgents = agents_get_agent_id_by_alias($id); + } else { + $idAgent = agents_get_agent_id($id); + } + + if ($agent_by_alias) { + foreach ($idsAgents as $id) { + if (!util_api_check_agent_and_print_error($id['id_agente'], 'string', 'AW')) { + return; + } + } + } else { + if (!util_api_check_agent_and_print_error($idAgent, 'string', 'AW')) { + return; + } } $row = db_get_row_filter('talert_templates', ['name' => $id2]); if ($row === false) { - returnError('error_parameter', 'Error in the parameters.'); + returnError('error_parameter', 'Error in the parameters1.'); return; } $idTemplate = $row['id']; $idActionTemplate = $row['id_alert_action']; - $idAgentModule = db_get_value_filter('id_agente_modulo', 'tagente_modulo', ['id_agente' => $idAgent, 'nombre' => $other['data'][0]]); + $inserted_count = 0; - if ($idAgentModule === false) { - returnError('error_parameter', 'Error in the parameters.'); + if ($agent_by_alias) { + foreach ($idsAgents as $id) { + $idAgentModule = db_get_value_filter('id_agente_modulo', 'tagente_modulo', ['id_agente' => $id['id_agente'], 'nombre' => $other['data'][0]]); + + if ($idAgentModule === false) { + continue; + } + + $values = [ + 'id_agent_module' => $idAgentModule, + 'id_alert_template' => $idTemplate, + ]; + + $return = db_process_sql_insert('talert_template_modules', $values); + + if ($return != false) { + $inserted_count++; + } + } + + returnData('string', ['type' => 'string', 'data' => __('Template have been inserted in %d agents.', $inserted_count)]); + } else { + $idAgentModule = db_get_value_filter('id_agente_modulo', 'tagente_modulo', ['id_agente' => $idAgent, 'nombre' => $other['data'][0]]); + + if ($idAgentModule === false) { + returnError('error_parameter', 'Error in the parameter2s.'); + return; + } + + $values = [ + 'id_agent_module' => $idAgentModule, + 'id_alert_template' => $idTemplate, + ]; + + $return = db_process_sql_insert('talert_template_modules', $values); + + $data['type'] = 'string'; + if ($return === false) { + $data['data'] = 0; + } else { + $data['data'] = $return; + } + + returnData('string', $data); return; } - - $values = [ - 'id_agent_module' => $idAgentModule, - 'id_alert_template' => $idTemplate, - ]; - - $return = db_process_sql_insert('talert_template_modules', $values); - - $data['type'] = 'string'; - if ($return === false) { - $data['data'] = 0; - } else { - $data['data'] = $return; - } - - returnData('string', $data); - return; } } @@ -8515,18 +8997,61 @@ function api_set_delete_module($id, $id2, $other, $trash1) return; } - if ($other['type'] == 'string') { - $simulate = false; - if ($other['data'] == 'simulate') { - $simulate = true; - } + $simulate = false; + if ($other['data'][0] == 'simulate') { + $simulate = true; + } + $agent_by_alias = false; + + if ($other['data'][1] === '1') { + $agent_by_alias = true; + } + + if ($agent_by_alias) { + $idsAgents = agents_get_agent_id_by_alias($id); + } else { $idAgent = agents_get_agent_id($id); + } + if ($agent_by_alias) { + foreach ($idsAgents as $id) { + if (!util_api_check_agent_and_print_error($id['id_agente'], 'string', 'AD')) { + return; + } + } + } else { if (!util_api_check_agent_and_print_error($idAgent, 'string', 'AD')) { return; } + } + if ($agent_by_alias) { + foreach ($idsAgents as $id) { + $idAgentModule = db_get_value_filter('id_agente_modulo', 'tagente_modulo', ['id_agente' => $id['id_agente'], 'nombre' => $id2]); + + if ($idAgentModule === false) { + continue; + } + + if (!$simulate) { + $return = modules_delete_agent_module($idAgentModule); + } else { + $return = true; + } + + $data['type'] = 'string'; + if ($return === false) { + $data['data'] = 0; + } else { + $data['data'] = $return; + } + + returnData('string', $data); + } + + return; + } else { $idAgentModule = db_get_value_filter('id_agente_modulo', 'tagente_modulo', ['id_agente' => $idAgent, 'nombre' => $id2]); if ($idAgentModule === false) { @@ -8549,9 +9074,6 @@ function api_set_delete_module($id, $id2, $other, $trash1) returnData('string', $data); return; - } else { - returnError('error_parameter', 'Error in the parameters.'); - return; } } @@ -8582,14 +9104,14 @@ function api_set_module_data($id, $thrash2, $other, $trash1) $agent = db_get_row_filter('tagente', ['id_agente' => $agentModule['id_agente']]); $xmlTemplate = " - - - - - - - - "; + + + + + + + + "; $xml = sprintf( $xmlTemplate, @@ -8631,9 +9153,29 @@ function api_set_new_module($id, $id2, $other, $trash1) return; } else if ($other['type'] == 'array') { $values = []; - $values['id_agente'] = agents_get_agent_id($id); - if (!util_api_check_agent_and_print_error($values['id_agente'], 'string', 'AW')) { - return; + + $agent_by_alias = false; + + if ($other['data'][15] === '1') { + $agent_by_alias = true; + } + + if ($agent_by_alias) { + $idsAgents = agents_get_agent_id_by_alias($id); + } else { + $values['id_agente'] = agents_get_agent_id($id); + } + + if ($agent_by_alias) { + foreach ($idsAgents as $id) { + if (!util_api_check_agent_and_print_error($id['id_agente'], 'string', 'AW')) { + return; + } + } + } else { + if (!util_api_check_agent_and_print_error($values['id_agente'], 'string', 'AW')) { + return; + } } $values['nombre'] = $id2; @@ -8713,11 +9255,30 @@ function api_set_new_module($id, $id2, $other, $trash1) $values['id_modulo'] = 2; - $return = modules_create_agent_module( - $values['id_agente'], - $values['nombre'], - $values - ); + if ($agent_by_alias) { + $agents_module_created = 0; + + foreach ($idsAgents as $id) { + $return = modules_create_agent_module( + $id['id_agente'], + $values['nombre'], + $values + ); + + if ($return != false) { + $agents_module_created++; + } + } + + returnData('string', ['type' => 'string', 'data' => __('Module has been created in %d agents.', $agents_module_created)]); + return; + } else { + $return = modules_create_agent_module( + $values['id_agente'], + $values['nombre'], + $values + ); + } $data['type'] = 'string'; if ($return === false) { @@ -8753,66 +9314,133 @@ function api_set_alert_actions($id, $id2, $other, $trash1) } if ($other['type'] == 'string') { - returnError('error_parameter', 'Error in the parameters.'); + returnError('error_parameter', 'Error in the parameters0.'); return; } else if ($other['type'] == 'array') { - $idAgent = agents_get_agent_id($id); - if (!util_api_check_agent_and_print_error($idAgent, 'string', 'AW')) { - return; + $agent_by_alias = false; + + if ($other['data'][4] === '1') { + $agent_by_alias = true; + } + + if ($agent_by_alias) { + $idsAgents = agents_get_agent_id_by_alias($id); + } else { + $idAgent = agents_get_agent_id($id); + } + + if ($agent_by_alias) { + foreach ($idsAgents as $id) { + if (!util_api_check_agent_and_print_error($id['id_agente'], 'string', 'AW')) { + return; + } + } + } else { + if (!util_api_check_agent_and_print_error($idAgent, 'string', 'AW')) { + return; + } } $row = db_get_row_filter('talert_templates', ['name' => $id2]); if ($row === false) { - returnError('error_parameter', 'Error in the parameters.'); + returnError('error_parameter', 'Error in the parameters1.'); return; } $idTemplate = $row['id']; - $idAgentModule = db_get_value_filter('id_agente_modulo', 'tagente_modulo', ['id_agente' => $idAgent, 'nombre' => $other['data'][0]]); - if ($idAgentModule === false) { - returnError('error_parameter', 'Error in the parameters.'); - return; - } + if ($agent_by_alias) { + $actions_set = 0; - $idAlertTemplateModule = db_get_value_filter('id', 'talert_template_modules', ['id_alert_template' => $idTemplate, 'id_agent_module' => $idAgentModule]); - if ($idAlertTemplateModule === false) { - returnError('error_parameter', 'Error in the parameters.'); - return; - } + foreach ($idsAgents as $id) { + $idAgentModule = db_get_value_filter('id_agente_modulo', 'tagente_modulo', ['id_agente' => $id['id_agente'], 'nombre' => $other['data'][0]]); + if ($idAgentModule === false) { + continue; + } - if ($other['data'][1] != '') { - $idAction = db_get_value_filter('id', 'talert_actions', ['name' => $other['data'][1]]); - if ($idAction === false) { + $idAlertTemplateModule = db_get_value_filter('id', 'talert_template_modules', ['id_alert_template' => $idTemplate, 'id_agent_module' => $idAgentModule]); + if ($idAlertTemplateModule === false) { + returnError('error_parameter', 'Error in the parameters.'); + return; + } + + if ($other['data'][1] != '') { + $idAction = db_get_value_filter('id', 'talert_actions', ['name' => $other['data'][1]]); + if ($idAction === false) { + returnError('error_parameter', 'Error in the parameters.'); + return; + } + } else { + returnError('error_parameter', 'Error in the parameters.'); + return; + } + + $firesMin = $other['data'][2]; + $firesMax = $other['data'][3]; + + $values = [ + 'id_alert_template_module' => $idAlertTemplateModule, + 'id_alert_action' => $idAction, + 'fires_min' => $firesMin, + 'fires_max' => $firesMax, + ]; + + $return = db_process_sql_insert('talert_template_module_actions', $values); + + if ($return != false) { + $actions_set++; + } + } + + returnData('string', ['type' => 'string', 'data' => __('Action has been set for %d agents.', $actions_set)]); + + return; + } else { + $idAgentModule = db_get_value_filter('id_agente_modulo', 'tagente_modulo', ['id_agente' => $idAgent, 'nombre' => $other['data'][0]]); + if ($idAgentModule === false) { returnError('error_parameter', 'Error in the parameters.'); return; } - } else { - returnError('error_parameter', 'Error in the parameters.'); + + $idAlertTemplateModule = db_get_value_filter('id', 'talert_template_modules', ['id_alert_template' => $idTemplate, 'id_agent_module' => $idAgentModule]); + if ($idAlertTemplateModule === false) { + returnError('error_parameter', 'Error in the parameters.'); + return; + } + + if ($other['data'][1] != '') { + $idAction = db_get_value_filter('id', 'talert_actions', ['name' => $other['data'][1]]); + if ($idAction === false) { + returnError('error_parameter', 'Error in the parameters.'); + return; + } + } else { + returnError('error_parameter', 'Error in the parameters.'); + return; + } + + $firesMin = $other['data'][2]; + $firesMax = $other['data'][3]; + + $values = [ + 'id_alert_template_module' => $idAlertTemplateModule, + 'id_alert_action' => $idAction, + 'fires_min' => $firesMin, + 'fires_max' => $firesMax, + ]; + + $return = db_process_sql_insert('talert_template_module_actions', $values); + + $data['type'] = 'string'; + if ($return === false) { + $data['data'] = 0; + } else { + $data['data'] = $return; + } + + returnData('string', $data); return; } - - $firesMin = $other['data'][2]; - $firesMax = $other['data'][3]; - - $values = [ - 'id_alert_template_module' => $idAlertTemplateModule, - 'id_alert_action' => $idAction, - 'fires_min' => $firesMin, - 'fires_max' => $firesMax, - ]; - - $return = db_process_sql_insert('talert_template_module_actions', $values); - - $data['type'] = 'string'; - if ($return === false) { - $data['data'] = 0; - } else { - $data['data'] = $return; - } - - returnData('string', $data); - return; } } @@ -9141,11 +9769,11 @@ function api_set_new_event($trash1, $trash2, $other, $trash3) } else { $idAlert = db_get_value_sql( "SELECT t1.id - FROM talert_template_modules t1 - INNER JOIN talert_templates t2 - ON t1.id_alert_template = t2.id - WHERE t1.id_agent_module = 1 - AND t2.name LIKE '".$other['data'][7]."'" + FROM talert_template_modules t1 + INNER JOIN talert_templates t2 + ON t1.id_alert_template = t2.id + WHERE t1.id_agent_module = 1 + AND t2.name LIKE '".$other['data'][7]."'" ); if ($idAlert === false) { @@ -9299,7 +9927,9 @@ function api_set_event_validate_filter($trash1, $trash2, $other, $trash3) } } - $filterString = otherParameter2Filter($other); + $use_agent_name = ($other['data'][8] === '1') ? true : false; + + $filterString = otherParameter2Filter($other, false, $use_agent_name); if (!users_can_manage_group_all('EW')) { $user_groups = implode( @@ -9382,9 +10012,9 @@ function api_get_gis_agent($id_agent, $trash1, $tresh2, $return_type, $user_in_d $agent_gis_data = db_get_row_sql( ' - SELECT * - FROM tgis_data_status - WHERE tagente_id_agente = '.$id_agent + SELECT * + FROM tgis_data_status + WHERE tagente_id_agente = '.$id_agent ); if ($agent_gis_data) { @@ -9616,7 +10246,9 @@ function get_events_with_user($trash1, $trash2, $other, $returnType, $user_in_db $utimestamp_upper = 0; $utimestamp_bottom = 0; - $filter = otherParameter2Filter($other, true); + $use_agent_name = ($other['data'][16] === '1') ? true : false; + + $filter = otherParameter2Filter($other, true, $use_agent_name); if (isset($filter['criticity'])) { $severity = $filter['criticity']; @@ -9751,7 +10383,7 @@ function get_events_with_user($trash1, $trash2, $other, $returnType, $user_in_db $sql_post .= " AND event_type LIKE '%$event_type%' "; } else if ($event_type == 'not_normal') { $sql_post .= " AND ( event_type LIKE '%warning%' - OR event_type LIKE '%critical%' OR event_type LIKE '%unknown%' ) "; + OR event_type LIKE '%critical%' OR event_type LIKE '%unknown%' ) "; } else { $sql_post .= " AND event_type = '".$event_type."'"; } @@ -9810,48 +10442,48 @@ function get_events_with_user($trash1, $trash2, $other, $returnType, $user_in_db case 'mysql': if ($filter['total']) { $sql = 'SELECT COUNT(*) - FROM '.$table_events.' - WHERE 1=1 '.$sql_post; + FROM '.$table_events.' + WHERE 1=1 '.$sql_post; } else if ($filter['more_criticity']) { $sql = 'SELECT criticity - FROM '.$table_events.' - WHERE 1=1 '.$sql_post.' - ORDER BY criticity DESC - LIMIT 1'; + FROM '.$table_events.' + WHERE 1=1 '.$sql_post.' + ORDER BY criticity DESC + LIMIT 1'; } else { if (defined('METACONSOLE')) { $sql = 'SELECT *, - (SELECT t2.nombre - FROM tgrupo t2 - WHERE t2.id_grupo = '.$table_events.'.id_grupo) AS group_name, - (SELECT t2.icon - FROM tgrupo t2 - WHERE t2.id_grupo = '.$table_events.'.id_grupo) AS group_icon - FROM '.$table_events.' - WHERE 1=1 '.$sql_post.' - ORDER BY utimestamp DESC - LIMIT '.$offset.','.$pagination; + (SELECT t2.nombre + FROM tgrupo t2 + WHERE t2.id_grupo = '.$table_events.'.id_grupo) AS group_name, + (SELECT t2.icon + FROM tgrupo t2 + WHERE t2.id_grupo = '.$table_events.'.id_grupo) AS group_icon + FROM '.$table_events.' + WHERE 1=1 '.$sql_post.' + ORDER BY utimestamp DESC + LIMIT '.$offset.','.$pagination; } else { $sql = 'SELECT *, - (SELECT t1.alias - FROM tagente t1 - WHERE t1.id_agente = tevento.id_agente) AS agent_name, - (SELECT t2.nombre - FROM tgrupo t2 - WHERE t2.id_grupo = tevento.id_grupo) AS group_name, - (SELECT t2.icon - FROM tgrupo t2 - WHERE t2.id_grupo = tevento.id_grupo) AS group_icon, - (SELECT tmodule.name - FROM tmodule - WHERE id_module IN ( - SELECT tagente_modulo.id_modulo - FROM tagente_modulo - WHERE tagente_modulo.id_agente_modulo=tevento.id_agentmodule)) AS module_name - FROM '.$table_events.' - WHERE 1=1 '.$sql_post.' - ORDER BY utimestamp DESC - LIMIT '.$offset.','.$pagination; + (SELECT t1.alias + FROM tagente t1 + WHERE t1.id_agente = tevento.id_agente) AS agent_name, + (SELECT t2.nombre + FROM tgrupo t2 + WHERE t2.id_grupo = tevento.id_grupo) AS group_name, + (SELECT t2.icon + FROM tgrupo t2 + WHERE t2.id_grupo = tevento.id_grupo) AS group_icon, + (SELECT tmodule.name + FROM tmodule + WHERE id_module IN ( + SELECT tagente_modulo.id_modulo + FROM tagente_modulo + WHERE tagente_modulo.id_agente_modulo=tevento.id_agentmodule)) AS module_name + FROM '.$table_events.' + WHERE 1=1 '.$sql_post.' + ORDER BY utimestamp DESC + LIMIT '.$offset.','.$pagination; } } break; @@ -9859,25 +10491,25 @@ function get_events_with_user($trash1, $trash2, $other, $returnType, $user_in_db case 'postgresql': // TODO TOTAL $sql = 'SELECT *, - (SELECT t1.alias - FROM tagente t1 - WHERE t1.id_agente = tevento.id_agente) AS agent_name, - (SELECT t2.nombre - FROM tgrupo t2 - WHERE t2.id_grupo = tevento.id_grupo) AS group_name, - (SELECT t2.icon - FROM tgrupo t2 - WHERE t2.id_grupo = tevento.id_grupo) AS group_icon, - (SELECT tmodule.name - FROM tmodule - WHERE id_module IN ( - SELECT tagente_modulo.id_modulo - FROM tagente_modulo - WHERE tagente_modulo.id_agente_modulo=tevento.id_agentmodule)) AS module_name - FROM tevento - WHERE 1=1 '.$sql_post.' - ORDER BY utimestamp DESC - LIMIT '.$pagination.' OFFSET '.$offset; + (SELECT t1.alias + FROM tagente t1 + WHERE t1.id_agente = tevento.id_agente) AS agent_name, + (SELECT t2.nombre + FROM tgrupo t2 + WHERE t2.id_grupo = tevento.id_grupo) AS group_name, + (SELECT t2.icon + FROM tgrupo t2 + WHERE t2.id_grupo = tevento.id_grupo) AS group_icon, + (SELECT tmodule.name + FROM tmodule + WHERE id_module IN ( + SELECT tagente_modulo.id_modulo + FROM tagente_modulo + WHERE tagente_modulo.id_agente_modulo=tevento.id_agentmodule)) AS module_name + FROM tevento + WHERE 1=1 '.$sql_post.' + ORDER BY utimestamp DESC + LIMIT '.$pagination.' OFFSET '.$offset; break; case 'oracle': @@ -9887,26 +10519,26 @@ function get_events_with_user($trash1, $trash2, $other, $returnType, $user_in_db $set['offset'] = $offset; $sql = 'SELECT *, - (SELECT t1.alias - FROM tagente t1 - WHERE t1.id_agente = tevento.id_agente) AS alias, - (SELECT t1.nombre - FROM tagente t1 - WHERE t1.id_agente = tevento.id_agente) AS agent_name, - (SELECT t2.nombre - FROM tgrupo t2 - WHERE t2.id_grupo = tevento.id_grupo) AS group_name, - (SELECT t2.icon - FROM tgrupo t2 - WHERE t2.id_grupo = tevento.id_grupo) AS group_icon, - (SELECT tmodule.name - FROM tmodule - WHERE id_module IN ( - SELECT tagente_modulo.id_modulo - FROM tagente_modulo - WHERE tagente_modulo.id_agente_modulo=tevento.id_agentmodule)) AS module_name - FROM tevento - WHERE 1=1 '.$sql_post.' ORDER BY utimestamp DESC'; + (SELECT t1.alias + FROM tagente t1 + WHERE t1.id_agente = tevento.id_agente) AS alias, + (SELECT t1.nombre + FROM tagente t1 + WHERE t1.id_agente = tevento.id_agente) AS agent_name, + (SELECT t2.nombre + FROM tgrupo t2 + WHERE t2.id_grupo = tevento.id_grupo) AS group_name, + (SELECT t2.icon + FROM tgrupo t2 + WHERE t2.id_grupo = tevento.id_grupo) AS group_icon, + (SELECT tmodule.name + FROM tmodule + WHERE id_module IN ( + SELECT tagente_modulo.id_modulo + FROM tagente_modulo + WHERE tagente_modulo.id_agente_modulo=tevento.id_agentmodule)) AS module_name + FROM tevento + WHERE 1=1 '.$sql_post.' ORDER BY utimestamp DESC'; $sql = oracle_recode_query($sql, $set); break; } @@ -9916,26 +10548,26 @@ function get_events_with_user($trash1, $trash2, $other, $returnType, $user_in_db db_process_sql('SET group_concat_max_len = 9999999'); $sql = "SELECT *, MAX(id_evento) AS id_evento, - GROUP_CONCAT(DISTINCT user_comment SEPARATOR '') AS user_comment, - MIN(estado) AS min_estado, MAX(estado) AS max_estado, - COUNT(*) AS event_rep, MAX(utimestamp) AS timestamp_rep - FROM ".$table_events.' - WHERE 1=1 '.$sql_post.' - GROUP BY evento, id_agentmodule - ORDER BY timestamp_rep DESC - LIMIT '.$offset.','.$pagination; + GROUP_CONCAT(DISTINCT user_comment SEPARATOR '') AS user_comment, + MIN(estado) AS min_estado, MAX(estado) AS max_estado, + COUNT(*) AS event_rep, MAX(utimestamp) AS timestamp_rep + FROM ".$table_events.' + WHERE 1=1 '.$sql_post.' + GROUP BY evento, id_agentmodule + ORDER BY timestamp_rep DESC + LIMIT '.$offset.','.$pagination; break; case 'postgresql': $sql = "SELECT *, MAX(id_evento) AS id_evento, - array_to_string(array_agg(DISTINCT user_comment), '') AS user_comment, - MIN(estado) AS min_estado, MAX(estado) AS max_estado, - COUNT(*) AS event_rep, MAX(utimestamp) AS timestamp_rep - FROM ".$table_events.' - WHERE 1=1 '.$sql_post.' - GROUP BY evento, id_agentmodule - ORDER BY timestamp_rep DESC - LIMIT '.$pagination.' OFFSET '.$offset; + array_to_string(array_agg(DISTINCT user_comment), '') AS user_comment, + MIN(estado) AS min_estado, MAX(estado) AS max_estado, + COUNT(*) AS event_rep, MAX(utimestamp) AS timestamp_rep + FROM ".$table_events.' + WHERE 1=1 '.$sql_post.' + GROUP BY evento, id_agentmodule + ORDER BY timestamp_rep DESC + LIMIT '.$pagination.' OFFSET '.$offset; break; case 'oracle': @@ -9944,21 +10576,21 @@ function get_events_with_user($trash1, $trash2, $other, $returnType, $user_in_db $set['offset'] = $offset; // TODO: Remove duplicate user comments $sql = 'SELECT a.*, b.event_rep, b.timestamp_rep - FROM (SELECT * - FROM tevento - WHERE 1=1 '.$sql_post.") a, - (SELECT MAX (id_evento) AS id_evento, - to_char(evento) AS evento, id_agentmodule, - COUNT(*) AS event_rep, MIN(estado) AS min_estado, - MAX(estado) AS max_estado, - LISTAGG(user_comment, '') AS user_comment, - MAX(utimestamp) AS timestamp_rep - FROM ".$table_events.' - WHERE 1=1 '.$sql_post.' - GROUP BY to_char(evento), id_agentmodule) b - WHERE a.id_evento=b.id_evento AND - to_char(a.evento)=to_char(b.evento) AND - a.id_agentmodule=b.id_agentmodule'; + FROM (SELECT * + FROM tevento + WHERE 1=1 '.$sql_post.") a, + (SELECT MAX (id_evento) AS id_evento, + to_char(evento) AS evento, id_agentmodule, + COUNT(*) AS event_rep, MIN(estado) AS min_estado, + MAX(estado) AS max_estado, + LISTAGG(user_comment, '') AS user_comment, + MAX(utimestamp) AS timestamp_rep + FROM ".$table_events.' + WHERE 1=1 '.$sql_post.' + GROUP BY to_char(evento), id_agentmodule) b + WHERE a.id_evento=b.id_evento AND + to_char(a.evento)=to_char(b.evento) AND + a.id_agentmodule=b.id_agentmodule'; $sql = oracle_recode_query($sql, $set); break; } @@ -10036,8 +10668,7 @@ function get_events_with_user($trash1, $trash2, $other, $returnType, $user_in_db $data['type'] = 'array'; $data['data'] = $result; - returnData($returnType, $data, $separator); - + // returnData($returnType, $data, $separator); if (empty($result)) { return false; } @@ -10077,8 +10708,6 @@ function api_get_events($trash1, $trash2, $other, $returnType, $user_in_db=null) returnError('ERROR_API_PANDORAFMS', $returnType); } } - - return; } if ($other['type'] == 'string') { @@ -10092,10 +10721,13 @@ function api_get_events($trash1, $trash2, $other, $returnType, $user_in_db=null) } else if ($other['type'] == 'array') { $separator = $other['data'][0]; - $filterString = otherParameter2Filter($other); + // By default it uses agent alias. + $use_agent_name = ($other['data'][16] === '1') ? true : false; + + $filterString = otherParameter2Filter($other, false, $use_agent_name); } - if (defined('METACONSOLE')) { + if (is_metaconsole()) { $dataRows = db_get_all_rows_filter('tmetaconsole_event', $filterString); } else { $dataRows = db_get_all_rows_filter('tevento', $filterString); @@ -10576,25 +11208,58 @@ function api_set_new_note_incident($id, $id2, $other, $thrash2) */ -function api_set_disable_module($agent_name, $module_name, $thrast3, $thrash4) +function api_set_disable_module($agent_name, $module_name, $other, $thrash4) { if (defined('METACONSOLE')) { return; } - $id_agent = agents_get_agent_id($agent_name); - if (!util_api_check_agent_and_print_error($id_agent, 'string', 'AD')) { - return; + $agent_by_alias = false; + + if ($other['data'][0] === '1') { + $agent_by_alias = true; } - $id_agent_module = db_get_value_filter('id_agente_modulo', 'tagente_modulo', ['id_agente' => $id_agent, 'nombre' => $module_name]); + if ($agent_by_alias) { + $ids_agents = agents_get_agent_id_by_alias($agent_name); - $result = modules_change_disabled($id_agent_module, 1); - - if ($result === NOERR) { - returnData('string', ['type' => 'string', 'data' => __('Correct module disable')]); + foreach ($ids_agents as $id) { + if (!util_api_check_agent_and_print_error($id['id_agente'], 'string', 'AD')) { + return; + } + } } else { - returnData('string', ['type' => 'string', 'data' => __('Error disabling module')]); + $id_agent = agents_get_agent_id($agent_name); + + if (!util_api_check_agent_and_print_error($id_agent, 'string', 'AD')) { + return; + } + } + + if ($agent_by_alias) { + $agents_affected = 0; + + foreach ($ids_agents as $id) { + $id_agent_module = db_get_value_filter('id_agente_modulo', 'tagente_modulo', ['id_agente' => $id['id_agente'], 'nombre' => $module_name]); + + $result = modules_change_disabled($id_agent_module, 1); + + if ($result === NOERR) { + $agents_affected++; + } + } + + returnData('string', ['type' => 'string', 'data' => __('%d agents affected', $agents_affected)]); + } else { + $id_agent_module = db_get_value_filter('id_agente_modulo', 'tagente_modulo', ['id_agente' => $id_agent, 'nombre' => $module_name]); + + $result = modules_change_disabled($id_agent_module, 1); + + if ($result === NOERR) { + returnData('string', ['type' => 'string', 'data' => __('Correct module disable')]); + } else { + returnData('string', ['type' => 'string', 'data' => __('Error disabling module')]); + } } } @@ -10609,25 +11274,58 @@ function api_set_disable_module($agent_name, $module_name, $thrast3, $thrash4) */ -function api_set_enable_module($agent_name, $module_name, $thrast3, $thrash4) +function api_set_enable_module($agent_name, $module_name, $other, $thrash4) { if (defined('METACONSOLE')) { return; } - $id_agent = agents_get_agent_id($agent_name); - if (!util_api_check_agent_and_print_error($id_agent, 'string', 'AD')) { - return; + $agent_by_alias = false; + + if ($other['data'][0] === '1') { + $agent_by_alias = true; } - $id_agent_module = db_get_value_filter('id_agente_modulo', 'tagente_modulo', ['id_agente' => $id_agent, 'nombre' => $module_name]); + if ($agent_by_alias) { + $ids_agents = agents_get_agent_id_by_alias($agent_name); - $result = modules_change_disabled($id_agent_module, 0); - - if ($result === NOERR) { - returnData('string', ['type' => 'string', 'data' => __('Correct module enable')]); + foreach ($ids_agents as $id) { + if (!util_api_check_agent_and_print_error($id['id_agente'], 'string', 'AD')) { + return; + } + } } else { - returnData('string', ['type' => 'string', 'data' => __('Error enabling module')]); + $id_agent = agents_get_agent_id($agent_name); + + if (!util_api_check_agent_and_print_error($id_agent, 'string', 'AD')) { + return; + } + } + + if ($agent_by_alias) { + $agents_affected = 0; + + foreach ($ids_agents as $id) { + $id_agent_module = db_get_value_filter('id_agente_modulo', 'tagente_modulo', ['id_agente' => $id['id_agente'], 'nombre' => $module_name]); + + $result = modules_change_disabled($id_agent_module, 0); + + if ($result === NOERR) { + $agents_affected++; + } + } + + returnData('string', ['type' => 'string', 'data' => __('%d agents affected', $agents_affected)]); + } else { + $id_agent_module = db_get_value_filter('id_agente_modulo', 'tagente_modulo', ['id_agente' => $id_agent, 'nombre' => $module_name]); + + $result = modules_change_disabled($id_agent_module, 0); + + if ($result === NOERR) { + returnData('string', ['type' => 'string', 'data' => __('Correct module enable')]); + } else { + returnData('string', ['type' => 'string', 'data' => __('Error enabling module')]); + } } } @@ -10667,8 +11365,8 @@ function api_set_disable_alert($agent_name, $module_name, $template_name, $thras $result = db_process_sql( "UPDATE talert_template_modules - SET disabled = 1 - WHERE id_agent_module = $id_agent_module AND id_alert_template = $id_template" + SET disabled = 1 + WHERE id_agent_module = $id_agent_module AND id_alert_template = $id_template" ); if ($result) { @@ -10716,8 +11414,8 @@ function api_set_disable_alert_alias($agent_alias, $module_name, $template_name, $result = db_process_sql( "UPDATE talert_template_modules - SET disabled = 1 - WHERE id_agent_module = $id_agent_module AND id_alert_template = $id_template" + SET disabled = 1 + WHERE id_agent_module = $id_agent_module AND id_alert_template = $id_template" ); if ($result) { @@ -10767,8 +11465,8 @@ function api_set_enable_alert($agent_name, $module_name, $template_name, $thrash $result = db_process_sql( "UPDATE talert_template_modules - SET disabled = 0 - WHERE id_agent_module = $id_agent_module AND id_alert_template = $id_template" + SET disabled = 0 + WHERE id_agent_module = $id_agent_module AND id_alert_template = $id_template" ); if ($result) { @@ -10816,8 +11514,8 @@ function api_set_enable_alert_alias($agent_alias, $module_name, $template_name, $result = db_process_sql( "UPDATE talert_template_modules - SET disabled = 0 - WHERE id_agent_module = $id_agent_module AND id_alert_template = $id_template" + SET disabled = 0 + WHERE id_agent_module = $id_agent_module AND id_alert_template = $id_template" ); if ($result) { @@ -10844,7 +11542,7 @@ function api_set_enable_alert_alias($agent_alias, $module_name, $template_name, */ -function api_set_disable_module_alerts($agent_name, $module_name, $thrash3, $thrash4) +function api_set_disable_module_alerts($agent_name, $module_name, $other, $thrash4) { global $config; @@ -10857,20 +11555,59 @@ function api_set_disable_module_alerts($agent_name, $module_name, $thrash3, $thr return; } - $id_agent = agents_get_agent_id($agent_name); - if (!util_api_check_agent_and_print_error($id_agent, 'string', 'AW')) { - return; + $agent_by_alias = false; + + if ($other['data'][0] === '1') { + $agent_by_alias = true; } - $id_agent_module = db_get_value_filter('id_agente_modulo', 'tagente_modulo', ['id_agente' => $id_agent, 'nombre' => $module_name]); + if ($agent_by_alias) { + $ids_agents = agents_get_agent_id_by_alias($agent_name); + } else { + $id_agent = agents_get_agent_id($agent_name); + } - db_process_sql( - "UPDATE talert_template_modules - SET disabled = 1 - WHERE id_agent_module = $id_agent_module" - ); + if ($agent_by_alias) { + foreach ($ids_agents as $id) { + if (!util_api_check_agent_and_print_error($id['id_agente'], 'string', 'AW')) { + return; + } + } + } else { + if (!util_api_check_agent_and_print_error($id_agent, 'string', 'AW')) { + return; + } + } - returnData('string', ['type' => 'string', 'data' => 'Correct alerts disable']); + if ($agent_by_alias) { + $agents_affected = 0; + + foreach ($ids_agents as $id) { + $id_agent_module = db_get_value_filter('id_agente_modulo', 'tagente_modulo', ['id_agente' => $id['id_agente'], 'nombre' => $module_name]); + + $return_value = db_process_sql( + "UPDATE talert_template_modules + SET disabled = 1 + WHERE id_agent_module = $id_agent_module" + ); + + if ($return_value != false) { + $agents_affected++; + } + } + + returnData('string', ['type' => 'string', 'data' => __('%d agents affected', $agents_affected)]); + } else { + $id_agent_module = db_get_value_filter('id_agente_modulo', 'tagente_modulo', ['id_agente' => $id_agent, 'nombre' => $module_name]); + + db_process_sql( + "UPDATE talert_template_modules + SET disabled = 1 + WHERE id_agent_module = $id_agent_module" + ); + + returnData('string', ['type' => 'string', 'data' => 'Correct alerts disable']); + } } @@ -10886,7 +11623,7 @@ function api_set_disable_module_alerts($agent_name, $module_name, $thrash3, $thr */ -function api_set_enable_module_alerts($agent_name, $module_name, $thrash3, $thrash4) +function api_set_enable_module_alerts($agent_name, $module_name, $other, $thrash4) { global $config; @@ -10899,20 +11636,59 @@ function api_set_enable_module_alerts($agent_name, $module_name, $thrash3, $thra return; } - $id_agent = agents_get_agent_id($agent_name); - if (!util_api_check_agent_and_print_error($id_agent, 'string', 'AW')) { - return; + $agent_by_alias = false; + + if ($other['data'][0] === '1') { + $agent_by_alias = true; } - $id_agent_module = db_get_value_filter('id_agente_modulo', 'tagente_modulo', ['id_agente' => $id_agent, 'nombre' => $module_name]); + if ($agent_by_alias) { + $ids_agents = agents_get_agent_id_by_alias($agent_name); + } else { + $id_agent = agents_get_agent_id($agent_name); + } - db_process_sql( - "UPDATE talert_template_modules - SET disabled = 0 - WHERE id_agent_module = $id_agent_module" - ); + if ($agent_by_alias) { + foreach ($ids_agents as $id) { + if (!util_api_check_agent_and_print_error($id['id_agente'], 'string', 'AW')) { + return; + } + } + } else { + if (!util_api_check_agent_and_print_error($id_agent, 'string', 'AW')) { + return; + } + } - returnData('string', ['type' => 'string', 'data' => 'Correct alerts enable']); + if ($agent_by_alias) { + $agents_affected = 0; + + foreach ($ids_agents as $id) { + $id_agent_module = db_get_value_filter('id_agente_modulo', 'tagente_modulo', ['id_agente' => $id['id_agente'], 'nombre' => $module_name]); + + $return_value = db_process_sql( + "UPDATE talert_template_modules + SET disabled = 0 + WHERE id_agent_module = $id_agent_module" + ); + + if ($return_value != false) { + $agents_affected++; + } + } + + returnData('string', ['type' => 'string', 'data' => __('%d agents affected', $agents_affected)]); + } else { + $id_agent_module = db_get_value_filter('id_agente_modulo', 'tagente_modulo', ['id_agente' => $id_agent, 'nombre' => $module_name]); + + db_process_sql( + "UPDATE talert_template_modules + SET disabled = 0 + WHERE id_agent_module = $id_agent_module" + ); + + returnData('string', ['type' => 'string', 'data' => 'Correct alerts enable']); + } } @@ -10984,11 +11760,11 @@ function api_get_total_modules($id_group, $trash1, $trash2, $returnType) } $sql = "SELECT COUNT(DISTINCT(id_agente_modulo)) - FROM tagente_modulo tam, tagente ta - LEFT JOIN tagent_secondary_group tasg - ON ta.id_agente = tasg.id_agent - WHERE tam.id_agente = ta.id_agente AND id_module_group = $id_group - AND delete_pending = 0 AND $groups_clause"; + FROM tagente_modulo tam, tagente ta + LEFT JOIN tagent_secondary_group tasg + ON ta.id_agente = tasg.id_agent + WHERE tam.id_agente = ta.id_agente AND id_module_group = $id_group + AND delete_pending = 0 AND $groups_clause"; $total = db_get_value_sql($sql); @@ -11049,8 +11825,8 @@ function api_get_agent_name($id_agent, $trash1, $trash2, $returnType) $sql = sprintf( 'SELECT nombre - FROM tagente - WHERE id_agente = %d', + FROM tagente + WHERE id_agente = %d', $id_agent ); $value = db_get_value_sql($sql); @@ -11126,8 +11902,8 @@ function api_get_agent_alias($id_agent, $id_node, $trash1, $returnType) $sql = sprintf( 'SELECT alias - FROM '.$table_agent_alias.' - WHERE id_agente = %d', + FROM '.$table_agent_alias.' + WHERE id_agente = %d', $id_agent ); $value = db_get_value_sql($sql); @@ -11159,8 +11935,8 @@ function api_get_module_name($id_module, $trash1, $trash2, $returnType) $sql = sprintf( 'SELECT nombre - FROM tagente_modulo - WHERE id_agente_modulo = %d', + FROM tagente_modulo + WHERE id_agente_modulo = %d', $id_module ); @@ -11201,15 +11977,15 @@ function api_get_alert_action_by_group($id_group, $id_action, $trash2, $returnTy } $sql = "SELECT SUM(internal_counter) - FROM - talert_template_modules tatm, - tagente ta LEFT JOIN tagent_secondary_group tasg - ON ta.id_agente = tasg.id_agent, - tagente_modulo tam - WHERE tam.id_agente = ta.id_agente - AND tatm.id_agent_module = tam.id_agente_modulo - AND ta.disabled = 0 - AND $filter_groups"; + FROM + talert_template_modules tatm, + tagente ta LEFT JOIN tagent_secondary_group tasg + ON ta.id_agente = tasg.id_agent, + tagente_modulo tam + WHERE tam.id_agente = ta.id_agente + AND tatm.id_agent_module = tam.id_agente_modulo + AND ta.disabled = 0 + AND $filter_groups"; $value = db_get_value_sql($sql); @@ -11239,8 +12015,8 @@ function api_get_event_info($id_event, $trash1, $trash, $returnType) } $sql = 'SELECT * - FROM '.$table_events." - WHERE id_evento=$id_event"; + FROM '.$table_events." + WHERE id_evento=$id_event"; $event_data = db_get_row_sql($sql); // Check the access to group @@ -13768,8 +14544,8 @@ function api_set_create_event_filter($name, $thrash1, $other, $thrash3) } else { $sql = sprintf( 'SELECT alias - FROM tagente - WHERE id_agente = %d', + FROM tagente + WHERE id_agente = %d', $agent[0]['id_agente'] ); @@ -13812,8 +14588,8 @@ function api_set_create_event_filter($name, $thrash1, $other, $thrash3) $agents = db_get_all_rows_sql( 'SELECT id_agente - FROM tagente - WHERE id_grupo IN ('.$id_groups.')' + FROM tagente + WHERE id_grupo IN ('.$id_groups.')' ); if ($agents === false) { @@ -13982,8 +14758,8 @@ function api_set_update_event_filter($id_event_filter, $thrash1, $other, $thrash } else { $sql = sprintf( 'SELECT alias - FROM tagente - WHERE id_agente = %d', + FROM tagente + WHERE id_agente = %d', $agent[0]['id_agente'] ); @@ -14025,12 +14801,10 @@ function api_set_update_event_filter($id_event_filter, $thrash1, $other, $thrash break; case 14: - print_r('14444444'); $values['tag_with'] = (preg_match('/^\[(("\d+"((,|\])("\d+"))+)|"\d+")\]$/', io_safe_output($other['data'][14]))) ? $other['data'][14] : '[]'; break; case 15: - print_r('1555555555'); $values['tag_without'] = (preg_match('/^\[(("\d+"((,|\])("\d+"))+)|"\d+")\]$/', io_safe_output($other['data'][15]))) ? $other['data'][15] : '[]'; break; @@ -14055,8 +14829,8 @@ function api_set_update_event_filter($id_event_filter, $thrash1, $other, $thrash $agents = db_get_all_rows_sql( 'SELECT id_agente - FROM tagente - WHERE id_grupo IN ('.$id_groups.')' + FROM tagente + WHERE id_grupo IN ('.$id_groups.')' ); if ($agents === false) { @@ -14089,7 +14863,6 @@ function api_set_update_event_filter($id_event_filter, $thrash1, $other, $thrash break; case 20: - print_r('adadadasds'); $values['user_comment'] = $other['data'][20]; break; } @@ -14478,7 +15251,7 @@ function api_get_group_id_by_name($thrash1, $thrash2, $other, $thrash3) $sql = sprintf( 'SELECT id_grupo - FROM tgrupo WHERE nombre = "'.$other['data'].'"' + FROM tgrupo WHERE nombre = "'.$other['data'].'"' ); $group_id = db_get_all_rows_sql($sql); @@ -14504,7 +15277,7 @@ function api_get_timezone($thrash1, $thrash2, $other, $thrash3) $sql = sprintf( 'SELECT value - FROM tconfig WHERE token = "timezone"' + FROM tconfig WHERE token = "timezone"' ); $timezone = db_get_all_rows_sql($sql); @@ -14530,7 +15303,7 @@ function api_get_language($thrash1, $thrash2, $other, $thrash3) $sql = sprintf( 'SELECT value - FROM tconfig WHERE token = "language"' + FROM tconfig WHERE token = "language"' ); $language = db_get_all_rows_sql($sql); @@ -14556,7 +15329,7 @@ function api_get_session_timeout($thrash1, $thrash2, $other, $thrash3) $sql = sprintf( 'SELECT value - FROM tconfig WHERE token = "session_timeout"' + FROM tconfig WHERE token = "session_timeout"' ); $language = db_get_all_rows_sql($sql); diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index ccbe7f6dd2..9563732c68 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -4615,7 +4615,7 @@ function events_page_comments($event, $ajax=false) foreach ($comm as $c) { $data[0] = ''.$c['action'].' by '.$c['id_user'].''; $data[0] .= '

'.date($config['date_format'], $c['utimestamp']).''; - $data[1] = $c['comment']; + $data[1] = '

'.$c['comment'].'

'; $table_comments->data[] = $data; } } diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index 4ad8294ae1..cddd447673 100644 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -3595,7 +3595,32 @@ function graph_custom_sql_graph( $SQL_GRAPH_MAX_LABEL_SIZE = 20; + if (is_metaconsole()) { + $server = metaconsole_get_connection_names(); + $connection = metaconsole_get_connection($server); + metaconsole_connect($connection); + } + $report_content = db_get_row('treport_content', 'id_rc', $id); + + if ($report_content == false || $report_content == '') { + $report_content = db_get_row('treport_content_template', 'id_rc', $id); + } + + if ($report_content == false || $report_content == '') { + enterprise_hook('metaconsole_restore_db'); + $report_content = db_get_row('treport_content', 'id_rc', $id); + if ($report_content == false || $report_content == '') { + $report_content = db_get_row('treport_content_template', 'id_rc', $id); + } + + if (is_metaconsole()) { + $server = metaconsole_get_connection_names(); + $connection = metaconsole_get_connection($server); + metaconsole_connect($connection); + } + } + if ($id != null) { $historical_db = db_get_value_sql('SELECT historical_db from treport_content where id_rc ='.$id); } else { @@ -3609,22 +3634,9 @@ function graph_custom_sql_graph( $sql = io_safe_output($sql['sql']); } - if (($config['metaconsole'] == 1) && defined('METACONSOLE')) { - $metaconsole_connection = enterprise_hook('metaconsole_get_connection', [$report_content['server_name']]); - - if ($metaconsole_connection === false) { - return false; - } - - if (enterprise_hook('metaconsole_load_external_db', [$metaconsole_connection]) != NOERR) { - // ui_print_error_message ("Error connecting to ".$server_name); - return false; - } - } - $data_result = db_get_all_rows_sql($sql, $historical_db); - if (($config['metaconsole'] == 1) && defined('METACONSOLE')) { + if (is_metaconsole()) { enterprise_hook('metaconsole_restore_db'); } diff --git a/pandora_console/include/functions_networkmap.php b/pandora_console/include/functions_networkmap.php index e4fb19e814..dda25538ee 100644 --- a/pandora_console/include/functions_networkmap.php +++ b/pandora_console/include/functions_networkmap.php @@ -2327,7 +2327,13 @@ function migrate_older_open_maps($id) $new_map_filter = []; $new_map_filter['dont_show_subgroups'] = $old_networkmap['dont_show_subgroups']; $new_map_filter['node_radius'] = 40; - $new_map_filter['id_migrate_map'] = $id; + $new_map_filter['x_offs'] = 0; + $new_map_filter['y_offs'] = 0; + $new_map_filter['z_dash'] = '0.5'; + $new_map_filter['node_sep'] = '0.1'; + $new_map_filter['rank_sep'] = 1; + $new_map_filter['mindist'] = 1; + $new_map_filter['kval'] = '0.1'; $map_values['filter'] = json_encode($new_map_filter); $map_values['description'] = 'Mapa open migrado'; @@ -2340,11 +2346,7 @@ function migrate_older_open_maps($id) $map_values['source_period'] = 60; $map_values['source'] = 0; $map_values['source_data'] = $old_networkmap['id_group']; - if ($old_networkmap['type'] == 'radial_dinamic') { - $map_values['generation_method'] = 6; - } else { - $map_values['generation_method'] = 4; - } + $map_values['generation_method'] = 3; $map_values['generated'] = 0; diff --git a/pandora_console/include/functions_planned_downtimes.php b/pandora_console/include/functions_planned_downtimes.php index 1147ad97a8..a9b701241b 100644 --- a/pandora_console/include/functions_planned_downtimes.php +++ b/pandora_console/include/functions_planned_downtimes.php @@ -796,6 +796,11 @@ function planned_downtimes_created($values) 'return' => false, 'message' => __('Not created. Error inserting data').'. '.__('There is no group with such id'), ]; + } else if (!$values['date_from'] || !$values['date_to']) { + return [ + 'return' => false, + 'message' => __('Not created. Error inserting data').'. '.__('Date is wrong formatted'), + ]; } else { if (trim(io_safe_output($values['name'])) != '') { if (!$check) { diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 0cf447eede..1d0355cf97 100755 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -282,6 +282,15 @@ function reporting_make_reporting_data( $agents_to_macro = $content['id_agent']; } + // Metaconsole connection. + if (is_metaconsole()) { + $server = metaconsole_get_connection_names(); + $connection = metaconsole_get_connection($server); + if (metaconsole_connect($connection) != NOERR) { + continue; + } + } + if (isset($content['style']['name_label'])) { // Add macros name. $items_label = []; @@ -294,14 +303,6 @@ function reporting_make_reporting_data( $metaconsole_on = is_metaconsole(); $server_name = $content['server_name']; - // Metaconsole connection. - if ($metaconsole_on && $server_name != '') { - $connection = metaconsole_get_connection($server_name); - if (!metaconsole_load_external_db($connection)) { - continue; - } - } - $items_label['agent_description'] = agents_get_description( $content['id_agent'] ); @@ -2824,13 +2825,12 @@ function reporting_group_report($report, $content) $content['name'] = __('Group Report'); } - if ($config['metaconsole']) { - $id_meta = metaconsole_get_id_server($content['server_name']); - - $server = metaconsole_get_connection_by_id($id_meta); - metaconsole_connect($server); + if (is_metaconsole()) { + $server = metaconsole_get_connection_names(); + $connection = metaconsole_get_connection($server); } + $return['server_name'] = $server[0]; $return['title'] = $content['name']; $return['subtitle'] = groups_get_name($content['id_group'], true); $return['description'] = $content['description']; @@ -3488,7 +3488,7 @@ function reporting_network_interfaces_report($report, $content, $type='dinamic', $return['failed'] = null; $return['data'] = []; - if ($config['metaconsole']) { + if (is_metaconsole()) { $server_names = metaconsole_get_connection_names(); if (isset($server_names) && is_array($server_names)) { foreach ($server_names as $key => $value) { @@ -3505,7 +3505,8 @@ function reporting_network_interfaces_report($report, $content, $type='dinamic', $content, $report, $fullscale, - $pdf + $pdf, + $id_meta ); metaconsole_restore_db(); } @@ -4190,6 +4191,19 @@ function reporting_sql_graph( $return['description'] = $content['description']; $return['date'] = reporting_get_date_text(); + $module_source = db_get_all_rows_sql( + 'SELECT id_agent_module + FROM tgraph_source + WHERE id_graph = '.$content['id_gs'] + ); + + if (isset($module_source) && is_array($module_source)) { + $modules = []; + foreach ($module_source as $key => $value) { + $modules[$key] = $value['id_agent_module']; + } + } + switch ($type) { case 'dinamic': case 'static': @@ -4206,6 +4220,16 @@ function reporting_sql_graph( break; case 'data': + $data = []; + foreach ($modules as $key => $value) { + $data[$value] = modules_get_agentmodule_data( + $value, + $content['period'], + $report['datetime'] + ); + } + + $return['chart'] = $data; break; } @@ -4406,6 +4430,7 @@ function reporting_netflow( switch ($type) { case 'dinamic': case 'static': + case 'data': $return['chart'] = netflow_draw_item( ($report['datetime'] - $content['period']), $report['datetime'], @@ -4879,22 +4904,23 @@ function reporting_value($report, $content, $type, $pdf=false) if ($content['visual_format'] != 2) { $time_begin = db_get_row_sql('select utimestamp from tagente_datos where id_agente_modulo ='.$content['id_agent_module'], true); - for ($i = $report['datetime']; $i > ($report['datetime'] - $content['period']); $i -= $content['lapse']) { + + for ($i = ($report['datetime'] - $content['period']); $i < $report['datetime']; $i += $content['lapse']) { $row = []; - $row[__('Lapse')] = date('Y-m-d H:i:s', ($i - $content['lapse'] + 1)).' to '.date('Y-m-d H:i:s', $i); + $row[__('Lapse')] = date('Y-m-d H:i:s', ($i + 1)).' to '.date('Y-m-d H:i:s', (($i + $content['lapse']) )); if ($i > $time_begin['utimestamp']) { switch ($type) { case 'max': - $row[__('Maximun')] = format_for_graph(reporting_get_agentmodule_data_max($content['id_agent_module'], $content['lapse'], $i), $config['graph_precision']).' '.$unit; + $row[__('Maximun')] = format_for_graph(reporting_get_agentmodule_data_max($content['id_agent_module'], $content['lapse'], ($i + $content['lapse'])), $config['graph_precision']).' '.$unit; break; case 'min': - $row[__('Maximun')] = format_for_graph(reporting_get_agentmodule_data_min($content['id_agent_module'], $content['lapse'], $i), $config['graph_precision']).' '.$unit; + $row[__('Maximun')] = format_for_graph(reporting_get_agentmodule_data_min($content['id_agent_module'], $content['lapse'], ($i + $content['lapse'])), $config['graph_precision']).' '.$unit; break; case 'avg': - $row[__('Maximun')] = format_for_graph(reporting_get_agentmodule_data_average($content['id_agent_module'], $content['lapse'], $i), $config['graph_precision']).' '.$unit; + $row[__('Maximun')] = format_for_graph(reporting_get_agentmodule_data_average($content['id_agent_module'], $content['lapse'], ($i + $content['lapse'])), $config['graph_precision']).' '.$unit; break; } } else { @@ -7560,8 +7586,35 @@ function reporting_custom_graph( $content['name'] = __('Simple graph'); } + $module_source = db_get_all_rows_sql( + 'SELECT id_agent_module + FROM tgraph_source + WHERE id_graph = '.$content['id_gs'] + ); + + if (isset($module_source) && is_array($module_source)) { + $modules = []; + foreach ($module_source as $key => $value) { + $modules[$key] = $value['id_agent_module']; + } + } + + $agent_description = agents_get_description($id_agent); + $agent_group = agents_get_agent_group($id_agent); + $agent_address = agents_get_address($id_agent); + $agent_alias = agents_get_alias($id_agent); + $module_name = modules_get_agentmodule_name( + $id_agent_module + ); + + $module_description = modules_get_agentmodule_descripcion( + $id_agent_module + ); + $return['title'] = $content['name']; $return['subtitle'] = io_safe_output($graph['name']); + $return['agent_name'] = $agent_alias; + $return['module_name'] = $module_name; $return['description'] = $content['description']; $return['date'] = reporting_get_date_text( $report, @@ -7605,6 +7658,19 @@ function reporting_custom_graph( ); break; + + case 'data': + $data = []; + foreach ($modules as $key => $value) { + $data[$value] = modules_get_agentmodule_data( + $value, + $content['period'], + $report['datetime'] + ); + } + + $return['chart'] = $data; + break; } if ($type_report == 'custom_graph') { diff --git a/pandora_console/include/functions_reports.php b/pandora_console/include/functions_reports.php index de52d3322b..319690946e 100755 --- a/pandora_console/include/functions_reports.php +++ b/pandora_console/include/functions_reports.php @@ -769,22 +769,34 @@ function reports_get_report_types($template=false, $not_editor=false) 'optgroup' => __('Grouped'), 'name' => __('General'), ]; - $types['group_report'] = [ - 'optgroup' => __('Grouped'), - 'name' => __('Group report'), - ]; + if (is_metaconsole()) { + if ($template === false) { + $types['group_report'] = [ + 'optgroup' => __('Grouped'), + 'name' => __('Group report'), + ]; + } + } else { + $types['group_report'] = [ + 'optgroup' => __('Grouped'), + 'name' => __('Group report'), + ]; + } + $types['exception'] = [ 'optgroup' => __('Grouped'), 'name' => __('Exception'), ]; if ($config['metaconsole'] != 1) { - $types['agent_module'] = [ - 'optgroup' => __('Grouped'), - 'name' => __('Agents/Modules'), - ]; + if (!$template) { + $types['agent_module'] = [ + 'optgroup' => __('Grouped'), + 'name' => __('Agents/Modules'), + ]; + } } - // Only pandora managers have access to the whole database + // Only pandora managers have access to the whole database. if (check_acl($config['id_user'], 0, 'PM')) { $types['sql'] = [ 'optgroup' => __('Grouped'), @@ -878,7 +890,7 @@ function reports_get_report_types($template=false, $not_editor=false) ]; } - if ($config['enterprise_installed']) { + if ($config['enterprise_installed'] && $template === false) { $types['event_report_log'] = [ 'optgroup' => __('Log'), 'name' => __('Log report'), diff --git a/pandora_console/include/functions_ui.php b/pandora_console/include/functions_ui.php index bdafcdf2f5..ad3ef037b9 100755 --- a/pandora_console/include/functions_ui.php +++ b/pandora_console/include/functions_ui.php @@ -39,7 +39,7 @@ if (isset($config['homedir'])) { /** - * Transform bbcode to HTML. + * Transform bbcode to HTML and truncate log. * * @param string $text Text. * @param array $allowed_tags Allowed_tags. @@ -48,16 +48,22 @@ if (isset($config['homedir'])) { */ function ui_bbcode_to_html($text, $allowed_tags=['[url]']) { - if (array_search('[url]', $allowed_tags) !== false) { - // If link hasn't http, add it. - if (preg_match('/https?:\/\//', $text)) { - $html_bbcode = '$2'; + if (array_search('[url]', $allowed_tags) !== false || a) { + // Replace bbcode format [url=www.example.org] String [/url] with or without http and slashes + preg_match('/\[url(?|](((?:https?:\/\/)?[^[]+))|(?:=[\'"]?((?:https?:\/\/)?[^]]+?)[\'"]?)](.+?))\[\/url]/', $text, $matches); + if ($matches) { + $url = $matches[1]; + // Truncate text + $t_text = ui_print_truncate_text($matches[2]); + // If link hasn't http, add it. + if (preg_match('/https?:\/\//', $text)) { + $return = ''.$t_text.''; + } else { + $return = ''.$t_text.''; + } } else { - $html_bbcode = '$2'; + $return = ui_print_truncate_text($text); } - - // Replace bbcode format [url=www.example.org] String [/url] with or without http and slashes. - $return = preg_replace('/\[url(?|](((?:https?:\/\/)?[^[]+))|(?:=[\'"]?((?:https?:\/\/)?[^]]+?)[\'"]?)](.+?))\[\/url]/', $html_bbcode, $text); } return $return; @@ -2521,9 +2527,22 @@ function ui_print_module_warn_value( $str_warning, $max_critical, $min_critical, - $str_critical + $str_critical, + $warning_inverse=0, + $critical_inverse=0 ) { - $data = ""; + $war_inv = ''; + $crit_inv = ''; + + if ($warning_inverse == 1) { + $war_inv = ' (inv)'; + } + + if ($critical_inverse == 1) { + $crit_inv = ' (inv)'; + } + + $data = ""; if ($max_warning != $min_warning) { $data .= format_for_graph($max_warning).'/'.format_for_graph($min_warning); @@ -3191,14 +3210,18 @@ function ui_print_datatable(array $parameters) $.fn.dataTable.ext.errMode = "none"; $.fn.dataTable.ext.classes.sPageButton = "'.$pagination_class.'"; dt_'.$table_id.' = $("#'.$table_id.'").DataTable({ - '; + drawCallback: function(settings) {'; if (isset($parameters['drawCallback'])) { - $js .= 'drawCallback: function(settings) { - '.$parameters['drawCallback'].' - },'; + $js .= $parameters['drawCallback']; } $js .= ' + if (dt_'.$table_id.'.page.info().pages > 1) { + $("#'.$table_id.'_wrapper > .dataTables_paginate.paging_simple_numbers").show() + } else { + $("#'.$table_id.'_wrapper > .dataTables_paginate.paging_simple_numbers").hide() + } + }, processing: true, serverSide: true, paging: true, @@ -3303,6 +3326,7 @@ function ui_print_datatable(array $parameters) dt_'.$table_id.'.draw().page(0) }); }); + '; // Order. @@ -5650,3 +5674,62 @@ function ui_print_breadcrums($tab_name) return $section; } + + +/** + * Show last comment + * + * @param array $comments array with comments + * + * @return string HTML string with the last comment of the events. + */ +function ui_print_comments($comments) +{ + global $config; + + $comments = explode('
', $comments); + $comments = str_replace(["\n", ' '], '
', $comments); + if (is_array($comments)) { + foreach ($comments as $comm) { + if (empty($comm)) { + continue; + } + + $comments_array[] = json_decode(io_safe_output($comm), true); + } + } + + foreach ($comments_array as $comm) { + // Show the comments more recent first. + if (is_array($comm)) { + $last_comment[] = array_reverse($comm); + } + } + + // Only show the last comment. If commment its too long,the comment will short with ... + // If $config['prominent_time'] is timestamp the date show Month, day, hour and minutes. + // Else show comments hours ago + if ($last_comment[0][0]['action'] != 'Added comment') { + $last_comment[0][0]['comment'] = $last_comment[0][0]['action']; + } + + $short_comment = substr($last_comment[0][0]['comment'], 0, '80px'); + if ($config['prominent_time'] == 'timestamp') { + $comentario = ''.date($config['date_format'], $last_comment[0][0]['utimestamp']).' ('.$last_comment[0][0]['id_user'].'): '.$last_comment[0][0]['comment'].''; + + if (strlen($comentario) > '200px') { + $comentario = ''.date($config['date_format'], $last_comment[0][0]['utimestamp']).' ('.$last_comment[0][0]['id_user'].'): '.$short_comment.'...'; + } + } else { + $rest_time = (time() - $last_comment[0][0]['utimestamp']); + $time_last = (($rest_time / 60) / 60); + $comentario = ''.number_format($time_last, 0).'  Hours  ('.$last_comment[0][0]['id_user'].'): '.$last_comment[0][0]['comment'].''; + + if (strlen($comentario) > '200px') { + $comentario = ''.number_format($time_last, 0).'  Hours  ('.$last_comment[0][0]['id_user'].'): '.$short_comment.'...'; + } + } + + return io_safe_output($comentario); + +} diff --git a/pandora_console/include/graphs/fgraph.php b/pandora_console/include/graphs/fgraph.php index d8012c15dd..40c79bbf51 100644 --- a/pandora_console/include/graphs/fgraph.php +++ b/pandora_console/include/graphs/fgraph.php @@ -170,17 +170,7 @@ function vbar_graph( setup_watermark($water_mark, $water_mark_file, $water_mark_url); if (empty($chart_data)) { - return html_print_image( - $no_data_image, - true, - [ - 'width' => $width, - 'height' => $height, - 'title' => __('No data to show'), - ], - false, - true - ); + return graph_nodata_image($width, $height, 'vbar'); } if ($ttl == 2) { @@ -357,17 +347,7 @@ function hbar_graph( setup_watermark($water_mark, $water_mark_file, $water_mark_url); if (empty($chart_data)) { - return html_print_image( - $no_data_image, - true, - [ - 'width' => $width, - 'height' => $height, - 'title' => __('No data to show'), - ], - false, - true - ); + return graph_nodata_image($width, $height, 'hbar'); } if ($ttl == 2) { diff --git a/pandora_console/include/graphs/flot/pandora.flot.js b/pandora_console/include/graphs/flot/pandora.flot.js index c62614ccd3..6387bf5442 100644 --- a/pandora_console/include/graphs/flot/pandora.flot.js +++ b/pandora_console/include/graphs/flot/pandora.flot.js @@ -172,7 +172,6 @@ function pandoraFlotPieCustom( show: true, radius: 5 / 8, formatter: function(label, series) { - console.log(series); return ( '
" + + (d.getHours() < 10 ? "0" : "") + + d.getHours() + ":" + - (v.getMinutes() < 10 ? "0" : "") + - v.getMinutes(); + (d.getMinutes() < 10 ? "0" : "") + + d.getMinutes(); return date_format; } } diff --git a/pandora_console/include/graphs/functions_flot.php b/pandora_console/include/graphs/functions_flot.php index 309ddf364b..eb5596cec4 100644 --- a/pandora_console/include/graphs/functions_flot.php +++ b/pandora_console/include/graphs/functions_flot.php @@ -786,6 +786,8 @@ function flot_slicesbar_graph( // Get a unique identifier to graph $graph_id = uniqid('graph_'); + $height = ((int) $height + 15); + // Set some containers to legend, graph, timestamp tooltip, etc. if ($stat_win) { $return = "
"; @@ -804,8 +806,6 @@ function flot_slicesbar_graph( $separator2 = ':,:,,,:,:'; // Transform data from our format to library format - $labels = []; - $a = []; $vars = []; $datacolor = []; @@ -819,12 +819,12 @@ function flot_slicesbar_graph( $fontsize = $config['font_size']; $fontpath = $config['fontpath']; - $extra_height = 15; + $extra_height = 40; if (defined('METACONSOLE')) { - $extra_height = 20; + $extra_height = 50; } - $return .= "
"; + $return .= ''; $maxticks = (int) 20; @@ -842,11 +842,7 @@ function flot_slicesbar_graph( $intervaltick = (int) $intervaltick; - $acumulate = 0; - $c = 0; - $acumulate_data = []; foreach ($graph_data as $label => $values) { - $labels[] = $label; $i--; foreach ($values as $key => $value) { @@ -857,19 +853,10 @@ function flot_slicesbar_graph( } $data[$jsvar][] = $value; - - $acumulate_data[$c] = $acumulate; - $acumulate += $value; - $c++; - - if ($value > $max) { - $max = $value; - } } } - // Store serialized data to use it from javascript - $labels = implode($separator, $labels); + // Store serialized data to use it from javascript. $datacolor = implode($separator, $datacolor); if (is_array($legend)) { $legend = io_safe_output(implode($separator, $legend)); @@ -881,19 +868,11 @@ function flot_slicesbar_graph( $full_legend_date = false; } - $acumulate_data = io_safe_output(implode($separator, $acumulate_data)); - - // Store data series in javascript format - $jsvars = ''; - $jsseries = []; - $date = get_system_time(); - $datelimit = (($date - $period) * 1000); + $datelimit = (($date - $period)); $i = 0; - $values2 = []; - foreach ($data as $jsvar => $values) { $values2[] = implode($separator, $values); $i ++; @@ -901,10 +880,10 @@ function flot_slicesbar_graph( $values = implode($separator2, $values2); - // Javascript code + // Javascript code. $return .= "'; diff --git a/pandora_console/include/javascript/openlayers.pandora.js b/pandora_console/include/javascript/openlayers.pandora.js index ae06463d95..bc4a7b99bf 100755 --- a/pandora_console/include/javascript/openlayers.pandora.js +++ b/pandora_console/include/javascript/openlayers.pandora.js @@ -87,9 +87,9 @@ function js_refreshParentLines(layerName) { { strokeWidth: 2, fillOpacity: 0.2, - fillColor: "red", + fillColor: "black", strokeDashstyle: "dash", - strokeColor: "red" + strokeColor: "black" } ); diff --git a/pandora_console/include/javascript/pandora_events.js b/pandora_console/include/javascript/pandora_events.js index 0fb6c1a6ef..79668406e1 100644 --- a/pandora_console/include/javascript/pandora_events.js +++ b/pandora_console/include/javascript/pandora_events.js @@ -63,6 +63,20 @@ function show_event_dialog(event, dialog_page, result) { height: 600 }) .show(); + $.post({ + url: "ajax.php", + data: { + page: "include/ajax/events", + get_comments: 1, + event: event, + filter: values + }, + dataType: "html", + success: function(data) { + $("#extended_event_comments_page").empty(); + $("#extended_event_comments_page").html(data); + } + }); $("#refrcounter").countdown("pause"); $("div.vc-countdown").countdown("pause"); diff --git a/pandora_console/include/lib/User.php b/pandora_console/include/lib/User.php new file mode 100644 index 0000000000..4eb5853676 --- /dev/null +++ b/pandora_console/include/lib/User.php @@ -0,0 +1,116 @@ +sessions[$data['phpsessionid']] = 1; + $info = \db_get_row_filter( + 'tsessions_php', + ['id_session' => $data['phpsessionid']] + ); + + if ($info !== false) { + // Process. + $session_data = session_decode($info['data']); + $this->idUser = $_SESSION['id_usuario']; + + // Valid session. + return $this; + } + + return null; + } + + if (isset($data['id_usuario']) === true + && isset($data['password']) === true + ) { + $user_in_db = process_user_login($user, $password, true); + if ($user_in_db !== false) { + $config['id_usuario'] = $user_in_db; + $correctLogin = true; + + // Originally at api.php. + if (session_status() === PHP_SESSION_NONE) { + session_start(); + } + + $_SESSION['id_usuario'] = $user; + session_write_close(); + + $this->idUser = $data['id_usuario']; + // Valid session. + return $this; + } + } + } + + return null; + + } + + +} diff --git a/pandora_console/include/load_session.php b/pandora_console/include/load_session.php index 39e0973287..7d06cea88d 100644 --- a/pandora_console/include/load_session.php +++ b/pandora_console/include/load_session.php @@ -91,11 +91,6 @@ function pandora_session_write($session_id, $data) { $session_id = addslashes($session_id); - // If it's an api call, the session must not be created. - if (get_parameter('op', false) && get_parameter('op2', false)) { - return true; - } - if (is_ajax()) { // Avoid session upadte while processing ajax responses - notifications. if (get_parameter('check_new_notifications', false)) { @@ -166,7 +161,7 @@ function pandora_session_gc($max_lifetime=300) if (isset($config['session_timeout'])) { $session_timeout = $config['session_timeout']; } else { - // if $config doesn`t work ... + // If $config doesn`t work ... $session_timeout = db_get_value( 'value', 'tconfig', @@ -175,9 +170,9 @@ function pandora_session_gc($max_lifetime=300) ); } - if (!empty($session_timeout)) { + if (empty($session_timeout) === false) { if ($session_timeout == -1) { - // The session expires in 10 years + // The session expires in 10 years. $session_timeout = 315576000; } else { $session_timeout *= 60; @@ -196,15 +191,14 @@ function pandora_session_gc($max_lifetime=300) ); // Deleting cron and empty sessions. - $sql = "DELETE FROM tsessions_php WHERE - data IS NULL OR id_session REGEXP '^cron-'"; + $sql = 'DELETE FROM tsessions_php WHERE data IS NULL'; db_process_sql($sql); return $retval; } -// FIXME: SAML should work with pandora session handlers +// TODO: SAML should work with pandora session handlers. if (db_get_value('value', 'tconfig', 'token', 'auth') != 'saml') { $result_handler = session_set_save_handler( 'pandora_session_open', diff --git a/pandora_console/include/styles/login.css b/pandora_console/include/styles/login.css index 8edd7d46c0..f6c072b314 100644 --- a/pandora_console/include/styles/login.css +++ b/pandora_console/include/styles/login.css @@ -261,6 +261,7 @@ div.login_button_saml input:hover { .login_back input { background-image: url("../../images/back_login.png"); background-position: left 5% center; + background-repeat: no-repeat; } .login_back input:hover { diff --git a/pandora_console/include/styles/pandora.css b/pandora_console/include/styles/pandora.css index 27b3094027..459cc5c54d 100644 --- a/pandora_console/include/styles/pandora.css +++ b/pandora_console/include/styles/pandora.css @@ -5888,3 +5888,18 @@ table.table_modal_alternate tr td:first-child { .fullwidth { width: 100%; } + +.slicebar-box-hover-styles { + position: absolute; + background-color: #fff; + width: 80px; + height: 20px; + text-align: center; + font-family: arial, sans-serif, verdana; + padding: 3px; + border: 1px solid black; +} + +.flot-text { + width: 101%; +} diff --git a/pandora_console/include/styles/wux.css b/pandora_console/include/styles/wux.css new file mode 100644 index 0000000000..cd9e3f61e2 --- /dev/null +++ b/pandora_console/include/styles/wux.css @@ -0,0 +1,10 @@ +/* + * Wux style + */ + +.wux_execution_result_transaction { + width: auto; + height: auto; + float: right; + margin-right: 200px; +} diff --git a/pandora_console/include/web2image.js b/pandora_console/include/web2image.js index 09f840e45e..8e2887aa26 100644 --- a/pandora_console/include/web2image.js +++ b/pandora_console/include/web2image.js @@ -1,5 +1,7 @@ var system = require("system"); +/* global phantom */ + if (system.args.length < 3 || system.args.length > 11) { phantom.exit(1); } @@ -14,6 +16,7 @@ var viewport_width = system.args[7]; var viewport_height = system.args[8]; var session_id = system.args[9]; var base_64 = system.args[10]; +var post_data = ""; if (!viewport_width) { viewport_width = 750; @@ -47,6 +50,29 @@ if (type_graph_pdf == "combined") { var page = require("webpage").create(); +page.onResourceError = function(resourceError) { + console.log( + "Unable to load resource (#" + + resourceError.id + + "URL:" + + resourceError.url + + ")" + ); + console.log( + "Error code: " + + resourceError.errorCode + + ". Description: " + + resourceError.errorString + ); + phantom.exit(1); +}; + +// Not supposed to be prompted messages. +page.onPrompt = function() { + console.log("Prompt message detected."); + phantom.exit(1); +}; + page.viewportSize = { width: viewport_width, height: viewport_height @@ -64,7 +90,7 @@ page.onError = function(msg) { phantom.exit(); }; -page.onCallback = function(st) { +page.onCallback = function() { if (!base_64) { page.render(output_filename, { format: "png" }); } else { @@ -81,3 +107,21 @@ page.open(url, "POST", post_data, function(status) { phantom.exit(); } }); + +phantom.onError = function(msg, trace) { + var msgStack = ["PHANTOM ERROR: " + msg]; + if (trace && trace.length) { + msgStack.push("TRACE:"); + trace.forEach(function(t) { + msgStack.push( + " -> " + + (t.file || t.sourceURL) + + ": " + + t.line + + (t.function ? " (in function " + t.function + ")" : "") + ); + }); + } + console.log(msgStack.join("\n")); + phantom.exit(1); +}; diff --git a/pandora_console/install.php b/pandora_console/install.php index f16ef72c72..4f668fcd81 100644 --- a/pandora_console/install.php +++ b/pandora_console/install.php @@ -128,8 +128,8 @@
graph_type == 'boolean') { + $fullscale = 1; + } else { + $fullscale = 0; + } + } + ob_start(); switch ($this->graph_type) { case 'boolean': @@ -188,6 +201,7 @@ class ModuleGraph 'menu' => false, 'type_graph' => $config['type_module_charts'], 'vconsole' => true, + 'fullscale' => $fullscale, ]; $graph = grafico_modulo_sparse($params); diff --git a/pandora_console/operation/agentes/gis_view.php b/pandora_console/operation/agentes/gis_view.php index 139f8f8ae9..352b66f7af 100644 --- a/pandora_console/operation/agentes/gis_view.php +++ b/pandora_console/operation/agentes/gis_view.php @@ -97,17 +97,6 @@ echo ''; html_print_submit_button(__('Refresh path'), 'refresh', false, 'class = "sub upd" style="margin-top:0px"'); echo ''; -// Get the total number of Elements for the pagination -$sqlCount = sprintf( - 'SELECT COUNT(*) - FROM tgis_data_history - WHERE tagente_id_agente = %d AND end_timestamp > FROM_UNIXTIME(%d) - ORDER BY end_timestamp DESC', - $agentId, - (get_system_time() - $period) -); -$countData = (int) db_get_value_sql($sqlCount); - // Get the elements to present in this page switch ($config['dbtype']) { case 'mysql': @@ -147,33 +136,39 @@ switch ($config['dbtype']) { $result = db_get_all_rows_sql($sql, true); -if ($result === false) { - $sql2 = sprintf( - ' - SELECT current_longitude AS longitude, current_latitude AS latitude, current_altitude AS altitude, - start_timestamp, description, number_of_packages, manual_placement - FROM tgis_data_status - WHERE tagente_id_agente = %d - ORDER BY start_timestamp DESC - LIMIT %d OFFSET %d', - $agentId, - $config['block_size'], - (int) get_parameter('offset') - ); +$sql2 = sprintf( + ' + SELECT current_longitude AS longitude, current_latitude AS latitude, current_altitude AS altitude, + start_timestamp, description, number_of_packages, manual_placement + FROM tgis_data_status + WHERE tagente_id_agente = %d + ORDER BY start_timestamp DESC + LIMIT %d OFFSET %d', + $agentId, + $config['block_size'], + (int) get_parameter('offset') +); $result2 = db_get_all_rows_sql($sql2, true); - if ($result2 === false) { +if ($result === false && $result2 === false) { ui_print_empty_data(__('This agent doesn\'t have any GIS data.')); +} else { + if ($result === false) { + $result = $result2; } else { $result2[0]['end_timestamp'] = date('Y-m-d H:i:s'); - $result = $result2; + array_unshift($result, $result2[0]); } } + if ($result !== false) { echo '

'.__('Positional data from the last').' '.human_time_description_raw($period).'

'; + // Get the total elements for UI pagination + $countData = count($result); + if ($countData > 0) { ui_pagination($countData, false); } diff --git a/pandora_console/operation/agentes/pandora_networkmap.view.php b/pandora_console/operation/agentes/pandora_networkmap.view.php index 77f3d2c8a5..2ee34806d9 100644 --- a/pandora_console/operation/agentes/pandora_networkmap.view.php +++ b/pandora_console/operation/agentes/pandora_networkmap.view.php @@ -713,11 +713,7 @@ if (is_ajax()) { $values['options'] = json_encode($options); - $return_update = db_process_sql_update('tnetworkmap_enterprise', $values, ['id' => $id_ent_map]); - if (!$return_update) { - $return_data['ent'] = false; - break; - } + db_process_sql_update('tnetworkmap_enterprise', $values, ['id' => $id_ent_map]); } } } @@ -735,11 +731,7 @@ if (is_ajax()) { } else { $values['text_filter'] = 'migrated'; - $return_update = db_process_sql_update('tnetwork_map', $values, ['id_networkmap' => $id_open_map]); - if (!$return_update) { - $return_data['open'] = false; - break; - } + db_process_sql_update('tnetwork_map', $values, ['id_networkmap' => $id_open_map]); } } } diff --git a/pandora_console/operation/agentes/status_monitor.php b/pandora_console/operation/agentes/status_monitor.php index 0f7257663a..783c389269 100644 --- a/pandora_console/operation/agentes/status_monitor.php +++ b/pandora_console/operation/agentes/status_monitor.php @@ -1541,7 +1541,9 @@ if (!empty($result)) { $row['str_warning'], $row['max_critical'], $row['min_critical'], - $row['str_critical'] + $row['str_critical'], + $row['warning_inverse'], + $row['critical_inverse'] ); if (is_numeric($row['datos']) && !modules_is_string_type($row['module_type'])) { diff --git a/pandora_console/operation/events/events.php b/pandora_console/operation/events/events.php index ece97f1f9a..bc9c59eda5 100644 --- a/pandora_console/operation/events/events.php +++ b/pandora_console/operation/events/events.php @@ -280,6 +280,14 @@ if (is_ajax()) { $events, function ($carry, $item) { $tmp = (object) $item; + $tmp->meta = is_metaconsole(); + if (is_metaconsole()) { + if ($tmp->server_name !== null) { + $tmp->data_server = metaconsole_get_servers($tmp->server_id); + $tmp->server_url_hash = metaconsole_get_servers_url_hash($tmp->data_server); + } + } + $tmp->evento = str_replace('"', '', io_safe_output($tmp->evento)); if (strlen($tmp->evento) >= 255) { $tmp->evento = ui_print_truncate_text($tmp->evento, 255, $tmp->evento, true, false); @@ -289,6 +297,10 @@ if (is_ajax()) { $tmp->module_name = io_safe_output($tmp->module_name); } + if ($tmp->comments) { + $tmp->comments = ui_print_comments($tmp->comments); + } + $tmp->agent_name = io_safe_output($tmp->agent_name); $tmp->ack_utimestamp = ui_print_timestamp( $tmp->ack_utimestamp, @@ -1594,6 +1606,28 @@ function process_datatables_callback(table, settings) { function process_datatables_item(item) { + // Url to go to node from meta. + var server_url = ''; + var hashdata = ''; + if(item.meta === true){ + if(typeof item.data_server !== 'undefined' && typeof item.server_url_hash !== 'undefined'){ + server_url = item.data_server.server_url; + hashdata = item.server_url_hash; + } + } + + + // Show comments events. + item.user_comment = item.comments + + if(item.comments.length > 80){ + + item.user_comment += '  '; + item.user_comment += ' __('Show more')]); ?>'; + + } + // Grouped events. if(item.max_id_evento) { item.id_evento = item.max_id_evento @@ -1828,9 +1862,19 @@ function process_datatables_item(item) { /* Update column content now to avoid json poisoning. */ + + // Url to agent view. + var url_link = ''; + var url_link_hash = ''; + if(item.meta === true){ + url_link = server_url+'/index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente='; + url_link_hash = hashdata; + } + + /* Agent name link */ if (item.id_agente > 0) { - item.agent_name = '' + item.agent_name + ''; + item.agent_name = '' + item.agent_name + ''; } else { item.agent_name = ''; } @@ -1840,11 +1884,11 @@ function process_datatables_item(item) { - item.id_agente = '' + item.id_agente + ''; + item.id_agente = '' + item.id_agente + ''; - item.id_agente = '' + item.agent_name + ''; + item.id_agente = '' + item.agent_name + ''; diff --git a/pandora_console/operation/search_policies.getdata.php b/pandora_console/operation/search_policies.getdata.php index 5186f1f0a9..1274b17076 100644 --- a/pandora_console/operation/search_policies.getdata.php +++ b/pandora_console/operation/search_policies.getdata.php @@ -18,6 +18,11 @@ enterprise_include_once('include/functions_policies.php'); $searchpolicies = check_acl($config['id_user'], 0, 'AW'); +if (!$searchpolicies) { + $totalPolicies = 0; + return; +} + $selectpolicieIDUp = ''; $selectpolicieIDDown = ''; $selectNameUp = ''; @@ -169,7 +174,7 @@ switch ($sortField) { break; } -if ($searchpolicies == 0) { +if ($searchpolicies) { /* We take the user groups to get policies that meet the requirements of the search and which the user have permission on this groups @@ -189,6 +194,7 @@ if ($searchpolicies == 0) { $policies = db_process_sql($sql); + if ($policies !== false) { $totalPolicies = count($policies); diff --git a/pandora_console/operation/search_results.php b/pandora_console/operation/search_results.php index 803a92cdd1..b856f5f14e 100644 --- a/pandora_console/operation/search_results.php +++ b/pandora_console/operation/search_results.php @@ -18,7 +18,7 @@ require_once $config['homedir'].'/include/functions_reporting.php'; enterprise_include('operation/reporting/custom_reporting.php'); $searchAgents = $searchAlerts = $searchModules = check_acl($config['id_user'], 0, 'AR'); -$searchUsers = $searchPolicies = check_acl($config['id_user'], 0, 'AW'); +$searchUsers = $searchPolicies = check_acl($config['id_user'], 0, 'AR'); $searchMaps = $searchReports = $searchGraphs = check_acl($config['id_user'], 0, 'IR'); $searchMain = true; $searchHelps = true; diff --git a/pandora_console/operation/search_users.getdata.php b/pandora_console/operation/search_users.getdata.php index a39cdf70f1..5e67c90059 100644 --- a/pandora_console/operation/search_users.getdata.php +++ b/pandora_console/operation/search_users.getdata.php @@ -18,6 +18,10 @@ require_once $config['homedir'].'/include/functions_users.php'; require_once $config['homedir'].'/include/functions_groups.php'; $searchUsers = check_acl($config['id_user'], 0, 'UM'); +if (!$searchUsers) { + $totalUsers = 0; + return; +} $selectUserIDUp = ''; $selectUserIDDown = ''; diff --git a/pandora_console/operation/search_users.php b/pandora_console/operation/search_users.php index 8014d5a261..b2232a44f9 100755 --- a/pandora_console/operation/search_users.php +++ b/pandora_console/operation/search_users.php @@ -91,7 +91,7 @@ if (!$users || !$searchUsers) { } echo '
'; - ui_pagination($totalUsers); + // ui_pagination($totalUsers); html_print_table($table); unset($table); ui_pagination($totalUsers); diff --git a/pandora_console/operation/users/user_edit.php b/pandora_console/operation/users/user_edit.php index ec065a6a52..fcc719dfaa 100644 --- a/pandora_console/operation/users/user_edit.php +++ b/pandora_console/operation/users/user_edit.php @@ -462,6 +462,8 @@ $autorefresh_list_out['operation/agentes/status_monitor'] = 'Monitor detail'; $autorefresh_list_out['enterprise/operation/services/services'] = 'Services'; $autorefresh_list_out['enterprise/dashboard/main_dashboard'] = 'Dashboard'; $autorefresh_list_out['operation/reporting/graph_viewer'] = 'Graph Viewer'; +$autorefresh_list_out['operation/gis_maps/render_view'] = 'Gis Map'; + $autorefresh_list_out['operation/snmpconsole/snmp_view'] = 'SNMP console'; $autorefresh_list_out['operation/agentes/pandora_networkmap'] = 'Network map'; $autorefresh_list_out['operation/visual_console/render_view'] = 'Visual console'; @@ -1150,7 +1152,7 @@ function ehorus_connection_test(host, port) { var user = $('input#text-ehorus_user_level_user').val(); var pass = $('input#password-ehorus_user_level_pass').val(); - debugger; + var badRequestMessage = ''; var notFoundMessage = ''; var invalidPassMessage = ''; diff --git a/pandora_console/pandora_console.redhat.spec b/pandora_console/pandora_console.redhat.spec index 8d28ed95e0..a662559b87 100644 --- a/pandora_console/pandora_console.redhat.spec +++ b/pandora_console/pandora_console.redhat.spec @@ -2,8 +2,8 @@ # Pandora FMS Console # %define name pandorafms_console -%define version 7.0NG.739 -%define release 191010 +%define version 7.0NG.740 +%define release 191029 # User and Group under which Apache is running %define httpd_name httpd diff --git a/pandora_console/pandora_console.rhel7.spec b/pandora_console/pandora_console.rhel7.spec index b030fbcf7a..91f5bebedf 100644 --- a/pandora_console/pandora_console.rhel7.spec +++ b/pandora_console/pandora_console.rhel7.spec @@ -2,8 +2,8 @@ # Pandora FMS Console # %define name pandorafms_console -%define version 7.0NG.739 -%define release 191010 +%define version 7.0NG.740 +%define release 191029 # User and Group under which Apache is running %define httpd_name httpd diff --git a/pandora_console/pandora_console.spec b/pandora_console/pandora_console.spec index c23657e4be..1aa902495e 100644 --- a/pandora_console/pandora_console.spec +++ b/pandora_console/pandora_console.spec @@ -2,8 +2,8 @@ # Pandora FMS Console # %define name pandorafms_console -%define version 7.0NG.739 -%define release 191010 +%define version 7.0NG.740 +%define release 191029 %define httpd_name httpd # User and Group under which Apache is running %define httpd_name apache2 diff --git a/pandora_console/pandora_console_install b/pandora_console/pandora_console_install index 9ed0bd594a..34fc8cd0b6 100644 --- a/pandora_console/pandora_console_install +++ b/pandora_console/pandora_console_install @@ -9,7 +9,7 @@ # This code is licensed under GPL 2.0 license. # ********************************************************************** -PI_VERSION="7.0NG.739" +PI_VERSION="7.0NG.740" FORCE=0 DESTDIR="" LOG_TIMESTAMP=`date +"%Y/%m/%d %H:%M:%S"` diff --git a/pandora_console/pandoradb_data.sql b/pandora_console/pandoradb_data.sql index 686f4aa487..aac7b708fb 100644 --- a/pandora_console/pandoradb_data.sql +++ b/pandora_console/pandoradb_data.sql @@ -112,7 +112,7 @@ INSERT INTO `tconfig` (`token`, `value`) VALUES ('MR', 32), ('identification_reminder', 1), ('identification_reminder_timestamp', 0), -('current_package_enterprise', '739'), +('current_package_enterprise', '740'), ('post_process_custom_values', '{"0.00000038580247":"Seconds to months","0.00000165343915":"Seconds to weeks","0.00001157407407":"Seconds to days","0.01666666666667":"Seconds to minutes","0.00000000093132":"Bytes to Gigabytes","0.00000095367432":"Bytes to Megabytes","0.0009765625":"Bytes to Kilobytes","0.00000001653439":"Timeticks to weeks","0.00000011574074":"Timeticks to days"}'), ('custom_docs_logo', 'default_docs.png'), ('custom_support_logo', 'default_support.png'), diff --git a/pandora_server/DEBIAN/control b/pandora_server/DEBIAN/control index a9f17f7b0b..69b27f4f9a 100644 --- a/pandora_server/DEBIAN/control +++ b/pandora_server/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-server -Version: 7.0NG.739-191010 +Version: 7.0NG.740-191029 Architecture: all Priority: optional Section: admin diff --git a/pandora_server/DEBIAN/make_deb_package.sh b/pandora_server/DEBIAN/make_deb_package.sh index 7b0a1bb983..34f150ed54 100644 --- a/pandora_server/DEBIAN/make_deb_package.sh +++ b/pandora_server/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.739-191010" +pandora_version="7.0NG.740-191029" package_cpan=0 package_pandora=1 diff --git a/pandora_server/conf/pandora_server.conf.new b/pandora_server/conf/pandora_server.conf.new index 3aa61de07f..1b76b1cf66 100644 --- a/pandora_server/conf/pandora_server.conf.new +++ b/pandora_server/conf/pandora_server.conf.new @@ -1,7 +1,7 @@ ############################################################################# # Pandora FMS Server Parameters # Pandora FMS, the Flexible Monitoring System. -# Version 7.0NG.739 +# Version 7.0NG.740 # Licensed under GPL license v2, # (c) 2003-2017 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_server/lib/PandoraFMS/Config.pm b/pandora_server/lib/PandoraFMS/Config.pm index ea9941bb47..04e57e4525 100644 --- a/pandora_server/lib/PandoraFMS/Config.pm +++ b/pandora_server/lib/PandoraFMS/Config.pm @@ -44,8 +44,8 @@ our @EXPORT = qw( ); # version: Defines actual version of Pandora Server for this module only -my $pandora_version = "7.0NG.739"; -my $pandora_build = "191010"; +my $pandora_version = "7.0NG.740"; +my $pandora_build = "191029"; our $VERSION = $pandora_version." ".$pandora_build; # Setup hash diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index ef8a9c18bf..f575d8e02b 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -1141,21 +1141,21 @@ sub pandora_execute_action ($$$$$$$$$;$) { #logger($pa_config, "Clean name ".$clean_name, 10); # User defined alert if ($action->{'internal'} == 0) { - $macros{_field1_} = subst_alert_macros ($field1, \%macros, $pa_config, $dbh, $agent, $module); - $macros{_field2_} = subst_alert_macros ($field2, \%macros, $pa_config, $dbh, $agent, $module); - $macros{_field3_} = subst_alert_macros ($field3, \%macros, $pa_config, $dbh, $agent, $module); - $macros{_field4_} = subst_alert_macros ($field4, \%macros, $pa_config, $dbh, $agent, $module); - $macros{_field5_} = subst_alert_macros ($field5, \%macros, $pa_config, $dbh, $agent, $module); - $macros{_field6_} = subst_alert_macros ($field6, \%macros, $pa_config, $dbh, $agent, $module); - $macros{_field7_} = subst_alert_macros ($field7, \%macros, $pa_config, $dbh, $agent, $module); - $macros{_field8_} = subst_alert_macros ($field8, \%macros, $pa_config, $dbh, $agent, $module); - $macros{_field9_} = subst_alert_macros ($field9, \%macros, $pa_config, $dbh, $agent, $module); - $macros{_field10_} = subst_alert_macros ($field10, \%macros, $pa_config, $dbh, $agent, $module); - $macros{_field11_} = subst_alert_macros ($field11, \%macros, $pa_config, $dbh, $agent, $module); - $macros{_field12_} = subst_alert_macros ($field12, \%macros, $pa_config, $dbh, $agent, $module); - $macros{_field13_} = subst_alert_macros ($field13, \%macros, $pa_config, $dbh, $agent, $module); - $macros{_field14_} = subst_alert_macros ($field14, \%macros, $pa_config, $dbh, $agent, $module); - $macros{_field15_} = subst_alert_macros ($field15, \%macros, $pa_config, $dbh, $agent, $module); + $macros{_field1_} = subst_alert_macros ($field1, \%macros, $pa_config, $dbh, $agent, $module, $alert); + $macros{_field2_} = subst_alert_macros ($field2, \%macros, $pa_config, $dbh, $agent, $module, $alert); + $macros{_field3_} = subst_alert_macros ($field3, \%macros, $pa_config, $dbh, $agent, $module, $alert); + $macros{_field4_} = subst_alert_macros ($field4, \%macros, $pa_config, $dbh, $agent, $module, $alert); + $macros{_field5_} = subst_alert_macros ($field5, \%macros, $pa_config, $dbh, $agent, $module, $alert); + $macros{_field6_} = subst_alert_macros ($field6, \%macros, $pa_config, $dbh, $agent, $module, $alert); + $macros{_field7_} = subst_alert_macros ($field7, \%macros, $pa_config, $dbh, $agent, $module, $alert); + $macros{_field8_} = subst_alert_macros ($field8, \%macros, $pa_config, $dbh, $agent, $module, $alert); + $macros{_field9_} = subst_alert_macros ($field9, \%macros, $pa_config, $dbh, $agent, $module, $alert); + $macros{_field10_} = subst_alert_macros ($field10, \%macros, $pa_config, $dbh, $agent, $module, $alert); + $macros{_field11_} = subst_alert_macros ($field11, \%macros, $pa_config, $dbh, $agent, $module, $alert); + $macros{_field12_} = subst_alert_macros ($field12, \%macros, $pa_config, $dbh, $agent, $module, $alert); + $macros{_field13_} = subst_alert_macros ($field13, \%macros, $pa_config, $dbh, $agent, $module, $alert); + $macros{_field14_} = subst_alert_macros ($field14, \%macros, $pa_config, $dbh, $agent, $module, $alert); + $macros{_field15_} = subst_alert_macros ($field15, \%macros, $pa_config, $dbh, $agent, $module, $alert); my @command_args = (); # divide command into words based on quotes and whitespaces @@ -1186,7 +1186,7 @@ sub pandora_execute_action ($$$$$$$$$;$) { # Internal Audit } elsif ($clean_name eq "Internal Audit") { - $field1 = subst_alert_macros ($field1, \%macros, $pa_config, $dbh, $agent, $module); + $field1 = subst_alert_macros ($field1, \%macros, $pa_config, $dbh, $agent, $module, $alert); pandora_audit ($pa_config, $field1, defined ($agent) ? safe_output($agent->{'alias'}) : 'N/A', 'Alert (' . safe_output($alert->{'description'}) . ')', $dbh); # Email @@ -1363,12 +1363,12 @@ sub pandora_execute_action ($$$$$$$$$;$) { # Pandora FMS Event } elsif ($clean_name eq "Monitoring Event") { - $field1 = subst_alert_macros ($field1, \%macros, $pa_config, $dbh, $agent, $module); - $field3 = subst_alert_macros ($field3, \%macros, $pa_config, $dbh, $agent, $module); - $field4 = subst_alert_macros ($field4, \%macros, $pa_config, $dbh, $agent, $module); - $field6 = subst_alert_macros ($field6, \%macros, $pa_config, $dbh, $agent, $module); - $field7 = subst_alert_macros ($field7, \%macros, $pa_config, $dbh, $agent, $module); - $field8 = subst_alert_macros ($field8, \%macros, $pa_config, $dbh, $agent, $module); + $field1 = subst_alert_macros ($field1, \%macros, $pa_config, $dbh, $agent, $module, $alert); + $field3 = subst_alert_macros ($field3, \%macros, $pa_config, $dbh, $agent, $module, $alert); + $field4 = subst_alert_macros ($field4, \%macros, $pa_config, $dbh, $agent, $module, $alert); + $field6 = subst_alert_macros ($field6, \%macros, $pa_config, $dbh, $agent, $module, $alert); + $field7 = subst_alert_macros ($field7, \%macros, $pa_config, $dbh, $agent, $module, $alert); + $field8 = subst_alert_macros ($field8, \%macros, $pa_config, $dbh, $agent, $module, $alert); # Field 1 (event text) my $event_text = $field1; @@ -1448,13 +1448,13 @@ sub pandora_execute_action ($$$$$$$$$;$) { my $config_api_pass = pandora_get_tconfig_token ($dbh, 'integria_api_pass', ''); my $config_integria_user = pandora_get_tconfig_token ($dbh, 'integria_user', ''); my $config_integria_user_pass = pandora_get_tconfig_token ($dbh, 'integria_pass', ''); - $field1 = subst_alert_macros ($field1, \%macros, $pa_config, $dbh, $agent, $module); - $field2 = subst_alert_macros ($field2, \%macros, $pa_config, $dbh, $agent, $module); - $field3 = subst_alert_macros ($field3, \%macros, $pa_config, $dbh, $agent, $module); - $field4 = subst_alert_macros ($field4, \%macros, $pa_config, $dbh, $agent, $module); - $field5 = subst_alert_macros ($field5, \%macros, $pa_config, $dbh, $agent, $module); - $field6 = subst_alert_macros ($field6, \%macros, $pa_config, $dbh, $agent, $module); - $field7 = subst_alert_macros ($field7, \%macros, $pa_config, $dbh, $agent, $module); + $field1 = subst_alert_macros ($field1, \%macros, $pa_config, $dbh, $agent, $module, $alert); + $field2 = subst_alert_macros ($field2, \%macros, $pa_config, $dbh, $agent, $module, $alert); + $field3 = subst_alert_macros ($field3, \%macros, $pa_config, $dbh, $agent, $module, $alert); + $field4 = subst_alert_macros ($field4, \%macros, $pa_config, $dbh, $agent, $module, $alert); + $field5 = subst_alert_macros ($field5, \%macros, $pa_config, $dbh, $agent, $module, $alert); + $field6 = subst_alert_macros ($field6, \%macros, $pa_config, $dbh, $agent, $module, $alert); + $field7 = subst_alert_macros ($field7, \%macros, $pa_config, $dbh, $agent, $module, $alert); # Field 1 (Integria IMS API path) my $api_path = $config_api_path . "/integria/include/api.php"; @@ -1513,8 +1513,7 @@ sub pandora_execute_action ($$$$$$$$$;$) { } elsif ($clean_name eq "Generate Notification") { # Translate macros - $field3 = subst_alert_macros($field3, \%macros, $pa_config, $dbh, $agent, $module); - $field4 = subst_alert_macros($field4, \%macros, $pa_config, $dbh, $agent, $module); + $field3 = subst_alert_macros($field3, \%macros, $pa_config, $dbh, $agent, $module, $alert); # If no targets ignore notification if (defined($field1) && defined($field2) && ($field1 ne "" || $field2 ne "")) { @@ -3259,7 +3258,7 @@ sub pandora_create_agent ($$$$$$$$$$;$$$$$$$$$$) { 'custom_id' => $custom_id, 'url_address' => $url_address, 'timezone_offset' => $timezone_offset, - 'alias' => $alias, + 'alias' => safe_input($alias), 'update_module_count' => 1, # Force to replicate in metaconsole }); diff --git a/pandora_server/lib/PandoraFMS/DB.pm b/pandora_server/lib/PandoraFMS/DB.pm index a257d5df07..63c756e5ae 100644 --- a/pandora_server/lib/PandoraFMS/DB.pm +++ b/pandora_server/lib/PandoraFMS/DB.pm @@ -57,6 +57,7 @@ our @EXPORT = qw( get_addr_id get_agent_addr_id get_agent_id + get_agent_ids_from_alias get_agent_address get_agent_alias get_agent_group @@ -232,6 +233,17 @@ sub get_agent_id ($$) { return defined ($rc) ? $rc : -1; } +######################################################################## +## Return agent IDs given an agent alias. +######################################################################## +sub get_agent_ids_from_alias ($$) { + my ($dbh, $agent_alias) = @_; + + my @rc = get_db_rows ($dbh, "SELECT id_agente, nombre FROM tagente WHERE alias = ?", safe_input($agent_alias)); + + return @rc; +} + ######################################################################## ## Return server ID given the name of server. ######################################################################## @@ -956,7 +968,7 @@ sub db_process_insert($$$$;@) { } } my $columns_string = join(',', @columns_array); - + my $res = db_insert ($dbh, $index, "INSERT INTO $table ($columns_string) VALUES " . $wildcards, @values_array); diff --git a/pandora_server/lib/PandoraFMS/DataServer.pm b/pandora_server/lib/PandoraFMS/DataServer.pm index b7beb919a3..df1cbbecfb 100644 --- a/pandora_server/lib/PandoraFMS/DataServer.pm +++ b/pandora_server/lib/PandoraFMS/DataServer.pm @@ -230,7 +230,7 @@ sub data_consumer ($$) { } # Ignore the timestamp in the XML and use the file timestamp instead - $xml_data->{'timestamp'} = strftime ("%Y-%m-%d %H:%M:%S", localtime((stat($file_name))[9])) if ($pa_config->{'use_xml_timestamp'} eq '1' || ! defined ($xml_data->{'timestamp'})); + $xml_data->{'timestamp'} = strftime ("%Y-%m-%d %H:%M:%S", localtime((stat($file_name))[9])) if ($pa_config->{'use_xml_timestamp'} eq '0' || ! defined ($xml_data->{'timestamp'})); # Double check that the file exists if (! -f $file_name) { diff --git a/pandora_server/lib/PandoraFMS/DiscoveryServer.pm b/pandora_server/lib/PandoraFMS/DiscoveryServer.pm index b2d8e71619..7d90ff411a 100644 --- a/pandora_server/lib/PandoraFMS/DiscoveryServer.pm +++ b/pandora_server/lib/PandoraFMS/DiscoveryServer.pm @@ -360,8 +360,9 @@ sub PandoraFMS::Recon::Base::guess_os($$) { if (-x $self->{'pa_config'}->{'xprobe2'}) { my $return = `"$self->{pa_config}->{xprobe2}" $device 2>$DEVNULL`; if ($? == 0) { - my ($output) = $a =~ /Running OS:(.*)/; - return pandora_get_os($self->{'dbh'}, $output); + if($return =~ /Running OS:(.*)/) { + return pandora_get_os($self->{'dbh'}, $1); + } } } @@ -370,8 +371,9 @@ sub PandoraFMS::Recon::Base::guess_os($$) { my $return = `"$self->{pa_config}->{nmap}" -F -O $device 2>$DEVNULL`; return OS_OTHER if ($? != 0); - my ($output) = $return =~ /Aggressive OS guesses:\s*(.*)/; - return pandora_get_os($self->{'dbh'}, $output); + if ($return =~ /Aggressive OS guesses:\s*(.*)/) { + return pandora_get_os($self->{'dbh'}, $1); + } } return OS_OTHER; @@ -536,7 +538,7 @@ sub PandoraFMS::Recon::Base::create_agents($$) { return undef; } - if ($agent->{'address'} ne '') { + if (defined($agent->{'address'}) && $agent->{'address'} ne '') { pandora_add_agent_address( $pa_config, $agent_id, $agent->{'agent_name'}, $agent->{'address'}, $dbh @@ -582,44 +584,14 @@ sub PandoraFMS::Recon::Base::create_agent($$) { # Clean name. $device = clean_blank($device); - my @agents = get_db_rows($self->{'dbh'}, - 'SELECT * FROM taddress, taddress_agent, tagente - WHERE tagente.id_agente = taddress_agent.id_agent - AND taddress_agent.id_a = taddress.id_a - AND ip = ?', $device - ); - - # Does the host already exist? - my $agent; - foreach my $candidate (@agents) { - $agent = {map {$_} %$candidate}; # copy contents, do not use shallow copy - # exclude $device itself, because it handle corner case when target includes NAT - my @registered = map {$_->{ip}} get_db_rows($self->{'dbh'}, - 'SELECT ip FROM taddress, taddress_agent, tagente - WHERE tagente.id_agente = taddress_agent.id_agent - AND taddress_agent.id_a = taddress.id_a - AND tagente.id_agente = ? - AND taddress.ip != ?', $agent->{id_agente}, $device - ); - foreach my $ip_addr (@registered) { - my @matched = grep { $_ =~ /^$ip_addr$/ } $self->get_addresses($device); - if (scalar(@matched) == 0) { - $agent = undef; - last; - } - } - last if(defined($agent)); # exit loop if match all ip_addr - } - - if (!defined($agent)) { - $agent = get_agent_from_name($self->{'dbh'}, $device); - } + # Resolve hostnames. + my $host_name = (($self->{'resolve_names'} == 1) ? gethostbyaddr(inet_aton($device), AF_INET) : $device); + # Fallback to device IP if host name could not be resolved. + $host_name = $device if (!defined($host_name) || $host_name eq ''); + my $agent = locate_agent($self->{'pa_config'}, $self->{'dbh'}, $host_name); my ($agent_id, $agent_learning); if (!defined($agent)) { - - # Resolve hostnames. - my $host_name = $self->{'resolve_names'} == 1 ? gethostbyaddr (inet_aton($device), AF_INET) : $device; $host_name = $device unless defined ($host_name); # Guess the OS. diff --git a/pandora_server/lib/PandoraFMS/PluginTools.pm b/pandora_server/lib/PandoraFMS/PluginTools.pm index c235a8acf3..287b11e900 100644 --- a/pandora_server/lib/PandoraFMS/PluginTools.pm +++ b/pandora_server/lib/PandoraFMS/PluginTools.pm @@ -31,8 +31,8 @@ use base 'Exporter'; our @ISA = qw(Exporter); # version: Defines actual version of Pandora Server for this module only -my $pandora_version = "7.0NG.739"; -my $pandora_build = "191010"; +my $pandora_version = "7.0NG.740"; +my $pandora_build = "191029"; our $VERSION = $pandora_version." ".$pandora_build; our %EXPORT_TAGS = ( 'all' => [ qw() ] ); @@ -762,7 +762,7 @@ sub transfer_xml { my $file_path; if (! (empty ($name))) { - $file_name = $name . "." . sprintf("%d",time()) . ".data"; + $file_name = $name . "." . sprintf("%d",getCurrentUTimeMilis(). (rand()*10000)) . ".data"; } else { # Inherit file name diff --git a/pandora_server/lib/PandoraFMS/Tools.pm b/pandora_server/lib/PandoraFMS/Tools.pm index df9d5b3901..ba15f03d24 100755 --- a/pandora_server/lib/PandoraFMS/Tools.pm +++ b/pandora_server/lib/PandoraFMS/Tools.pm @@ -141,6 +141,7 @@ our @EXPORT = qw( long_to_ip ip_to_long get_enabled_servers + dateTimeToTimestamp ); # ID of the different servers @@ -641,19 +642,29 @@ sub logger ($$;$) { # Set the security level my $security_level = 'info'; if ($level < 2) { - $security = 'crit'; + $security_level = 'crit'; } elsif ($level < 5) { - $security = 'warn'; + $security_level = 'warn'; } openlog('pandora_server', 'ndelay', 'daemon'); syslog($security_level, $message); closelog(); } else { + # Obtain the script that invoke this log + my $parent_caller = ""; + $parent_caller = ( caller(2) )[1]; + if (defined $parent_caller) { + $parent_caller = (split '/', $parent_caller)[-1]; + $parent_caller =~ s/\.[^.]+$//; + $parent_caller = " ** " . $parent_caller . " **: "; + } else { + $parent_caller = " "; + } open (FILE, ">> $file") or die "[FATAL] Could not open logfile '$file'"; # Get an exclusive lock on the file (LOCK_EX) flock (FILE, 2); - print FILE strftime ("%Y-%m-%d %H:%M:%S", localtime()) . " " . (defined($pa_config->{'servername'}) ? $pa_config->{'servername'} : '') . " [V". $level ."] " . $message . "\n"; + print FILE strftime ("%Y-%m-%d %H:%M:%S", localtime()) . $parent_caller . (defined($pa_config->{'servername'}) ? $pa_config->{'servername'} : '') . " [V". $level ."] " . $message . "\n"; close (FILE); } } diff --git a/pandora_server/pandora_server.redhat.spec b/pandora_server/pandora_server.redhat.spec index e4370a41b7..805efb4c41 100644 --- a/pandora_server/pandora_server.redhat.spec +++ b/pandora_server/pandora_server.redhat.spec @@ -2,8 +2,8 @@ # Pandora FMS Server # %define name pandorafms_server -%define version 7.0NG.739 -%define release 191010 +%define version 7.0NG.740 +%define release 191029 Summary: Pandora FMS Server Name: %{name} diff --git a/pandora_server/pandora_server.spec b/pandora_server/pandora_server.spec index 39180c91ca..e2eb323b24 100644 --- a/pandora_server/pandora_server.spec +++ b/pandora_server/pandora_server.spec @@ -2,8 +2,8 @@ # Pandora FMS Server # %define name pandorafms_server -%define version 7.0NG.739 -%define release 191010 +%define version 7.0NG.740 +%define release 191029 Summary: Pandora FMS Server Name: %{name} diff --git a/pandora_server/pandora_server_installer b/pandora_server/pandora_server_installer index 302c4355a7..6b1870fadf 100755 --- a/pandora_server/pandora_server_installer +++ b/pandora_server/pandora_server_installer @@ -8,8 +8,8 @@ # This code is licensed under GPL 2.0 license. # ********************************************************************** -PI_VERSION="7.0NG.739" -PI_BUILD="191010" +PI_VERSION="7.0NG.740" +PI_BUILD="191029" MODE=$1 if [ $# -gt 1 ]; then diff --git a/pandora_server/util/pandora_db.pl b/pandora_server/util/pandora_db.pl index b1e06cb14d..a9cc09579b 100644 --- a/pandora_server/util/pandora_db.pl +++ b/pandora_server/util/pandora_db.pl @@ -34,7 +34,7 @@ use PandoraFMS::Config; use PandoraFMS::DB; # version: define current version -my $version = "7.0NG.739 PS191010"; +my $version = "7.0NG.740 PS191029"; # Pandora server configuration my %conf; diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index 0365db0acf..3b72f91063 100755 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -36,7 +36,7 @@ use Encode::Locale; Encode::Locale::decode_argv; # version: define current version -my $version = "7.0NG.739 PS191010"; +my $version = "7.0NG.740 PS191029"; # save program name for logging my $progname = basename($0); @@ -104,8 +104,8 @@ sub help_screen{ print "Available options for $param:\n\n" unless $param eq ''; print "AGENTS:\n\n" unless $param ne ''; help_screen_line('--create_agent', " \n\t [
]", 'Create agent'); - help_screen_line('--update_agent', ' ', "Update an agent field. The fields can be \n\t the following: agent_name, address, description, group_name, interval, os_name, disabled (0-1), \n\t parent_name, cascade_protection (0-1), icon_path, update_gis_data (0-1), custom_id"); - help_screen_line('--delete_agent', '', 'Delete agent'); + help_screen_line('--update_agent', ' []', "Update an agent field. The fields can be \n\t the following: agent_name, address, description, group_name, interval, os_name, disabled (0-1), \n\t parent_name, cascade_protection (0-1), icon_path, update_gis_data (0-1), custom_id"); + help_screen_line('--delete_agent', ' []', 'Delete agent'); help_screen_line('--disable_group', '', 'Disable agents from an entire group'); help_screen_line('--enable_group', '', 'Enable agents from an entire group'); help_screen_line('--create_group', ' [ ]', 'Create an agent group'); @@ -118,14 +118,14 @@ sub help_screen{ help_screen_line('--get_planned_downtimes_items', ' [ ]', 'Get all items of planned downtimes'); help_screen_line('--set_planned_downtimes_deleted', ' ', 'Deleted a planned downtime'); help_screen_line('--get_module_id', ' ', 'Get the id of an module'); - help_screen_line('--get_agent_group', '', 'Get the group name of an agent'); - help_screen_line('--get_agent_group_id', '', 'Get the group ID of an agent'); - help_screen_line('--get_agent_modules', '', 'Get the modules of an agent'); - help_screen_line('--get_agents', '[ ]', "Get \n\t list of agents with optative filter parameters"); - help_screen_line('--delete_conf_file', '', 'Delete a local conf of a given agent'); - help_screen_line('--clean_conf_file', '', "Clean a local conf of a given agent deleting all modules, \n\t policies, file collections and comments"); + help_screen_line('--get_agent_group', ' []', 'Get the group name of an agent'); + help_screen_line('--get_agent_group_id', ' []', 'Get the group ID of an agent'); + help_screen_line('--get_agent_modules', ' []', 'Get the modules of an agent'); + help_screen_line('--get_agents', '[ ]', "Get \n\t list of agents with optative filter parameters"); + help_screen_line('--delete_conf_file', ' []', 'Delete a local conf of a given agent'); + help_screen_line('--clean_conf_file', ' []', "Clean a local conf of a given agent deleting all modules, \n\t policies, file collections and comments"); help_screen_line('--get_bad_conf_files', '', 'Get the files bad configured (without essential tokens)'); - help_screen_line('--locate_agent', '', 'Search a agent into of nodes of metaconsole. Only Enterprise.'); + help_screen_line('--locate_agent', ' []', 'Search a agent into of nodes of metaconsole. Only Enterprise.'); help_screen_line('--migration_agent_queue', ' []', 'Migrate agent only metaconsole'); help_screen_line('--migration_agent', ' ', 'Is migrating the agent only metaconsole'); help_screen_line('--apply_module_template', ' ', 'Apply module template to agent'); @@ -139,29 +139,29 @@ sub help_screen{ help_screen_line('--set_disabled_and_standby', ' ', 'Overwrite and disable and standby status'); help_screen_line('--reset_agent_counts', '', 'Resets module counts and alert counts in the agents'); print "\nMODULES:\n\n" unless $param ne ''; - help_screen_line('--create_data_module', " [ \n\t \n\t \n\t \n\t \n\t ]", 'Add data server module to agent'); - help_screen_line('--create_web_module', " [ \n\t \n\t \n\t \n\t \n\t \n\t ].\n\t The valid data types are web_data, web_proc, web_content_data or web_content_string", 'Add web server module to agent'); - help_screen_line('--create_network_module', " \n\t [ \n\t \n\t \n\t \n\t \n\t ]", 'Add not snmp network module to agent'); - help_screen_line('--create_snmp_module', " \n\t [ \n\t \n\t \n\t \n\t \n\t + help_screen_line('--create_data_module', " [ \n\t \n\t \n\t \n\t \n\t ]", 'Add data server module to agent'); + help_screen_line('--create_web_module', " [ \n\t \n\t \n\t \n\t \n\t \n\t ].\n\t The valid data types are web_data, web_proc, web_content_data or web_content_string", 'Add web server module to agent'); + help_screen_line('--create_network_module', " \n\t [ \n\t \n\t \n\t \n\t \n\t ]", 'Add not snmp network module to agent'); + help_screen_line('--create_snmp_module', " \n\t [ \n\t \n\t \n\t \n\t \n\t ] \n\t \n\t ]", 'Add snmp network module to agent'); - help_screen_line('--create_plugin_module', " \n\t [ \n\t \n\t \n\t \n\t \n\t \n\t ]", 'Add plug-in module to agent'); + help_screen_line('--create_plugin_module', " \n\t [ \n\t \n\t \n\t \n\t \n\t \n\t ]", 'Add plug-in module to agent'); help_screen_line('--get_module_group', '[]', 'Dysplay all module groups'); help_screen_line('--create_module_group', ''); help_screen_line('--module_group_synch', " []", 'Synchronize metaconsole module groups'); - help_screen_line('--delete_module', 'Delete module from agent', ' '); - help_screen_line('--data_module', " \n\t []", 'Insert data to module'); - help_screen_line('--get_module_data', " []", "\n\t Show the data of a module in the last X seconds (interval) in CSV format"); - help_screen_line('--delete_data', '-m | -a | -g ', "Delete historic \n\t data of a module, the modules of an agent or the modules of the agents of a group"); - help_screen_line('--update_module', ' ', 'Update a module field'); + help_screen_line('--delete_module', 'Delete module from agent', ' []'); + help_screen_line('--data_module', " \n\t [ ]", 'Insert data to module'); + help_screen_line('--get_module_data', " [ ]", "\n\t Show the data of a module in the last X seconds (interval) in CSV format"); + help_screen_line('--delete_data', '-m | -a | -g []', "Delete historic \n\t data of a module, the modules of an agent or the modules of the agents of a group"); + help_screen_line('--update_module', ' []', 'Update a module field'); help_screen_line('--get_agents_module_current_data', '', "Get the agent and current data \n\t of all the modules with a given name"); - help_screen_line('--create_network_module_from_component', ' ', "Create a new network \n\t module from a network component"); + help_screen_line('--create_network_module_from_component', ' []', "Create a new network \n\t module from a network component"); help_screen_line('--create_network_component', " \n\t [ \n\t \n\t \n\t \n\t \n\t \n\t ]", "Create a new network component"); - help_screen_line('--create_synthetic', " ,,|, \n\t [ , | ,, ]", "Create a new Synthetic module"); + help_screen_line('--create_synthetic', " ,,|, \n\t [ , | ,, ]", "Create a new Synthetic module"); print "\nALERTS:\n\n" unless $param ne ''; - help_screen_line('--create_template_module', ' ', 'Add alert template to module'); - help_screen_line('--delete_template_module', ' ', 'Delete alert template from module'); - help_screen_line('--create_template_action', " \n\t [ ]', 'Add alert action to module-template"); - help_screen_line('--delete_template_action', " \n\t ", 'Delete alert action from module-template'); + help_screen_line('--create_template_module', ' []', 'Add alert template to module'); + help_screen_line('--delete_template_module', ' []', 'Delete alert template from module'); + help_screen_line('--create_template_action', " \n\t [ ]', 'Add alert action to module-template"); + help_screen_line('--delete_template_action', " \n\t []", 'Delete alert action from module-template'); help_screen_line('--disable_alerts', '', 'Disable alerts in all groups (system wide)'); help_screen_line('--enable_alerts', '', 'Enable alerts in all groups (system wide)'); help_screen_line('--create_alert_template', " \n\t [ \n\t \n\t \n\t ]", 'Create alert template'); @@ -175,7 +175,7 @@ sub help_screen{ help_screen_line('--create_special_day', " ", 'Create special day'); help_screen_line('--delete_special_day', '', 'Delete special day'); help_screen_line('--update_special_day', " ", 'Update a field of a special day'); - help_screen_line('--create_data_module_from_local_component', ' ', "Create a new data \n\t module from a local component"); + help_screen_line('--create_data_module_from_local_component', ' []', "Create a new data \n\t module from a local component"); help_screen_line('--create_local_component', " [ \n\t \n\t \n\t \n\t \n\t \n\t \n\t \n\t ]", 'Create local component'); print "\nUSERS:\n\n" unless $param ne ''; @@ -193,17 +193,17 @@ sub help_screen{ help_screen_line('--disable_double_auth', '', 'Disable the double authentication for the specified user'); help_screen_line('--meta_synch_user', " [ \n\t ]", 'Synchronize metaconsole users'); print "\nEVENTS:\n\n" unless $param ne ''; - help_screen_line('--create_event', " [ \n\t \n\t \n\t ]", 'Add event'); - help_screen_line('--validate_event', " \n\t ", 'Validate events'); - help_screen_line('--validate_event_id', '', 'Validate event given a event id'); - help_screen_line('--get_event_info', '[]', 'Show info about a event given a event id'); - help_screen_line('--add_event_comment', ' ', 'Add event\'s comment'); + help_screen_line('--create_event', " [ \n\t \n\t \n\t ]", 'Add event'); + help_screen_line('--validate_event', " \n\t []", 'Validate events'); + help_screen_line('--validate_event_id', '', 'Validate event given a event id'); + help_screen_line('--get_event_info', '[]', 'Show info about a event given a event id'); + help_screen_line('--add_event_comment', ' ', 'Add event\'s comment'); print "\nINCIDENTS:\n\n" unless $param ne ''; help_screen_line('--create_incident', " <description> <origin> <status> <priority 0 for Informative, \n\t 1 for Low, 2 for Medium, 3 for Serious, 4 for Very serious or 5 for Maintenance>\n\t <group> [<owner>]", 'Create incidents'); print "\nPOLICIES:\n\n" unless $param ne ''; help_screen_line('--apply_policy', '<id_policy> [<id_agent> <name(boolean)> <id_server>]', 'Force apply a policy in an agent'); help_screen_line('--apply_all_policies', '', 'Force apply to all the policies'); - help_screen_line('--add_agent_to_policy', '<agent_name> <policy_name>', 'Add an agent to a policy'); + help_screen_line('--add_agent_to_policy', '<agent_name> <policy_name> [<use_alias>]', 'Add an agent to a policy'); help_screen_line('--remove_agent_from_policy', '<policy_id> <agent_id>', 'Delete an agent to a policy'); help_screen_line('--delete_not_policy_modules', '', 'Delete all modules without policy from configuration file'); help_screen_line('--disable_policy_alerts', '<policy_name>', 'Disable all the alerts of a policy'); @@ -218,7 +218,7 @@ sub help_screen{ help_screen_line('--add_collection_to_policy', "<policy_name> <collection_name>"); help_screen_line('--validate_policy_alerts', '<policy_name>', 'Validate the alerts of a given policy'); help_screen_line('--get_policy_modules', '<policy_name>', 'Get the modules of a policy'); - help_screen_line('--get_policies', '[<agent_name>]', "Get all the policies (without parameters) or \n\tthe policies of a given agent (agent name as parameter)"); + help_screen_line('--get_policies', '[<agent_name> <use_alias>]', "Get all the policies (without parameters) or \n\tthe policies of a given agent (agent name as parameter)"); help_screen_line('--recreate_collection', '<collection_id>', 'Recreate the files of a collection'); print "\nNETFLOW:\n\n" unless $param ne ''; @@ -1135,19 +1135,26 @@ sub cli_create_agent() { ############################################################################## sub cli_delete_agent() { - my $agent_name = @ARGV[2]; + my ($agent_name,$use_alias) = @ARGV[2..3]; + + my @id_agents; + my $id_agent; $agent_name = decode_entities($agent_name); - + if (is_metaconsole($conf) == 1) { - my $agents_groups = enterprise_hook('get_metaconsole_agent',[$dbh, $agent_name]); - - if (scalar(@{$agents_groups}) != 0) { - foreach my $agent (@{$agents_groups}) { - my $return = enterprise_hook('delete_metaconsole_agent',[$dbh,$agent->{'id_agente'}]); - print_log "[INFO] Deleting agent '$agent_name' \n\n"; + if (not defined $use_alias) { + my $agents_groups = enterprise_hook('get_metaconsole_agent',[$dbh, $agent_name]); + + if (scalar(@{$agents_groups}) != 0) { + foreach my $agent (@{$agents_groups}) { + my $return = enterprise_hook('delete_metaconsole_agent',[$dbh,$agent->{'id_agente'}]); + print_log "[INFO] Deleting agent '$agent_name' \n\n"; + } } } + + my $servers = enterprise_hook('get_metaconsole_setup_servers',[$dbh]); my @servers_id = split(',',$servers); my @list_servers; @@ -1155,24 +1162,58 @@ sub cli_delete_agent() { foreach my $server (@servers_id) { my $dbh_metaconsole = enterprise_hook('get_node_dbh',[$conf, $server, $dbh]); - my $id_agent = get_agent_id($dbh_metaconsole,$agent_name); + my @id_agents; + my $id_agent; + + if (defined $use_alias and $use_alias eq 'use_alias') { + @id_agents = get_agent_ids_from_alias($dbh_metaconsole,$agent_name); + + foreach my $id (@id_agents) { + + if ($id->{'id_agente'} == -1) { + next; + } + else { + print_log "[INFO] Deleting agent '$id->{'nombre'}' in ID server: '$server'\n\n"; + pandora_delete_agent($dbh_metaconsole,$id->{'id_agente'},$conf); + } + } + } else { + $id_agent = get_agent_id($dbh_metaconsole,$agent_name); + + if ($id_agent == -1) { + next; + } + else { + print_log "[INFO] Deleting agent '$agent_name' in ID server: '$server'\n\n"; + pandora_delete_agent($dbh_metaconsole,$id_agent,$conf); + } + } + - if ($id_agent == -1) { - next; - } - else { - print_log "[INFO] Deleting agent '$agent_name' in ID server: '$server'\n\n"; - pandora_delete_agent($dbh_metaconsole,$id_agent,$conf); - } } } else { - - my $id_agent = get_agent_id($dbh,$agent_name); - exist_check($id_agent,'agent',$agent_name); - - print_log "[INFO] Deleting agent '$agent_name'\n\n"; - pandora_delete_agent($dbh,$id_agent,$conf); + my @id_agents; + my $id_agent; + + if (defined $use_alias and $use_alias eq 'use_alias') { + @id_agents = get_agent_ids_from_alias($dbh,$agent_name); + } else { + $id_agent = get_agent_id($dbh,$agent_name); + exist_check($id_agent,'agent',$agent_name); + } + + if (defined $use_alias and $use_alias eq 'use_alias') { + foreach my $id (@id_agents) { + exist_check($id->{'id_agente'},'agent',$agent_name); + print_log "[INFO] Deleting agent '$id->{'nombre'}'\n\n"; + pandora_delete_agent($dbh,$id->{'id_agente'},$conf); + } + } else { + print_log "[INFO] Deleting agent '$agent_name'\n\n"; + pandora_delete_agent($dbh,$id_agent,$conf); + } } } @@ -1290,14 +1331,14 @@ sub cli_create_data_module($) { $min,$max,$post_process, $interval, $warning_min, $warning_max, $critical_min, $critical_max, $history_data, $definition_file, $configuration_data, $warning_str, $critical_str, $enable_unknown_events, $ff_threshold, $each_ff, $ff_threshold_normal, $ff_threshold_warning, $ff_threshold_critical, $ff_timeout, - $warning_inverse, $critical_inverse, $critical_instructions, $warning_instructions, $unknown_instructions); + $warning_inverse, $critical_inverse, $critical_instructions, $warning_instructions, $unknown_instructions, $use_alias); if ($in_policy == 0) { ($module_name, $module_type, $agent_name, $description, $module_group, $min,$max,$post_process, $interval, $warning_min, $warning_max, $critical_min, $critical_max, $history_data, $definition_file, $warning_str, $critical_str, $enable_unknown_events, $ff_threshold, $each_ff, $ff_threshold_normal, $ff_threshold_warning, $ff_threshold_critical, $ff_timeout, - $warning_inverse, $critical_inverse, $critical_instructions, $warning_instructions, $unknown_instructions) = @ARGV[2..30]; + $warning_inverse, $critical_inverse, $critical_instructions, $warning_instructions, $unknown_instructions, $use_alias) = @ARGV[2..31]; } else { ($policy_name, $module_name, $module_type, $description, $module_group, @@ -1311,6 +1352,7 @@ sub cli_create_data_module($) { my $module_type_def; my $agent_id; + my @id_agents; my $policy_id; my $disabled_types_event = {}; @@ -1323,13 +1365,22 @@ sub cli_create_data_module($) { my $disabled_types_event_json = encode_json($disabled_types_event); if ($in_policy == 0) { - $agent_id = get_agent_id($dbh,$agent_name); - exist_check($agent_id,'agent',$agent_name); - - my $module_exists = get_agent_module_id($dbh, $module_name, $agent_id); - non_exist_check($module_exists, 'module name', $module_name); - - #~ print_log "[INFO] Adding module '$module_name' to agent '$agent_name'\n\n"; + if (defined $use_alias and $use_alias eq 'use_alias') { + @id_agents = get_agent_ids_from_alias($dbh,$agent_name); + + foreach my $id (@id_agents) { + exist_check($id->{'id_agente'},'agent',$agent_name); + + my $module_exists = get_agent_module_id($dbh, $module_name, $id->{'id_agente'}); + non_exist_check($module_exists, 'module name', $module_name); + } + } else { + $agent_id = get_agent_id($dbh,$agent_name); + exist_check($agent_id,'agent',$agent_name); + + my $module_exists = get_agent_module_id($dbh, $module_name, $agent_id); + non_exist_check($module_exists, 'module name', $module_name); + } } else { $policy_id = enterprise_hook('get_policy_id',[$dbh, safe_input($policy_name)]); @@ -1343,44 +1394,91 @@ sub cli_create_data_module($) { $module_name_def = $module_name; $module_type_def = $module_type; - # If the module is local and is not to policy, we add it to the conf file - if (defined($definition_file) && (-e $definition_file) && (-e $conf->{incomingdir}.'/conf/'.md5($agent_name).'.conf')){ - open (FILE, $definition_file); - my @file = <FILE>; - my $definition = join("", @file); - close (FILE); - - # If the parameter name or type and the definition file name or type - # dont match will be set the file definitions - open (FILE, $definition_file); - while (<FILE>) { - chomp; - my ($key, $val) = split / /,2; - if ($key eq 'module_name') { - $module_name_def = $val; - } - if ($key eq 'module_type') { - $module_type_def = $val; + + if (defined $use_alias and $use_alias eq 'use_alias') { + foreach my $id (@id_agents) { + # If the module is local and is not to policy, we add it to the conf file + if (defined($definition_file) && (-e $definition_file) && (-e $conf->{incomingdir}.'/conf/'.md5($id->{'nombre'}).'.conf')){ + open (FILE, $definition_file); + my @file = <FILE>; + my $definition = join("", @file); + close (FILE); + + # If the parameter name or type and the definition file name or type + # dont match will be set the file definitions + open (FILE, $definition_file); + while (<FILE>) { + chomp; + my ($key, $val) = split / /,2; + if ($key eq 'module_name') { + $module_name_def = $val; + } + if ($key eq 'module_type') { + $module_type_def = $val; + } + } + close (FILE); + + open (FILE, $conf->{incomingdir}.'/conf/'.md5($id->{'nombre'}).'.conf'); + my @file = <FILE>; + my $conf_file = join("", @file); + close(FILE); + + open FILE, "> ".$conf->{incomingdir}.'/conf/'.md5($id->{'nombre'}).'.conf'; + print FILE "$conf_file\n$definition"; + close(FILE); + + enterprise_hook('pandora_update_md5_file', [$conf, $id->{'nombre'}]); } } - close (FILE); - - open (FILE, $conf->{incomingdir}.'/conf/'.md5($agent_name).'.conf'); - my @file = <FILE>; - my $conf_file = join("", @file); - close(FILE); - - open FILE, "> ".$conf->{incomingdir}.'/conf/'.md5($agent_name).'.conf'; - print FILE "$conf_file\n$definition"; - close(FILE); - - enterprise_hook('pandora_update_md5_file', [$conf, $agent_name]); + } else { + # If the module is local and is not to policy, we add it to the conf file + if (defined($definition_file) && (-e $definition_file) && (-e $conf->{incomingdir}.'/conf/'.md5($agent_name).'.conf')){ + open (FILE, $definition_file); + my @file = <FILE>; + my $definition = join("", @file); + close (FILE); + + # If the parameter name or type and the definition file name or type + # dont match will be set the file definitions + open (FILE, $definition_file); + while (<FILE>) { + chomp; + my ($key, $val) = split / /,2; + if ($key eq 'module_name') { + $module_name_def = $val; + } + if ($key eq 'module_type') { + $module_type_def = $val; + } + } + close (FILE); + + open (FILE, $conf->{incomingdir}.'/conf/'.md5($agent_name).'.conf'); + my @file = <FILE>; + my $conf_file = join("", @file); + close(FILE); + + open FILE, "> ".$conf->{incomingdir}.'/conf/'.md5($agent_name).'.conf'; + print FILE "$conf_file\n$definition"; + close(FILE); + + enterprise_hook('pandora_update_md5_file', [$conf, $agent_name]); + } } if ($in_policy == 0) { - my $module_exists = get_agent_module_id($dbh, $module_name_def, $agent_id); - non_exist_check($module_exists, 'module name', $module_name_def); - print_log "[INFO] Adding module '$module_name' to agent '$agent_name'\n\n"; + if (defined $use_alias and $use_alias eq 'use_alias') { + foreach my $id (@id_agents) { + my $module_exists = get_agent_module_id($dbh, $module_name_def, $id->{'id_agente'}); + non_exist_check($module_exists, 'module name', $module_name_def); + print_log "[INFO] Adding module '$module_name' to agent '$id->{'nombre'}'\n\n"; + } + } else { + my $module_exists = get_agent_module_id($dbh, $module_name_def, $agent_id); + non_exist_check($module_exists, 'module name', $module_name_def); + print_log "[INFO] Adding module '$module_name' to agent '$agent_name'\n\n"; + } } else { my $policy_module_exist = enterprise_hook('get_policy_module_id',[$dbh, $policy_id, $module_name_def]); @@ -1398,7 +1496,6 @@ sub cli_create_data_module($) { print_log "[INFO] The module name has been forced to '$module_name' by the definition file\n\n"; } - # The get_module_id has wrong name. Change in future my $module_type_id = get_module_id($dbh,$module_type); exist_check($module_type_id,'module type',$module_type); @@ -1417,10 +1514,13 @@ sub cli_create_data_module($) { my %parameters; $parameters{'id_tipo_modulo'} = $module_type_id; - + if ($in_policy == 0) { $parameters{'nombre'} = safe_input($module_name); - $parameters{'id_agente'} = $agent_id; + + if (not defined $use_alias) { + $parameters{'id_agente'} = $agent_id; + } } else { $parameters{'name'} = safe_input($module_name); @@ -1464,7 +1564,14 @@ sub cli_create_data_module($) { $parameters{'unknown_instructions'} = $unknown_instructions unless !defined ($unknown_instructions); if ($in_policy == 0) { - pandora_create_module_from_hash ($conf, \%parameters, $dbh); + if (defined $use_alias and $use_alias eq 'use_alias') { + foreach my $id (@id_agents) { + $parameters{'id_agente'} = $id->{'id_agente'}; + pandora_create_module_from_hash ($conf, \%parameters, $dbh); + } + } else { + pandora_create_module_from_hash ($conf, \%parameters, $dbh); + } } else { enterprise_hook('pandora_create_policy_module_from_hash', [$conf, \%parameters, $dbh]); @@ -1483,7 +1590,7 @@ sub cli_create_web_module($) { $critical_max, $history_data, $retries, $requests, $agent_browser_id, $auth_server, $auth_realm, $definition_file, $proxy_url, $proxy_auth_login, $proxy_auth_password, $configuration_data, $warning_str, $critical_str, $enable_unknown_events, $ff_threshold, $each_ff, $ff_threshold_normal, $ff_threshold_warning, $ff_threshold_critical, $ff_timeout, - $warning_inverse, $critical_inverse, $critical_instructions, $warning_instructions, $unknown_instructions); + $warning_inverse, $critical_inverse, $critical_instructions, $warning_instructions, $unknown_instructions, $use_alias); if ($in_policy == 0) { ($module_name, $module_type, $agent_name, $description, $module_group, @@ -1491,7 +1598,7 @@ sub cli_create_web_module($) { $critical_max, $history_data, $retries, $requests, $agent_browser_id, $auth_server, $auth_realm, $definition_file, $proxy_url, $proxy_auth_login, $proxy_auth_password, $warning_str, $critical_str, $enable_unknown_events, $ff_threshold, $each_ff, $ff_threshold_normal, $ff_threshold_warning, $ff_threshold_critical, $ff_timeout, - $warning_inverse, $critical_inverse, $critical_instructions, $warning_instructions, $unknown_instructions) = @ARGV[2..38]; + $warning_inverse, $critical_inverse, $critical_instructions, $warning_instructions, $unknown_instructions, $use_alias) = @ARGV[2..39]; } else { ($policy_name, $module_name, $module_type, $description, $module_group, @@ -1506,6 +1613,7 @@ sub cli_create_web_module($) { my $module_type_def; my $agent_id; + my @id_agents; my $policy_id; my $disabled_types_event = {}; @@ -1518,13 +1626,22 @@ sub cli_create_web_module($) { my $disabled_types_event_json = encode_json($disabled_types_event); if ($in_policy == 0) { - $agent_id = get_agent_id($dbh,$agent_name); - exist_check($agent_id,'agent',$agent_name); - - my $module_exists = get_agent_module_id($dbh, $module_name, $agent_id); - non_exist_check($module_exists, 'module name', $module_name); - - #~ print_log "[INFO] Adding module '$module_name' to agent '$agent_name'\n\n"; + if (defined $use_alias and $use_alias eq 'use_alias') { + @id_agents = get_agent_ids_from_alias($dbh,$agent_name); + + foreach my $id (@id_agents) { + exist_check($id->{'id_agente'},'agent',$agent_name); + + my $module_exists = get_agent_module_id($dbh, $module_name, $id->{'id_agente'}); + non_exist_check($module_exists, 'module name', $module_name); + } + } else { + $agent_id = get_agent_id($dbh,$agent_name); + exist_check($agent_id,'agent',$agent_name); + + my $module_exists = get_agent_module_id($dbh, $module_name, $agent_id); + non_exist_check($module_exists, 'module name', $module_name); + } } else { $policy_id = enterprise_hook('get_policy_id',[$dbh, safe_input($policy_name)]); @@ -1538,44 +1655,90 @@ sub cli_create_web_module($) { $module_name_def = $module_name; $module_type_def = $module_type; + # If the module is local and is not to policy, we add it to the conf file - if (defined($definition_file) && (-e $definition_file) && (-e $conf->{incomingdir}.'/conf/'.md5($agent_name).'.conf')){ - open (FILE, $definition_file); - my @file = <FILE>; - my $definition = join("", @file); - close (FILE); - - # If the parameter name or type and the definition file name or type - # dont match will be set the file definitions - open (FILE, $definition_file); - while (<FILE>) { - chomp; - my ($key, $val) = split / /; - if ($key eq 'module_name') { - $module_name_def = $val; - } - if ($key eq 'module_type') { - $module_type_def = $val; + if (defined $use_alias and $use_alias eq 'use_alias') { + foreach my $id (@id_agents) { + if (defined($definition_file) && (-e $definition_file) && (-e $conf->{incomingdir}.'/conf/'.md5($agent_name).'.conf')){ + open (FILE, $definition_file); + my @file = <FILE>; + my $definition = join("", @file); + close (FILE); + + # If the parameter name or type and the definition file name or type + # dont match will be set the file definitions + open (FILE, $definition_file); + while (<FILE>) { + chomp; + my ($key, $val) = split / /; + if ($key eq 'module_name') { + $module_name_def = $val; + } + if ($key eq 'module_type') { + $module_type_def = $val; + } + } + close (FILE); + + #open (FILE, $conf->{incomingdir}.'/conf/'.md5($agent_name).'.conf'); + #my @file = <FILE>; + #my $conf_file = join("", @file); + #close(FILE); + + #open FILE, "> ".$conf->{incomingdir}.'/conf/'.md5($agent_name).'.conf'; + #print FILE "$conf_file\n$definition"; + #close(FILE); + + enterprise_hook('pandora_update_md5_file', [$conf, $agent_name]); } } - close (FILE); - - #open (FILE, $conf->{incomingdir}.'/conf/'.md5($agent_name).'.conf'); - #my @file = <FILE>; - #my $conf_file = join("", @file); - #close(FILE); - - #open FILE, "> ".$conf->{incomingdir}.'/conf/'.md5($agent_name).'.conf'; - #print FILE "$conf_file\n$definition"; - #close(FILE); - - enterprise_hook('pandora_update_md5_file', [$conf, $agent_name]); + } else { + if (defined($definition_file) && (-e $definition_file) && (-e $conf->{incomingdir}.'/conf/'.md5($agent_name).'.conf')){ + open (FILE, $definition_file); + my @file = <FILE>; + my $definition = join("", @file); + close (FILE); + + # If the parameter name or type and the definition file name or type + # dont match will be set the file definitions + open (FILE, $definition_file); + while (<FILE>) { + chomp; + my ($key, $val) = split / /; + if ($key eq 'module_name') { + $module_name_def = $val; + } + if ($key eq 'module_type') { + $module_type_def = $val; + } + } + close (FILE); + + #open (FILE, $conf->{incomingdir}.'/conf/'.md5($agent_name).'.conf'); + #my @file = <FILE>; + #my $conf_file = join("", @file); + #close(FILE); + + #open FILE, "> ".$conf->{incomingdir}.'/conf/'.md5($agent_name).'.conf'; + #print FILE "$conf_file\n$definition"; + #close(FILE); + + enterprise_hook('pandora_update_md5_file', [$conf, $agent_name]); + } } - + if ($in_policy == 0) { - my $module_exists = get_agent_module_id($dbh, $module_name_def, $agent_id); - non_exist_check($module_exists, 'module name', $module_name_def); - print_log "[INFO] Adding module '$module_name' to agent '$agent_name'\n\n"; + if (defined $use_alias and $use_alias eq 'use_alias') { + foreach my $id (@id_agents) { + my $module_exists = get_agent_module_id($dbh, $module_name_def, $id->{'id_agente'}); + non_exist_check($module_exists, 'module name', $module_name_def); + print_log "[INFO] Adding module '$module_name' to agent '$id->{'nombre'}'\n\n"; + } + } else { + my $module_exists = get_agent_module_id($dbh, $module_name_def, $agent_id); + non_exist_check($module_exists, 'module name', $module_name_def); + print_log "[INFO] Adding module '$module_name' to agent '$agent_name'\n\n"; + } } else { my $policy_module_exist = enterprise_hook('get_policy_module_id',[$dbh, $policy_id, $module_name_def]); @@ -1615,7 +1778,10 @@ sub cli_create_web_module($) { if ($in_policy == 0) { $parameters{'nombre'} = safe_input($module_name); - $parameters{'id_agente'} = $agent_id; + + if (not defined $use_alias) { + $parameters{'id_agente'} = $agent_id; + } } else { $parameters{'name'} = safe_input($module_name); @@ -1672,14 +1838,21 @@ sub cli_create_web_module($) { if ($in_policy == 0) { - pandora_create_module_from_hash ($conf, \%parameters, $dbh); + if (defined $use_alias and $use_alias eq 'use_alias') { + foreach my $id (@id_agents) { + $parameters{'id_agente'} = $id->{'id_agente'}; + pandora_create_module_from_hash ($conf, \%parameters, $dbh); + } + } else { + pandora_create_module_from_hash ($conf, \%parameters, $dbh); + } } else { enterprise_hook('pandora_create_policy_module_from_hash', [$conf, \%parameters, $dbh]); } #Begin Insert module definition from file_definition in bd - if (defined($definition_file)){ + if (defined($definition_file)){ open(my $fh, '<', $definition_file) or die($!); my @lines = <$fh>; @@ -1766,21 +1939,50 @@ sub cli_module_group_synch() { ############################################################################## sub cli_create_network_module_from_component() { - my ($agent_name, $component_name) = @ARGV[2..3]; - - my $agent_id = get_agent_id($dbh,$agent_name); - exist_check($agent_id,'agent',$agent_name); - - my $nc_id = pandora_get_network_component_id($dbh, $component_name); - exist_check($nc_id,'network component',$component_name); - - my $module_exists = get_agent_module_id($dbh, $component_name, $agent_id); - non_exist_check($module_exists, 'module name', $component_name); - - # Get network component data - my $component = get_db_single_row ($dbh, 'SELECT * FROM tnetwork_component WHERE id_nc = ?', $nc_id); - - pandora_create_module_from_network_component ($conf, $component, $agent_id, $dbh); + my ($agent_name, $component_name, $use_alias) = @ARGV[2..4]; + + if (defined $use_alias and $use_alias eq 'use_alias') { + my @id_agents = get_agent_ids_from_alias($dbh,$agent_name); + my $agent_id; + my $module_exists; + my $component; + my $nc_id; + + foreach my $id (@id_agents) { + $agent_id = $id->{'id_agente'}; + exist_check($agent_id,'agent',$agent_name); + + $nc_id = pandora_get_network_component_id($dbh, $component_name); + exist_check($nc_id,'network component',$component_name); + + # Get network component data + $component = get_db_single_row ($dbh, 'SELECT * FROM tnetwork_component WHERE id_nc = ?', $nc_id); + + my $module_exists = get_agent_module_id($dbh, $component_name, $agent_id); + non_exist_check($module_exists, 'module name', $component_name); + + print_log "[INFO] Creating module from component '$component_name'\n\n"; + + pandora_create_module_from_network_component ($conf, $component, $agent_id, $dbh); + } + } else { + my $nc_id = pandora_get_network_component_id($dbh, $component_name); + exist_check($nc_id,'network component',$component_name); + + # Get network component data + my $component = get_db_single_row ($dbh, 'SELECT * FROM tnetwork_component WHERE id_nc = ?', $nc_id); + + my $agent_id = get_agent_id($dbh,$agent_name); + exist_check($agent_id,'agent',$agent_name); + + my $module_exists = get_agent_module_id($dbh, $component_name, $agent_id); + non_exist_check($module_exists, 'module name', $component_name); + + + print_log "[INFO] Creating module from component '$component_name'\n\n"; + + pandora_create_module_from_network_component ($conf, $component, $agent_id, $dbh); + } } ############################################################################## @@ -1831,7 +2033,7 @@ sub cli_create_network_module($) { $module_group, $min, $max, $post_process, $interval, $warning_min, $warning_max, $critical_min, $critical_max, $history_data, $ff_threshold, $warning_str, $critical_str, $enable_unknown_events, $each_ff, $ff_threshold_normal, $ff_threshold_warning, $ff_threshold_critical, $timeout, $retries, $critical_instructions, - $warning_instructions, $unknown_instructions, $warning_inverse, $critical_inverse); + $warning_instructions, $unknown_instructions, $warning_inverse, $critical_inverse, $use_alias); if ($in_policy == 0) { ($module_name, $module_type, $agent_name, $module_address, $module_port, $description, @@ -1839,7 +2041,7 @@ sub cli_create_network_module($) { $critical_max, $history_data, $ff_threshold, $warning_str, $critical_str, $enable_unknown_events, $each_ff, $ff_threshold_normal, $ff_threshold_warning, $ff_threshold_critical, $timeout, $retries,$critical_instructions, $warning_instructions, $unknown_instructions, - $warning_inverse, $critical_inverse) = @ARGV[2..32]; + $warning_inverse, $critical_inverse, $use_alias) = @ARGV[2..33]; } else { ($policy_name, $module_name, $module_type, $module_port, $description, @@ -1849,10 +2051,12 @@ sub cli_create_network_module($) { $ff_threshold_critical, $timeout, $retries, $critical_instructions, $warning_instructions, $unknown_instructions, $warning_inverse, $critical_inverse) = @ARGV[2..31]; } - + my $module_name_def; my $module_type_def; + my $agent_id; + my @id_agents; my $policy_id; my $disabled_types_event = {}; @@ -1865,13 +2069,26 @@ sub cli_create_network_module($) { my $disabled_types_event_json = encode_json($disabled_types_event); if ($in_policy == 0) { - $agent_id = get_agent_id($dbh,$agent_name); - exist_check($agent_id,'agent',$agent_name); - - my $module_exists = get_agent_module_id($dbh, $module_name, $agent_id); - non_exist_check($module_exists, 'module name', $module_name); - - print_log "[INFO] Adding module '$module_name' to agent '$agent_name'\n\n"; + if (defined $use_alias and $use_alias eq 'use_alias') { + @id_agents = get_agent_ids_from_alias($dbh,$agent_name); + + foreach my $id (@id_agents) { + exist_check($id->{'id_agente'},'agent',$agent_name); + + my $module_exists = get_agent_module_id($dbh, $module_name, $id->{'id_agente'}); + non_exist_check($module_exists, 'module name', $module_name); + + print_log "[INFO] Adding module '$module_name' to agent '$id->{'nombre'}'\n\n"; + } + } else { + $agent_id = get_agent_id($dbh,$agent_name); + exist_check($agent_id,'agent',$agent_name); + + my $module_exists = get_agent_module_id($dbh, $module_name, $agent_id); + non_exist_check($module_exists, 'module name', $module_name); + + print_log "[INFO] Adding module '$module_name' to agent '$agent_name'\n\n"; + } } else { $policy_id = enterprise_hook('get_policy_id',[$dbh, safe_input($policy_name)]); @@ -1921,7 +2138,11 @@ sub cli_create_network_module($) { if ($in_policy == 0) { $parameters{'nombre'} = safe_input($module_name); - $parameters{'id_agente'} = $agent_id; + + if (not defined $use_alias) { + $parameters{'id_agente'} = $agent_id; + } + $parameters{'ip_target'} = $module_address; } else { @@ -1966,7 +2187,14 @@ sub cli_create_network_module($) { $parameters{'warning_inverse'} = $warning_inverse unless !defined ($warning_inverse); if ($in_policy == 0) { - pandora_create_module_from_hash ($conf, \%parameters, $dbh); + if (defined $use_alias and $use_alias eq 'use_alias') { + foreach my $id (@id_agents) { + $parameters{'id_agente'} = $id->{'id_agente'}; + pandora_create_module_from_hash ($conf, \%parameters, $dbh); + } + } else { + pandora_create_module_from_hash ($conf, \%parameters, $dbh); + } } else { enterprise_hook('pandora_create_policy_module_from_hash', [$conf, \%parameters, $dbh]); @@ -1985,7 +2213,7 @@ sub cli_create_snmp_module($) { $warning_max, $critical_min, $critical_max, $history_data, $snmp3_priv_method, $snmp3_priv_pass, $snmp3_sec_level, $snmp3_auth_method, $snmp3_auth_user, $snmp3_auth_pass, $ff_threshold, $warning_str, $critical_str, $enable_unknown_events, $each_ff, $ff_threshold_normal, $ff_threshold_warning, $ff_threshold_critical, $timeout, $retries, - $critical_instructions, $warning_instructions, $unknown_instructions, $warning_inverse, $critical_inverse); + $critical_instructions, $warning_instructions, $unknown_instructions, $warning_inverse, $critical_inverse, $use_alias); if ($in_policy == 0) { ($module_name, $module_type, $agent_name, $module_address, $module_port, $version, $community, @@ -1993,7 +2221,7 @@ sub cli_create_snmp_module($) { $warning_max, $critical_min, $critical_max, $history_data, $snmp3_priv_method, $snmp3_priv_pass, $snmp3_sec_level, $snmp3_auth_method, $snmp3_auth_user, $snmp3_auth_pass, $ff_threshold, $warning_str, $critical_str, $enable_unknown_events, $each_ff, $ff_threshold_normal, $ff_threshold_warning, $ff_threshold_critical, $timeout, $retries, - $critical_instructions, $warning_instructions, $unknown_instructions, $warning_inverse, $critical_inverse) = @ARGV[2..41]; + $critical_instructions, $warning_instructions, $unknown_instructions, $warning_inverse, $critical_inverse, $use_alias) = @ARGV[2..42]; } else { ($policy_name, $module_name, $module_type, $module_port, $version, $community, @@ -2006,7 +2234,9 @@ sub cli_create_snmp_module($) { my $module_name_def; my $module_type_def; + my $agent_id; + my @id_agents; my $policy_id; my $disabled_types_event = {}; @@ -2019,13 +2249,26 @@ sub cli_create_snmp_module($) { my $disabled_types_event_json = encode_json($disabled_types_event); if ($in_policy == 0) { - $agent_id = get_agent_id($dbh,$agent_name); - exist_check($agent_id,'agent',$agent_name); - - my $module_exists = get_agent_module_id($dbh, $module_name, $agent_id); - non_exist_check($module_exists, 'module name', $module_name); - - print_log "[INFO] Adding module '$module_name' to agent '$agent_name'\n\n"; + if (defined $use_alias and $use_alias eq 'use_alias') { + @id_agents = get_agent_ids_from_alias($dbh,$agent_name); + + foreach my $id (@id_agents) { + exist_check($id->{'id_agente'},'agent',$agent_name); + + my $module_exists = get_agent_module_id($dbh, $module_name, $id->{'id_agente'}); + non_exist_check($module_exists, 'module name', $module_name); + + print_log "[INFO] Adding module '$module_name' to agent '$id->{'nombre'}'\n\n"; + } + } else { + $agent_id = get_agent_id($dbh,$agent_name); + exist_check($agent_id,'agent',$agent_name); + + my $module_exists = get_agent_module_id($dbh, $module_name, $agent_id); + non_exist_check($module_exists, 'module name', $module_name); + + print_log "[INFO] Adding module '$module_name' to agent '$agent_name'\n\n"; + } } else { $policy_id = enterprise_hook('get_policy_id',[$dbh, safe_input($policy_name)]); @@ -2064,7 +2307,11 @@ sub cli_create_snmp_module($) { if ($in_policy == 0) { $parameters{'nombre'} = safe_input($module_name); - $parameters{'id_agente'} = $agent_id; + + if (not defined $use_alias) { + $parameters{'id_agente'} = $agent_id; + } + $parameters{'ip_target'} = $module_address; } else { @@ -2125,7 +2372,14 @@ sub cli_create_snmp_module($) { $parameters{'warning_inverse'} = $warning_inverse unless !defined ($warning_inverse); if ($in_policy == 0) { - pandora_create_module_from_hash ($conf, \%parameters, $dbh); + if (defined $use_alias and $use_alias eq 'use_alias') { + foreach my $id (@id_agents) { + $parameters{'id_agente'} = $id->{'id_agente'}; + pandora_create_module_from_hash ($conf, \%parameters, $dbh); + } + } else { + pandora_create_module_from_hash ($conf, \%parameters, $dbh); + } } else { enterprise_hook('pandora_create_policy_module_from_hash', [$conf, \%parameters, $dbh]); @@ -2144,7 +2398,7 @@ sub cli_create_plugin_module($) { $interval, $warning_min, $warning_max, $critical_min, $critical_max, $history_data, $ff_threshold, $warning_str, $critical_str, $enable_unknown_events, $each_ff, $ff_threshold_normal, $ff_threshold_warning, $ff_threshold_critical, $timeout, - $critical_instructions, $warning_instructions, $unknown_instructions, $warning_inverse, $critical_inverse); + $critical_instructions, $warning_instructions, $unknown_instructions, $warning_inverse, $critical_inverse, $use_alias); if ($in_policy == 0) { ($module_name, $module_type, $agent_name, $module_address, $module_port, $plugin_name, @@ -2152,7 +2406,7 @@ sub cli_create_plugin_module($) { $interval, $warning_min, $warning_max, $critical_min, $critical_max, $history_data, $ff_threshold, $warning_str, $critical_str, $enable_unknown_events, $each_ff, $ff_threshold_normal, $ff_threshold_warning, $ff_threshold_critical, $timeout, - $critical_instructions, $warning_instructions, $unknown_instructions, $warning_inverse, $critical_inverse) = @ARGV[2..35]; + $critical_instructions, $warning_instructions, $unknown_instructions, $warning_inverse, $critical_inverse, $use_alias) = @ARGV[2..36]; } else { ($policy_name, $module_name, $module_type, $module_port, $plugin_name, @@ -2162,10 +2416,12 @@ sub cli_create_plugin_module($) { $each_ff, $ff_threshold_normal, $ff_threshold_warning, $ff_threshold_critical, $timeout, $critical_instructions, $warning_instructions, $unknown_instructions, $warning_inverse, $critical_inverse) = @ARGV[2..34]; } - + my $module_name_def; my $module_type_def; + my $agent_id; + my @id_agents; my $policy_id; my $disabled_types_event = {}; @@ -2178,13 +2434,26 @@ sub cli_create_plugin_module($) { my $disabled_types_event_json = encode_json($disabled_types_event); if ($in_policy == 0) { - $agent_id = get_agent_id($dbh,$agent_name); - exist_check($agent_id,'agent',$agent_name); - - my $module_exists = get_agent_module_id($dbh, $module_name, $agent_id); - non_exist_check($module_exists, 'module name', $module_name); - - print_log "[INFO] Adding module '$module_name' to agent '$agent_name'\n\n"; + if (defined $use_alias and $use_alias eq 'use_alias') { + @id_agents = get_agent_ids_from_alias($dbh,$agent_name); + + foreach my $id (@id_agents) { + exist_check($id->{'id_agente'},'agent',$agent_name); + + my $module_exists = get_agent_module_id($dbh, $module_name, $id->{'id_agente'}); + non_exist_check($module_exists, 'module name', $module_name); + + print_log "[INFO] Adding module '$module_name' to agent '$id->{'nombre'}'\n\n"; + } + } else { + $agent_id = get_agent_id($dbh,$agent_name); + exist_check($agent_id,'agent',$agent_name); + + my $module_exists = get_agent_module_id($dbh, $module_name, $agent_id); + non_exist_check($module_exists, 'module name', $module_name); + + print_log "[INFO] Adding module '$module_name' to agent '$agent_name'\n\n"; + } } else { $policy_id = enterprise_hook('get_policy_id',[$dbh, safe_input($policy_name)]); @@ -2222,7 +2491,11 @@ sub cli_create_plugin_module($) { if ($in_policy == 0) { $parameters{'nombre'} = safe_input($module_name); - $parameters{'id_agente'} = $agent_id; + + if (not defined $use_alias) { + $parameters{'id_agente'} = $agent_id; + } + $parameters{'ip_target'} = $module_address; } else { @@ -2299,7 +2572,14 @@ sub cli_create_plugin_module($) { $parameters{'warning_inverse'} = $warning_inverse unless !defined ($warning_inverse); if ($in_policy == 0) { - pandora_create_module_from_hash ($conf, \%parameters, $dbh); + if (defined $use_alias and $use_alias eq 'use_alias') { + foreach my $id (@id_agents) { + $parameters{'id_agente'} = $id->{'id_agente'}; + pandora_create_module_from_hash ($conf, \%parameters, $dbh); + } + } else { + pandora_create_module_from_hash ($conf, \%parameters, $dbh); + } } else { enterprise_hook('pandora_create_policy_module_from_hash', [$conf, \%parameters, $dbh]); @@ -2312,16 +2592,36 @@ sub cli_create_plugin_module($) { ############################################################################## sub cli_delete_module() { - my ($module_name,$agent_name) = @ARGV[2..3]; + my ($module_name,$agent_name, $use_alias) = @ARGV[2..4]; - print_log "[INFO] Deleting module '$module_name' from agent '$agent_name' \n\n"; - - my $id_agent = get_agent_id($dbh,$agent_name); - exist_check($id_agent,'agent',$agent_name); - my $id_module = get_agent_module_id($dbh,$module_name,$id_agent); - exist_check($id_module,'module',$module_name); - - pandora_delete_module($dbh,$id_module,$conf); + my @id_agents; + + if (defined $use_alias and $use_alias eq 'use_alias') { + @id_agents = get_agent_ids_from_alias($dbh,$agent_name); + my $id_agent; + + foreach my $id (@id_agents) { + print_log "[INFO] Deleting module '$module_name' from agent '$id->{'nombre'}' \n\n"; + + $id_agent = $id->{'id_agente'}; + exist_check($id_agent,'agent',$agent_name); + my $id_module = get_agent_module_id($dbh,$module_name,$id_agent); + if ($id_module == -1) { + next; + } + + pandora_delete_module($dbh,$id_module,$conf); + } + } else { + print_log "[INFO] Deleting module '$module_name' from agent '$agent_name' \n\n"; + + my $id_agent = get_agent_id($dbh,$agent_name); + exist_check($id_agent,'agent',$agent_name); + my $id_module = get_agent_module_id($dbh,$module_name,$id_agent); + exist_check($id_module,'module',$module_name); + + pandora_delete_module($dbh,$id_module,$conf); + } } ############################################################################## @@ -2370,18 +2670,41 @@ sub cli_delete_not_policy_modules() { ############################################################################## sub cli_create_template_module() { - my ($template_name,$module_name,$agent_name) = @ARGV[2..4]; + my ($template_name,$module_name,$agent_name, $use_alias) = @ARGV[2..5]; - print_log "[INFO] Adding template '$template_name' to module '$module_name' from agent '$agent_name' \n\n"; - - my $id_agent = get_agent_id($dbh,$agent_name); - exist_check($id_agent,'agent',$agent_name); - my $module_id = get_agent_module_id($dbh,$module_name,$id_agent); - exist_check($module_id,'module',$module_name); - my $template_id = get_template_id($dbh,$template_name); - exist_check($template_id,'template',$template_name); - - pandora_create_template_module ($conf, $dbh, $module_id, $template_id); + my @id_agents; + + if (defined $use_alias and $use_alias eq 'use_alias') { + @id_agents = get_agent_ids_from_alias($dbh,$agent_name); + + foreach my $id (@id_agents) { + print_log "[INFO] Adding template '$template_name' to module '$module_name' from agent '$agent_name' \n\n"; + + my $id_agent = $id->{'id_agente'}; + exist_check($id_agent,'agent',$agent_name); + my $module_id = get_agent_module_id($dbh,$module_name,$id_agent); + if ($module_id == -1) { + print_log "[ERROR] Error: The module '$module_name' does not exist. \n\n"; + next; + } + + my $template_id = get_template_id($dbh,$template_name); + exist_check($template_id,'template',$template_name); + + pandora_create_template_module ($conf, $dbh, $module_id, $template_id); + } + } else { + print_log "[INFO] Adding template '$template_name' to module '$module_name' from agent '$agent_name' \n\n"; + + my $id_agent = get_agent_id($dbh,$agent_name); + exist_check($id_agent,'agent',$agent_name); + my $module_id = get_agent_module_id($dbh,$module_name,$id_agent); + exist_check($module_id,'module',$module_name); + my $template_id = get_template_id($dbh,$template_name); + exist_check($template_id,'template',$template_name); + + pandora_create_template_module ($conf, $dbh, $module_id, $template_id); + } } ############################################################################## @@ -2390,21 +2713,46 @@ sub cli_create_template_module() { ############################################################################## sub cli_delete_template_module() { - my ($template_name,$module_name,$agent_name) = @ARGV[2..4]; + my ($template_name,$module_name,$agent_name, $use_alias) = @ARGV[2..5]; - print_log "[INFO] Delete template '$template_name' from module '$module_name' from agent '$agent_name' \n\n"; + if (defined $use_alias and $use_alias eq 'use_alias') { + my @id_agents = get_agent_ids_from_alias($dbh,$agent_name); - my $id_agent = get_agent_id($dbh,$agent_name); - exist_check($id_agent,'agent',$agent_name); - my $module_id = get_agent_module_id($dbh,$module_name,$id_agent); - exist_check($module_id,'module',$module_name); - my $template_id = get_template_id($dbh,$template_name); - exist_check($template_id,'template',$template_name); + my $id_agent; - my $template_module_id = get_template_module_id($dbh, $module_id, $template_id); - exist_check($template_module_id,"template '$template_name' on module",$module_name); + foreach my $id (@id_agents) { + print_log "[INFO] Delete template '$template_name' from module '$module_name' from agent '$agent_name' \n\n"; + + $id_agent = $id->{'id_agente'}; + exist_check($id_agent,'agent',$agent_name); + my $module_id = get_agent_module_id($dbh,$module_name,$id_agent); + if ($module_id eq -1) { + print_log "[ERROR] Error: The module '$module_name' does not exist. \n\n"; + next; + } + my $template_id = get_template_id($dbh,$template_name); + exist_check($template_id,'template',$template_name); + + my $template_module_id = get_template_module_id($dbh, $module_id, $template_id); + exist_check($template_module_id,"template '$template_name' on module",$module_name); - pandora_delete_template_module ($dbh, $template_module_id); + pandora_delete_template_module ($dbh, $template_module_id); + } + } else { + print_log "[INFO] Delete template '$template_name' from module '$module_name' from agent '$agent_name' \n\n"; + + my $id_agent = get_agent_id($dbh,$agent_name); + exist_check($id_agent,'agent',$agent_name); + my $module_id = get_agent_module_id($dbh,$module_name,$id_agent); + exist_check($module_id,'module',$module_name); + my $template_id = get_template_id($dbh,$template_name); + exist_check($template_id,'template',$template_name); + + my $template_module_id = get_template_module_id($dbh, $module_id, $template_id); + exist_check($template_module_id,"template '$template_name' on module",$module_name); + + pandora_delete_template_module ($dbh, $template_module_id); + } } ############################################################################## @@ -2413,32 +2761,68 @@ sub cli_delete_template_module() { ############################################################################## sub cli_create_template_action() { - my ($action_name,$template_name,$module_name,$agent_name,$fires_min,$fires_max) = @ARGV[2..7]; + my ($action_name,$template_name,$module_name,$agent_name,$fires_min,$fires_max, $use_alias) = @ARGV[2..8]; - print_log "[INFO] Adding action '$action_name' to template '$template_name' in module '$module_name' from agent '$agent_name' with $fires_min min. fires and $fires_max max. fires\n\n"; - - my $id_agent = get_agent_id($dbh,$agent_name); - exist_check($id_agent,'agent',$agent_name); - my $module_id = get_agent_module_id($dbh,$module_name,$id_agent); - exist_check($module_id,'module',$module_name); - my $template_id = get_template_id($dbh,$template_name); - exist_check($template_id,'template',$template_name); - my $template_module_id = get_template_module_id($dbh,$module_id,$template_id); - exist_check($template_module_id,'template module',$template_name); - my $action_id = get_action_id($dbh,safe_input($action_name)); - exist_check($action_id,'action',$action_name); - - $fires_min = 0 unless defined ($fires_min); - $fires_max = 0 unless defined ($fires_max); - - my %parameters; - - $parameters{'id_alert_template_module'} = $template_module_id; - $parameters{'id_alert_action'} = $action_id; - $parameters{'fires_min'} = $fires_min; - $parameters{'fires_max'} = $fires_max; - - pandora_create_template_module_action ($conf, \%parameters, $dbh); + my @id_agents; + + if (defined $use_alias and $use_alias eq 'use_alias') { + @id_agents = get_agent_ids_from_alias($dbh,$agent_name); + + foreach my $id (@id_agents) { + print_log "[INFO] Adding action '$action_name' to template '$template_name' in module '$module_name' from agent '$agent_name' with $fires_min min. fires and $fires_max max. fires\n\n"; + + my $id_agent = $id->{'id_agente'}; + exist_check($id_agent,'agent',$agent_name); + my $module_id = get_agent_module_id($dbh,$module_name,$id_agent); + if ($module_id eq -1) { + print_log "[ERROR] Error: The module '$module_name' does not exist. \n\n"; + next; + } + my $template_id = get_template_id($dbh,$template_name); + exist_check($template_id,'template',$template_name); + my $template_module_id = get_template_module_id($dbh,$module_id,$template_id); + exist_check($template_module_id,'template module',$template_name); + my $action_id = get_action_id($dbh,safe_input($action_name)); + exist_check($action_id,'action',$action_name); + + $fires_min = 0 unless defined ($fires_min); + $fires_max = 0 unless defined ($fires_max); + + my %parameters; + + $parameters{'id_alert_template_module'} = $template_module_id; + $parameters{'id_alert_action'} = $action_id; + $parameters{'fires_min'} = $fires_min; + $parameters{'fires_max'} = $fires_max; + + pandora_create_template_module_action ($conf, \%parameters, $dbh); + } + } else { + print_log "[INFO] Adding action '$action_name' to template '$template_name' in module '$module_name' from agent '$agent_name' with $fires_min min. fires and $fires_max max. fires\n\n"; + + my $id_agent = get_agent_id($dbh,$agent_name); + exist_check($id_agent,'agent',$agent_name); + my $module_id = get_agent_module_id($dbh,$module_name,$id_agent); + exist_check($module_id,'module',$module_name); + my $template_id = get_template_id($dbh,$template_name); + exist_check($template_id,'template',$template_name); + my $template_module_id = get_template_module_id($dbh,$module_id,$template_id); + exist_check($template_module_id,'template module',$template_name); + my $action_id = get_action_id($dbh,safe_input($action_name)); + exist_check($action_id,'action',$action_name); + + $fires_min = 0 unless defined ($fires_min); + $fires_max = 0 unless defined ($fires_max); + + my %parameters; + + $parameters{'id_alert_template_module'} = $template_module_id; + $parameters{'id_alert_action'} = $action_id; + $parameters{'fires_min'} = $fires_min; + $parameters{'fires_max'} = $fires_max; + + pandora_create_template_module_action ($conf, \%parameters, $dbh); + } } ############################################################################## @@ -2447,22 +2831,46 @@ sub cli_create_template_action() { ############################################################################## sub cli_delete_template_action() { - my ($action_name,$template_name,$module_name,$agent_name) = @ARGV[2..5]; + my ($action_name,$template_name,$module_name,$agent_name, $use_alias) = @ARGV[2..6]; - print_log "[INFO] Deleting action '$action_name' from template '$template_name' in module '$module_name' from agent '$agent_name')\n\n"; + if (defined $use_alias and $use_alias eq 'use_alias') { + my @id_agents = get_agent_ids_from_alias($dbh,$agent_name); - my $id_agent = get_agent_id($dbh,$agent_name); - exist_check($id_agent,'agent',$agent_name); - my $module_id = get_agent_module_id($dbh,$module_name,$id_agent); - exist_check($module_id,'module',$module_name); - my $template_id = get_template_id($dbh,$template_name); - exist_check($template_id,'template',$template_name); - my $template_module_id = get_template_module_id($dbh,$module_id,$template_id); - exist_check($template_module_id,'template module',$template_name); - my $action_id = get_action_id($dbh,safe_input($action_name)); - exist_check($action_id,'action',$action_name); + foreach my $id (@id_agents) { + print_log "[INFO] Deleting action '$action_name' from template '$template_name' in module '$module_name' from agent '$agent_name')\n\n"; - pandora_delete_template_module_action ($dbh, $template_module_id, $action_id); + my $id_agent = $id->{'id_agente'}; + exist_check($id_agent,'agent',$agent_name); + my $module_id = get_agent_module_id($dbh,$module_name,$id_agent); + if ($module_id eq -1) { + print_log "[ERROR] Error: The module '$module_name' does not exist. \n\n"; + next; + } + my $template_id = get_template_id($dbh,$template_name); + exist_check($template_id,'template',$template_name); + my $template_module_id = get_template_module_id($dbh,$module_id,$template_id); + exist_check($template_module_id,'template module',$template_name); + my $action_id = get_action_id($dbh,safe_input($action_name)); + exist_check($action_id,'action',$action_name); + + pandora_delete_template_module_action ($dbh, $template_module_id, $action_id); + } + } else { + print_log "[INFO] Deleting action '$action_name' from template '$template_name' in module '$module_name' from agent '$agent_name')\n\n"; + + my $id_agent = get_agent_id($dbh,$agent_name); + exist_check($id_agent,'agent',$agent_name); + my $module_id = get_agent_module_id($dbh,$module_name,$id_agent); + exist_check($module_id,'module',$module_name); + my $template_id = get_template_id($dbh,$template_name); + exist_check($template_id,'template',$template_name); + my $template_module_id = get_template_module_id($dbh,$module_id,$template_id); + exist_check($template_module_id,'template module',$template_name); + my $action_id = get_action_id($dbh,safe_input($action_name)); + exist_check($action_id,'action',$action_name); + + pandora_delete_template_module_action ($dbh, $template_module_id, $action_id); + } } ############################################################################## @@ -2471,9 +2879,11 @@ sub cli_delete_template_action() { ############################################################################## sub cli_data_module() { - my ($server_name,$agent_name,$module_name,$module_type,$module_new_data,$datetime) = @ARGV[2..7]; + my ($server_name,$agent_name,$module_name,$module_type,$module_new_data,$datetime,$use_alias) = @ARGV[2..8]; my $utimestamp; + my @id_agents; + if(defined($datetime)) { if ($datetime !~ /([0-9]{2,4})\-([0-1][0-9])\-([0-3][0-9]) +([0-2][0-9]):([0-5][0-9])/) { print_log "[ERROR] Invalid datetime $datetime. (Correct format: YYYY-MM-DD HH:mm)\n"; @@ -2490,29 +2900,58 @@ sub cli_data_module() { # The get_module_id has wrong name. Change in future my $module_type_id = get_module_id($dbh,$module_type); exist_check($module_type_id,'module type',$module_type); - - my $id_agent = get_agent_id($dbh,$agent_name); - exist_check($id_agent,'agent',$agent_name); - - my $id_module = get_agent_module_id($dbh, $module_name, $id_agent); - exist_check($id_module, 'module name', $module_name); - + # Server_type 0 is dataserver my $server_id = get_server_id($dbh,$server_name,0); exist_check($server_id,'data server',$server_name); - - my $module = get_db_single_row ($dbh, 'SELECT * FROM tagente_modulo WHERE id_agente_modulo = ? AND id_tipo_modulo = ?', $id_module, $id_agent, $module_type_id); - - if(not defined($module->{'module_interval'})) { - print_log "[ERROR] No module found with this type. \n\n"; - exit; + + if (defined $use_alias and $use_alias eq 'use_alias') { + @id_agents = get_agent_ids_from_alias($dbh,$agent_name); + + my $id_agent; + + foreach my $id (@id_agents) { + $id_agent = $id->{'id_agente'}; + exist_check($id_agent,'agent',$agent_name); + + my $id_module = get_agent_module_id($dbh, $module_name, $id_agent); + if ($id_module == -1) { + next; + } + + my $module = get_db_single_row ($dbh, 'SELECT * FROM tagente_modulo WHERE id_agente_modulo = ? AND id_tipo_modulo = ?', $id_module, $module_type_id); + + if(not defined($module->{'module_interval'})) { + print_log "[ERROR] No module found with this type. \n\n"; + exit; + } + + my %data = ('data' => $module_new_data); + + pandora_process_module ($conf, \%data, '', $module, $module_type, '', $utimestamp, $server_id, $dbh); + + print_log "[INFO] Inserting data to module '$module_name'\n\n"; + } + } else { + my $id_agent = get_agent_id($dbh,$agent_name); + exist_check($id_agent,'agent',$agent_name); + + my $id_module = get_agent_module_id($dbh, $module_name, $id_agent); + exist_check($id_module, 'module name', $module_name); + + my $module = get_db_single_row ($dbh, 'SELECT * FROM tagente_modulo WHERE id_agente_modulo = ? AND id_tipo_modulo = ?', $id_module, $module_type_id); + + if(not defined($module->{'module_interval'})) { + print_log "[ERROR] No module found with this type. \n\n"; + exit; + } + + my %data = ('data' => $module_new_data); + + pandora_process_module ($conf, \%data, '', $module, $module_type, '', $utimestamp, $server_id, $dbh); + + print_log "[INFO] Inserting data to module '$module_name'\n\n"; } - - my %data = ('data' => $module_new_data); - - pandora_process_module ($conf, \%data, '', $module, $module_type, '', $utimestamp, $server_id, $dbh); - - print_log "[INFO] Inserting data to module '$module_name'\n\n"; } ############################################################################## @@ -2578,10 +3017,20 @@ sub cli_user_update() { ############################################################################## sub cli_agent_update() { - my ($agent_name,$field,$new_value) = @ARGV[2..4]; - - my $id_agent = get_agent_id($dbh,$agent_name); - exist_check($id_agent,'agent',$agent_name); + my ($agent_name,$field,$new_value,$use_alias) = @ARGV[2..5]; + + my @id_agents; + my $id_agent; + + if (defined $use_alias and $use_alias eq 'use_alias') { + @id_agents = get_agent_ids_from_alias($dbh,$agent_name); + foreach my $id (@id_agents) { + exist_check($id->{'id_agente'},'agent',$agent_name); + } + } else { + $id_agent = get_agent_id($dbh,$agent_name); + exist_check($id_agent,'agent',$agent_name); + } # agent_name, address, description, group_name, interval, os_name, disabled, parent_name, cascade_protection, icon_path, update_gis_data, custom_id @@ -2629,7 +3078,13 @@ sub cli_agent_update() { } # Add the address to the agent - add_new_address_agent ($dbh, $address_id, $id_agent); + if (defined $use_alias and $use_alias eq 'use_alias') { + foreach my $id (@id_agents) { + add_new_address_agent ($dbh, $address_id, $id->{'id_agente'}); + } + } else { + add_new_address_agent ($dbh, $address_id, $id_agent); + } $field = 'direccion'; } @@ -2637,14 +3092,24 @@ sub cli_agent_update() { print_log "[ERROR] Field '$field' doesnt exist\n\n"; exit; } - - print_log "[INFO] Updating field '$field' in agent '$agent_name'\n\n"; + + if (defined $use_alias and $use_alias eq 'use_alias') { + print_log "[INFO] Updating field '$field' in agents with alias '$agent_name'\n\n"; + } else { + print_log "[INFO] Updating field '$field' in agent '$agent_name'\n\n"; + } my $update; $update->{$field} = $new_value; - pandora_update_table_from_hash ($conf, $update, 'id_agente', safe_input($id_agent), 'tagente', $dbh); + if (defined $use_alias and $use_alias eq 'use_alias') { + foreach my $id (@id_agents) { + pandora_update_table_from_hash ($conf, $update, 'id_agente', safe_input($id->{'id_agente'}), 'tagente', $dbh); + } + } else { + pandora_update_table_from_hash ($conf, $update, 'id_agente', safe_input($id_agent), 'tagente', $dbh); + } } ############################################################################## @@ -2901,150 +3366,306 @@ sub pandora_check_plugin_module_fields($) { ############################################################################## sub cli_module_update() { - my ($module_name,$agent_name,$field,$new_value) = @ARGV[2..5]; - - my $id_agent = get_agent_id($dbh,$agent_name); - exist_check($id_agent,'agent',$agent_name); - my $id_agent_module = get_agent_module_id ($dbh, $module_name, $id_agent); - exist_check($id_agent_module,'agent module',$module_name); - - # Check and adjust parameters in common values - - if($field eq 'min' || $field eq 'max' || $field eq 'post_process' || $field eq 'history_data') { - # Fields admited, no changes - } - elsif($field eq 'interval') { - $field = 'module_interval'; - } - elsif($field eq 'warning_min') { - $field = 'min_warning'; - } - elsif($field eq 'warning_max') { - $field = 'max_warning'; - } - elsif($field eq 'critical_min') { - $field = 'min_critical'; - } - elsif($field eq 'critical_max') { - $field = 'max_critical'; - } - elsif($field eq 'warning_str') { - $field = 'str_warning'; - $new_value = safe_input($new_value); - } - elsif($field eq 'critical_str') { - $field = 'str_critical'; - $new_value = safe_input($new_value); - } - elsif($field eq 'agent_name') { - my $id_agent_change = get_agent_id($dbh,$new_value); - exist_check($id_agent_change,'agent',$new_value); - my $id_agent_module_exist = get_agent_module_id ($dbh, $module_name, $id_agent_change); - if($id_agent_module_exist != -1) { - print_log "[ERROR] A module called '$module_name' already exist in the agent '$new_value'\n\n"; - exit; - } - $field = 'id_agente'; - $new_value = $id_agent_change; - } - elsif ($field eq 'module_name') { - my $id_agent_module_change = get_agent_module_id ($dbh, $new_value, $id_agent); - if ($id_agent_module_change != -1) { - print_log "[ERROR] A module called '$new_value' already exist in the agent '$agent_name'\n\n"; - exit; - } - $field = 'nombre'; - $new_value = safe_input($new_value); - } - elsif ($field eq 'description') { - $field = 'descripcion'; - $new_value = safe_input($new_value); - } - elsif ($field eq 'module_group') { - my $module_group_id = get_module_group_id($dbh,$new_value); - - if ($module_group_id == -1) { - print_log "[ERROR] Module group '$new_value' doesnt exist\n\n"; - exit; - } - $field = 'id_module_group'; - $new_value = $module_group_id; - } - elsif ($field eq 'enable_unknown_events') { - my $disabled_types_event = {}; - if ($new_value) { - $disabled_types_event->{'going_unknown'} = 0; - } - else { - $disabled_types_event->{'going_unknown'} = 1; - } - $field = 'disabled_types_event'; - $new_value = encode_json($disabled_types_event); - } - elsif ($field eq 'ff_threshold') { - $field = 'min_ff_event'; - } - elsif ($field eq 'each_ff') { - $field = 'each_ff'; - } - elsif ($field eq 'ff_threshold_normal') { - $field = 'min_ff_event_normal'; - } - elsif ($field eq 'ff_threshold_warning') { - $field = 'min_ff_event_warning'; - } - elsif ($field eq 'ff_threshold_critical') { - $field = 'min_ff_event_critical'; - } - elsif ($field eq 'critical_instructions') { - $field = 'critical_instructions'; - } - elsif ($field eq 'warning_instructions') { - $field = 'warning_instructions'; - } - elsif ($field eq 'unknown_instructions') { - $field = 'unknown_instructions'; - } - else { - # If is not a common value, check type and call type update funtion - my $type = pandora_get_module_type($dbh,$id_agent_module); - - my %field_value; - $field_value{'field'} = $field; - $field_value{'new_value'} = $new_value; - - if($type eq 'data') { - pandora_check_data_module_fields(\%field_value); - } - elsif($type eq 'network') { - pandora_check_network_module_fields(\%field_value); - } - elsif($type eq 'snmp') { - pandora_check_snmp_module_fields(\%field_value); - } - elsif($type eq 'plugin') { - pandora_check_plugin_module_fields(\%field_value); - } - else { - print_log "[ERROR] The field '$field' is not available for this type of module\n\n"; - } - - $field = $field_value{'field'}; - $new_value = $field_value{'new_value'}; - } - - print_log "[INFO] Updating field '$field' in module '$module_name' of agent '$agent_name' with new value '$new_value'\n\n"; - - my $update; - - $update->{$field} = $new_value; + my ($module_name,$agent_name,$field,$new_value, $use_alias) = @ARGV[2..6]; - my $policy_id = enterprise_hook('get_id_policy_module_agent_module',[$dbh, safe_input($id_agent_module)]); - if ( $policy_id > 0) { - $update->{policy_linked} = 0; + if (defined $use_alias and $use_alias eq 'use_alias') { + my @id_agents = get_agent_ids_from_alias($dbh,$agent_name); + + my $save_initial_field = $field; + my $save_new_value = $new_value; + + foreach my $id (@id_agents) { + $field = $save_initial_field; + $new_value = $save_new_value; + my $id_agent = $id->{'id_agente'}; + exist_check($id_agent,'agent',$agent_name); + my $id_agent_module = get_agent_module_id ($dbh, $module_name, $id_agent); + if ($id_agent_module == -1) { + next; + } + + # Check and adjust parameters in common values + + if($field eq 'min' || $field eq 'max' || $field eq 'post_process' || $field eq 'history_data') { + # Fields admited, no changes + } + elsif($field eq 'interval') { + $field = 'module_interval'; + } + elsif($field eq 'warning_min') { + $field = 'min_warning'; + } + elsif($field eq 'warning_max') { + $field = 'max_warning'; + } + elsif($field eq 'critical_min') { + $field = 'min_critical'; + } + elsif($field eq 'critical_max') { + $field = 'max_critical'; + } + elsif($field eq 'warning_str') { + $field = 'str_warning'; + $new_value = safe_input($new_value); + } + elsif($field eq 'critical_str') { + $field = 'str_critical'; + $new_value = safe_input($new_value); + } + elsif($field eq 'agent_name') { + my $id_agent_change = get_agent_id($dbh,$new_value); + exist_check($id_agent_change,'agent',$new_value); + my $id_agent_module_exist = get_agent_module_id ($dbh, $module_name, $id_agent_change); + if($id_agent_module_exist != -1) { + print_log "[ERROR] A module called '$module_name' already exist in the agent '$new_value'\n\n"; + exit; + } + $field = 'id_agente'; + $new_value = $id_agent_change; + } + elsif ($field eq 'module_name') { + my $id_agent_module_change = get_agent_module_id ($dbh, $new_value, $id_agent); + if ($id_agent_module_change != -1) { + print_log "[ERROR] A module called '$new_value' already exist in the agent '$agent_name'\n\n"; + exit; + } + $field = 'nombre'; + $new_value = safe_input($new_value); + } + elsif ($field eq 'description') { + $field = 'descripcion'; + $new_value = safe_input($new_value); + } + elsif ($field eq 'module_group') { + my $module_group_id = get_module_group_id($dbh,$new_value); + + if ($module_group_id == -1) { + print_log "[ERROR] Module group '$new_value' doesnt exist\n\n"; + exit; + } + $field = 'id_module_group'; + $new_value = $module_group_id; + } + elsif ($field eq 'enable_unknown_events') { + my $disabled_types_event = {}; + if ($new_value) { + $disabled_types_event->{'going_unknown'} = 0; + } + else { + $disabled_types_event->{'going_unknown'} = 1; + } + $field = 'disabled_types_event'; + $new_value = encode_json($disabled_types_event); + } + elsif ($field eq 'ff_threshold') { + $field = 'min_ff_event'; + } + elsif ($field eq 'each_ff') { + $field = 'each_ff'; + } + elsif ($field eq 'ff_threshold_normal') { + $field = 'min_ff_event_normal'; + } + elsif ($field eq 'ff_threshold_warning') { + $field = 'min_ff_event_warning'; + } + elsif ($field eq 'ff_threshold_critical') { + $field = 'min_ff_event_critical'; + } + elsif ($field eq 'critical_instructions') { + $field = 'critical_instructions'; + } + elsif ($field eq 'warning_instructions') { + $field = 'warning_instructions'; + } + elsif ($field eq 'unknown_instructions') { + $field = 'unknown_instructions'; + } + else { + # If is not a common value, check type and call type update funtion + my $type = pandora_get_module_type($dbh,$id_agent_module); + print("TYPE EN ELSE".$type); + my %field_value; + $field_value{'field'} = $field; + $field_value{'new_value'} = $new_value; + + if($type eq 'data') { + pandora_check_data_module_fields(\%field_value); + } + elsif($type eq 'network') { + pandora_check_network_module_fields(\%field_value); + } + elsif($type eq 'snmp') { + pandora_check_snmp_module_fields(\%field_value); + } + elsif($type eq 'plugin') { + pandora_check_plugin_module_fields(\%field_value); + } + else { + print_log "[ERROR] The field '$field' is not available for this type of module\n\n"; + } + + $field = $field_value{'field'}; + $new_value = $field_value{'new_value'}; + } + + print_log "[INFO] Updating field '$field' in module '$module_name' of agent '$agent_name' with new value '$new_value'\n\n"; + + my $update; + + $update->{$field} = $new_value; + + my $policy_id = enterprise_hook('get_id_policy_module_agent_module',[$dbh, safe_input($id_agent_module)]); + if ( $policy_id > 0) { + $update->{policy_linked} = 0; + } + + pandora_update_module_from_hash ($conf, $update, 'id_agente_modulo', $id_agent_module, $dbh); + } + } else { + my $id_agent = get_agent_id($dbh,$agent_name); + exist_check($id_agent,'agent',$agent_name); + my $id_agent_module = get_agent_module_id ($dbh, $module_name, $id_agent); + exist_check($id_agent_module,'agent module',$module_name); + + # Check and adjust parameters in common values + + if($field eq 'min' || $field eq 'max' || $field eq 'post_process' || $field eq 'history_data') { + # Fields admited, no changes + } + elsif($field eq 'interval') { + $field = 'module_interval'; + } + elsif($field eq 'warning_min') { + $field = 'min_warning'; + } + elsif($field eq 'warning_max') { + $field = 'max_warning'; + } + elsif($field eq 'critical_min') { + $field = 'min_critical'; + } + elsif($field eq 'critical_max') { + $field = 'max_critical'; + } + elsif($field eq 'warning_str') { + $field = 'str_warning'; + $new_value = safe_input($new_value); + } + elsif($field eq 'critical_str') { + $field = 'str_critical'; + $new_value = safe_input($new_value); + } + elsif($field eq 'agent_name') { + my $id_agent_change = get_agent_id($dbh,$new_value); + exist_check($id_agent_change,'agent',$new_value); + my $id_agent_module_exist = get_agent_module_id ($dbh, $module_name, $id_agent_change); + if($id_agent_module_exist != -1) { + print_log "[ERROR] A module called '$module_name' already exist in the agent '$new_value'\n\n"; + exit; + } + $field = 'id_agente'; + $new_value = $id_agent_change; + } + elsif ($field eq 'module_name') { + my $id_agent_module_change = get_agent_module_id ($dbh, $new_value, $id_agent); + if ($id_agent_module_change != -1) { + print_log "[ERROR] A module called '$new_value' already exist in the agent '$agent_name'\n\n"; + exit; + } + $field = 'nombre'; + $new_value = safe_input($new_value); + } + elsif ($field eq 'description') { + $field = 'descripcion'; + $new_value = safe_input($new_value); + } + elsif ($field eq 'module_group') { + my $module_group_id = get_module_group_id($dbh,$new_value); + + if ($module_group_id == -1) { + print_log "[ERROR] Module group '$new_value' doesnt exist\n\n"; + exit; + } + $field = 'id_module_group'; + $new_value = $module_group_id; + } + elsif ($field eq 'enable_unknown_events') { + my $disabled_types_event = {}; + if ($new_value) { + $disabled_types_event->{'going_unknown'} = 0; + } + else { + $disabled_types_event->{'going_unknown'} = 1; + } + $field = 'disabled_types_event'; + $new_value = encode_json($disabled_types_event); + } + elsif ($field eq 'ff_threshold') { + $field = 'min_ff_event'; + } + elsif ($field eq 'each_ff') { + $field = 'each_ff'; + } + elsif ($field eq 'ff_threshold_normal') { + $field = 'min_ff_event_normal'; + } + elsif ($field eq 'ff_threshold_warning') { + $field = 'min_ff_event_warning'; + } + elsif ($field eq 'ff_threshold_critical') { + $field = 'min_ff_event_critical'; + } + elsif ($field eq 'critical_instructions') { + $field = 'critical_instructions'; + } + elsif ($field eq 'warning_instructions') { + $field = 'warning_instructions'; + } + elsif ($field eq 'unknown_instructions') { + $field = 'unknown_instructions'; + } + else { + # If is not a common value, check type and call type update funtion + my $type = pandora_get_module_type($dbh,$id_agent_module); + + my %field_value; + $field_value{'field'} = $field; + $field_value{'new_value'} = $new_value; + + if($type eq 'data') { + pandora_check_data_module_fields(\%field_value); + } + elsif($type eq 'network') { + pandora_check_network_module_fields(\%field_value); + } + elsif($type eq 'snmp') { + pandora_check_snmp_module_fields(\%field_value); + } + elsif($type eq 'plugin') { + pandora_check_plugin_module_fields(\%field_value); + } + else { + print_log "[ERROR] The field '$field' is not available for this type of module\n\n"; + } + + $field = $field_value{'field'}; + $new_value = $field_value{'new_value'}; + } + + print_log "[INFO] Updating field '$field' in module '$module_name' of agent '$agent_name' with new value '$new_value'\n\n"; + + my $update; + + $update->{$field} = $new_value; + + my $policy_id = enterprise_hook('get_id_policy_module_agent_module',[$dbh, safe_input($id_agent_module)]); + if ( $policy_id > 0) { + $update->{policy_linked} = 0; + } + + pandora_update_module_from_hash ($conf, $update, 'id_agente_modulo', $id_agent_module, $dbh); } - - pandora_update_module_from_hash ($conf, $update, 'id_agente_modulo', $id_agent_module, $dbh); } ############################################################################## @@ -3401,7 +4022,7 @@ sub cli_delete_profile() { ############################################################################## sub cli_create_event() { - my ($event,$event_type,$group_name,$agent_name,$module_name,$event_status,$severity,$template_name, $user_name, $comment, $source, $id_extra, $tags, $custom_data,$force_create_agent,$c_instructions,$w_instructions,$u_instructions) = @ARGV[2..19]; + my ($event,$event_type,$group_name,$agent_name,$module_name,$event_status,$severity,$template_name, $user_name, $comment, $source, $id_extra, $tags, $custom_data,$force_create_agent,$c_instructions,$w_instructions,$u_instructions, $use_alias) = @ARGV[2..20]; $event_status = 0 unless defined($event_status); $severity = 0 unless defined($severity); @@ -3427,58 +4048,108 @@ sub cli_create_event() { } my $id_agent; - - if (! $agent_name) { - $id_agent = 0; - } - else { - $id_agent = get_agent_id($dbh,$agent_name); - # exist_check($id_agent,'agent',$agent_name); - if($id_agent == -1){ - if($force_create_agent == 1){ - pandora_create_agent ($conf, '', $agent_name, '', '', '', '', 'Created by cli_create_event', '', $dbh); - print_log "[INFO] Adding agent '$agent_name' \n\n"; - $id_agent = get_agent_id($dbh,$agent_name); + + if (defined $use_alias and $use_alias eq 'use_alias') { + + my @id_agents = get_agent_ids_from_alias($dbh,$agent_name); + + foreach my $id (@id_agents) { + if (! $agent_name) { + $id_agent = 0; } - else{ - exist_check($id_agent,'agent',$agent_name); + else { + $id_agent = $id->{'id_agente'}; } + + my $id_agentmodule; + + if (! $module_name) { + $id_agentmodule = 0; + } + else { + $id_agentmodule = get_agent_module_id($dbh,$module_name,$id_agent); + if ($id_agentmodule eq -1) { + next; + } + } + + my $id_alert_agent_module; + + if(defined($template_name) && $template_name ne '') { + my $id_template = get_template_id($dbh,$template_name); + exist_check($id_template,'template',$template_name); + $id_alert_agent_module = get_template_module_id($dbh,$id_agentmodule,$id_template); + exist_check($id_alert_agent_module,'alert template module',$template_name); + } + else { + $id_alert_agent_module = 0; + } + + if (defined($comment) && $comment ne '') { + $comment = '<b>-- Added comment by '.$user_name. ' ['. localtime(time).'] --</b><br>'.$comment.'<br>'; + } + print_log "[INFO] Adding event '$event' for agent '$agent_name' \n\n"; + + # Base64 encode custom data + $custom_data = encode_base64 ($custom_data); + + pandora_event ($conf, $event, $id_group, $id_agent, $severity, + $id_alert_agent_module, $id_agentmodule, $event_type, $event_status, $dbh, $source, $user_name, $comment, $id_extra, $tags, $c_instructions, $w_instructions, $u_instructions, $custom_data); } + } else { + if (! $agent_name) { + $id_agent = 0; + } + else { + $id_agent = get_agent_id($dbh,$agent_name); + # exist_check($id_agent,'agent',$agent_name); + if($id_agent == -1){ + if($force_create_agent == 1){ + pandora_create_agent ($conf, '', $agent_name, '', '', '', '', 'Created by cli_create_event', '', $dbh); + print_log "[INFO] Adding agent '$agent_name' \n\n"; + $id_agent = get_agent_id($dbh,$agent_name); + } + else{ + exist_check($id_agent,'agent',$agent_name); + } + } + + } + + my $id_agentmodule; + + if (! $module_name) { + $id_agentmodule = 0; + } + else { + $id_agentmodule = get_agent_module_id($dbh,$module_name,$id_agent); + exist_check($id_agentmodule,'module',$module_name); + } + + my $id_alert_agent_module; + + if(defined($template_name) && $template_name ne '') { + my $id_template = get_template_id($dbh,$template_name); + exist_check($id_template,'template',$template_name); + $id_alert_agent_module = get_template_module_id($dbh,$id_agentmodule,$id_template); + exist_check($id_alert_agent_module,'alert template module',$template_name); + } + else { + $id_alert_agent_module = 0; + } + + if (defined($comment) && $comment ne '') { + $comment = '<b>-- Added comment by '.$user_name. ' ['. localtime(time).'] --</b><br>'.$comment.'<br>'; + } + print_log "[INFO] Adding event '$event' for agent '$agent_name' \n\n"; + + # Base64 encode custom data + $custom_data = encode_base64 ($custom_data); + + pandora_event ($conf, $event, $id_group, $id_agent, $severity, + $id_alert_agent_module, $id_agentmodule, $event_type, $event_status, $dbh, $source, $user_name, $comment, $id_extra, $tags, $c_instructions, $w_instructions, $u_instructions, $custom_data); } - - my $id_agentmodule; - - if (! $module_name) { - $id_agentmodule = 0; - } - else { - $id_agentmodule = get_agent_module_id($dbh,$module_name,$id_agent); - exist_check($id_agentmodule,'module',$module_name); - } - - my $id_alert_agent_module; - - if(defined($template_name) && $template_name ne '') { - my $id_template = get_template_id($dbh,$template_name); - exist_check($id_template,'template',$template_name); - $id_alert_agent_module = get_template_module_id($dbh,$id_agentmodule,$id_template); - exist_check($id_alert_agent_module,'alert template module',$template_name); - } - else { - $id_alert_agent_module = 0; - } - - if (defined($comment) && $comment ne '') { - $comment = '<b>-- Added comment by '.$user_name. ' ['. localtime(time).'] --</b><br>'.$comment.'<br>'; - } - print_log "[INFO] Adding event '$event' for agent '$agent_name' \n\n"; - - # Base64 encode custom data - $custom_data = encode_base64 ($custom_data); - - pandora_event ($conf, $event, $id_group, $id_agent, $severity, - $id_alert_agent_module, $id_agentmodule, $event_type, $event_status, $dbh, $source, $user_name, $comment, $id_extra, $tags, $c_instructions, $w_instructions, $u_instructions, $custom_data); } ############################################################################## @@ -3487,20 +4158,10 @@ sub cli_create_event() { ############################################################################## sub cli_validate_event() { - my ($agent_name, $module_name, $datetime_min, $datetime_max, $user_name, $criticity, $template_name) = @ARGV[2..8]; + my ($agent_name, $module_name, $datetime_min, $datetime_max, $user_name, $criticity, $template_name, $use_alias) = @ARGV[2..9]; my $id_agent = ''; my $id_agentmodule = ''; - if(defined($agent_name) && $agent_name ne '') { - $id_agent = get_agent_id($dbh,$agent_name); - exist_check($id_agent,'agent',$agent_name); - - if($module_name ne '') { - $id_agentmodule = get_agent_module_id($dbh, $module_name, $id_agent); - exist_check($id_agentmodule,'module',$module_name); - } - } - if(defined($datetime_min) && $datetime_min ne '') { if ($datetime_min !~ /([0-9]{2,4})\-([0-1][0-9])\-([0-3][0-9]) +([0-2][0-9]):([0-5][0-9])/) { print_log "[ERROR] Invalid datetime_min format. (Correct format: YYYY-MM-DD HH:mm)\n"; @@ -3519,17 +4180,57 @@ sub cli_validate_event() { $datetime_max .= ":00"; } - my $id_alert_agent_module = ''; - - if(defined($template_name) && $template_name ne '') { - my $id_template = get_template_id($dbh,$template_name); - exist_check($id_template,'template',$template_name); - $id_alert_agent_module = get_template_module_id($dbh,$id_agentmodule,$id_template); - exist_check($id_alert_agent_module,'template module',$template_name); - } + if (defined $use_alias and $use_alias eq 'use_alias') { + my @id_agents = get_agent_ids_from_alias($dbh,$agent_name); + + foreach my $id (@id_agents) { + if(defined($agent_name) && $agent_name ne '') { + $id_agent = $id->{'id_agente'}; + exist_check($id_agent,'agent',$agent_name); - pandora_validate_event_filter ($conf, $id_agentmodule, $id_agent, $datetime_min, $datetime_max, $user_name, $id_alert_agent_module, $criticity, $dbh); - print_log "[INFO] Validating event for agent '$agent_name'\n\n"; + if($module_name ne '') { + $id_agentmodule = get_agent_module_id($dbh, $module_name, $id_agent); + if ($id_agentmodule eq -1) { + next; + } + } + } + + my $id_alert_agent_module = ''; + + if(defined($template_name) && $template_name ne '') { + my $id_template = get_template_id($dbh,$template_name); + exist_check($id_template,'template',$template_name); + $id_alert_agent_module = get_template_module_id($dbh,$id_agentmodule,$id_template); + exist_check($id_alert_agent_module,'template module',$template_name); + } + + pandora_validate_event_filter ($conf, $id_agentmodule, $id_agent, $datetime_min, $datetime_max, $user_name, $id_alert_agent_module, $criticity, $dbh); + print_log "[INFO] Validating event for agent '$id->{'nombre'}'\n\n"; + } + } else { + if(defined($agent_name) && $agent_name ne '') { + $id_agent = get_agent_id($dbh,$agent_name); + exist_check($id_agent,'agent',$agent_name); + + if($module_name ne '') { + $id_agentmodule = get_agent_module_id($dbh, $module_name, $id_agent); + exist_check($id_agentmodule,'module',$module_name); + } + } + + my $id_alert_agent_module = ''; + + if(defined($template_name) && $template_name ne '') { + my $id_template = get_template_id($dbh,$template_name); + exist_check($id_template,'template',$template_name); + $id_alert_agent_module = get_template_module_id($dbh,$id_agentmodule,$id_template); + exist_check($id_alert_agent_module,'template module',$template_name); + } + + pandora_validate_event_filter ($conf, $id_agentmodule, $id_agent, $datetime_min, $datetime_max, $user_name, $id_alert_agent_module, $criticity, $dbh); + print_log "[INFO] Validating event for agent '$agent_name'\n\n"; + } } ############################################################################## @@ -3675,38 +4376,84 @@ sub cli_create_incident() { sub cli_delete_data($) { my $ltotal = shift; - my ($opt, $name, $name2) = @ARGV[2..4]; + my ($opt, $name, $name2, $use_alias) = @ARGV[2..5]; + if($opt eq '-m' || $opt eq '--m') { - # Delete module data - param_check($ltotal, 3) unless ($name2 ne ''); - my $id_agent = get_agent_id($dbh,$name2); - exist_check($id_agent,'agent',$name2); + if (defined $use_alias and $use_alias eq 'use_alias') { + my @id_agents = get_agent_ids_from_alias($dbh,$name2); + + foreach my $id (@id_agents) { + # Delete module data + param_check($ltotal, 3) unless ($name2 ne ''); + my $id_agent = $id->{'id_agente'}; + exist_check($id_agent,'agent',$name2); + + my $id_module = get_agent_module_id($dbh,$name,$id_agent); + exist_check($id_module,'module',$name); + + print_log "DELETING THE DATA OF THE MODULE $name OF THE AGENT $name2\n\n"; + + pandora_delete_data($dbh, 'module', $id_module); + } + } else { + # Delete module data + param_check($ltotal, 3) unless ($name2 ne ''); + my $id_agent = get_agent_id($dbh,$name2); + exist_check($id_agent,'agent',$name2); + + my $id_module = get_agent_module_id($dbh,$name,$id_agent); + exist_check($id_module,'module',$name); - my $id_module = get_agent_module_id($dbh,$name,$id_agent); - exist_check($id_module,'module',$name); - - print_log "DELETING THE DATA OF THE MODULE $name OF THE AGENT $name2\n\n"; - - pandora_delete_data($dbh, 'module', $id_module); + print_log "DELETING THE DATA OF THE MODULE $name OF THE AGENT $name2\n\n"; + + pandora_delete_data($dbh, 'module', $id_module); + } + } elsif($opt eq '-a' || $opt eq '--a') { - # Delete agent's modules data - my $id_agent = get_agent_id($dbh,$name); - exist_check($id_agent,'agent',$name); + if (defined $use_alias and $use_alias eq 'use_alias') { + my @id_agents = get_agent_ids_from_alias($dbh,$name); + foreach my $id (@id_agents) { + # Delete agent's modules data + my $id_agent = $id->{'id_agente'}; + exist_check($id_agent,'agent',$name); - print_log "DELETING THE DATA OF THE AGENT $name\n\n"; + print_log "DELETING THE DATA OF THE AGENT $name\n\n"; - pandora_delete_data($dbh, 'module', $id_agent); + pandora_delete_data($dbh, 'module', $id_agent); + } + } else { + my $id_agent = get_agent_id($dbh,$name); + exist_check($id_agent,'agent',$name); + + print_log "DELETING THE DATA OF THE AGENT $name\n\n"; + + pandora_delete_data($dbh, 'module', $id_agent); + } } elsif($opt eq '-g' || $opt eq '--g') { - # Delete group's modules data - my $id_group = get_group_id($dbh,$name); - exist_check($id_group,'group',$name); - - print_log "DELETING THE DATA OF THE GROUP $name\n\n"; - - pandora_delete_data($dbh, 'group', $id_group); + if (defined $use_alias and $use_alias eq 'use_alias') { + my @id_agents = get_agent_ids_from_alias($dbh,$name); + + foreach my $id (@id_agents) { + # Delete group's modules data + my $id_group = $id->{'id_agente'}; + exist_check($id_group,'group',$name); + + print_log "DELETING THE DATA OF THE GROUP $name\n\n"; + + pandora_delete_data($dbh, 'group', $id_group); + } + } else { + # Delete group's modules data + my $id_group = get_group_id($dbh,$name); + exist_check($id_group,'group',$name); + + print_log "DELETING THE DATA OF THE GROUP $name\n\n"; + + pandora_delete_data($dbh, 'group', $id_group); + } } else { print_log "[ERROR] Invalid parameter '$opt'.\n\n"; @@ -3863,21 +4610,20 @@ sub cli_get_module_id() { ############################################################################## -# Show the group name where is a given agent +# Show the group name where a given agent is # Related option: --get_agent_group ############################################################################## sub cli_get_agent_group() { - my $agent_name = @ARGV[2]; - + my ($agent_name,$use_alias) = @ARGV[2..3]; + if (is_metaconsole($conf) == 1) { my $agents_groups = enterprise_hook('get_metaconsole_agent',[$dbh, $agent_name]); - if (scalar(@{$agents_groups}) != 0) { + if (not defined $use_alias and scalar(@{$agents_groups}) != 0) { foreach my $agent (@{$agents_groups}) { my @test = $agent; - print Dumper $test[0]; my $group_name = get_group_name ($dbh, $agent->{'id_grupo'}); print "Server: $agent->{'server_name'} Agent: $agent->{'nombre'} Name Group: $group_name \n\n"; } @@ -3890,28 +4636,68 @@ sub cli_get_agent_group() { foreach my $server (@servers_id) { my $dbh_metaconsole = enterprise_hook('get_node_dbh',[$conf, $server, $dbh]); - my $id_agent = get_agent_id($dbh_metaconsole,$agent_name); - - if ($id_agent == -1) { - next; - } - else { - my $id_group = get_agent_group ($dbh_metaconsole, $id_agent); - my $group_name = get_group_name ($dbh_metaconsole, $id_group); - $agent_name = safe_output($agent_name); - print "[INFO] Agent: $agent_name Name Group: $group_name\n\n"; + my @id_agents; + my $id_agent; + + if (defined $use_alias and $use_alias eq 'use_alias') { + @id_agents = get_agent_ids_from_alias($dbh_metaconsole,$agent_name); + + foreach my $id (@id_agents) { + + if ($id->{'id_agente'} == -1) { + next; + } + else { + my $id_group = get_agent_group ($dbh_metaconsole, $id->{'id_agente'}); + my $group_name = get_group_name ($dbh_metaconsole, $id_group); + $agent_name = safe_output($agent_name); + print "[INFO] Agent: $id->{'nombre'} Name Group: $group_name\n\n"; + } + } + } else { + $id_agent = get_agent_id($dbh_metaconsole,$agent_name); + + if ($id_agent == -1) { + next; + } + else { + my $id_group = get_agent_group ($dbh_metaconsole, $id_agent); + my $group_name = get_group_name ($dbh_metaconsole, $id_group); + $agent_name = safe_output($agent_name); + print "[INFO] Agent: $agent_name Name Group: $group_name\n\n"; + } } } } } else { - my $id_agent = get_agent_id($dbh,$agent_name); - exist_check($id_agent,'agent',$agent_name); + my @id_agents; + my $id_agent; + my $id_group; + my $group_name; + + if (defined $use_alias and $use_alias eq 'use_alias') { + @id_agents = get_agent_ids_from_alias($dbh,$agent_name); + + foreach my $id (@id_agents) { + exist_check($id->{'id_agente'},'agent',$agent_name); + + $id_group = get_agent_group ($dbh, $id->{'id_agente'}); - my $id_group = get_agent_group ($dbh, $id_agent); + $group_name = get_group_name ($dbh, $id_group); + print $group_name."\n"; + } + } else { + $id_agent = get_agent_id($dbh,$agent_name); + exist_check($id_agent,'agent',$agent_name); + + $id_group = get_agent_group ($dbh, $id_agent); - my $group_name = get_group_name ($dbh, $id_group); - print $group_name; + $group_name = get_group_name ($dbh, $id_group); + print $group_name; + } + + } } @@ -3920,12 +4706,13 @@ sub cli_get_agent_group() { # Related option: --get_agent_group_id ############################################################################## sub cli_get_agent_group_id() { - my $agent_name = @ARGV[2]; + my ($agent_name,$use_alias) = @ARGV[2..3]; if (is_metaconsole($conf) == 1) { + my $agents_groups = enterprise_hook('get_metaconsole_agent',[$dbh, $agent_name]); - if (scalar(@{$agents_groups}) != 0) { + if (not defined $use_alias and scalar(@{$agents_groups}) != 0) { foreach my $agent (@{$agents_groups}) { print "Server: $agent->{'server_name'} Agent: $agent->{'nombre'} ID Group: $agent->{'id_grupo'}\n\n"; @@ -3939,26 +4726,62 @@ sub cli_get_agent_group_id() { foreach my $server (@servers_id) { my $dbh_metaconsole = enterprise_hook('get_node_dbh',[$conf, $server, $dbh]); - my $id_agent = get_agent_id($dbh_metaconsole,$agent_name); - - if ($id_agent == -1) { - next; - } - else { - my $id_group = get_agent_group ($dbh_metaconsole, $id_agent); - $agent_name = safe_output($agent_name); - print "Agent: $agent_name ID Group: $id_group\n\n"; + my @id_agents; + my $id_agent; + + if (defined $use_alias and $use_alias eq 'use_alias') { + @id_agents = get_agent_ids_from_alias($dbh_metaconsole,$agent_name); + + foreach my $id (@id_agents) { + + if ($id->{'id_agente'} == -1) { + next; + } + else { + my $id_group = get_agent_group ($dbh_metaconsole, $id->{'id_agente'}); + $agent_name = safe_output($agent_name); + print "Agent: $id->{'nombre'} ID Group: $id_group\n\n"; + } + } + } else { + $id_agent = get_agent_id($dbh_metaconsole,$agent_name); + + if ($id_agent == -1) { + next; + } + else { + my $id_group = get_agent_group ($dbh_metaconsole, $id_agent); + $agent_name = safe_output($agent_name); + print "Agent: $agent_name ID Group: $id_group\n\n"; + } } } } } else { - my $id_agent = get_agent_id($dbh,$agent_name); - exist_check($id_agent,'agent',$agent_name); - - my $id_group = get_agent_group ($dbh, $id_agent); + my @id_agents; + my $id_agent; + my $id_group; + my $group_name; - print $id_group; + if (defined $use_alias and $use_alias eq 'use_alias') { + @id_agents = get_agent_ids_from_alias($dbh,$agent_name); + + foreach my $id (@id_agents) { + exist_check($id->{'id_agente'},'agent',$agent_name); + + $id_group = get_agent_group ($dbh, $id->{'id_agente'}); + + print $id_group."\n"; + } + } else { + $id_agent = get_agent_id($dbh,$agent_name); + exist_check($id_agent,'agent',$agent_name); + + $id_group = get_agent_group ($dbh, $id_agent); + + print $id_group; + } } } @@ -3986,20 +4809,43 @@ sub cli_get_agents_module_current_data() { ############################################################################## sub cli_get_agent_modules() { - my $agent_name = @ARGV[2]; + my ($agent_name,$use_alias) = @ARGV[2..3]; - my $id_agent = get_agent_id($dbh,$agent_name); - exist_check($id_agent,'agent',$agent_name); + my @id_agents; + my $id_agent; + + if (defined $use_alias and $use_alias eq 'use_alias') { + @id_agents = get_agent_ids_from_alias($dbh,$agent_name); + + foreach my $id (@id_agents) { + exist_check($id->{'id_agente'},'agent',$agent_name); + + my $modules = pandora_get_agent_modules ($dbh, $id->{'id_agente'}); + + if(scalar(@{$modules}) == 0) { + print_log "[INFO] The agent '$agent_name' have no modules\n\n"; + } + + print "\n".$id->{'nombre'}."\n"; + print "id_module, module_name\n"; + foreach my $module (@{$modules}) { + print $module->{'id_agente_modulo'}.",".safe_output($module->{'nombre'})."\n"; + } + } + } else { + $id_agent = get_agent_id($dbh,$agent_name); + exist_check($id_agent,'agent',$agent_name); - my $modules = pandora_get_agent_modules ($dbh, $id_agent); + my $modules = pandora_get_agent_modules ($dbh, $id_agent); + + if(scalar(@{$modules}) == 0) { + print_log "[INFO] The agent '$agent_name' have no modules\n\n"; + } - if(scalar(@{$modules}) == 0) { - print_log "[INFO] The agent '$agent_name' have not modules\n\n"; - } - - print "id_module, module_name\n"; - foreach my $module (@{$modules}) { - print $module->{'id_agente_modulo'}.",".safe_output($module->{'nombre'})."\n"; + print "id_module, module_name\n"; + foreach my $module (@{$modules}) { + print $module->{'id_agente_modulo'}.",".safe_output($module->{'nombre'})."\n"; + } } } @@ -4008,7 +4854,15 @@ sub cli_create_synthetic() { my $synthetic_type = @ARGV[3]; my $agent_name = @ARGV[4]; - my @module_data = @ARGV[5..$#ARGV]; + + my @module_data; + + if (@ARGV[$#ARGV] == "use_alias") { + @module_data = @ARGV[5..$#ARGV-1]; + } else { + @module_data = @ARGV[5..$#ARGV]; + } + my $module; my (@filterdata,@data_module); @@ -4030,86 +4884,181 @@ sub cli_create_synthetic() { $module->{'prediction_module'} = 3; # Synthetic code is 3 $module->{'flag'} = 1; - my $id_agent = int(get_agent_id($dbh,$agent_name)); - - if ($id_agent > 0) { - foreach my $i (0 .. $#module_data) { - my @split_data = split(',',$module_data[$i]); - if (@split_data[0] =~ m/(x|\/|\+|\*|\-)/ && length(@split_data[0]) == 1 ) { - if ( @split_data[0] =~ m/(\/|\+|\*|\-)/ && $synthetic_type eq 'average' ) { - print("[ERROR] With this type: $synthetic_type only be allow use this operator: 'x' \n\n"); - exit 1; + my @id_agents; + my $id_agent; + + if (@ARGV[$#ARGV] eq 'use_alias') { + @id_agents = get_agent_ids_from_alias($dbh,$agent_name); + + foreach my $id (@id_agents) { + @filterdata = (); + $id_agent = $id->{'id_agente'}; + + if ($id_agent > 0) { + + foreach my $i (0 .. $#module_data) { + my @split_data = split(',',$module_data[$i]); + if (@split_data[0] =~ m/(x|\/|\+|\*|\-)/ && length(@split_data[0]) == 1 ) { + if ( @split_data[0] =~ m/(\/|\+|\*|\-)/ && $synthetic_type eq 'average' ) { + print("[ERROR] With this type: $synthetic_type only be allow use this operator: 'x' \n\n"); + exit 1; + } + if (is_numeric(@split_data[1]) == 0) { + next; + } + @data_module = ("",@split_data[0],@split_data[1]); + my $text_data = join(',',@data_module); + push (@filterdata,$text_data); + } + else { + if (scalar(@split_data) == 2) { + @data_module = (safe_output(@split_data[0]),'',safe_output(@split_data[1])); + my $text_data = join(',',@data_module); + push (@filterdata,$text_data); + } + else { + if (length(@split_data[1]) > 1 ) { + print("[ERROR] You can only use +, -, *, / or x, and you use this: @split_data[1] \n\n"); + exit 1; + } + if ( @split_data[1] =~ m/(\/|\+|\*|\-)/ && $synthetic_type eq 'average' ) { + print("[ERROR] With this type: $synthetic_type only be allow use this operator: 'x' \n\n"); + exit 1; + } + if ( $synthetic_type eq 'arithmetic' && $i == 0) { + @data_module = (safe_output(@split_data[0]),'',safe_output(@split_data[2])); + } + else { + @data_module = (safe_output(@split_data[0]),@split_data[1],safe_output(@split_data[2])); + } + my $text_data = join(',',@data_module); + push (@filterdata,$text_data); + } + } } - if (is_numeric(@split_data[1]) == 0) { - next; + + my $module_exists = get_agent_module_id($dbh, $name_module, $id_agent); + non_exist_check($module_exists, 'module name', $name_module); + + $module->{'id_agente'} = $id_agent; + $module->{'nombre'} = safe_input($name_module); + my $id_tipo_modulo = get_db_value ($dbh, "SELECT id_tipo FROM ttipo_modulo WHERE nombre = ?", "generic_data"); + $module->{'id_modulo'} = 5; + $module->{'id_tipo_modulo'} = $id_tipo_modulo; + + my $id_module = db_process_insert($dbh, 'id_agente_modulo', 'tagente_modulo', $module); + + if ($id_module) { + my $result = enterprise_hook('create_synthetic_operations_by_alias', + [$dbh,int($id_module), @filterdata]); + + if ($result) { + + db_do ($dbh, 'INSERT INTO tagente_estado (id_agente_modulo, id_agente, estado, + known_status, last_status, last_known_status, last_try, datos) + VALUES (?, ?, ?, ?, ?, ?, \'1970-01-01 00:00:00\', \'\')', $id_module, $id_agent, 4, 4, 4, 4); + # Update the module status count. When the module is created disabled dont do it + pandora_mark_agent_for_module_update ($dbh, $id_agent); + print("[OK] Created module ID: $id_module \n\n"); + } + else { + #db_do ($dbh, 'DELETE FROM tagente_modulo WHERE id_agente_modulo = ?', $id_module); + print("[ERROR] Problems with creating data module. \n\n"); + } + } + else { + db_do ($dbh, 'DELETE FROM tagente_modulo WHERE nombre = ? AND id_agente = ?', $name_module, $id_agent); + print("[INFO] Problems with creating module \n\n"); } - @data_module = ("",@split_data[0],@split_data[1]); - my $text_data = join(',',@data_module); - push (@filterdata,$text_data); } else { - if (scalar(@split_data) == 2) { - @data_module = (safe_output(@split_data[0]),'',safe_output(@split_data[1])); + print( "[INFO] The agent '$id->{'nombre'}' doesn't exist\n\n"); + } + } + } else { + my $id_agent = int(get_agent_id($dbh,$agent_name)); + + if ($id_agent > 0) { + foreach my $i (0 .. $#module_data) { + my @split_data = split(',',$module_data[$i]); + if (@split_data[0] =~ m/(x|\/|\+|\*|\-)/ && length(@split_data[0]) == 1 ) { + if ( @split_data[0] =~ m/(\/|\+|\*|\-)/ && $synthetic_type eq 'average' ) { + print("[ERROR] With this type: $synthetic_type only be allow use this operator: 'x' \n\n"); + exit 1; + } + if (is_numeric(@split_data[1]) == 0) { + next; + } + @data_module = ("",@split_data[0],@split_data[1]); my $text_data = join(',',@data_module); push (@filterdata,$text_data); } else { - if (length(@split_data[1]) > 1 ) { - print("[ERROR] You can only use +, -, *, / or x, and you use this: @split_data[1] \n\n"); - exit 1; - } - if ( @split_data[1] =~ m/(\/|\+|\*|\-)/ && $synthetic_type eq 'average' ) { - print("[ERROR] With this type: $synthetic_type only be allow use this operator: 'x' \n\n"); - exit 1; - } - if ( $synthetic_type eq 'arithmetic' && $i == 0) { - @data_module = (safe_output(@split_data[0]),'',safe_output(@split_data[2])); + if (scalar(@split_data) == 2) { + @data_module = (safe_output(@split_data[0]),'',safe_output(@split_data[1])); + my $text_data = join(',',@data_module); + push (@filterdata,$text_data); } else { - @data_module = (safe_output(@split_data[0]),@split_data[1],safe_output(@split_data[2])); + if (length(@split_data[1]) > 1 ) { + print("[ERROR] You can only use +, -, *, / or x, and you use this: @split_data[1] \n\n"); + exit 1; + } + if ( @split_data[1] =~ m/(\/|\+|\*|\-)/ && $synthetic_type eq 'average' ) { + print("[ERROR] With this type: $synthetic_type only be allow use this operator: 'x' \n\n"); + exit 1; + } + if ( $synthetic_type eq 'arithmetic' && $i == 0) { + @data_module = (safe_output(@split_data[0]),'',safe_output(@split_data[2])); + } + else { + @data_module = (safe_output(@split_data[0]),@split_data[1],safe_output(@split_data[2])); + } + + my $text_data = join(',',@data_module); + push (@filterdata,$text_data); } - - my $text_data = join(',',@data_module); - push (@filterdata,$text_data); } } - } - my $module_exists = get_agent_module_id($dbh, $name_module, $id_agent); - non_exist_check($module_exists, 'module name', $name_module); - - $module->{'id_agente'} = $id_agent; - $module->{'nombre'} = safe_input($name_module); - my $id_tipo_modulo = get_db_value ($dbh, "SELECT id_tipo FROM ttipo_modulo WHERE nombre = ?", "generic_data"); - $module->{'id_modulo'} = 5; - $module->{'id_tipo_modulo'} = $id_tipo_modulo; - - my $id_module = db_process_insert($dbh, 'id_agente_modulo', 'tagente_modulo', $module); - - if ($id_module) { - my $result = enterprise_hook('create_synthetic_operations', - [$dbh,int($id_module), @filterdata]); - if ($result) { - db_do ($dbh, 'INSERT INTO tagente_estado (id_agente_modulo, id_agente, estado, - known_status, last_status, last_known_status, last_try, datos) - VALUES (?, ?, ?, ?, ?, ?, \'1970-01-01 00:00:00\', \'\')', $id_module, $id_agent, 4, 4, 4, 4); - # Update the module status count. When the module is created disabled dont do it - pandora_mark_agent_for_module_update ($dbh, $id_agent); - print("[OK] The modules are creating ID: $id_module \n\n"); + my $module_exists = get_agent_module_id($dbh, $name_module, $id_agent); + non_exist_check($module_exists, 'module name', $name_module); + + $module->{'id_agente'} = $id_agent; + $module->{'nombre'} = safe_input($name_module); + my $id_tipo_modulo = get_db_value ($dbh, "SELECT id_tipo FROM ttipo_modulo WHERE nombre = ?", "generic_data"); + $module->{'id_modulo'} = 5; + $module->{'id_tipo_modulo'} = $id_tipo_modulo; + + my $id_module = db_process_insert($dbh, 'id_agente_modulo', 'tagente_modulo', $module); + + if ($id_module) { + my $result = enterprise_hook('create_synthetic_operations', + [$dbh,int($id_module), @filterdata]); + if ($result) { + db_do ($dbh, 'INSERT INTO tagente_estado (id_agente_modulo, id_agente, estado, + known_status, last_status, last_known_status, last_try, datos) + VALUES (?, ?, ?, ?, ?, ?, \'1970-01-01 00:00:00\', \'\')', $id_module, $id_agent, 4, 4, 4, 4); + # Update the module status count. When the module is created disabled dont do it + pandora_mark_agent_for_module_update ($dbh, $id_agent); + print("[OK] Created module ID: $id_module \n\n"); + } + else { + db_do ($dbh, 'DELETE FROM tagente_modulo WHERE id_agente_modulo = ?', $id_module); + print("[ERROR] Problems with creating data module. \n\n"); + } } else { - db_do ($dbh, 'DELETE FROM tagente_modulo WHERE id_agente_modulo = ?', $id_module); - print("[ERROR] Problems with creating data module. \n\n"); + db_do ($dbh, 'DELETE FROM tagente_modulo WHERE nombre = ? AND id_agente = ?', $name_module, $id_agent); + print("[INFO] Problems with creating module \n\n"); } } - else { - db_do ($dbh, 'DELETE FROM tagente_modulo WHERE nombre = ? AND id_agente = ?', $name_module, $id_agent); - print("[INFO] Problems with creating module \n\n"); + else { + print( "[INFO] The agent '$agent_name' doesn't exist\n\n"); } } - else { - print( "[INFO] The agent '$agent_name' doesn't exists\n\n"); - } + + } @@ -4146,32 +5095,63 @@ sub cli_get_policy_modules() { ######################################################################## sub cli_get_policies() { - my $agent_name = @ARGV[2]; + my ($agent_name, $use_alias) = @ARGV[2..3]; my $policies; - if (defined($agent_name)) { - my $id_agent = get_agent_id($dbh,$agent_name); - exist_check($id_agent,'agent',$agent_name); + if (defined $use_alias and $use_alias eq 'use_alias') { + my @id_agents = get_agent_ids_from_alias($dbh,$agent_name); + + foreach my $id (@id_agents) { + if (defined($agent_name)) { + my $id_agent = $id->{'id_agente'}; + exist_check($id_agent,'agent',$agent_name); + + $policies = enterprise_hook('get_agent_policies', [$dbh,$id_agent]); + + if (scalar(@{$policies}) == 0) { + print_log "[INFO] No policies found on agent $id->{'nombre'}\n\n"; + exit; + } + } + else { + $policies = enterprise_hook('get_policies', [$dbh]); + if (scalar(@{$policies}) == 0) { + print_log "[INFO] No policies found\n\n"; + exit; + } + } + + print "agent_name, id_policy, policy_name\n"; + foreach my $module (@{$policies}) { + print $id->{'nombre'}.",".$module->{'id'}.",".safe_output($module->{'name'})."\n"; + } + } + } else { + if (defined($agent_name)) { + my $id_agent = get_agent_id($dbh,$agent_name); + exist_check($id_agent,'agent',$agent_name); + + $policies = enterprise_hook('get_agent_policies', [$dbh,$id_agent]); + + if (scalar(@{$policies}) == 0) { + print_log "[INFO] No policies found on agent '$agent_name'\n\n"; + exit; + } + } + else { + $policies = enterprise_hook('get_policies', [$dbh]); + if (scalar(@{$policies}) == 0) { + print_log "[INFO] No policies found\n\n"; + exit; + } + } - $policies = enterprise_hook('get_agent_policies', [$dbh,$id_agent]); - - if (scalar(@{$policies}) == 0) { - print_log "[INFO] No policies found on agent '$agent_name'\n\n"; - exit; + print "id_policy, policy_name\n"; + foreach my $module (@{$policies}) { + print $module->{'id'}.",".safe_output($module->{'name'})."\n"; } } - else { - $policies = enterprise_hook('get_policies', [$dbh]); - if (scalar(@{$policies}) == 0) { - print_log "[INFO] No policies found\n\n"; - exit; - } - } - - print "id_policy, policy_name\n"; - foreach my $module (@{$policies}) { - print $module->{'id'}.",".safe_output($module->{'name'})."\n"; - } + } ############################################################################## @@ -4180,7 +5160,7 @@ sub cli_get_policies() { ############################################################################## sub cli_get_agents() { - my ($group_name, $os_name, $status, $max_modules, $filter_substring, $policy_name) = @ARGV[2..7]; + my ($group_name, $os_name, $status, $max_modules, $filter_substring, $policy_name, $use_alias) = @ARGV[2..8]; my $condition = ' disabled=0'; @@ -4191,7 +5171,7 @@ sub cli_get_agents() { if($group_name ne '') { $id_group = get_group_id($dbh, $group_name); exist_check($id_group,'group',$group_name); - + $condition .= " AND id_grupo = $id_group "; } @@ -4216,7 +5196,11 @@ sub cli_get_agents() { } if($filter_substring ne '') { - $condition .= " AND nombre LIKE '%".safe_input($filter_substring)."%'"; + if (defined $use_alias and $use_alias eq 'use_alias') { + $condition .= " AND alias LIKE '%".safe_input($filter_substring)."%'"; + } else { + $condition .= " AND nombre LIKE '%".safe_input($filter_substring)."%'"; + } } my @agents = get_db_rows ($dbh, "SELECT * FROM tagente WHERE $condition"); @@ -4229,6 +5213,10 @@ sub cli_get_agents() { my $agent_status; my $head_print = 0; + + use Data::Dumper; + + foreach my $agent (@agents) { if($status ne '') { $agent_status = pandora_get_agent_status($dbh,$agent->{'id_agente'}); @@ -4240,6 +5228,7 @@ sub cli_get_agents() { $head_print = 1; print "id_agent, agent_name\n"; } + print $agent->{'id_agente'}.",".safe_output($agent->{'nombre'})."\n"; } @@ -4254,26 +5243,51 @@ sub cli_get_agents() { ############################################################################## sub cli_delete_conf_file() { - my $agent_name = @ARGV[2]; - + my ($agent_name,$use_alias) = @ARGV[2..3]; + my $conf_deleted = 0; my $md5_deleted = 0; - - if (-e $conf->{incomingdir}.'/conf/'.md5($agent_name).'.conf') { - unlink($conf->{incomingdir}.'/conf/'.md5($agent_name).'.conf'); - $conf_deleted = 1; - } - if (-e $conf->{incomingdir}.'/md5/'.md5($agent_name).'.md5') { - unlink($conf->{incomingdir}.'/md5/'.md5($agent_name).'.md5'); - $md5_deleted = 1; - } - - if($conf_deleted == 1 || $md5_deleted == 1) { - print_log "[INFO] Local conf files of the agent '$agent_name' has been deleted succesfully\n\n"; - } - else { - print_log "[ERROR] Local conf file of the agent '$agent_name' didn't found\n\n"; - exit; + + if (defined $use_alias and $use_alias eq 'use_alias') { + my @id_agents = get_agent_ids_from_alias($dbh,$agent_name); + + foreach my $id (@id_agents) { + $agent_name = $id->{'nombre'}; + + if (-e $conf->{incomingdir}.'/conf/'.md5($agent_name).'.conf') { + unlink($conf->{incomingdir}.'/conf/'.md5($agent_name).'.conf'); + $conf_deleted = 1; + } + if (-e $conf->{incomingdir}.'/md5/'.md5($agent_name).'.md5') { + unlink($conf->{incomingdir}.'/md5/'.md5($agent_name).'.md5'); + $md5_deleted = 1; + } + + if($conf_deleted == 1 || $md5_deleted == 1) { + print_log "[INFO] Local conf files of the agent '$agent_name' has been deleted succesfully\n\n"; + } + else { + print_log "[ERROR] Local conf file of the agent '$agent_name' was not found\n\n"; + exit; + } + } + } else { + if (-e $conf->{incomingdir}.'/conf/'.md5($agent_name).'.conf') { + unlink($conf->{incomingdir}.'/conf/'.md5($agent_name).'.conf'); + $conf_deleted = 1; + } + if (-e $conf->{incomingdir}.'/md5/'.md5($agent_name).'.md5') { + unlink($conf->{incomingdir}.'/md5/'.md5($agent_name).'.md5'); + $md5_deleted = 1; + } + + if($conf_deleted == 1 || $md5_deleted == 1) { + print_log "[INFO] Local conf files of the agent '$agent_name' has been deleted succesfully\n\n"; + } + else { + print_log "[ERROR] Local conf file of the agent '$agent_name' was not found\n\n"; + exit; + } } } @@ -4283,14 +5297,29 @@ sub cli_delete_conf_file() { ############################################################################## sub cli_clean_conf_file() { - my $agent_name = @ARGV[2]; + my ($agent_name,$use_alias) = @ARGV[2..3]; my $result; if(defined($agent_name)) { - if (-e $conf->{incomingdir}.'/conf/'.md5($agent_name).'.conf') { - $result = enterprise_hook('pandora_clean_conf_file',[$conf, md5($agent_name)]); - if($result != -1) { - print_log "[INFO] Conf file '".$conf->{incomingdir}.'/conf/'.md5($agent_name).".conf has been cleaned'\n\n"; + if (defined $use_alias and $use_alias eq 'use_alias') { + my @id_agents = get_agent_ids_from_alias($dbh,$agent_name); + + foreach my $id (@id_agents) { + $agent_name = $id->{'nombre'}; + + if (-e $conf->{incomingdir}.'/conf/'.md5($agent_name).'.conf') { + $result = enterprise_hook('pandora_clean_conf_file',[$conf, md5($agent_name)]); + if($result != -1) { + print_log "[INFO] Conf file '".$conf->{incomingdir}.'/conf/'.md5($agent_name).".conf has been cleaned'\n\n"; + } + } + } + } else { + if (-e $conf->{incomingdir}.'/conf/'.md5($agent_name).'.conf') { + $result = enterprise_hook('pandora_clean_conf_file',[$conf, md5($agent_name)]); + if($result != -1) { + print_log "[INFO] Conf file '".$conf->{incomingdir}.'/conf/'.md5($agent_name).".conf has been cleaned'\n\n"; + } } } } @@ -4367,23 +5396,46 @@ sub cli_disable_policy_alerts() { ############################################################################## sub cli_policy_add_agent() { - my ($agent_name, $policy_name) = @ARGV[2..3]; + my ($agent_name, $policy_name, $use_alias) = @ARGV[2..4]; - my $agent_id = get_agent_id($dbh,$agent_name); - exist_check($agent_id,'agent',$agent_name); - - my $policy_id = enterprise_hook('get_policy_id',[$dbh, safe_input($policy_name)]); - exist_check($policy_id,'policy',$policy_name); + if (defined $use_alias and $use_alias eq 'use_alias') { + my @id_agents = get_agent_ids_from_alias($dbh,$agent_name); + + foreach my $id (@id_agents) { + my $agent_id = $id->{'id_agente'}; + exist_check($agent_id,'agent',$agent_name); + + my $policy_id = enterprise_hook('get_policy_id',[$dbh, safe_input($policy_name)]); + exist_check($policy_id,'policy',$policy_name); + + # Add the agent to policy + my $policy_agent_id = enterprise_hook('pandora_policy_add_agent',[$policy_id, $agent_id, $dbh]); + + if($policy_agent_id == -1) { + print_log "[ERROR] A problem has been ocurred adding agent $id->{'nombre'} to policy '$policy_name'\n\n"; + } + else { + print_log "[INFO] Added agent $id->{'nombre'} to policy $policy_name. Is necessary to apply the policy in order to changes take effect.\n\n"; + } + } + } else { + my $agent_id = get_agent_id($dbh,$agent_name); + exist_check($agent_id,'agent',$agent_name); - # Add the agent to policy - my $policy_agent_id = enterprise_hook('pandora_policy_add_agent',[$policy_id, $agent_id, $dbh]); - - if($policy_agent_id == -1) { - print_log "[ERROR] A problem has been ocurred adding agent '$agent_name' to policy '$policy_name'\n\n"; - } - else { - print_log "[INFO] Added agent '$agent_name' to policy '$policy_name'. Is necessary to apply the policy in order to changes take effect.\n\n"; + my $policy_id = enterprise_hook('get_policy_id',[$dbh, safe_input($policy_name)]); + exist_check($policy_id,'policy',$policy_name); + + # Add the agent to policy + my $policy_agent_id = enterprise_hook('pandora_policy_add_agent',[$policy_id, $agent_id, $dbh]); + + if($policy_agent_id == -1) { + print_log "[ERROR] A problem has been ocurred adding agent '$agent_name' to policy '$policy_name'\n\n"; + } + else { + print_log "[INFO] Added agent '$agent_name' to policy '$policy_name'. Is necessary to apply the policy in order to changes take effect.\n\n"; + } } + } ############################################################################## @@ -4609,11 +5661,6 @@ sub cli_update_group() { print_log "[INFO] Updated group '$group_id'\n\n"; } } - - - - - } @@ -4622,47 +5669,79 @@ sub cli_update_group() { # Related option: --locate_agent ############################################################################### sub cli_locate_agent () { - my ($agent_name) = @ARGV[2]; + my ($agent_name, $use_alias) = @ARGV[2..3]; if (is_metaconsole($conf) == 1) { - my $agents_server = enterprise_hook('get_metaconsole_agent',[$dbh, $agent_name]); - - if (scalar(@{$agents_server}) != 0) { - foreach my $agent (@{$agents_server}) { - #my $server = enterprise_hook('get_metaconsole_setup_server_id',[$dbh, $agent->{'server_name'}]); - print $agent->{'id_tmetaconsole_setup'} . "\n"; - } - } - else { + if (defined $use_alias and $use_alias eq 'use_alias') { my $servers = enterprise_hook('get_metaconsole_setup_servers',[$dbh]); my @servers_id = split(',',$servers); my @list_servers; my $list_names_servers; + my @id_agents; foreach my $server (@servers_id) { my $dbh_metaconsole = enterprise_hook('get_node_dbh',[$conf, $server, $dbh]); - my $agent_id = get_agent_id($dbh_metaconsole,$agent_name); + @id_agents = get_agent_ids_from_alias($dbh_metaconsole,$agent_name); - if ($agent_id == -1) { - next; - } - else { - push @list_servers,$server; + foreach my $id (@id_agents) { + if ($id->{'id_agente'} == -1) { + next; + } + else { + push @list_servers,$server; + last; + } } } if (scalar(@list_servers) > 0) { $list_names_servers = join(',',@list_servers); - print_log "[INFO] The agent: $agent_name find in server with IDS: $list_names_servers\n\n"; + print_log "[INFO] One or more agents with the alias '$agent_name' were found in server with IDS: $list_names_servers\n\n"; } else { - print_log "[ERROR] This agent: $agent_name not find in any node\n\n"; + print_log "[ERROR] No agent with alias '$agent_name' found in any node\n\n"; + } + } else { + my $agents_server = enterprise_hook('get_metaconsole_agent',[$dbh, $agent_name]); + + if (scalar(@{$agents_server}) != 0) { + foreach my $agent (@{$agents_server}) { + #my $server = enterprise_hook('get_metaconsole_setup_server_id',[$dbh, $agent->{'server_name'}]); + print $agent->{'id_tmetaconsole_setup'} . "\n"; + } + } + else { + my $servers = enterprise_hook('get_metaconsole_setup_servers',[$dbh]); + my @servers_id = split(',',$servers); + my @list_servers; + my $list_names_servers; + foreach my $server (@servers_id) { + my $dbh_metaconsole = enterprise_hook('get_node_dbh',[$conf, $server, $dbh]); + + my $agent_id = get_agent_id($dbh_metaconsole,$agent_name); + + if ($agent_id == -1) { + next; + } + else { + push @list_servers,$server; + } + } + + if (scalar(@list_servers) > 0) { + $list_names_servers = join(',',@list_servers); + print_log "[INFO] Agent '$agent_name' found in server with IDS: $list_names_servers\n\n"; + } + else { + print_log "[ERROR] Agent '$agent_name' not found in any node\n\n"; + } } } + } else { - print_log "[ERROR] This functions only working in metaconsole system\n\n"; + print_log "[ERROR] This function can only be used in metaconsole\n\n"; } } @@ -4835,7 +5914,7 @@ sub cli_stop_downtime () { # Related option: --get_module_data ############################################################################### sub cli_module_get_data () { - my ($agent_name, $module_name, $interval, $csv_separator) = @ARGV[2..5]; + my ($agent_name, $module_name, $interval, $csv_separator, $use_alias) = @ARGV[2..6]; $csv_separator = '|' unless defined($csv_separator); @@ -4843,57 +5922,112 @@ sub cli_module_get_data () { print_log "[ERROR] Interval must be a possitive value\n\n"; exit; } + + my @id_agents; - - - my $agent_id = get_agent_id($dbh,$agent_name); - exist_check($agent_id, 'agent name', $agent_name); - - my $module_id = get_agent_module_id($dbh, $module_name, $agent_id); - exist_check($module_id, 'module name', $module_name); - - my $id_agent_module = get_agent_module_id ($dbh, $module_name, $agent_id); - - my $module_type_id = get_db_value($dbh, - "SELECT id_tipo_modulo FROM tagente_modulo WHERE id_agente_modulo = ?", - $id_agent_module); - - my $module_type = get_db_value($dbh, - "SELECT nombre FROM ttipo_modulo WHERE id_tipo = ?", - $module_type_id); - - my @data = NULL; - if ($module_type eq "log4x") { - @data = get_db_rows ($dbh, "SELECT utimestamp, datos - FROM tagente_datos_log4x - WHERE id_agente_modulo = $id_agent_module - AND utimestamp > (UNIX_TIMESTAMP(NOW()) - $interval) - ORDER BY utimestamp DESC"); - } - elsif ($module_type =~ m/_string/) { - print("aaaa\n"); - @data = get_db_rows ($dbh, "SELECT utimestamp, datos - FROM tagente_datos_string - WHERE id_agente_modulo = $id_agent_module - AND utimestamp > (UNIX_TIMESTAMP(NOW()) - $interval) - ORDER BY utimestamp DESC"); - } - else { - @data = get_db_rows ($dbh, "SELECT utimestamp, datos - FROM tagente_datos - WHERE id_agente_modulo = $id_agent_module - AND utimestamp > (UNIX_TIMESTAMP(NOW()) - $interval) - ORDER BY utimestamp DESC"); - } - - - - foreach my $data_timestamp (@data) { - print $data_timestamp->{'utimestamp'}; - print $csv_separator; - print $data_timestamp->{'datos'}; - print "\n"; + if (defined $use_alias and $use_alias eq 'use_alias') { + @id_agents = get_agent_ids_from_alias($dbh,$agent_name); + + my $agent_id; + + foreach my $id (@id_agents) { + $agent_id = $id->{'id_agente'}; # se hace para cada agente + exist_check($agent_id, 'agent name', $agent_name); + + my $module_id = get_agent_module_id($dbh, $module_name, $agent_id); # se hace para ada agente + if ($module_id == -1) { + next; + } + + my $id_agent_module = get_agent_module_id ($dbh, $module_name, $agent_id); # 6 + + my $module_type_id = get_db_value($dbh, + "SELECT id_tipo_modulo FROM tagente_modulo WHERE id_agente_modulo = ?", + $id_agent_module); # se hace para cada agente + + my $module_type = get_db_value($dbh, + "SELECT nombre FROM ttipo_modulo WHERE id_tipo = ?", + $module_type_id); # se hace para cada agente + + my @data = NULL; + if ($module_type eq "log4x") { + @data = get_db_rows ($dbh, "SELECT utimestamp, datos + FROM tagente_datos_log4x + WHERE id_agente_modulo = $id_agent_module + AND utimestamp > (UNIX_TIMESTAMP(NOW()) - $interval) + ORDER BY utimestamp DESC"); + } + elsif ($module_type =~ m/_string/) { + @data = get_db_rows ($dbh, "SELECT utimestamp, datos + FROM tagente_datos_string + WHERE id_agente_modulo = $id_agent_module + AND utimestamp > (UNIX_TIMESTAMP(NOW()) - $interval) + ORDER BY utimestamp DESC"); + } + else { + @data = get_db_rows ($dbh, "SELECT utimestamp, datos + FROM tagente_datos + WHERE id_agente_modulo = $id_agent_module + AND utimestamp > (UNIX_TIMESTAMP(NOW()) - $interval) + ORDER BY utimestamp DESC"); + } + + foreach my $data_timestamp (@data) { + print $data_timestamp->{'utimestamp'}; + print $csv_separator; + print $data_timestamp->{'datos'}; + print "\n"; + } + } + + } else { + my $agent_id = get_agent_id($dbh,$agent_name); # se hace para cada agente + exist_check($agent_id, 'agent name', $agent_name); + + my $module_id = get_agent_module_id($dbh, $module_name, $agent_id); # se hace para ada agente + exist_check($module_id, 'module name', $module_name); + + my $id_agent_module = get_agent_module_id ($dbh, $module_name, $agent_id); # 6 + + my $module_type_id = get_db_value($dbh, + "SELECT id_tipo_modulo FROM tagente_modulo WHERE id_agente_modulo = ?", + $id_agent_module); # se hace para cada agente + + my $module_type = get_db_value($dbh, + "SELECT nombre FROM ttipo_modulo WHERE id_tipo = ?", + $module_type_id); # se hace para cada agente + + my @data = NULL; + if ($module_type eq "log4x") { + @data = get_db_rows ($dbh, "SELECT utimestamp, datos + FROM tagente_datos_log4x + WHERE id_agente_modulo = $id_agent_module + AND utimestamp > (UNIX_TIMESTAMP(NOW()) - $interval) + ORDER BY utimestamp DESC"); + } + elsif ($module_type =~ m/_string/) { + @data = get_db_rows ($dbh, "SELECT utimestamp, datos + FROM tagente_datos_string + WHERE id_agente_modulo = $id_agent_module + AND utimestamp > (UNIX_TIMESTAMP(NOW()) - $interval) + ORDER BY utimestamp DESC"); + } + else { + @data = get_db_rows ($dbh, "SELECT utimestamp, datos + FROM tagente_datos + WHERE id_agente_modulo = $id_agent_module + AND utimestamp > (UNIX_TIMESTAMP(NOW()) - $interval) + ORDER BY utimestamp DESC"); + } + + foreach my $data_timestamp (@data) { + print $data_timestamp->{'utimestamp'}; + print $csv_separator; + print $data_timestamp->{'datos'}; + print "\n"; + } } + exit; } @@ -6023,7 +7157,7 @@ sub pandora_manage_main ($$$) { cli_create_agent(); } elsif ($param eq '--delete_agent') { - param_check($ltotal, 1); + param_check($ltotal, 2, 1); cli_delete_agent(); } elsif ($param eq '--create_data_module') { @@ -6031,7 +7165,7 @@ sub pandora_manage_main ($$$) { cli_create_data_module(0); } elsif ($param eq '--create_web_module') { - param_check($ltotal, 38, 35); + param_check($ltotal, 39, 36); cli_create_web_module(0); } @@ -6048,19 +7182,19 @@ sub pandora_manage_main ($$$) { cli_module_group_synch(); } elsif ($param eq '--create_network_module') { - param_check($ltotal, 32, 20); + param_check($ltotal, 33, 21); cli_create_network_module(0); } elsif ($param eq '--create_snmp_module') { - param_check($ltotal, 40, 28); + param_check($ltotal, 41, 29); cli_create_snmp_module(0); } elsif ($param eq '--create_plugin_module') { - param_check($ltotal, 34, 19); + param_check($ltotal, 35, 20); cli_create_plugin_module(0); } elsif ($param eq '--delete_module') { - param_check($ltotal, 2); + param_check($ltotal, 3, 1); cli_delete_module(); } elsif ($param eq '--delete_not_policy_modules') { @@ -6068,23 +7202,23 @@ sub pandora_manage_main ($$$) { cli_delete_not_policy_modules(); } elsif ($param eq '--create_template_module') { - param_check($ltotal, 3); + param_check($ltotal, 4, 1); cli_create_template_module(); } elsif ($param eq '--delete_template_module') { - param_check($ltotal, 3); + param_check($ltotal, 4, 1); cli_delete_template_module(); } elsif ($param eq '--create_template_action') { - param_check($ltotal, 6, 2); + param_check($ltotal, 7, 3); cli_create_template_action(); } elsif ($param eq '--delete_template_action') { - param_check($ltotal, 4); + param_check($ltotal,5, 1); cli_delete_template_action(); } elsif ($param eq '--data_module') { - param_check($ltotal, 6, 1); + param_check($ltotal, 7, 2); cli_data_module(); } elsif ($param eq '--create_user') { @@ -6108,11 +7242,11 @@ sub pandora_manage_main ($$$) { cli_delete_profile(); } elsif ($param eq '--create_event') { - param_check($ltotal, 18, 15); + param_check($ltotal, 19, 16); cli_create_event(); } elsif ($param eq '--validate_event') { - param_check($ltotal, 7, 6); + param_check($ltotal, 8, 7); cli_validate_event(); } elsif ($param eq '--validate_event_id') { @@ -6132,7 +7266,7 @@ sub pandora_manage_main ($$$) { cli_create_incident(); } elsif ($param eq '--delete_data') { - param_check($ltotal, 3, 1); + param_check($ltotal, 4, 2); cli_delete_data($ltotal); } elsif ($param eq '--apply_policy') { @@ -6156,7 +7290,7 @@ sub pandora_manage_main ($$$) { cli_update_group(); } elsif ($param eq '--add_agent_to_policy') { - param_check($ltotal, 2); + param_check($ltotal, 3, 1); cli_policy_add_agent(); } elsif ($param eq '--remove_agent_from_policy') { @@ -6180,7 +7314,7 @@ sub pandora_manage_main ($$$) { cli_user_add_profile(); } elsif ($param eq '--get_module_data') { - param_check($ltotal, 4, 1); + param_check($ltotal, 5, 2); cli_module_get_data(); } elsif ($param eq '--add_collection_to_policy') { @@ -6196,7 +7330,7 @@ sub pandora_manage_main ($$$) { cli_create_policy(); } elsif ($param eq '--create_policy_data_module') { - param_check($ltotal, 28, 20); + param_check($ltotal, 29, 21); cli_create_data_module(1); } elsif ($param eq '--create_policy_web_module') { @@ -6244,7 +7378,7 @@ sub pandora_manage_main ($$$) { cli_alert_template_update(); } elsif ($param eq '--update_module') { - param_check($ltotal, 4); + param_check($ltotal, 6, 2); cli_module_update(); } elsif ($param eq '--exec_from_file') { @@ -6270,11 +7404,11 @@ sub pandora_manage_main ($$$) { cli_get_module_id(); } elsif ($param eq '--get_agent_group') { - param_check($ltotal, 1); + param_check($ltotal, 2, 1); cli_get_agent_group(); } elsif ($param eq '--get_agent_group_id') { - param_check($ltotal, 1); + param_check($ltotal, 2, 1); cli_get_agent_group_id(); } elsif ($param eq '--get_agents_module_current_data') { @@ -6282,7 +7416,7 @@ sub pandora_manage_main ($$$) { cli_get_agents_module_current_data(); } elsif ($param eq '--get_agent_modules') { - param_check($ltotal, 1); + param_check($ltotal, 2, 1); cli_get_agent_modules(); } elsif ($param eq '--get_policy_modules') { @@ -6290,23 +7424,23 @@ sub pandora_manage_main ($$$) { cli_get_policy_modules(); } elsif ($param eq '--get_policies') { - param_check($ltotal, 1, 1); + param_check($ltotal, 2, 2); cli_get_policies(); } elsif ($param eq '--get_agents') { - param_check($ltotal, 6, 6); + param_check($ltotal, 7, 7); cli_get_agents(); } elsif ($param eq '--delete_conf_file') { - param_check($ltotal, 1); + param_check($ltotal, 2, 1); cli_delete_conf_file(); } elsif ($param eq '--clean_conf_file') { - param_check($ltotal, 1, 1); + param_check($ltotal, 2, 1); cli_clean_conf_file(); } elsif ($param eq '--update_agent') { - param_check($ltotal, 3); + param_check($ltotal, 4, 1); cli_agent_update(); } elsif ($param eq '--get_bad_conf_files') { @@ -6314,7 +7448,7 @@ sub pandora_manage_main ($$$) { cli_get_bad_conf_files(); } elsif ($param eq '--create_network_module_from_component') { - param_check($ltotal, 2); + param_check($ltotal, 3, 1); cli_create_network_module_from_component(); } elsif ($param eq '--create_network_component') { @@ -6366,7 +7500,7 @@ sub pandora_manage_main ($$$) { cli_delete_special_day(); } elsif ($param eq '--create_data_module_from_local_component') { - param_check($ltotal, 2); + param_check($ltotal, 3, 1); cli_create_data_module_from_local_component(); } elsif ($param eq '--create_local_component') { @@ -6414,7 +7548,7 @@ sub pandora_manage_main ($$$) { cli_set_delete_planned_downtime(); } elsif ($param eq '--locate_agent') { - param_check($ltotal, 1); + param_check($ltotal, 2, 1); cli_locate_agent(); } elsif ($param eq '--create_visual_console') { @@ -6638,22 +7772,53 @@ sub cli_add_collection_to_policy () { ############################################################################## sub cli_create_data_module_from_local_component() { - my ($agent_name, $component_name) = @ARGV[2..3]; - - my $agent_id = get_agent_id($dbh,$agent_name); - exist_check($agent_id,'agent',$agent_name); + my ($agent_name, $component_name, $use_alias) = @ARGV[2..4]; + + my @id_agents; + + if (defined $use_alias and $use_alias eq 'use_alias') { + @id_agents = get_agent_ids_from_alias($dbh,$agent_name); + + my $agent_id; + + foreach my $id (@id_agents) { + $agent_id = $id->{'id_agente'}; + exist_check($agent_id,'agent',$agent_name); + + my $lc_id = pandora_get_local_component_id($dbh, $component_name); + exist_check($lc_id,'local component',$component_name); + + my $module_exists = get_agent_module_id($dbh, $component_name, $agent_id); + if ($module_exists ne -1) { + next; + } + + # Get local component data + my $component = get_db_single_row ($dbh, 'SELECT * FROM tlocal_component WHERE id = ?', $lc_id); + + print_log "[INFO] Creating module from local component '$component_name'\n\n"; + + #~ pandora_create_module_from_local_component ($conf, $component, $agent_id, $dbh); + enterprise_hook('pandora_create_module_from_local_component',[$conf, $component, $agent_id, $dbh]); + } + } else { + my $agent_id = get_agent_id($dbh,$agent_name); + exist_check($agent_id,'agent',$agent_name); + + my $lc_id = pandora_get_local_component_id($dbh, $component_name); + exist_check($lc_id,'local component',$component_name); - my $lc_id = pandora_get_local_component_id($dbh, $component_name); - exist_check($lc_id,'local component',$component_name); - - my $module_exists = get_agent_module_id($dbh, $component_name, $agent_id); - non_exist_check($module_exists, 'module name', $component_name); - - # Get local component data - my $component = get_db_single_row ($dbh, 'SELECT * FROM tlocal_component WHERE id = ?', $lc_id); - - #~ pandora_create_module_from_local_component ($conf, $component, $agent_id, $dbh); - enterprise_hook('pandora_create_module_from_local_component',[$conf, $component, $agent_id, $dbh]); + my $module_exists = get_agent_module_id($dbh, $component_name, $agent_id); + non_exist_check($module_exists, 'module name', $component_name); + + # Get local component data + my $component = get_db_single_row ($dbh, 'SELECT * FROM tlocal_component WHERE id = ?', $lc_id); + + print_log "[INFO] Creating module from local component '$component_name'\n\n"; + + #~ pandora_create_module_from_local_component ($conf, $component, $agent_id, $dbh); + enterprise_hook('pandora_create_module_from_local_component',[$conf, $component, $agent_id, $dbh]); + } } ############################################################################## # Create policy data module from local component. diff --git a/pandora_server/util/pandora_smpp.pl b/pandora_server/util/pandora_smpp.pl index af85d496f5..720d0e9589 100755 --- a/pandora_server/util/pandora_smpp.pl +++ b/pandora_server/util/pandora_smpp.pl @@ -19,7 +19,7 @@ Usage: $0 -server <smsc_server:port> -user <user_id> -password <user_password> -source <source_number> -destination <destination_numbers> -message <short_message> [OPTIONS] -- <destination_numbers> Comma separated list of destination numbers (+123456789,+234567891,...) +- <destination_numbers> Comma separated list of destination numbers (123456789,234567891,...) OPTIONS: @@ -45,7 +45,7 @@ OPTIONS: Example: -$0 -server 192.168.1.50:2775 -user myuser -password mypassword -source +123456789 -destination +234567891 -message "Content of SMS message" +$0 -server 192.168.1.50:2775 -user myuser -password mypassword -source 123456789 -destination 234567891 -message "Content of SMS message" EO_H @@ -85,7 +85,7 @@ if (!$config->{'message'}){ my ($smsc_server, $smsc_port) = split /:/, $config->{'server'}; -my @destination_numbers = $config->{'destination'}; +my @destination_numbers = split /,/, $config->{'destination'}; if (!$smsc_port){ $smsc_port = 2775;