diff --git a/pandora_agents/pc/AIX/pandora_agent.conf b/pandora_agents/pc/AIX/pandora_agent.conf index dcfa365e6b..520eaff838 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.726, AIX version +# Version 7.0NG.727, 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 f7d23ab200..c81ad7428b 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.726, FreeBSD Version +# Version 7.0NG.727, 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 532fbe65e4..50fc5ba4be 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.726, HP-UX Version +# Version 7.0NG.727, 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 8fd5498d51..82830cf957 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.726, GNU/Linux +# Version 7.0NG.727, 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 5bea10d1fa..ea633488e4 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.726, GNU/Linux +# Version 7.0NG.727, 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 d30b3459ac..c8a2153376 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.726, Solaris Version +# Version 7.0NG.727, 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 ed451d9de0..6a01d22b4b 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.726 +# Version 7.0NG.727 # 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 7f7e1d96f9..27cbee7dfb 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.726, AIX version +# Version 7.0NG.727, 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 8fc6f4e1eb..6eaf0415c2 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.726 +# Version 7.0NG.727 # 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 0e80d51dd9..906269e8bb 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.726, HPUX Version +# Version 7.0NG.727, HPUX Version # General Parameters # ================== diff --git a/pandora_agents/shellscript/linux/pandora_agent.conf b/pandora_agents/shellscript/linux/pandora_agent.conf index 5dd411ecd3..b2cdc0e920 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.726 +# Version 7.0NG.727 # 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 e5dd6122af..82363fdb43 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.726 +# Version 7.0NG.727 # 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 2eee374d68..2b4f58566b 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.726 +# Version 7.0NG.727 # 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 138448fd17..a1c4130f17 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.726, Solaris version +# Version 7.0NG.727, Solaris version # General Parameters # ================== diff --git a/pandora_agents/unix/AIX/pandora_agent.conf b/pandora_agents/unix/AIX/pandora_agent.conf index ce926a7cac..5f755ae4af 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.726, AIX version +# Version 7.0NG.727, 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 b74e8c1560..9a4a63356f 100644 --- a/pandora_agents/unix/DEBIAN/control +++ b/pandora_agents/unix/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-agent-unix -Version: 7.0NG.726-180904 +Version: 7.0NG.727-180918 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 43ea3a400c..090702f0ff 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.726-180904" +pandora_version="7.0NG.727-180918" 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 6e58735751..bfe673cf6c 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.726, GNU/Linux +# Version 7.0NG.727, 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 af429aa2b7..d829dfe933 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.726, FreeBSD Version +# Version 7.0NG.727, 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 6d4e113c16..29dc961d62 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.726, HP-UX Version +# Version 7.0NG.727, 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 4b86143f9a..c97d6b489f 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.726, GNU/Linux +# Version 7.0NG.727, 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 b15043bc67..e493e71850 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.726, GNU/Linux +# Version 7.0NG.727, 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 e26488592f..6954f557e0 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.726, NetBSD Version +# Version 7.0NG.727, 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 5764320b0a..8fe67c12d0 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.726, Solaris Version +# Version 7.0NG.727, 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 44678d3fbd..492b7bbd3f 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.726'; -use constant AGENT_BUILD => '180904'; +use constant AGENT_VERSION => '7.0NG.727'; +use constant AGENT_BUILD => '180918'; # 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 365c4932c2..20926174de 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.726 -%define release 180904 +%define version 7.0NG.727 +%define release 180918 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 397a11f66b..0f4f2e2d45 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.726 -%define release 180904 +%define version 7.0NG.727 +%define release 180918 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 3dd4fb013a..f52e708fa6 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.726" -PI_BUILD="180904" +PI_VERSION="7.0NG.727" +PI_BUILD="180918" 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 4e9edf8157..e8caadc9c3 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.726 +# Version 7.0NG.727 # 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 e2740e3c84..3f33fbca69 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.726} +{Pandora FMS Windows Agent v7.0NG.727} ApplicationID {17E3D2CF-CA02-406B-8A80-9D31C17BD08F} @@ -186,7 +186,7 @@ UpgradeApplicationID {} Version -{180904} +{180918} ViewReadme {Yes} diff --git a/pandora_agents/win32/modules/pandora_data.cc b/pandora_agents/win32/modules/pandora_data.cc index 6b9390f3f7..be891414ba 100644 --- a/pandora_agents/win32/modules/pandora_data.cc +++ b/pandora_agents/win32/modules/pandora_data.cc @@ -32,7 +32,7 @@ using namespace Pandora; */ Pandora_Data::Pandora_Data (string value) { this->value = value; - GetSystemTime (&(this->timestamp)); + GetLocalTime (&(this->timestamp)); this->data_origin = pandora_data_unknown_source; } @@ -68,7 +68,7 @@ Pandora_Data::Pandora_Data (string value, SYSTEMTIME *system_time) { */ Pandora_Data::Pandora_Data (string value, string data_origin) { this->value = value; - GetSystemTime (&(this->timestamp)); + GetLocalTime (&(this->timestamp)); this->data_origin = data_origin; } @@ -99,7 +99,7 @@ Pandora_Data::Pandora_Data (string value, SYSTEMTIME *system_time, string data_o */ Pandora_Data::Pandora_Data () { this->value = ""; - GetSystemTime (&(this->timestamp)); + GetLocalTime (&(this->timestamp)); this->data_origin = ""; } diff --git a/pandora_agents/win32/pandora.cc b/pandora_agents/win32/pandora.cc index f031c55ee5..88e358508a 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.726(Build 180904)") +#define PANDORA_VERSION ("7.0NG.727(Build 180918)") string pandora_path; string pandora_dir; diff --git a/pandora_agents/win32/versioninfo.rc b/pandora_agents/win32/versioninfo.rc index 2d5195b07b..fa2574b879 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.726(Build 180904))" + VALUE "ProductVersion", "(7.0NG.727(Build 180918))" VALUE "FileVersion", "1.0.0.0" END END diff --git a/pandora_console/DEBIAN/control b/pandora_console/DEBIAN/control index 697348b76a..e4f98f7884 100644 --- a/pandora_console/DEBIAN/control +++ b/pandora_console/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-console -Version: 7.0NG.726-180904 +Version: 7.0NG.727-180918 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 2a4605f103..d8d13c3037 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.726-180904" +pandora_version="7.0NG.727-180918" package_pear=0 package_pandora=1 diff --git a/pandora_console/attachment/.htaccess b/pandora_console/attachment/.htaccess new file mode 100644 index 0000000000..815f1e1776 --- /dev/null +++ b/pandora_console/attachment/.htaccess @@ -0,0 +1,2 @@ +Order deny,allow +Deny from All diff --git a/pandora_console/extras/mr/20.sql b/pandora_console/extras/mr/20.sql index 33ac240498..a36a832839 100644 --- a/pandora_console/extras/mr/20.sql +++ b/pandora_console/extras/mr/20.sql @@ -18,4 +18,32 @@ ALTER TABLE `tlayout_template_data` ADD COLUMN `linked_layout_status_as_service_ ALTER TABLE `tlayout_template_data` ADD COLUMN `linked_layout_status_as_service_critical` FLOAT(20, 3) NOT NULL default 0; ALTER TABLE `tlayout_template_data` ADD COLUMN `linked_layout_node_id` INT(10) NOT NULL default 0; +-- ----------------------------------------------------- +-- Add column in table `treport` +-- ----------------------------------------------------- + +ALTER TABLE `treport` ADD COLUMN `hidden` tinyint(1) NOT NULL DEFAULT 0; + +ALTER TABLE `trecon_task` ADD COLUMN `snmp_version` varchar(5) NOT NULL default '1'; +ALTER TABLE `trecon_task` ADD COLUMN `snmp_auth_user` varchar(255) NOT NULL default ''; +ALTER TABLE `trecon_task` ADD COLUMN `snmp_auth_pass` varchar(255) NOT NULL default ''; +ALTER TABLE `trecon_task` ADD COLUMN `snmp_auth_method` varchar(25) NOT NULL default ''; +ALTER TABLE `trecon_task` ADD COLUMN `snmp_privacy_method` varchar(25) NOT NULL default ''; +ALTER TABLE `trecon_task` ADD COLUMN `snmp_privacy_pass` varchar(255) NOT NULL default ''; +ALTER TABLE `trecon_task` ADD COLUMN `snmp_security_level` varchar(25) NOT NULL default ''; +ALTER TABLE `tpolicy_modules_inventory` ADD COLUMN `custom_fields` MEDIUMBLOB NOT NULL; + +CREATE TABLE IF NOT EXISTS `tlog_graph_models` ( + `id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, + `title` TEXT NOT NULL, + `regexp` TEXT NOT NULL, + `fields` TEXT NOT NULL, + `average` tinyint(1) NOT NULL default '0', + PRIMARY KEY(`id`) +) ENGINE = InnoDB DEFAULT CHARSET=utf8; + +INSERT INTO tlog_graph_models VALUES (1, 'Apache log model', + '^.*?\s+.*".*?\s(\/.*?)\?.*1.1"\s+(.*?)\s+(.*?)\s+', + 'pagina, html_err_code, _tiempo_', 1); + COMMIT; \ No newline at end of file diff --git a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql index 88478f5c9b..a0d724faab 100644 --- a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql +++ b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql @@ -1768,3 +1768,33 @@ CREATE TABLE IF NOT EXISTS `tlayout_template_data` ( PRIMARY KEY(`id`), FOREIGN KEY (`id_layout_template`) REFERENCES tlayout_template(`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE = InnoDB DEFAULT CHARSET=utf8; + +-- --------------------------------------------------------------------- +-- Table `tlog_graph_models` +-- --------------------------------------------------------------------- +CREATE TABLE IF NOT EXISTS `tlog_graph_models` ( + `id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, + `title` TEXT NOT NULL, + `regexp` TEXT NOT NULL, + `fields` TEXT NOT NULL, + `average` tinyint(1) NOT NULL default '0', + PRIMARY KEY(`id`) +) ENGINE = InnoDB DEFAULT CHARSET=utf8; + +INSERT INTO tlog_graph_models VALUES (1, 'Apache log model', + '^.*?\s+.*".*?\s(\/.*?)\?.*1.1"\s+(.*?)\s+(.*?)\s+', + 'pagina, html_err_code, _tiempo_', 1); + +-- ----------------------------------------------------- +-- Add column in table `treport` +-- ----------------------------------------------------- + +ALTER TABLE `treport` ADD COLUMN `hidden` tinyint(1) NOT NULL DEFAULT 0; + +ALTER TABLE `trecon_task` ADD COLUMN `snmp_version` varchar(5) NOT NULL default '1'; +ALTER TABLE `trecon_task` ADD COLUMN `snmp_auth_user` varchar(255) NOT NULL default ''; +ALTER TABLE `trecon_task` ADD COLUMN `snmp_auth_pass` varchar(255) NOT NULL default ''; +ALTER TABLE `trecon_task` ADD COLUMN `snmp_auth_method` varchar(25) NOT NULL default ''; +ALTER TABLE `trecon_task` ADD COLUMN `snmp_privacy_method` varchar(25) NOT NULL default ''; +ALTER TABLE `trecon_task` ADD COLUMN `snmp_privacy_pass` varchar(255) NOT NULL default ''; +ALTER TABLE `trecon_task` ADD COLUMN `snmp_security_level` varchar(25) NOT NULL default ''; diff --git a/pandora_console/godmode/groups/group_list.php b/pandora_console/godmode/groups/group_list.php index 9201e50c18..0efe11ad31 100644 --- a/pandora_console/godmode/groups/group_list.php +++ b/pandora_console/godmode/groups/group_list.php @@ -32,39 +32,38 @@ if (is_ajax ()) { require ("general/noaccess.php"); return; } - + $get_group_json = (bool) get_parameter ('get_group_json'); $get_group_agents = (bool) get_parameter ('get_group_agents'); $get_is_disabled = (bool) get_parameter ('get_is_disabled'); - + if ($get_group_json) { $id_group = (int) get_parameter ('id_group'); - + if ($id_group == 0) { $group = array('id_grupo' => 0, - 'nombre' => 'All', + 'nombre' => 'All', 'icon' => 'world', 'parent' => 0, 'disabled' => 0, 'custom_id' => null); - echo json_encode ($group); return; } - + if (! check_acl ($config['id_user'], $id_group, "AR")) { db_pandora_audit("ACL Violation", "Trying to access Alert Management"); echo json_encode (false); return; } - + $group = db_get_row ('tgrupo', 'id_grupo', $id_group); - + echo json_encode ($group); return; } - + if ($get_group_agents) { ob_clean(); $id_group = (int) get_parameter ('id_group'); @@ -86,33 +85,33 @@ if (is_ajax ()) { $serialized = (bool)get_parameter('serialized', false); $serialized_separator = (string)get_parameter('serialized_separator', "|"); $force_serialized = (bool)get_parameter('force_serialized', false); - + if (! check_acl ($config['id_user'], $id_group, "AR")) { db_pandora_audit("ACL Violation", "Trying to access Alert Management"); echo json_encode (false); return; } - + if ( https_is_running() ) { header('Content-type: application/json'); } - + if ($filter_agents_json != '') { $filter['id_agente'] = json_decode(io_safe_output($filter_agents_json), true); } - + if ($all_agents) { $filter['all_agents'] = true; } else { $filter['disabled'] = $disabled; } - + if ($search != '') { $filter['string'] = $search; } - + if ($status_agents != AGENT_STATUS_ALL) { $filter['status'] = $status_agents; } @@ -120,10 +119,8 @@ if (is_ajax ()) { # Juanma (22/05/2014) Fix: If remove void agents setted $_sql_post = ' 1=1 '; if ($show_void_agents == 0) { - $_sql_post .= ' AND id_agente IN (SELECT a.id_agente FROM tagente a, tagente_modulo b WHERE a.id_agente=b.id_agente AND b.delete_pending=0) AND \'1\''; $filter[$_sql_post] = '1'; - } $id_groups_get_agents = $id_group; @@ -192,7 +189,7 @@ if (is_ajax ()) { $agents = $all_agents_array; } - + echo json_encode ($agents); return; } @@ -208,36 +205,68 @@ if (is_ajax ()) { echo json_encode($return); return; } - return; } -if (! check_acl($config['id_user'], 0, "AW")) { +if (! check_acl($config['id_user'], 0, "PM")) { db_pandora_audit("ACL Violation", "Trying to access Group Management"); require ("general/noaccess.php"); return; } +$sec = defined('METACONSOLE') ? 'advanced' : 'gagente'; +$url_tree = "index.php?sec=$sec&sec2=godmode/groups/group_list&tab=tree"; +$url_groups = "index.php?sec=$sec&sec2=godmode/groups/group_list&tab=groups"; +$buttons['tree'] = array( + 'active' => false, + 'text' => "" . + html_print_image( + "images/gm_massive_operations.png", + true, + array ( + "title" => __('Tree Group view') + ) + ) . "" +); + +$buttons['groups'] = array( + 'active' => false, + 'text' => "" . + html_print_image( + "images/group.png", + true, + array( + "title" => __('Group view') + ) + ) . "" +); + +$tab = (string)get_parameter('tab', 'groups'); + +// Marks correct tab +switch ($tab) { + case 'tree': + $buttons['tree']['active'] = true; + break; + case 'groups': + default: + $buttons['groups']['active'] = true; + break; +} + // Header if (defined('METACONSOLE')) { - agents_meta_print_header(); - $sec = 'advanced'; - echo '
'; echo __("Edit or delete groups can cause problems with synchronization"); echo '
'; - +} else { + ui_print_page_header ( + __("Groups defined in %s", get_product_name()), + "images/group.png", false, "", true, $buttons + ); } -else { - - ui_print_page_header (__("Groups defined in %s", get_product_name()), - "images/group.png", false, "", true, ""); - $sec = 'gagente'; - -} - $create_group = (bool) get_parameter ('create_group'); $update_group = (bool) get_parameter ('update_group'); @@ -258,7 +287,7 @@ if (($create_group) && (check_acl($config['id_user'], 0, "PM"))) { $other = (string) get_parameter ('other'); $check = db_get_value('nombre', 'tgrupo', 'nombre', $name); $propagate = (bool) get_parameter('propagate'); - + /*Check if name field is empty*/ if ($name != "") { if (!$check) { @@ -275,7 +304,7 @@ if (($create_group) && (check_acl($config['id_user'], 0, "PM"))) { 'other' => $other, 'password' => io_safe_input($group_pass) ); - + $result = db_process_sql_insert('tgrupo', $values); if ($result) { ui_print_success_message(__('Group successfully created')); @@ -309,7 +338,7 @@ if ($update_group) { $description = (string) get_parameter ('description'); $contact = (string) get_parameter ('contact'); $other = (string) get_parameter ('other'); - + /*Check if name field is empty*/ if ( $name != "") { switch ($config["dbtype"]) { @@ -332,7 +361,7 @@ if ($update_group) { else { $result = false; } - + if ($result !== false) { ui_print_success_message(__('Group successfully updated')); } @@ -344,19 +373,19 @@ if ($update_group) { /* Delete group */ if (($delete_group) && (check_acl($config['id_user'], 0, "PM"))) { $id_group = (int) get_parameter ('id_group'); - + $usedGroup = groups_check_used($id_group); - + if (!$usedGroup['return']) { $group = db_get_row_filter('tgrupo', array('id_grupo' => $id_group)); - + db_process_sql_update('tgrupo', array('parent' => $group['parent']), array('parent' => $id_group)); - + $result = db_process_sql_delete('tgroup_stat', array('id_group' => $id_group)); - + $result = db_process_sql_delete('tgrupo', array('id_grupo' => $id_group)); } @@ -364,136 +393,272 @@ if (($delete_group) && (check_acl($config['id_user'], 0, "PM"))) { ui_print_error_message( sprintf(__('The group is not empty. It is use in %s.'), implode(', ', $usedGroup['tables']))); } - + if ($result && (!$usedGroup['return'])) { ui_print_success_message(__('Group successfully deleted')); - } + } else { ui_print_error_message(__('There was a problem deleting group')); } } -db_clean_cache(); -if ($create_group || $delete_group || $update_group) { - $groups = users_get_groups ($config['id_user'], "AR", true, true, null, 'id_grupo', false); - $groups = groups_get_groups_tree_recursive($groups); -} else { - $groups = users_get_groups_tree ($config['id_user'], "AR", true); +if($tab == 'tree'){ + echo html_print_image('images/spinner.gif', true, + array('class' => "loading_tree", + 'style' => 'display: none;')); + echo "
"; + } - -$table = new StdClass(); -$table->width = '100%'; - -$all_parents = array(); -$groups_count = 0; -$sons = array(); - -$groups_count = count($groups); - -foreach ($groups as $k => $g) { - if ($g['parent'] != 0) { - $all_parents[$g['parent']] = $g['parent']; - } -} -krsort($all_parents); -foreach ($all_parents as $parent) { - foreach ($groups as $k => $g) { - if ($g['parent'] == $parent) { - $sons[$g['parent']][] = $g; - unset($groups[$k]); - } - } -} - - -if (!empty($groups)) { - $table->class = "databox data"; - $table->head = array (); - $table->head[0] = __('Name'); - $table->head[1] = __('ID'); - $table->head[2] = __('Icon'); - $table->head[3] = __('Alerts'); - $table->head[4] = __('Description'); - $table->head[5] = __('Actions'); - $table->align = array (); - $table->align[2] = 'left'; - $table->align[5] = 'left'; - $table->size[4] = '30%'; - $table->size[5] = '10%'; - $table->data = array (); - +else{ + $acl=''; + $search_name = ''; $offset = (int)get_parameter('offset', 0); - $limit = $offset + $config['block_size']; - - - - $pagination = ui_pagination($groups_count, - false, 0, $config['block_size'], true, 'offset', false); - - $n = -1; - $iterator = 0; - $branch_classes = array(); - foreach ($groups as $group) { - $n++; - - // Only print the page range - if ($n < $offset || $n >= $limit) { - continue; - } - - $symbolBranchs = ' symbol_branch_' . $group['parent']; - - $has_children = isset($sons[$group['id_grupo']]); - $data = groups_get_group_to_list($group, $groups_count, $symbolBranchs, $has_children); - array_push ($table->data, $data); - $table->rowstyle[$iterator] = ''; - if ($group['id_grupo'] != 0) { - $branch_classes[$group['id_grupo']] = ' branch_0'; - $table->rowclass[$iterator] = 'parent_' . $group['parent'] . ' branch_0'; - } - $iterator++; - - groups_print_group_sons($group, $sons, $branch_classes, - $groups_count, $table, $iterator, $symbolBranchs); + $search = (string)get_parameter('search', ''); + $block_size = $config['block_size']; + + if(!empty($search)){ + $search_name = "AND t.nombre LIKE '%$search%'"; + } + + if (!users_can_manage_group_all("AR")){ + $user_groups_acl = users_get_groups(false, "AR"); + $groups_acl = implode(",", $user_groups_ACL); + if(empty($groups_acl)) return ui_print_info_message ( array('no_close'=>true, 'message'=> __('There are no defined groups') ) ); + + $acl = "AND t.id_grupo IN ($groups_acl)"; + } + + $form = "
"; + $form .= ""; + $form .= ""; + $form .= "
" . __('Search') . ' '; + $form .= html_print_input_text ("search", $search, '', 100, 100, true); + $form .= ""; + $form .= ""; + $form .= "
"; + $form .= "
"; + + echo $form; + + $groups_sql = + "SELECT t.*, + p.nombre AS parent_name, + IF(t.parent=p.id_grupo, 1, 0) AS has_child + FROM tgrupo t + LEFT JOIN tgrupo p + ON t.parent=p.id_grupo + WHERE 1=1 + $acl + $search_name + ORDER BY nombre + LIMIT $offset, $block_size + "; + + $groups = db_get_all_rows_sql($groups_sql); + + if (!empty($groups)) { + //Count all groups for pagination only saw user and filters + $groups_sql_count = "SELECT count(*) + FROM tgrupo t + WHERE 1=1 + $acl + $search_name + "; + $groups_count = db_get_value_sql($groups_sql_count); + + $table = new StdClass(); + $table->width = '100%'; + $table->class = "databox data"; + $table->head = array (); + $table->head[0] = __('ID'); + $table->head[1] = __('Name'); + $table->head[2] = __('Icon'); + $table->head[3] = __('Alerts'); + $table->head[4] = __('Parent'); + $table->head[5] = __('Description'); + $table->head[6] = __('Actions'); + $table->align = array (); + $table->align[0] = 'left'; + $table->align[2] = 'left'; + $table->align[6] = 'left'; + $table->size[0] = '3%'; + $table->size[5] = '30%'; + $table->size[6] = '5%'; + $table->data = array (); + + foreach ($groups as $key => $group) { + $url = "index.php?sec=gagente&sec2=godmode/groups/configure_group&id_group=".$group['id_grupo']; + $url_delete = "index.php?sec=gagente&sec2=godmode/groups/group_list&delete_group=1&id_group=" . $group['id_grupo']; + $table->data[$key][0] = $group['id_grupo']; + $table->data[$key][1] = "" . $group['nombre'] . ""; + $table->data[$key][2] = html_print_image( + "images/groups_small/" . $group['icon'] . ".png", + true, + array( + "style" => '', + "class" => "bot", + "alt" => $group['nombre'], + "title" => $group['nombre'], + false, false, false, true + ) + ); + + //reporting_get_group_stats + $table->data[$key][3] = $group['disabled'] ? __('Disabled') : __('Enabled'); + $table->data[$key][4] = $group['parent_name']; + $table->data[$key][5] = $group['description']; + $table->data[$key][6] = "" . + html_print_image( + "images/config.png", + true, + array( + "alt" => __('Edit'), + "title" => __('Edit'), + "border" => '0' + ) + ) . + ""; + + $confirm_message = __('Are you sure?'); + if ($group['has_child']) { + $confirm_message = __('The child groups will be updated to use the parent id of the deleted group') . ". " . $confirm_message; + } + + $table->data[$key][6] .= '  ' . + '' . + html_print_image( + "images/cross.png", + true, + array( + "alt" => __('Delete'), + "title" => __('Delete'), + "border" => '0' + ) + ) . + ""; + + } + + echo ui_pagination( + $groups_count, false, + $offset, $block_size, + true, 'offset', false + ); + html_print_table ($table); + echo ui_pagination( + $groups_count, false, + $offset, $block_size, + true, 'offset', true + ); + } + else { + ui_print_info_message ( array('no_close'=>true, 'message'=> __('There are no defined groups') ) ); } - - echo $pagination; - - html_print_table ($table); - - echo $pagination; -} -else { - ui_print_info_message ( array('no_close'=>true, 'message'=> __('There are no defined groups') ) ); } if (check_acl($config['id_user'], 0, "PM")) { - echo '
'; - echo '
'; - html_print_submit_button (__('Create group'), 'crt', false, 'class="sub next"'); - echo '
'; + echo ''; + echo '
'; + html_print_submit_button (__('Create group'), 'crt', false, 'class="sub next"'); + echo '
'; echo '
'; } +ui_require_javascript_file("TreeController", "include/javascript/tree/"); + enterprise_hook('close_meta_frame'); +$tab = "group_edition"; ?> + + + + + + diff --git a/pandora_console/godmode/servers/manage_recontask.php b/pandora_console/godmode/servers/manage_recontask.php index 2b9527704d..1d5dc69c89 100644 --- a/pandora_console/godmode/servers/manage_recontask.php +++ b/pandora_console/godmode/servers/manage_recontask.php @@ -97,7 +97,15 @@ if ((isset ($_GET["update"])) OR ((isset ($_GET["create"])))) { $field2 = get_parameter ("_field2_", ""); $field3 = get_parameter ("_field3_", ""); $field4 = get_parameter ("_field4_", ""); - + $snmp_version = get_parameter_post ("snmp_version"); + $snmp3_auth_user = get_parameter_post ("snmp_auth_user"); + $snmp3_auth_pass = get_parameter_post ("snmp_auth_pass"); + $snmp3_privacy_method = get_parameter_post ("snmp_privacy_method"); + $snmp3_privacy_pass = get_parameter_post ("snmp_privacy_pass"); + $snmp3_auth_method = get_parameter_post ("snmp_auth_method"); + $snmp3_security_level = get_parameter_post ("snmp_security_level"); + + if ($mode == "network_sweep") $id_recon_script = 0; else @@ -154,8 +162,30 @@ if (isset($_GET["update"])) { 'macros' => $macros, 'alias_as_name' => $alias_as_name, 'snmp_enabled' => $snmp_enabled, - 'vlan_enabled' => $vlan_enabled + 'vlan_enabled' => $vlan_enabled, + 'snmp_version' => $snmp_version ); + + $values_v3 = array( + 'snmp_auth_user' => $snmp3_auth_user, + 'snmp_auth_pass' => $snmp3_auth_pass, + 'snmp_privacy_method' => $snmp3_privacy_method, + 'snmp_privacy_pass' => $snmp3_privacy_pass, + 'snmp_auth_method' => $snmp3_auth_method, + 'snmp_security_level' => $snmp3_security_level + ); + if($values['snmp_version'] == '1' || $values['snmp_version'] == '2' || $values['snmp_version'] == '2c'){ + $values_v3 = array( + 'snmp_auth_user' => '', + 'snmp_auth_pass' => '', + 'snmp_privacy_method' => '', + 'snmp_privacy_pass' => '', + 'snmp_auth_method' => '', + 'snmp_security_level' => '' + ); + } + + $values = array_merge($values, $values_v3); $where = array('id_rt' => $id); @@ -217,13 +247,37 @@ if (isset($_GET["create"])) { 'macros' => $macros, 'alias_as_name' => $alias_as_name, 'snmp_enabled' => $snmp_enabled, - 'vlan_enabled' => $vlan_enabled + 'vlan_enabled' => $vlan_enabled, + 'snmp_version' => $snmp_version ); + $values_v3 = array( + 'snmp_auth_user' => $snmp3_auth_user, + 'snmp_auth_pass' => $snmp3_auth_pass, + 'snmp_privacy_method' => $snmp3_privacy_method, + 'snmp_privacy_pass' => $snmp3_privacy_pass, + 'snmp_auth_method' => $snmp3_auth_method, + 'snmp_security_level' => $snmp3_security_level + ); + if($values['snmp_version'] == '1' || $values['snmp_version'] == '2' || $values['snmp_version'] == '2c'){ + $values_v3 = array( + 'snmp_auth_user' => '', + 'snmp_auth_pass' => '', + 'snmp_privacy_method' => '', + 'snmp_privacy_pass' => '', + 'snmp_auth_method' => '', + 'snmp_security_level' => '' + ); + } + if ($values['snmp_version'] == '3'){ + $values['vlan_enabled'] = 0; + } + + $values = array_merge($values, $values_v3); + $name = io_safe_output($name); $name = trim($name, ' '); $name = io_safe_input($name); - $reason = ""; if ($name != "") { @@ -293,7 +347,7 @@ else { $color=1; if ($result !== false) { $table = new StdClass(); - $table->head = array (__('Name'), __('Network'), __('Mode'), __('Group'), __('Incident'), __('OS'), __('Interval'), __('Ports'), __('Action')); + $table->head = array (__('Name'), __('Network'), __('Mode'), __('Group'), __('SNMP Version'), __('Incident'), __('OS'), __('Interval'), __('Ports'), __('Action')); $table->align = array ("left","left","left","left","left","left","left","left"); $table->width = "100%"; $table->cellpadding = 4; @@ -336,48 +390,64 @@ if ($result !== false) { $data[3] = "-"; } + //SNMP VERSION + if ($row["snmp_version"] == '1'){ + $data[4] = "v. 1"; + } + elseif($row["snmp_version"] == '2'){ + $data[4] = "v. 2"; + } + elseif($row["snmp_version"] == '2c'){ + $data[4] = "v. 2c"; + } + elseif($row["snmp_version"] == '3'){ + $data[4] = "v. 3"; + } + + + // INCIDENT - $data[4] = (($row["create_incident"] == 1) ? __('Yes') : __('No')); + $data[5] = (($row["create_incident"] == 1) ? __('Yes') : __('No')); // OS if ($row["id_recon_script"] == 0) { - $data[5] =(($row["id_os"] > 0) ? ui_print_os_icon ($row["id_os"], false, true) : __('Any')); + $data[6] =(($row["id_os"] > 0) ? ui_print_os_icon ($row["id_os"], false, true) : __('Any')); } else { - $data[5] = "-"; + $data[6] = "-"; } // INTERVAL if ($row["interval_sweep"]==0) - $data[6] = __("Manual"); + $data[7] = __("Manual"); else - $data[6] =human_time_description_raw($row["interval_sweep"]); + $data[7] =human_time_description_raw($row["interval_sweep"]); // PORTS if ($row["id_recon_script"] == 0) { - $data[7] = substr($row["recon_ports"],0,15); + $data[8] = substr($row["recon_ports"],0,15); } else { - $data[7] = "-"; + $data[8] = "-"; } // ACTION $task_group = $row["id_group"]; if (in_array($task_group, $user_groups_w)){ - $data[8] = '' . html_print_image("images/eye.png", true) . ''; - $data[8] .= '' . html_print_image("images/cross.png", true, array("border" => '0')) . ''; + $data[9] = '' . html_print_image("images/eye.png", true) . ''; + $data[9] .= '' . html_print_image("images/cross.png", true, array("border" => '0')) . ''; if($mode_name != 'IPAM Recon'){ - $data[8] .= '' .html_print_image("images/config.png", true) . ''; + $data[9] .= '' .html_print_image("images/config.png", true) . ''; } else { $sql_ipam = 'select id from tipam_network where id_recon_task =' . $row["id_rt"]; $id_recon_ipam = db_get_sql($sql_ipam); - $data[8] .= '' . html_print_image("images/config.png", true) . ''; + $data[9] .= '' . html_print_image("images/config.png", true) . ''; } if($row["disabled"] == 0) { - $data[8] .= '' .html_print_image("images/lightbulb.png", true) . ''; + $data[9] .= '' .html_print_image("images/lightbulb.png", true) . ''; } else { - $data[8] .= '' .html_print_image("images/lightbulb_off.png", true) . ''; + $data[9] .= '' .html_print_image("images/lightbulb_off.png", true) . ''; } } diff --git a/pandora_console/godmode/servers/manage_recontask_form.php b/pandora_console/godmode/servers/manage_recontask_form.php index d33e0ee19c..f5865d1470 100644 --- a/pandora_console/godmode/servers/manage_recontask_form.php +++ b/pandora_console/godmode/servers/manage_recontask_form.php @@ -108,6 +108,13 @@ if (isset($_GET["update"]) || (isset($_GET["upd"]))) { $id_os = $row["id_os"]; $recon_ports = $row["recon_ports"]; $snmp_community = $row["snmp_community"]; + $snmp_version = $row["snmp_version"]; + $snmp3_auth_user = $row["snmp_auth_user"]; + $snmp3_auth_pass = $row["snmp_auth_pass"]; + $snmp3_privacy_method = $row["snmp_privacy_method"]; + $snmp3_privacy_pass = $row["snmp_privacy_pass"]; + $snmp3_auth_method = $row["snmp_auth_method"]; + $snmp3_security_level = $row["snmp_security_level"]; $id_recon_script = $row["id_recon_script"]; $field1 = $row["field1"]; $field2 = $row["field2"]; @@ -156,6 +163,13 @@ elseif (isset($_GET["create"]) || isset($_GET["crt"])) { $id_group = 0; $create_incident = 1; $snmp_community = "public"; + $snmp3_auth_user = ''; + $snmp3_auth_pass = ''; + $snmp_version = 1; + $snmp3_privacy_method = ''; + $snmp3_privacy_pass = ''; + $snmp3_auth_method = ''; + $snmp3_security_level = ''; $id_network_profile = 0; $id_os = -1; // Any $recon_ports = ""; // Any @@ -212,6 +226,13 @@ $table->rowclass[20] = "network_sweep"; $table->rowclass[21] = "network_sweep"; $table->rowclass[22] = "network_sweep"; $table->rowclass[23] = "network_sweep"; +$table->rowclass[24] = "network_sweep"; +$table->rowclass[25] = "network_sweep recon_v3"; +$table->rowclass[26] = "network_sweep recon_v3"; +$table->rowclass[27] = "network_sweep recon_v3"; +$table->rowclass[28] = "network_sweep recon_v3"; +$table->rowclass[29] = "network_sweep recon_v3"; +$table->rowclass[30] = "network_sweep recon_v3"; $table->rowclass[6] = "recon_script"; $table->rowclass[13] = "recon_script"; @@ -327,6 +348,34 @@ $table->data[12][0] = "".__('SNMP Default community'); $table->data[12][0] .= ui_print_help_tip (__('You can specify several values, separated by commas, for example: public,mysecret,1234'), true); $table->data[12][1] = html_print_input_text ('snmp_community', $snmp_community, '', 35, 0, true); +//SNMP version + +$snmp_versions['1'] = 'v. 1'; +$snmp_versions['2'] = 'v. 2'; +$snmp_versions['2c'] = 'v. 2c'; +$snmp_versions['3'] = 'v. 3'; +$table->data[24][0] ="". _('SNMP version'); +$table->data[24][1] = html_print_select ($snmp_versions, 'snmp_version', $snmp_version, '', '', 0, true); + +$table->data[25][0] ="".__('Auth user'); +$table->data[25][1] = html_print_input_text ('snmp_auth_user', $snmp3_auth_user, '', 15, 60, true, '', + false, '', ''); +$table->data[26][0] ="". __('Auth password') . ui_print_help_tip(__("The pass length must be eight character minimum."), true); +$table->data[26][1] = html_print_input_password ('snmp_auth_pass', $snmp3_auth_pass, '', 15, 60, true, '', + false, ''); +$table->data[26][1] .= html_print_input_hidden_extended('active_snmp_v3', 0, 'active_snmp_v3_mmen', true); + +$table->data[27][0] ="". __('Privacy method'); +$table->data[27][1] = html_print_select(array('DES' => __('DES'), 'AES' => __('AES')), 'snmp_privacy_method', $snmp3_privacy_method, '', '', '', true, false, false, '', ''); +$table->data[28][0] ="". __('Privacy pass') . ui_print_help_tip(__("The pass length must be eight character minimum."), true); +$table->data[28][1] = html_print_input_password ('snmp_privacy_pass', $snmp3_privacy_pass, '', 15, 60, true, '', + false, ''); +$table->data[29][0] ="". __('Auth method'); +$table->data[29][1] = html_print_select(array('MD5' => __('MD5'), 'SHA' => __('SHA')), 'snmp_auth_method', $snmp3_auth_method, '', '', '', true, false, false, '', ''); +$table->data[30][0] ="". __('Security level'); +$table->data[30][1] = html_print_select(array('noAuthNoPriv' => __('Not auth and not privacy method'), + 'authNoPriv' => __('Auth and not privacy method'), 'authPriv' => __('Auth and privacy method')), 'snmp_security_level', $snmp3_security_level, '', '', '', true, false, false, '', ''); + // Explanation $explanation = db_get_value('description', 'trecon_script', 'id_recon_script', $id_recon_script); @@ -461,9 +510,24 @@ $('select#id_recon_script').change(function() { get_explanation_recon_script($(this).val()); }); +$('select#snmp_version').change(function () { + if (this.value == "3") { + $(".recon_v3").show(); + $("input[name=active_snmp_v3]").val(1); + $("input[name=snmp_community]").attr("disabled", true); + $("input[name=vlan_enabled]").removeAttr("checked"); + $("input[name=vlan_enabled]").attr("disabled", true); + } + else { + $(".recon_v3").hide(); + $("input[name=active_snmp_v3]").val(0); + $("input[name=snmp_community]").removeAttr('disabled'); + $("input[name=vlan_enabled]").removeAttr('disabled'); + } +}); + $('select#mode').change(function() { var type = $(this).val(); - if (type == 'recon_script') { $(".recon_script").show(); $(".network_sweep").hide(); @@ -474,6 +538,7 @@ $('select#mode').change(function() { $(".recon_script").hide(); $(".network_sweep").show(); $('.macro_field').remove(); + $('select#snmp_version').trigger('change'); } }).change(); @@ -543,5 +608,5 @@ function get_explanation_recon_script (id) { }); taskManager.addTask(xhr); } -/* ]]> */ + diff --git a/pandora_console/godmode/servers/plugin.php b/pandora_console/godmode/servers/plugin.php index 93ed8841f7..e592fd570d 100644 --- a/pandora_console/godmode/servers/plugin.php +++ b/pandora_console/godmode/servers/plugin.php @@ -833,7 +833,7 @@ ui_require_javascript_file('pandora_modules'); i++; } - $('#command_preview').html(command+' '+parameters); + $('#command_preview').html(_.escape(command) + ' ' + _.escape(parameters)); } function show_locked_dialog(id_plugin, plugin_name) { diff --git a/pandora_console/godmode/setup/setup_visuals.php b/pandora_console/godmode/setup/setup_visuals.php index 88b2392e14..057c220001 100755 --- a/pandora_console/godmode/setup/setup_visuals.php +++ b/pandora_console/godmode/setup/setup_visuals.php @@ -709,6 +709,10 @@ $table_chars->data[$row][1] = html_print_select($options_zoom_graphs, 'zoom_grap $row++; $table_chars->data[$row][0] = __('Graph image height'); +$table_chars->data[$row][0] .= ui_print_help_tip( + __('This is the height in pixels of the module graph or custom graph in the reports (both: HTML and PDF)'), + true +); $table_chars->data[$row][1] = html_print_input_text ('graph_image_height', $config['graph_image_height'], '', 20, 20, true); $row++; diff --git a/pandora_console/godmode/users/configure_user.php b/pandora_console/godmode/users/configure_user.php index 080b90a120..f5b7fdc5bc 100644 --- a/pandora_console/godmode/users/configure_user.php +++ b/pandora_console/godmode/users/configure_user.php @@ -152,7 +152,8 @@ if ($create_user) { ui_print_error_message (__('The current authentication scheme doesn\'t support creating users on %s', get_product_name())); return; } - + if (html_print_csrf_error()) return; + $values = array (); $values['id_user'] = (string) get_parameter ('id_user'); $values['fullname'] = (string) get_parameter ('fullname'); @@ -279,6 +280,8 @@ if ($create_user) { } if ($update_user) { + if (html_print_csrf_error()) return; + $values = array (); $values['id_user'] = (string) get_parameter ('id_user'); $values['fullname'] = (string) get_parameter ('fullname'); @@ -705,14 +708,12 @@ echo '
'; html_print_table ($table); echo '
'; -if ($new_user) { - if ($config['admin_can_add_user']) { +if ($config['admin_can_add_user']) { + html_print_csrf_hidden(); + if ($new_user) { html_print_input_hidden ('create_user', 1); html_print_submit_button (__('Create'), 'crtbutton', false, 'class="sub wand"'); - } -} -else { - if ($config['user_can_update_info']) { + } else { html_print_input_hidden ('update_user', 1); html_print_submit_button (__('Update'), 'uptbutton', false, 'class="sub upd"'); } diff --git a/pandora_console/include/ajax/tree.ajax.php b/pandora_console/include/ajax/tree.ajax.php index 6e7a612171..07435d9109 100644 --- a/pandora_console/include/ajax/tree.ajax.php +++ b/pandora_console/include/ajax/tree.ajax.php @@ -38,7 +38,14 @@ if (is_ajax ()) { } require_once($config['homedir'] . "/include/class/Tree.class.php"); - enterprise_include_once("include/class/Tree.class.php"); + require_once($config['homedir'] . "/include/class/TreeOS.class.php"); + require_once($config['homedir'] . "/include/class/TreeModuleGroup.class.php"); + require_once($config['homedir'] . "/include/class/TreeModule.class.php"); + require_once($config['homedir'] . "/include/class/TreeTag.class.php"); + require_once($config['homedir'] . "/include/class/TreeGroup.class.php"); + require_once($config['homedir'] . "/include/class/TreeGroupEdition.class.php"); + enterprise_include_once("include/class/TreePolicies.class.php"); + enterprise_include_once("include/class/TreeGroupMeta.class.php"); require_once($config['homedir'] . "/include/functions_reporting.php"); require_once($config['homedir'] . "/include/functions_os.php"); @@ -67,17 +74,45 @@ if (is_ajax ()) { 'tagID' => 0, ); $filter = get_parameter('filter', $default_filters); - + $agent_a = check_acl ($config['id_user'], 0, "AR"); $agent_w = check_acl ($config['id_user'], 0, "AW"); $access = ($agent_a == true) ? 'AR' : (($agent_w == true) ? 'AW' : 'AR'); - if (class_exists('TreeEnterprise')) { - $tree = new TreeEnterprise($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access); + $switch_type = !empty($rootType) ? $rootType : $type; + switch ($switch_type) { + case 'os': + $tree = new TreeOS($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access); + break; + case 'module_group': + $tree = new TreeModuleGroup($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access); + break; + case 'module': + $tree = new TreeModule($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access); + break; + case 'tag': + $tree = new TreeTag($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access); + break; + case 'group': + if(is_metaconsole()){ + if (!class_exists('TreeGroupMeta')) break; + $tree = new TreeGroupMeta($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access); + } + else{ + $tree = new TreeGroup($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access); + } + break; + case 'policies': + if (!class_exists('TreePolicies')) break; + $tree = new TreePolicies($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access); + break; + case 'group_edition': + $tree = new TreeGroupEdition($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access); + break; + default: + // FIXME. No error handler + return; } - else { - $tree = new Tree($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access); - } - + $tree->setFilter($filter); ob_clean(); echo json_encode(array('success' => 1, 'tree' => $tree->getArray())); diff --git a/pandora_console/include/class/Tree.class.php b/pandora_console/include/class/Tree.class.php index 497b12aa0d..e18cfb599e 100644 --- a/pandora_console/include/class/Tree.class.php +++ b/pandora_console/include/class/Tree.class.php @@ -19,17 +19,31 @@ class Tree { protected $id = -1; protected $rootID = -1; protected $serverID = false; + protected $serverName = ''; protected $tree = array(); protected $filter = array(); protected $childrenMethod = "on_demand"; protected $userGroupsACL; protected $userGroups; + protected $userGroupsArray; - protected $strictACL = false; protected $acltags = false; protected $access = false; + protected $L1fieldName = ''; + protected $L1fieldNameSql = ''; + protected $L1extraFields = array(); + protected $L1inner = ''; + protected $L1innerInside = ''; + protected $L1orderByFinal = ''; + + protected $L2condition = ''; + protected $L2conditionInside = ''; + protected $L2inner = ''; + + const TV_DEFAULT_AGENT_STATUS = -1; + public function __construct($type, $rootType = '', $id = -1, $rootID = -1, $serverID = false, $childrenMethod = "on_demand", $access = 'AR') { $this->type = $type; @@ -37,12 +51,16 @@ class Tree { $this->id = $id; $this->rootID = !empty($rootID) ? $rootID : $id; $this->serverID = $serverID; + if (is_metaconsole()) { + $this->serverName = metaconsole_get_server_by_id($serverID); + } $this->childrenMethod = $childrenMethod; $this->access = $access; $userGroupsACL = users_get_groups(false, $this->access); $this->userGroupsACL = empty($userGroupsACL) ? false : $userGroupsACL; $this->userGroups = $this->userGroupsACL; + $this->userGroupsArray = array_keys($this->userGroups); global $config; include_once($config['homedir']."/include/functions_servers.php"); @@ -52,21 +70,46 @@ class Tree { if (is_metaconsole()) enterprise_include_once("meta/include/functions_ui_meta.php"); - $this->strictACL = (bool) db_get_value("strict_acl", "tusuario", "id_user", $config['id_user']); - $this->acltags = tags_get_user_groups_and_tags($config['id_user'], $this->access); } public function setFilter($filter) { + // There is not module filter in metaconsole. + if (is_metaconsole()) { + $filter['searchModule'] = ""; + $filter['statusModule'] = self::TV_DEFAULT_AGENT_STATUS; + } $this->filter = $filter; } - protected function getAgentStatusFilter ($status = -1) { - if ($status == -1) + protected function getEmptyModuleFilterStatus() { + return ( + !isset($this->filter['statusModule']) || + $this->filter['statusModule'] == -1 + ); + } + + protected function getModuleSearchFilter() { + if (empty($this->filter['searchModule'])) { + return ""; + } + return " AND tam.nombre LIKE '%".$this->filter['searchModule']."%' "; + } + + protected function getAgentSearchFilter() { + if (empty($this->filter['searchAgent'])) return ""; + return " AND LOWER(ta.alias) LIKE LOWER('%".$this->filter['searchAgent']."%')"; + } + + + protected function getAgentStatusFilter ($status = self::TV_DEFAULT_AGENT_STATUS) { + if ($status == self::TV_DEFAULT_AGENT_STATUS) $status = $this->filter['statusAgent']; $agent_status_filter = ""; switch ($status) { + case AGENT_STATUS_ALL: + break; case AGENT_STATUS_NOT_INIT: $agent_status_filter = " AND (ta.total_count = 0 OR ta.total_count = ta.notinit_count) "; @@ -94,1302 +137,149 @@ class Tree { return $agent_status_filter; } - protected function getAgentCounterColumnsSql ($agent_table) { - // Add the agent counters to the columns - - if ($this->filter['statusAgent'] == -1) { - // Critical - $agent_critical_filter = $this->getAgentStatusFilter(AGENT_STATUS_CRITICAL); - $agents_critical_count = "($agent_table - $agent_critical_filter) AS total_critical_count"; - // Warning - $agent_warning_filter = $this->getAgentStatusFilter(AGENT_STATUS_WARNING); - $agents_warning_count = "($agent_table - $agent_warning_filter) AS total_warning_count"; - // Unknown - $agent_unknown_filter = $this->getAgentStatusFilter(AGENT_STATUS_UNKNOWN); - $agents_unknown_count = "($agent_table - $agent_unknown_filter) AS total_unknown_count"; - // Normal - $agent_normal_filter = $this->getAgentStatusFilter(AGENT_STATUS_NORMAL); - $agents_normal_count = "($agent_table - $agent_normal_filter) AS total_normal_count"; - // Not init - - if($this->filter['show_not_init_agents']){ - $agent_not_init_filter = $this->getAgentStatusFilter(AGENT_STATUS_NOT_INIT); - $agents_not_init_count = "($agent_table - $agent_not_init_filter) AS total_not_init_count"; - } - else{ - $agent_not_init_filter = 0; - $agents_not_init_count = 0; - } - - // Alerts fired - $agents_fired_count = "($agent_table - AND ta.fired_count > 0) AS total_fired_count"; - // Total - $agents_total_count = "($agent_table) AS total_count"; - - $columns = "$agents_critical_count, $agents_warning_count, " - . "$agents_unknown_count, $agents_normal_count, $agents_not_init_count, " - . "$agents_fired_count, $agents_total_count"; - } - else { - // Alerts fired - $agents_fired_count = "($agent_table - AND ta.fired_count > 0) AS total_fired_count"; - // Total - $agents_total_count = "($agent_table) AS total_count"; - - switch ($this->filter['statusAgent']) { - case AGENT_STATUS_NOT_INIT: - // Not init - $agent_not_init_filter = $this->getAgentStatusFilter(AGENT_STATUS_NOT_INIT); - $agents_not_init_count = "($agent_table - $agent_not_init_filter) AS total_not_init_count"; - $columns = "$agents_not_init_count, $agents_fired_count, $agents_total_count"; - break; - case AGENT_STATUS_CRITICAL: - // Critical - $agent_critical_filter = $this->getAgentStatusFilter(AGENT_STATUS_CRITICAL); - $agents_critical_count = "($agent_table - $agent_critical_filter) AS total_critical_count"; - $columns = "$agents_critical_count, $agents_fired_count, $agents_total_count"; - break; - case AGENT_STATUS_WARNING: - // Warning - $agent_warning_filter = $this->getAgentStatusFilter(AGENT_STATUS_WARNING); - $agents_warning_count = "($agent_table - $agent_warning_filter) AS total_warning_count"; - $columns = "$agents_warning_count, $agents_fired_count, $agents_total_count"; - break; - case AGENT_STATUS_UNKNOWN: - // Unknown - $agent_unknown_filter = $this->getAgentStatusFilter(AGENT_STATUS_UNKNOWN); - $agents_unknown_count = "($agent_table - $agent_unknown_filter) AS total_unknown_count"; - $columns = "$agents_unknown_count, $agents_fired_count, $agents_total_count"; - break; - case AGENT_STATUS_NORMAL: - // Normal - $agent_normal_filter = $this->getAgentStatusFilter(AGENT_STATUS_NORMAL); - $agents_normal_count = "($agent_table - $agent_normal_filter) AS total_normal_count"; - $columns = "$agents_normal_count, $agents_fired_count, $agents_total_count"; - break; - } - } - - return $columns; + protected function getFirstLevelFields() { + $fields = array ( + "g AS " . $this->L1fieldName, + "SUM(x_critical) AS total_critical_count", + "SUM(x_warning) AS total_warning_count", + "SUM(x_normal) AS total_normal_count", + "SUM(x_unknown) AS total_unknown_count", + "SUM(x_not_init) AS total_not_init_count", + "SUM(x_alerts) AS total_alerts_count", + "SUM(x_total) AS total_count" + ); + return implode(",", array_merge($fields, $this->L1extraFields)); } - protected function getAgentCountersSql ($agent_table) { - global $config; - - $columns = $this->getAgentCounterColumnsSql($agent_table); - - switch ($config["dbtype"]) { - case "mysql": - case "postgresql": - $columns = "SELECT $columns FROM dual LIMIT 1"; - break; - case "oracle": - $columns = "SELECT $columns FROM dual WHERE rownum <= 1"; - break; - } - - return $columns; + protected function getFirstLevelFieldsInside() { + return array( + 'warning' => array( + 'header' => "0 AS x_critical, SUM(total) AS x_warning, 0 AS x_normal, 0 AS x_unknown, 0 AS x_not_init, 0 AS x_alerts, 0 AS x_total, g", + 'condition' => "AND " . agents_get_status_clause(AGENT_STATUS_WARNING, $this->filter['show_not_init_agents']) + ), + 'critical' => array( + 'header' => "SUM(total) AS x_critical, 0 AS x_warning, 0 AS x_normal, 0 AS x_unknown, 0 AS x_not_init, 0 AS x_alerts, 0 AS x_total, g", + 'condition' => "AND " . agents_get_status_clause(AGENT_STATUS_CRITICAL, $this->filter['show_not_init_agents']) + ), + 'normal' => array( + 'header' => "0 AS x_critical, 0 AS x_warning, SUM(total) AS x_normal, 0 AS x_unknown, 0 AS x_not_init, 0 AS x_alerts, 0 AS x_total, g", + 'condition' => "AND " . agents_get_status_clause(AGENT_STATUS_NORMAL, $this->filter['show_not_init_agents']) + ), + 'unknown' => array( + 'header' => "0 AS x_critical, 0 AS x_warning, 0 AS x_normal, SUM(total) AS x_unknown, 0 AS x_not_init, 0 AS x_alerts, 0 AS x_total, g", + 'condition' => "AND " . agents_get_status_clause(AGENT_STATUS_UNKNOWN, $this->filter['show_not_init_agents']) + ), + 'not_init' => array( + 'header' => "0 AS x_critical, 0 AS x_warning, 0 AS x_normal, 0 AS x_unknown, SUM(total) AS x_not_init, 0 AS x_alerts, 0 AS x_total, g", + 'condition' => "AND " . agents_get_status_clause(AGENT_STATUS_NOT_INIT, $this->filter['show_not_init_agents']) + ), + 'alerts' => array( + 'header' => "0 AS x_critical, 0 AS x_warning, 0 AS x_normal, 0 AS x_unknown, 0 AS x_not_init, SUM(total) AS x_alerts, 0 AS x_total, g", + 'condition' => "AND ta.fired_count > 0" + ), + 'total' => array( + 'header' => "0 AS x_critical, 0 AS x_warning, 0 AS x_normal, 0 AS x_unknown, 0 AS x_not_init, 0 AS x_alerts, SUM(total) AS x_total, g", + 'condition' => "AND " . agents_get_status_clause(AGENT_STATUS_ALL, $this->filter['show_not_init_agents']) + ) + ); } - protected function getSql ($item_for_count = false) { - // Get the type - if (empty($this->type)) - $type = 'none'; - else - $type = $this->type; - - // Get the root type - if (empty($this->rootType)) - $rootType = 'none'; - else - $rootType = $this->rootType; - - // Get the parent - $parent = $this->id; - - // Get the root id - $rootID = $this->rootID; - - // Get the server id - $serverID = $this->serverID; - - // Agent name filter - $agent_search_filter = ""; - if (!empty($this->filter['searchAgent'])) { - $agent_search_filter = " AND LOWER(ta.alias) LIKE LOWER('%".$this->filter['searchAgent']."%')"; - } - - //Search hirearchy - $search_hirearchy = false; - if($this->filter['searchHirearchy']){ - $search_hirearchy = true; - } - - // Agent status filter - $agent_status_filter = ""; - if (isset($this->filter['statusAgent']) - && $this->filter['statusAgent'] != AGENT_STATUS_ALL - && !$this->strictACL) { - $agent_status_filter = $this->getAgentStatusFilter($this->filter['statusAgent']); - } - - // Agents join - $agents_join = ""; - if (!empty($agent_search_filter) || !empty($agent_status_filter)) { - $agents_join = "INNER JOIN tagente ta - ON ta.disabled = 0 - AND tam.id_agente = ta.id_agente - $agent_search_filter - $agent_status_filter"; - } - - // Module name filter - $module_search_filter = ""; - if (!empty($this->filter['searchModule'])) { - $module_search_filter = " AND tam.nombre LIKE '%".$this->filter['searchModule']."%' "; - } - - // Module status filter - $module_status_filter = ""; - if (isset($this->filter['statusModule']) - && $this->filter['statusModule'] != -1) { - - switch ($this->filter['statusModule']) { - case AGENT_MODULE_STATUS_CRITICAL_ALERT: - case AGENT_MODULE_STATUS_CRITICAL_BAD: - $module_status_filter = " AND (tae.estado = ".AGENT_MODULE_STATUS_CRITICAL_ALERT." - OR tae.estado = ".AGENT_MODULE_STATUS_CRITICAL_BAD.") "; - break; - case AGENT_MODULE_STATUS_WARNING_ALERT: - case AGENT_MODULE_STATUS_WARNING: - $module_status_filter = " AND (tae.estado = ".AGENT_MODULE_STATUS_WARNING_ALERT." - OR tae.estado = ".AGENT_MODULE_STATUS_WARNING.") "; - break; - case AGENT_MODULE_STATUS_UNKNOWN: - $module_status_filter = " AND tae.estado = ".AGENT_MODULE_STATUS_UNKNOWN." "; - break; - case AGENT_MODULE_STATUS_NO_DATA: - case AGENT_MODULE_STATUS_NOT_INIT: - $module_status_filter = " AND (tae.estado = ".AGENT_MODULE_STATUS_NO_DATA." - OR tae.estado = ".AGENT_MODULE_STATUS_NOT_INIT.") "; - break; - case AGENT_MODULE_STATUS_NORMAL_ALERT: - case AGENT_MODULE_STATUS_NORMAL: - $module_status_filter = " AND (tae.estado = ".AGENT_MODULE_STATUS_NORMAL_ALERT." - OR tae.estado = ".AGENT_MODULE_STATUS_NORMAL.") "; - break; - } - } - - // Modules join - $modules_join = ""; - $module_status_join = ""; - if (!empty($module_search_filter) || !empty($module_status_filter) || !$this->filter['show_not_init_agents']) { - - if (!empty($module_status_filter) || !$this->filter['show_not_init_agents']) { - $module_status_join = "INNER JOIN tagente_estado tae - ON tam.id_agente_modulo IS NOT NULL - AND tam.id_agente_modulo = tae.id_agente_modulo - $module_status_filter"; - - if(!$this->filter['show_not_init_modules'] || ($this->filter['show_not_init_modules'] && !$this->filter['show_not_init_agents'])){ - if($type != 'agent' || ($type == 'agent' && !$this->filter['show_not_init_modules'] && !$this->filter['show_not_init_agents'])){ - $module_status_join .= ' AND tae.estado <> '.AGENT_MODULE_STATUS_NO_DATA.' AND tae.estado <> '.AGENT_MODULE_STATUS_NOT_INIT.' '; - } - } - } - - $modules_join = "INNER JOIN tagente_modulo tam - ON tam.disabled = 0 - AND ta.id_agente = tam.id_agente - $module_search_filter - $module_status_join"; - } - - if (empty($module_status_join)) { - if(!$this->filter['show_not_init_modules'] || !$this->filter['show_not_init_agents']){ - if($type == "agent"){ - $module_status_join = 'INNER JOIN tagente_estado tae - ON tam.id_agente_modulo = tae.id_agente_modulo '; - } - else{ - $module_status_join = 'LEFT JOIN tagente_estado tae - ON tam.id_agente_modulo = tae.id_agente_modulo '; - } - - $module_status_join .= ' AND 1=1 AND tae.estado <> '.AGENT_MODULE_STATUS_NO_DATA.' AND tae.estado <> '.AGENT_MODULE_STATUS_NOT_INIT.' '; - } - else{ - $module_status_join = 'LEFT JOIN tagente_estado tae - ON tam.id_agente_modulo = tae.id_agente_modulo '; - } - } - - $sql = false; - - switch ($rootType) { - case 'group': - // ACL Group - $user_groups_str = "-1"; - $group_filter = ""; - - if (empty($this->userGroups)) { - return; - } - - // Asking for a specific group. - if ($item_for_count !== false) { - if (!isset($this->userGroups[$item_for_count])) { - return; - } - } - // Asking for all groups. - else { - $user_groups_str = implode(",", array_keys($this->userGroups)); - $group_filter = "AND ( - ta.id_grupo IN ($user_groups_str) - OR tasg.id_group IN ($user_groups_str) - )"; - } - - if(!$search_hirearchy && (!empty($agent_search_filter) || !empty($module_search_filter))){ - - if(is_metaconsole()){ - $id_groups_agents = db_get_all_rows_sql( - " SELECT DISTINCT(ta.id_grupo) - FROM tmetaconsole_agent ta - LEFT JOIN tmetaconsole_agent_secondary_group tasg - ON ta.id_agente = tasg.id_agent - WHERE ta.disabled = 0 - $agent_search_filter" - ); - $id_secondary_groups_agents = db_get_all_rows_sql( - " SELECT DISTINCT(tasg.id_group) - FROM tmetaconsole_agent ta - LEFT JOIN tmetaconsole_agent_secondary_group tasg - ON ta.id_agente = tasg.id_agent - WHERE ta.disabled = 0 - $agent_search_filter" - ); - } - else{ - $id_groups_agents = db_get_all_rows_sql( - " SELECT DISTINCT(ta.id_grupo) - FROM 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 ta.disabled = 0 - $agent_search_filter - $module_search_filter" - ); - $id_secondary_groups_agents = db_get_all_rows_sql( - " SELECT DISTINCT(tasg.id_group) - FROM 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 ta.disabled = 0 - $agent_search_filter - $module_search_filter" - ); - } - - if($id_groups_agents != false){ - foreach ($id_groups_agents as $key => $value) { - $id_groups_agents_array[$value['id_grupo']] = $value['id_grupo']; - } - foreach ($id_secondary_groups_agents as $key => $value) { - $id_groups_agents_array[$value['id_group']] = $value['id_group']; - } - $user_groups_array = explode(",", $user_groups_str); - $user_groups_array = array_intersect($user_groups_array, $id_groups_agents_array); - $user_groups_str = implode("," , $user_groups_array); - } - else{ - $user_groups_str = false; - } - } - - switch ($type) { - // Get the agents of a group - case 'group': - if (empty($rootID) || $rootID == -1) { - if(!$search_hirearchy && (!empty($agent_search_filter) || !empty($module_search_filter))){ - $columns = 'tg.id_grupo AS id, tg.nombre AS name, tg.icon'; - } - else{ - $columns = 'tg.id_grupo AS id, tg.nombre AS name, tg.parent, tg.icon'; - } - - $order_fields = 'tg.nombre ASC, tg.id_grupo ASC'; - - if (! is_metaconsole()) { - // Groups SQL - if ($item_for_count === false) { - $sql = "SELECT $columns - FROM tgrupo tg - WHERE tg.id_grupo IN ($user_groups_str) - ORDER BY $order_fields"; - } - // Counters SQL - else { - $agent_table = "SELECT COUNT(DISTINCT(ta.id_agente)) - FROM tagente ta - LEFT JOIN tagent_secondary_group tasg - ON ta.id_agente=tasg.id_agent - LEFT JOIN tagente_modulo tam - ON tam.disabled = 0 - AND ta.id_agente = tam.id_agente - $module_search_filter - $module_status_join - WHERE ta.disabled = 0 - AND ( - ta.id_grupo = $item_for_count - OR tasg.id_group = $item_for_count - ) - $group_filter - $agent_search_filter - $agent_status_filter"; - $sql = $this->getAgentCountersSql($agent_table); - } - } - // Metaconsole - else { - // Groups SQL - if ($item_for_count === false) { - $sql = "SELECT $columns - FROM tgrupo tg - WHERE tg.id_grupo IN ($user_groups_str) - ORDER BY $order_fields"; - } - // Counters SQL - else { - $agent_table = "SELECT COUNT(DISTINCT(ta.id_agente)) - FROM tmetaconsole_agent ta - LEFT JOIN tmetaconsole_agent_secondary_group tasg - ON ta.id_agente = tasg.id_agent - WHERE ta.disabled = 0 - AND ( - ta.id_grupo = $item_for_count - OR tasg.id_group = $item_for_count - ) - $group_filter - $agent_search_filter - $agent_status_filter"; - $sql = $this->getAgentCountersSql($agent_table); - } - } - } - else { - if (! is_metaconsole()) { - $columns = 'ta.id_agente AS id, ta.nombre AS name, ta.alias, - ta.fired_count, ta.normal_count, ta.warning_count, - ta.critical_count, ta.unknown_count, ta.notinit_count, - ta.total_count, ta.quiet'; - $group_by_fields = 'ta.id_agente, ta.nombre, ta.alias, - ta.fired_count, ta.normal_count, ta.warning_count, - ta.critical_count, ta.unknown_count, ta.notinit_count, - ta.total_count, ta.quiet'; - $order_fields = 'ta.alias ASC, ta.id_agente ASC'; - - $sql = "SELECT $columns - FROM tagente ta - LEFT JOIN tagent_secondary_group tasg - ON tasg.id_agent = ta.id_agente - LEFT JOIN tagente_modulo tam - ON tam.disabled = 0 - AND ta.id_agente = tam.id_agente - $module_search_filter - $module_status_join - WHERE ta.disabled = 0 - AND ( - ta.id_grupo = $rootID - OR tasg.id_group = $rootID - ) - $group_filter - $agent_search_filter - $agent_status_filter - GROUP BY $group_by_fields - ORDER BY $order_fields"; - } - else { - $columns = 'ta.id_tagente AS id, ta.nombre AS name, ta.alias, - ta.fired_count, ta.normal_count, ta.warning_count, - ta.critical_count, ta.unknown_count, ta.notinit_count, - ta.total_count, ta.quiet, ta.id_tmetaconsole_setup AS server_id'; - $order_fields = 'ta.alias ASC, ta.id_tagente ASC'; - - $sql = "SELECT $columns - FROM tmetaconsole_agent ta - LEFT JOIN tmetaconsole_agent_secondary_group tasg - ON ta.id_agente = tasg.id_agent - WHERE ta.disabled = 0 - AND ( - ta.id_grupo = $rootID - OR tasg.id_group = $rootID - ) - $group_filter - $agent_search_filter - $agent_status_filter - GROUP BY ta.id_agente - ORDER BY $order_fields"; - } - } - break; - // Get the modules of an agent - case 'agent': - $columns = 'tam.id_agente_modulo AS id, - tam.parent_module_id AS parent, - tam.nombre AS name, tam.id_tipo_modulo, - tam.id_modulo, tae.estado, tae.datos'; - $order_fields = 'tam.nombre ASC, tam.id_agente_modulo ASC'; - - // Set for the common ACL only. The strict ACL case is different (groups and tags divided). - // The modules only have visibility in two cases: - // 1. The user has access to the group of its agent and this group hasn't tags. - // 2. The user has access to the group of its agent, this group has tags and the module - // has any of this tags. - $tag_join = ''; - if (!$this->strictACL) { - // $rootID it the agent group id in this case - if (!empty($this->acltags) && isset($this->acltags[$rootID])) { - $tags_str = $this->acltags[$rootID]; - - if (!empty($tags_str)) { - $tag_join = sprintf('INNER JOIN ttag_module ttm - ON tam.id_agente_modulo = ttm.id_agente_modulo - AND ttm.id_tag IN (%s)', $tags_str); - } - } - } - - $sql = "SELECT DISTINCT $columns - FROM tagente_modulo tam - $tag_join - $module_status_join - INNER JOIN tagente ta - ON ta.disabled = 0 - LEFT JOIN tagent_secondary_group tasg - ON ta.id_agente = tasg.id_agent - AND tam.id_agente = ta.id_agente - AND ta.id_grupo = $rootID - $group_filter - $agent_search_filter - $agent_status_filter - WHERE tam.disabled = 0 - AND tam.id_agente = $parent - $module_search_filter - ORDER BY $order_fields"; - break; - } - break; - case 'tag': - // ACL Group - $group_acl = ""; - if (!$this->strictACL) { - if (!empty($this->userGroups)) { - $user_groups_str = implode(",", array_keys($this->userGroups)); - $group_acl = " AND ta.id_grupo IN ($user_groups_str) "; - } - else { - $group_acl = "AND ta.id_grupo = -1"; - } - } - else { - if (!empty($this->acltags) && !empty($rootID) && $rootID != -1) { - $groups = array(); - foreach ($this->acltags as $group_id => $tags_str) { - if (!empty($tags_str)) { - $tags = explode(",", $tags_str); - - if (in_array($rootID, $tags)) { - $hierarchy_groups = groups_get_id_recursive($group_id); - $groups = array_merge($groups, $hierarchy_groups); - } - } - } - if (!empty($groups)) { - if (array_search(0, $groups) === false) { - $user_groups_str = implode(",", $groups); - $group_acl = " AND ta.id_grupo IN ($user_groups_str) "; - } - } - else { - $group_acl = "AND ta.id_grupo = -1"; - } - } - else { - $group_acl = "AND ta.id_grupo = -1"; - } - } - - switch ($type) { - // Get the agents of a tag - case 'tag': - if (empty($rootID) || $rootID == -1) { - if ($this->strictACL) - return false; - - // tagID filter. To access the view from tactical views f.e. - $tag_filter = ''; - if (!empty($this->filter['tagID'])) { - $tag_filter = "WHERE tt.id_tag = " . $this->filter['tagID']; - } - - $columns = 'tt.id_tag AS id, tt.name AS name'; - $group_by_fields = 'tt.id_tag, tt.name'; - $order_fields = 'tt.name ASC, tt.id_tag ASC'; - - // Tags SQL - if ($item_for_count === false) { - $sql = "SELECT $columns - FROM ttag tt - INNER JOIN ttag_module ttm - ON tt.id_tag = ttm.id_tag - INNER JOIN tagente_modulo tam - ON tam.disabled = 0 - AND ttm.id_agente_modulo = tam.id_agente_modulo - $module_search_filter - $module_status_join - INNER JOIN tagente ta - ON ta.disabled = 0 - AND tam.id_agente = ta.id_agente - $group_acl - $agent_search_filter - $agent_status_filter - $tag_filter - GROUP BY $group_by_fields - ORDER BY $order_fields"; - } - // Counters SQL - else { - $agent_table = "SELECT COUNT(DISTINCT(ta.id_agente)) - FROM tagente ta - INNER JOIN tagente_modulo tam - ON tam.disabled = 0 - AND ta.id_agente = tam.id_agente - $module_search_filter - $module_status_join - INNER JOIN ttag_module ttm - ON tam.id_agente_modulo = ttm.id_agente_modulo - AND ttm.id_tag = $item_for_count - WHERE ta.disabled = 0 - $group_acl - $agent_search_filter - $agent_status_filter"; - $sql = $this->getAgentCountersSql($agent_table); - } - } - else { - $columns = 'ta.id_agente AS id, ta.nombre AS name, ta.alias, - ta.fired_count, ta.normal_count, ta.warning_count, - ta.critical_count, ta.unknown_count, ta.notinit_count, - ta.total_count, ta.quiet'; - $group_by_fields = 'ta.id_agente, ta.nombre, ta.alias, - ta.fired_count, ta.normal_count, ta.warning_count, - ta.critical_count, ta.unknown_count, ta.notinit_count, - ta.total_count, ta.quiet'; - $order_fields = 'ta.alias ASC, ta.id_agente ASC'; - - $sql = "SELECT $columns - FROM tagente ta - INNER JOIN tagente_modulo tam - ON tam.disabled = 0 - AND ta.id_agente = tam.id_agente - $module_search_filter - $module_status_join - INNER JOIN ttag_module ttm - ON tam.id_agente_modulo = ttm.id_agente_modulo - AND ttm.id_tag = $rootID - WHERE ta.disabled = 0 - $group_acl - $agent_search_filter - $agent_status_filter - GROUP BY $group_by_fields - ORDER BY $order_fields"; - } - break; - // Get the modules of an agent - case 'agent': - $columns = 'tam.id_agente_modulo AS id, tam.nombre AS name, - tam.id_tipo_modulo, tam.id_modulo, tae.estado, tae.datos'; - $order_fields = 'tam.nombre ASC, tam.id_agente_modulo ASC'; - - // Set for the common ACL only. The strict ACL case is different (groups and tags divided). - // The modules only have visibility in two cases: - // 1. The user has access to the group of its agent and this group hasn't tags. - // 2. The user has access to the group of its agent, this group has tags and the module - // has any of this tags. - $tag_filter = ''; - if (!$this->strictACL) { - // $parent is the agent id - $group_id = (int) db_get_value('id_grupo', 'tagente', 'id_agente', $parent); - if (empty($group_id)) { - // ACL error, this will restrict (fuck) the module search - $tag_filter = 'AND 1=0'; - } - else if (!empty($this->acltags) && isset($this->acltags[$group_id])) { - $tags_str = $this->acltags[$group_id]; - - if (!empty($tags_str)) { - $tag_filter = sprintf('AND ttm.id_tag IN (%s)', $tags_str); - } - } - } - - $sql = "SELECT $columns - FROM tagente_modulo tam - INNER JOIN ttag_module ttm - ON tam.id_agente_modulo = ttm.id_agente_modulo - AND ttm.id_tag = $rootID - $tag_filter - $module_status_join - INNER JOIN tagente ta - ON ta.disabled = 0 - AND tam.id_agente = ta.id_agente - $group_acl - $agent_search_filter - $agent_status_filter - WHERE tam.disabled = 0 - AND tam.id_agente = $parent - $module_search_filter - ORDER BY $order_fields"; - break; - } - break; - case 'os': - // ACL Group - $group_acl = ""; - if (!empty($this->userGroups)) { - $user_groups_str = implode(",", array_keys($this->userGroups)); - $group_acl = " AND ta.id_grupo IN ($user_groups_str) "; - } - else { - $group_acl = "AND ta.id_grupo = -1"; - } - - switch ($type) { - // Get the agents of an os - case 'os': - if (empty($rootID) || $rootID == -1) { - $columns = 'tos.id_os AS id, tos.name AS name, tos.icon_name AS os_icon'; - $group_by_fields = 'tos.id_os, tos.name, tos.icon_name'; - $order_fields = 'tos.icon_name ASC, tos.id_os ASC'; - - // OS SQL - if ($item_for_count === false) { - $sql = "SELECT $columns - FROM tconfig_os tos - INNER JOIN tagente ta - ON ta.disabled = 0 - AND ta.id_os = tos.id_os - $agent_search_filter - $agent_status_filter - $group_acl - $modules_join - GROUP BY $group_by_fields - ORDER BY $order_fields"; - } - // Counters SQL - else { - $agent_table = "SELECT COUNT(DISTINCT(ta.id_agente)) - FROM tagente ta - $modules_join - WHERE ta.disabled = 0 - AND ta.id_os = $item_for_count - $group_acl - $agent_search_filter - $agent_status_filter"; - $sql = $this->getAgentCountersSql($agent_table); - } - } - else { - $columns = 'ta.id_agente AS id, ta.nombre AS name, ta.alias, - ta.fired_count, ta.normal_count, ta.warning_count, - ta.critical_count, ta.unknown_count, ta.notinit_count, - ta.total_count, ta.quiet'; - $group_by_fields = 'ta.id_agente, ta.nombre, ta.alias, - ta.fired_count, ta.normal_count, ta.warning_count, - ta.critical_count, ta.unknown_count, ta.notinit_count, - ta.total_count, ta.quiet'; - $order_fields = 'ta.alias ASC, ta.id_agente ASC'; - - $sql = "SELECT $columns - FROM tagente ta - $modules_join - WHERE ta.disabled = 0 - AND ta.id_os = $rootID - $group_acl - $agent_search_filter - $agent_status_filter - GROUP BY $group_by_fields - ORDER BY $order_fields"; - } - break; - // Get the modules of an agent - case 'agent': - $columns = 'tam.id_agente_modulo AS id, tam.nombre AS name, - tam.id_tipo_modulo, tam.id_modulo, tae.estado, tae.datos'; - $order_fields = 'tam.nombre ASC, tam.id_agente_modulo ASC'; - - $os_filter = "AND ta.id_os = $rootID"; - $agent_filter = "AND ta.id_agente = $parent"; - - // Set for the common ACL only. The strict ACL case is different (groups and tags divided). - // The modules only have visibility in two cases: - // 1. The user has access to the group of its agent and this group hasn't tags. - // 2. The user has access to the group of its agent, this group has tags and the module - // has any of this tags. - $tag_join = ''; - if (!$this->strictACL) { - // $parent is the agent id - $group_id = (int) db_get_value('id_grupo', 'tagente', 'id_agente', $parent); - if (empty($group_id)) { - // ACL error, this will restrict (fuck) the module search - $tag_join = 'INNER JOIN ttag_module tta - ON 1=0'; - } - else if (!empty($this->acltags) && isset($this->acltags[$group_id])) { - $tags_str = $this->acltags[$group_id]; - - if (!empty($tags_str)) { - $tag_join = sprintf('INNER JOIN ttag_module ttm - ON tam.id_agente_modulo = ttm.id_agente_modulo - AND ttm.id_tag IN (%s)', $tags_str); - } - } - } - - $sql = "SELECT $columns - FROM tagente_modulo tam - $tag_join - $module_status_join - INNER JOIN tagente ta - ON ta.disabled = 0 - AND tam.id_agente = ta.id_agente - $os_filter - $group_acl - $agent_search_filter - $agent_status_filter - WHERE tam.disabled = 0 - $agent_filter - $module_search_filter - ORDER BY $order_fields"; - break; - } - break; - case 'module_group': - // ACL Group - $group_acl = ""; - if (!empty($this->userGroups)) { - $user_groups_str = implode(",", array_keys($this->userGroups)); - $group_acl = " AND ta.id_grupo IN ($user_groups_str) "; - } - else { - $group_acl = "AND ta.id_grupo = -1"; - } - - switch ($type) { - // Get the agents of a module group - case 'module_group': - if (empty($rootID) || $rootID == -1) { - $columns = 'tmg.id_mg AS id, tmg.name AS name'; - $group_by_fields = 'tmg.id_mg, tmg.name'; - $order_fields = 'tmg.name ASC, tmg.id_mg ASC'; - - // Module groups SQL - if ($item_for_count === false) { - $sql = "SELECT $columns - FROM tmodule_group tmg - INNER JOIN tagente_modulo tam - ON tam.disabled = 0 - AND tam.id_module_group = tmg.id_mg - $module_search_filter - $module_status_join - INNER JOIN tagente ta - ON ta.disabled = 0 - AND tam.id_agente = ta.id_agente - $group_acl - $agent_search_filter - $agent_status_filter - GROUP BY $group_by_fields - ORDER BY $order_fields"; - } - // Counters SQL - else { - $agent_table = "SELECT COUNT(DISTINCT(ta.id_agente)) - FROM tagente ta - INNER JOIN tagente_modulo tam - ON tam.disabled = 0 - AND ta.id_agente = tam.id_agente - AND tam.id_module_group = $item_for_count - $module_search_filter - $module_status_join - WHERE ta.disabled = 0 - $group_acl - $agent_search_filter - $agent_status_filter"; - $sql = $this->getAgentCountersSql($agent_table); - } - } - else { - $columns = 'ta.id_agente AS id, ta.nombre AS name, ta.alias, - ta.fired_count, ta.normal_count, ta.warning_count, - ta.critical_count, ta.unknown_count, ta.notinit_count, - ta.total_count, ta.quiet'; - $group_by_fields = 'ta.id_agente, ta.nombre, ta.alias, - ta.fired_count, ta.normal_count, ta.warning_count, - ta.critical_count, ta.unknown_count, ta.notinit_count, - ta.total_count, ta.quiet'; - $order_fields = 'ta.alias ASC, ta.id_agente ASC'; - - $sql = "SELECT $columns - FROM tagente ta - INNER JOIN tagente_modulo tam - ON tam.disabled = 0 - AND ta.id_agente = tam.id_agente - AND tam.id_module_group = $rootID - $module_search_filter - $module_status_join - WHERE ta.disabled = 0 - $group_acl - $agent_search_filter - $agent_status_filter - GROUP BY $group_by_fields - ORDER BY $order_fields"; - } - break; - // Get the modules of an agent - case 'agent': - $columns = 'tam.id_agente_modulo AS id, tam.nombre AS name, - tam.id_tipo_modulo, tam.id_modulo, tae.estado, tae.datos'; - $order_fields = 'tam.nombre ASC, tam.id_agente_modulo ASC'; - - $module_group_filter = "AND tam.id_module_group = $rootID"; - $agent_filter = "AND tam.id_agente = $parent"; - - // Set for the common ACL only. The strict ACL case is different (groups and tags divided). - // The modules only have visibility in two cases: - // 1. The user has access to the group of its agent and this group hasn't tags. - // 2. The user has access to the group of its agent, this group has tags and the module - // has any of this tags. - $tag_join = ''; - if (!$this->strictACL) { - // $parent is the agent id - $group_id = (int) db_get_value('id_grupo', 'tagente', 'id_agente', $parent); - if (empty($group_id)) { - // ACL error, this will restrict (fuck) the module search - $tag_join = 'INNER JOIN ttag_module tta - ON 1=0'; - } - else if (!empty($this->acltags) && isset($this->acltags[$group_id])) { - $tags_str = $this->acltags[$group_id]; - - if (!empty($tags_str)) { - $tag_join = sprintf('INNER JOIN ttag_module ttm - ON tam.id_agente_modulo = ttm.id_agente_modulo - AND ttm.id_tag IN (%s)', $tags_str); - } - } - } - - $sql = "SELECT $columns - FROM tagente_modulo tam - $tag_join - $module_status_join - INNER JOIN tagente ta - ON ta.disabled = 0 - AND tam.id_agente = ta.id_agente - $group_acl - $agent_search_filter - $agent_status_filter - WHERE tam.disabled = 0 - $agent_filter - $module_group_filter - $module_search_filter - ORDER BY $order_fields"; - break; - } - break; - case 'module': - // ACL Group - $group_acl = ""; - if (!empty($this->userGroups)) { - $user_groups_str = implode(",", array_keys($this->userGroups)); - $group_acl = " AND ta.id_grupo IN ($user_groups_str) "; - } - else { - $group_acl = "AND ta.id_grupo = -1"; - } - - switch ($type) { - // Get the agents of a module - case 'module': - if (empty($rootID) || $rootID == -1) { - $columns = 'tam.nombre AS name'; - $order_fields = 'tam.nombre ASC'; - - // Modules SQL - if ($item_for_count === false) { - //FIXME This group ACL should be the same in all modules view - $group_acl = " AND (ta.id_grupo IN ($user_groups_str) OR tasg.id_group IN ($user_groups_str))"; - $sql = "SELECT $columns - FROM tagente_modulo tam - INNER JOIN tagente ta - ON ta.disabled = 0 - AND tam.id_agente = ta.id_agente - LEFT JOIN tagent_secondary_group tasg - ON tasg.id_agent = ta.id_agente - $agent_search_filter - $agent_status_filter - $module_status_join - WHERE tam.disabled = 0 - $group_acl - $module_search_filter - GROUP BY tam.nombre - ORDER BY $order_fields"; - } - // Counters SQL - else { - $agent_table = "SELECT COUNT(DISTINCT(ta.id_agente)) - FROM tagente ta - INNER JOIN tagente_modulo tam - ON tam.disabled = 0 - AND ta.id_agente = tam.id_agente - AND tam.nombre = '$item_for_count' - $module_group_filter - $module_search_filter - $module_status_join - WHERE ta.disabled = 0 - $group_acl - $agent_search_filter - $agent_status_filter"; - $sql = $this->getAgentCountersSql($agent_table); - } - } - else { - $columns = 'ta.id_agente AS id, ta.nombre AS name, ta.alias, - ta.fired_count, ta.normal_count, ta.warning_count, - ta.critical_count, ta.unknown_count, ta.notinit_count, - ta.total_count, ta.quiet'; - $group_by_fields = 'ta.id_agente, ta.nombre, ta.alias, - ta.fired_count, ta.normal_count, ta.warning_count, - ta.critical_count, ta.unknown_count, ta.notinit_count, - ta.total_count, ta.quiet'; - $order_fields = 'ta.alias ASC, ta.id_agente ASC'; - - $symbols = ' !"#$%&\'()*+,./:;<=>?@[\\]^{|}~'; - $name = $rootID; - for ($i = 0; $i < strlen($symbols); $i++) { - $name = str_replace('_articapandora_' . - ord(substr($symbols, $i, 1)) .'_pandoraartica_', - substr($symbols, $i, 1), $name); - } - $name = io_safe_input($name); - - $sql = "SELECT $columns - FROM tagente ta - INNER JOIN tagente_modulo tam - ON tam.disabled = 0 - AND ta.id_agente = tam.id_agente - AND tam.nombre = '$name' - $module_group_filter - $module_search_filter - $module_status_join - WHERE ta.disabled = 0 - $group_acl - $agent_search_filter - $agent_status_filter - GROUP BY $group_by_fields - ORDER BY $order_fields"; - } - break; - // Get the modules of an agent - case 'agent': - $columns = 'tam.id_agente_modulo AS id, tam.nombre AS name, - tam.id_tipo_modulo, tam.id_modulo, tae.estado, tae.datos'; - $order_fields = 'tam.nombre ASC, tam.id_agente_modulo ASC'; - - $symbols = ' !"#$%&\'()*+,./:;<=>?@[\\]^{|}~'; - $name = $rootID; - for ($i = 0; $i < strlen($symbols); $i++) { - $name = str_replace('_articapandora_' . - ord(substr($symbols, $i, 1)) .'_pandoraartica_', - substr($symbols, $i, 1), $name); - } - $name = io_safe_input($name); - - $module_name_filter = "AND tam.nombre = '$name'"; - $agent_filter = "AND tam.id_agente = $parent"; - - // We need the agents table - if (empty($agents_join)) { - $agents_join = "INNER JOIN tagente ta - ON ta.disabled = 0 - AND tam.id_agente = ta.id_agente - $group_acl"; - } - else { - $agents_join .= " $group_acl"; - } - - // Set for the common ACL only. The strict ACL case is different (groups and tags divided). - // The modules only have visibility in two cases: - // 1. The user has access to the group of its agent and this group hasn't tags. - // 2. The user has access to the group of its agent, this group has tags and the module - // has any of this tags. - $tag_join = ''; - if (!$this->strictACL) { - // $parent is the agent id - $group_id = (int) db_get_value('id_grupo', 'tagente', 'id_agente', $parent); - if (empty($group_id)) { - // ACL error, this will restrict (fuck) the module search - $tag_join = 'INNER JOIN ttag_module tta - ON 1=0'; - } - else if (!empty($this->acltags) && isset($this->acltags[$group_id])) { - $tags_str = $this->acltags[$group_id]; - - if (!empty($tags_str)) { - $tag_join = sprintf('INNER JOIN ttag_module ttm - ON tam.id_agente_modulo = ttm.id_agente_modulo - AND ttm.id_tag IN (%s)', $tags_str); - } - } - } - - $sql = "SELECT $columns - FROM tagente_modulo tam - $tag_join - $module_status_join - INNER JOIN tagente ta - ON ta.disabled = 0 - AND tam.id_agente = ta.id_agente - $group_acl - WHERE tam.disabled = 0 - $agent_filter - $module_name_filter - $module_group_filter - $module_search_filter - ORDER BY $order_fields"; - break; - } - break; - default: - $sql = $this->getSqlExtended($item_for_count, $type, $rootType, $parent, $rootID, - $agent_search_filter, $agent_status_filter, $agents_join, - $module_search_filter, $module_status_filter, $modules_join, - $module_status_join); - } - - return $sql; + protected function getInnerOrLeftJoin () { + return $this->filter['show_not_init_agents'] + ? "LEFT" + : "INNER"; } - // Override this method - protected function getSqlExtended ($item_for_count, $type, $rootType, $parent, $rootID, - $agent_search_filter, $agent_status_filter, $agents_join, - $module_search_filter, $module_status_filter, $modules_join, - $module_status_join) { - return false; + protected function getModuleStatusFilter () { + $show_init_condition = ($this->filter['show_not_init_agents']) + ? "" + : " AND ta.notinit_count <> ta.total_count"; + + if ($this->getEmptyModuleFilterStatus()) { + return $show_init_condition; + } + + $field_filter = modules_get_counter_by_states($this->filter['statusModule']); + if ($field_filter === false) return " AND 1=0"; + + return "AND ta.$field_filter > 0" . $show_init_condition; } - protected function getItems ($item_for_count = false) { - $sql = $this->getSql($item_for_count); - if (empty($sql)) - return array(); + // FIXME: Separate and condition from inner join + protected function getTagJoin () { + // $parent is the agent id + $group_id = (int) db_get_value('id_grupo', 'tagente', 'id_agente', $this->id); + $tag_join = ''; + if (empty($group_id)) { + // ACL error, this will restrict the module search + $tag_join = 'INNER JOIN ttag_module tta + ON 1=0'; + } + else if (!empty($this->acltags) && isset($this->acltags[$group_id])) { + $tags_str = $this->acltags[$group_id]; - $data = db_process_sql($sql); - if (empty($data)) - return array(); - - foreach ($data[0] as $key => $value) { - - if($key != 'total_count' && $key != 'total_fired_count' && strpos($key, 'count')){ - $zero_counter += $value; + if (!empty($tags_str)) { + $tag_join = sprintf('INNER JOIN ttag_module ttm + ON tam.id_agente_modulo = ttm.id_agente_modulo + AND ttm.id_tag IN (%s)', $tags_str); } - } - - if(!$zero_counter){ - $data[0]['total_count'] = 0; - } - else{ - $data[0]['total_count'] = $zero_counter; - } - - - - // [26/10/2017] It seems the module hierarchy should be only available into the tree by group - if ($this->rootType == 'group' && $this->type == 'agent') { - $data = $this->getProcessedModules($data); - } - - return $data; + return $tag_join; } - protected function getCounters ($id) { - $counters = $this->getItems($id); + protected function getModuleStatusFilterFromTestado ($state = false, $without_ands = false) { + $selected_status = ($state !== false && $state !== self::TV_DEFAULT_AGENT_STATUS) + ? $state + : $this->filter['statusModule']; - if (!empty($counters)) { - $counters = array_pop($counters); + $filter = array( + modules_get_state_condition($selected_status) + ); + if (!$this->filter['show_not_init_modules'] && $state === false) { + if (!empty($filter)) + $filter[] = "( + tae.estado <> ".AGENT_MODULE_STATUS_NO_DATA." + AND tae.estado <> ".AGENT_MODULE_STATUS_NOT_INIT." + )"; } - return $counters; + $filter = implode(" AND ", $filter); + return ($without_ands) + ? $filter + : " AND $filter "; + } + + public function getGroupAclCondition() { + if (users_can_manage_group_all("AR")) return ""; + + $groups_str= implode(",", $this->userGroupsArray); + return " AND ( + ta.id_grupo IN ($groups_str) + OR tasg.id_group IN ($groups_str) + )"; + } + + protected function getGroupSearchInner() { + if (empty($this->filter['searchGroup'])) return ""; + return "INNER JOIN tgrupo tg + ON ta.id_grupo = tg.id_grupo + OR tasg.id_group = tg.id_grupo" + ; + } + + protected function getGroupSearchFilter() { + if (empty($this->filter['searchGroup'])) return ""; + return " AND tg.nombre LIKE '%" . $this->filter['searchGroup'] . "%'"; } static function cmpSortNames($a, $b) { return strcmp($a["name"], $b["name"]); } - protected function getProcessedGroups ($items, $remove_empty = false) { - $processed_groups = array(); - // Index and process the groups - $groups = array(); - foreach ($items as $item) { - $groups[$item['id']] = $this->getProcessedItem($item); - } - - // If user have not permissions in parent, set parent node to 0 (all) - $user_groups_with_privileges = $this->userGroups; - foreach ($groups as $id => $group) { - if (!in_array($groups[$id]['parent'], array_keys($user_groups_with_privileges))) { - $groups[$id]['parent'] = 0; - } - } - // Build the group hierarchy - foreach ($groups as $id => $group) { - if (isset($groups[$id]['parent']) && ($groups[$id]['parent'] != 0)) { - $parent = $groups[$id]['parent']; - // Parent exists - if (!isset($groups[$parent]['children'])) { - $groups[$parent]['children'] = array(); - } - // Store a reference to the group into the parent - $groups[$parent]['children'][] = &$groups[$id]; - // This group was introduced into a parent - $groups[$id]['have_parent'] = true; - } - } - // Sort the children groups - foreach ($groups as $id => $group) { - if (isset($groups[$id]['children'])) { - usort($groups[$id]['children'], array("Tree", "cmpSortNames")); - } - } - //Filter groups and eliminates the reference to children groups out of her parent - $groups = array_filter($groups, function ($group) { - return !$group['have_parent']; - }); - // Propagate child counters to her parents - Tree::processCounters($groups); - // Filter groups and eliminates the reference to empty groups - if ($remove_empty) { - $groups = Tree::deleteEmptyGroups($groups); - } - usort($groups, array("Tree", "cmpSortNames")); - return $groups; - } - - protected function getProcessedItem ($item, $server = false, &$items = array(), &$items_tmp = array(), $remove_empty = false) { + protected function getProcessedItem ($item, $server = false) { if (isset($processed_item['is_processed']) && $processed_item['is_processed']) return $item; - // For strict items - if (isset($item['_id_'])) { - $item['id'] = $item['_id_']; - $item['name'] = $item['_name_']; - - if (isset($item['_is_tag_']) && $item['_is_tag_']) { - $item['type'] = 'tag'; - $item['rootType'] = 'tag'; - } - else { - $item['type'] = 'group'; - $item['rootType'] = 'group'; - $item['parent'] = $item['_parent_id_']; - - if (!empty($item['_iconImg_'])) - $item['iconHTML'] = $item['_iconImg_']; - } - - if (isset($item['_agents_unknown_'])) - $item['total_unknown_count'] = $item['_agents_unknown_']; - if (isset($item['_agents_critical_'])) - $item['total_critical_count'] = $item['_agents_critical_']; - if (isset($item['_agents_warning_'])) - $item['total_warning_count'] = $item['_agents_warning_']; - if (isset($item['_agents_not_init_'])) - $item['total_not_init_count'] = $item['_agents_not_init_']; - if (isset($item['_agents_ok_'])) - $item['total_normal_count'] = $item['_agents_ok_']; - if (isset($item['_total_agents_'])) - $item['total_count'] = $item['_total_agents_']; - if (isset($item['_monitors_alerts_fired_'])) - $item['total_fired_count'] = $item['_monitors_alerts_fired_']; - - // Agent filter for Strict ACL users - if ($this->filter["statusAgent"] != -1) { - switch ($this->filter["statusAgent"]) { - case AGENT_STATUS_NOT_INIT: - $item['total_count'] = $item['total_not_init_count']; - - $item['total_unknown_count'] = 0; - $item['total_critical_count'] = 0; - $item['total_warning_count'] = 0; - $item['total_normal_count'] = 0; - break; - case AGENT_STATUS_CRITICAL: - $item['total_count'] = $item['total_critical_count']; - - $item['total_unknown_count'] = 0; - $item['total_warning_count'] = 0; - $item['total_not_init_count'] = 0; - $item['total_normal_count'] = 0; - break; - case AGENT_STATUS_WARNING: - $item['total_count'] = $item['total_warning_count']; - - $item['total_unknown_count'] = 0; - $item['total_critical_count'] = 0; - $item['total_not_init_count'] = 0; - $item['total_normal_count'] = 0; - break; - case AGENT_STATUS_UNKNOWN: - $item['total_count'] = $item['total_unknown_count']; - - $item['total_critical_count'] = 0; - $item['total_warning_count'] = 0; - $item['total_not_init_count'] = 0; - $item['total_normal_count'] = 0; - break; - case AGENT_STATUS_NORMAL: - $item['total_count'] = $item['total_normal_count']; - - $item['total_unknown_count'] = 0; - $item['total_critical_count'] = 0; - $item['total_warning_count'] = 0; - $item['total_not_init_count'] = 0; - break; - } - } - } - - $processed_item = array(); $processed_item['id'] = $item['id']; $processed_item['name'] = $item['name']; @@ -1410,28 +300,18 @@ class Tree { if ($processed_item['type'] == 'group') { $processed_item['parent'] = $item['parent']; - if (!empty($item['iconHTML'])) - $processed_item['iconHTML'] = $item['iconHTML']; - else if (!empty($item['icon'])) - $processed_item['icon'] = $item['icon'].".png"; - else - $processed_item['icon'] = "without_group.png"; + $processed_item['icon'] = empty($item['icon']) + ? "without_group.png" + : $item['icon'].".png"; + } + if (isset($item['iconHTML'])) { + $processed_item['icon'] = $item['iconHTML']; } if (is_metaconsole() && !empty($server)) { $processed_item['serverID'] = $server['id']; } - // Get the counters of the group (special case) - if ($processed_item['type'] == 'group') { - $counters = $this->getGroupCounters($item['id']); - if (!empty($counters)) { - foreach ($counters as $type => $value) { - $item[$type] = $value; - } - } - } - $counters = array(); if (isset($item['total_unknown_count'])) $counters['unknown'] = $item['total_unknown_count']; @@ -1554,12 +434,12 @@ class Tree { return $mergedItems; } - protected function processModule (&$module, $server = false) { + protected function processModule (&$module, $server = false, $all_groups) { global $config; if (isset($module['children'])) { foreach ($module['children'] as $i => $children) { - $this->processModule($module['children'][$i], $server); + $this->processModule($module['children'][$i], $server, $all_groups); } } @@ -1571,9 +451,9 @@ class Tree { $module['status'] = $module['estado']; $module['value'] = $module['datos']; - if (is_metaconsole() && !empty($server)) { - $module['serverID'] = $server['id']; - $module['serverName'] = $server['server_name']; + if (is_metaconsole()) { + $module['serverID'] = $this->serverID; + $module['serverName'] = $this->serverName; } else { $module['serverName'] = false; @@ -1638,7 +518,6 @@ class Tree { // Link to the Module graph // ACL - $all_groups = modules_get_agent_groups($module['id']); $acl_graphs = false; $module["showGraphs"] = 0; @@ -1667,7 +546,7 @@ class Tree { "refresh" => SECONDS_10MINUTES ); - if (is_metaconsole() && !empty($server)) { + if (is_metaconsole()) { // Set the server id $graph_params["server"] = $module['serverID']; } @@ -1690,18 +569,17 @@ class Tree { } // Alerts fired image - $has_alerts = (bool) db_get_value( - 'COUNT(DISTINCT(id_agent_module))', - 'talert_template_modules', 'id_agent_module', $module['id']); - - if ($has_alerts) { + if ((bool)$module['alerts']) { $module['alertsImageHTML'] = html_print_image("images/bell.png", true, array("title" => __('Module alerts'))); } } protected function processModules (&$modules, $server = false) { + if (!empty($modules)) { + $all_groups = modules_get_agent_groups($modules[0]['id']); + } foreach ($modules as $iterator => $module) { - $this->processModule($modules[$iterator], $server); + $this->processModule($modules[$iterator], $server, $all_groups); } } @@ -1721,183 +599,17 @@ class Tree { else if (!empty($server)) $agent['serverID'] = $server['id']; } - - // Realtime counters for Strict ACL - if ($this->strictACL) { - $agent_filter = array("id" => $agent['id']); - $module_filter = array(); - - if (isset($this->filter["statusAgent"])) - $agent_filter["status"] = $this->filter["statusAgent"]; - if (isset($this->filter["searchAgent"])) - $agent_filter["name"] = $this->filter["searchAgent"]; - - if (isset($this->filter["statusModule"])) - $module_filter["status"] = $this->filter["statusModule"]; - if (isset($this->filter["searchModule"])) - $module_filter["name"] = $this->filter["searchModule"]; - - $agent['counters'] = array(); - $agent['counters']['unknown'] = 0; - $agent['counters']['critical'] = 0; - $agent['counters']['warning'] = 0; - $agent['counters']['not_init'] = 0; - $agent['counters']['ok'] = 0; - $agent['counters']['total'] = 0; - $agent['counters']['alerts'] = 0; - - if ($agent['rootType'] == "group") { - $agent['counters']['alerts'] = agents_get_alerts_fired($agent['id']); - - // With module filter - if (isset($this->filter["statusModule"]) && $this->filter["statusModule"] != AGENT_MODULE_STATUS_ALL) { - switch ($this->filter["statusModule"]) { - case AGENT_MODULE_STATUS_CRITICAL_ALERT: - case AGENT_MODULE_STATUS_CRITICAL_BAD: - $agent['counters']['critical'] = (int) groups_get_critical_monitors ($agent['rootID'], $agent_filter, $module_filter, true, $this->acltags); - $agent['counters']['total'] = $agent['counters']['critical']; - break; - case AGENT_MODULE_STATUS_WARNING_ALERT: - case AGENT_MODULE_STATUS_WARNING: - $agent['counters']['warning'] = (int) groups_get_warning_monitors ($agent['rootID'], $agent_filter, $module_filter, true, $this->acltags); - $agent['counters']['total'] = $agent['counters']['warning']; - break; - case AGENT_MODULE_STATUS_UNKNOWN: - $agent['counters']['unknown'] = (int) groups_get_unknown_monitors ($agent['rootID'], $agent_filter, $module_filter, true, $this->acltags); - $agent['counters']['total'] = $agent['counters']['unknown']; - break; - case AGENT_MODULE_STATUS_NO_DATA: - case AGENT_MODULE_STATUS_NOT_INIT: - $agent['counters']['not_init'] = (int) groups_get_not_init_monitors ($agent['rootID'], $agent_filter, $module_filter, true, $this->acltags); - $agent['counters']['total'] = $agent['counters']['not_init']; - break; - case AGENT_MODULE_STATUS_NORMAL_ALERT: - case AGENT_MODULE_STATUS_NORMAL: - $agent['counters']['ok'] = (int) groups_get_normal_monitors ($agent['rootID'], $agent_filter, $module_filter, true, $this->acltags); - $agent['counters']['total'] = $agent['counters']['ok']; - break; - } - } - // Without module filter - else { - $agent['counters']['unknown'] = (int) groups_get_unknown_monitors ($agent['rootID'], $agent_filter, $module_filter, true, $this->acltags); - $agent['counters']['critical'] = (int) groups_get_critical_monitors ($agent['rootID'], $agent_filter, $module_filter, true, $this->acltags); - $agent['counters']['warning'] = (int) groups_get_warning_monitors ($agent['rootID'], $agent_filter, $module_filter, true, $this->acltags); - $agent['counters']['not_init'] = (int) groups_get_not_init_monitors ($agent['rootID'], $agent_filter, $module_filter, true, $this->acltags); - $agent['counters']['ok'] = (int) groups_get_normal_monitors ($agent['rootID'], $agent_filter, $module_filter, true, $this->acltags); - $agent['counters']['total'] = (int) groups_get_total_monitors ($agent['rootID'], $agent_filter, $module_filter, true, $this->acltags); - } - } - else if ($agent['rootType'] == "tag") { - $agent['counters']['alerts'] = (int) tags_monitors_fired_alerts ($agent['rootID'], $this->acltags, $agent['id']); - - // With module filter - if (isset($this->filter["statusModule"]) && $this->filter["statusModule"] != AGENT_MODULE_STATUS_ALL) { - switch ($this->filter["statusModule"]) { - case AGENT_MODULE_STATUS_CRITICAL_ALERT: - case AGENT_MODULE_STATUS_CRITICAL_BAD: - $agent['counters']['critical'] = (int) tags_get_critical_monitors ($agent['rootID'], $this->acltags, $agent_filter, $module_filter); - $agent['counters']['total'] = $agent['counters']['critical']; - break; - case AGENT_MODULE_STATUS_WARNING_ALERT: - case AGENT_MODULE_STATUS_WARNING: - $agent['counters']['warning'] = (int) tags_get_warning_monitors ($agent['rootID'], $this->acltags, $agent_filter, $module_filter); - $agent['counters']['total'] = $agent['counters']['warning']; - break; - case AGENT_MODULE_STATUS_UNKNOWN: - $agent['counters']['unknown'] = (int) tags_get_unknown_monitors ($agent['rootID'], $this->acltags, $agent_filter, $module_filter); - $agent['counters']['total'] = $agent['counters']['unknown']; - break; - case AGENT_MODULE_STATUS_NO_DATA: - case AGENT_MODULE_STATUS_NOT_INIT: - $agent['counters']['not_init'] = (int) tags_get_not_init_monitors ($agent['rootID'], $this->acltags, $agent_filter, $module_filter); - $agent['counters']['total'] = $agent['counters']['not_init']; - break; - case AGENT_MODULE_STATUS_NORMAL_ALERT: - case AGENT_MODULE_STATUS_NORMAL: - $agent['counters']['ok'] = (int) tags_get_normal_monitors ($agent['rootID'], $this->acltags, $agent_filter, $module_filter); - $agent['counters']['total'] = $agent['counters']['ok']; - break; - } - } - // Without module filter - else { - $agent['counters']['unknown'] = (int) tags_get_unknown_monitors ($agent['rootID'], $this->acltags, $agent_filter, $module_filter); - $agent['counters']['critical'] = (int) tags_get_critical_monitors ($agent['rootID'], $this->acltags, $agent_filter, $module_filter); - $agent['counters']['warning'] = (int) tags_get_warning_monitors ($agent['rootID'], $this->acltags, $agent_filter, $module_filter); - $agent['counters']['not_init'] = (int) tags_get_not_init_monitors ($agent['rootID'], $this->acltags, $agent_filter, $module_filter); - $agent['counters']['ok'] = (int) tags_get_normal_monitors ($agent['rootID'], $this->acltags, $agent_filter, $module_filter); - $agent['counters']['total'] = (int) tags_get_total_monitors ($agent['rootID'], $this->acltags, $agent_filter, $module_filter); - } - } - - if (isset($this->filter["statusAgent"]) && $this->filter["statusAgent"] != AGENT_STATUS_ALL) { - switch ($this->filter["statusAgent"]) { - case AGENT_STATUS_CRITICAL: - if ($agent['counters']['critical'] == 0) - $agent = array(); - break; - case AGENT_STATUS_WARNING: - if ($agent['counters']['total'] == 0 || $agent['counters']['critical'] > 0 || $agent['counters']['warning'] == 0) - $agent = array(); - break; - case AGENT_STATUS_UNKNOWN: - if ($agent['counters']['critical'] > 0 || $agent['counters']['warning'] > 0 || $agent['counters']['unknown'] == 0) - $agent = array(); - break; - case AGENT_STATUS_NOT_INIT: - if ($agent['counters']['total'] != 0 && $agent['counters']['total'] != $agent['counters']['not_init']) - $agent = array(); - break; - case AGENT_STATUS_NORMAL: - if ($agent['counters']['critical'] > 0 || $agent['counters']['warning'] > 0 || $agent['counters']['unknown'] > 0 || $agent['counters']['ok'] == 0) - $agent = array(); - break; - } - // Leave the function - if (empty($agent)) - return; - } - } - // Counters if (empty($agent['counters'])) { $agent['counters'] = array(); - if (isset($agent['unknown_count'])) - $agent['counters']['unknown'] = $agent['unknown_count']; - else - $agent['counters']['unknown'] = (int) agents_monitor_unknown($agent['id']); - - if (isset($agent['critical_count'])) - $agent['counters']['critical'] = $agent['critical_count']; - else - $agent['counters']['critical'] = (int) agents_monitor_critical($agent['id']); - - if (isset($agent['warning_count'])) - $agent['counters']['warning'] = $agent['warning_count']; - else - $agent['counters']['warning'] = (int) agents_monitor_warning($agent['id']); - - if (isset($agent['notinit_count'])) - $agent['counters']['not_init'] = $agent['notinit_count']; - else - $agent['counters']['not_init'] = (int) agents_monitor_notinit($agent['id']); - - if (isset($agent['normal_count'])) - $agent['counters']['ok'] = $agent['normal_count']; - else - $agent['counters']['ok'] = (int) agents_monitor_ok($agent['id']); - - if (isset($agent['total_count'])) - $agent['counters']['total'] = $agent['total_count']; - else - $agent['counters']['total'] = (int) agents_monitor_total($agent['id']); - - if (isset($agent['fired_count'])) - $agent['counters']['alerts'] = $agent['fired_count']; - else - $agent['counters']['alerts'] = (int) agents_get_alerts_fired($agent['id']); + $agent['counters']['unknown'] = isset($agent['unknown_count']) ? $agent['unknown_count'] : 0; + $agent['counters']['critical'] = isset($agent['critical_count']) ? $agent['critical_count'] : 0; + $agent['counters']['warning'] = isset($agent['warning_count']) ? $agent['warning_count'] : 0; + $agent['counters']['not_init'] = isset($agent['notinit_count']) ? $agent['notinit_count'] : 0; + $agent['counters']['ok'] = isset($agent['normal_count']) ? $agent['normal_count'] : 0; + $agent['counters']['total'] = isset($agent['total_count']) ? $agent['total_count'] : 0; + $agent['counters']['alerts'] = isset($agent['fired_count']) ? $agent['fired_count'] : 0; } // Status image @@ -1911,33 +623,67 @@ class Tree { // Alerts fired image $agent["alertImageHTML"] = agents_tree_view_alert_img_ball($agent['counters']['alerts']); + // search module recalculate counters + if(array_key_exists('state_normal', $agent)){ + $agent['counters']['unknown'] = $agent['state_unknown']; + $agent['counters']['critical'] = $agent['state_critical']; + $agent['counters']['warning'] = $agent['state_warning']; + $agent['counters']['not_init'] = $agent['state_notinit']; + $agent['counters']['ok'] = $agent['state_normal']; + $agent['counters']['total'] = $agent['state_total']; + + $agent['critical_count'] = $agent['counters']['critical']; + $agent['warning_count'] = $agent['counters']['warning']; + $agent['unknown_count'] = $agent['counters']['unknown']; + $agent['notinit_count'] = $agent['counters']['not_init']; + $agent['normal_count'] = $agent['counters']['ok']; + $agent['total_count'] = $agent['counters']['total']; + } + + if (!$this->getEmptyModuleFilterStatus()) { + $agent['counters']['unknown'] = 0; + $agent['counters']['critical'] = 0; + $agent['counters']['warning'] = 0; + $agent['counters']['not_init'] = 0; + $agent['counters']['ok'] = 0; + $agent['counters']['total'] = 0; + switch($this->filter['statusModule']) { + case AGENT_MODULE_STATUS_CRITICAL_ALERT: + case AGENT_MODULE_STATUS_CRITICAL_BAD: + $agent['counters']['critical'] = $agent['critical_count']; + $agent['counters']['total'] = $agent['critical_count']; + break; + case AGENT_MODULE_STATUS_WARNING_ALERT: + case AGENT_MODULE_STATUS_WARNING: + $agent['counters']['warning'] = $agent['warning_count']; + $agent['counters']['total'] = $agent['warning_count']; + break; + case AGENT_MODULE_STATUS_UNKNOWN: + $agent['counters']['unknown'] = $agent['unknown_count']; + $agent['counters']['total'] = $agent['unknown_count']; + break; + case AGENT_MODULE_STATUS_NO_DATA: + case AGENT_MODULE_STATUS_NOT_INIT: + $agent['counters']['not_init'] = $agent['notinit_count']; + $agent['counters']['total'] = $agent['notinit_count']; + break; + case AGENT_MODULE_STATUS_NORMAL_ALERT: + case AGENT_MODULE_STATUS_NORMAL: + $agent['counters']['ok'] = $agent['normal_count']; + $agent['counters']['total'] = $agent['normal_count']; + break; + } + } + + if (!$this->filter['show_not_init_modules']) { + $agent['counters']['total'] -= $agent['counters']['not_init']; + $agent['counters']['not_init'] = 0; + } + // Quiet image if (isset($agent['quiet']) && $agent['quiet']) $agent['quietImageHTML'] = html_print_image("/images/dot_blue.png", true, array("title" => __('Quiet'))); - // Status - $agent['statusRaw'] = agents_get_status($agent['id'], !$this->strictACL); - switch ($agent['statusRaw']) { - case AGENT_STATUS_NORMAL: - $agent['status'] = "ok"; - break; - case AGENT_STATUS_WARNING: - $agent['status'] = "warning"; - break; - case AGENT_STATUS_CRITICAL: - $agent['status'] = "critical"; - break; - case AGENT_STATUS_UNKNOWN: - $agent['status'] = "unknown"; - break; - case AGENT_STATUS_NOT_INIT: - $agent['status'] = "not_init"; - break; - default: - $agent['status'] = "none"; - break; - } - // Children if (empty($agent['children'])) { $agent['children'] = array(); @@ -1948,9 +694,6 @@ class Tree { break; case 'live': $agent['searchChildren'] = 0; - - // if ($searchChildren) - // $agent['children'] = $this->getModules($agent['id'], $modulesFilter); break; } } @@ -1975,800 +718,222 @@ class Tree { } } - /** - * @brief Recursive function to remove the empty groups - * - * @param groups All groups structure - * - * @return new_groups A new groups structure without empty groups - */ - protected static function deleteEmptyGroups ($groups) { - $new_groups = array(); - foreach ($groups as $group) { - // If a group is empty, do not add to new_groups. - if (!isset($group['counters']['total']) || $group['counters']['total'] == 0) { - continue; - } - // Tray to remove the children groups - if (!empty($group['children'])) { - $children = Tree::deleteEmptyGroups ($group['children']); - if (empty($children)) unset($group['children']); - else $group['children'] = $children; - } - $new_groups[] = $group; - } - return $new_groups; + protected function getData() { + } - private static function extractGroupsWithIDs ($groups, $ids_hash) { - $result_groups = array(); - foreach ($groups as $group) { - if (isset($ids_hash[$group['id']])) { - $result_groups[] = $group; - } - else if (!empty($group['children'])) { - $result = self::extractGroupsWithIDs($group['children'], $ids_hash); + protected function getFirstLevel() { + $sql = $this->getFirstLevelSql(); + $items = db_get_all_rows_sql($sql); + if ($items === false) $items = array(); - // Item found on children - if (!empty($result)) { - $result_groups = array_merge($result_groups, $result); - } - } - } - - return $result_groups; + $this->tree = $this->getProcessedItemsFirstLevel($items); } - private static function extractItemWithID ($items, $item_id, $item_type = "group", $strictACL = false) { - foreach ($items as $item) { - if ($item["type"] != $item_type) - continue; - - // Item found - if ($strictACL && is_metaconsole()) { - foreach ($item["id"] as $server_id => $id) { - if ($id == $item_id) - return $item; - } - } - else { - if ($item["id"] == $item_id) - return $item; - } - - if ($item["type"] == "group" && !empty($item["children"])) { - $result = self::extractItemWithID($item["children"], $item_id, $item_type, $strictACL); - - // Item found on children - if ($result !== false) - return $result; - } - } - - // Item not found - return false; - } - - public function getData() { - if (! is_metaconsole()) { - if ($this->strictACL) { - switch ($this->type) { - case 'group': - case 'tag': - $this->getDataStrict(); - break; - case 'agent': - $this->getDataAgent(); - break; - } - } - else{ - switch ($this->type) { - case 'os': - $this->getDataOS(); - break; - case 'group': - $this->getDataGroup(); - break; - case 'module_group': - $this->getDataModuleGroup(); - break; - case 'module': - $this->getDataModules(); - break; - case 'tag': - $this->getDataTag(); - break; - case 'agent': - $this->getDataAgent(); - break; - default: - $this->getDataExtended(); - } - } - } - else if ($this->strictACL) { - switch ($this->type) { - case 'group': - case 'tag': - $this->getDataStrict(); - break; - case 'agent': - $this->getDataAgent(); - break; - } - } - else { - if ($this->type == 'agent') { - $this->getDataAgent(); - } - else { - $this->getDataGroup(); - } - } - } - - protected function getDataExtended () { - // Override this method to add new types - } - - private function getDataAgent () { + protected function getProcessedItemsFirstLevel($items){ $processed_items = array(); - - // Module names - if ($this->id == -1) { - + foreach ($items as $key => $item) { + $processed_item = $this->getProcessedItem($item); + $processed_items[] = $processed_item; } - // Agents - else { - if (! is_metaconsole()) { - $items = $this->getItems(); - $this->processModules($items); - $processed_items = $items; - - if(!$this->filter['show_not_init_modules']){ - - foreach ($items as $key => $value) { - if($items[$key]['total_count'] != $items[$key]['notinit_count']){ - $items[$key]['total_count'] = $items[$key]['total_count'] - $items[$key]['notinit_count']; - $items[$key]['notinit_count'] = 0; - } - - } - - } - } - else { - $items = array(); - - if ($this->serverID !== false) { - - $server = metaconsole_get_servers($this->serverID); - if (metaconsole_connect($server) == NOERR) { - $items = $this->getItems(); - $this->processModules($items, $server); - - metaconsole_restore_db(); - } - } - - $processed_items = $items; - } - } - - $this->tree = $processed_items; + return $processed_items; } - private function getDataStrict () { - global $config; + protected function getFirstLevelSql() { - require_once($config['homedir']."/include/functions_groups.php"); + $fields = $this->getFirstLevelFields(); + $field_name_sql = $this->L1fieldNameSql; + $inside_fields = $this->getFirstLevelFieldsInside(); + $inner = $this->L1inner; + $inner_inside = $this->L1innerInside; + $order_by_final = $this->L1orderByFinal; - $processed_items = array(); - - // Groups and tags - if ($this->id == -1) { - $agent_filter = array(); - if (isset($this->filter["statusAgent"])) - $agent_filter["status"] = $this->filter["statusAgent"]; - if (isset($this->filter["searchAgent"])) - $agent_filter["name"] = $this->filter["searchAgent"]; - - $module_filter = array(); - if (isset($this->filter["statusModule"])) - $module_filter["status"] = $this->filter["statusModule"]; - if (isset($this->filter["searchModule"])) - $module_filter["name"] = $this->filter["searchModule"]; - - if (! is_metaconsole()) { - $items = group_get_data($config['id_user'], $this->strictACL, $this->acltags, false, 'tree', $agent_filter, $module_filter); - - // Build the group and tag hierarchy - $processed_groups = array(); - $processed_tags = array(); - - foreach ($items as $key => $item) { - $processed_item = $this->getProcessedItem($item); - if ($processed_item['type'] == 'tag') { - if (!empty($processed_item) && - isset($processed_item['counters']) && - isset($processed_item['counters']['total']) && - !empty($processed_item['counters']['total'])) { - $processed_tags[] = $processed_item; - } - } - else { - $processed_groups[] = $processed_item; - } - } - - // Build the groups hierarchy - $processed_groups = $this->getProcessedGroups($processed_groups, true); - // Sort tags - usort($processed_tags, array("Tree", "cmpSortNames")); - - // Join tags and groups - $processed_items = array_merge($processed_groups, $processed_tags); - } - else { - $unmerged_items = array(); - - $servers = metaconsole_get_servers(); - foreach ($servers as $server) { - if (metaconsole_connect($server) != NOERR) - continue; - db_clean_cache(); - - $items = group_get_data($config['id_user'], $this->strictACL, $this->acltags, false, 'tree', $agent_filter, $module_filter); - - // Build the group and tag hierarchy - $processed_groups = array(); - $processed_tags = array(); - - foreach ($items as $key => $item) { - $processed_item = $this->getProcessedItem($item); - if ($processed_item['type'] == 'tag') - $processed_tags[] = $processed_item; - else - $processed_groups[] = $processed_item; - } - - // Build the groups hierarchy - $processed_groups = $this->getProcessedGroups($processed_groups); - // Sort tags - usort($processed_tags, array("Tree", "cmpSortNames")); - - // Join tags and groups - $processed_items = array_merge($processed_groups, $processed_tags); - - $unmerged_items += $processed_items; - - metaconsole_restore_db(); - } - - $processed_items = $this->getMergedItems($unmerged_items); - } - - if (!empty($processed_items)) { - if (!empty($this->filter["groupID"])) { - $result = self::extractItemWithID($processed_items, $this->filter["groupID"], "group", $this->strictACL); - - if ($result === false) - $processed_items = array(); - else - $processed_items = array($result); - } - else if (!empty($this->filter["tagID"])) { - $result = self::extractItemWithID($processed_items, $this->filter["tagID"], "tag", $this->strictACL); - - if ($result === false) - $processed_items = array(); - else - $processed_items = array($result); - } - } - } - // Agents - else { - if (! is_metaconsole()) { - $items = $this->getItems(); - $this->processAgents($items); - // Remove empty entrys - $processed_items = array_filter($items); - // Restart the array keys -> Important! - $processed_items = array_values($processed_items); - } - else { - $rootIDs = $this->rootID; - - $items = array(); - $j = 1; - $server = metaconsole_get_servers(); - foreach ($rootIDs as $serverID => $rootID) { - if (metaconsole_connect($server[$j]) != NOERR) - continue; - db_clean_cache(); - - $this->rootID = $rootID; - $newItems = $this->getItems(); - $this->processAgents($newItems, $server[$j]); - $newItems = array_filter($newItems); - $items = array_merge($items, $newItems); - - metaconsole_restore_db(); - $j++; - } - $this->rootID = $rootIDs; - - if (!empty($items)) - usort($items, array("Tree", "cmpSortNames")); - - $processed_items = $items; - } + $group_inner = $this->getGroupSearchInner(); + $group_acl = $this->getGroupAclCondition(); + $group_search_filter = $this->getGroupSearchFilter(); + $agent_search_filter = $this->getAgentSearchFilter(); + $agent_status_filter = $this->getAgentStatusFilter(); + $module_search_filter = $this->getModuleSearchFilter(); + $module_status_inner = ""; + $module_status_filter = $this->getModuleStatusFilterFromTestado(); + if (!empty($module_status_filter)) { + $module_status_inner = " + INNER JOIN tagente_estado tae + ON tae.id_agente_modulo = tam.id_agente_modulo"; } - $this->tree = $processed_items; + $sql_model = "SELECT %s FROM + ( + SELECT COUNT(DISTINCT(ta.id_agente)) AS total, $field_name_sql AS g + FROM tagente ta + LEFT JOIN tagent_secondary_group tasg + ON ta.id_agente = tasg.id_agent + INNER JOIN tagente_modulo tam + ON ta.id_agente = tam.id_agente + $inner_inside + $module_status_inner + $group_inner + WHERE ta.disabled = 0 + AND tam.disabled = 0 + %s + $agent_search_filter + $agent_status_filter + $module_search_filter + $module_status_filter + $group_search_filter + $group_acl + GROUP BY $field_name_sql + ) x GROUP BY g"; + $sql_array = array(); + foreach ($inside_fields as $inside_field) { + $sql_array[] = sprintf( + $sql_model, + $inside_field['header'], + $inside_field['condition'] + ); + } + $sql = "SELECT $fields FROM (" . implode(" UNION ALL ", $sql_array) . ") x2 + $inner + GROUP BY g + ORDER BY $order_by_final"; + return $sql; } - private function getDataGroup() { - $processed_items = array(); - - // Groups - if ($this->id == -1) { - - $items = $this->getItems(); - - $processed_items = $this->getProcessedGroups($items, true); - - if (!empty($processed_items)) { - // Filter by group name. This should be done after rerieving the items cause we need the possible items descendants - if (!empty($this->filter['searchGroup'])) { - // Save the groups which intersect with the user groups - $groups = db_get_all_rows_filter('tgrupo', array('nombre' => '%' . $this->filter['searchGroup'] . '%')); - if ($groups == false) $groups = array(); - $userGroupsACL = $this->userGroupsACL; - $ids_hash = array_reduce($groups, function ($userGroups, $group) use ($userGroupsACL) { - $group_id = $group['id_grupo']; - if (isset($userGroupsACL[$group_id])) { - $userGroups[$group_id] = $userGroupsACL[$group_id]; - } - - return $userGroups; - }, array()); - - $result = self::extractGroupsWithIDs($processed_items, $ids_hash); - - $processed_items = ($result === false) ? array() : $result; - } - - // groupID filter. To access the view from tactical views f.e. - if (!empty($this->filter['groupID'])) { - $result = self::extractItemWithID($processed_items, $this->filter['groupID'], "group", $this->strictACL); - - $processed_items = ($result === false) ? array() : array($result); - } - } - } - // Agents - else { - $items = $this->getItems(); - - - if(!$this->filter['show_not_init_modules']){ - - foreach ($items as $key => $value) { - $items[$key]['total_count'] = $items[$key]['total_count'] - $items[$key]['notinit_count']; - $items[$key]['notinit_count'] = 0; - - } - - } - - if(!$this->filter['show_not_init_agents']){ - - foreach ($items as $key => $value) { - if($items[$key]['total_count'] == $items[$key]['notinit_count']){ - unset($items[$key]); - } - } - - } - - $this->processAgents($items); - $processed_items = $items; + protected function getSecondLevel() { + $sql = $this->getSecondLevelSql(); + $data = db_process_sql($sql); + if (empty($data)) { + $this->tree = array(); + return; } + $this->processAgents($data); - $this->tree = $processed_items; + $this->tree = $data; } - private function getDataTag() { - $processed_items = array(); + protected function getSecondLevelSql() { + $columns = sprintf("ta.id_agente AS id, ta.nombre AS name, ta.alias, + ta.fired_count, ta.normal_count, ta.warning_count, + ta.critical_count, ta.unknown_count, ta.notinit_count, + ta.total_count, ta.quiet, + SUM(if(%s, 1, 0)) as state_critical, + SUM(if(%s, 1, 0)) as state_warning, + SUM(if(%s, 1, 0)) as state_unknown, + SUM(if(%s, 1, 0)) as state_notinit, + SUM(if(%s, 1, 0)) as state_normal, + SUM(if(%s AND tae.estado IS NOT NULL, 1, 0)) as state_total + ", + $this->getModuleStatusFilterFromTestado(AGENT_MODULE_STATUS_CRITICAL_ALERT, true), + $this->getModuleStatusFilterFromTestado(AGENT_MODULE_STATUS_WARNING_ALERT, true), + $this->getModuleStatusFilterFromTestado(AGENT_MODULE_STATUS_UNKNOWN, true), + $this->getModuleStatusFilterFromTestado(AGENT_MODULE_STATUS_NO_DATA, true), + $this->getModuleStatusFilterFromTestado(AGENT_MODULE_STATUS_NORMAL, true), + $this->getModuleStatusFilterFromTestado(self::TV_DEFAULT_AGENT_STATUS, true) + ); - // Tags - if ($this->id == -1) { - if (! is_metaconsole()) { - $items = $this->getItems(); + $inner_or_left = $this->getInnerOrLeftJoin(); + $group_inner = $this->getGroupSearchInner(); + $group_acl = $this->getGroupAclCondition(); + $group_search_filter = $this->getGroupSearchFilter(); + $agent_search_filter = $this->getAgentSearchFilter(); + $agent_status_filter = $this->getAgentStatusFilter(); + $module_search_filter = $this->getModuleSearchFilter(); + $module_status_filter = $this->getModuleStatusFilter(); - foreach ($items as $key => $item) { + $condition = $this->L2condition; + $condition_inside = $this->L2conditionInside; + $inner = $this->L2inner; - $counters = $this->getCounters($item['id']); - if (!empty($counters)) { - foreach ($counters as $type => $value) { - $item[$type] = $value; - } - } + $sql = "SELECT $columns + FROM tagente ta + $inner_or_left JOIN tagente_modulo tam + ON ta.id_agente = tam.id_agente + AND tam.disabled = 0 + $inner_or_left JOIN tagente_estado tae + ON tae.id_agente_modulo = tam.id_agente_modulo + $inner + WHERE ta.id_agente IN + ( + SELECT ta.id_agente + FROM tagente ta + LEFT JOIN tagent_secondary_group tasg + ON tasg.id_agent = ta.id_agente + $group_inner + WHERE ta.disabled = 0 + $group_acl + $group_search_filter + $condition_inside + ) + AND ta.disabled = 0 + $condition + $agent_search_filter + $agent_status_filter + $module_search_filter + $module_status_filter + GROUP BY ta.id_agente + ORDER BY ta.alias ASC, ta.id_agente ASC + "; - $processed_item = $this->getProcessedItem($item); - $processed_items[] = $processed_item; - } - } - else { - $servers = metaconsole_get_servers(); - - $item_list = array(); - foreach ($servers as $server) { - if (metaconsole_connect($server) != NOERR) - continue; - db_clean_cache(); - - $items = $this->getItems(); - - $processed_items = array(); - foreach ($items as $key => $item) { - - $counters = $this->getCounters($item['id']); - if (!empty($counters)) { - foreach ($counters as $type => $value) { - $item[$type] = $value; - } - } - - $processed_item = $this->getProcessedItem($item, $server); - $processed_items[] = $processed_item; - } - $item_list = array_merge($item_list, $processed_items); - - metaconsole_restore_db(); - } - - $processed_items = $this->getMergedItems($item_list); - } - } - // Agents - else { - if (! is_metaconsole()) { - $items = $this->getItems(); - $this->processAgents($items); - $processed_items = $items; - } - else { - $rootIDs = $this->rootID; - - $items = array(); - foreach ($rootIDs as $serverID => $rootID) { - $server = metaconsole_get_servers($serverID); - if (metaconsole_connect($server) != NOERR) - continue; - db_clean_cache(); - - $this->rootID = $rootID; - $newItems = $this->getItems(); - $this->processAgents($newItems, $server); - $items = array_merge($items, $newItems); - - metaconsole_restore_db(); - } - $this->rootID = $rootIDs; - - if (!empty($items)) - usort($items, array("Tree", "cmpSortNames")); - - $processed_items = $items; - } - } - - $this->tree = $processed_items; + return $sql; } - private function getDataModules() { - $processed_items = array(); - - // Module names - if ($this->id == -1) { - if (! is_metaconsole()) { - $items = $this->getItems(); - - foreach ($items as $key => $item) { - - $counters = $this->getCounters($item['name']); - if (!empty($counters)) { - foreach ($counters as $type => $value) { - $item[$type] = $value; - } - } - - $name = str_replace(array(' ','#','/','.','(',')','¿','?','¡','!'), - array( '_articapandora_'.ord(' ').'_pandoraartica_', - '_articapandora_'.ord('#').'_pandoraartica_', - '_articapandora_'.ord('/').'_pandoraartica_', - '_articapandora_'.ord('.').'_pandoraartica_', - '_articapandora_'.ord('(').'_pandoraartica_', - '_articapandora_'.ord(')').'_pandoraartica_', - '_articapandora_'.ord('¿').'_pandoraartica_', - '_articapandora_'.ord('?').'_pandoraartica_', - '_articapandora_'.ord('¡').'_pandoraartica_', - '_articapandora_'.ord('!').'_pandoraartica_'), - io_safe_output($item['name'])); - - $processed_item = $this->getProcessedItem($item); - $processed_item['id'] = $name; - $processed_item['rootID'] = $name; - - $processed_items[] = $processed_item; - } - } - else { - $servers = metaconsole_get_servers(); - - $item_list = array(); - foreach ($servers as $server) { - if (metaconsole_connect($server) != NOERR) - continue; - db_clean_cache(); - - $items = $this->getItems(); - - $processed_items = array(); - foreach ($items as $key => $item) { - - $counters = $this->getCounters($item['name']); - if (!empty($counters)) { - foreach ($counters as $type => $value) { - $item[$type] = $value; - } - } - - $name = str_replace(array(' ','#','/','.','(',')','¿','?','¡','!'), - array( '_articapandora_'.ord(' ').'_pandoraartica_', - '_articapandora_'.ord('#').'_pandoraartica_', - '_articapandora_'.ord('/').'_pandoraartica_', - '_articapandora_'.ord('.').'_pandoraartica_', - '_articapandora_'.ord('(').'_pandoraartica_', - '_articapandora_'.ord(')').'_pandoraartica_', - '_articapandora_'.ord('¿').'_pandoraartica_', - '_articapandora_'.ord('?').'_pandoraartica_', - '_articapandora_'.ord('¡').'_pandoraartica_', - '_articapandora_'.ord('!').'_pandoraartica_'), - io_safe_output($item['name'])); - - $processed_item = $this->getProcessedItem($item, $server); - $processed_item['id'] = $name; - $processed_item['rootID'] = $name; - - $processed_items[] = $processed_item; - } - $item_list = array_merge($item_list, $processed_items); - - metaconsole_restore_db(); - } - - $processed_items = $this->getMergedItems($item_list); - } + protected function getThirdLevel() { + $sql = $this->getThirdLevelSql(); + $data = db_process_sql($sql); + if (empty($data)) { + $this->tree = array(); + return; } - // Agents - else { - if (! is_metaconsole()) { - $items = $this->getItems(); - $this->processAgents($items); - $processed_items = $items; - } - else { - $rootIDs = $this->rootID; + $data = $this->getProcessedModules($data); + $this->processModules($data); - $items = array(); - foreach ($rootIDs as $serverID => $rootID) { - $server = metaconsole_get_servers($serverID); - if (metaconsole_connect($server) != NOERR) - continue; - db_clean_cache(); - - $this->rootID = $rootID; - $newItems = $this->getItems(); - $this->processAgents($newItems, $server); - $items = array_merge($items, $newItems); - - metaconsole_restore_db(); - } - $this->rootID = $rootIDs; - - if (!empty($items)) - usort($items, array("Tree", "cmpSortNames")); - - $processed_items = $items; - } - } - - $this->tree = $processed_items; + $this->tree = $data; } - private function getDataModuleGroup() { - $processed_items = array(); + protected function getThirdLevelSql() { + // Get the server id + $serverID = $this->serverID; - // Module groups - if ($this->id == -1) { - if (! is_metaconsole()) { - $items = $this->getItems(); + $group_acl = $this->getGroupAclCondition(); + $agent_search_filter = $this->getAgentSearchFilter(); + $agent_status_filter = $this->getAgentStatusFilter(); + $module_search_filter = $this->getModuleSearchFilter(); + $module_status_filter = $this->getModuleStatusFilterFromTestado(); + $agent_filter = "AND ta.id_agente = " . $this->id; + $tag_join = $this->getTagJoin(); - foreach ($items as $key => $item) { + $condition = $this->L2condition; + $inner = $this->L2inner; - $counters = $this->getCounters($item['id']); - if (!empty($counters)) { - foreach ($counters as $type => $value) { - $item[$type] = $value; - } - } + $columns = 'DISTINCT(tam.id_agente_modulo) AS id, tam.nombre AS name, + tam.id_tipo_modulo, tam.id_modulo, tae.estado, tae.datos, + tam.parent_module_id AS parent, tatm.id AS alerts'; - $processed_item = $this->getProcessedItem($item); - $processed_items[] = $processed_item; - } - } - else { - $servers = metaconsole_get_servers(); + // has any of this tags. + $tag_join = ''; - $item_list = array(); - foreach ($servers as $server) { - if (metaconsole_connect($server) != NOERR) - continue; - db_clean_cache(); - - $items = $this->getItems(); - - $processed_items = array(); - foreach ($items as $key => $item) { - - $counters = $this->getCounters($item['id']); - if (!empty($counters)) { - foreach ($counters as $type => $value) { - $item[$type] = $value; - } - } - - $processed_item = $this->getProcessedItem($item, $server); - $processed_items[] = $processed_item; - } - $item_list = array_merge($item_list, $processed_items); - - metaconsole_restore_db(); - } - - $processed_items = $this->getMergedItems($item_list); - } - } - // Agents - else { - if (! is_metaconsole()) { - $items = $this->getItems(); - $this->processAgents($items); - $processed_items = $items; - } - else { - $rootIDs = $this->rootID; - - $items = array(); - foreach ($rootIDs as $serverID => $rootID) { - $server = metaconsole_get_servers($serverID); - if (metaconsole_connect($server) != NOERR) - continue; - db_clean_cache(); - - $this->rootID = $rootID; - $newItems = $this->getItems(); - $this->processAgents($newItems, $server); - $items = array_merge($items, $newItems); - - metaconsole_restore_db(); - } - $this->rootID = $rootIDs; - - if (!empty($items)) - usort($items, array("Tree", "cmpSortNames")); - - $processed_items = $items; - } - } - - $this->tree = $processed_items; - } - - private function getDataOS() { - $processed_items = array(); - - // OS - if ($this->id == -1) { - if (! is_metaconsole()) { - $items = $this->getItems(); - - foreach ($items as $key => $item) { - - $counters = $this->getCounters($item['id']); - if (!empty($counters)) { - foreach ($counters as $type => $value) { - $item[$type] = $value; - } - } - - $processed_item = $this->getProcessedItem($item); - $processed_item['icon'] = $item['os_icon']; - $processed_items[] = $processed_item; - } - } - else { - $servers = metaconsole_get_servers(); - - $item_list = array(); - foreach ($servers as $server) { - if (metaconsole_connect($server) != NOERR) - continue; - db_clean_cache(); - - $items = $this->getItems(); - - $processed_items = array(); - foreach ($items as $key => $item) { - - $counters = $this->getCounters($item['id']); - if (!empty($counters)) { - foreach ($counters as $type => $value) { - $item[$type] = $value; - } - } - - $processed_item = $this->getProcessedItem($item, $server); - $processed_item['icon'] = $item['os_icon']; - $processed_items[] = $processed_item; - } - $item_list = array_merge($item_list, $processed_items); - - metaconsole_restore_db(); - } - - $processed_items = $this->getMergedItems($item_list); - } - } - // Agents - else { - if (! is_metaconsole()) { - $items = $this->getItems(); - $this->processAgents($items); - $processed_items = $items; - } - else { - $rootIDs = $this->rootID; - - $items = array(); - foreach ($rootIDs as $serverID => $rootID) { - $server = metaconsole_get_servers($serverID); - if (metaconsole_connect($server) != NOERR) - continue; - db_clean_cache(); - - $this->rootID = $rootID; - $newItems = $this->getItems(); - $this->processAgents($newItems, $server); - $items = array_merge($items, $newItems); - - metaconsole_restore_db(); - } - $this->rootID = $rootIDs; - - if (!empty($items)) - usort($items, array("Tree", "cmpSortNames")); - - $processed_items = $items; - } - } - - $this->tree = $processed_items; + $sql = "SELECT $columns + FROM tagente_modulo tam + $tag_join + INNER JOIN tagente_estado tae + ON tam.id_agente_modulo = tae.id_agente_modulo + INNER JOIN tagente ta + ON tam.id_agente = ta.id_agente + LEFT JOIN tagent_secondary_group tasg + ON ta.id_agente = tasg.id_agent + LEFT JOIN talert_template_modules tatm + ON tatm.id_agent_module = tam.id_agente_modulo + $inner + WHERE tam.disabled = 0 AND ta.disabled = 0 + $condition + $agent_filter + $group_acl + $agent_search_filter + $agent_status_filter + $module_status_filter + $module_search_filter + ORDER BY tam.nombre ASC, tam.id_agente_modulo ASC"; + return $sql; } public function getJSON() { @@ -2783,112 +948,37 @@ class Tree { return $this->tree; } - static function processCounters(&$groups) { - $all_counters = array(); - foreach ($groups as $id => $group) { - $child_counters = array(); - if (!empty($groups[$id]['children'])) { - $child_counters = Tree::processCounters($groups[$id]['children']); - } - if (!empty($child_counters)) { - foreach($child_counters as $type => $value) { - $groups[$id]['counters'][$type] += $value; - } - } - foreach($groups[$id]['counters'] as $type => $value) { - $all_counters[$type] += $value; - } + static function name2symbol($name) { + return str_replace( + array(' ','#','/','.','(',')','¿','?','¡','!'), + array( + '_articapandora_'.ord(' ').'_pandoraartica_', + '_articapandora_'.ord('#').'_pandoraartica_', + '_articapandora_'.ord('/').'_pandoraartica_', + '_articapandora_'.ord('.').'_pandoraartica_', + '_articapandora_'.ord('(').'_pandoraartica_', + '_articapandora_'.ord(')').'_pandoraartica_', + '_articapandora_'.ord('¿').'_pandoraartica_', + '_articapandora_'.ord('?').'_pandoraartica_', + '_articapandora_'.ord('¡').'_pandoraartica_', + '_articapandora_'.ord('!').'_pandoraartica_' + ), + io_safe_output($name) + ); + } + + static function symbol2name($name) { + $symbols = ' !"#$%&\'()*+,./:;<=>?@[\\]^{|}~'; + for ($i = 0; $i < strlen($symbols); $i++) { + $name = str_replace('_articapandora_' . + ord(substr($symbols, $i, 1)) .'_pandoraartica_', + substr($symbols, $i, 1), $name); } - return $all_counters; + return io_safe_input($name); } protected function getProcessedModules($modules_tree) { - $tree_modules = array(); - $new_modules_root = array_filter($modules_tree, function ($module) { - return (isset($module['parent']) && ($module['parent'] == 0)); - }); - - $new_modules_child = array_filter($modules_tree, function ($module) { - return (isset($module['parent']) && ($module['parent'] != 0)); - }); - - while (!empty($new_modules_child)) { - foreach ($new_modules_child as $i => $child) { - Tree::recursive_modules_tree_view($new_modules_root, $new_modules_child, $i, $child); - } - } - - foreach ($new_modules_root as $m) { - $tree_modules[] = $m; - } - - return $tree_modules; - } - - protected function getGroupCounters($group_id) { - global $config; - static $group_stats = false; - // FIXME: Avoid to use cache when secondary groups is used - if (enterprise_hook('agents_is_using_secondary_groups')) { - return $this->getCounters($group_id); - } - # Do not use the group stat cache when using tags or real time group stats. - if ($config['realtimestats'] == 1 || - (isset($this->userGroups[$group_id]['tags']) && $this->userGroups[$group_id]['tags'] != "") || - !empty($this->filter['searchAgent']) ) { - return $this->getCounters($group_id); - } - - # Update the group stat cache. - if ( $group_stats === false) { - $group_stats = array(); - $stats = db_get_all_rows_sql('SELECT * FROM tgroup_stat'); - foreach ($stats as $group) { - if ($group['modules'] > 0) { - $group_stats[$group['id_group']]['total_count'] = $group['modules'] > 0 ? $group['agents'] : 0; - $group_stats[$group['id_group']]['total_critical_count'] = $group['critical']; - $group_stats[$group['id_group']]['total_unknown_count'] = $group['unknown']; - $group_stats[$group['id_group']]['total_warning_count'] = $group['warning']; - if($this->filter['show_not_init_modules']){ - $group_stats[$group['id_group']]['total_not_init_count'] = $group['non-init']; - } - else{ - $group_stats[$group['id_group']]['total_not_init_count'] = 0; - } - $group_stats[$group['id_group']]['total_normal_count'] = $group['normal']; - $group_stats[$group['id_group']]['total_fired_count'] = $group['alerts_fired']; - } - # Skip groups without modules. - else { - $group_stats[$group['id_group']]['total_count'] = 0; - $group_stats[$group['id_group']]['total_critical_count'] = 0; - $group_stats[$group['id_group']]['total_unknown_count'] = 0; - $group_stats[$group['id_group']]['total_warning_count'] = 0; - $group_stats[$group['id_group']]['total_not_init_count'] = 0; - $group_stats[$group['id_group']]['total_normal_count'] = 0; - $group_stats[$group['id_group']]['total_fired_count'] = 0; - } - } - } - - if ($group_stats !== false && isset($group_stats[$group_id])) { - return $group_stats[$group_id]; - } - - return $this->getCounters($group_id); - } - - static function recursive_modules_tree_view (&$new_modules, &$new_modules_child, $i, $child) { - foreach ($new_modules as $index => $module) { - if ($module['id'] == $child['parent']) { - $new_modules[$index]['children'][] = $child; - unset($new_modules_child[$i]); - break; - } - else if (isset($new_modules[$index]['children'])) { - Tree::recursive_modules_tree_view ($new_modules[$index]['children'], $new_modules_child, $i, $child); - } - } + return $modules_tree; } } diff --git a/pandora_console/include/class/TreeGroup.class.php b/pandora_console/include/class/TreeGroup.class.php new file mode 100644 index 0000000000..af5542e396 --- /dev/null +++ b/pandora_console/include/class/TreeGroup.class.php @@ -0,0 +1,449 @@ +L1fieldName = "id_group"; + $this->L1extraFields = array( + "tg.nombre AS `name`", + "tg.icon", + "tg.id_grupo AS gid" + ); + + $this->L2conditionInside = "AND ( + ta.id_grupo = " . $this->id . " + OR tasg.id_group = " . $this->id . " + )"; + } + + public function setPropagateCounters($value) { + $this->propagateCounters = (bool)$value; + } + + protected function getData() { + if ($this->id == -1) { + $this->getFirstLevel(); + } elseif ($this->type == 'group') { + $this->getSecondLevel(); + } elseif ($this->type == 'agent') { + $this->getThirdLevel(); + } + } + + protected function getGroupSearchFilter() { + return ""; + } + + protected function getFirstLevel() { + $processed_items = $this->getProcessedGroups(); + + if (!empty($processed_items)) { + // Filter by group name. This should be done after rerieving the items cause we need the possible items descendants + if (!empty($this->filter['searchGroup'])) { + // Save the groups which intersect with the user groups + $groups = db_get_all_rows_filter('tgrupo', array('nombre' => '%' . $this->filter['searchGroup'] . '%')); + if ($groups == false) $groups = array(); + $userGroupsACL = $this->userGroupsACL; + $ids_hash = array_reduce($groups, function ($userGroups, $group) use ($userGroupsACL) { + $group_id = $group['id_grupo']; + if (isset($userGroupsACL[$group_id])) { + $userGroups[$group_id] = $userGroupsACL[$group_id]; + } + + return $userGroups; + }, array()); + + $result = self::extractGroupsWithIDs($processed_items, $ids_hash); + + $processed_items = ($result === false) ? array() : $result; + } + + // groupID filter. To access the view from tactical views f.e. + if (!empty($this->filter['groupID'])) { + $result = self::extractItemWithID($processed_items, $this->filter['groupID'], "group", $this->strictACL); + + $processed_items = ($result === false) ? array() : array($result); + } + } + + $this->tree = $processed_items; + } + + protected function getProcessedGroups () { + $processed_groups = array(); + // Index and process the groups + $groups = $this->getGroupCounters(); + + // If user have not permissions in parent, set parent node to 0 (all) + // Avoid to do foreach for admins + if (!users_can_manage_group_all("AR")) { + foreach ($groups as $id => $group) { + if (!isset($this->userGroups[$groups[$id]['parent']])) { + $groups[$id]['parent'] = 0; + } + } + } + // Build the group hierarchy + foreach ($groups as $id => $group) { + if (isset($groups[$id]['parent']) && ($groups[$id]['parent'] != 0)) { + $parent = $groups[$id]['parent']; + // Parent exists + if (!isset($groups[$parent]['children'])) { + $groups[$parent]['children'] = array(); + } + // Store a reference to the group into the parent + $groups[$parent]['children'][] = &$groups[$id]; + // This group was introduced into a parent + $groups[$id]['have_parent'] = true; + } + } + // Sort the children groups + foreach ($groups as $id => $group) { + if (isset($groups[$id]['children'])) { + usort($groups[$id]['children'], array("Tree", "cmpSortNames")); + } + } + //Filter groups and eliminates the reference to children groups out of her parent + $groups = array_filter($groups, function ($group) { + return !$group['have_parent']; + }); + // Propagate child counters to her parents + if ($this->propagateCounters) { + TreeGroup::processCounters($groups); + // Filter groups and eliminates the reference to empty groups + $groups = TreeGroup::deleteEmptyGroups($groups); + } else { + $groups = TreeGroup::deleteEmptyGroupsNotPropagate($groups); + } + + usort($groups, array("Tree", "cmpSortNames")); + return $groups; + } + + protected function getGroupCounters() { + $fields = $this->getFirstLevelFields(); + $inside_fields = $this->getFirstLevelFieldsInside(); + + $group_acl = ""; + $secondary_group_acl = ""; + if (!users_can_manage_group_all("AR")) { + $user_groups_str = implode(",", $this->userGroupsArray); + $group_acl = " AND ta.id_grupo IN ($user_groups_str)"; + $secondary_group_acl = " AND tasg.id_group IN ($user_groups_str)"; + } + $agent_search_filter = $this->getAgentSearchFilter(); + $agent_search_filter = preg_replace("/%/", "%%", $agent_search_filter); + $agent_status_filter = $this->getAgentStatusFilter(); + $module_status_filter = $this->getModuleStatusFilter(); + + $module_search_inner = ""; + $module_search_filter = ""; + if (!empty($this->filter['searchModule'])) { + $module_search_inner = " + INNER JOIN tagente_modulo tam + ON ta.id_agente = tam.id_agente + INNER JOIN tagente_estado tae + ON tae.id_agente_modulo = tam.id_agente_modulo"; + $module_search_filter = "AND tam.disabled = 0 + AND tam.nombre LIKE '%%" . $this->filter['searchModule'] . "%%' " . + $this->getModuleStatusFilterFromTestado() + ; + } + + $table = is_metaconsole() ? "tmetaconsole_agent" : "tagente"; + $table_sec = is_metaconsole() ? "tmetaconsole_agent_secondary_group" : "tagent_secondary_group"; + + $sql_model = "SELECT %s FROM + ( + SELECT COUNT(DISTINCT(ta.id_agente)) AS total, id_grupo AS g + FROM $table ta + $module_search_inner + WHERE ta.disabled = 0 + %s + $agent_search_filter + $agent_status_filter + $module_status_filter + $module_search_filter + $group_acl + GROUP BY id_grupo + UNION ALL + SELECT COUNT(DISTINCT(ta.id_agente)) AS total, id_group AS g + FROM $table ta INNER JOIN $table_sec tasg + ON ta.id_agente = tasg.id_agent + $module_search_inner + WHERE ta.disabled = 0 + %s + $agent_search_filter + $agent_status_filter + $module_status_filter + $module_search_filter + $secondary_group_acl + GROUP BY id_group + ) x GROUP BY g"; + $sql_array = array(); + foreach ($inside_fields as $inside_field) { + $sql_array[] = sprintf( + $sql_model, + $inside_field['header'], + $inside_field['condition'], + $inside_field['condition'] + ); + } + $sql = "SELECT $fields FROM (" . implode(" UNION ALL ", $sql_array) . ") x2 + RIGHT JOIN tgrupo tg + ON x2.g = tg.id_grupo + GROUP BY tg.id_grupo"; + $stats = db_get_all_rows_sql($sql); + + $group_stats = array(); + foreach ($stats as $group) { + $group_stats[$group['gid']]['total_count'] = (int)$group['total_count']; + $group_stats[$group['gid']]['total_critical_count'] = (int)$group['total_critical_count']; + $group_stats[$group['gid']]['total_unknown_count'] = (int)$group['total_unknown_count']; + $group_stats[$group['gid']]['total_warning_count'] = (int)$group['total_warning_count']; + $group_stats[$group['gid']]['total_not_init_count'] = (int)$group['total_not_init_count']; + $group_stats[$group['gid']]['total_normal_count'] = (int)$group['total_normal_count']; + $group_stats[$group['gid']]['total_fired_count'] = (int)$group['total_alerts_count']; + $group_stats[$group['gid']]['name'] = $group['name']; + $group_stats[$group['gid']]['parent'] = $group['parent']; + $group_stats[$group['gid']]['icon'] = $group['icon']; + $group_stats[$group['gid']]['id'] = $group['gid']; + $group_stats[$group['gid']] = $this->getProcessedItem($group_stats[$group['gid']]); + } + + return $group_stats; + } + + protected function getFirstLevelFields() { + $fields = parent::getFirstLevelFields(); + $parent = $this->getDisplayHierarchy() ? 'tg.parent' : '0 as parent'; + return "$fields, $parent"; + } + + protected function getProcessedModules($modules_tree) { + + $groups = array(); + foreach ($modules_tree as $group) { + $groups[$group["id"]] = $group; + } + + // Build the module hierarchy + foreach ($groups as $id => $group) { + if (isset($groups[$id]['parent']) && ($groups[$id]['parent'] != 0)) { + $parent = $groups[$id]['parent']; + // Parent exists + if (!isset($groups[$parent]['children'])) { + $groups[$parent]['children'] = array(); + } + // Store a reference to the group into the parent + $groups[$parent]['children'][] = &$groups[$id]; + // This group was introduced into a parent + $groups[$id]['have_parent'] = true; + } + } + + // Sort the children groups + foreach ($groups as $id => $group) { + if (isset($groups[$id]['children'])) { + usort($groups[$id]['children'], array("Tree", "cmpSortNames")); + } + } + //Filter groups and eliminates the reference to children groups out of her parent + $groups = array_filter($groups, function ($group) { + return !$group['have_parent']; + }); + + return array_values($groups); + } + + // FIXME: Hierarchy lops is broken + protected function getProcessedModules_old($modules_tree) { + + $tree_modules = array(); + $new_modules_root = array_filter($modules_tree, function ($module) { + return (isset($module['parent']) && ($module['parent'] == 0)); + }); + + $new_modules_child = array_filter($modules_tree, function ($module) { + return (isset($module['parent']) && ($module['parent'] != 0)); + }); + + $i = 0; + while (!empty($new_modules_child)) { + foreach ($new_modules_child as $i => $child) { + TreeGroup::recursive_modules_tree_view($new_modules_root, $new_modules_child, $i, $child); + } + } + + foreach ($new_modules_root as $m) { + $tree_modules[] = $m; + } + return $tree_modules; + } + + // FIXME with getProcessedModules_old + static function recursive_modules_tree_view (&$new_modules, &$new_modules_child, $i, $child) { + foreach ($new_modules as $index => $module) { + if ($module['id'] == $child['parent']) { + $new_modules[$index]['children'][] = $child; + unset($new_modules_child[$i]); + break; + } + else if (isset($new_modules[$index]['children'])) { + TreeGroup::recursive_modules_tree_view ($new_modules[$index]['children'], $new_modules_child, $i, $child); + } + } + } + + static function processCounters(&$groups) { + $all_counters = array(); + foreach ($groups as $id => $group) { + $child_counters = array(); + if (!empty($groups[$id]['children'])) { + $child_counters = TreeGroup::processCounters($groups[$id]['children']); + } + if (!empty($child_counters)) { + foreach($child_counters as $type => $value) { + $groups[$id]['counters'][$type] += $value; + } + } + foreach($groups[$id]['counters'] as $type => $value) { + $all_counters[$type] += $value; + } + } + return $all_counters; + } + + /** + * @brief Recursive function to remove the empty groups + * + * @param groups All groups structure + * + * @return new_groups A new groups structure without empty groups + */ + protected static function deleteEmptyGroups ($groups) { + $new_groups = array(); + foreach ($groups as $group) { + // If a group is empty, do not add to new_groups. + if (!isset($group['counters']['total']) || $group['counters']['total'] == 0) { + continue; + } + // Tray to remove the children groups + if (!empty($group['children'])) { + $children = TreeGroup::deleteEmptyGroups ($group['children']); + if (empty($children)) unset($group['children']); + else $group['children'] = $children; + } + $new_groups[] = $group; + } + return $new_groups; + } + + protected static function deleteEmptyGroupsNotPropagate ($groups) { + $new_groups = array(); + foreach ($groups as $group) { + // Tray to remove the children groups + if (!empty($group['children'])) { + $children = TreeGroup::deleteEmptyGroupsNotPropagate ($group['children']); + if (empty($children)) { + unset($group['children']); + // If a group is empty, do not add to new_groups. + if (isset($group['counters']['total']) && $group['counters']['total'] != 0) { + $new_groups[] = $group; + } + } else { + $group['children'] = $children; + $new_groups[] = $group; + } + } else { + // If a group is empty, do not add to new_groups. + if (isset($group['counters']['total']) && $group['counters']['total'] != 0) { + $new_groups[] = $group; + } + } + } + return $new_groups; + } + + private static function extractGroupsWithIDs ($groups, $ids_hash) { + $result_groups = array(); + foreach ($groups as $group) { + if (isset($ids_hash[$group['id']])) { + $result_groups[] = $group; + } + else if (!empty($group['children'])) { + $result = self::extractGroupsWithIDs($group['children'], $ids_hash); + + // Item found on children + if (!empty($result)) { + $result_groups = array_merge($result_groups, $result); + } + } + } + + return $result_groups; + } + + private static function extractItemWithID ($items, $item_id, $item_type = "group", $strictACL = false) { + foreach ($items as $item) { + if ($item["type"] != $item_type) + continue; + + // Item found + if ($strictACL && is_metaconsole()) { + foreach ($item["id"] as $server_id => $id) { + if ($id == $item_id) + return $item; + } + } + else { + if ($item["id"] == $item_id) + return $item; + } + + if ($item["type"] == "group" && !empty($item["children"])) { + $result = self::extractItemWithID($item["children"], $item_id, $item_type, $strictACL); + + // Item found on children + if ($result !== false) + return $result; + } + } + + // Item not found + return false; + } + + protected function getDisplayHierarchy() { + return $this->filter['searchHirearchy'] || + (empty($this->filter['searchAgent']) && empty($this->filter['searchModule'])); + } + +} + +?> + diff --git a/pandora_console/include/class/TreeGroupEdition.class.php b/pandora_console/include/class/TreeGroupEdition.class.php new file mode 100644 index 0000000000..dea62da238 --- /dev/null +++ b/pandora_console/include/class/TreeGroupEdition.class.php @@ -0,0 +1,108 @@ +id == -1) { + $this->getFirstLevel(); + } + } + + protected function getProcessedGroups () { + $processed_groups = array(); + // Index and process the groups + $groups = $this->getGroupCounters(); + + // If user have not permissions in parent, set parent node to 0 (all) + // Avoid to do foreach for admins + if (!users_can_manage_group_all("AR")) { + foreach ($groups as $id => $group) { + if (!isset($this->userGroups[$groups[$id]['parent']])) { + $groups[$id]['parent'] = 0; + } + } + } + // Build the group hierarchy + foreach ($groups as $id => $group) { + if (isset($groups[$id]['parent']) && ($groups[$id]['parent'] != 0)) { + $parent = $groups[$id]['parent']; + // Parent exists + if (!isset($groups[$parent]['children'])) { + $groups[$parent]['children'] = array(); + } + // Store a reference to the group into the parent + $groups[$parent]['children'][] = &$groups[$id]; + // This group was introduced into a parent + $groups[$id]['have_parent'] = true; + } + } + + // Sort the children groups + foreach ($groups as $id => $group) { + if (isset($groups[$id]['children'])) { + usort($groups[$id]['children'], array("Tree", "cmpSortNames")); + } + } + //Filter groups and eliminates the reference to children groups out of her parent + $groups = array_filter($groups, function ($group) { + return !$group['have_parent']; + }); + + usort($groups, array("Tree", "cmpSortNames")); + return $groups; + } + + + protected function getGroupCounters() { + $messages = array( + 'confirm' => __('Confirm'), + 'cancel' => __('Cancel'), + 'messg' => __('Are you sure?') + ); + $sql = "SELECT id_grupo AS gid, + nombre as name, parent, icon + FROM tgrupo + "; + + $stats = db_get_all_rows_sql($sql); + $group_stats = array(); + foreach ($stats as $group) { + $group_stats[$group['gid']]['name'] = $group['name']; + $group_stats[$group['gid']]['parent'] = $group['parent']; + $group_stats[$group['gid']]['icon'] = $group['icon']; + $group_stats[$group['gid']]['id'] = $group['gid']; + $group_stats[$group['gid']]['type'] = 'group'; + + $group_stats[$group['gid']] = $this->getProcessedItem($group_stats[$group['gid']]); + $group_stats[$group['gid']]['delete']['messages'] = $messages; + $group_stats[$group['gid']]['edit'] = 1; + $group_stats[$group['gid']]['alerts'] = ''; + } + + return $group_stats; + } +} + +?> + diff --git a/pandora_console/include/class/TreeModule.class.php b/pandora_console/include/class/TreeModule.class.php new file mode 100644 index 0000000000..45f9259854 --- /dev/null +++ b/pandora_console/include/class/TreeModule.class.php @@ -0,0 +1,60 @@ +L1fieldName = 'name'; + $this->L1fieldNameSql = 'tam.nombre'; + $this->L1inner = ''; + $this->L1orderByFinal = 'name'; + + $this->L2condition = "AND tam.nombre = '" . $this->symbol2name($this->rootID) . "'"; + } + + protected function getData() { + if ($this->id == -1) { + $this->getFirstLevel(); + } elseif ($this->type == 'module') { + $this->getSecondLevel(); + } elseif ($this->type == 'agent') { + $this->getThirdLevel(); + } + } + + protected function getProcessedItemsFirstLevel($items){ + $processed_items = array(); + foreach ($items as $key => $item) { + $name = $this->name2symbol($item['name']); + $processed_item = $this->getProcessedItem($item); + $processed_item['id'] = $name; + $processed_item['rootID'] = $name; + $processed_items[] = $processed_item; + } + return $processed_items; + } +} + +?> + diff --git a/pandora_console/include/class/TreeModuleGroup.class.php b/pandora_console/include/class/TreeModuleGroup.class.php new file mode 100644 index 0000000000..06bc8fb6ff --- /dev/null +++ b/pandora_console/include/class/TreeModuleGroup.class.php @@ -0,0 +1,49 @@ +L1fieldName = 'id_module_group'; + $this->L1fieldNameSql = 'tam.id_module_group'; + $this->L1extraFields = array('tmg.name', 'tmg.id_mg AS id'); + $this->L1inner = 'INNER JOIN tmodule_group tmg ON tmg.id_mg = x2.g'; + $this->L1orderByFinal = 'tmg.name'; + + $this->L2condition = "AND tam.id_module_group = " . $this->rootID; + } + + protected function getData() { + if ($this->id == -1) { + $this->getFirstLevel(); + } elseif ($this->type == 'module_group') { + $this->getSecondLevel(); + } elseif ($this->type == 'agent') { + $this->getThirdLevel(); + } + } +} + +?> + diff --git a/pandora_console/include/class/TreeOS.class.php b/pandora_console/include/class/TreeOS.class.php new file mode 100644 index 0000000000..8d7724f209 --- /dev/null +++ b/pandora_console/include/class/TreeOS.class.php @@ -0,0 +1,49 @@ +L1fieldName = 'id_os'; + $this->L1fieldNameSql = 'ta.id_os'; + $this->L1extraFields = array('tco.name', 'tco.id_os AS id', 'tco.icon_name AS iconHTML'); + $this->L1inner = 'INNER JOIN tconfig_os tco ON tco.id_os = x2.g'; + $this->L1orderByFinal = 'tco.name'; + + $this->L2condition = "AND ta.id_os = " . $this->rootID; + } + + protected function getData() { + if ($this->id == -1) { + $this->getFirstLevel(); + } elseif ($this->type == 'os') { + $this->getSecondLevel(); + } elseif ($this->type == 'agent') { + $this->getThirdLevel(); + } + } +} + +?> + diff --git a/pandora_console/include/class/TreeTag.class.php b/pandora_console/include/class/TreeTag.class.php new file mode 100644 index 0000000000..c6562db725 --- /dev/null +++ b/pandora_console/include/class/TreeTag.class.php @@ -0,0 +1,54 @@ +L1fieldName = 'id_tag'; + $this->L1fieldNameSql = 'ttm.id_tag'; + $this->L1innerInside = ' + INNER JOIN ttag_module ttm + ON ttm.id_agente_modulo = tam.id_agente_modulo + '; + $this->L1extraFields = array('tt.name', 'tt.id_tag AS id'); + $this->L1inner = 'INNER JOIN ttag tt ON tt.id_tag = x2.g'; + $this->L1orderByFinal = 'tt.name'; + + $this->L2condition = "AND ttm.id_tag = " . $this->rootID; + $this->L2inner = $this->L1innerInside; + } + + protected function getData() { + if ($this->id == -1) { + $this->getFirstLevel(); + } elseif ($this->type == 'tag') { + $this->getSecondLevel(); + } elseif ($this->type == 'agent') { + $this->getThirdLevel(); + } + } +} + +?> + diff --git a/pandora_console/include/config_process.php b/pandora_console/include/config_process.php index 6ac53b997a..eee0eda964 100644 --- a/pandora_console/include/config_process.php +++ b/pandora_console/include/config_process.php @@ -22,8 +22,8 @@ /** * Pandora build version and version */ -$build_version = 'PC180904'; -$pandora_version = 'v7.0NG.726'; +$build_version = 'PC180918'; +$pandora_version = 'v7.0NG.727'; // Do not overwrite default timezone set if defined. $script_tz = @date_default_timezone_get(); diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index 7982e62995..e2c5c742a3 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -3274,7 +3274,7 @@ function generator_chart_to_pdf($type_graph_pdf, $params, $params_combined = fal $img_url = $config["homeurl"] . "attachment/" . $img_file; $width_img = 500; - $height_img = (isset($config['graph_image_height'])) ? $config['graph_image_height'] : 350; + $height_img = (isset($config['graph_image_height'])) ? $config['graph_image_height'] : 280; $params['height'] = $height_img; @@ -3344,4 +3344,27 @@ function get_copyright_notice () { return $stored_name; } +/** + * Generate a random code to prevent cross site request fogery attacks + * + * @return string Generated code + */ +function generate_csrf_code() { + // Start session to make this var permanent + session_start(); + $_SESSION['csrf_code'] = md5(uniqid(mt_rand(), true)); + session_write_close(); + return $_SESSION['csrf_code']; +} + +/** + * Validate the CSRF code + * + * @return bool True if code is valid + */ +function validate_csrf_code() { + $code = get_parameter('csrf_code'); + return isset($code) && isset($_SESSION['csrf_code']) + && $_SESSION['csrf_code'] == $code; +} ?> diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index 547c037ee4..5bdd03a418 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -966,12 +966,12 @@ function agents_get_group_agents ( $filter['order'] = 'alias'; if (is_metaconsole()) { - $table_name = 'tmetaconsole_agent LEFT JOIN tmetaconsole_agent_secondary_group ON ta.id_agente = tasg.id_agent'; + $table_name = 'tmetaconsole_agent ta LEFT JOIN tmetaconsole_agent_secondary_group tasg ON ta.id_agente = tasg.id_agent'; $fields = array( - 'id_tagente AS id_agente', + 'ta.id_tagente AS id_agente', 'alias', - 'id_tmetaconsole_setup AS id_server' + 'ta.id_tmetaconsole_setup AS id_server' ); } else { @@ -2684,6 +2684,9 @@ function agents_generate_name ($alias, $address = '') { * @return Array with the main and secondary groups */ function agents_get_all_groups_agent ($id_agent, $group = false) { + // Cache the agent id groups + static $cache = array(); + if (isset($cache[$id_agent])) return $cache[$id_agent]; // Get the group if is not defined if ($group === false) $group = agents_get_agent_group($id_agent); @@ -2697,6 +2700,7 @@ function agents_get_all_groups_agent ($id_agent, $group = false) { // Add a list of groups $secondary_groups['plain'][] = $group; + $cache[$id_agent] = $secondary_groups['plain']; return $secondary_groups['plain']; } @@ -2738,4 +2742,33 @@ function agents_check_access_agent ($id_agent, $access = "AR") { // Return null otherwise return null; } + +function agents_get_status_clause($state, $show_not_init = true) { + switch ($state) { + case AGENT_STATUS_CRITICAL: + return "(ta.critical_count > 0)"; + case AGENT_STATUS_WARNING: + return "(ta.warning_count > 0 AND ta.critical_count = 0)"; + case AGENT_STATUS_UNKNOWN: + return "( + ta.critical_count = 0 AND ta.warning_count = 0 AND ta.unknown_count > 0 + )"; + case AGENT_STATUS_NOT_INIT: + return $show_not_init + ? "(ta.total_count = ta.notinit_count)" + : "1=0"; + case AGENT_STATUS_NORMAL: + return "( + ta.critical_count = 0 AND ta.warning_count = 0 + AND ta.unknown_count = 0 AND ta.normal_count > 0 + )"; + case AGENT_STATUS_ALL: + default: + return $show_not_init + ? "1=1" + : "(ta.total_count <> ta.notinit_count)"; + } + // If the state is not an expected state, return no condition + return "1=1"; +} ?> diff --git a/pandora_console/include/functions_alerts.php b/pandora_console/include/functions_alerts.php index 4d89dca614..84419f5ab4 100644 --- a/pandora_console/include/functions_alerts.php +++ b/pandora_console/include/functions_alerts.php @@ -50,7 +50,10 @@ function alerts_get_alerts($id_group = 0, $free_search = "", $status = "all", $s $id_groups = array_keys($groups); - $group_query = " AND t3.id_grupo IN (" . implode(',', $id_groups) . ") "; + $group_query = " AND ( + t3.id_grupo IN (" . implode(',', $id_groups) . ") + OR tasg.id_group IN (" . implode(',', $id_groups) . ") + )"; } else { $group_query = ""; @@ -103,6 +106,8 @@ function alerts_get_alerts($id_group = 0, $free_search = "", $status = "all", $s ON t0.id_agent_module = t2.id_agente_modulo INNER JOIN tagente t3 ON t2.id_agente = t3.id_agente + LEFT JOIN tagent_secondary_group tasg + ON tasg.id_agent = t3.id_agente WHERE 1=1 ' . $status_query . ' ' . $standby_query . ' ' . $group_query . ' AND (t1.name LIKE "%' . $free_search . '%" @@ -1633,23 +1638,13 @@ function get_agent_alert_fired ($id_agent, $id_alert, $period, $date = 0) { * * @return array An array with all the events happened. */ -function get_module_alert_fired ($id_agent_module, $id_alert, $period, $date = 0) { +function get_module_alert_fired ($id_agent_module, $id_alert) { - if (!is_numeric ($date)) { - $date = time_w_fixed_tz($date); - } - if (empty ($date)) { - $date = get_system_time(); - } - - $datelimit = $date - $period; - - $sql = sprintf ('SELECT timestamp + $sql = sprintf ('SELECT * FROM tevento - WHERE id_agentmodule = %d AND utimestamp > %d - AND utimestamp <= %d + WHERE id_agentmodule = %d AND id_alert_am = %d - ORDER BY timestamp DESC', $id_agent_module, $datelimit, $date, $id_alert); + ORDER BY timestamp DESC', $id_agent_module, $id_alert); return db_get_all_rows_sql ($sql); } @@ -1792,9 +1787,12 @@ function get_group_alerts($id_group, $filter = '', $options = false, FROM tagente_modulo WHERE delete_pending = 0 AND id_agente IN (SELECT id_agente - FROM tagente + FROM tagente ta + LEFT JOIN tagent_secondary_group tasg + ON ta.id_agente = tasg.id_agent WHERE - id_grupo IN (' . implode(',', $id_group) . '))'; + id_grupo IN (' . implode(',', $id_group) . ') + OR id_group IN (' . implode(',', $id_group) . '))'; } } @@ -1861,6 +1859,8 @@ function get_group_alerts($id_group, $filter = '', $options = false, ON talert_template_modules.id_agent_module = t2.id_agente_modulo INNER JOIN tagente t3 ON t2.id_agente = t3.id_agente + LEFT JOIN tagent_secondary_group tasg + ON tasg.id_agent = t2.id_agente INNER JOIN talert_templates t4 ON talert_template_modules.id_alert_template = t4.id WHERE id_agent_module in (%s) %s %s %s", diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index 76968e1e75..189cc4203b 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -30,6 +30,7 @@ include_once($config['homedir'] . "/include/functions_network_components.php"); include_once($config['homedir'] . "/include/functions_netflow.php"); include_once($config['homedir'] . "/include/functions_servers.php"); include_once($config['homedir'] . "/include/functions_planned_downtimes.php"); +include_once($config['homedir'] . "/include/functions_db.php"); enterprise_include_once ('include/functions_local_components.php'); enterprise_include_once ('include/functions_events.php'); enterprise_include_once ('include/functions_agents.php'); @@ -11397,8 +11398,282 @@ function util_api_check_agent_and_print_error($id_agent, $returnType, $access = return false; } +function api_get_user_info($thrash1, $thrash2, $other, $returnType) { + if (defined ('METACONSOLE')) { + return; + } + + $separator = ';'; + + $other = json_decode(base64_decode($other['data']),true); + + $sql = 'select * from tusuario where id_user = "'.$other[0]['id_user'].'" and password = "'.$other[0]['password'].'"'; + + $user_info = db_get_all_rows_sql($sql); + + if (count($user_info) > 0 and $user_info !== false) { + $data = array('type' => 'array', 'data' => $user_info); + returnData($returnType, $data, $separator); + } + else { + return 0; + } +} +/* + +This function receives different parameters to process one of these actions the logging process in our application from the records in the audit of pandora fms, to avoid concurrent access of administrator users, and optionally to prohibit access to non-administrator users: + +Parameter 0 + +The User ID that attempts the action is used to check the status of the application for access. + +Parameter 1 + +Login, logout, exclude, browse. + +These requests receive a response that we can treat as we consider, this function only sends answers, does not perform any action in your application, you must customize them. + +Login action: free (register our access), taken, denied (if you are not an administrator user and parameter four is set to 1, register the expulsion). + +Browse action: It has the same answers as login, but does not register anything in the audit. + +Logout action: It records the deslogeo but does not send a response. + +All other actions do not return a response, + +Parameter 2 + +IP address of the application is also used to check the status of the application for access. + +Parameter 3 + +Name of the application, it is also used to check the status of the application for access. + +Parameter 4 + +If you mark 1 you will avoid the access to the non-administrators users, returning the response `denied' and registering that expulsion in the audit of pandora fms. + +*/ + + + +function api_set_access_process($thrash1, $thrash2, $other, $returnType) { + if (defined ('METACONSOLE')) { + return; + } + + $other['data'] = explode('|',$other['data']); + + $sql = 'select id_usuario,utimestamp from tsesion where descripcion like "%'.$other['data'][2].'%" and accion like "%'.$other['data'][3].' Logon%" and id_usuario IN (select id_user from tusuario where is_admin = 1) and id_usuario != "'.$other['data'][0].'" order by utimestamp DESC limit 1'; + $audit_concurrence = db_get_all_rows_sql($sql); + $sql_user = 'select id_usuario,utimestamp from tsesion where descripcion like "%'.$other['data'][2].'%" and accion like "%'.$other['data'][3].' Logon%" and id_usuario IN (select id_user from tusuario where is_admin = 1) and id_usuario = "'.$other['data'][0].'" order by utimestamp DESC limit 1'; + $audit_concurrence_user = db_get_all_rows_sql($sql_user); + $sql2 = 'select id_usuario,utimestamp,accion from tsesion where descripcion like "%'.$other['data'][2].'%" and accion like "%'.$other['data'][3].' Logoff%" and id_usuario = "'.$audit_concurrence[0]['id_usuario'].'" order by utimestamp DESC limit 1'; + $audit_concurrence_2 = db_get_all_rows_sql($sql2); + + //The user trying to log in is an administrator + if(users_is_admin($other['data'][0])){ + //The admin user is trying to login + if($other['data'][1] == 'login'){ + // Check if there is an administrator user logged in prior to our last login + if($audit_concurrence[0]['utimestamp'] > $audit_concurrence_user[0]['utimestamp']){ + // Check if the administrator user logged in later to us has unlogged and left the node free + if($audit_concurrence[0]['utimestamp'] > $audit_concurrence_2[0]['utimestamp']){ + // The administrator user logged in later has not yet unlogged + returnData('string', array('type' => 'string', 'data' => 'taken')); + } + else{ + // The administrator user logged in later has already unlogged + returnData('string', array('type' => 'string', 'data' => 'free')); + } + } + else{ + // There is no administrator user who has logged in since then to log us in. + db_pandora_audit($other['data'][3].' Logon', 'Logged in '.$other['data'][3].' node '.$other['data'][2] , $other['data'][0]); + returnData('string', array('type' => 'string', 'data' => 'free')); + } + + } + elseif ($other['data'][1] == 'logout') { + // The administrator user wants to log out + db_pandora_audit($other['data'][3].' Logoff', 'Logout from '.$other['data'][3].' node '.$other['data'][2], $other['data'][0]); + } + elseif ($other['data'][1] == 'exclude') { + // The administrator user has ejected another administrator user who was logged in + db_pandora_audit($other['data'][3].' Logon', 'Logged in '.$other['data'][3].' node '.$other['data'][2] , $other['data'][0]); + db_pandora_audit($other['data'][3].' Logoff', 'Logout from '.$other['data'][3].' node '.$other['data'][2] , $audit_concurrence[0]['id_usuario']); + + } + //The admin user is trying to browse + elseif ($other['data'][1] == 'browse') { + // Check if there is an administrator user logged in prior to our last login + if($audit_concurrence[0]['utimestamp'] > $audit_concurrence_user[0]['utimestamp']){ + // Check if the administrator user logged in later to us has unlogged and left the node free + if($audit_concurrence[0]['utimestamp'] > $audit_concurrence_2[0]['utimestamp']){ + // The administrator user logged in later has not yet unlogged + returnData('string', array('type' => 'string', 'data' => $audit_concurrence[0]['id_usuario'])); + } + else{ + // The administrator user logged in later has already unlogged + returnData('string', array('type' => 'string', 'data' => 'free')); + } + } + else{ + // There is no administrator user who has logged in since then to log us in. + returnData('string', array('type' => 'string', 'data' => 'free')); + } + + } + elseif ($other['data'][1] == 'cancelled'){ + //The administrator user tries to log in having another administrator logged in, but instead of expelling him he cancels his log in. + db_pandora_audit($other['data'][3].' cancelled access', 'Cancelled access in '.$other['data'][3].' node '.$other['data'][2] , $other['data'][0]); + returnData('string', array('type' => 'string', 'data' => 'cancelled')); + } + +} +else{ + + if($other['data'][4] == 1){ + //The user trying to log in is not an administrator and is not allowed no admin access + db_pandora_audit($other['data'][3].' denied access', 'Denied access to non-admin user '.$other['data'][3].' node '.$other['data'][2] , $other['data'][0]); + returnData('string', array('type' => 'string', 'data' => 'denied')); + } + else{ + //The user trying to log in is not an administrator and is allowed no admin access + if($other['data'][1] == 'login'){ + //The user trying to login is not admin, can enter without concurrent use filter + db_pandora_audit($other['data'][3].' Logon', 'Logged in '.$other['data'][3].' node '.$other['data'][2] , $other['data'][0]); + returnData('string', array('type' => 'string', 'data' => 'free')); + + } + elseif ($other['data'][1] == 'logout') { + //The user trying to logoff is not admin + db_pandora_audit($other['data'][3].' Logoff', 'Logout from '.$other['data'][3].' node '.$other['data'][2], $other['data'][0]); + } + elseif ($other['data'][1] == 'browse'){ + //The user trying to browse in an app page is not admin, can enter without concurrent use filter + returnData('string', array('type' => 'string', 'data' => 'free')); + } + } + } +} + + +function api_get_traps($thrash1, $thrash2, $other, $returnType) { + + if (defined ('METACONSOLE')) { + return; + } + + $other['data'] = explode('|',$other['data']); + + $other['data'][1] = date("Y-m-d H:i:s",$other['data'][1]); + + $sql = 'SELECT * from ttrap where timestamp >= "'.$other['data'][1].'"'; + + // $sql = 'SELECT * from ttrap where source = "'.$other['data'][0].'" and timestamp >= "'.$other['data'][1].'"'; + + if($other['data'][4]){ + $other['data'][4] = date("Y-m-d H:i:s",$other['data'][4]); + $sql .= ' and timestamp <= "'.$other['data'][4].'"'; + } + + if($other['data'][2]){ + $sql .= ' limit '.$other['data'][2]; + } + + if($other['data'][3]){ + $sql .= ' offset '.$other['data'][3]; + } + + if($other['data'][5]){ + $sql .= ' and status = 0'; + } + + if(sizeof($other['data']) == 0){ + $sql = 'SELECT * from ttrap'; + } + + + $traps = db_get_all_rows_sql($sql); + + if($other['data'][6]){ + + foreach ($traps as $key => $value) { + + if(!strpos($value['oid_custom'],$other['data'][6]) && $other['data'][7] == 'false'){ + unset($traps[$key]); + } + + if(strpos($value['oid_custom'],$other['data'][6]) && $other['data'][7] == 'true'){ + unset($traps[$key]); + } + + } + + } + + $traps_json = json_encode($traps); + + if (count($traps) > 0 and $traps !== false) { + returnData('string', array('type' => 'string', 'data' => $traps_json)); + } + else { + return 0; + } + +} + +function api_set_validate_traps ($id, $thrash2, $other, $thrash3) { + + if (defined ('METACONSOLE')) { + return; + } + + if($id == 'all'){ + $result = db_process_sql_update('ttrap',array('status' => 1)); + } + else{ + $result = db_process_sql_update('ttrap', + array('status' => 1), array('id_trap' => $id)); + } + + if (is_error($result)) { + // TODO: Improve the error returning more info + returnError('error_update_trap', __('Error in trap update.')); + } + else { + returnData('string', + array('type' => 'string', + 'data' => __('Validated traps.'))); + } + } + + function api_set_delete_traps ($id, $thrash2, $other, $thrash3) { + + if (defined ('METACONSOLE')) { + return; + } + + if($id == 'all'){ + $result = db_process_sql ('delete from ttrap'); + } + else{ + $result = db_process_sql_delete('ttrap',array('id_trap' => $id)); + } + + if (is_error($result)) { + // TODO: Improve the error returning more info + returnError('error_delete_trap', __('Error in trap delete.')); + } + else { + returnData('string', + array('type' => 'string', + 'data' => __('Deleted traps.'))); + } + } ?> diff --git a/pandora_console/include/functions_config.php b/pandora_console/include/functions_config.php index 3bc48f519a..ca94033ef7 100644 --- a/pandora_console/include/functions_config.php +++ b/pandora_console/include/functions_config.php @@ -631,10 +631,10 @@ function config_update_config () { if (!config_update_value ('type_mode_graph', (int) get_parameter('type_mode_graph', 0))) $error_update[] = __('Default soft graphs'); - if (!config_update_value ('zoom_graph', (int) get_parameter('zoom_graph', 0))) + if (!config_update_value ('zoom_graph', (int) get_parameter('zoom_graph', 1))) $error_update[] = __('Default zoom graphs'); - if (!config_update_value ('graph_image_height', (int) get_parameter('graph_image_height', 0))) + if (!config_update_value ('graph_image_height', (int) get_parameter('graph_image_height', 280))) $error_update[] = __('Default height of the chart image'); if (!config_update_value ('classic_menu', (bool) get_parameter('classic_menu', false))) @@ -667,10 +667,7 @@ function config_update_config () { } } //-------------------------------------------------- - - - - + //-------------------------------------------------- // CUSTOM INTERVAL VALUES //-------------------------------------------------- @@ -1859,11 +1856,15 @@ function config_process_config () { if (!isset($config['render_proc'])) { config_update_value ('render_proc', 0); } - + if (!isset($config['graph_image_height'])) { - config_update_value ('graph_image_height', 320); + config_update_value ('graph_image_height', 280); } - + + if (!isset($config['zoom_graph'])) { + config_update_value ('zoom_graph', 1); + } + if (!isset($config["render_proc_ok"])) { config_update_value ('render_proc_ok', __('Ok') ); } diff --git a/pandora_console/include/functions_forecast.php b/pandora_console/include/functions_forecast.php index f58e3592e7..fb09624081 100644 --- a/pandora_console/include/functions_forecast.php +++ b/pandora_console/include/functions_forecast.php @@ -20,31 +20,29 @@ */ /** - * Create a prediction based on module data with least square method (linear regression) + * Create a prediction based on module data with least square method (linear regression) * * @param int Module id. * @param int Period of the module data. - * @param int Period of the prediction or false to use it in prediction_date function (see below). + * @param int Period of the prediction or false to use it in prediction_date function (see below). * @param int Maximun value using this function for prediction_date. * @param int Minimun value using this function for prediction_date. * @param bool Result data for CSV file exportation. - * + * * @return array Void array or prediction of the module data. */ function forecast_projection_graph($module_id, $period = SECONDS_2MONTHS, $prediction_period, $max_value = false, $min_value = false, $csv = false) { - + global $config; - - $max_exec_time = ini_get('max_execution_time'); - + + $max_exec_time = ini_get('max_execution_time'); + if ($max_exec_time !== false) { - - $max_exec_time = (int)$max_exec_time; - + $max_exec_time = (int)$max_exec_time; } - + $begin_time = time(); $params =array( @@ -54,16 +52,16 @@ function forecast_projection_graph($module_id, 'projection' => true ); - $module_data = grafico_modulo_sparse ($params); - + $module_data = grafico_modulo_sparse($params); + if (empty($module_data)) { - return array(); + return array(); } - // Prevents bad behaviour over image error + // Prevents bad behaviour over image error else if (!is_array($module_data) and preg_match('/^= -1.0 and $linear_coef <= -0.8999 // Function variables have an inverse linear relathionship! - // else - // Function variables don't have an inverse linear relathionship! - + // else + // Function variables don't have an inverse linear relathionship! // Could be a direct correlation coefficient - // else + // else // if ($linear_coef >= 0.8999 and $linear_coef <= 1.0) { // Function variables have a direct linear relathionship! - // else + // else // Function variables don't have a direct linear relathionship! - // 2. Calculation of linear regresion... - + $b_num = (($cont * $sum_xi_yi) - ($sum_xi * $sum_yi)); $b_den = (($cont * $sum_xi2) - ($sum_xi * $sum_xi)); if ($b_den == 0) return; $b = $b_num / $b_den; - + $a_num = ($sum_yi) - ($b * $sum_xi); - + if ($cont != 0) { $a = $a_num / $cont; } else { $a = 0; } - + // Data inicialization $output_data = array(); if ($prediction_period != false) { @@ -188,11 +165,11 @@ function forecast_projection_graph($module_id, $current_ts = $last_timestamp; $in_range = true; $time_format_2 = ''; - + $temp_range = $period; if ($period < $prediction_period) $temp_range = $prediction_period; - + if ($temp_range <= SECONDS_6HOURS) { $time_format = 'H:i:s'; } @@ -206,15 +183,15 @@ function forecast_projection_graph($module_id, elseif ($temp_range <= SECONDS_1MONTH) { $time_format = 'M d'; $time_format_2 = 'H\h'; - } + } else { $time_format = 'M d'; } - - // Aplying linear regression to module data in order to do the prediction - $output_data = array(); + + // Aplying linear regression to module data in order to do the prediction $idx = 0; // Create data in graph format like + while ($in_range) { $now = time(); @@ -242,9 +219,10 @@ function forecast_projection_graph($module_id, if ($current_ts - $last_timestamp >= 94608000) { return false; } - + // Found it - if ($max_value >= $output_data[$idx][0] and $min_value <= $output_data[$idx][0]) { + if (($max_value >= $output_data[$idx][0]) && + ($min_value <= $output_data[$idx][0]) ) { return $current_ts; } } @@ -254,7 +232,6 @@ function forecast_projection_graph($module_id, $current_ts = $current_ts + $agent_interval; $idx++; } - return $output_data; } @@ -264,8 +241,8 @@ function forecast_projection_graph($module_id, * @param int Module id. * @param int Given data period to make the prediction * @param int Max value in the interval. - * @param int Min value in the interval. - * + * @param int Min value in the interval. + * * @return mixed timestamp with the prediction date or false */ function forecast_prediction_date ($module_id, @@ -274,6 +251,5 @@ function forecast_prediction_date ($module_id, if ($min_value > $max_value) { return false; } - return forecast_projection_graph($module_id, $period, false, $max_value, $min_value); } diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index 36b36a345d..e8fa13df9f 100644 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -264,9 +264,7 @@ function grafico_modulo_sparse_data_chart ( $data_module_graph['id_module_type'] == 18 || $data_module_graph['id_module_type'] == 9 || $data_module_graph['id_module_type'] == 31 || - $data_module_graph['id_module_type'] == 100 || - $params['baseline'] || $params['projection'] - ){ + $data_module_graph['id_module_type'] == 100 ){ $data = db_get_all_rows_filter ( 'tagente_datos', @@ -421,8 +419,7 @@ function grafico_modulo_sparse_data( $data_module_graph['id_module_type'] == 18 || $data_module_graph['id_module_type'] == 9 || $data_module_graph['id_module_type'] == 31 || - $data_module_graph['id_module_type'] == 100 || - $params['projection'] ){ + $data_module_graph['id_module_type'] == 100 ){ $array_data = grafico_modulo_sparse_data_chart ( $agent_module_id, $date_array, @@ -516,6 +513,8 @@ function grafico_modulo_sparse_data( } $period_time_interval = $period_time_interval - $params['time_interval']; } + //drag the last value to paint the graph correctly + $acum_array_data[]= array( 0 => $start_period, 1 => $acum_array_data[$i-1][1]); $array_data['sum1']['data'] = $acum_array_data; } @@ -892,7 +891,9 @@ function grafico_modulo_sparse ($params) { } if(!isset($params['zoom'])){ - $params['zoom'] = $config['zoom_graph']; + $params['zoom'] = $config['zoom_graph'] + ? $config['zoom_graph'] + : 1; } if(!isset($params['type_mode_graph'])){ @@ -922,7 +923,6 @@ function grafico_modulo_sparse ($params) { $legend = array(); $array_events_alerts = array(); - $date_array = array(); $date_array["period"] = $params['period']; $date_array["final_date"] = $params['date']; @@ -964,53 +964,58 @@ function grafico_modulo_sparse ($params) { } if(!$params['array_data_create']){ - if ($params['compare'] !== false) { - $series_suffix = 2; + if($params['baseline']){ + $array_data = get_baseline_data($agent_module_id, $date_array, $data_module_graph, $params); + } + else{ + if ($params['compare'] !== false) { + $series_suffix = 2; - $date_array_prev['final_date'] = $date_array['start_date']; - $date_array_prev['start_date'] = $date_array['start_date'] - $date_array['period']; - $date_array_prev['period'] = $date_array['period']; + $date_array_prev['final_date'] = $date_array['start_date']; + $date_array_prev['start_date'] = $date_array['start_date'] - $date_array['period']; + $date_array_prev['period'] = $date_array['period']; - if ($params['compare'] === 'overlapped') { - $params['flag_overlapped'] = 1; - } - else{ - $params['flag_overlapped'] = 0; + if ($params['compare'] === 'overlapped') { + $params['flag_overlapped'] = 1; + } + else{ + $params['flag_overlapped'] = 0; + } + + $array_data = grafico_modulo_sparse_data( + $agent_module_id, + $date_array_prev, + $data_module_graph, + $params, + $series_suffix + ); + + switch ($params['compare']) { + case 'separated': + case 'overlapped': + // Store the chart calculated + $array_data_prev = $array_data; + $legend_prev = $legend; + break; + } } + $series_suffix = 1; + $params['flag_overlapped'] = 0; + $array_data = grafico_modulo_sparse_data( $agent_module_id, - $date_array_prev, + $date_array, $data_module_graph, $params, $series_suffix ); - switch ($params['compare']) { - case 'separated': - case 'overlapped': - // Store the chart calculated - $array_data_prev = $array_data; - $legend_prev = $legend; - break; - } - } - - $series_suffix = 1; - $params['flag_overlapped'] = 0; - - $array_data = grafico_modulo_sparse_data( - $agent_module_id, - $date_array, - $data_module_graph, - $params, - $series_suffix - ); - - if($params['compare']){ - if ($params['compare'] === 'overlapped') { - $array_data = array_merge($array_data, $array_data_prev); - $legend = array_merge($legend, $legend_prev); + if($params['compare']){ + if ($params['compare'] === 'overlapped') { + $array_data = array_merge($array_data, $array_data_prev); + $legend = array_merge($legend, $legend_prev); + } } } } @@ -1219,7 +1224,7 @@ function graphic_combined_module ( } else{ $params['stacked'] = 'area'; - $params['projection'] = $params_combined['projection']; + $params['projection'] = true; } if(!isset($params_combined['labels'])){ @@ -1512,6 +1517,14 @@ function graphic_combined_module ( $date_array["final_date"] = $params['date']; $date_array["start_date"] = $params['date'] - $params['period']; + if($params_combined['projection']){ + $output_projection = forecast_projection_graph( + $module_list[0], + $params['period'], + $params_combined['projection'] + ); + } + $i=0; $array_data = array(); foreach ($module_list as $key => $agent_module_id) { @@ -1578,10 +1591,13 @@ function graphic_combined_module ( $i++; } - if($params_combined['projection'] && is_array($params_combined['projection'])){ - $date_array_projection = max($params_combined['projection']); - $date_array['final_date'] = $date_array_projection[0] / 1000; - $array_data['projection']['data']= $params_combined['projection']; + if($params_combined['projection']){ + // If projection doesn't have data then don't draw graph + if ($output_projection != NULL) { + $date_array_projection = max($output_projection); + $date_array['final_date'] = $date_array_projection[0] / 1000; + $array_data['projection']['data']= $output_projection; + } } //summatory and average series @@ -4115,7 +4131,7 @@ function fullscale_data ( if($min_value != PHP_INT_MAX) { $data["min" . $series_suffix]['data'][] = array($real_date , $min_value); } - + if($max_value != -PHP_INT_MAX) { $data["max" . $series_suffix]['data'][] = array($real_date , $max_value); } @@ -4141,7 +4157,7 @@ function fullscale_data ( $min_value_total = $min_value; } //avg sum_total - $sum_data_total += $sum_data; + $sum_data_total += $sum_data/$count_data; //avg count_total $count_data_total++; @@ -4189,6 +4205,7 @@ function fullscale_data ( } } } + $data["sum" . $series_suffix]['min'] = $min_value_total; $data["sum" . $series_suffix]['max'] = $max_value_total; $data["sum" . $series_suffix]['avg'] = $sum_data_total/$count_data_total; @@ -4253,12 +4270,12 @@ function fullscale_data ( if(isset($v["datos"]) && $v["datos"]){ //max - if($v['datos'] >= $max_value){ - $max_value = $v['datos']; + if((float)$v['datos'] >= $max_value_max){ + $max_value_max = $v['datos']; } //min - if($v['datos'] <= $min_value){ - $min_value = $v['datos']; + if((float)$v['datos'] <= $min_value_min){ + $min_value_min = $v['datos']; } //avg sum $sum_data += $v["datos"]; @@ -4274,8 +4291,8 @@ function fullscale_data ( } } - $data["sum" . $series_suffix]['min'] = $min_value; - $data["sum" . $series_suffix]['max'] = $max_value; + $data["sum" . $series_suffix]['min'] = $min_value_min; + $data["sum" . $series_suffix]['max'] = $max_value_max; $data["sum" . $series_suffix]['avg'] = $sum_data/$count_data; } @@ -5096,4 +5113,53 @@ function graph_monitor_wheel ($width = 550, $height = 600, $filter = false) { return d3_sunburst_graph ($graph_data, $width, $height, true); } +function get_baseline_data($agent_module_id, $date_array, $data_module_graph, $params){ + $period = $date_array["period"]; + $date = $date_array["final_date"]; + $array_data = array(); + for ($i = 0; $i < 4; $i++) { + $date_array = array(); + $date_array["period"] = $period; + $date_array["final_date"] = $date - $period * $i; + $date_array["start_date"] = $date - $period * ($i + 1); + + $data = grafico_modulo_sparse_data( + $agent_module_id, + $date_array, + $data_module_graph, + $params, + $i + ); + + $array_data[] = $data; + + } + $result = array(); + $array_data[1] = array_reverse($array_data[1]['sum1']['slice_data']); + $array_data[2] = array_reverse($array_data[2]['sum2']['slice_data']); + $array_data[3] = array_reverse($array_data[3]['sum3']['slice_data']); + foreach ($array_data[0]['sum0']['slice_data'] as $key => $value) { + $data1 = array_pop($array_data[1]); + $data2 = array_pop($array_data[2]); + $data3 = array_pop($array_data[3]); + + $result['slice_data'][$key]['min'] = ($data1['min'] + $data2['min'] + $data3['min'] + $value['min']) / 4; + $result['slice_data'][$key]['avg'] = ($data1['avg'] + $data2['avg'] + $data3['avg'] + $value['avg']) / 4; + $result['slice_data'][$key]['max'] = ($data1['max'] + $data2['max'] + $data3['max'] + $value['max']) / 4; + + $result['data'][] = array($key, $result['slice_data'][$key]['avg']); + } + + $result['avg'] = ($array_data[0]['sum0']['avg'] + $array_data[1]['sum1']['avg'] + $array_data[2]['sum2']['avg'] +$array_data[3]['sum3']['avg'])/4; + $result['max'] = max($array_data[0]['sum0']['max'], $array_data[1]['sum1']['max'], $array_data[2]['sum2']['max'], $array_data[3]['sum3']['max']); + $result['min'] = min($array_data[0]['sum0']['min'], $array_data[1]['sum1']['min'], $array_data[2]['sum2']['min'], $array_data[3]['sum3']['min']); + + $result['agent_module_id'] = $array_data[0]['sum0']['agent_module_id']; + $result['id_module_type'] = $array_data[0]['sum0']['id_module_type']; + $result['agent_name'] = $array_data[0]['sum0']['agent_name']; + $result['module_name'] = $array_data[0]['sum0']['module_name']; + $result['agent_alias'] = $array_data[0]['sum0']['agent_alias']; + return array('sum0' => $result); +} + ?> diff --git a/pandora_console/include/functions_groups.php b/pandora_console/include/functions_groups.php index 23f74bf2b3..2ce647c324 100644 --- a/pandora_console/include/functions_groups.php +++ b/pandora_console/include/functions_groups.php @@ -270,22 +270,20 @@ function groups_get_childrens($parent, $groups = null, $onlyPropagate = false) { if (empty($groups)) { $groups = db_get_all_rows_in_table('tgrupo'); } - + $return = array(); - + foreach ($groups as $key => $group) { if ($group['id_grupo'] == 0) { continue; } - if ($group['propagate'] || $onlyPropagate) { if ($group['parent'] == $parent) { $return = $return + array($group['id_grupo'] => $group) + groups_get_childrens($group['id_grupo'], $groups, $onlyPropagate); } } - } - + return $return; } @@ -300,23 +298,20 @@ function groups_get_parents($parent, $onlyPropagate = false, $groups = null) { if (empty($groups)) { $groups = db_get_all_rows_in_table('tgrupo'); } - + $return = array(); - foreach ($groups as $key => $group) { if ($group['id_grupo'] == 0) { continue; } - + if (($group['id_grupo'] == $parent) && ($group['propagate'] || !$onlyPropagate)) { - $return = $return + array($group['id_grupo'] => $group) + groups_get_parents($group['parent'], $onlyPropagate, $groups); } } - return $return; } @@ -373,32 +368,6 @@ function groups_give_disabled_group ($id_group) { return (bool) db_get_value ('disabled', 'tgrupo', 'id_grupo', (int) $id_group); } -/** - * Test if the param array is all groups in db. - * - * @param array $id_groups - * - * @return bool It's true when the array is all groups in db. - */ -function groups_is_all_group($idGroups) { - if (!is_array($idGroups)) - $arrayGroups = array($idGroups); - else - $arrayGroups = $idGroups; - - $groupsDB = db_get_all_rows_in_table ('tgrupo'); - - $returnVar = true; - foreach ($groupsDB as $group) { - if (!in_array($group['id_grupo'], $arrayGroups)) { - $returnVar = false; - break; - } - } - - return $returnVar; -} - /** * Get group icon from group. * @@ -632,7 +601,7 @@ function groups_get_id ($group_name, $returnAllGroup = false) { * * @param int $id_group The group id to look for * @param mixed filter array - * @param bool True if users with all permissions in the group are retrieved + * @param bool True if users with all permissions in the group are retrieved * * @return array An array with all the users or an empty array */ @@ -641,7 +610,7 @@ function groups_get_users ($id_group, $filter = false, $return_user_all = false) if (! is_array ($filter)) $filter = array (); - + if($return_user_all){ if (is_array($id_group)){ $filter['id_grupo'] = $id_group; @@ -655,18 +624,18 @@ function groups_get_users ($id_group, $filter = false, $return_user_all = false) $filter['id_grupo'] = $id_group; } - $query = "SELECT tu.* - FROM tusuario tu, tusuario_perfil tup - WHERE tup.id_usuario = tu.id_user" ; + $query = "SELECT tu.* + FROM tusuario tu, tusuario_perfil tup + WHERE tup.id_usuario = tu.id_user" ; if(is_array($filter)){ foreach ($filter as $key => $value) { if($key != 'limit' && $key != 'order' && - $key != 'offset' &&$key != 'group'){ + $key != 'offset' &&$key != 'group'){ $filter_array["tup.".$key] = $value; } else{ - $filter_array[$key] = $value; + $filter_array[$key] = $value; } } $clause_sql = mysql_db_format_array_where_clause_sql($filter_array,'AND',false); @@ -674,451 +643,16 @@ function groups_get_users ($id_group, $filter = false, $return_user_all = false) $query .= " AND " . $clause_sql; } } - + $result = db_get_all_rows_sql($query); if ($result === false){ return array (); } - + return $result; } -/** - * Returning data for a row in the groups view (Recursive function) - * - * @param int $id_group The group id of the row - * @param array $group_all An array of all groups - * @param array $group arrayy The group name and childs - * @param array $printed_groups The printed groups list (by reference) - * - */ -function groups_get_group_row_data($id_group, $group_all, $group, &$printed_groups) { - global $config; - - $rows = array(); - $row = array(); - - if (isset($printed_groups[$id_group])) { - return; - } - - // Store printed group to not print it again - $printed_groups[$id_group] = 1; - - if ($id_group < 0) - return; - - // Get stats for this group - $data = reporting_get_group_stats($id_group); - - if ($data["total_agents"] == 0) - return; // Skip empty groups - - // Calculate entire row color - if ($data["monitor_alerts_fired"] > 0) { - $row["status"] = "group_view_alrm"; - } - elseif ($data["monitor_critical"] > 0) { - $row["status"] = "group_view_crit"; - } - elseif ($data["monitor_warning"] > 0) { - $row["status"] = "group_view_warn"; - } - elseif (($data["monitor_unknown"] > 0) || ($data["agents_unknown"] > 0)) { - $row["status"] = "group_view_unk"; - } - elseif ($data["monitor_ok"] > 0) { - $row["status"] = "group_view_ok"; - } - else { - $row["status"] = "group_view_normal"; - } - - // Group name - $group_cell = __('Group'); - $row[$group_cell] = $group['prefix']; - $row[$group_cell] .= ""; - $row[$group_cell] .= ui_print_group_icon ($id_group, true, "groups_small", '', false); - $row[$group_cell] .= ui_print_truncate_text($group['name']); - $row[$group_cell] .= ""; - - $row['group_name'] = ui_print_truncate_text($group['name']); - - if ($id_group > 0) - $icon = (string) db_get_value ('icon', 'tgrupo', 'id_grupo', (int) $id_group); - else - $icon = "world"; - - $row['group_icon'] = html_print_image("images/groups_small/" . $icon . ".png", - true, false, true); - - if (!isset($html)) { - $html = false; - } - - //Update network group - if ($html) { - echo ""; - if (check_acl ($config['id_user'], $id_group, "AW")) { - echo '' . - html_print_image("images/target.png", true, array("border" => '0', "alt" => __('Force'))) . ''; - } - echo ""; - } - - // Total agents - if ($id_group != 0) { - $data["total_agents"] = db_get_sql ("SELECT COUNT(id_agente) - FROM tagente - WHERE id_grupo = $id_group AND disabled = 0"); - } - - // Total agents - $row['links'][__('Agents')] = "index.php?" . - "page=agents&group=" . $id_group; - $row['counts'][__('Agents')] = $data["total_agents"]; - - $row[__('Agents')] = ""; - $row[__('Agents')] .= $row['counts'][__('Agents')]; - $row[__('Agents')] .= ""; - - - // Agents unknown - $row['links'][__('Agents unknown')] = "index.php?" . - "page=agents&group=" . $id_group . "&status=" . AGENT_STATUS_UNKNOWN; - $row['counts'][__('Agents unknown')] = $data["agents_unknown"]; - - $row[__('Agents unknown')] = ""; - $row[__('Agents unknown')] .= $row['counts'][__('Agents unknown')]; - $row[__('Agents unknown')] .= ""; - - // Monitors Unknown - $row['links'][__('Unknown')] = "index.php?" . - "page=modules&group=" . $id_group . "&status=" . AGENT_MODULE_STATUS_UNKNOWN; - $row['counts'][__('Unknown')] = $data["monitor_unknown"]; - - $row[__('Unknown')] = ""; - $row[__('Unknown')] .= $row['counts'][__('Unknown')]; - $row[__('Unknown')] .= ""; - - // Monitors Not Init - $row['links'][__('Not init')] = "index.php?" . - "page=modules&group=" . $id_group . "&status=" . AGENT_MODULE_STATUS_NOT_INIT; - $row['counts'][__('Not init')] = $data["monitor_unknown"]; - - $row[__('Not init')] = ""; - $row[__('Not init')] .= $row['counts'][__('Not init')]; - $row[__('Not init')] .= ""; - - // Monitors OK - $row['links'][__('Normal')] = "index.php?" . - "page=modules&group=" . $id_group . "&status=" . AGENT_MODULE_STATUS_NORMAL; - $row['counts'][__('Normal')] = $data["monitor_ok"]; - - $row[__('Normal')] = ""; - $row[__('Normal')] .= $row['counts'][__('Normal')]; - $row[__('Normal')] .= ""; - - // Monitors Warning - $row['links'][__('Warning')] = "index.php?" . - "page=modules&group=" . $id_group . "&status=" . AGENT_MODULE_STATUS_WARNING; - $row['counts'][__('Warning')] = $data["monitor_warning"]; - - $row[__('Warning')] = ""; - $row[__('Warning')] .= $row['counts'][__('Normal')]; - $row[__('Warning')] .= ""; - - // Monitors Critical - $row['links'][__('Critical')] = "index.php?" . - "page=modules&group=" . $id_group . "&status=" . AGENT_MODULE_STATUS_CRITICAL_BAD; - $row['counts'][__('Critical')] = $data["monitor_critical"]; - - $row[__('Critical')] = ""; - $row[__('Critical')] .= $row['counts'][__('Critical')]; - $row[__('Critical')] .= ""; - - // Alerts fired - $row['links'][__('Alerts fired')] = "index.php?" . - "page=alerts&group=" . $id_group . "&status=fired"; - $row['counts'][__('Alerts fired')] = $data["monitor_alerts_fired"]; - - $row[__('Alerts fired')] = ""; - $row[__('Alerts fired')] .= $row['counts'][__('Alerts fired')]; - $row[__('Alerts fired')] .= ""; - - $rows[$id_group] = $row; - - foreach($group['childs'] as $child) { - $sub_rows = groups_get_group_row_data($child, $group_all, - $group_all[$child], $printed_groups); - - if (!$html) { - if (!empty($sub_rows)) - $rows = $rows + $sub_rows; - } - } - - return $rows; -} - -function groups_get_groups_with_agent($id_user = false, $privilege = "AR", $returnAllGroup = true, $returnAllColumns = false, $id_groups = null, $keys_field = 'id_grupo') { - $groups = users_get_groups($id_user, $privilege, $returnAllGroup, $returnAllColumns, $id_groups, $keys_field); - - $return = array(); - foreach ($groups as $group) { - $data = reporting_get_group_stats($group['id_grupo']); - - if ($data["total_agents"] != 0) { - $return[] = $group; - } - } - - return $return; -} - -/** - * Print a row in the groups view (Recursive function) - * - * @param int $id_group The group id of the row - * @param array $group_all An array of all groups - * @param array $group arrayy The group name and childs - * @param array $printed_groups The printed groups list (by reference) - * - */ -function groups_get_group_row($id_group, $group_all, $group, &$printed_groups) { - global $config; - - if ($id_group < 0) - return; - - if (isset($printed_groups[$id_group])) { - return; - } - - // Store printed group to not print it again - $printed_groups[$id_group] = 1; - - // Get stats for this group - $data = reporting_get_group_stats($id_group); - - - if ($data["total_agents"] == 0) { - if (!empty($group['childs'])) { - $group_childrens = groups_get_childrens($id_group, null, true); - $group_childrens_agents = groups_total_agents(array_keys($group_childrens)); - - if (empty($group_childrens_agents)) { - return; // Skip empty groups - } - } - else { - return; // Skip empty groups - } - } - - // Calculate entire row color - if ($data["monitor_alerts_fired"] > 0) { - $group_class = 'group_view_alrm'; - $status_image = ui_print_status_image ('agent_alertsfired_ball.png', "", true); - } - elseif ($data["monitor_critical"] > 0) { - $group_class = 'group_view_crit'; - $status_image = ui_print_status_image ('agent_critical_ball.png', "", true); - } - elseif ($data["monitor_warning"] > 0) { - $group_class = 'group_view_warn'; - $status_image = ui_print_status_image ('agent_warning_ball.png', "", true); - } - elseif (($data["monitor_unknown"] > 0) || ($data["agents_unknown"] > 0)) { - $group_class = 'group_view_unk'; - $status_image = ui_print_status_image ('agent_no_monitors_ball.png', "", true); - } - elseif ($data["monitor_ok"] > 0) { - $group_class = 'group_view_ok'; - $status_image = ui_print_status_image ('agent_ok_ball.png', "", true); - } - elseif ($data["agent_not_init"] > 0) { - $group_class = 'group_view_not_init'; - $status_image = ui_print_status_image ('agent_no_data_ball.png', "", true); - } - else { - $group_class = 'group_view_normal'; - $status_image = ui_print_status_image ('agent_no_data_ball.png', "", true); - } - - ob_start(); - - echo ""; - - // Force - echo ""; - if (check_acl ($config['id_user'], $id_group, "AW")) { - echo '' . - html_print_image("images/target.png", true, array("border" => '0', "title" => __('Force'))) . ''; - } - echo ""; - - // Status - // echo "" . $status_image . ""; - - // Group name - echo "  "; - //echo $group['prefix'] . ui_print_group_icon ($id_group, true, "groups_small", 'font-size: 7.5pt'); - echo " "; - echo $group['prefix'] . ui_print_truncate_text($group['name']); - echo ""; - echo ""; - - // Total agents - echo ""; - if ($data["total_agents"] > 0) - echo ""; - - //Total agent field given by function reporting_get_group_stats return the number of agents - //of this groups and its children. It was done to print empty fathers of children groups. - //We need to recalculate the total agents for this group here to get only the total agents - //for this group. Of course the group All (0) is a special case. - - if ($id_group != 0) { - $data["total_agents"] = db_get_sql ("SELECT COUNT(id_agente) - FROM tagente - WHERE id_grupo = $id_group AND disabled = 0"); - } - - echo $data["total_agents"]; - echo ""; - - // Agents unknown - if ($data["agents_unknown"] > 0) { - echo ""; - echo ""; - echo $data["agents_unknown"]; - echo ""; - echo ""; - } - else { - echo ""; - } - - // Agents not init - if ($data["agent_not_init"] > 0) { - echo ""; - echo ""; - echo $data["agent_not_init"]; - echo ""; - echo ""; - } - else { - echo ""; - } - - // Monitors Unknown - if ($data["monitor_unknown"] > 0) { - echo ""; - echo ""; - echo $data["monitor_unknown"]; - echo ""; - echo ""; - } - else { - echo ""; - } - - - // Monitors Not Init - if ($data["monitor_not_init"] > 0) { - echo ""; - echo ""; - echo $data["monitor_not_init"]; - echo ""; - echo ""; - } - else { - echo ""; - } - - - // Monitors OK - echo ""; - if ($data["monitor_ok"] > 0) { - echo ""; - echo $data["monitor_ok"]; - echo ""; - } - else { - echo " "; - } - echo ""; - - // Monitors Warning - if ($data["monitor_warning"] > 0) { - echo ""; - echo ""; - echo $data["monitor_warning"]; - echo ""; - echo ""; - } - else { - echo ""; - } - - // Monitors Critical - if ($data["monitor_critical"] > 0) { - echo ""; - echo ""; - echo $data["monitor_critical"]; - echo ""; - echo ""; - } - else { - echo ""; - } - // Alerts fired - if ($data["monitor_alerts_fired"] > 0) { - echo ""; - echo ""; - echo $data["monitor_alerts_fired"]; - echo ""; - echo ""; - } - else { - echo ""; - } - - echo ""; - - $row[$id_group] = ob_get_clean(); - - - foreach ($group['childs'] as $child) { - if (array_key_exists($child, $group_all)) { - $row_child = groups_get_group_row($child, $group_all, $group_all[$child], $printed_groups); - - if (!is_array_empty($row_child)) { - $row = $row + $row_child; - } - } - } - - return $row; -} - /** * Gets a group by id_group * @@ -1956,251 +1490,159 @@ function groups_get_not_init_monitors ($group, $agent_filter = array(), $module_ } // Get alerts defined for a given group, except disabled - -function groups_monitor_alerts ($group_array, $strict_user = false, $id_group_strict = false) { - - // If there are not groups to query, we jump to nextone - - if (empty ($group_array)) { - return 0; - - } - else if (!is_array ($group_array)) { - $group_array = array($group_array); - } - - $group_clause = implode (",", $group_array); - $group_clause = "(" . $group_clause . ")"; - - if ($strict_user) { - $sql = "SELECT COUNT(talert_template_modules.id) - FROM talert_template_modules, tagente_modulo, tagente_estado, tagente - WHERE tagente.id_grupo = $id_group_strict AND tagente_modulo.id_agente = tagente.id_agente - AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo - AND tagente_modulo.disabled = 0 AND tagente.disabled = 0 - AND talert_template_modules.disabled = 0 - AND talert_template_modules.id_agent_module = tagente_modulo.id_agente_modulo"; - $count = db_get_sql ($sql); - return $count; - } else { - //TODO REVIEW ORACLE AND POSTGRES - return db_get_sql ("SELECT COUNT(talert_template_modules.id) - FROM talert_template_modules, tagente_modulo, tagente_estado, tagente - WHERE tagente.id_grupo IN $group_clause AND tagente_modulo.id_agente = tagente.id_agente - AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo - AND tagente_modulo.disabled = 0 AND tagente.disabled = 0 - AND talert_template_modules.disabled = 0 - AND talert_template_modules.id_agent_module = tagente_modulo.id_agente_modulo"); - } +function groups_monitor_alerts ($group_array) { + $total = groups_monitor_alerts_total_counters($group_array); + return $total['total']; } // Get alert configured currently FIRED, except disabled +function groups_monitor_fired_alerts ($group_array) { + $total = groups_monitor_alerts_total_counters($group_array); + return $total['fired']; +} -function groups_monitor_fired_alerts ($group_array, $strict_user = false, $id_group_strict = false) { - +function groups_monitor_alerts_total_counters ($group_array) { // If there are not groups to query, we jump to nextone - + $default_total = array('total' => 0, 'fired' => 0); if (empty ($group_array)) { - return 0; - + return $default_total; } else if (!is_array ($group_array)) { $group_array = array($group_array); } - - $group_clause = implode (",", $group_array); - $group_clause = "(" . $group_clause . ")"; - - if ($strict_user) { - $sql = "SELECT COUNT(talert_template_modules.id) - FROM talert_template_modules, tagente_modulo, tagente_estado, tagente - WHERE tagente.id_grupo = $id_group_strict AND tagente_modulo.id_agente = tagente.id_agente - AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo - AND tagente_modulo.disabled = 0 AND tagente.disabled = 0 - AND talert_template_modules.disabled = 0 - AND talert_template_modules.id_agent_module = tagente_modulo.id_agente_modulo - AND times_fired > 0 "; - $count = db_get_sql ($sql); - return $count; + $group_clause = implode (",", $group_array); + $group_clause = "(tasg.id_group IN ($group_clause) OR ta.id_grupo IN ($group_clause))"; + + $alerts = db_get_row_sql ("SELECT + COUNT(tatm.id) AS total, + SUM(IF(tatm.times_fired > 0, 1, 0)) AS fired + FROM talert_template_modules tatm + INNER JOIN tagente_modulo tam + ON tatm.id_agent_module = tam.id_agente_modulo + INNER JOIN tagente ta + ON ta.id_agente = tam.id_agente + WHERE ta.id_agente IN ( + SELECT ta.id_agente + FROM tagente ta + LEFT JOIN tagent_secondary_group tasg + ON ta.id_agente = tasg.id_agent + WHERE ta.disabled = 0 + AND $group_clause + ) AND tam.disabled = 0" + ); + + return ($alerts === false) ? $default_total : $alerts; +} + +function groups_monitor_total_counters ($group_array, $search_in_testado = false) { + $default_total = array( + 'ok' => 0, 'critical' => 0, 'warning' => 0, + 'unknown' => 0, 'not_init' => 0, 'total' => 0 + ); + if (empty ($group_array)) { + return $default_total; + } + else if (!is_array ($group_array)) { + $group_array = array($group_array); + } + $group_clause = implode (",", $group_array); + $group_clause = "(tasg.id_group IN ($group_clause) OR ta.id_grupo IN ($group_clause))"; + + if ($search_in_testado) { + $condition_critical = modules_get_state_condition(AGENT_MODULE_STATUS_CRITICAL_ALERT); + $condition_warning = modules_get_state_condition(AGENT_MODULE_STATUS_WARNING_ALERT); + $condition_unknown = modules_get_state_condition(AGENT_MODULE_STATUS_UNKNOWN); + $condition_not_init = modules_get_state_condition(AGENT_MODULE_STATUS_NO_DATA); + $condition_normal = modules_get_state_condition(AGENT_MODULE_STATUS_NORMAL); + $sql = + "SELECT SUM(IF($condition_normal, 1, 0)) AS ok, + SUM(IF($condition_critical, 1, 0)) AS critical, + SUM(IF($condition_warning, 1, 0)) AS warning, + SUM(IF($condition_unknown, 1, 0)) AS unknown, + SUM(IF($condition_not_init, 1, 0)) AS not_init, + COUNT(tam.id_agente_modulo) AS total + FROM tagente ta + INNER JOIN tagente_modulo tam + ON ta.id_agente = tam.id_agente + INNER JOIN tagente_estado tae + ON tam.id_agente_modulo = tae.id_agente_modulo + WHERE ta.disabled = 0 AND tam.disabled = 0 + AND ta.id_agente IN ( + SELECT ta.id_agente FROM tagente ta + LEFT JOIN tagent_secondary_group tasg + ON ta.id_agente = tasg.id_agent + WHERE ta.disabled = 0 + AND $group_clause + GROUP BY ta.id_agente + ) + "; } else { - //TODO REVIEW ORACLE AND POSTGRES - return db_get_sql ("SELECT COUNT(talert_template_modules.id) - FROM talert_template_modules, tagente_modulo, tagente_estado, tagente - WHERE tagente.id_grupo IN $group_clause AND tagente_modulo.id_agente = tagente.id_agente - AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo - AND tagente_modulo.disabled = 0 AND tagente.disabled = 0 - AND talert_template_modules.disabled = 0 - AND talert_template_modules.id_agent_module = tagente_modulo.id_agente_modulo - AND times_fired > 0"); + $sql = + "SELECT SUM(ta.normal_count) AS ok, + SUM(ta.critical_count) AS critical, + SUM(ta.warning_count) AS warning, + SUM(ta.unknown_count) AS unknown, + SUM(ta.notinit_count) AS not_init, + SUM(ta.total_count) AS total + FROM tagente ta + WHERE ta.disabled = 0 + AND ta.id_agente IN ( + SELECT ta.id_agente FROM tagente ta + LEFT JOIN tagent_secondary_group tasg + ON ta.id_agente = tasg.id_agent + WHERE ta.disabled = 0 + AND $group_clause + GROUP BY ta.id_agente + ) + "; } - + $monitors = db_get_row_sql($sql); + + return ($monitors === false) ? $default_total : $monitors; } -/** - * Total agents in a group, (by default except disabled ones) - * - * @param mixed Array or (comma separated) string with groups - * @param bool Whether to count disabled agents - * - * @return mixed Return group count or false if something goes wrong - * - */ -function groups_total_agents ($group_array, $disabled = false) { - +function groups_agents_total_counters ($group_array) { + $default_total = array( + 'ok' => 0, 'critical' => 0, 'warning' => 0, + 'unknown' => 0, 'not_init' => 0, 'total' => 0 + ); if (empty ($group_array)) { - return 0; - + return $default_total; } else if (!is_array ($group_array)) { $group_array = array($group_array); } - $group_clause = implode (",", $group_array); - $group_clause = "(" . $group_clause . ")"; - - $sql = "SELECT COUNT(*) FROM tagente WHERE id_grupo IN $group_clause"; - - if (!$disabled) - $sql .= " AND disabled = 0"; - - return db_get_sql ($sql); -} + $group_clause = "(tasg.id_group IN ($group_clause) OR ta.id_grupo IN ($group_clause))"; -/** - * Number of disabled agents in a group - * - * @param mixed Array or (comma separated) string with groups - * - * @return mixed Return group count or false if something goes wrong - * - */ -function groups_agent_disabled ($group_array) { - - if (empty ($group_array)) { - return 0; - - } - else if (!is_array ($group_array)) { - $group_array = array($group_array); - } - - $group_clause = implode (",", $group_array); - $group_clause = "(" . $group_clause . ")"; - - $sql = "SELECT COUNT(*) FROM tagente WHERE id_grupo IN $group_clause AND disabled = 1"; - - return db_get_sql ($sql); -} + $condition_critical = agents_get_status_clause(AGENT_STATUS_CRITICAL); + $condition_warning = agents_get_status_clause(AGENT_STATUS_WARNING); + $condition_unknown = agents_get_status_clause(AGENT_STATUS_UNKNOWN); + $condition_not_init = agents_get_status_clause(AGENT_STATUS_NOT_INIT); + $condition_normal = agents_get_status_clause(AGENT_STATUS_NORMAL); + $sql = + "SELECT SUM(IF($condition_normal, 1, 0)) AS ok, + SUM(IF($condition_critical, 1, 0)) AS critical, + SUM(IF($condition_warning, 1, 0)) AS warning, + SUM(IF($condition_unknown, 1, 0)) AS unknown, + SUM(IF($condition_not_init, 1, 0)) AS not_init, + COUNT(ta.id_agente) AS total + FROM tagente ta + WHERE ta.disabled = 0 + AND ta.id_agente IN ( + SELECT ta.id_agente FROM tagente ta + LEFT JOIN tagent_secondary_group tasg + ON ta.id_agente = tasg.id_agent + WHERE ta.disabled = 0 + AND $group_clause + GROUP BY ta.id_agente + ) + "; -/** - * Return a group row for Groups managment list - * - * @param mixed Group info - * @param int total number of groups - * @param string (ref) Concatenation of branches class with the parent classes - * - * @return mixed Row with html_print_table format - * - */ -function groups_get_group_to_list($group, $groups_count, &$symbolBranchs, $has_children = false) { - $tabulation = str_repeat('    ', $group['deep']); - - if ($group['id_grupo'] == 0) { - $symbol = '-'; - } - else { - $symbol = '+'; - } - - $group_hash_branch = false; - if (isset($group['hash_branch'])) { - $group_hash_branch = $group['hash_branch']; - } - - if ($group_hash_branch) { - $data[0] = ''.$tabulation . ' ' . - '' . - $symbol . ' '. ui_print_truncate_text($group['nombre']) . ''; - } - else { - $data[0] = '' . $tabulation . ' ' . ui_print_truncate_text($group['nombre']) . ''; - } - $data[1] = $group['id_grupo']; - $data[2] = ui_print_group_icon($group['id_grupo'], true); - $data[3] = $group['disabled'] ? __('Disabled') : __('Enabled'); - $data[4] = $group['description']; - if ($group['id_grupo'] == 0) { - $data[5] = ''; - } - else { - $data[5] = '' . html_print_image("images/config.png", true, array("alt" => __('Edit'), "title" => __('Edit'), "border" => '0')); - //Check if there is only a group to unable delete it - if ($groups_count > 2) { - $confirm_message = __('Are you sure?'); - if ($has_children) { - $confirm_message = __('The child groups will be updated to use the parent id of the deleted group') . ". " . $confirm_message; - } + $agents = db_get_row_sql($sql); - $data[5] .= '  ' . - '' . html_print_image("images/cross.png", true, array("alt" => __('Delete'), "border" => '0')); - } - else { - $data[5] .= '  ' . - ui_print_help_tip( - __('You cannot delete the last group. A common installation must have at least one group.'), true); - } - } - - return $data; -} - -/** - * Store to be printed the subgroups rows (Recursive) - * - * @param mixed Group info - * @param mixed Hash list with all the groups of 2nd or higher level - * @param string (ref) Concatenation of branches classes to control the symbols from Javascript - * @param int total number of groups - * @param obj (ref) table object in html_print_table format with the stored groups - * @param int (ref) counter of the row stored - * @param string (ref) Concatenation of branches class with the parent classes - * - */ -function groups_print_group_sons($group, $sons, &$branch_classes, $groups_count, &$table, &$iterator, &$symbolBranchs) { - if (isset($sons[$group['id_grupo']])) { - foreach($sons[$group['id_grupo']] as $key => $g) { - $symbolBranchs .= ' symbol_branch_' . $g['parent']; - - $has_children = isset($sons[$g['id_grupo']]); - - $data = groups_get_group_to_list($g, $groups_count, $symbolBranchs, $has_children); - array_push ($table->data, $data); - - $branch_classes[$g['id_grupo']] = $branch_classes[$g['parent']] . ' branch_' . $g['parent']; - $table->rowclass[$iterator] = 'parent_' . $g['parent'] . $branch_classes[$g['id_grupo']]; - - if ($g['deep'] == 0) { - $table->rowstyle[$iterator] = ''; - } - else { - if ($g['parent'] != 0) { - $table->rowstyle[$iterator] = 'display: none;'; - } - } - - $iterator++; - - groups_print_group_sons($g, $sons, $branch_classes, $groups_count, $table, $iterator, $symbolBranchs); - } - } + return ($agents === false) ? $default_total : $agents; } /** @@ -2295,108 +1737,47 @@ function groups_get_tree_keys ($groups, &$group_keys) { } } -function groups_get_all_hierarchy_group ($id_group, $hierarchy = array()) { - global $config; - - if ($id_group == 0) { - $hierarchy = groups_get_childrens($id_group); - } - else { - $hierarchy[] = $id_group; - $parent = db_get_value('parent','tgrupo','id_grupo',$id_group); - - if ($parent !== 0) { - $propagate = db_get_value('propagate','tgrupo','id_grupo',$parent); - - if ($propagate == 1) { - //$childrens_ids_parent = array($parent); - $hierarchy[] = $parent; - $childrens = groups_get_childrens($parent); - if (!empty($childrens)) { - foreach ($childrens as $child) { - //$childrens_ids_parent[] = (int)$child['id_grupo']; - $hierarchy[] = (int)$child['id_grupo']; - } - } - - $hierarchy = groups_get_all_hierarchy_group ($parent, $hierarchy); - } - } - } - return $hierarchy; -} - - - function group_get_data ($id_user = false, $user_strict = false, $acltags, $returnAllGroup = false, $mode = 'group', $agent_filter = array(), $module_filter = array()) { global $config; if ($id_user == false) { $id_user = $config['id_user']; } - + $user_groups = array(); $user_tags = array(); - $groups_without_tags = array(); foreach ($acltags as $group => $tags) { - if ($user_strict) { //Remove groups with tags - if ($tags == '') { - $groups_without_tags[$group] = $group; - } - } $user_groups[$group] = groups_get_name($group); if ($tags != '') { $tags_group = explode(',', $tags); - + foreach ($tags_group as $tag) { $user_tags[$tag] = tags_get_name($tag); } } } - - if ($user_strict) { - $user_groups_ids = implode(',', array_keys($groups_without_tags)); - } - else { - $user_groups_ids = implode(',', array_keys($acltags)); - } - + + $user_groups_ids = implode(',', array_keys($acltags)); + if (!empty($user_groups_ids)) { - switch ($config["dbtype"]) { - case "mysql": - $list_groups = db_get_all_rows_sql(" - SELECT * - FROM tgrupo - WHERE id_grupo IN (" . $user_groups_ids . ") - ORDER BY nombre COLLATE utf8_general_ci ASC"); - break; - case "postgresql": - $list_groups = db_get_all_rows_sql(" - SELECT * - FROM tgrupo - WHERE id_grupo IN (" . $user_groups_ids . ") - ORDER BY nombre ASC"); - break; - case "oracle": - $list_groups = db_get_all_rows_sql(" - SELECT * - FROM tgrupo - WHERE id_grupo IN (" . $user_groups_ids . ") - ORDER BY nombre ASC"); - break; - } + $list_groups = db_get_all_rows_sql(" + SELECT * + FROM tgrupo + WHERE id_grupo IN (" . $user_groups_ids . ") + ORDER BY nombre COLLATE utf8_general_ci ASC" + ); } - + $list = array(); - + if ($list_groups == false) { $list_groups = array(); } - + if ($returnAllGroup) { $i = 1; $list[0]['_id_'] = 0; $list[0]['_name_'] = __('All'); - + $list[0]['_agents_unknown_'] = 0; $list[0]['_monitors_alerts_fired_'] = 0; $list[0]['_total_agents_'] = 0; @@ -2406,7 +1787,7 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu $list[0]['_monitors_unknown_'] = 0; $list[0]['_monitors_not_init_'] = 0; $list[0]['_agents_not_init_'] = 0; - + if ($mode == 'tactical') { $list[0]['_agents_ok_'] = 0; $list[0]['_agents_warning_'] = 0; @@ -2417,81 +1798,93 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu else { $i = 0; } - - /* + + /* * Agent cache for metaconsole. * Retrieve the statistic data from the cache table. */ - if (!$user_strict && is_metaconsole() && !empty($list_groups)) { + if (is_metaconsole() && !empty($list_groups)) { $cache_table = 'tmetaconsole_agent'; - - $sql_stats = "SELECT id_grupo, COUNT(id_agente) AS agents_total, - SUM(total_count) AS monitors_total, - SUM(normal_count) AS monitors_ok, - SUM(warning_count) AS monitors_warning, - SUM(critical_count) AS monitors_critical, - SUM(unknown_count) AS monitors_unknown, - SUM(notinit_count) AS monitors_not_init, - SUM(fired_count) AS alerts_fired - FROM $cache_table - WHERE disabled = 0 - AND id_grupo IN ($user_groups_ids) - GROUP BY id_grupo"; + + $sql_stats = + "SELECT id_grupo, COUNT(id_agente) AS agents_total, + SUM(total_count) AS monitors_total, + SUM(normal_count) AS monitors_ok, + SUM(warning_count) AS monitors_warning, + SUM(critical_count) AS monitors_critical, + SUM(unknown_count) AS monitors_unknown, + SUM(notinit_count) AS monitors_not_init, + SUM(fired_count) AS alerts_fired + FROM $cache_table + WHERE disabled = 0 + AND id_grupo IN ($user_groups_ids) + GROUP BY id_grupo" + ; $data_stats = db_get_all_rows_sql($sql_stats); - - $sql_stats_unknown = "SELECT id_grupo, COUNT(id_agente) AS agents_unknown - FROM $cache_table - WHERE disabled = 0 - AND id_grupo IN ($user_groups_ids) - AND critical_count = 0 - AND warning_count = 0 - AND unknown_count > 0 - GROUP BY id_grupo"; + + $sql_stats_unknown = + "SELECT id_grupo, COUNT(id_agente) AS agents_unknown + FROM $cache_table + WHERE disabled = 0 + AND id_grupo IN ($user_groups_ids) + AND critical_count = 0 + AND warning_count = 0 + AND unknown_count > 0 + GROUP BY id_grupo" + ; $data_stats_unknown = db_get_all_rows_sql($sql_stats_unknown); - - $sql_stats_not_init = "SELECT id_grupo, COUNT(id_agente) AS agents_not_init - FROM $cache_table - WHERE disabled = 0 - AND id_grupo IN ($user_groups_ids) - AND (total_count = 0 OR total_count = notinit_count) - GROUP BY id_grupo"; + + $sql_stats_not_init = + "SELECT id_grupo, COUNT(id_agente) AS agents_not_init + FROM $cache_table + WHERE disabled = 0 + AND id_grupo IN ($user_groups_ids) + AND (total_count = 0 OR total_count = notinit_count) + GROUP BY id_grupo" + ; $data_stats_not_init = db_get_all_rows_sql($sql_stats_not_init); - + if ($mode == 'tactical' || $mode == 'tree') { - $sql_stats_ok = "SELECT id_grupo, COUNT(id_agente) AS agents_ok - FROM $cache_table - WHERE disabled = 0 - AND id_grupo IN ($user_groups_ids) - AND critical_count = 0 - AND warning_count = 0 - AND unknown_count = 0 - AND normal_count > 0 - GROUP BY id_grupo"; + $sql_stats_ok = + "SELECT id_grupo, COUNT(id_agente) AS agents_ok + FROM $cache_table + WHERE disabled = 0 + AND id_grupo IN ($user_groups_ids) + AND critical_count = 0 + AND warning_count = 0 + AND unknown_count = 0 + AND normal_count > 0 + GROUP BY id_grupo" + ; $data_stats_ok = db_get_all_rows_sql($sql_stats_ok); - - $sql_stats_warning = "SELECT id_grupo, COUNT(id_agente) AS agents_warning - FROM $cache_table - WHERE disabled = 0 - AND id_grupo IN ($user_groups_ids) - AND critical_count = 0 - AND warning_count > 0 - GROUP BY id_grupo"; + + $sql_stats_warning = + "SELECT id_grupo, COUNT(id_agente) AS agents_warning + FROM $cache_table + WHERE disabled = 0 + AND id_grupo IN ($user_groups_ids) + AND critical_count = 0 + AND warning_count > 0 + GROUP BY id_grupo" + ; $data_stats_warning = db_get_all_rows_sql($sql_stats_warning); - - $sql_stats_critical = "SELECT id_grupo, COUNT(id_agente) AS agents_critical - FROM $cache_table - WHERE disabled = 0 - AND id_grupo IN ($user_groups_ids) - AND critical_count > 0 - GROUP BY id_grupo"; + + $sql_stats_critical = + "SELECT id_grupo, COUNT(id_agente) AS agents_critical + FROM $cache_table + WHERE disabled = 0 + AND id_grupo IN ($user_groups_ids) + AND critical_count > 0 + GROUP BY id_grupo" + ; $data_stats_critical = db_get_all_rows_sql($sql_stats_critical); } - + $stats_by_group = array(); if (!empty($data_stats)) { foreach ($data_stats as $value) { $group_id = (int) $value['id_grupo']; - + $stats = array(); $stats['agents_total'] = (int) $value['agents_total']; $stats['monitors_total'] = (int) $value['monitors_total']; @@ -2503,7 +1896,7 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu $stats['alerts_fired'] = (int) $value['alerts_fired']; $stats_by_group[$group_id] = $stats; } - + if (!empty($stats_by_group)) { if (!empty($data_stats_unknown)) { foreach ($data_stats_unknown as $value) { @@ -2548,26 +1941,26 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu } } } - + foreach ($list_groups as $key => $item) { $id = $item['id_grupo']; - - if (!$user_strict && is_metaconsole()) { // Agent cache + + if (is_metaconsole()) { // Agent cache $group_stat = array(); if (isset($stats_by_group[$id])) $group_stat = $stats_by_group[$id]; - + $list[$i]['_id_'] = $id; $list[$i]['_name_'] = $item['nombre']; $list[$i]['_iconImg_'] = html_print_image ("images/groups_small/" . groups_get_icon($item['id_grupo']).".png", true, array ("style" => 'vertical-align: middle;')); - + if ($mode == 'tree' && !empty($item['parent'])) $list[$i]['_parent_id_'] = $item['parent']; - + $list[$i]['_agents_unknown_'] = isset($group_stat['agents_unknown']) ? $group_stat['agents_unknown'] : 0; $list[$i]['_monitors_alerts_fired_'] = isset($group_stat['alerts_fired']) ? $group_stat['alerts_fired'] : 0; $list[$i]['_total_agents_'] = isset($group_stat['agents_total']) ? $group_stat['agents_total'] : 0; - + // This fields are not in database $list[$i]['_monitors_ok_'] = isset($group_stat['monitors_ok']) ? $group_stat['monitors_ok'] : 0; $list[$i]['_monitors_critical_'] = isset($group_stat['monitors_critical']) ? $group_stat['monitors_critical'] : 0; @@ -2575,38 +1968,38 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu $list[$i]['_monitors_unknown_'] = isset($group_stat['monitors_unknown']) ? $group_stat['monitors_unknown'] : 0; $list[$i]['_monitors_not_init_'] = isset($group_stat['monitors_not_init']) ? $group_stat['monitors_not_init'] : 0; $list[$i]['_agents_not_init_'] = isset($group_stat['agents_not_init']) ? $group_stat['agents_not_init'] : 0; - + if ($mode == 'tactical' || $mode == 'tree') { $list[$i]['_agents_ok_'] = isset($group_stat['agents_ok']) ? $group_stat['agents_ok'] : 0; $list[$i]['_agents_warning_'] = isset($group_stat['agents_warning']) ? $group_stat['agents_warning'] : 0; $list[$i]['_agents_critical_'] = isset($group_stat['agents_critical']) ? $group_stat['agents_critical'] : 0; $list[$i]['_monitors_alerts_'] = isset($group_stat['alerts']) ? $group_stat['alerts'] : 0;; - + $list[$i]["_monitor_alerts_fire_count_"] = $group_stat[0]["alerts_fired"]; $list[$i]["_total_checks_"] = $group_stat[0]["modules"]; $list[$i]["_total_alerts_"] = $group_stat[0]["alerts"]; } if ($mode == 'tactical') { - // Get total count of monitors for this group, except disabled. + // Get total count of monitors for this group, except disabled. $list[$i]["_monitor_checks_"] = $list[$i]["_monitors_not_init_"] + $list[$i]["_monitors_unknown_"] + $list[$i]["_monitors_warning_"] + $list[$i]["_monitors_critical_"] + $list[$i]["_monitors_ok_"]; - + // Calculate not_normal monitors $list[$i]["_monitor_not_normal_"] = $list[$i]["_monitor_checks_"] - $list[$i]["_monitors_ok_"]; - + if ($list[$i]["_monitor_not_normal_"] > 0 && $list[$i]["_monitor_checks_"] > 0) { $list[$i]["_monitor_health_"] = format_numeric (100 - ($list[$i]["_monitor_not_normal_"] / ($list[$i]["_monitor_checks_"] / 100)), 1); } else { $list[$i]["_monitor_health_"] = 100; } - + if ($list[$i]["_monitors_not_init_"] > 0 && $list[$i]["_monitor_checks_"] > 0) { $list[$i]["_module_sanity_"] = format_numeric (100 - ($list[$i]["_monitors_not_init_"] / ($list[$i]["_monitor_checks_"] / 100)), 1); } else { $list[$i]["_module_sanity_"] = 100; } - + if (isset($list[$i]["_alerts_"])) { if ($list[$i]["_monitors_alerts_fired_"] > 0 && $list[$i]["_alerts_"] > 0) { $list[$i]["_alert_level_"] = format_numeric (100 - ($list[$i]["_monitors_alerts_fired_"] / ($list[$i]["_alerts_"] / 100)), 1); @@ -2619,19 +2012,19 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu $list[$i]["_alert_level_"] = 100; $list[$i]["_alerts_"] = 0; } - + $list[$i]["_monitor_bad_"] = $list[$i]["_monitors_critical_"] + $list[$i]["_monitors_warning_"]; - + if ($list[$i]["_monitor_bad_"] > 0 && $list[$i]["_monitor_checks_"] > 0) { $list[$i]["_global_health_"] = format_numeric (100 - ($list[$i]["_monitor_bad_"] / ($list[$i]["_monitor_checks_"] / 100)), 1); } else { $list[$i]["_global_health_"] = 100; } - + $list[$i]["_server_sanity_"] = format_numeric (100 - $list[$i]["_module_sanity_"], 1); } - + if ($returnAllGroup) { $list[0]['_agents_unknown_'] += $list[$i]['_agents_unknown_']; $list[0]['_monitors_alerts_fired_'] += $list[$i]['_monitors_alerts_fired_']; @@ -2642,7 +2035,7 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu $list[0]['_monitors_unknown_'] += $list[$i]['_monitors_unknown_']; $list[0]['_monitors_not_init_'] += $list[$i]['_monitors_not_init_']; $list[0]['_agents_not_init_'] += $list[$i]['_agents_not_init_']; - + if ($mode == 'tactical' || $mode == 'tree') { $list[0]['_agents_ok_'] += $list[$i]['_agents_ok_']; $list[0]['_agents_warning_'] += $list[$i]['_agents_warning_']; @@ -2650,7 +2043,7 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu $list[0]['_monitors_alerts_'] += $list[$i]['_monitors_alerts_']; } } - + if ($mode == 'group') { if (($list[$i]['_agents_unknown_'] == 0) && ($list[$i]['_monitors_alerts_fired_'] == 0) && ($list[$i]['_total_agents_'] == 0) && ($list[$i]['_monitors_ok_'] == 0) @@ -2658,26 +2051,26 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu unset($list[$i]); } } - + } - else if (($config["realtimestats"] == 0) && !$user_strict) { + else if (($config["realtimestats"] == 0)) { $group_stat = db_get_all_rows_sql ("SELECT * FROM tgroup_stat, tgrupo WHERE tgrupo.id_grupo = tgroup_stat.id_group AND tgroup_stat.id_group = $id ORDER BY nombre"); - + $list[$i]['_id_'] = $id; $list[$i]['_name_'] = $item['nombre']; $list[$i]['_iconImg_'] = html_print_image ("images/groups_small/" . groups_get_icon($item['id_grupo']).".png", true, array ("style" => 'vertical-align: middle;')); - + if ($mode == 'tree' && !empty($item['parent'])) $list[$i]['_parent_id_'] = $item['parent']; - + $list[$i]['_agents_unknown_'] = $group_stat[0]["unknown"]; $list[$i]['_monitors_alerts_fired_'] = $group_stat[0]["alerts_fired"]; $list[$i]['_total_agents_'] = $group_stat[0]["agents"]; - + // This fields are not in database $list[$i]['_monitors_ok_'] = (int) groups_get_normal_monitors($id); $list[$i]['_monitors_critical_'] = (int) groups_get_critical_monitors($id); @@ -2685,38 +2078,38 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu $list[$i]['_monitors_unknown_'] = (int) groups_get_unknown_monitors($id); $list[$i]['_monitors_not_init_'] = (int) groups_get_not_init_monitors($id); $list[$i]['_agents_not_init_'] = (int) groups_get_not_init_agents($id); - + if ($mode == 'tactical' || $mode == 'tree') { $list[$i]['_agents_ok_'] = $group_stat[0]["normal"]; $list[$i]['_agents_warning_'] = $group_stat[0]["warning"]; $list[$i]['_agents_critical_'] = $group_stat[0]["critical"]; $list[$i]['_monitors_alerts_'] = $group_stat[0]["alerts"]; - + $list[$i]["_monitor_alerts_fire_count_"] = $group_stat[0]["alerts_fired"]; $list[$i]["_total_checks_"] = $group_stat[0]["modules"]; $list[$i]["_total_alerts_"] = $group_stat[0]["alerts"]; } if ($mode == 'tactical') { - // Get total count of monitors for this group, except disabled. + // Get total count of monitors for this group, except disabled. $list[$i]["_monitor_checks_"] = $list[$i]["_monitors_not_init_"] + $list[$i]["_monitors_unknown_"] + $list[$i]["_monitors_warning_"] + $list[$i]["_monitors_critical_"] + $list[$i]["_monitors_ok_"]; - + // Calculate not_normal monitors $list[$i]["_monitor_not_normal_"] = $list[$i]["_monitor_checks_"] - $list[$i]["_monitors_ok_"]; - + if ($list[$i]["_monitor_not_normal_"] > 0 && $list[$i]["_monitor_checks_"] > 0) { $list[$i]["_monitor_health_"] = format_numeric (100 - ($list[$i]["_monitor_not_normal_"] / ($list[$i]["_monitor_checks_"] / 100)), 1); } else { $list[$i]["_monitor_health_"] = 100; } - + if ($list[$i]["_monitors_not_init_"] > 0 && $list[$i]["_monitor_checks_"] > 0) { $list[$i]["_module_sanity_"] = format_numeric (100 - ($list[$i]["_monitors_not_init_"] / ($list[$i]["_monitor_checks_"] / 100)), 1); } else { $list[$i]["_module_sanity_"] = 100; } - + if (isset($list[$i]["_alerts_"])) { if ($list[$i]["_monitors_alerts_fired_"] > 0 && $list[$i]["_alerts_"] > 0) { $list[$i]["_alert_level_"] = format_numeric (100 - ($list[$i]["_monitors_alerts_fired_"] / ($list[$i]["_alerts_"] / 100)), 1); @@ -2724,24 +2117,24 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu else { $list[$i]["_alert_level_"] = 100; } - } + } else { $list[$i]["_alert_level_"] = 100; $list[$i]["_alerts_"] = 0; } - + $list[$i]["_monitor_bad_"] = $list[$i]["_monitors_critical_"] + $list[$i]["_monitors_warning_"]; - + if ($list[$i]["_monitor_bad_"] > 0 && $list[$i]["_monitor_checks_"] > 0) { $list[$i]["_global_health_"] = format_numeric (100 - ($list[$i]["_monitor_bad_"] / ($list[$i]["_monitor_checks_"] / 100)), 1); } else { $list[$i]["_global_health_"] = 100; } - + $list[$i]["_server_sanity_"] = format_numeric (100 - $list[$i]["_module_sanity_"], 1); } - + if ($returnAllGroup) { $list[0]['_agents_unknown_'] += $group_stat[0]["unknown"]; $list[0]['_monitors_alerts_fired_'] += $group_stat[0]["alerts_fired"]; @@ -2752,7 +2145,7 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu $list[0]['_monitors_unknown_'] += $list[$i]['_monitors_unknown_']; $list[0]['_monitors_not_init_'] += $list[$i]['_monitors_not_init_']; $list[0]['_agents_not_init_'] += $list[$i]['_agents_not_init_']; - + if ($mode == 'tactical' || $mode == 'tree') { $list[0]['_agents_ok_'] += $group_stat[0]["normal"]; $list[0]['_agents_warning_'] += $group_stat[0]["warning"]; @@ -2760,7 +2153,7 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu $list[0]['_monitors_alerts_'] += $group_stat[0]["alerts"]; } } - + if ($mode == 'group') { if (! defined ('METACONSOLE')) { if (($list[$i]['_agents_unknown_'] == 0) && ($list[$i]['_monitors_alerts_fired_'] == 0) && ($list[$i]['_total_agents_'] == 0) && ($list[$i]['_monitors_ok_'] == 0) && ($list[$i]['_monitors_critical_'] == 0) && ($list[$i]['_monitors_warning_'] == 0) && ($list[$i]['_monitors_unknown_'] == 0) && ($list[$i]['_monitors_not_init_'] == 0) && ($list[$i]['_agents_not_init_'] == 0)) { @@ -2773,56 +2166,55 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu } } } - } else { $list[$i]['_id_'] = $id; $list[$i]['_name_'] = $item['nombre']; $list[$i]['_iconImg_'] = html_print_image ("images/groups_small/" . groups_get_icon($item['id_grupo']).".png", true, array ("style" => 'vertical-align: middle;')); - + if ($mode == 'tree' && !empty($item['parent'])) $list[$i]['_parent_id_'] = $item['parent']; - + $list[$i]['_monitors_ok_'] = (int) groups_get_normal_monitors ($id, $agent_filter, $module_filter, $user_strict, $acltags, $config["realtimestats"]); $list[$i]['_monitors_critical_'] = (int) groups_get_critical_monitors ($id, $agent_filter, $module_filter, $user_strict, $acltags, $config["realtimestats"]); $list[$i]['_monitors_warning_'] = (int) groups_get_warning_monitors ($id, $agent_filter, $module_filter, $user_strict, $acltags, $config["realtimestats"]); $list[$i]['_monitors_unknown_'] = (int) groups_get_unknown_monitors ($id, $agent_filter, $module_filter, $user_strict, $acltags, $config["realtimestats"]); $list[$i]['_monitors_not_init_'] = (int) groups_get_not_init_monitors ($id, $agent_filter, $module_filter, $user_strict, $acltags, $config["realtimestats"]); - $list[$i]['_monitors_alerts_fired_'] = groups_monitor_fired_alerts ($id, $user_strict, $id); + $list[$i]['_monitors_alerts_fired_'] = groups_monitor_fired_alerts ($id); $list[$i]['_total_agents_'] = (int) groups_get_total_agents ($id, $agent_filter, $module_filter, $user_strict, $acltags, $config["realtimestats"]); $list[$i]['_agents_unknown_'] = (int) groups_get_unknown_agents ($id, $agent_filter, $module_filter, $user_strict, $acltags, $config["realtimestats"]); $list[$i]['_agents_not_init_'] = (int) groups_get_not_init_agents ($id, $agent_filter, $module_filter, $user_strict, $acltags, $config["realtimestats"]); - + if ($mode == 'tactical' || $mode == 'tree') { $list[$i]['_agents_ok_'] = (int) groups_get_normal_agents ($id, $agent_filter, $module_filter, $user_strict, $acltags, $config["realtimestats"]); $list[$i]['_agents_warning_'] = (int) groups_get_warning_agents ($id, $agent_filter, $module_filter, $user_strict, $acltags, $config["realtimestats"]); $list[$i]['_agents_critical_'] = (int) groups_get_critical_agents ($id, $agent_filter, $module_filter, $user_strict, $acltags, $config["realtimestats"]); - $list[$i]['_monitors_alerts_'] = groups_monitor_alerts ($id, $user_strict, $id); - + $list[$i]['_monitors_alerts_'] = groups_monitor_alerts ($id); + // TODO - //~ $list[$i]["_total_checks_"] + //~ $list[$i]["_total_checks_"] //~ $list[$i]["_total_alerts_"] - - // Get total count of monitors for this group, except disabled. + + // Get total count of monitors for this group, except disabled. $list[$i]["_monitor_checks_"] = $list[$i]["_monitors_not_init_"] + $list[$i]["_monitors_unknown_"] + $list[$i]["_monitors_warning_"] + $list[$i]["_monitors_critical_"] + $list[$i]["_monitors_ok_"]; - + // Calculate not_normal monitors $list[$i]["_monitor_not_normal_"] = $list[$i]["_monitor_checks_"] - $list[$i]["_monitors_ok_"]; - + if ($list[$i]["_monitor_not_normal_"] > 0 && $list[$i]["_monitor_checks_"] > 0) { $list[$i]["_monitor_health_"] = format_numeric (100 - ($list[$i]["_monitor_not_normal_"] / ($list[$i]["_monitor_checks_"] / 100)), 1); } else { $list[$i]["_monitor_health_"] = 100; } - + if ($list[$i]["_monitors_not_init_"] > 0 && $list[$i]["_monitor_checks_"] > 0) { $list[$i]["_module_sanity_"] = format_numeric (100 - ($list[$i]["_monitors_not_init_"] / ($list[$i]["_monitor_checks_"] / 100)), 1); } else { $list[$i]["_module_sanity_"] = 100; } - + if (isset($list[$i]["_alerts_"])) { if ($list[$i]["_monitors_alerts_fired_"] > 0 && $list[$i]["_alerts_"] > 0) { $list[$i]["_alert_level_"] = format_numeric (100 - ($list[$i]["_monitors_alerts_fired_"] / ($list[$i]["_alerts_"] / 100)), 1); @@ -2835,19 +2227,19 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu $list[$i]["_alert_level_"] = 100; $list[$i]["_alerts_"] = 0; } - + $list[$i]["_monitor_bad_"] = $list[$i]["_monitors_critical_"] + $list[$i]["_monitors_warning_"]; - + if ($list[$i]["_monitor_bad_"] > 0 && $list[$i]["_monitor_checks_"] > 0) { $list[$i]["_global_health_"] = format_numeric (100 - ($list[$i]["_monitor_bad_"] / ($list[$i]["_monitor_checks_"] / 100)), 1); } else { $list[$i]["_global_health_"] = 100; } - + $list[$i]["_server_sanity_"] = format_numeric (100 - $list[$i]["_module_sanity_"], 1); } - + if ($returnAllGroup) { $list[0]['_agents_unknown_'] += $list[$i]['_agents_unknown_']; $list[0]['_monitors_alerts_fired_'] += $list[$i]['_monitors_alerts_fired_']; @@ -2858,7 +2250,7 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu $list[0]['_monitors_unknown_'] += $list[$i]['_monitors_unknown_']; $list[0]['_monitors_not_init_'] = $list[$i]['_monitors_not_init_']; $list[0]['_agents_not_init_'] += $list[$i]['_agents_not_init_']; - + if ($mode == 'tactical' || $mode == 'tree') { $list[0]['_agents_ok_'] += $list[$i]['_agents_ok_']; $list[0]['_agents_warning_'] += $list[$i]['_agents_warning_']; @@ -2866,7 +2258,7 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu $list[0]['_monitors_alerts_'] += $list[$i]['_monitors_alerts_']; } } - + if ($mode == 'group') { if (! defined ('METACONSOLE')) { if (($list[$i]['_agents_unknown_'] == 0) && ($list[$i]['_monitors_alerts_fired_'] == 0) && ($list[$i]['_total_agents_'] == 0) && ($list[$i]['_monitors_ok_'] == 0) && ($list[$i]['_monitors_critical_'] == 0) && ($list[$i]['_monitors_warning_'] == 0) && ($list[$i]['_monitors_unknown_'] == 0) && ($list[$i]['_monitors_not_init_'] == 0) && ($list[$i]['_agents_not_init_'] == 0)) { @@ -2881,198 +2273,24 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu } $i++; } - - if ($user_strict) { - foreach ($user_tags as $group_id => $tag_name) { - $id = db_get_value('id_tag', 'ttag', 'name', $tag_name); - - $list[$i]['_id_'] = $id; - $list[$i]['_name_'] = $tag_name; - $list[$i]['_iconImg_'] = html_print_image ("images/tag_red.png", true, array ("style" => 'vertical-align: middle;')); - $list[$i]['_is_tag_'] = 1; - - $list[$i]['_total_agents_'] = (int) tags_get_total_agents ($id, $acltags, $agent_filter, $module_filter, $config["realtimestats"]); - $list[$i]['_agents_unknown_'] = (int) tags_get_unknown_agents ($id, $acltags, $agent_filter, $module_filter, $config["realtimestats"]); - $list[$i]['_agents_not_init_'] = (int) tags_get_not_init_agents ($id, $acltags, $agent_filter, $module_filter, $config["realtimestats"]); - $list[$i]['_monitors_ok_'] = (int) tags_get_normal_monitors ($id, $acltags, $agent_filter, $module_filter); - $list[$i]['_monitors_critical_'] = (int) tags_get_critical_monitors ($id, $acltags, $agent_filter, $module_filter); - $list[$i]['_monitors_warning_'] = (int) tags_get_warning_monitors ($id, $acltags, $agent_filter, $module_filter); - $list[$i]['_monitors_not_init_'] = (int) tags_get_not_init_monitors ($id, $acltags, $agent_filter, $module_filter); - $list[$i]['_monitors_unknown_'] = (int) tags_get_unknown_monitors ($id, $acltags, $agent_filter, $module_filter); - $list[$i]['_monitors_alerts_fired_'] = tags_monitors_fired_alerts($id, $acltags); - - if ($mode == 'tactical' || $mode == 'tree') { - $list[$i]['_agents_ok_'] = (int) tags_get_normal_agents ($id, $acltags, $agent_filter, $module_filter, $config["realtimestats"]); - $list[$i]['_agents_warning_'] = (int) tags_get_warning_agents ($id, $acltags, $agent_filter, $module_filter, $config["realtimestats"]); - $list[$i]['_agents_critical_'] = (int) tags_get_critical_agents ($id, $acltags, $agent_filter, $module_filter, $config["realtimestats"]); - $list[$i]['_monitors_alerts_'] = tags_get_monitors_alerts ($id, $acltags); - } - if ($mode == 'tactical') { - // Get total count of monitors for this group, except disabled. - $list[$i]["_monitor_checks_"] = $list[$i]["_monitors_not_init_"] + $list[$i]["_monitors_unknown_"] + $list[$i]["_monitors_warning_"] + $list[$i]["_monitors_critical_"] + $list[$i]["_monitors_ok_"]; - - // Calculate not_normal monitors - $list[$i]["_monitor_not_normal_"] = $list[$i]["_monitor_checks_"] - $list[$i]["_monitors_ok_"]; - - if ($list[$i]["_monitor_not_normal_"] > 0 && $list[$i]["_monitor_checks_"] > 0) { - $list[$i]["_monitor_health_"] = format_numeric (100 - ($list[$i]["_monitor_not_normal_"] / ($list[$i]["_monitor_checks_"] / 100)), 1); - } - else { - $list[$i]["_monitor_health_"] = 100; - } - - if ($list[$i]["_monitors_not_init_"] > 0 && $list[$i]["_monitor_checks_"] > 0) { - $list[$i]["_module_sanity_"] = format_numeric (100 - ($list[$i]["_monitors_not_init_"] / ($list[$i]["_monitor_checks_"] / 100)), 1); - } - else { - $list[$i]["_module_sanity_"] = 100; - } - - if (isset($list[$i]["_monitors_alerts_"])) { - if ($list[$i]["_monitors_alerts_fired_"] > 0 && $list[$i]["_monitors_alerts_"] > 0) { - $list[$i]["_alert_level_"] = format_numeric (100 - ($list[$i]["_monitors_alerts_fired_"] / ($list[$i]["_monitors_alerts_"] / 100)), 1); - } - else { - $list[$i]["_alert_level_"] = 100; - } - } - else { - $list[$i]["_alert_level_"] = 100; - $list[$i]["_monitors_alerts_"] = 0; - } - - $list[$i]["_monitor_bad_"] = $list[$i]["_monitors_critical_"] + $list[$i]["_monitors_warning_"]; - - if ($list[$i]["_monitor_bad_"] > 0 && $list[$i]["_monitor_checks_"] > 0) { - $list[$i]["_global_health_"] = format_numeric (100 - ($list[$i]["_monitor_bad_"] / ($list[$i]["_monitor_checks_"] / 100)), 1); - } - else { - $list[$i]["_global_health_"] = 100; - } - - $list[$i]["_server_sanity_"] = format_numeric (100 - $list[$i]["_module_sanity_"], 1); - } - - if ($returnAllGroup) { - $list[0]['_agents_unknown_'] += $list[$i]['_agents_unknown_']; - $list[0]['_monitors_alerts_fired_'] += $list[$i]['_monitors_alerts_fired_']; - $list[0]['_total_agents_'] += $list[$i]['_total_agents_']; - $list[0]['_monitors_ok_'] += $list[$i]['_monitors_ok_']; - $list[0]['_monitors_critical_'] += $list[$i]['_monitors_critical_']; - $list[0]['_monitors_warning_'] += $list[$i]['_monitors_warning_']; - $list[0]['_monitors_unknown_'] += $list[$i]['_monitors_unknown_']; - $list[0]['_agents_not_init_'] += $list[$i]['_agents_not_init_']; - $list[0]['_monitors_not_init_'] += $list[$i]['_monitors_not_init_']; - - if ($mode == 'tactical' || $mode == 'tree') { - $list[0]['_agents_ok_'] += $list[$i]['_agents_ok_']; - $list[0]['_agents_warning_'] += $list[$i]['_agents_warning_']; - $list[0]['_agents_critical_'] += $list[$i]['_agents_critical_']; - $list[0]['_monitors_alerts_'] += $list[$i]['_monitors_alerts_']; - } - } - - if ($mode == 'group') { - if (! defined ('METACONSOLE')) { - if (($list[$i]['_agents_unknown_'] == 0) && ($list[$i]['_monitors_alerts_fired_'] == 0) && ($list[$i]['_total_agents_'] == 0) && ($list[$i]['_monitors_ok_'] == 0) && ($list[$i]['_monitors_critical_'] == 0) && ($list[$i]['_monitors_warning_'] == 0) && ($list[$i]['_monitors_unknown_'] == 0) && ($list[$i]['_monitors_not_init_'] == 0) && ($list[$i]['_agents_not_init_'] == 0)) { - unset($list[$i]); - } - } - else { - if (($list[$i]['_agents_unknown_'] == 0) && ($list[$i]['_monitors_alerts_fired_'] == 0) && ($list[$i]['_total_agents_'] == 0) && ($list[$i]['_monitors_ok_'] == 0) && ($list[$i]['_monitors_critical_'] == 0) && ($list[$i]['_monitors_warning_'] == 0)) { - unset($list[$i]); - } - } - } - $i++; - } - } - - return $list; -} -function group_get_groups_list($id_user = false, $user_strict = false, $access = 'AR', $force_group_and_tag = true, $returnAllGroup = false, $mode = 'group') { - global $config; - - if ($id_user == false) { - $id_user = $config['id_user']; - } - - $acltags = tags_get_user_groups_and_tags ($id_user, $access, $user_strict); - - // If using metaconsole, the strict users will use the agent table of every node - if (is_metaconsole() && $user_strict) { - $servers = metaconsole_get_servers(); - - $result_list = array (); - foreach ($servers as $server) { - - if (metaconsole_connect($server) != NOERR) { - continue; - } - $server_list = group_get_data ($id_user, $user_strict, - $acltags, $returnAllGroup, $mode); - - foreach ($server_list as $server_item) { - if (! isset ($result_list[$server_item['_name_']])) { - - $result_list[$server_item['_name_']] = $server_item; - } - else { - $result_list[$server_item['_name_']]['_monitors_ok_'] += $server_item['_monitors_ok_']; - $result_list[$server_item['_name_']]['_monitors_critical_'] += $server_item['_monitors_critical_']; - $result_list[$server_item['_name_']]['_monitors_warning_'] += $server_item['_monitors_warning_']; - $result_list[$server_item['_name_']]['_agents_unknown_'] += $server_item['_agents_unknown_']; - $result_list[$server_item['_name_']]['_total_agents_'] += $server_item['_total_agents_']; - $result_list[$server_item['_name_']]['_monitors_alerts_fired_'] += $server_item['_monitors_alerts_fired_']; - - if ($mode == 'tactical') { - $result_list[$server_item['_name_']]['_agents_ok_'] += $server_item['_agents_ok_']; - $result_list[$server_item['_name_']]['_agents_critical_'] += $server_item['_agents_critical_']; - $result_list[$server_item['_name_']]['_agents_warning_'] += $server_item['_agents_warning_']; - $result_list[$server_item['_name_']]['_monitors_alerts_'] += $server_item['_monitors_alerts_']; - - $result_list[$server_item['_name_']]["_monitor_checks_"] += $server_item["_monitor_checks_"]; - $result_list[$server_item['_name_']]["_monitor_not_normal_"] += $server_item["_monitor_not_normal_"]; - $result_list[$server_item['_name_']]["_monitor_health_"] += $server_item["_monitor_health_"]; - $result_list[$server_item['_name_']]["_module_sanity_"] += $server_item["_module_sanity_"]; - $result_list[$server_item['_name_']]["_alerts_"] += $server_item["_alerts_"]; - $result_list[$server_item['_name_']]["_alert_level_"] += $server_item["_alert_level_"]; - $result_list[$server_item['_name_']]["_monitor_bad_"] += $server_item["_monitor_bad_"]; - $result_list[$server_item['_name_']]["_global_health_"] += $server_item["_global_health_"]; - $result_list[$server_item['_name_']]["_server_sanity_"] += $server_item["_server_sanity_"]; - $result_list[$server_item['_name_']]["_monitor_alerts_fire_count_"] += $server_item["_monitor_alerts_fire_count_"]; - $result_list[$server_item['_name_']]["_total_checks_"] += $server_item["_total_checks_"]; - $result_list[$server_item['_name_']]["_total_alerts_"] += $server_item["_total_alerts_"]; - } - } - } - metaconsole_restore_db(); - - } - - return $result_list; - } - // If using metaconsole, the not strict users will use the metaconsole's agent cache table - else { - $result_list = group_get_data ($id_user, $user_strict, $acltags, - $returnAllGroup, $mode); - - return $result_list; - } + return $list; } function groups_get_group_deep ($id_group) { global $config; - $parents = groups_get_parents($id_group, false); - + + $groups = users_get_groups(false, "AR", true, true); + + $parents = groups_get_parents($id_group, false, $groups); + if (empty($parents)) { $deep = ""; } else { $deep = str_repeat("  ", count($parents)); } - + return $deep; } diff --git a/pandora_console/include/functions_groupview.php b/pandora_console/include/functions_groupview.php index db7eec8706..15b4d577bf 100644 --- a/pandora_console/include/functions_groupview.php +++ b/pandora_console/include/functions_groupview.php @@ -16,877 +16,179 @@ include_once ($config['homedir'] . "/include/functions_groups.php"); include_once ($config['homedir'] . "/include/functions_tags.php"); +include_once ($config['homedir'] . "/include/class/Tree.class.php"); +include_once ($config['homedir'] . "/include/class/TreeGroup.class.php"); -function groupview_get_all_data ($id_user = false, $user_strict = false, $acltags, $returnAllGroup = false, $agent_filter = array(), $module_filter = array(), $access = 'AR') { - global $config; - if ($id_user == false) { - $id_user = $config['id_user']; - } - - $user_groups = array(); - $user_tags = array(); - - foreach ($acltags as $item) { - $user_groups[$item["id_grupo"]] = $item["nombre"]; - - if ($item["tags"] != '') { - $tags_group = explode(',', $item["tags"]); - - foreach ($tags_group as $tag) { - $user_tags[$tag] = tags_get_name($tag); - } - } - } - - $user_groups_ids = implode(',', array_keys($acltags)); - - if (!empty($user_groups_ids)) { - if (is_metaconsole()) { - switch ($config["dbtype"]) { - case "mysql": - $list_groups = db_get_all_rows_sql(" - SELECT * - FROM tgrupo - WHERE id_grupo IN (" . $user_groups_ids . ") - AND id_grupo IN (SELECT id_grupo FROM tmetaconsole_agent WHERE disabled = 0) - ORDER BY nombre COLLATE utf8_general_ci ASC"); - break; - case "postgresql": - $list_groups = db_get_all_rows_sql(" - SELECT * - FROM tgrupo - WHERE id_grupo IN (" . $user_groups_ids . ") - AND id_grupo IN (SELECT id_grupo FROM tmetaconsole_agent WHERE disabled = 0) - ORDER BY nombre ASC"); - break; - case "oracle": - $list_groups = db_get_all_rows_sql(" - SELECT * - FROM tgrupo - WHERE id_grupo IN (" . $user_groups_ids . ") - AND id_grupo IN (SELECT id_grupo FROM tmetaconsole_agent WHERE disabled = 0) - ORDER BY nombre ASC"); - break; - } - } - else { - switch ($config["dbtype"]) { - case "mysql": - $list_groups = db_get_all_rows_sql(" - SELECT * - FROM tgrupo - WHERE id_grupo IN (" . $user_groups_ids . ") - AND id_grupo IN (SELECT id_grupo FROM tagente WHERE disabled = 0) - ORDER BY nombre COLLATE utf8_general_ci ASC"); - break; - case "postgresql": - $list_groups = db_get_all_rows_sql(" - SELECT * - FROM tgrupo - WHERE id_grupo IN (" . $user_groups_ids . ") - AND id_grupo IN (SELECT id_grupo FROM tagente WHERE disabled = 0) - ORDER BY nombre ASC"); - break; - case "oracle": - $list_groups = db_get_all_rows_sql(" - SELECT * - FROM tgrupo - WHERE id_grupo IN (" . $user_groups_ids . ") - AND id_grupo IN (SELECT id_grupo FROM tagente WHERE disabled = 0) - ORDER BY nombre ASC"); - break; - } - } - } - - foreach ($list_groups as $group) { - $list[$group['id_grupo']]['_name_'] = $group['nombre']; - $list[$group['id_grupo']]['_id_'] = $group['id_grupo']; - $list[$group['id_grupo']]['_monitors_critical_'] = 0; - $list[$group['id_grupo']]['_monitors_warning_'] = 0; - $list[$group['id_grupo']]['_monitors_unknown_'] = 0; - $list[$group['id_grupo']]['_monitors_not_init_'] = 0; - $list[$group['id_grupo']]['_monitors_ok_'] = 0; - $list[$group['id_grupo']]['_agents_not_init_'] = 0; - $list[$group['id_grupo']]['_agents_unknown_'] = 0; - $list[$group['id_grupo']]['_agents_critical_'] = 0; - $list[$group['id_grupo']]['_total_agents_'] = 0; - $list[$group['id_grupo']]["_monitor_checks_"] = 0; - $list[$group['id_grupo']]["_monitor_not_normal_"] = 0; - $list[$group['id_grupo']]['_monitors_alerts_fired_'] = 0; - } - if ($list_groups == false) { - $list_groups = array(); - } - - /* - * Agent cache for metaconsole. - * Retrieve the statistic data from the cache table. - */ - if (is_metaconsole()) { - foreach ($list_groups as $group) { - $group_agents = db_get_row_sql("SELECT SUM(warning_count) AS _monitors_warning_, - SUM(critical_count) AS _monitors_critical_, - SUM(normal_count) AS _monitors_ok_, - SUM(unknown_count) AS _monitors_unknown_, - SUM(notinit_count) AS _monitors_not_init_, - SUM(fired_count) AS _monitors_alerts_fired_, - COUNT(*) AS _total_agents_, id_grupo, intervalo, - ultimo_contacto, disabled - FROM tmetaconsole_agent ta - LEFT JOIN tmetaconsole_agent_secondary_group tasg - ON ta.id_agente = tasg.id_agent - WHERE ( - ta.id_grupo = " . $group['id_grupo'] . " - OR tasg.id_group = " . $group['id_grupo'] . " - ) AND disabled = 0 GROUP BY id_grupo"); - $list[$group['id_grupo']]['_monitors_critical_'] = (int)$group_agents['_monitors_critical_']; - $list[$group['id_grupo']]['_monitors_warning_'] = (int)$group_agents['_monitors_warning_']; - $list[$group['id_grupo']]['_monitors_unknown_'] = (int)$group_agents['_monitors_unknown_']; - $list[$group['id_grupo']]['_monitors_not_init_'] = (int)$group_agents['_monitors_not_init_']; - $list[$group['id_grupo']]['_monitors_ok_'] = (int)$group_agents['_monitors_ok_']; - - $list[$group['id_grupo']]['_monitors_alerts_fired_'] = (int)$group_agents['_monitors_alerts_fired_']; - - $list[$group['id_grupo']]['_total_agents_'] = (int)$group_agents['_total_agents_']; - - $list[$group['id_grupo']]["_monitor_checks_"] = $list[$group['id_grupo']]["_monitors_not_init_"] + $list[$group['id_grupo']]["_monitors_unknown_"] + $list[$group['id_grupo']]["_monitors_warning_"] + $list[$group['id_grupo']]["_monitors_critical_"] + $list[$group['id_grupo']]["_monitors_ok_"]; - - // Calculate not_normal monitors - $list[$group['id_grupo']]["_monitor_not_normal_"] = $list[$group['id_grupo']]["_monitor_checks_"] - $list[$group['id_grupo']]["_monitors_ok_"]; - - $total_agents = $list[$group['id_grupo']]['_total_agents_']; - - if (($group['id_grupo'] != 0) && ($total_agents > 0)) { - $agents = db_get_all_rows_sql("SELECT warning_count, - critical_count, - normal_count, - unknown_count, - notinit_count, - fired_count, - disabled - FROM tmetaconsole_agent - WHERE id_grupo = " . $group['id_grupo'] ); - foreach ($agents as $agent) { - if ($agent['critical_count'] > 0) { - $list[$group['id_grupo']]['_agents_critical_'] += 1; - } - else { - if (($agent['critical_count'] == 0) && ($agent['warning_count'] == 0) && ($group_agents['disabled'] == 0) && ($agent['normal_count'] == 0)) { - if ($agent['unknown_count'] > 0) { - $list[$group['id_grupo']]['_agents_unknown_'] += 1; - } - } - if (($agent['critical_count'] == 0) && ($agent['warning_count'] == 0) && ($group_agents['disabled'] == 0) && ($agent['normal_count'] == 0) && ($agent['unknown_count'] == 0)) { - if ($agent['notinit_count'] > 0) { - $list[$group['id_grupo']]['_agents_not_init_'] += 1; - } - } - } - } - } - } - } - else if (false) { //FIXME: The cached group view is wasted. Avoid to reach this code. - - $group_stat = db_get_all_rows_sql ("SELECT - SUM(ta.normal_count) as normal, SUM(ta.critical_count) as critical, - SUM(ta.warning_count) as warning,SUM(ta.unknown_count) as unknown, - SUM(ta.notinit_count) as not_init, SUM(fired_count) as alerts_fired - FROM tagente ta - WHERE id_grupo IN ($user_groups_ids)"); - - $list['_agents_unknown_'] = $group_stat[0]["unknown"]; - $list['_monitors_alerts_fired_'] = $group_stat[0]["alerts_fired"]; - - $list['_monitors_ok_'] = $group_stat[0]["normal"]; - $list['_monitors_warning_'] = $group_stat[0]["warning"]; - $list['_monitors_critical_'] = $group_stat[0]["critical"]; - $list['_monitors_unknown_'] = $group_stat[0]["unknown"]; - $list['_monitors_not_init_'] = $group_stat[0]["not_init"]; - $total_agentes = agents_get_agents (false, array('count(*) as total_agents'), $access,false, false); - $list['_total_agents_'] = $total_agentes[0]['total_agents']; - $list["_monitor_alerts_fire_count_"] = $group_stat[0]["alerts_fired"]; - - $list['_monitors_alerts_'] = groupview_monitor_alerts (explode(',',$user_groups_ids), $user_strict,explode(',',$user_groups_ids)); - // Get total count of monitors for this group, except disabled. - $list["_monitor_checks_"] = $list["_monitors_not_init_"] + $list["_monitors_unknown_"] + $list["_monitors_warning_"] + $list["_monitors_critical_"] + $list["_monitors_ok_"]; - - // Calculate not_normal monitors - $list["_monitor_not_normal_"] = $list["_monitor_checks_"] - $list["_monitors_ok_"]; - - if ($list["_monitor_not_normal_"] > 0 && $list["_monitor_checks_"] > 0) { - $list["_monitor_health_"] = format_numeric (100 - ($list["_monitor_not_normal_"] / ($list["_monitor_checks_"] / 100)), 1); - } - else { - $list["_monitor_health_"] = 100; - } - - if ($list["_monitors_not_init_"] > 0 && $list["_monitor_checks_"] > 0) { - $list["_module_sanity_"] = format_numeric (100 - ($list["_monitors_not_init_"] / ($list["_monitor_checks_"] / 100)), 1); - } - else { - $list["_module_sanity_"] = 100; - } - - if (isset($list["_alerts_"])) { - if ($list["_monitors_alerts_fired_"] > 0 && $list["_alerts_"] > 0) { - $list["_alert_level_"] = format_numeric (100 - ($list["_monitors_alerts_fired_"] / ($list["_alerts_"] / 100)), 1); - } - else { - $list["_alert_level_"] = 100; - } - } - else { - $list["_alert_level_"] = 100; - $list["_alerts_"] = 0; - } - - $list["_monitor_bad_"] = $list["_monitors_critical_"] + $list["_monitors_warning_"]; - - if ($list["_monitor_bad_"] > 0 && $list["_monitor_checks_"] > 0) { - $list["_global_health_"] = format_numeric (100 - ($list["_monitor_bad_"] / ($list["_monitor_checks_"] / 100)), 1); - } - else { - $list["_global_health_"] = 100; - } - - $list["_server_sanity_"] = format_numeric (100 - $list["_module_sanity_"], 1); - } - else { - foreach ($list_groups as $group) { - $agent_not_init = agents_get_agents(array ( - 'disabled' => 0, - 'id_grupo' => $group['id_grupo'], - 'status' => AGENT_STATUS_NOT_INIT), - array ('COUNT(DISTINCT id_agente) as total'), $access, false); - $list[$group['id_grupo']]['_agents_not_init_'] = isset ($agent_not_init[0]['total']) ? $agent_not_init[0]['total'] : 0; - $agent_unknown = agents_get_agents(array ( - 'disabled' => 0, - 'id_grupo' => $group['id_grupo'], - 'status' => AGENT_STATUS_UNKNOWN), - array ('COUNT(DISTINCT id_agente) as total'), $access, false); - $list[$group['id_grupo']]['_agents_unknown_'] = isset ($agent_unknown[0]['total']) ? $agent_unknown[0]['total'] : 0; - $agent_critical = agents_get_agents(array ( - 'disabled' => 0, - 'id_grupo' => $group['id_grupo'], - 'status' => AGENT_STATUS_CRITICAL), - array ('COUNT(DISTINCT id_agente) as total'), $access, false); - $list[$group['id_grupo']]['_agents_critical_'] = isset ($agent_critical[0]['total']) ? $agent_critical[0]['total'] : 0; - $agent_total = agents_get_agents(array ( - 'disabled' => 0, - 'id_grupo' => $group['id_grupo']), - array ('COUNT(DISTINCT id_agente) as total'), $access, false); - $list[$group['id_grupo']]['_total_agents_'] = isset ($agent_total[0]['total']) ? $agent_total[0]['total'] : 0; - $list[$group['id_grupo']]["_monitor_not_normal_"] = $list[$group['id_grupo']]["_monitor_checks_"] - $list[$group['id_grupo']]["_monitors_ok_"]; - $list[$group['id_grupo']]['_monitors_alerts_fired_'] = groupview_monitor_fired_alerts ($group['id_grupo'], $user_strict,array($group['id_grupo'])); - $result_list = db_get_all_rows_sql("SELECT COUNT(*) as contado, estado - FROM tagente_estado tae INNER JOIN tagente ta - ON tae.id_agente = ta.id_agente - AND ta.disabled = 0 - AND ta.id_grupo = " . $group['id_grupo'] . " - INNER JOIN tagente_modulo tam - ON tae.id_agente_modulo = tam.id_agente_modulo - AND tam.disabled = 0 - WHERE tae.utimestamp > 0 - GROUP BY estado"); - if ($result_list) { - foreach ($result_list as $result) { - switch ($result['estado']) { - case AGENT_MODULE_STATUS_CRITICAL_BAD: - $list[$group['id_grupo']]['_monitors_critical_'] = (int)$result['contado']; - break; - case AGENT_MODULE_STATUS_WARNING_ALERT: - break; - case AGENT_MODULE_STATUS_WARNING: - $list[$group['id_grupo']]['_monitors_warning_'] = (int)$result['contado']; - break; - case AGENT_MODULE_STATUS_UNKNOWN: - $list[$group['id_grupo']]['_monitors_unknown_'] = (int)$result['contado']; - break; - } - } - } - $result_normal = db_get_row_sql("SELECT COUNT(*) as contado - FROM tagente_estado tae INNER JOIN tagente ta - ON tae.id_agente = ta.id_agente - AND ta.disabled = 0 - AND ta.id_grupo = " . $group['id_grupo'] . " - INNER JOIN tagente_modulo tam - ON tae.id_agente_modulo = tam.id_agente_modulo - AND tam.disabled = 0 - WHERE tae.estado = 0 - AND (tae.utimestamp > 0 OR tam.id_tipo_modulo IN(21,22,23,100)) - GROUP BY estado"); - $list[$group['id_grupo']]['_monitors_ok_'] = isset ($result_normal['contado']) ? $result_normal['contado'] : 0; - - $result_not_init = db_get_row_sql("SELECT COUNT(*) as contado - FROM tagente_estado tae INNER JOIN tagente ta - ON tae.id_agente = ta.id_agente - AND ta.disabled = 0 - AND ta.id_grupo = " . $group['id_grupo'] . " - INNER JOIN tagente_modulo tam - ON tae.id_agente_modulo = tam.id_agente_modulo - AND tam.disabled = 0 - WHERE tae.utimestamp = 0 - AND tae.estado IN (".AGENT_MODULE_STATUS_NO_DATA.",".AGENT_MODULE_STATUS_NOT_INIT." ) - AND tam.id_tipo_modulo NOT IN (21,22,23,100) - GROUP BY estado"); - $list[$group['id_grupo']]['_monitors_not_init_'] = isset ($result_not_init['contado']) ? $result_not_init['contado'] : 0; - } - } - return $list; -} - -function groupview_status_modules_agents($id_user = false, $user_strict = false, $access = 'AR', $force_group_and_tag = true, $returnAllGroup = false) { - global $config; - - if ($id_user == false) { - $id_user = $config['id_user']; - } - - //$acltags = tags_get_user_groups_and_tags ($id_user, $access, $user_strict); - $acltags = users_get_groups ($id_user, $access, true, true); - - $result_list = groupview_get_all_data ($id_user, $user_strict, - $acltags, false, array(), array(), $access); - return $result_list; -} - -function groupview_monitor_alerts ($group_array, $strict_user = false, $id_group_strict = false) { - - // If there are not groups to query, we jump to nextone - - if (empty ($group_array)) { - return 0; - - } - else if (!is_array ($group_array)) { - $group_array = array($group_array); - } - - $group_clause = implode (",", $group_array); - $group_clause = "(" . $group_clause . ")"; - - if ($strict_user) { - $group_clause_strict = implode (",", $id_group_strict); - $group_clause_strict = "(" . $group_clause_strict . ")"; - if ($group_clause_strict !== '()') { - $sql = "SELECT COUNT(talert_template_modules.id) - FROM talert_template_modules, tagente_modulo, tagente_estado, tagente - WHERE tagente.id_grupo IN $group_clause_strict AND tagente_modulo.id_agente = tagente.id_agente - AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo - AND talert_template_modules.id_agent_module = tagente_modulo.id_agente_modulo"; - } - $count = db_get_sql ($sql); - return $count; - } else { - //TODO REVIEW ORACLE AND POSTGRES - return db_get_sql ("SELECT COUNT(talert_template_modules.id) - FROM talert_template_modules, tagente_modulo, tagente_estado, tagente - WHERE tagente.id_grupo IN $group_clause AND tagente_modulo.id_agente = tagente.id_agente - AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo - AND talert_template_modules.id_agent_module = tagente_modulo.id_agente_modulo"); - } -} - -function groupview_monitor_fired_alerts ($group_array, $strict_user = false, $id_group_strict = false) { - - // If there are not groups to query, we jump to nextone - if (empty ($group_array)) { - return 0; - } - else if (!is_array ($group_array)) { - $group_array = array($group_array); - } - - $group_clause = implode (",", $group_array); - $group_clause = "(" . $group_clause . ")"; - - return db_get_sql ("SELECT COUNT(talert_template_modules.id) - FROM talert_template_modules, tagente_modulo, tagente_estado, tagente - WHERE tagente.id_grupo IN $group_clause AND tagente_modulo.id_agente = tagente.id_agente - AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo - AND talert_template_modules.id_agent_module = tagente_modulo.id_agente_modulo - AND times_fired > 0"); -} - -function groupview_get_groups_list($id_user = false, $user_strict = false, $access = 'AR', $force_group_and_tag = true, $returnAllGroup = false) { - global $config; - - if ($id_user == false) { - $id_user = $config['id_user']; - } - - $acltags = users_get_groups($id_user, $access, true, true); - $result_list = groupview_get_data ($id_user, $user_strict, $acltags, - $returnAllGroup, array(), array(), $access); - - return $result_list; -} - -function groupview_get_data ($id_user = false, $user_strict = false, $acltags, $returnAllGroup = false, $agent_filter = array(), $module_filter = array(), $access = 'AR') { - global $config; - if ($id_user == false) { - $id_user = $config['id_user']; - } - - $user_groups = array(); - $user_tags = array(); - - foreach ($acltags as $item) { - $user_groups[$item["id_grupo"]] = $item["nombre"]; - - if ($item["tags"] != '') { - $tags_group = explode(',', $item["tags"]); - - foreach ($tags_group as $tag) { - $user_tags[$tag] = tags_get_name($tag); - } - } - } - - $groups_with_privileges = implode(',', array_keys($acltags)); - - if (!$user_strict) - $acltags[0] = 0; - - $user_groups_ids = implode(',', array_keys($acltags)); - - if (!empty($user_groups_ids)) { - if (is_metaconsole()) { - switch ($config["dbtype"]) { - case "mysql": - $list_groups = db_get_all_rows_sql(" - SELECT * - FROM tgrupo - WHERE id_grupo IN (" . $user_groups_ids . ") - AND ( - id_grupo IN (SELECT id_grupo FROM tmetaconsole_agent WHERE disabled = 0) - OR id_grupo IN (SELECT id_group FROM tmetaconsole_agent_secondary_group WHERE id_group IN (" . $user_groups_ids . ")) - ) - ORDER BY nombre COLLATE utf8_general_ci ASC"); - break; - case "postgresql": - $list_groups = db_get_all_rows_sql(" - SELECT * - FROM tgrupo - WHERE id_grupo IN (" . $user_groups_ids . ") - AND id_grupo IN (SELECT id_grupo FROM tmetaconsole_agent WHERE disabled = 0) - ORDER BY nombre ASC"); - break; - case "oracle": - $list_groups = db_get_all_rows_sql(" - SELECT * - FROM tgrupo - WHERE id_grupo IN (" . $user_groups_ids . ") - AND id_grupo IN (SELECT id_grupo FROM tmetaconsole_agent WHERE disabled = 0) - ORDER BY nombre ASC"); - break; - } - } - else { - switch ($config["dbtype"]) { - case "mysql": - $list_groups = db_get_all_rows_sql(" - SELECT * - FROM tgrupo - WHERE id_grupo IN (" . $user_groups_ids . ") - AND ( - id_grupo IN (SELECT id_grupo FROM tagente WHERE disabled = 0) - OR id_grupo IN (SELECT id_group FROM tagent_secondary_group WHERE id_group IN (" . $user_groups_ids . ")) - ) - ORDER BY nombre COLLATE utf8_general_ci ASC"); - break; - case "postgresql": - $list_groups = db_get_all_rows_sql(" - SELECT * - FROM tgrupo - WHERE id_grupo IN (" . $user_groups_ids . ") - AND id_grupo IN (SELECT id_grupo FROM tagente WHERE disabled = 0) - ORDER BY nombre ASC"); - break; - case "oracle": - $list_groups = db_get_all_rows_sql(" - SELECT * - FROM tgrupo - WHERE id_grupo IN (" . $user_groups_ids . ") - AND id_grupo IN (SELECT id_grupo FROM tagente WHERE disabled = 0) - ORDER BY nombre ASC"); - break; - } - } - } - - //Add the group "All" at first - $group_all = array('id_grupo'=>0, 'nombre'=>'All', 'icon'=>'', 'parent'=>'', 'propagate'=>0, 'disabled'=>0, - 'custom_id'=>'', 'id_skin'=>0, 'description'=>'', 'contact'=>'', 'other'=>'', 'password'=>''); - if ($list_groups !== false) { - array_unshift($list_groups, $group_all); - } else { - $list_groups = array($group_all); - } - - if (!$user_strict) { - //Takes the parents even without agents, first ids - $fathers_id = ''; - $list_father_groups = array(); - foreach ($list_groups as $group) { - if ($group['parent'] != '') { - $grup = $group['parent']; - while ($grup != 0) { - $recursive_fathers = db_get_row_sql ("SELECT parent FROM tgrupo - WHERE id_grupo = " . $grup); - $grup = $recursive_fathers['parent']; - if (!strpos($fathers_id, $grup)) { - $fathers_id .= ',' . $grup; - } - } - if (!strpos($fathers_id, $group['parent'])) { - $fathers_id .= ',' . $group['parent']; - } - } - } - //Eliminate the first comma - $fathers_id = substr($fathers_id, 1); - while ($fathers_id{0} == ',') { - $fathers_id = substr($fathers_id, 1); - } - //Takes the parents even without agents, complete groups - if ($fathers_id) { - $list_father_groups = db_get_all_rows_sql(" - SELECT * - FROM tgrupo - WHERE id_grupo IN (" . $fathers_id . ") - AND id_grupo IN (" . $groups_with_privileges . ") - ORDER BY nombre COLLATE utf8_general_ci ASC"); - if (!empty($list_father_groups)) { - //Merges the arrays and eliminates the duplicates groups - $list_groups = array_merge($list_groups, $list_father_groups); - } - } - $list_groups = groupview_array_unique_multidim($list_groups, 'id_grupo'); - //Order groups (Father-children) - $ordered_groups = groupview_order_groups_for_parents($list_groups); - $ordered_ids = array(); - $ordered_ids = groupview_order_group_ids($ordered_groups, $ordered_ids); - $final_list = array(); - array_push($final_list, $group_all); - - foreach ($ordered_ids as $key) { - if ($key == 'All') { - continue; - } - $complete_group = db_get_row_sql(" - SELECT * - FROM tgrupo - WHERE nombre = '" . $key . "'"); - array_push($final_list, $complete_group); - } - - $list_groups = $final_list; - } - - $list = array(); - foreach ($list_groups as $group) { - $list[$group['id_grupo']]['_name_'] = $group['nombre']; - $list[$group['id_grupo']]['_id_'] = $group['id_grupo']; - $list[$group['id_grupo']]['icon'] = $group['icon']; - $list[$group['id_grupo']]['_monitors_critical_'] = 0; - $list[$group['id_grupo']]['_monitors_warning_'] = 0; - $list[$group['id_grupo']]['_monitors_unknown_'] = 0; - $list[$group['id_grupo']]['_monitors_not_init_'] = 0; - $list[$group['id_grupo']]['_monitors_ok_'] = 0; - $list[$group['id_grupo']]['_agents_not_init_'] = 0; - $list[$group['id_grupo']]['_agents_unknown_'] = 0; - $list[$group['id_grupo']]['_agents_critical_'] = 0; - $list[$group['id_grupo']]['_total_agents_'] = 0; - $list[$group['id_grupo']]["_monitor_checks_"] = 0; - $list[$group['id_grupo']]["_monitor_not_normal_"] = 0; - $list[$group['id_grupo']]['_monitors_alerts_fired_'] = 0; - } - - if ($list_groups == false) { - $list_groups = array(); - } - - if (is_metaconsole() || ($config["realtimestats"] == 0)) { // Agent cache - $list = group_view_get_cache_stats ($list, $list_groups, $user_groups_ids); - } else { - foreach ($list_groups as $group) { - // If id group is 0 get all accesses groups - $group_id = $group['id_grupo'] == 0 - ? $user_groups_ids - : $group['id_grupo']; - $agent_not_init = agents_get_agents(array ( - 'disabled' => 0, - 'id_grupo' => $group['id_grupo'], - 'status' => AGENT_STATUS_NOT_INIT), - array ('COUNT(DISTINCT id_agente) as total'), $access, false); - $list[$group['id_grupo']]['_agents_not_init_'] = isset ($agent_not_init[0]['total']) ? $agent_not_init[0]['total'] : 0; - $agent_unknown = agents_get_agents(array ( - 'disabled' => 0, - 'id_grupo' => $group['id_grupo'], - 'status' => AGENT_STATUS_UNKNOWN), - array ('COUNT(DISTINCT id_agente) as total'), $access, false); - $list[$group['id_grupo']]['_agents_unknown_'] = isset ($agent_unknown[0]['total']) ? $agent_unknown[0]['total'] : 0; - $agent_critical = agents_get_agents(array ( - 'disabled' => 0, - 'id_grupo' => $group['id_grupo'], - 'status' => AGENT_STATUS_CRITICAL), - array ('COUNT(DISTINCT id_agente) as total'), $access, false); - $list[$group['id_grupo']]['_agents_critical_'] = isset ($agent_critical[0]['total']) ? $agent_critical[0]['total'] : 0; - $agent_total = agents_get_agents(array ( - 'disabled' => 0, - 'id_grupo' => $group['id_grupo']), - array ('COUNT(DISTINCT id_agente) as total'), $access, false); - $list[$group['id_grupo']]['_total_agents_'] = isset ($agent_total[0]['total']) ? $agent_total[0]['total'] : 0; - $list[$group['id_grupo']]["_monitor_not_normal_"] = $list[$group['id_grupo']]["_monitor_checks_"] - $list[$group['id_grupo']]["_monitors_ok_"]; - $list[$group['id_grupo']]["_monitor_not_normal_"] = $list[$group['id_grupo']]["_monitor_checks_"] - $list[$group['id_grupo']]["_monitors_ok_"]; - $list[$group['id_grupo']]['_monitors_alerts_fired_'] = groupview_monitor_fired_alerts ($group['id_grupo'], $user_strict,$group['id_grupo']); - $result_list = db_get_all_rows_sql("SELECT COUNT(*) as contado, estado - FROM tagente_estado tae INNER JOIN tagente ta - ON tae.id_agente = ta.id_agente - AND ta.disabled = 0 - LEFT JOIN tagent_secondary_group tasg - ON tasg.id_agent = ta.id_agente - INNER JOIN tagente_modulo tam - ON tae.id_agente_modulo = tam.id_agente_modulo - AND tam.disabled = 0 - WHERE tae.utimestamp > 0 - AND ( - ta.id_grupo IN (" . $group_id . ") - OR tasg.id_group IN (" . $group_id . ") - ) - GROUP BY estado"); - if ($result_list) { - foreach ($result_list as $result) { - switch ($result['estado']) { - case AGENT_MODULE_STATUS_CRITICAL_BAD: - $list[$group['id_grupo']]['_monitors_critical_'] = (int)$result['contado']; - break; - case AGENT_MODULE_STATUS_WARNING_ALERT: - break; - case AGENT_MODULE_STATUS_WARNING: - $list[$group['id_grupo']]['_monitors_warning_'] = (int)$result['contado']; - break; - case AGENT_MODULE_STATUS_UNKNOWN: - $list[$group['id_grupo']]['_monitors_unknown_'] = (int)$result['contado']; - break; - } - } - } - - $result_normal = db_get_row_sql("SELECT COUNT(*) as contado - FROM tagente_estado tae INNER JOIN tagente ta - ON tae.id_agente = ta.id_agente - AND ta.disabled = 0 - LEFT JOIN tagent_secondary_group tasg - ON tasg.id_agent = ta.id_agente - INNER JOIN tagente_modulo tam - ON tae.id_agente_modulo = tam.id_agente_modulo - AND tam.disabled = 0 - WHERE tae.estado = 0 - AND (tae.utimestamp > 0 OR tam.id_tipo_modulo IN(21,22,23,100)) - AND ( - ta.id_grupo IN (" . $group_id . ") - OR tasg.id_group IN (" . $group_id . ") - ) - GROUP BY estado"); - $list[$group['id_grupo']]['_monitors_ok_'] = isset ($result_normal['contado']) ? $result_normal['contado'] : 0; - - $result_not_init = db_get_row_sql("SELECT COUNT(*) as contado - FROM tagente_estado tae INNER JOIN tagente ta - ON tae.id_agente = ta.id_agente - AND ta.disabled = 0 - LEFT JOIN tagent_secondary_group tasg - ON tasg.id_agent = ta.id_agente - INNER JOIN tagente_modulo tam - ON tae.id_agente_modulo = tam.id_agente_modulo - AND tam.disabled = 0 - WHERE tae.utimestamp = 0 AND - tae.estado IN (".AGENT_MODULE_STATUS_NO_DATA.",".AGENT_MODULE_STATUS_NOT_INIT." ) - AND tam.id_tipo_modulo NOT IN (21,22,23,100) - AND ( - ta.id_grupo IN (" . $group_id . ") - OR tasg.id_group IN (" . $group_id . ") - ) - GROUP BY estado"); - $list[$group['id_grupo']]['_monitors_not_init_'] = isset ($result_not_init['contado']) ? $result_not_init['contado'] : 0; - } - } - - return $list; -} - -//Order the groups by parents -function groupview_order_groups_for_parents ($view_groups) { - $final_groups = array(); - // Index the groups - $groups = array(); - foreach ($view_groups as $item) { - $groups[$item['id_grupo']] = $item; - } - // Build the group hierarchy - foreach ($groups as $id => $group) { - $groups[$id]['have_parent'] = false; - if (!isset($groups[$id]['parent'])) - continue; - $parent = $groups[$id]['parent']; - // Parent exists - if (isset($groups[$parent])) { - if (!isset($groups[$parent]['children'])) - $groups[$parent]['children'] = array(); - // Store a reference to the group into the parent - $groups[$parent]['children'][] = &$groups[$id]; - - // This group was introduced into a parent - $groups[$id]['have_parent'] = true; - } - } - - // Sort the children groups - for ($i = 0; $i < count($groups); $i++) { - if (isset($groups[$i]['children'])) - usort($groups[$i]['children'], function ($a, $b) { - return strcmp($a["nombre"], $b["nombre"]); - }); - } - // Extract the root groups - foreach ($groups as $group) { - if (!$group['have_parent']) - $final_groups[] = $group; - } - // Sort the root groups - usort($final_groups, function ($a, $b) { - return strcmp($a["name"], $b["name"]); - }); - - return $final_groups; -} - -function groupview_order_group_ids($groups, $ordered_ids){ +function groupview_plain_groups($groups) { + $group_result = array(); foreach ($groups as $group) { + $plain_child = array(); if (!empty($group['children'])) { - $ordered_ids[$group['id_grupo']] = $group['nombre']; - $ordered_ids = groupview_order_group_ids($group['children'], $ordered_ids); - } - else { - $ordered_ids[$group['id_grupo']] = $group['nombre']; + $plain_child = groupview_plain_groups($group['children']); + unset($group['children']); } + $group_result[] = $group; + $group_result = array_merge($group_result, $plain_child); } - return $ordered_ids; + return $group_result; } -//Function to eliminate duplicates groups in multidimensional array -function groupview_array_unique_multidim($groups, $key){ - $temp_group = array(); - $i = 0; - $key_group = array(); - foreach($groups as $group){ - if(!in_array($group[$key],$key_group)){ - $key_group[$i] = $group[$key]; - $temp_group[$i] = $group; - } - $i++; - } - return $temp_group; +function groupview_get_modules_counters($groups_ids = false) { + if(empty($groups_ids)){ + return array(); + } + + $groups_ids = implode(',', $groups_ids); + $table = is_metaconsole() ? 'tmetaconsole_agent' : 'tagente'; + $table_sec = is_metaconsole() + ? 'tmetaconsole_agent_secondary_group' + : 'tagent_secondary_group'; + + $fields = array ( + "g" , + "SUM(module_normal) AS total_module_normal", + "SUM(module_critical) AS total_module_critical", + "SUM(module_warning) AS total_module_warning", + "SUM(module_unknown) AS total_module_unknown", + "SUM(module_not_init) AS total_module_not_init", + "SUM(module_alerts) AS total_module_alerts", + "SUM(module_total) AS total_module" + ); + + $fields_impl = implode(',', $fields); + $sql = "SELECT $fields_impl FROM + ( + SELECT SUM(ta.normal_count) AS module_normal, + SUM(ta.critical_count) AS module_critical, + SUM(ta.warning_count) AS module_warning, + SUM(ta.unknown_count) AS module_unknown, + SUM(ta.notinit_count) AS module_not_init, + SUM(ta.fired_count) AS module_alerts, + SUM(ta.total_count) AS module_total, + ta.id_grupo AS g + FROM $table ta + WHERE ta.id_grupo IN ($groups_ids) + GROUP BY ta.id_grupo + UNION ALL + SELECT SUM(ta.normal_count) AS module_normal, + SUM(ta.critical_count) AS module_critical, + SUM(ta.warning_count) AS module_warning, + SUM(ta.unknown_count) AS module_unknown, + SUM(ta.notinit_count) AS module_not_init, + SUM(ta.fired_count) AS module_alerts, + SUM(ta.total_count) AS module_total, + tasg.id_group AS g + FROM $table ta + INNER JOIN $table_sec tasg + ON ta.id_agente = tasg.id_agent + WHERE tasg.id_group IN ($groups_ids) + GROUP BY tasg.id_group + ) x GROUP BY g"; + return db_get_all_rows_sql($sql); } -/** - * Get the stats to group view using the cache - * - * @param array Skeleton to fill with the group information - * @param array Groups information - * @param string Groups that user has access separated by commas - */ -function group_view_get_cache_stats ($list, $list_groups, $user_groups_ids) { +function groupview_get_all_counters($tree_group) { + $all_name = __("All"); + $group_acl = $tree_group->getGroupAclCondition(); + $table = is_metaconsole() ? 'tmetaconsole_agent' : 'tagente'; + $table_sec = is_metaconsole() + ? 'tmetaconsole_agent_secondary_group' + : 'tagent_secondary_group'; + $sql = + "SELECT SUM(ta.normal_count) AS _monitors_ok_, + SUM(ta.critical_count) AS _monitors_critical_, + SUM(ta.warning_count) AS _monitors_warning_, + SUM(ta.unknown_count) AS _monitors_unknown_, + SUM(ta.notinit_count) AS _monitors_not_init_, + SUM(ta.fired_count) AS _monitors_alerts_fired_, + SUM(ta.total_count) AS _monitor_checks_, + SUM(IF(ta.critical_count > 0, 1, 0)) AS _agents_critical_, + SUM(IF(ta.critical_count = 0 AND ta.warning_count = 0 AND ta.unknown_count > 0, 1, 0)) AS _agents_unknown_, + SUM(IF(ta.total_count = ta.notinit_count, 1, 0)) AS _agents_not_init_, + COUNT(ta.id_agente) AS _total_agents_, + '$all_name' AS _name_, + 0 AS _id_, + '' AS _icon_ + FROM $table ta + WHERE ta.disabled = 0 + AND ta.id_agente IN ( + SELECT ta.id_agente FROM $table ta + LEFT JOIN $table_sec tasg + ON ta.id_agente = tasg.id_agent + WHERE ta.disabled = 0 + $group_acl + GROUP BY ta.id_agente + ) + "; + $data = db_get_row_sql($sql); + $data["_monitor_not_normal_"] = $data["_monitor_checks_"] - $data["_monitors_ok_"]; + return $data; +} - $table_agent = 'tagente'; - $table_secondary = 'tagent_secondary_group'; - // Change the metaconsole tables - if (is_metaconsole()) { - $table_agent = 'tmetaconsole_agent'; - $table_secondary = 'tmetaconsole_agent_secondary_group'; +function groupview_get_groups_list($id_user = false, $access = 'AR', $is_not_paginated = false) { + global $config; + if ($id_user == false) { + $id_user = $config['id_user']; } - // Walk for each group - foreach ($list_groups as $group) { - // If id group is 0 get all accesses groups - $group_id = $group['id_grupo'] == 0 - ? $user_groups_ids - : $group['id_grupo']; - $group_agents = db_get_row_sql("SELECT SUM(warning_count) AS _monitors_warning_, - SUM(critical_count) AS _monitors_critical_, - SUM(normal_count) AS _monitors_ok_, - SUM(unknown_count) AS _monitors_unknown_, - SUM(notinit_count) AS _monitors_not_init_, - SUM(fired_count) AS _monitors_alerts_fired_, - COUNT(*) AS _total_agents_, id_grupo, intervalo, - ultimo_contacto, disabled - FROM $table_agent ta - LEFT JOIN $table_secondary tasg - ON tasg.id_agent = ta.id_agente - WHERE ( - ta.id_grupo IN (" . $group_id . ") - OR tasg.id_group IN (" . $group_id . ") - ) - AND disabled = 0"); + $tree_group = new TreeGroup("group", "group"); + $tree_group->setPropagateCounters(false); + $tree_group->setFilter( array( + 'searchAgent' => '', + 'statusAgent' => AGENT_STATUS_ALL, + 'searchModule' => '', + 'statusModule' => -1, + 'groupID' => 0, + 'tagID' => 0, + 'show_not_init_agents' => 1, + 'show_not_init_modules' => 1 + )); + $info = $tree_group->getArray(); + $info = groupview_plain_groups($info); + $counter = count($info); - $list[$group['id_grupo']]['_monitors_critical_'] = (int)$group_agents['_monitors_critical_']; - $list[$group['id_grupo']]['_monitors_warning_'] = (int)$group_agents['_monitors_warning_']; - $list[$group['id_grupo']]['_monitors_unknown_'] = (int)$group_agents['_monitors_unknown_']; - $list[$group['id_grupo']]['_monitors_not_init_'] = (int)$group_agents['_monitors_not_init_']; - $list[$group['id_grupo']]['_monitors_ok_'] = (int)$group_agents['_monitors_ok_']; - $list[$group['id_grupo']]['_monitors_alerts_fired_'] = (int)$group_agents['_monitors_alerts_fired_']; - $list[$group['id_grupo']]['_total_agents_'] = (int)$group_agents['_total_agents_']; - $list[$group['id_grupo']]["_monitor_checks_"] = $list[$group['id_grupo']]["_monitors_not_init_"] - + $list[$group['id_grupo']]["_monitors_unknown_"] - + $list[$group['id_grupo']]["_monitors_warning_"] - + $list[$group['id_grupo']]["_monitors_critical_"] - + $list[$group['id_grupo']]["_monitors_ok_"]; + $offset = get_parameter('offset', 0); + $groups_view = $is_not_paginated + ? $info + : array_slice($info, $offset, $config['block_size']); + $agents_counters = array_reduce($groups_view, function($carry, $item){ + $carry[$item['id']] = $item; + return $carry; + }, array()); - if ($group['icon']) - $list[$group['id_grupo']]["_iconImg_"] = html_print_image ("images/".$group['icon'].".png", true, array ("style" => 'vertical-align: middle;')); + $modules_counters = groupview_get_modules_counters(array_keys($agents_counters)); + $modules_counters = array_reduce($modules_counters, function($carry, $item){ + $carry[$item['g']] = $item; + return $carry; + }, array()); - // Calculate not_normal monitors - $list[$group['id_grupo']]["_monitor_not_normal_"] = $list["_monitor_checks_"] - $list["_monitors_ok_"]; + $total_counters = array(); - $total_agents = $list[$group['id_grupo']]['_total_agents_']; + foreach ($agents_counters as $id_group => $agent_counter) { + $list[$id_group]['_name_'] = $agent_counter['name']; + $list[$id_group]['_id_'] = $agent_counter['id']; + $list[$id_group]['_iconImg_'] = $agent_counter['icon']; - if ($total_agents > 0) { - $agents = db_get_all_rows_sql(sprintf ("SELECT warning_count, - critical_count, - normal_count, - unknown_count, - notinit_count, - fired_count, - disabled - FROM $table_agent ta - LEFT JOIN $table_secondary tasg - ON ta.id_agente = tasg.id_agent - WHERE ta.id_grupo IN (%s) OR tasg.id_group IN (%s)", - $group_id, $group_id)); - foreach ($agents as $agent) { - if ($agent['critical_count'] > 0) { - $list[$group['id_grupo']]['_agents_critical_'] += 1; - } - else { - if (($agent['critical_count'] == 0) && ($agent['warning_count'] == 0) && ($group_agents['disabled'] == 0) && ($agent['normal_count'] == 0)) { - if ($agent['unknown_count'] > 0) { - $list[$group['id_grupo']]['_agents_unknown_'] += 1; - } - } - if (($agent['critical_count'] == 0) && ($agent['warning_count'] == 0) && ($group_agents['disabled'] == 0) && ($agent['normal_count'] == 0) && ($agent['unknown_count'] == 0)) { - if ($agent['notinit_count'] > 0) { - $list[$group['id_grupo']]['_agents_not_init_'] += 1; - } - } - } - } - } + $list[$id_group]['_agents_not_init_'] = $agent_counter['counters']['not_init']; + $list[$id_group]['_agents_unknown_'] = $agent_counter['counters']['unknown']; + $list[$id_group]['_agents_critical_'] = $agent_counter['counters']['critical']; + $list[$id_group]['_total_agents_'] = $agent_counter['counters']['total']; + + $list[$id_group]['_monitors_critical_'] = (int)$modules_counters[$id_group]['total_module_critical']; + $list[$id_group]['_monitors_warning_'] = (int)$modules_counters[$id_group]['total_module_warning']; + $list[$id_group]['_monitors_unknown_'] = (int)$modules_counters[$id_group]['total_module_unknown']; + $list[$id_group]['_monitors_not_init_'] = (int)$modules_counters[$id_group]['total_module_not_init']; + $list[$id_group]['_monitors_ok_'] = (int)$modules_counters[$id_group]['total_module_normal']; + $list[$id_group]["_monitor_checks_"] = (int)$modules_counters[$id_group]['total_module']; + $list[$id_group]["_monitor_not_normal_"] = $list[$group['id_grupo']]["_monitor_checks_"] - $list[$group['id_grupo']]['_monitors_ok_']; + $list[$id_group]['_monitors_alerts_fired_'] = (int)$modules_counters[$id_group]['total_module_alerts']; } - return $list; + + array_unshift($list, groupview_get_all_counters($tree_group)); + return array( + 'groups' => $list, + 'counter' => $counter + ); } ?> diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index 83e49c5b43..783f1a9cab 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -2504,4 +2504,24 @@ function html_print_sort_arrows ($params, $order_tag, $up = 'up', $down = 'down' '' ; } + +/** + * Print an input hidden with a new csrf token generated + */ +function html_print_csrf_hidden () { + html_print_input_hidden('csrf_code', generate_csrf_code()); +} + +/** + * Print an error if csrf is incorrect + */ +function html_print_csrf_error () { + if (validate_csrf_code()) return false; + + ui_print_error_message ( + __('%s cannot verify the origin of the request. Try again, please.', + get_product_name()) + ); + return true; +} ?> diff --git a/pandora_console/include/functions_modules.php b/pandora_console/include/functions_modules.php index e78d4f15ca..f8e632dad4 100755 --- a/pandora_console/include/functions_modules.php +++ b/pandora_console/include/functions_modules.php @@ -2750,5 +2750,62 @@ function modules_get_modules_status ($mod_status_id) { } return $mod_status_desc; -} -?> +} + +function modules_get_counter_by_states($state) { + switch ($state) { + case AGENT_MODULE_STATUS_CRITICAL_ALERT: + case AGENT_MODULE_STATUS_CRITICAL_BAD: + return "critical_count"; + case AGENT_MODULE_STATUS_WARNING_ALERT: + case AGENT_MODULE_STATUS_WARNING: + return "warning_count"; + break; + case AGENT_MODULE_STATUS_UNKNOWN: + return "unknown_count"; + case AGENT_MODULE_STATUS_NO_DATA: + case AGENT_MODULE_STATUS_NOT_INIT: + return "notinit_count"; + case AGENT_MODULE_STATUS_NORMAL_ALERT: + case AGENT_MODULE_STATUS_NORMAL: + return "normal_count"; + } + + // If the state is not an expected state, return condition + // to not show any data + return false; +} + +function modules_get_state_condition($state) { + switch ($state) { + case AGENT_MODULE_STATUS_CRITICAL_ALERT: + case AGENT_MODULE_STATUS_CRITICAL_BAD: + return "( + tae.estado = ".AGENT_MODULE_STATUS_CRITICAL_ALERT." + OR tae.estado = ".AGENT_MODULE_STATUS_CRITICAL_BAD." + )"; + case AGENT_MODULE_STATUS_WARNING_ALERT: + case AGENT_MODULE_STATUS_WARNING: + return "( + tae.estado = ".AGENT_MODULE_STATUS_WARNING_ALERT." + OR tae.estado = ".AGENT_MODULE_STATUS_WARNING." + )"; + case AGENT_MODULE_STATUS_UNKNOWN: + return "tae.estado = ".AGENT_MODULE_STATUS_UNKNOWN." "; + case AGENT_MODULE_STATUS_NO_DATA: + case AGENT_MODULE_STATUS_NOT_INIT: + return "( + tae.estado = ".AGENT_MODULE_STATUS_NO_DATA." + OR tae.estado = ".AGENT_MODULE_STATUS_NOT_INIT." + )"; + case AGENT_MODULE_STATUS_NORMAL_ALERT: + case AGENT_MODULE_STATUS_NORMAL: + return "( + tae.estado = ".AGENT_MODULE_STATUS_NORMAL_ALERT." + OR tae.estado = ".AGENT_MODULE_STATUS_NORMAL." + )"; + } + // If the state is not an expected state, return no condition + return "1=1"; +} +?> \ No newline at end of file diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index c5e8e53725..d385b424be 100755 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -395,7 +395,8 @@ function reporting_make_reporting_data($report = null, $id_report, $content, $type, $force_width_chart, - $force_height_chart); + $force_height_chart + ); break; case 'netflow_area': $report['contents'][] = reporting_netflow( @@ -628,7 +629,6 @@ function reporting_make_reporting_data($report = null, $id_report, } $index_content++; } - return reporting_check_structure_report($report); } @@ -1552,7 +1552,7 @@ function reporting_event_report_group($report, $content, function reporting_event_report_module($report, $content, $type = 'dinamic', $force_width_chart = null, $force_height_chart = null, $pdf=0) { - + global $config; if($pdf){ @@ -1563,20 +1563,29 @@ function reporting_event_report_module($report, $content, } $return['type'] = 'event_report_module'; - + if (empty($content['name'])) { $content['name'] = __('Event Report Module'); } - + + $id_server = false; + if(is_metaconsole()){ + $id_server = metaconsole_get_id_server($content["server_name"]); + metaconsole_connect(null, $id_server); + } + $return['title'] = $content['name']; - $return['subtitle'] = agents_get_alias($content['id_agent']) . - " - " . - io_safe_output( - modules_get_agentmodule_name($content['id_agent_module'])); + $return['subtitle'] = agents_get_alias($content['id_agent']) . " - " . + io_safe_output(modules_get_agentmodule_name($content['id_agent_module'])); + + if(is_metaconsole()){ + metaconsole_restore_db(); + } + $return["description"] = $content["description"]; $return["date"] = reporting_get_date_text($report, $content); $return['label'] = (isset($content['style']['label'])) ? $content['style']['label'] : ''; - + $event_filter = $content['style']; $return['show_summary_group'] = $event_filter['show_summary_group']; //filter @@ -1585,22 +1594,18 @@ function reporting_event_report_module($report, $content, $filter_event_type = json_decode($event_filter['filter_event_type'],true); $filter_event_status = json_decode($event_filter['filter_event_status'],true); $filter_event_filter_search = $event_filter['event_filter_search']; - + //graphs $event_graph_by_user_validator = $event_filter['event_graph_by_user_validator']; $event_graph_by_criticity = $event_filter['event_graph_by_criticity']; $event_graph_validated_vs_unvalidated = $event_filter['event_graph_validated_vs_unvalidated']; - - $id_server = false; - if(is_metaconsole()){ - $id_server = metaconsole_get_id_server($content["server_name"]); - } + //data events $data = reporting_get_module_detailed_event ( - $content['id_agent_module'], $content['period'], $report["datetime"], - $show_summary_group, $filter_event_severity, $filter_event_type, + $content['id_agent_module'], $content['period'], $report["datetime"], + $show_summary_group, $filter_event_severity, $filter_event_type, $filter_event_status, $filter_event_filter_search, $force_width_chart, - $event_graph_by_user_validator, $event_graph_by_criticity, + $event_graph_by_user_validator, $event_graph_by_criticity, $event_graph_validated_vs_unvalidated, $ttl, $id_server); if (empty($data)) { @@ -1608,7 +1613,7 @@ function reporting_event_report_module($report, $content, } else { $return['data'] = array_reverse($data); - } + } if ($config['metaconsole']) { metaconsole_restore_db(); @@ -1621,7 +1626,7 @@ function reporting_event_report_module($report, $content, else{ $return['total_events'] = 0; } - + return reporting_check_structure_content($return); } @@ -2807,18 +2812,17 @@ function agents_get_network_interfaces_array( $row_interface['chart'] = null; $width = null; - $height = null; $params =array( 'period' => $content['period'], 'width' => $width, - 'height' => $height, 'unit_name' => array_fill(0, count($interface['traffic']), __("bytes/s")), 'date' => $report["datetime"], 'only_image'=> $pdf, 'homeurl' => $config['homeurl'], 'fullscale' => $fullscale, - 'server_id' => $id_meta + 'server_id' => $id_meta, + 'height' => $config['graph_image_height'] ); $params_combined = array( @@ -2866,14 +2870,27 @@ function reporting_alert_get_fired($id_agent_module, $id_alert_template_module, $id_alert_template_module, $period, $datetime); + + if (!is_numeric ($datetime)) { + $datetime = time_w_fixed_tz($datetime); + } + if (empty ($datetime)) { + $datetime = get_system_time(); + } + + $datelimit = $datetime - $period; + $empty = '----------------------------'; if (empty($firedTimes)) { $firedTimes = array(); - $firedTimes[0]['timestamp'] = null; + $firedTimes[0]['timestamp'] = $empty; } foreach ($firedTimes as $fireTime) { + if($fireTime['utimestamp'] > $datelimit && $fireTime['utimestamp'] <= $datetime) $fired[] = $fireTime['timestamp']; + else + $fired[] = $empty; } return $fired; @@ -2956,6 +2973,16 @@ function reporting_alert_report_group($report, $content) { foreach ($alerts as $template => $actions) { + $datetime = (int) $report["datetime"]; + if (!is_numeric ($datetime)) { + $datetime = time_w_fixed_tz($datetime); + } + if (empty ($datetime)) { + $datetime = get_system_time(); + } + $period = (int) $content["period"]; + $datelimit = $datetime - $period; + $data_action = array(); $data_action['actions'] = array(); @@ -2964,7 +2991,7 @@ function reporting_alert_report_group($report, $content) { foreach ($actions["custom"] as $action) { $data_action[$naction]["name"] = $action["name"]; $fired = $action["fired"]; - if ($fired == 0){ + if ($fired == 0 || ($fired <= $datelimit || $fired > $datetime)){ $data_action[$naction]['fired'] = '----------------------------'; } else { @@ -2977,7 +3004,7 @@ function reporting_alert_report_group($report, $content) { foreach ($actions["default"] as $action) { $data_action[$naction]["name"] = $action["name"]; $fired = $action["fired"]; - if ($fired == 0){ + if ($fired == 0 || ($fired <= $datelimit || $fired > $datetime)){ $data_action[$naction]['fired'] = '----------------------------'; } else { @@ -2990,7 +3017,7 @@ function reporting_alert_report_group($report, $content) { foreach ($actions["unavailable"] as $action) { $data_action[$naction]["name"] = $action["name"]; $fired = $action["fired"]; - if ($fired == 0){ + if ($fired == 0 || ($fired <= $datelimit || $fired > $datetime)){ $data_action[$naction]['fired'] = '----------------------------'; } else { @@ -3010,10 +3037,7 @@ function reporting_alert_report_group($report, $content) { (int) $report["datetime"]); $module_actions["actions"] = $data_action; - if ($module_actions["template_fired"][0] !== null) $data_row['alerts'][$ntemplates] = $module_actions; - else - $data_row = null; $ntemplates++; } @@ -3076,6 +3100,16 @@ function reporting_alert_report_agent($report, $content) { foreach ($alerts as $template => $actions) { + $datetime = (int) $report["datetime"]; + if (!is_numeric ($datetime)) { + $datetime = time_w_fixed_tz($datetime); + } + if (empty ($datetime)) { + $datetime = get_system_time(); + } + $period = (int) $content["period"]; + $datelimit = $datetime - $period; + $data_action = array(); $data_action['actions'] = array(); @@ -3084,7 +3118,7 @@ function reporting_alert_report_agent($report, $content) { foreach ($actions["custom"] as $action) { $data_action[$naction]["name"] = $action["name"]; $fired = $action["fired"]; - if ($fired == 0){ + if ($fired == 0 || ($fired <= $datelimit || $fired > $datetime)){ $data_action[$naction]['fired'] = '----------------------------'; } else { @@ -3097,7 +3131,7 @@ function reporting_alert_report_agent($report, $content) { foreach ($actions["default"] as $action) { $data_action[$naction]["name"] = $action["name"]; $fired = $action["fired"]; - if ($fired == 0){ + if ($fired == 0 || ($fired <= $datelimit || $fired > $datetime)){ $data_action[$naction]['fired'] = '----------------------------'; } else { @@ -3110,7 +3144,7 @@ function reporting_alert_report_agent($report, $content) { foreach ($actions["unavailable"] as $action) { $data_action[$naction]["name"] = $action["name"]; $fired = $action["fired"]; - if ($fired == 0){ + if ($fired == 0 || ($fired <= $datelimit || $fired > $datetime)){ $data_action[$naction]['fired'] = '----------------------------'; } else { @@ -3130,10 +3164,7 @@ function reporting_alert_report_agent($report, $content) { (int) $report["datetime"]); $module_actions["actions"] = $data_action; - if ($module_actions["template_fired"][0] !== null) $data_row['alerts'][$ntemplates] = $module_actions; - else - $data_row = null; $ntemplates++; } @@ -3199,6 +3230,15 @@ function reporting_alert_report_module($report, $content) { $ntemplates = 0; foreach ($alerts as $template => $actions) { + $datetime = (int) $report["datetime"]; + if (!is_numeric ($datetime)) { + $datetime = time_w_fixed_tz($datetime); + } + if (empty ($datetime)) { + $datetime = get_system_time(); + } + $period = (int) $content["period"]; + $datelimit = $datetime - $period; $data_action = array(); $data_action['actions'] = array(); @@ -3208,7 +3248,7 @@ function reporting_alert_report_module($report, $content) { foreach ($actions["custom"] as $action) { $data_action[$naction]["name"] = $action["name"]; $fired = $action["fired"]; - if ($fired == 0){ + if ($fired == 0 || ($fired <= $datelimit || $fired > $datetime)){ $data_action[$naction]['fired'] = '----------------------------'; } else { @@ -3221,7 +3261,7 @@ function reporting_alert_report_module($report, $content) { foreach ($actions["default"] as $action) { $data_action[$naction]["name"] = $action["name"]; $fired = $action["fired"]; - if ($fired == 0){ + if ($fired == 0 || ($fired <= $datelimit || $fired > $datetime)){ $data_action[$naction]['fired'] = '----------------------------'; } else { @@ -3234,7 +3274,7 @@ function reporting_alert_report_module($report, $content) { foreach ($actions["unavailable"] as $action) { $data_action[$naction]["name"] = $action["name"]; $fired = $action["fired"]; - if ($fired == 0){ + if ($fired == 0 || ($fired <= $datelimit || $fired > $datetime)){ $data_action[$naction]['fired'] = '----------------------------'; } else { @@ -3254,10 +3294,7 @@ function reporting_alert_report_module($report, $content) { (int) $report["datetime"]); $module_actions["actions"] = $data_action; - if ($module_actions["template_fired"][0] !== null) $data_row['alerts'][$ntemplates] = $module_actions; - else - $data_row = null; $ntemplates++; } @@ -3483,79 +3520,6 @@ function reporting_netflow($report, $content, $type, return reporting_check_structure_content($return); } -function reporting_simple_baseline_graph($report, $content, - $type = 'dinamic', $force_width_chart = null, - $force_height_chart = null) { - - global $config; - - if ($config['metaconsole']) { - $id_meta = metaconsole_get_id_server($content["server_name"]); - $server = metaconsole_get_connection_by_id ($id_meta); - metaconsole_connect($server); - } - - $return['type'] = 'simple_baseline_graph'; - - if (empty($content['name'])) { - $content['name'] = __('Simple baseline graph'); - } - - $module_name = io_safe_output( - modules_get_agentmodule_name($content['id_agent_module'])); - $agent_name = io_safe_output( - modules_get_agentmodule_agent_alias ($content['id_agent_module'])); - - $return['title'] = $content['name']; - $return['subtitle'] = $agent_name . " - " . $module_name; - $return["description"] = $content["description"]; - $return["date"] = reporting_get_date_text($report, $content); - $return['label'] = (isset($content['style']['label'])) ? $content['style']['label'] : ''; - - // Get chart - reporting_set_conf_charts($width, $height, $only_image, $type, - $content, $ttl); - - $baseline_data = enterprise_hook( - 'reporting_enterprise_get_baseline', - array ( - $content['id_agent_module'], - $content['period'], - $report["datetime"] - ) - ); - - if ($baseline_data === ENTERPRISE_NOT_HOOK) { - $baseline_data = array (); - } - - switch ($type) { - case 'dinamic': - case 'static': - $params =array( - 'agent_module_id' => $content['id_agent_module'], - 'period' => $content['period'], - 'date' => $report["datetime"], - 'only_image' => $only_image, - 'homeurl' => ui_get_full_url(false, false, false, false), - 'ttl' => $ttl, - 'array_data_create' => $baseline_data, - 'server_id' => $id_meta - ); - - $return['chart'] = grafico_modulo_sparse ($params); - break; - case 'data': - break; - } - - if ($config['metaconsole']) { - metaconsole_restore_db(); - } - - return reporting_check_structure_content($return); -} - function reporting_prediction_date($report, $content) { global $config; @@ -3631,31 +3595,20 @@ function reporting_projection_graph($report, $content, switch ($type) { case 'dinamic': case 'static': - $output_projection = forecast_projection_graph( - $content['id_agent_module'], - $content['period'], - $content['top_n_value'] - ); - - // If projection doesn't have data then don't draw graph - if ($output_projection == NULL) { - $output_projection = false; - } - $params =array( 'period' => $content['period'], 'width' => $width, - 'height' => $height, 'date' => $report["datetime"], 'unit' => '', 'only_image' => $pdf, 'homeurl' => ui_get_full_url(false, false, false, false) . '/', 'ttl' => $ttl, - 'server_id' => $id_meta + 'server_id' => $id_meta, + 'height' => $config['graph_image_height'] ); $params_combined = array( - 'projection' => $output_projection + 'projection' => $content['top_n_value'], ); $return['chart'] = graphic_combined_module( @@ -3884,131 +3837,131 @@ function reporting_value($report, $content, $type,$pdf) { $return['agent_name'] = $agent_name; $return['module_name'] = $module_name; - + if($pdf){ $only_image = 1; } $params =array( - 'agent_module_id' => $content['id_agent_module'], - 'period' => $content['period'], - 'width' => '600px', - 'pure' => false,///true - 'date' => $report["datetime"], - 'only_image' => $only_image, - 'homeurl' => ui_get_full_url(false, false, false, false), - 'ttl' => 1,///2 - 'type_graph' => $config['type_module_charts'], - 'time_interval' => $content['lapse'], - 'server_id' => $id_meta + 'agent_module_id' => $content['id_agent_module'], + 'period' => $content['period'], + 'width' => '600px', + 'pure' => false,///true + 'date' => $report["datetime"], + 'only_image' => $only_image, + 'homeurl' => ui_get_full_url(false, false, false, false), + 'ttl' => 1,///2 + 'type_graph' => $config['type_module_charts'], + 'time_interval' => $content['lapse'], + 'server_id' => $id_meta, + 'height' => $config['graph_image_height'], + 'fullscale' => true ); - - switch ($type) { + switch ($type) { case 'max': - if($content['lapse_calc'] == 0){ - $value = reporting_get_agentmodule_data_max( - $content['id_agent_module'], $content['period'], $report["datetime"]); - if (!$config['simple_module_value']) { - $formated_value = $value; + if($content['lapse_calc'] == 0){ + $value = reporting_get_agentmodule_data_max( + $content['id_agent_module'], $content['period'], $report["datetime"]); + if (!$config['simple_module_value']) { + $formated_value = $value; + } + else { + $formated_value = format_for_graph($value, $config['graph_precision']) . " " . $unit; + } } - else { - $formated_value = format_for_graph($value, $config['graph_precision']) . " " . $unit; - } - } - else{ - $value = ' - - - - - - - - - -
'; - if($content['visual_format'] == 1 || $content['visual_format'] == 2 || $content['visual_format'] == 3){ + else{ + $value = ' + + + + + + +
'; + if($content['visual_format'] == 1 || $content['visual_format'] == 2 || $content['visual_format'] == 3){ + + $value .= ' + + + + + + + + + + +
+ '.__("Agent").' + + '.__("Module").' + + '.__("Maximum").' +
+ '.$agent_name.' + + '.$module_name.' + + '.format_for_graph(reporting_get_agentmodule_data_max( + $content['id_agent_module'], $content['period'], $report["datetime"]), $config['graph_precision']) . ' ' . $unit.' +
'; + } + + $value .= ' +
+ '; + + if($content['visual_format'] == 2 || $content['visual_format'] == 3){ + $params['force_interval'] = 'max_only'; + $value .= grafico_modulo_sparse($params); + } $value .= ' - + + + + + '; + $time_begin = db_get_row_sql('select utimestamp from tagente_datos where id_agente_modulo ='.$content['id_agent_module'], true); + $date_reference = getdate(); + + for ($i=$date_reference[0]; $i > ($date_reference[0]-$content["period"]); $i -= $content["lapse"]) { + + $value .= ''; + } else { + $value .= 'N/A'; + } + + } + + $value .='
'; + + if($content['visual_format'] == 1 || $content['visual_format'] == 3){ + + $value .= ' + - - - - - -
- '.__("Agent").' - - '.__("Module").' + '.__("Lapse").' '.__("Maximum").'
- '.$agent_name.' - - '.$module_name.' - - '.format_for_graph(reporting_get_agentmodule_data_max( - $content['id_agent_module'], $content['period'], $report["datetime"]), $config['graph_precision']) . ' ' . $unit.' -
'; +
'. date("Y-m-d H:i:s", ($i-$content["lapse"]+1)).' to '.date("Y-m-d H:i:s",$i).''; + + if ($i>$time_begin['utimestamp']) { + $value .= format_for_graph(reporting_get_agentmodule_data_max( + $content['id_agent_module'], $content["lapse"], $i), $config['graph_precision']) . ' ' . $unit.'
'; } + $value .= ' +
'; - $value .= ' -
- '; + $formated_value = $value; + } - if($content['visual_format'] == 2 || $content['visual_format'] == 3){ - $params['force_interval'] = 'max_only'; - $value .= grafico_modulo_sparse($params); - } - - $value .= ' - -
'; - - if($content['visual_format'] == 1 || $content['visual_format'] == 3){ - - $value .= ' - - - - - - '; - $time_begin = db_get_row_sql('select utimestamp from tagente_datos where id_agente_modulo ='.$content['id_agent_module']); - $date_reference = getdate(); - - for ($i=$date_reference[0]; $i > ($date_reference[0]-$content["period"]); $i -= $content["lapse"]) { - - $value .= ''; - } - else{ - $value .= 'N/A'; - } - - } - - $value .='
- '.__("Lapse").' - - '.__("Maximum").' -
'. date("Y-m-d H:i:s", ($i-$content["lapse"]+1)).' to '.date("Y-m-d H:i:s",$i).''; - - if($i>$time_begin['utimestamp']){ - $value .= format_for_graph(reporting_get_agentmodule_data_max( - $content['id_agent_module'], $content["lapse"], $i), $config['graph_precision']) . ' ' . $unit.'
'; - } - $value .= ' -
'; - - $formated_value = $value; - } - - break; + break; case 'min': if($content['lapse_calc'] == 0){ $value = reporting_get_agentmodule_data_min( @@ -4119,111 +4072,111 @@ function reporting_value($report, $content, $type,$pdf) { break; case 'avg': - if($content['lapse_calc'] == 0){ - $value = reporting_get_agentmodule_data_average( - $content['id_agent_module'], $content['period'], $report["datetime"]); - if (!$config['simple_module_value']) { - $formated_value = $value; + if($content['lapse_calc'] == 0){ + $value = reporting_get_agentmodule_data_average( + $content['id_agent_module'], $content['period'], $report["datetime"]); + if (!$config['simple_module_value']) { + $formated_value = $value; + } + else { + $formated_value = format_for_graph($value, $config['graph_precision']) . " " . $unit; + } } - else { - $formated_value = format_for_graph($value, $config['graph_precision']) . " " . $unit; - } - } - else{ - $value = ' - - - - - - - -
'; + else{ + $value = ' + + + + + - - + +
'; + + if($content['visual_format'] == 1 || $content['visual_format'] == 2 || $content['visual_format'] == 3){ + $value .= ' + + + + + + + + + + +
+ '.__("Agent").' + + '.__("Module").' + + '.__("Average").' +
+ '.$agent_name.' + + '.$module_name.' + + '.format_for_graph(reporting_get_agentmodule_data_average( + $content['id_agent_module'], $content['period'], $report["datetime"]), $config['graph_precision']) . ' ' . $unit.' +
'; + + } + + $value .= ' +
+ '; + if($content['visual_format'] == 2 || $content['visual_format'] == 3){ + $params['force_interval'] = 'avg_only'; + $value .= grafico_modulo_sparse($params); + } - if($content['visual_format'] == 1 || $content['visual_format'] == 2 || $content['visual_format'] == 3){ $value .= ' - + + + + + '; + $time_begin = db_get_row_sql('select utimestamp from tagente_datos where id_agente_modulo ='.$content['id_agent_module']); + $date_reference = getdate(); + + for ($i=$date_reference[0]; $i > ($date_reference[0]-$content["period"]); $i -= $content["lapse"]) { + + $value .= ''; + } + else{ + $value .= 'N/A'; + } + + } + + $value .='
'; + + if($content['visual_format'] == 1 || $content['visual_format'] == 3){ + + $value .= ' + - - - - - -
- '.__("Agent").' - - '.__("Module").' + '.__("Lapse").' '.__("Average").'
- '.$agent_name.' - - '.$module_name.' - - '.format_for_graph(reporting_get_agentmodule_data_average( - $content['id_agent_module'], $content['period'], $report["datetime"]), $config['graph_precision']) . ' ' . $unit.' -
'; - +
'. date("Y-m-d H:i:s", ($i-$content["lapse"]+1)).' to '.date("Y-m-d H:i:s",$i).''; + + if($i>$time_begin['utimestamp']){ + $value .= format_for_graph(reporting_get_agentmodule_data_average( + $content['id_agent_module'], $content["lapse"], $i), $config['graph_precision']) . ' ' . $unit.'
'; } - $value .= ' -
- '; - if($content['visual_format'] == 2 || $content['visual_format'] == 3){ - $params['force_interval'] = 'avg_only'; - $value .= grafico_modulo_sparse($params); - } + $value .= ' + +
'; - $value .= ' - -
'; - - if($content['visual_format'] == 1 || $content['visual_format'] == 3){ - - $value .= ' - - - - - - '; - $time_begin = db_get_row_sql('select utimestamp from tagente_datos where id_agente_modulo ='.$content['id_agent_module']); - $date_reference = getdate(); - - for ($i=$date_reference[0]; $i > ($date_reference[0]-$content["period"]); $i -= $content["lapse"]) { - - $value .= ''; - } - else{ - $value .= 'N/A'; - } - - } - - $value .='
- '.__("Lapse").' - - '.__("Average").' -
'. date("Y-m-d H:i:s", ($i-$content["lapse"]+1)).' to '.date("Y-m-d H:i:s",$i).''; - - if($i>$time_begin['utimestamp']){ - $value .= format_for_graph(reporting_get_agentmodule_data_average( - $content['id_agent_module'], $content["lapse"], $i), $config['graph_precision']) . ' ' . $unit.'
'; - } - - $value .= ' - -
'; + $formated_value = $value; - $formated_value = $value; - - } - break; + } + break; case 'sum': $value = reporting_get_agentmodule_data_sum( @@ -6344,24 +6297,23 @@ function reporting_custom_graph($report, $content, $type = 'dinamic', $return['chart'] = ''; $width =null; - $height =null; switch ($type) { case 'dinamic': case 'static': - $params =array( 'period' => $content['period'], 'width' => $width, - 'height' => $height, 'date' => $report["datetime"], 'only_image' => $pdf, 'homeurl' => ui_get_full_url(false, false, false, false), 'ttl' => $ttl, 'percentil' => $graphs[0]["percentil"], 'fullscale' => $graphs[0]["fullscale"], - 'server_id' => $id_meta + 'server_id' => $id_meta, + 'height' => $config['graph_image_height'] ); + $params_combined = array( 'stacked' => $graphs[0]["stacked"], 'summatory' => $graphs[0]["summatory_series"], @@ -6464,7 +6416,8 @@ function reporting_simple_graph($report, $content, $type = 'dinamic', 'show_unknown' => true, 'percentil' => ($content['style']['percentil'] == 1) ? $config['percentil'] : null, 'fullscale' => $fullscale, - 'server_id' => $id_meta + 'server_id' => $id_meta, + 'height' => $config['graph_image_height'] ); $return['chart'] = grafico_modulo_sparse($params); @@ -6491,15 +6444,14 @@ function reporting_simple_graph($report, $content, $type = 'dinamic', function reporting_get_date_text($report = null, $content = null) { global $config; - + $return = array(); $return['date'] = null; $return['period'] = null; $return['from'] = null; $return['to'] = null; - + if (!empty($report) && !empty($content)) { - if ($content['period'] == 0) { $es = json_decode($content['external_source'], true); if ($es['date'] == 0) { @@ -6515,7 +6467,7 @@ function reporting_get_date_text($report = null, $content = null) { $return['to'] = $report["datetime"]; } } - + return $return; } @@ -6531,7 +6483,7 @@ function reporting_check_structure_report($return) { $return['datetime'] = ""; if (!isset($return['period'])) $return['period'] = ""; - + return $return; } @@ -6551,7 +6503,7 @@ function reporting_check_structure_content($report) { $report["date"]['from'] = ""; $report["date"]['to'] = ""; } - + return $report; } @@ -7000,54 +6952,41 @@ function reporting_get_group_stats ($id_group = 0, $access = 'AR') { continue; } } - + if (!empty($group_array)) { + $monitors_info = groups_monitor_total_counters($group_array, true); // Get monitor NOT INIT, except disabled AND async modules - $data["monitor_not_init"] += (int) groups_get_not_init_monitors ($group_array, array(), array(), false, false, true); - - // Get monitor OK, except disabled and non-init - $data["monitor_ok"] += (int) groups_get_normal_monitors ($group_array, array(), array(), false, false, true); - - // Get monitor CRITICAL, except disabled and non-init - $data["monitor_critical"] += (int) groups_get_critical_monitors ($group_array, array(), array(), false, false, true); - - // Get monitor WARNING, except disabled and non-init - $data["monitor_warning"] += (int) groups_get_warning_monitors ($group_array, array(), array(), false, false, true); - - // Get monitor UNKNOWN, except disabled and non-init - $data["monitor_unknown"] += (int) groups_get_unknown_monitors ($group_array, array(), array(), false, false, true); - - // Get alerts configured, except disabled - $data["monitor_alerts"] += groups_monitor_alerts ($group_array) ; - - // Get alert configured currently FIRED, except disabled - $data["monitor_alerts_fired"] += groups_monitor_fired_alerts ($group_array); - - // Calculate totals using partial counts from above - - // Get TOTAL non-init modules, except disabled ones and async modules + $data["monitor_not_init"] += $monitors_info['not_init']; $data["total_not_init"] += $data["monitor_not_init"]; - + // Get monitor OK, except disabled and non-init + $data["monitor_ok"] += $monitors_info['ok']; + // Get monitor CRITICAL, except disabled and non-init + $data["monitor_critical"] += $monitors_info['critical']; + // Get monitor WARNING, except disabled and non-init + $data["monitor_warning"] += $monitors_info['warning']; + // Get monitor UNKNOWN, except disabled and non-init + $data["monitor_unknown"] += $monitors_info['unknown']; + $data["monitor_checks"] += $monitors_info['total']; + + // Get alerts configured, except disabled + $alerts_info = groups_monitor_alerts_total_counters ($group_array); + $data["monitor_alerts"] += $alerts_info['total']; + // Get alert configured currently FIRED, except disabled + $data["monitor_alerts_fired"] += $alerts_info['fired']; + + $agents_info = groups_agents_total_counters($group_array); // Get TOTAL agents in a group - $data["total_agents"] += (int) groups_get_total_agents ($group_array, array(), array(), false, false, true); - + $data["total_agents"] += $agents_info['total']; // Get Agents OK - $data["agent_ok"] += (int) groups_get_normal_agents ($group_array, array(), array(), false, false, true); - - // Get Agents Warning - $data["agent_warning"] += (int) groups_get_warning_agents ($group_array, array(), array(), false, false, true); - + $data["agent_ok"] += $agents_info['ok']; + // Get Agents Warning + $data["agent_warning"] += $agents_info['warning']; // Get Agents Critical - $data["agent_critical"] += (int) groups_get_critical_agents ($group_array, array(), array(), false, false, true); - + $data["agent_critical"] += $agents_info['critical']; // Get Agents Unknown - $data["agent_unknown"] += (int) groups_get_unknown_agents ($group_array, array(), array(), false, false, true); - + $data["agent_unknown"] += $agents_info['unknown']; // Get Agents Not init - $data["agent_not_init"] += (int) groups_get_not_init_agents ($group_array, array(), array(), false, false, true); - - // Get total count of monitors for this group, except disabled. - $data["monitor_checks"] += $data["monitor_not_init"] + $data["monitor_unknown"] + $data["monitor_warning"] + $data["monitor_critical"] + $data["monitor_ok"]; + $data["agent_not_init"] += $agents_info['not_init']; } } // Calculate not_normal monitors diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index 9ed6ab16e1..fd4d0a2c76 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -1960,6 +1960,12 @@ function reporting_html_alert_report($table, $item, $pdf = 0) { $table1->data = array (); $table1->rowspan = array(); $table1->valign = array(); + + if ($item['data'] == null) { + $table->data['alerts']['cell'] = ui_print_empty_data ( __('No alerts defined') , '', true) ; + return true; + } + $table1->head['agent'] = __('Agent'); $table1->head['module'] = __('Module'); $table1->head['template'] = __('Template'); diff --git a/pandora_console/include/functions_reports.php b/pandora_console/include/functions_reports.php index dfa3d3d490..b836f534a2 100755 --- a/pandora_console/include/functions_reports.php +++ b/pandora_console/include/functions_reports.php @@ -95,10 +95,12 @@ function reports_get_reports ($filter = false, $fields = false, $filter[] = sprintf ('private = 0 OR (private = 1 AND id_user = "%s")', $config['id_user']); */ + $filter['hidden'] = 0; if (is_array ($fields)) { $fields[] = 'id_group'; $fields[] = 'id_user'; $fields[] = 'id_group_edit'; + $fields[] = 'hidden'; } $reports = array (); diff --git a/pandora_console/include/graphs/flot/pandora.flot.js b/pandora_console/include/graphs/flot/pandora.flot.js index 7af352cd69..a71cb5eb19 100644 --- a/pandora_console/include/graphs/flot/pandora.flot.js +++ b/pandora_console/include/graphs/flot/pandora.flot.js @@ -284,7 +284,7 @@ function pandoraFlotPieCustom(graph_id, values, labels, width, set_watermark(graph_id, plot, $('#watermark_image_' + graph_id).attr('src')); } - +/* window.onresize = function(event) { $.plot($('#' + graph_id), data, conf_pie); if (no_data == data.length) { @@ -319,7 +319,7 @@ function pandoraFlotPieCustom(graph_id, values, labels, width, $(this).css('transform', "rotate(-35deg)").css('color', 'black'); }); } - +*/ } function pandoraFlotHBars(graph_id, values, labels, water_mark, @@ -1673,7 +1673,9 @@ function pandoraFlotArea( graph_id, values, legend, // Re-calculate the graph height with the legend height if (dashboard || vconsole) { - var hDiff = $('#'+graph_id).height() - $('#legend_'+graph_id).height(); + $acum = 0; + if(dashboard) $acum = 35; + var hDiff = $('#'+graph_id).height() - $('#legend_'+graph_id).height() - $acum; if(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ){ } else { @@ -2169,10 +2171,11 @@ function pandoraFlotArea( graph_id, values, legend, } }); - $('#'+graph_id).bind('mouseout',resetInteractivity(vconsole)); - if(!vconsole){ - $('#overview_'+graph_id).bind('mouseout',resetInteractivity); + $('#'+graph_id) + .bind('mouseout', resetInteractivity); + $('#overview_'+graph_id) + .bind('mouseout', resetInteractivity); } if(image_treshold){ @@ -2216,7 +2219,7 @@ function pandoraFlotArea( graph_id, values, legend, } // Reset interactivity styles - function resetInteractivity(vconsole) { + function resetInteractivity() { $('#timestamp_'+graph_id).hide(); dataset = plot.getData(); for (i = 0; i < dataset.length; ++i) { @@ -2225,14 +2228,15 @@ function pandoraFlotArea( graph_id, values, legend, $('#legend_' + graph_id + ' .legendLabel') .eq(i).html(label_aux); } - $('#legend_' + graph_id + ' .legendLabel').css('color', legend_color); - $('#legend_' + graph_id + ' .legendLabel').css('font-size', font_size + 2 +'px'); - $('#legend_' + graph_id + ' .legendLabel').css('font-family', font + 'Font'); + $('#legend_' + graph_id + ' .legendLabel') + .css('color', legend_color); + $('#legend_' + graph_id + ' .legendLabel') + .css('font-size', font_size + 2 +'px'); + $('#legend_' + graph_id + ' .legendLabel') + .css('font-family', font + 'Font'); plot.clearCrosshair(); - if(!vconsole){ - overview.clearCrosshair(); - } + overview.clearCrosshair(); } function yFormatter(v, axis) { diff --git a/pandora_console/include/graphs/functions_flot.php b/pandora_console/include/graphs/functions_flot.php index 27b64fdde0..bf423d2267 100644 --- a/pandora_console/include/graphs/functions_flot.php +++ b/pandora_console/include/graphs/functions_flot.php @@ -132,9 +132,10 @@ function flot_area_graph ( $params['grid_color'] = '#C1C1C1'; break; } + $padding_vconsole = $params['dashboard'] ? 'padding: 1px 0px 10px 10px;' : ''; // Parent layer - $return = "
"; + $return = "
"; // Set some containers to legend, graph, timestamp tooltip, etc. if($params['show_legend']){ $return .= "

"; diff --git a/pandora_console/include/javascript/pandora.js b/pandora_console/include/javascript/pandora.js index bc8432ae48..11157ed3ff 100644 --- a/pandora_console/include/javascript/pandora.js +++ b/pandora_console/include/javascript/pandora.js @@ -1585,6 +1585,10 @@ function display_confirm_dialog (message, ok_text, cancel_text, ok_function) { clean_function(); } + var buttons_obj = {}; + buttons_obj[cancel_text] = clean_function; + buttons_obj[ok_text] = ok_function_clean; + // Display the dialog $("body").append('

' + message + '

'); $("#pandora_confirm_dialog_text").dialog({ @@ -1598,10 +1602,7 @@ function display_confirm_dialog (message, ok_text, cancel_text, ok_function) { }, closeOnEscape: true, modal: true, - buttons: { - Cancel: clean_function, - "Confirm": ok_function_clean - } + buttons: buttons_obj }); } diff --git a/pandora_console/include/javascript/tree/TreeController.js b/pandora_console/include/javascript/tree/TreeController.js index 409fc517d1..13a0b31cd4 100644 --- a/pandora_console/include/javascript/tree/TreeController.js +++ b/pandora_console/include/javascript/tree/TreeController.js @@ -55,7 +55,7 @@ var TreeController = { } container.append($group); - + _.each(elements, function(element) { element.jqObject = _processNode($group, element); }); @@ -279,14 +279,13 @@ var TreeController = { // Load leaf function _processNode (container, element) { - // type, [id], [serverID], callback function _getTreeDetailData (type, id, serverID, callback) { var lastParam = arguments[arguments.length - 1]; var callback; if (typeof lastParam === 'function') callback = lastParam; - + var serverID; if (arguments.length >= 4) serverID = arguments[2]; @@ -296,23 +295,23 @@ var TreeController = { var type; if (arguments.length >= 2) type = arguments[0]; - + if (typeof type === 'undefined') throw new TypeError('Type required'); if (typeof callback === 'undefined') throw new TypeError('Callback required'); - + var postData = { page: controller.ajaxPage, getDetail: 1, type: type } - + if (typeof id !== 'undefined') postData.id = id; if (typeof serverID !== 'undefined') postData.serverID = serverID; - + $.ajax({ url: controller.ajaxURL, type: 'POST', @@ -346,6 +345,36 @@ var TreeController = { $content.append(element.iconHTML + " "); } $content.append(element.name); + + if(typeof element.edit != 'undefined'){ + var url_edit = controller.baseURL + "index.php?sec=gagente&sec2=godmode/groups/configure_group&tab=tree&id_group=" + element.id; + var $updateicon = $('') + var $updatebtn = $('') + .append($updateicon); + $content.append($updatebtn); + } + + if(typeof element.delete != 'undefined'){ + var url_delete = controller.baseURL + "index.php?sec=gagente&sec2=godmode/groups/group_list&tab=tree&delete_group=1&id_group=" + element.id; + var $deleteBtn = $(''); + $deleteBtn.click(function (event){ + var ok_function = function(){ + window.location.replace(url_delete); + }; + display_confirm_dialog( + element.delete.messages.messg, + element.delete.messages.confirm, + element.delete.messages.cancel, + ok_function + ) + }); + $content.append($deleteBtn); + } + + if(typeof element.alerts != 'undefined'){ + $content.append(element.alerts); + } + break; case 'agent': // Is quiet @@ -583,95 +612,99 @@ var TreeController = { if (typeof(public_user) === 'undefined') public_user = 0; if (typeof element.searchChildren != 'undefined' && element.searchChildren) { - $node - .removeClass("leaf-empty") - .addClass("leaf-closed"); + if(element.rootType == "group_edition" + && typeof element.children == 'undefined'){ + $node.addClass("leaf-empty"); + } + else{ + $node + .removeClass("leaf-empty") + .addClass("leaf-closed"); + $leafIcon.click(function (e) { + e.preventDefault(); - $leafIcon.click(function (e) { - e.preventDefault(); - - if (!$node.hasClass("leaf-loading") && !$node.hasClass("children-loaded") && !$node.hasClass("leaf-empty")) { - $node - .removeClass("leaf-closed") - .removeClass("leaf-error") - .addClass("leaf-loading"); - - $.ajax({ - url: controller.ajaxURL, - type: 'POST', - dataType: 'json', - data: { - page: controller.ajaxPage, - getChildren: 1, - id: element.id, - type: element.type, - rootID: element.rootID, - serverID: element.serverID, - rootType: element.rootType, - filter: controller.filter, - hash: public_hash, - id_user: public_user - }, - complete: function(xhr, textStatus) { - $node.removeClass("leaf-loading"); - $node.addClass("children-loaded"); - }, - success: function(data, textStatus, xhr) { - if (data.success) { - var $group = $node.children("ul.tree-group"); - - if ((typeof data.tree != 'undefined' && data.tree.length > 0) || $group.length > 0) { - $node.addClass("leaf-open"); - - if ($group.length <= 0) { - $group = $("
    "); - $group - .addClass("tree-group") - .hide(); - $node.append($group); - } - - _.each(data.tree, function(element) { - element.jqObject = _processNode($group, element); - }); - - $group.slideDown(); - - $node.data('children', $group); - - // Add again the hover event to the 'force_callback' elements - forced_title_callback(); - } - else { - $node.addClass("leaf-empty"); - } - } - else { - $node.addClass("leaf-error"); - } - }, - error: function(xhr, textStatus, errorThrown) { - $node.addClass("leaf-error"); - } - }); - } - else if (! $node.hasClass("leaf-empty")) { - if ($node.hasClass("leaf-open")) { - $node - .removeClass("leaf-open") - .addClass("leaf-closed") - .data('children') - .slideUp(); - } - else { + if (!$node.hasClass("leaf-loading") && !$node.hasClass("children-loaded") && !$node.hasClass("leaf-empty")) { $node .removeClass("leaf-closed") - .addClass("leaf-open") - .data('children') - .slideDown(); + .removeClass("leaf-error") + .addClass("leaf-loading"); + + $.ajax({ + url: controller.ajaxURL, + type: 'POST', + dataType: 'json', + data: { + page: controller.ajaxPage, + getChildren: 1, + id: element.id, + type: element.type, + rootID: element.rootID, + serverID: element.serverID, + rootType: element.rootType, + filter: controller.filter, + hash: public_hash, + id_user: public_user + }, + complete: function(xhr, textStatus) { + $node.removeClass("leaf-loading"); + $node.addClass("children-loaded"); + }, + success: function(data, textStatus, xhr) { + if (data.success) { + var $group = $node.children("ul.tree-group"); + if ((typeof data.tree != 'undefined' && data.tree.length > 0) || $group.length > 0) { + $node.addClass("leaf-open"); + + if ($group.length <= 0) { + $group = $("
      "); + $group + .addClass("tree-group") + .hide(); + $node.append($group); + } + + _.each(data.tree, function(element) { + element.jqObject = _processNode($group, element); + }); + + $group.slideDown(); + + $node.data('children', $group); + + // Add again the hover event to the 'force_callback' elements + forced_title_callback(); + } + else { + $node.addClass("leaf-empty"); + } + } + else { + $node.addClass("leaf-error"); + } + }, + error: function(xhr, textStatus, errorThrown) { + $node.addClass("leaf-error"); + } + }); } - } - }); + else if (! $node.hasClass("leaf-empty")) { + if ($node.hasClass("leaf-open")) { + $node + .removeClass("leaf-open") + .addClass("leaf-closed") + .data('children') + .slideUp(); + } + else { + $node + .removeClass("leaf-closed") + .addClass("leaf-open") + .data('children') + .slideDown(); + } + } + }); + } } return $node; diff --git a/pandora_console/include/styles/pandora.css b/pandora_console/include/styles/pandora.css index 7ffd0d59a4..8cdfa3a9e7 100644 --- a/pandora_console/include/styles/pandora.css +++ b/pandora_console/include/styles/pandora.css @@ -3709,6 +3709,57 @@ div.simple_value > a > span.text p color:white; } +.modaldeletebutton{ + transition-property: background-color, color; + transition-duration: 1s; + transition-timing-function: ease-out; + -webkit-transition-property: background-color, color; + -webkit-transition-duration: 1s; + -o-transition-property: background-color, color; + -o-transition-duration: 1s; + cursor:pointer; + text-align:center; + margin-left:45px; + float:left; + -moz-border-radius: 3px; + -webkit-border-radius: 3px; + margin-bottom:30px; + border-radius: 3px;width:90px;height:30px;background-color:white;border: 1px solid #FA5858; +} + +.modaldeletebuttontext{ + transition-property: background-color, color; + transition-duration: 1s; + transition-timing-function: ease-out; + -webkit-transition-property: background-color, color; + -webkit-transition-duration: 1s; + -o-transition-property: background-color, color; + -o-transition-duration: 1s; + color:#FA5858;font-family:Nunito;font-size:10pt;position:relative;top:6px; +} + +.modaldeletebutton:hover .modaldeletebuttontext { + transition-property: background-color, color; + transition-duration: 1s; + transition-timing-function: ease-out; + -webkit-transition-property: background-color, color; + -webkit-transition-duration: 1s; + -o-transition-property: background-color, color; + -o-transition-duration: 1s; + color:white; +} + +.modaldeletebutton:hover { + transition-property: background-color, color; + transition-duration: 1s; + transition-timing-function: ease-out; + -webkit-transition-property: background-color, color; + -webkit-transition-duration: 1s; + -o-transition-property: background-color, color; + -o-transition-duration: 1s; + background-color:#FA5858; +} + .modalgobutton{ transition-property: background-color, color; transition-duration: 1s; diff --git a/pandora_console/install.php b/pandora_console/install.php index f0826fb787..7c57b2b569 100755 --- a/pandora_console/install.php +++ b/pandora_console/install.php @@ -70,8 +70,8 @@
      show(); break; - case 'networkmaps': - $networkmaps = new Networkmaps(); - $networkmaps->show(); - break; - case 'networkmap': - $networkmap = new Networkmap(); - $networkmap->show(); - break; case 'visualmaps': $visualmaps = new Visualmaps(); $visualmaps->show(); diff --git a/pandora_console/mobile/operation/groups.php b/pandora_console/mobile/operation/groups.php index da797f7425..e371c56986 100644 --- a/pandora_console/mobile/operation/groups.php +++ b/pandora_console/mobile/operation/groups.php @@ -179,29 +179,14 @@ class Groups { $ui->endContent(); $ui->showPage(); } - + private function getListGroups() { $return = array(); - + $system = System::getInstance(); $user = User::getInstance(); - - $all_data = groupview_status_modules_agents ($system->getConfig('id_user'), false, 'AR', false); - $result_groups = groupview_get_groups_list($system->getConfig('id_user'), false, 'AR', true, true); - - foreach ($all_data as $group_all_data) { - $result_groups[0]['_total_agents_'] += $group_all_data["_total_agents_"]; - $result_groups[0]['_monitors_ok_'] += $group_all_data["_monitors_ok_"]; - $result_groups[0]['_monitors_warning_'] += $group_all_data["_monitors_warning_"]; - $result_groups[0]['_monitors_critical_'] += $group_all_data["_monitors_critical_"]; - $result_groups[0]['_monitors_unknown_'] += $group_all_data["_monitors_unknown_"]; - $result_groups[0]['_monitors_not_init_'] += $group_all_data["_monitors_not_init_"]; - $result_groups[0]['_agents_unknown_'] += $group_all_data["_agents_unknown_"]; - $result_groups[0]['_agents_not_init_'] += $group_all_data["_agents_not_init_"]; - $result_groups[0]['_agents_critical_'] += $group_all_data["_agents_critical_"]; - $result_groups[0]['_monitors_alerts_fired_'] += $group_all_data["_monitors_alerts_fired_"]; - } - - return $result_groups; + $result_groups = groupview_get_groups_list($system->getConfig('id_user'),'AR', true); + + return $result_groups['groups']; } } diff --git a/pandora_console/mobile/operation/home.php b/pandora_console/mobile/operation/home.php index 59728010a5..1a1ff12110 100644 --- a/pandora_console/mobile/operation/home.php +++ b/pandora_console/mobile/operation/home.php @@ -73,13 +73,6 @@ class Home { 'menu_item' => true, 'icon' => 'modules' ); - - $items['networkmaps'] = array( - 'name' => __('Networkmaps'), - 'filename' => 'networkmaps.php', - 'menu_item' => true, - 'icon' => 'network_maps' - ); $items['visualmaps'] = array( 'name' => __('Visual consoles'), 'filename' => 'visualmaps.php', @@ -100,12 +93,6 @@ class Home { 'menu_item' => false, 'icon' => '' ); - $items['networkmap'] = array( - 'name' => __('Networkmap'), - 'filename' => 'networkmap.php', - 'menu_item' => false, - 'icon' => '' - ); $items['visualmap'] = array( 'name' => __('Visualmap'), 'filename' => 'visualmap.php', diff --git a/pandora_console/mobile/operation/networkmap.php b/pandora_console/mobile/operation/networkmap.php deleted file mode 100755 index 9595efaa87..0000000000 --- a/pandora_console/mobile/operation/networkmap.php +++ /dev/null @@ -1,246 +0,0 @@ -getFilters(); - else - $this->id = $id; - - $store_group = db_get_value('store_group', - 'tnetwork_map', 'id_networkmap', $this->id); - - if ($store_group !== false - && $system->checkACL($this->acl, $store_group)) - $this->correct_acl = true; - } - - public function ajax($parameter2 = false) { - $system = System::getInstance(); - - if (!$this->correct_acl) { - return; - } - else { - switch ($parameter2) { - case 'xxx': - //$this->getFilters(); - //$page = $system->getRequest('page', 0); - break; - } - } - } - - private function getFilters() { - $system = System::getInstance(); - - $this->id = (int)$system->getRequest('id', 0); - } - - public function show() { - if (!$this->correct_acl) { - $this->show_fail_acl(); - } - else { - $this->getFilters(); - - $this->networkmap = db_get_row('tnetwork_map', - 'id_networkmap', $this->id); - - $this->show_networkmap(); - } - } - - private function show_fail_acl() { - $error['type'] = 'onStart'; - $error['title_text'] = __('You don\'t have access to this page'); - $error['content_text'] = System::getDefaultACLFailText(); - if (class_exists("HomeEnterprise")) - $home = new HomeEnterprise(); - else - $home = new Home(); - $home->show($error); - } - - private function show_networkmap() { - $ui = Ui::getInstance(); - $system = System::getInstance(); - - $ui->createPage(); - $ui->createDefaultHeader( - sprintf("%s", - $this->networkmap['name']), - $ui->createHeaderButton( - array('icon' => 'back', - 'pos' => 'left', - 'text' => __('Back'), - 'href' => 'index.php?page=networkmaps'))); - $ui->showFooter(false); - $ui->beginContent(); - - //Hack for mobile - global $hack_networkmap_mobile; - $hack_networkmap_mobile = true; - - switch ($this->networkmap['type']) { - case 'groups': - $graph = networkmap_generate_dot_groups ( - __('Pandora FMS'), - $this->networkmap['id_group'], - $this->networkmap['simple'], - $this->networkmap['font_size'], - $this->networkmap['layout'], - (bool)$this->networkmap['nooverlap'], - $this->networkmap['zoom'], - $this->networkmap['distance_nodes'], - $this->networkmap['center'], 1, 0, - $this->networkmap['only_modules_with_alerts'], - $this->networkmap['id_module_group'], - $this->networkmap['hide_policy_modules'], - $this->networkmap['depth'], - $this->networkmap['id_networkmap']); - break; - case 'policies': - $enterprise = enterprise_include('/include/functions_policies.php'); - - if ($enterprise != ENTERPRISE_NOT_HOOK) { - $graph = policies_generate_dot_graph (__('Pandora FMS'), - $this->networkmap['id_group'], - $this->networkmap['simple'], - $this->networkmap['font_size'], - $this->networkmap['layout'], - (bool)$this->networkmap['nooverlap'], - $this->networkmap['zoom'], - $this->networkmap['distance_nodes'], - $this->networkmap['center'], 1, 0, - $this->networkmap['only_modules_with_alerts'], - $this->networkmap['id_module_group'], - $this->networkmap['depth'], - $this->networkmap['id_networkmap']); - } - break; - default: - case 'topology': - $graph = networkmap_generate_dot (__('Pandora FMS'), - $this->networkmap['id_group'], - $this->networkmap['simple'], - $this->networkmap['font_size'], - $this->networkmap['layout'], - (bool)$this->networkmap['nooverlap'], - $this->networkmap['zoom'], - $this->networkmap['distance_nodes'], - $this->networkmap['center'], 1, 0, - $this->networkmap['id_networkmap'], - $this->networkmap['show_snmp_modules'], true, - true); - break; - } - - - - if ($graph === false) { - $ui->contentAddHtml('

      ' . __('No networkmaps') . '

      '); - - $ui->endContent(); - $ui->showPage(); - - return; - } - - - $filter = networkmap_get_filter($this->networkmap['layout']); - - // Generate image and map - // If image was generated just a few minutes ago, then don't regenerate (it takes long) unless regen checkbox is set - $filename_map = safe_url_extraclean ( - $system->getConfig('attachment_store')) . "/networkmap_" . $filter; - $filename_img = safe_url_extraclean ( - $system->getConfig('attachment_store')) . "/networkmap_" . - $filter . "_" . $this->networkmap['font_size']; - $url_img = "../attachment/networkmap_" . - $filter . "_" . $this->networkmap['font_size']; - $filename_dot = safe_url_extraclean( - $system->getConfig("attachment_store")) . "/networkmap_" . $filter; - if ($this->networkmap['simple']) { - $filename_map .= "_simple"; - $filename_img .= "_simple"; - $url_img .= "_simple"; - $filename_dot .= "_simple"; - } - if ($this->networkmap['nooverlap']) { - $filename_map .= "_nooverlap"; - $filename_img .= "_nooverlap"; - $url_img .= "_nooverlap"; - $filename_dot .= "_nooverlap"; - } - $filename_map .= "_" . $this->networkmap['id_networkmap'] . ".map"; - $filename_img .= "_" . $this->networkmap['id_networkmap'] . ".png"; - $url_img .= "_" . $this->networkmap['id_networkmap'] . ".png"; - $filename_dot .= "_" . $this->networkmap['id_networkmap'] . ".dot"; - - if ($this->networkmap['regenerate'] != 1 && file_exists($filename_img) && filemtime($filename_img) > get_system_time () - 300) { - $result = true; - } - else { - $fh = @fopen ($filename_dot, 'w'); - if ($fh === false) { - $result = false; - } - else { - fwrite ($fh, $graph); - $cmd = $filter . " -Tcmapx -o" . $filename_map." -Tpng -o".$filename_img." ".$filename_dot; - $result = system ($cmd); - fclose ($fh); - //unlink ($filename_dot); - } - } - - if ($result !== false) { - if (! file_exists ($filename_map)) { - $ui->contentAddHtml('

      ' . __('Map could not be generated') . '

      '); - - $ui->endContent(); - $ui->showPage(); - - return; - } - $ui->contentAddHtml('
      '); - $ui->contentAddHtml(''); - $ui->contentAddHtml('
      '); - } - else { - $ui->contentAddHtml('

      ' . __('Map could not be generated') . '

      '); - - $ui->endContent(); - $ui->showPage(); - - return; - } - - $ui->endContent(); - $ui->showPage(); - } -} -?> diff --git a/pandora_console/mobile/operation/networkmaps.php b/pandora_console/mobile/operation/networkmaps.php deleted file mode 100755 index f8f533cc84..0000000000 --- a/pandora_console/mobile/operation/networkmaps.php +++ /dev/null @@ -1,250 +0,0 @@ -checkACL($this->acl)) { - $this->correct_acl = true; - } - else { - $this->correct_acl = false; - } - } - - public function ajax($parameter2 = false) { - $system = System::getInstance(); - - if (!$this->correct_acl) { - return; - } - else { - switch ($parameter2) { - case 'xxx': - //$this->getFilters(); - //$page = $system->getRequest('page', 0); - break; - } - } - } - - private function getFilters() { - $system = System::getInstance(); - $user = User::getInstance(); - - $this->default_filters['group'] = true; - $this->default_filters['type'] = true; - - $this->group = (int)$system->getRequest('group', __("Group")); - if (!$user->isInGroup($this->acl, $this->group)) { - $this->group = 0; - } - if (($this->group === __("Group")) || ($this->group == 0)) { - $this->group = 0; - } - else { - $this->default = false; - $this->default_filters['group'] = false; - } - - $this->type = $system->getRequest('type', __("Type")); - if (($this->type === __("Type")) || ($this->type === '0')) { - $this->type = '0'; - } - else { - $this->default = false; - $this->default_filters['type'] = false; - } - } - - public function show() { - if (!$this->correct_acl) { - $this->show_fail_acl(); - } - else { - $this->getFilters(); - $this->show_networkmaps(); - } - } - - private function show_fail_acl() { - $error['type'] = 'onStart'; - $error['title_text'] = __('You don\'t have access to this page'); - $error['content_text'] = System::getDefaultACLFailText(); - if (class_exists("HomeEnterprise")) - $home = new HomeEnterprise(); - else - $home = new Home(); - $home->show($error); - } - - private function show_networkmaps() { - $ui = Ui::getInstance(); - - $ui->createPage(); - $ui->createDefaultHeader(__("Networkmaps"), - $ui->createHeaderButton( - array('icon' => 'back', - 'pos' => 'left', - 'text' => __('Back'), - 'href' => 'index.php?page=home'))); - $ui->showFooter(false); - $ui->beginContent(); - $filter_title = sprintf(__('Filter Networkmaps by %s'), - $this->filterNetworkmapsGetString()); - $ui->contentBeginCollapsible($filter_title); - $ui->beginForm("index.php?page=networkmaps"); - $system = System::getInstance(); - $groups = users_get_groups_for_select( - $system->getConfig('id_user'), "AR", true, true, false, 'id_grupo'); - $options = array( - 'name' => 'group', - 'title' => __('Group'), - 'label' => __('Group'), - 'items' => $groups, - 'selected' => $this->group - ); - $ui->formAddSelectBox($options); - - $networkmap_types = networkmap_get_filter_types(); - $networkmap_types[0] = __('All'); - $options = array( - 'name' => 'type', - 'title' => __('Type'), - 'label' => __('Type'), - 'items' => $networkmap_types, - 'selected' => $this->type - ); - $ui->formAddSelectBox($options); - - $options = array( - 'icon' => 'refresh', - 'icon_pos' => 'right', - 'text' => __('Apply Filter') - ); - $ui->formAddSubmitButton($options); - $html = $ui->getEndForm(); - $ui->contentCollapsibleAddItem($html); - $ui->contentEndCollapsible(); - $this->listNetworkmapsHtml(); - $ui->endContent(); - $ui->showPage(); - } - - private function listNetworkmapsHtml() { - $system = System::getInstance(); - $ui = Ui::getInstance(); - - // Create filter - $where = array(); - // Order by type field - $where['order'] = 'type'; - - if ($this->group != '0') { - $where['store_group'] = $this->group; - } - else { - $where['store_group'] = array_keys(users_get_groups()); - } - - if ($this->type != '0') - $where['type'] = $this->type; - - $network_maps = db_get_all_rows_filter('tnetwork_map', - $where); - if (empty($network_maps)) { - $network_maps = array(); - } - $list = array(); - foreach ($network_maps as $networkmap) { - // ACL - if (! $system->checkACL("AR", $networkmap['store_group'])) - continue; - - // If enterprise not loaded then skip this code - if ($networkmap['type'] == 'policies' and (!defined('PANDORA_ENTERPRISE'))) - continue; - $row = array(); - $row[__('Name')] = '' . io_safe_output($networkmap['name']) . ''; - $row[__('Type')] = $networkmap['type']; - $row[__('Group')] = ui_print_group_icon($networkmap["store_group"], true, "groups_small", "" , false); - $list[] = $row; - } - - if (count($network_maps) == 0) { - $ui->contentAddHtml('

      ' . __('No networkmaps') . '

      '); - } - else { - $table = new Table(); - $table->id = 'list_networkmaps'; - $table->importFromHash($list); - $ui->contentAddHtml($table->getHTML()); - } - - $ui->contentAddLinkListener('list_networkmaps'); - } - - private function filterNetworkmapsGetString() { - if ($this->default) { - return __("(Default)"); - } - else { - $filters_to_serialize = array(); - - if (!$this->default_filters['group']) { - $filters_to_serialize[] = sprintf(__("Group: %s"), - groups_get_name($this->group, true)); - } - if (!$this->default_filters['type']) { - $networkmap_types = networkmap_get_filter_types(); - $networkmap_types[0] = __('All'); - - $filters_to_serialize[] = sprintf(__("Type: %s"), - $networkmap_types[$this->type]); - } - - $string = '(' . implode(' - ', $filters_to_serialize) . ')'; - - - //~ $networkmap_types = networkmap_get_filter_types(); - //~ $networkmap_types[0] = __('All'); - //~ $type = $networkmap_types[$this->type]; - //~ $group = groups_get_name($this->group, true); - //~ - //~ - //~ $string = sprintf( - //~ __("(Type: %s - Group: %s)"), - //~ $type, $group); - - return $string; - } - } -} -?> diff --git a/pandora_console/operation/agentes/alerts_status.php b/pandora_console/operation/agentes/alerts_status.php index 12c7fd5d8d..753baf56bb 100755 --- a/pandora_console/operation/agentes/alerts_status.php +++ b/pandora_console/operation/agentes/alerts_status.php @@ -187,77 +187,37 @@ if ($alert_validate) { enterprise_hook('open_meta_frame'); if ($free_search != '') { - switch ($config["dbtype"]) { - case "mysql": - $whereAlertSimple = 'AND (' . - 'id_alert_template IN ( - SELECT id - FROM talert_templates - WHERE name LIKE "%' . $free_search . '%") OR ' . - 'id_alert_template IN ( - SELECT id - FROM talert_templates - WHERE id_alert_action IN ( - SELECT id - FROM talert_actions - WHERE name LIKE "%' . $free_search . '%")) OR ' . - 'talert_template_modules.id IN ( - SELECT id_alert_template_module - FROM talert_template_module_actions - WHERE id_alert_action IN ( - SELECT id - FROM talert_actions - WHERE name LIKE "%' . $free_search . '%")) OR ' . - 'id_agent_module IN ( - SELECT id_agente_modulo - FROM tagente_modulo - WHERE nombre LIKE "%' . $free_search . '%") OR ' . - 'id_agent_module IN ( - SELECT id_agente_modulo - FROM tagente_modulo - WHERE id_agente IN ( - SELECT id_agente - FROM tagente - WHERE nombre LIKE "%' . $free_search . '%") OR alias LIKE "%' . $free_search . '%")' . - ')'; - - break; - case "postgresql": - case "oracle": - $whereAlertSimple = 'AND (' . - 'id_alert_template IN ( - SELECT id - FROM talert_templates - WHERE name LIKE \'%' . $free_search . '%\') OR ' . - 'id_alert_template IN ( - SELECT id - FROM talert_templates - WHERE id_alert_action IN ( - SELECT id - FROM talert_actions - WHERE name LIKE \'%' . $free_search . '%\')) OR ' . - 'talert_template_modules.id IN ( - SELECT id_alert_template_module - FROM talert_template_module_actions - WHERE id_alert_action IN ( - SELECT id - FROM talert_actions - WHERE name LIKE \'%' . $free_search . '%\')) OR ' . - 'id_agent_module IN ( - SELECT id_agente_modulo - FROM tagente_modulo - WHERE nombre LIKE \'%' . $free_search . '%\') OR ' . - 'id_agent_module IN ( - SELECT id_agente_modulo - FROM tagente_modulo - WHERE id_agente IN ( - SELECT id_agente - FROM tagente - WHERE nombre LIKE \'%' . $free_search . '%\' OR alias LIKE \'%' . $free_search . '%\'))' . - ')'; - - break; - } + $whereAlertSimple = 'AND (' . + 'id_alert_template IN ( + SELECT id + FROM talert_templates + WHERE name LIKE "%' . $free_search . '%") OR ' . + 'id_alert_template IN ( + SELECT id + FROM talert_templates + WHERE id_alert_action IN ( + SELECT id + FROM talert_actions + WHERE name LIKE "%' . $free_search . '%")) OR ' . + 'talert_template_modules.id IN ( + SELECT id_alert_template_module + FROM talert_template_module_actions + WHERE id_alert_action IN ( + SELECT id + FROM talert_actions + WHERE name LIKE "%' . $free_search . '%")) OR ' . + 'id_agent_module IN ( + SELECT id_agente_modulo + FROM tagente_modulo + WHERE nombre LIKE "%' . $free_search . '%") OR ' . + 'id_agent_module IN ( + SELECT id_agente_modulo + FROM tagente_modulo + WHERE id_agente IN ( + SELECT id_agente + FROM tagente + WHERE nombre LIKE "%' . $free_search . '%") OR alias LIKE "%' . $free_search . '%")' . + ')'; } else { $whereAlertSimple = ''; diff --git a/pandora_console/operation/agentes/gis_view.php b/pandora_console/operation/agentes/gis_view.php index c67a97037a..1b7d341917 100644 --- a/pandora_console/operation/agentes/gis_view.php +++ b/pandora_console/operation/agentes/gis_view.php @@ -36,7 +36,6 @@ $agentId = (int)get_parameter('id_agente'); $id_agente = $agentId; $agent_name = agents_get_name($id_agente); $agent_alias = agents_get_alias($id_agente); -$agentData = gis_get_data_last_position_agent($id_agente); //Avoid the agents with characters that fails the div. $agent_name_original = $agent_name; @@ -83,35 +82,22 @@ switch ($config["dbtype"]) { gis_activate_ajax_refresh(null, $timestampLastOperation); gis_activate_select_control(); -if ($agentData === false) { - ui_print_info_message ( - __("There is no GIS data for this agent, so it's positioned in default position of map.") ); -} - -$dataLastPosition = gis_get_data_last_position_agent($agentId); -if ($dataLastPosition !== false) { - echo "" . __("Last position in ") . - $dataLastPosition['start_timestamp'] . ": " . - $dataLastPosition['stored_longitude'] . ", " . $dataLastPosition['stored_latitude'] . ", " . $dataLastPosition['stored_altitude']; -} - +echo "
      "; echo ""; echo ""; -echo "
      " . __("Period to show data as path") . ": "; +echo "
      " . __("Period to show data as path"); echo ""; html_print_extended_select_for_time ('period', $period, '', '', '0', 10); echo ""; html_print_submit_button(__('Refresh path'), 'refresh', false, 'class = "sub upd" style="margin-top:0px"'); echo "
      "; -echo "

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

      "; /* 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 = db_get_value_sql($sqlCount); - +$countData = (int) db_get_value_sql($sqlCount); /* Get the elements to present in this page */ switch ($config["dbtype"]) { @@ -141,9 +127,7 @@ 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 @@ -163,10 +147,11 @@ if ($result === false) { } if ($result !== false) { - if(!$countData){ - $countData = 1; - } - ui_pagination ($countData, false) ; + echo "

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

      "; + + if ($countData > 0) ui_pagination($countData, false); + + $table = new StdClass(); $table->data = array(); foreach ($result as $key => $row) { $distance = 0; @@ -187,9 +172,13 @@ if ($result !== false) { $rowdata = array( $row['longitude'], $row['latitude'], - $row['altitude'], - $row['start_timestamp'], - $row['end_timestamp'], + (int) $row['altitude'] . " m", + is_numeric($row['start_timestamp']) + ? date($config["date_format"], $row['start_timestamp']) + : date_w_fixed_tz($row['start_timestamp']), + is_numeric($row['end_timestamp']) + ? date($config["date_format"], $row['end_timestamp']) + : date_w_fixed_tz($row['end_timestamp']), $row['description'], sprintf(__('%s Km'), $distance), $row['number_of_packages'], @@ -206,13 +195,12 @@ if ($result !== false) { __('Distance'), __("# of Packages"), __("Manual placement")); - $table->class = 'position_data_table'; + $table->class = 'databox data'; $table->id = $agent_name.'_position_data_table'; - $table->title = $agent_alias . " " . __("positional data"); - $table->titlestyle = "background-color:#799E48;"; - html_print_table($table); unset($table); + $table->width = '100%'; + html_print_table($table); + unset($table); - ui_pagination ($countData, false) ; - echo "

      " . __('Total') . ' ' . $countData . ' ' . __('Data') . "

      "; + if ($countData > 0) ui_pagination($countData, false); } ?> diff --git a/pandora_console/operation/agentes/group_view.php b/pandora_console/operation/agentes/group_view.php index b177464a59..abc31b4ea4 100644 --- a/pandora_console/operation/agentes/group_view.php +++ b/pandora_console/operation/agentes/group_view.php @@ -30,7 +30,6 @@ if (!$agent_a && !$agent_w) { require ("general/noaccess.php"); exit; } -$offset = get_parameter('offset', 0); // Update network modules for this group // Check for Network FLAG change request // Made it a subquery, much faster on both the database and server side @@ -69,8 +68,6 @@ else { // Header ui_print_page_header (__("Group view"), "images/group.png", false, "", false, $updated_time); -$strict_user = false; - $total_agentes = 0; $monitor_ok = 0; $monitor_warning = 0; @@ -83,9 +80,12 @@ $agents_notinit = 0; $all_alerts_fired = 0; //Groups and tags -$result_groups = groupview_get_groups_list($config['id_user'], $strict_user, - ($agent_a == true) ? 'AR' : (($agent_w == true) ? 'AW' : 'AR'), true, true); -$count = count($result_groups); +$result_groups_info = groupview_get_groups_list( + $config['id_user'], + ($agent_a == true) ? 'AR' : (($agent_w == true) ? 'AW' : 'AR') +); +$result_groups = $result_groups_info['groups']; +$count = $result_groups_info['counter']; if ($result_groups[0]["_id_"] == 0) { $total_agentes = $result_groups[0]["_total_agents_"]; @@ -186,10 +186,7 @@ if (!empty($result_groups)) { echo "" . __("Alert fired") . ""; echo ""; - $result_groups = array_slice($result_groups, $offset, $config['block_size']); - foreach ($result_groups as $data) { - $groups_id = $data["_id_"]; // Calculate entire row color @@ -453,4 +450,4 @@ if (!empty($result_groups)) { } else { ui_print_info_message ( __('There are no defined agents')); } -?> \ No newline at end of file +?> diff --git a/pandora_console/operation/agentes/tactical.php b/pandora_console/operation/agentes/tactical.php index 7c41cf8565..578c0c6af4 100755 --- a/pandora_console/operation/agentes/tactical.php +++ b/pandora_console/operation/agentes/tactical.php @@ -56,7 +56,6 @@ ui_print_page_header (__("Tactical view"), "", false, "", false, $updated_time); //Currently this function makes loading this page is impossible. Change //and create new function. -//$all_data = group_get_groups_list($config['id_user'], $user_strict, 'AR', true, false, 'tactical'); $all_data = tactical_status_modules_agents($config['id_user'], $user_strict, 'AR', $user_strict); diff --git a/pandora_console/operation/gis_maps/render_view.php b/pandora_console/operation/gis_maps/render_view.php index eabefebbfe..de453a5a81 100644 --- a/pandora_console/operation/gis_maps/render_view.php +++ b/pandora_console/operation/gis_maps/render_view.php @@ -108,6 +108,9 @@ $layers = gis_get_layers($idMap); // Render map +$has_management_acl = check_acl($config["id_user"], $map['group_id'], "MW") + || check_acl ($config["id_user"], $map['group_id'], "MM"); + $buttons = array(); if ($config["pure"] == 0) { @@ -119,22 +122,14 @@ else { html_print_image ("images/normalscreen.png", true, array ("title" => __('Back to normal mode'))) . ""; } -if (check_acl ($config["id_user"], $map['group_id'], "MW") || check_acl ($config["id_user"], $map['group_id'], "MM")) { - $buttons['setup']['text'] = ''.html_print_image ("images/setup.png", true, array ("title" => __('Setup'))).''; - $buttons['setup']['godmode'] = 1; - - +if ($has_management_acl) { $hash = md5($config["dbpass"] . $idMap . $config["id_user"]); - $buttons['public_link']['text'] = ''. html_print_image ("images/camera_mc.png", true, array ("title" => __('Show link to public Visual Console'))).''; } -$buttonsString = '' . - html_print_image("images/bricks.png", true, array("class" => "top", "border" => '0')) . '  Agent - test_gis1
      '; diff --git a/pandora_console/pandora_console.redhat.spec b/pandora_console/pandora_console.redhat.spec index 0c6ee23221..5e1f2e7dfd 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.726 -%define release 180904 +%define version 7.0NG.727 +%define release 180918 # 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 ce2ed21b39..b293741eab 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.726 -%define release 180904 +%define version 7.0NG.727 +%define release 180918 %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 a9c44bc998..8e48a00720 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.726" +PI_VERSION="7.0NG.727" FORCE=0 DESTDIR="" LOG_TIMESTAMP=`date +"%Y/%m/%d %H:%M:%S"` diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index b2282c3685..655bae59bf 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -775,6 +775,13 @@ CREATE TABLE IF NOT EXISTS `trecon_task` ( `alias_as_name` tinyint(2) NOT NULL default '0', `snmp_enabled` tinyint(1) unsigned default '0', `vlan_enabled` tinyint(1) unsigned default '0', + `snmp_version` varchar(5) NOT NULL default '1', + `snmp_auth_user` varchar(255) NOT NULL default '', + `snmp_auth_pass` varchar(255) NOT NULL default '', + `snmp_auth_method` varchar(25) NOT NULL default '', + `snmp_privacy_method` varchar(25) NOT NULL default '', + `snmp_privacy_pass` varchar(255) NOT NULL default '', + `snmp_security_level` varchar(25) NOT NULL default '', PRIMARY KEY (`id_rt`), KEY `recon_task_daemon` (`id_recon_server`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; @@ -1242,6 +1249,7 @@ CREATE TABLE IF NOT EXISTS `treport` ( `id_group_edit` mediumint(8) unsigned NULL DEFAULT 0, `metaconsole` tinyint(1) DEFAULT 0, `non_interactive` tinyint(1) UNSIGNED NOT NULL default 0, + `hidden` tinyint(1) DEFAULT 0, PRIMARY KEY(`id_report`) ) ENGINE = InnoDB DEFAULT CHARSET=utf8; @@ -2364,6 +2372,7 @@ CREATE TABLE IF NOT EXISTS `tpolicy_modules_inventory` ( `username` varchar(100) default '', `password` varchar(100) default '', `pending_delete` tinyint(1) default '0', + `custom_fields` MEDIUMBLOB NOT NULL, PRIMARY KEY (`id`), FOREIGN KEY (`id_policy`) REFERENCES tpolicies(`id`) ON UPDATE CASCADE ON DELETE CASCADE, @@ -3329,3 +3338,15 @@ CREATE TABLE IF NOT EXISTS `tlayout_template_data` ( PRIMARY KEY(`id`), FOREIGN KEY (`id_layout_template`) REFERENCES tlayout_template(`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE = InnoDB DEFAULT CHARSET=utf8; + +-- --------------------------------------------------------------------- +-- Table `tlog_graph_models` +-- --------------------------------------------------------------------- +CREATE TABLE IF NOT EXISTS `tlog_graph_models` ( + `id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, + `title` TEXT NOT NULL, + `regexp` TEXT NOT NULL, + `fields` TEXT NOT NULL, + `average` tinyint(1) NOT NULL default '0', + PRIMARY KEY(`id`) +) ENGINE = InnoDB DEFAULT CHARSET=utf8; diff --git a/pandora_console/pandoradb_data.sql b/pandora_console/pandoradb_data.sql index 58f35ab553..07fd6acd64 100644 --- a/pandora_console/pandoradb_data.sql +++ b/pandora_console/pandoradb_data.sql @@ -112,7 +112,7 @@ INSERT INTO `tconfig` (`token`, `value`) VALUES ('MR', 19), ('identification_reminder', 1), ('identification_reminder_timestamp', 0), -('current_package_enterprise', '726'), +('current_package_enterprise', '727'), ('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'), @@ -1260,3 +1260,10 @@ INSERT INTO `tprofile_view` (`id_profile`, `sec`, `sec2`, `sec3`) VALUES (5, '*' -- Dumping data for table `tcontainer` -- INSERT INTO `tcontainer` SET `name` = 'Default graph container'; + +-- +-- Dumping data for table `tlog_graph_models` +-- +INSERT INTO tlog_graph_models VALUES (1, 'Apache log model', + '^.*?\s+.*".*?\s(\/.*?)\?.*1.1"\s+(.*?)\s+(.*?)\s+', + 'pagina, html_err_code, _tiempo_', 1); diff --git a/pandora_server/DEBIAN/control b/pandora_server/DEBIAN/control index 5f259c4acb..c35c51c92a 100644 --- a/pandora_server/DEBIAN/control +++ b/pandora_server/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-server -Version: 7.0NG.726-180904 +Version: 7.0NG.727-180918 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 31f520655d..70e0110594 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.726-180904" +pandora_version="7.0NG.727-180918" 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 c4982acf77..53490bdf11 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.726 +# Version 7.0NG.727 # 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 5a87dcdd89..621da73512 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.726"; -my $pandora_build = "180904"; +my $pandora_version = "7.0NG.727"; +my $pandora_build = "180918"; 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 a8a26e6ad2..05cd5ab9e1 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -4635,97 +4635,93 @@ Process groups statistics for statistics table ########################################################################## sub pandora_group_statistics ($$) { my ($pa_config, $dbh) = @_; - - # Variable init - my $modules = 0; - my $normal = 0; - my $critical = 0; - my $warning = 0; - my $unknown = 0; - my $non_init = 0; - my $alerts = 0; - my $alerts_fired = 0; - my $agents = 0; - my $agents_unknown = 0; - my $utimestamp = 0; - my $group = 0; + my $is_meta = is_metaconsole($pa_config); - # Get all groups - my @groups = get_db_rows ($dbh, 'SELECT id_grupo FROM tgrupo'); - my $table = is_metaconsole($pa_config) ? 'tmetaconsole_agent' : 'tagente'; - my $sec_table = is_metaconsole($pa_config) - ? 'tmetaconsole_agent_secondary_group' - : 'tagent_secondary_group'; + logger($pa_config, "Updating no realtime group stats.", 10); - # For each valid group get the stats: Simple uh? - foreach my $group_row (@groups) { + my $total_alerts_condition = $is_meta + ? "0" + : "COUNT(tatm.id)"; + my $joins_alerts = $is_meta + ? "" + : "LEFT JOIN tagente_modulo tam + ON tam.id_agente = ta.id_agente + INNER JOIN talert_template_modules tatm + ON tatm.id_agent_module = tam.id_agente_modulo"; + my $agent_table = $is_meta + ? "tmetaconsole_agent" + : "tagente"; + my $agent_seconsary_table = $is_meta + ? "tmetaconsole_agent_secondary_group" + : "tagent_secondary_group"; - $group = $group_row->{'id_grupo'}; - - # NOTICE - Calculations done here MUST BE the same than used in PHP code to have - # the same criteria. PLEASE, double check any changes here and in functions_groups.php - $agents_unknown = get_db_value ($dbh, "SELECT COUNT(DISTINCT(id_agente)) - FROM $table LEFT JOIN $sec_table ON id_agente=id_agent - WHERE disabled=0 AND critical_count=0 AND warning_count=0 AND unknown_count>0 AND (id_grupo=? OR id_group=?)", $group, $group); - $agents_unknown = 0 unless defined ($agents_unknown); - - $agents = get_db_value ($dbh, "SELECT COUNT(DISTINCT(id_agente)) - FROM $table LEFT JOIN $sec_table ON id_agente=id_agent - WHERE(id_grupo=$group OR id_group=$group) AND disabled=0"); - $agents = 0 unless defined ($agents); - - $modules = get_db_value ($dbh, "SELECT SUM(total_count) FROM + # Update the record. + db_do ($dbh, "REPLACE INTO tgroup_stat( + `id_group`, `modules`, `normal`, `critical`, `warning`, `unknown`, + `non-init`, `alerts`, `alerts_fired`, `agents`, + `agents_unknown`, `utimestamp` + ) + SELECT + tg.id_grupo AS id_group, + IF (SUM(modules_total) IS NULL,0,SUM(modules_total)) AS modules, + IF (SUM(modules_ok) IS NULL,0,SUM(modules_ok)) AS normal, + IF (SUM(modules_critical) IS NULL,0,SUM(modules_critical)) AS critical, + IF (SUM(modules_warning) IS NULL,0,SUM(modules_warning)) AS warning, + IF (SUM(modules_unknown) IS NULL,0,SUM(modules_unknown)) AS unknown, + IF (SUM(modules_not_init) IS NULL,0,SUM(modules_not_init)) AS `non-init`, + IF (SUM(alerts_total) IS NULL,0,SUM(alerts_total)) AS alerts, + IF (SUM(alerts_fired) IS NULL,0,SUM(alerts_fired)) AS alerts_fired, + IF (SUM(agents_total) IS NULL,0,SUM(agents_total)) AS agents, + IF (SUM(agents_unknown) IS NULL,0,SUM(agents_unknown)) AS agents_unknown, + UNIX_TIMESTAMP() AS utimestamp + FROM ( - SELECT DISTINCT(id_agente), total_count - FROM $table LEFT JOIN $sec_table ON id_agente=id_agent - WHERE disabled=0 AND (id_grupo=? OR id_group=?) - ) AS t1", $group, $group); - $modules = 0 unless defined ($modules); + SELECT SUM(ta.normal_count) AS modules_ok, + SUM(ta.critical_count) AS modules_critical, + SUM(ta.warning_count) AS modules_warning, + SUM(ta.unknown_count) AS modules_unknown, + SUM(ta.notinit_count) AS modules_not_init, + SUM(ta.total_count) AS modules_total, + SUM(ta.fired_count) AS alerts_fired, + $total_alerts_condition AS alerts_total, + SUM(IF(ta.critical_count > 0, 1, 0)) AS agents_critical, + SUM(IF(ta.critical_count = 0 AND ta.warning_count = 0 AND ta.unknown_count > 0, 1, 0)) AS agents_unknown, + SUM(IF(ta.total_count = ta.notinit_count, 1, 0)) AS agents_not_init, + COUNT(ta.id_agente) AS agents_total, + ta.id_grupo AS g + FROM $agent_table ta + $joins_alerts + WHERE ta.disabled = 0 + GROUP BY g - $normal = get_db_value ($dbh, "SELECT COUNT(DISTINCT(id_agente)) - FROM $table LEFT JOIN $sec_table ON id_agente=id_agent - WHERE disabled=0 AND critical_count=0 AND warning_count=0 AND unknown_count=0 AND normal_count>0 AND (id_grupo=? OR id_group=?)", $group, $group); - $normal = 0 unless defined ($normal); + UNION ALL - $critical = get_db_value ($dbh, "SELECT COUNT(DISTINCT(id_agente)) - FROM $table LEFT JOIN $sec_table ON id_agente=id_agent - WHERE disabled=0 AND critical_count>0 AND (id_grupo=? OR id_group=?)", $group, $group); - $critical = 0 unless defined ($critical); - - $warning = get_db_value ($dbh, "SELECT COUNT(DISTINCT(id_agente)) - FROM $table LEFT JOIN $sec_table ON id_agente=id_agent - WHERE disabled=0 AND critical_count=0 AND warning_count>0 AND (id_grupo=? OR id_group=?)", $group, $group); - $warning = 0 unless defined ($warning); - - $unknown = get_db_value ($dbh, "SELECT COUNT(DISTINCT(id_agente)) - FROM $table LEFT JOIN $sec_table ON id_agente=id_agent - WHERE disabled=0 AND critical_count=0 AND warning_count=0 AND unknown_count>0 AND (id_grupo=? OR id_group=?)", $group, $group); - $unknown = 0 unless defined ($unknown); - - $non_init = get_db_value ($dbh, "SELECT COUNT(DISTINCT(id_agente)) - FROM $table LEFT JOIN $sec_table ON id_agente=id_agent - WHERE disabled=0 AND total_count=notinit_count AND (id_grupo=? OR id_group=?)", $group, $group); - $non_init = 0 unless defined ($non_init); - - # Total alert count not available on the meta console. - if ($table eq 'tagente') { - $alerts = get_db_value ($dbh, "SELECT COUNT(talert_template_modules.id) - FROM talert_template_modules, tagente_modulo, tagente - WHERE tagente.id_grupo = $group AND tagente_modulo.id_agente = tagente.id_agente - AND tagente_modulo.disabled = 0 AND tagente.disabled = 0 - AND talert_template_modules.disabled = 0 - AND talert_template_modules.id_agent_module = tagente_modulo.id_agente_modulo"); - } - $alerts = 0 unless defined ($alerts); - - $alerts_fired = get_db_value ($dbh, "SELECT SUM(fired_count) FROM $table WHERE disabled=0 AND id_grupo=?", $group); - $alerts_fired = 0 unless defined ($alerts_fired); - - # Update the record. - db_do ($dbh, "REPLACE INTO tgroup_stat (id_group, modules, normal, critical, warning, unknown, " . $PandoraFMS::DB::RDBMS_QUOTE . 'non-init' . $PandoraFMS::DB::RDBMS_QUOTE . ", alerts, alerts_fired, agents, agents_unknown, utimestamp) VALUES ($group, $modules, $normal, $critical, $warning, $unknown, $non_init, $alerts, $alerts_fired, $agents, $agents_unknown, UNIX_TIMESTAMP())"); - - } + SELECT SUM(ta.normal_count) AS modules_ok, + SUM(ta.critical_count) AS modules_critical, + SUM(ta.warning_count) AS modules_warning, + SUM(ta.unknown_count) AS modules_unknown, + SUM(ta.notinit_count) AS modules_not_init, + SUM(ta.total_count) AS modules_total, + SUM(ta.fired_count) AS alerts_fired, + $total_alerts_condition AS alerts_total, + SUM(IF(ta.critical_count > 0, 1, 0)) AS agents_critical, + SUM(IF(ta.critical_count = 0 AND ta.warning_count = 0 AND ta.unknown_count > 0, 1, 0)) AS agents_unknown, + SUM(IF(ta.total_count = ta.notinit_count, 1, 0)) AS agents_not_init, + COUNT(ta.id_agente) AS agents_total, + tasg.id_group AS g + FROM $agent_table ta + LEFT JOIN $agent_seconsary_table tasg + ON ta.id_agente = tasg.id_agent + $joins_alerts + WHERE ta.disabled = 0 + GROUP BY g + ) counters + RIGHT JOIN tgrupo tg + ON counters.g = tg.id_grupo + GROUP BY tg.id_grupo" + ); + logger($pa_config, "No realtime group stats updated.", 6); } diff --git a/pandora_server/lib/PandoraFMS/PluginTools.pm b/pandora_server/lib/PandoraFMS/PluginTools.pm index bf454bed07..da56b3f4ba 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.726"; -my $pandora_build = "180904"; +my $pandora_version = "7.0NG.727"; +my $pandora_build = "180918"; our $VERSION = $pandora_version." ".$pandora_build; our %EXPORT_TAGS = ( 'all' => [ qw() ] ); diff --git a/pandora_server/lib/PandoraFMS/Recon/Base.pm b/pandora_server/lib/PandoraFMS/Recon/Base.pm index e0d6ae8fe1..902a1d86d9 100644 --- a/pandora_server/lib/PandoraFMS/Recon/Base.pm +++ b/pandora_server/lib/PandoraFMS/Recon/Base.pm @@ -96,6 +96,9 @@ sub new { # Working SNMP community for each device. community_cache => {}, + # Cache of deviced discovered. + dicovered_cache => {}, + # Connections between devices. connections => {}, @@ -147,8 +150,15 @@ sub new { recon_timing_template => 3, recon_ports => '', resolve_names => 0, + snmp_auth_user => '', + snmp_auth_pass => '', + snmp_auth_method => '', snmp_checks => 2, + snmp_privacy_method => '', + snmp_privacy_pass => '', + snmp_security_level => '', snmp_timeout => 2, + snmp_version => 1, subnets => [], @_, @@ -157,8 +167,66 @@ sub new { # Perform some sanity checks. die("No subnet was specified.") unless defined($self->{'subnets'}); - # Disable SNMP scans if no community was given. - $self->{'snmp_enabled'} = 0 if (scalar(@{$self->{'communities'}}) == 0); + # Check SNMP params id SNMP is enabled + if ($self->{'snmp_enabled'}) { + # Check SNMP version + if ($self->{'snmp_version'} ne '1' && $self->{'snmp_version'} ne '2' + && $self->{'snmp_version'} ne '2c' && $self->{'snmp_version'} ne '3' + ) { + $self->{'snmp_enabled'} = 0; + $self->call('message', "SNMP version " . $self->{'snmp_version'} . " not supported (only 1, 2, 2c and 3).", 5); + } + + # Check the version 3 parameters + if ($self->{'snmp_version'} eq '3') { + # Fixed some vars + $self->{'communities'} = []; + + # SNMP v3 checks + if ( + $self->{'snmp_security_level'} ne 'noAuthNoPriv' && + $self->{'snmp_security_level'} ne 'authNoPriv' && + $self->{'snmp_security_level'} ne 'authPriv' + ) { + $self->{'snmp_enabled'} = 0; + $self->call('message', "Invalid SNMP security level " . $self->{'snmp_security_level'} . ".", 5); + } + if ($self->{'snmp_privacy_method'} ne 'DES' && $self->{'snmp_privacy_method'} ne 'AES') { + $self->{'snmp_enabled'} = 0; + $self->call('message', "Invalid SNMP privacy method " . $self->{'snmp_privacy_method'} . ".", 5); + } + if ($self->{'snmp_auth_method'} ne 'MD5' && $self->{'snmp_auth_method'} ne 'SHA') { + $self->{'snmp_enabled'} = 0; + $self->call('message', "Invalid SNMP authentication method " . $self->{'snmp_auth_method'} . ".", 5); + } + } else { + # Fixed some vars + $self->{'snmp_auth_user'} = ''; + $self->{'snmp_auth_pass'} = ''; + $self->{'snmp_auth_method'} = ''; + $self->{'snmp_privacy_method'} = ''; + $self->{'snmp_privacy_pass'} = ''; + $self->{'snmp_security_level'} = ''; + + # Disable SNMP scans if no community was given. + if (scalar(@{$self->{'communities'}}) == 0) { + $self->{'snmp_enabled'} = 0; + $self->call('message', "There is not any SNMP community configured.", 5); + + } + } + } + + # Remove all snmp related values if disabled + if (!$self->{'snmp_enabled'}) { + $self->{'communities'} = []; + $self->{'snmp_auth_user'} = ''; + $self->{'snmp_auth_pass'} = ''; + $self->{'snmp_auth_method'} = ''; + $self->{'snmp_privacy_method'} = ''; + $self->{'snmp_privacy_pass'} = ''; + $self->{'snmp_security_level'} = ''; + } return bless($self, $class); } @@ -199,7 +267,7 @@ sub aft_connectivity($$) { my ($self, $switch) = @_; my (%mac_temp, @aft_temp); - return unless defined($self->get_community($switch)); + return unless ($self->is_snmp_discovered($switch)); $self->enable_vlan_cache(); @@ -397,8 +465,7 @@ sub find_ifaces($$) { my ($self, $device) = @_; # Does it respond to SNMP? - my $community = $self->get_community($device); - return unless defined($community); + return unless ($self->is_snmp_discovered($device)); my @output = $self->snmp_get_value_array($device, $PandoraFMS::Recon::Base::IFINDEX); foreach my $if_index (@output) { @@ -476,11 +543,13 @@ sub get_device($$) { sub get_community($$) { my ($self, $device) = @_; + return '' if ($self->{'snmp_version'} eq "3"); + if (defined($self->{'community_cache'}->{$device})) { return $self->{'community_cache'}->{$device}; } - return undef; + return ''; } ######################################################################################## @@ -787,6 +856,9 @@ sub get_visited_devices($) { sub get_vlans($$) { my ($self, $device) = @_; + # Disabled in verison 3 + return () if ($self->{'snmp_version'} eq "3"); + # Is the VLAN cache disabled? return () unless ($self->{'__vlan_cache_enabled__'} == 1); @@ -945,6 +1017,17 @@ sub is_visited($$) { return 0; } +######################################################################################## +# Returns 1 if the given device has responded successfully to a snmp request +# Returns 0 otherwise. +######################################################################################## +sub is_snmp_discovered($$) { + my ($self, $device) = @_; + + # Check if device is into discovered cache + return (defined($self->{'discovered_cache'}->{$device})) ? 1 : 0; +} + ######################################################################################## # Mark the given devices as connected to each other on the given interfaces. ######################################################################################## @@ -999,23 +1082,46 @@ sub mark_visited($$) { } ######################################################################################## -# Looks for a working SNMP community for the given device. Returns 1 if one is -# found, 0 otherwise. Updates the SNMP community cache. +# Mark the given device as snmp discovered. +######################################################################################## +sub mark_discovered($$) { + my ($self, $device) = @_; + + $self->{'discovered_cache'}->{$device} = 1; +} + +######################################################################################## +# Validate the configuration for the given device. +# Returns 1 if successfull snmp contact, 0 otherwise. +# Updates the SNMP community cache on v1, v2 and v2c. ######################################################################################## sub snmp_responds($$) { my ($self, $device) = @_; - # We already have a working SNMP community for this device. - return 1 if (defined($self->get_community($device))); + return 1 if($self->is_snmp_discovered($device)); + + return ($self->{'snmp_version'} eq "3") + ? $self->snmp_responds_v3($device) + : $self->snmp_responds_v122c($device); +} + +######################################################################################## +# Looks for a working SNMP community for the given device. Returns 1 if one is +# found, 0 otherwise. Updates the SNMP community cache. +######################################################################################## +sub snmp_responds_v122c($$) { + my ($self, $device) = @_; foreach my $community (@{$self->{'communities'}}) { # Clean blanks. $community =~ s/\s+//g; - `snmpwalk -M/dev/null -r$self->{'snmp_checks'} -t$self->{'snmp_timeout'} -v1 -On -Oe -c $community $device .0 2>/dev/null`; + my $command = $self->snmp_get_command($device, ".0", $community); + `$command`; if ($? == 0) { $self->set_community($device, $community); + $self->mark_discovered($device); return 1; } } @@ -1023,6 +1129,25 @@ sub snmp_responds($$) { return 0; } + +######################################################################################## +# Validate the SNMP v3 configuration for a device. +# Returns 1 if successfull snmp contact, 0 otherwise. +######################################################################################## +sub snmp_responds_v3($$) { + my ($self, $device) = @_; + + my $command = $self->snmp_get_command($device, ".0"); + `$command`; + + if ($? == 0) { + $self->mark_discovered($device); + return 1; + } + + return 0; +} + ############################################################################## # Parse the local ARP cache. ############################################################################## @@ -1309,8 +1434,8 @@ sub snmp_get($$$) { my ($self, $device, $oid) = @_; my @output; + return () unless defined $self->is_snmp_discovered($device); my $community = $self->get_community($device); - return () unless defined ($community); # Check the SNMP query cache first. if (defined($self->{'snmp_cache'}->{"${device}_${oid}"})) { @@ -1320,13 +1445,15 @@ sub snmp_get($$$) { # Check VLANS. my @vlans = $self->get_vlans($device); if (scalar(@vlans) == 0) { - @output = `snmpwalk -M/dev/null -r$self->{'snmp_checks'} -t$self->{'snmp_timeout'} -v1 -On -Oe -c $community $device $oid 2>/dev/null`; + my $command = $self->snmp_get_command($device, $oid, $community); + @output = `$command`; } else { # Handle duplicate lines. my %output_hash; foreach my $vlan (@vlans) { - foreach my $line (`snmpwalk -M/dev/null -r$self->{'snmp_checks'} -t$self->{'snmp_timeout'} -v1 -On -Oe -c $community\@$vlan $device $oid 2>/dev/null`) { + my $command = $self->snmp_get_command($device, $oid, $community, $vlan); + foreach my $line (`$vlan`) { $output_hash{$line} = 1; } } @@ -1339,6 +1466,30 @@ sub snmp_get($$$) { return @output; } +######################################################################################## +# Get the snmpwalk command seing version 1, 2, 2c or 3. +######################################################################################## +sub snmp_get_command { + my ($self, $device, $oid, $community, $vlan) = @_; + $vlan = defined($vlan) ? "\@" . $vlan : ''; + + my $command = "snmpwalk -M/dev/null -r$self->{'snmp_checks'} -t$self->{'snmp_timeout'} -v$self->{'snmp_version'} -On -Oe "; + if ($self->{'snmp_version'} eq "3") { + $command .= " -l$self->{'snmp_security_level'} "; + if ($self->{'snmp_security_level'} ne "noAuthNoPriv") { + $command .= " -u$self->{'snmp_auth_user'} -a$self->{'snmp_auth_method'} -A$self->{'snmp_auth_pass'} "; + } + if ($self->{'snmp_security_level'} eq "authPriv") { + $command .= " -x$self->{'snmp_privacy_method'} -X$self->{'snmp_privacy_pass'} "; + } + } else { + $command .= " -c$community$vlan "; + } + + return "$command $device $oid 2>/dev/null"; + +} + ######################################################################################## # Performs an SNMP WALK and returns the value of the given OID. Returns undef # on error. diff --git a/pandora_server/lib/PandoraFMS/ReconServer.pm b/pandora_server/lib/PandoraFMS/ReconServer.pm index f0c272b3c7..13d563cd8e 100644 --- a/pandora_server/lib/PandoraFMS/ReconServer.pm +++ b/pandora_server/lib/PandoraFMS/ReconServer.pm @@ -173,7 +173,16 @@ sub data_consumer ($$) { pa_config => $pa_config, recon_ports => $task->{'recon_ports'}, resolve_names => $task->{'resolve_names'}, + snmp_auth_user => $task->{'snmp_auth_user'}, + snmp_auth_pass => $task->{'snmp_auth_pass'}, + snmp_auth_method => $task->{'snmp_auth_method'}, + snmp_checks => $task->{'snmp_checks'}, snmp_enabled => $task->{'snmp_enabled'}, + snmp_privacy_method => $task->{'snmp_privacy_method'}, + snmp_privacy_pass => $task->{'snmp_privacy_pass'}, + snmp_security_level => $task->{'snmp_security_level'}, + snmp_timeout => $task->{'snmp_timeout'}, + snmp_version => $task->{'snmp_version'}, subnets => \@subnets, task_id => $task->{'id_rt'}, vlan_cache_enabled => $task->{'vlan_enabled'}, @@ -310,10 +319,17 @@ sub PandoraFMS::Recon::Base::create_network_profile_modules($$$) { $self->call('message', "Network component ID " . $np_component->{'id_nc'} . " not found.", 5); next; } - + # Use snmp_community from network task instead the component snmp_community $component->{'snmp_community'} = safe_output($self->get_community($device)); - + $component->{'tcp_send'} = $self->{'snmp_version'}; + $component->{'custom_string_1'} = $self->{'snmp_privacy_method'}; + $component->{'custom_string_2'} = $self->{'snmp_privacy_pass'}; + $component->{'custom_string_3'} = $self->{'snmp_security_level'}; + $component->{'plugin_parameter'} = $self->{'snmp_auth_method'}; + $component->{'plugin_user'} = $self->{'snmp_auth_user'}; + $component->{'plugin_pass'} = $self->{'snmp_auth_pass'}; + pandora_create_module_from_network_component($self->{'pa_config'}, $component, $agent_id, $self->{'dbh'}); } } @@ -466,8 +482,8 @@ sub PandoraFMS::Recon::Base::create_agent($$) { } # Add interfaces to the agent if it responds to SNMP. + return $agent_id unless ($self->is_snmp_discovered($device)); my $community = $self->get_community($device); - return $agent_id unless defined($community); my @output = $self->snmp_get_value_array($device, $PandoraFMS::Recon::Base::IFINDEX); foreach my $if_index (@output) { @@ -506,7 +522,13 @@ sub PandoraFMS::Recon::Base::create_agent($$) { 'descripcion' => $if_desc, 'id_agente' => $agent_id, 'ip_target' => $device, - 'tcp_send' => 1, + 'tcp_send' => $self->{'snmp_version'}, + 'custom_string_1' => $self->{'snmp_privacy_method'}, + 'custom_string_2' => $self->{'snmp_privacy_pass'}, + 'custom_string_3' => $self->{'snmp_security_level'}, + 'plugin_parameter' => $self->{'snmp_auth_method'}, + 'plugin_user' => $self->{'snmp_auth_user'}, + 'plugin_pass' => $self->{'snmp_auth_pass'}, 'snmp_community' => $community, 'snmp_oid' => "$PandoraFMS::Recon::Base::IFOPERSTATUS.$if_index" ); @@ -516,6 +538,14 @@ sub PandoraFMS::Recon::Base::create_agent($$) { 'descripcion' => $if_desc, 'ip_target' => $device, 'snmp_community' => $community, + 'tcp_send' => $self->{'snmp_version'}, + 'custom_string_1' => $self->{'snmp_privacy_method'}, + 'custom_string_2' => $self->{'snmp_privacy_pass'}, + 'custom_string_3' => $self->{'snmp_security_level'}, + 'plugin_parameter' => $self->{'snmp_auth_method'}, + 'plugin_user' => $self->{'snmp_auth_user'}, + 'plugin_pass' => $self->{'snmp_auth_pass'}, + 'tcp_send' => $self->{'snmp_version'}, ); pandora_update_module_from_hash ($self->{'pa_config'}, \%module, 'id_agente_modulo', $module_id, $self->{'dbh'}); } @@ -531,7 +561,13 @@ sub PandoraFMS::Recon::Base::create_agent($$) { 'descripcion' => 'The total number of octets received on the interface, including framing characters. This object is a 64-bit version of ifInOctets.', 'id_agente' => $agent_id, 'ip_target' => $device, - 'tcp_send' => 1, + 'tcp_send' => $self->{'snmp_version'}, + 'custom_string_1' => $self->{'snmp_privacy_method'}, + 'custom_string_2' => $self->{'snmp_privacy_pass'}, + 'custom_string_3' => $self->{'snmp_security_level'}, + 'plugin_parameter' => $self->{'snmp_auth_method'}, + 'plugin_user' => $self->{'snmp_auth_user'}, + 'plugin_pass' => $self->{'snmp_auth_pass'}, 'snmp_community' => $community, 'snmp_oid' => "$PandoraFMS::Recon::Base::IFHCINOCTECTS.$if_index"); pandora_create_module_from_hash ($self->{'pa_config'}, \%module, $self->{'dbh'}); @@ -539,6 +575,13 @@ sub PandoraFMS::Recon::Base::create_agent($$) { my %module = ( 'ip_target' => $device, 'snmp_community' => $community, + 'tcp_send' => $self->{'snmp_version'}, + 'custom_string_1' => $self->{'snmp_privacy_method'}, + 'custom_string_2' => $self->{'snmp_privacy_pass'}, + 'custom_string_3' => $self->{'snmp_security_level'}, + 'plugin_parameter' => $self->{'snmp_auth_method'}, + 'plugin_user' => $self->{'snmp_auth_user'}, + 'plugin_pass' => $self->{'snmp_auth_pass'}, ); pandora_update_module_from_hash ($self->{'pa_config'}, \%module, 'id_agente_modulo', $module_id, $self->{'dbh'}); } @@ -553,7 +596,13 @@ sub PandoraFMS::Recon::Base::create_agent($$) { 'descripcion' => 'The total number of octets received on the interface, including framing characters.', 'id_agente' => $agent_id, 'ip_target' => $device, - 'tcp_send' => 1, + 'tcp_send' => $self->{'snmp_version'}, + 'custom_string_1' => $self->{'snmp_privacy_method'}, + 'custom_string_2' => $self->{'snmp_privacy_pass'}, + 'custom_string_3' => $self->{'snmp_security_level'}, + 'plugin_parameter' => $self->{'snmp_auth_method'}, + 'plugin_user' => $self->{'snmp_auth_user'}, + 'plugin_pass' => $self->{'snmp_auth_pass'}, 'snmp_community' => $community, 'snmp_oid' => "$PandoraFMS::Recon::Base::IFINOCTECTS.$if_index"); pandora_create_module_from_hash ($self->{'pa_config'}, \%module, $self->{'dbh'}); @@ -561,6 +610,13 @@ sub PandoraFMS::Recon::Base::create_agent($$) { my %module = ( 'ip_target' => $device, 'snmp_community' => $community, + 'tcp_send' => $self->{'snmp_version'}, + 'custom_string_1' => $self->{'snmp_privacy_method'}, + 'custom_string_2' => $self->{'snmp_privacy_pass'}, + 'custom_string_3' => $self->{'snmp_security_level'}, + 'plugin_parameter' => $self->{'snmp_auth_method'}, + 'plugin_user' => $self->{'snmp_auth_user'}, + 'plugin_pass' => $self->{'snmp_auth_pass'}, ); pandora_update_module_from_hash ($self->{'pa_config'}, \%module, 'id_agente_modulo', $module_id, $self->{'dbh'}); } @@ -577,7 +633,13 @@ sub PandoraFMS::Recon::Base::create_agent($$) { 'descripcion' => 'The total number of octets received on the interface, including framing characters. This object is a 64-bit version of ifOutOctets.', 'id_agente' => $agent_id, 'ip_target' => $device, - 'tcp_send' => 1, + 'tcp_send' => $self->{'snmp_version'}, + 'custom_string_1' => $self->{'snmp_privacy_method'}, + 'custom_string_2' => $self->{'snmp_privacy_pass'}, + 'custom_string_3' => $self->{'snmp_security_level'}, + 'plugin_parameter' => $self->{'snmp_auth_method'}, + 'plugin_user' => $self->{'snmp_auth_user'}, + 'plugin_pass' => $self->{'snmp_auth_pass'}, 'snmp_community' => $community, 'snmp_oid' => "$PandoraFMS::Recon::Base::IFHCOUTOCTECTS.$if_index"); pandora_create_module_from_hash ($self->{'pa_config'}, \%module, $self->{'dbh'}); @@ -585,6 +647,14 @@ sub PandoraFMS::Recon::Base::create_agent($$) { my %module = ( 'ip_target' => $device, 'snmp_community' => $community, + 'tcp_send' => $self->{'snmp_version'}, + 'tcp_send' => $self->{'snmp_version'}, + 'custom_string_1' => $self->{'snmp_privacy_method'}, + 'custom_string_2' => $self->{'snmp_privacy_pass'}, + 'custom_string_3' => $self->{'snmp_security_level'}, + 'plugin_parameter' => $self->{'snmp_auth_method'}, + 'plugin_user' => $self->{'snmp_auth_user'}, + 'plugin_pass' => $self->{'snmp_auth_pass'}, ); pandora_update_module_from_hash ($self->{'pa_config'}, \%module, 'id_agente_modulo', $module_id, $self->{'dbh'}); } @@ -599,7 +669,13 @@ sub PandoraFMS::Recon::Base::create_agent($$) { 'descripcion' => 'The total number of octets received on the interface, including framing characters.', 'id_agente' => $agent_id, 'ip_target' => $device, - 'tcp_send' => 1, + 'tcp_send' => $self->{'snmp_version'}, + 'custom_string_1' => $self->{'snmp_privacy_method'}, + 'custom_string_2' => $self->{'snmp_privacy_pass'}, + 'custom_string_3' => $self->{'snmp_security_level'}, + 'plugin_parameter' => $self->{'snmp_auth_method'}, + 'plugin_user' => $self->{'snmp_auth_user'}, + 'plugin_pass' => $self->{'snmp_auth_pass'}, 'snmp_community' => $community, 'snmp_oid' => "$PandoraFMS::Recon::Base::IFOUTOCTECTS.$if_index"); pandora_create_module_from_hash ($self->{'pa_config'}, \%module, $self->{'dbh'}); @@ -607,6 +683,14 @@ sub PandoraFMS::Recon::Base::create_agent($$) { my %module = ( 'ip_target' => $device, 'snmp_community' => $community, + 'tcp_send' => $self->{'snmp_version'}, + 'tcp_send' => $self->{'snmp_version'}, + 'custom_string_1' => $self->{'snmp_privacy_method'}, + 'custom_string_2' => $self->{'snmp_privacy_pass'}, + 'custom_string_3' => $self->{'snmp_security_level'}, + 'plugin_parameter' => $self->{'snmp_auth_method'}, + 'plugin_user' => $self->{'snmp_auth_user'}, + 'plugin_pass' => $self->{'snmp_auth_pass'}, ); pandora_update_module_from_hash ($self->{'pa_config'}, \%module, 'id_agente_modulo', $module_id, $self->{'dbh'}); } diff --git a/pandora_server/pandora_server.redhat.spec b/pandora_server/pandora_server.redhat.spec index e7ba2d470f..94df2173d4 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.726 -%define release 180904 +%define version 7.0NG.727 +%define release 180918 Summary: Pandora FMS Server Name: %{name} diff --git a/pandora_server/pandora_server.spec b/pandora_server/pandora_server.spec index cfab1cd536..4ab5cf468b 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.726 -%define release 180904 +%define version 7.0NG.727 +%define release 180918 Summary: Pandora FMS Server Name: %{name} diff --git a/pandora_server/pandora_server_installer b/pandora_server/pandora_server_installer index 3de83b1456..2b5a205cb4 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.726" -PI_BUILD="180904" +PI_VERSION="7.0NG.727" +PI_BUILD="180918" MODE=$1 if [ $# -gt 1 ]; then diff --git a/pandora_server/util/pandora_db.pl b/pandora_server/util/pandora_db.pl index 304bf7e3b5..216a456c25 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.726 PS180904"; +my $version = "7.0NG.727 PS180918"; # Pandora server configuration my %conf; diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index c2bea673d9..457544d958 100644 --- 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.726 PS180904"; +my $version = "7.0NG.727 PS180918"; # save program name for logging my $progname = basename($0); diff --git a/pandora_server/util/pandora_server b/pandora_server/util/pandora_server index 601946edf4..89beee8e55 100755 --- a/pandora_server/util/pandora_server +++ b/pandora_server/util/pandora_server @@ -100,7 +100,8 @@ case "$1" in echo "$PANDORA_RB_PRODUCT_NAME Server is currently running on this machine with PID ($PANDORA_PID)." rc_exit # running start on a service already running fi - + + export PERL_LWP_SSL_VERIFY_HOSTNAME=0 $PANDORA_DAEMON $PANDORA_HOME -D sleep 1