diff --git a/pandora_agents/unix/DEBIAN/control b/pandora_agents/unix/DEBIAN/control index e48d2d69b1..ad7d406839 100644 --- a/pandora_agents/unix/DEBIAN/control +++ b/pandora_agents/unix/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-agent-unix -Version: 6.1dev-151222 +Version: 6.1dev-151223 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 0b2418a610..34dddeac5b 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="6.1dev-151222" +pandora_version="6.1dev-151223" echo "Test if you has the tools for to make the packages." whereis dpkg-deb | cut -d":" -f2 | grep dpkg-deb > /dev/null diff --git a/pandora_agents/unix/pandora_agent b/pandora_agents/unix/pandora_agent index b521710c26..84b41de0bf 100644 --- a/pandora_agents/unix/pandora_agent +++ b/pandora_agents/unix/pandora_agent @@ -41,7 +41,7 @@ my $Sem = undef; my $ThreadSem = undef; use constant AGENT_VERSION => '6.1dev'; -use constant AGENT_BUILD => '151222'; +use constant AGENT_BUILD => '151223'; # Commands to retrieve total memory information in kB use constant TOTALMEMORY_CMDS => { diff --git a/pandora_agents/unix/pandora_agent.redhat.spec b/pandora_agents/unix/pandora_agent.redhat.spec index 84ae686cc2..a07a198f69 100644 --- a/pandora_agents/unix/pandora_agent.redhat.spec +++ b/pandora_agents/unix/pandora_agent.redhat.spec @@ -3,7 +3,7 @@ # %define name pandorafms_agent_unix %define version 6.1dev -%define release 151222 +%define release 151223 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 406f3ed586..c2a6b935a4 100644 --- a/pandora_agents/unix/pandora_agent.spec +++ b/pandora_agents/unix/pandora_agent.spec @@ -3,7 +3,7 @@ # %define name pandorafms_agent_unix %define version 6.1dev -%define release 151222 +%define release 151223 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 8b5ef5c281..3a6fa6187e 100644 --- a/pandora_agents/unix/pandora_agent_installer +++ b/pandora_agents/unix/pandora_agent_installer @@ -10,7 +10,7 @@ # ********************************************************************** PI_VERSION="6.1dev" -PI_BUILD="151222" +PI_BUILD="151223" 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 eceab88088..52032989e2 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-2014 Artica Soluciones Tecnologicas -# Version 6.1dev +# Version 6.1dev # 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 @@ -201,72 +201,73 @@ module_end #module_description Last update for Antivirus Signature file #module_end -# Windows inventory module (This information will be displayed only in enterprise version) +## Windows inventory module (This information will be displayed only in enterprise version) +## Please check the WMI is healthy before activate this functionality -module_begin -module_plugin cscript.exe //B //t:20 "%PROGRAMFILES%\Pandora_Agent\util\cpuinfo.vbs" -module_crontab * 12-15 * * 1 -module_end +# module_begin +# module_plugin cscript.exe //B //t:20 "%PROGRAMFILES%\Pandora_Agent\util\cpuinfo.vbs" +# module_crontab * 12-15 * * 1 +# module_end -module_begin -module_plugin cscript.exe //B //t:20 "%PROGRAMFILES%\Pandora_Agent\util\moboinfo.vbs" -module_crontab * 12-15 * * 1 -module_end +# module_begin +# module_plugin cscript.exe //B //t:20 "%PROGRAMFILES%\Pandora_Agent\util\moboinfo.vbs" +# module_crontab * 12-15 * * 1 +# module_end -module_begin -module_plugin cscript.exe //B //t:20 "%PROGRAMFILES%\Pandora_Agent\util\diskdrives.vbs" -module_crontab * 12-15 * * 1 -module_end +# module_begin +# module_plugin cscript.exe //B //t:20 "%PROGRAMFILES%\Pandora_Agent\util\diskdrives.vbs" +# module_crontab * 12-15 * * 1 +# module_end -module_begin -module_plugin cscript.exe //B //t:20 "%PROGRAMFILES%\Pandora_Agent\util\cdromdrives.vbs" -module_crontab * 12-15 * * 1 -module_end +# module_begin +# module_plugin cscript.exe //B //t:20 "%PROGRAMFILES%\Pandora_Agent\util\cdromdrives.vbs" +# module_crontab * 12-15 * * 1 +# module_end -module_begin -module_plugin cscript.exe //B //t:20 "%PROGRAMFILES%\Pandora_Agent\util\videocardinfo.vbs" -module_crontab * 12-15 * * 1 -module_end +# module_begin +# module_plugin cscript.exe //B //t:20 "%PROGRAMFILES%\Pandora_Agent\util\videocardinfo.vbs" +# module_crontab * 12-15 * * 1 +# module_end -module_begin -module_plugin cscript.exe //B //t:20 "%PROGRAMFILES%\Pandora_Agent\util\ifaces.vbs" -module_crontab * 12-15 * * 1 -module_end +# module_begin +# module_plugin cscript.exe //B //t:20 "%PROGRAMFILES%\Pandora_Agent\util\ifaces.vbs" +# module_crontab * 12-15 * * 1 +# module_end -module_begin -module_plugin cscript.exe //B //t:20 "%PROGRAMFILES%\Pandora_Agent\util\monitors.vbs" -module_crontab * 12-15 * * 1 -module_end +# module_begin +# module_plugin cscript.exe //B //t:20 "%PROGRAMFILES%\Pandora_Agent\util\monitors.vbs" +# module_crontab * 12-15 * * 1 +# module_end -module_begin -module_plugin cscript.exe //B //t:20 "%PROGRAMFILES%\Pandora_Agent\util\printers.vbs" -module_crontab * 12-15 * * 1 -module_end +# module_begin +# module_plugin cscript.exe //B //t:20 "%PROGRAMFILES%\Pandora_Agent\util\printers.vbs" +# module_crontab * 12-15 * * 1 +# module_end -module_begin -module_plugin cscript.exe //B //t:20 "%PROGRAMFILES%\Pandora_Agent\util\raminfo.vbs" -module_crontab * 12-15 * * 1 -module_end +# module_begin +# module_plugin cscript.exe //B //t:20 "%PROGRAMFILES%\Pandora_Agent\util\raminfo.vbs" +# module_crontab * 12-15 * * 1 +# module_end -module_begin -module_plugin cscript.exe //B //t:20 "%PROGRAMFILES%\Pandora_Agent\util\software_installed.vbs" -module_crontab * 12-15 * * 1 -module_end +# module_begin +# module_plugin cscript.exe //B //t:20 "%PROGRAMFILES%\Pandora_Agent\util\software_installed.vbs" +# module_crontab * 12-15 * * 1 +# module_end -module_begin -module_plugin cscript.exe //B //t:20 "%PROGRAMFILES%\Pandora_Agent\util\userslogged.vbs" -module_crontab * 12-15 * * 1 -module_end +# module_begin +# module_plugin cscript.exe //B //t:20 "%PROGRAMFILES%\Pandora_Agent\util\userslogged.vbs" +# module_crontab * 12-15 * * 1 +# module_end -module_begin -module_plugin cscript.exe //B //t:20 "%PROGRAMFILES%\Pandora_Agent\util\productkey.vbs" -module_crontab * 12-15 * * 1 -module_end +# module_begin +# module_plugin cscript.exe //B //t:20 "%PROGRAMFILES%\Pandora_Agent\util\productkey.vbs" +# module_crontab * 12-15 * * 1 +# module_end -module_begin -module_plugin cscript.exe //B //t:20 "%PROGRAMFILES%\Pandora_Agent\util\productID.vbs" -module_crontab * 12-15 * * 1 -module_end +# module_begin +# module_plugin cscript.exe //B //t:20 "%PROGRAMFILES%\Pandora_Agent\util\productID.vbs" +# module_crontab * 12-15 * * 1 +# module_end ## Plugin example for custom fields (version, architecture, IP, IPv6, MAC) # module_begin diff --git a/pandora_agents/win32/installer/pandora.mpi b/pandora_agents/win32/installer/pandora.mpi index e4228c7ab1..ee01ebd98e 100644 --- a/pandora_agents/win32/installer/pandora.mpi +++ b/pandora_agents/win32/installer/pandora.mpi @@ -186,7 +186,7 @@ UpgradeApplicationID {} Version -{151222} +{151223} ViewReadme {Yes} diff --git a/pandora_agents/win32/pandora.cc b/pandora_agents/win32/pandora.cc index 4aa0c46291..fa4d63ff0e 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 ("6.1dev(Build 151222)") +#define PANDORA_VERSION ("6.1dev(Build 151223)") string pandora_path; string pandora_dir; diff --git a/pandora_agents/win32/versioninfo.rc b/pandora_agents/win32/versioninfo.rc index 7560c90307..52029b2b07 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", "(6.1dev(Build 151222))" + VALUE "ProductVersion", "(6.1dev(Build 151223))" VALUE "FileVersion", "1.0.0.0" END END diff --git a/pandora_console/DEBIAN/control b/pandora_console/DEBIAN/control index 81bf3d0412..9aa415eb08 100644 --- a/pandora_console/DEBIAN/control +++ b/pandora_console/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-console -Version: 6.1dev-151222 +Version: 6.1dev-151223 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 4674ae4ac7..d73dcfc00c 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="6.1dev-151222" +pandora_version="6.1dev-151223" package_pear=0 package_pandora=1 diff --git a/pandora_console/godmode/groups/group_list.php b/pandora_console/godmode/groups/group_list.php index caee73a739..866bdd3c39 100644 --- a/pandora_console/godmode/groups/group_list.php +++ b/pandora_console/godmode/groups/group_list.php @@ -72,6 +72,9 @@ if (is_ajax ()) { $privilege = (string) get_parameter ('privilege', ''); // Is is possible add keys prefix to avoid auto sorting in js object conversion $keys_prefix = (string) get_parameter ('keys_prefix', ''); + // This attr is for the operation "bulk alert accions add", it controls the query that take the agents + // from db + $add_alert_bulk_op = get_parameter ('add_alert_bulk_op', false); // Ids of agents to be include in the SQL clause as id_agent IN () $filter_agents_json = (string) get_parameter ('filter_agents_json', ''); $status_agents = (int)get_parameter('status_agents', AGENT_STATUS_ALL); @@ -113,10 +116,10 @@ if (is_ajax ()) { } if ( $id_group == 0 && $privilege != '') { + $groups = users_get_groups ($config["id_user"], $privilege, false); // if group ID doesn't matter and $privilege is specified (like 'AW'), // retruns all agents that current user has $privilege privilege for. - $agents = agents_get_group_agents( - array_keys (users_get_groups ($config["id_user"], $privilege, false)),$filter,"none",false,$recursion); + $agents = agents_get_group_agents(array_keys($groups), $filter, "none", false, $recursion, false, '|', $add_alert_bulk_op); } else { $agents = agents_get_group_agents($id_group, $filter, "none", diff --git a/pandora_console/godmode/massive/massive_add_action_alerts.php b/pandora_console/godmode/massive/massive_add_action_alerts.php index 49592797bb..3900e80fec 100755 --- a/pandora_console/godmode/massive/massive_add_action_alerts.php +++ b/pandora_console/godmode/massive/massive_add_action_alerts.php @@ -220,6 +220,7 @@ $(document).ready (function () { $("#id_group").pandoraSelectGroupAgent ({ agentSelect: "select#id_agents", privilege: "AW", + add_alert_bulk_op: true, recursion: function() {return recursion}, filter_agents_json: filter_agents_json, callbackPost: function () { diff --git a/pandora_console/include/config_process.php b/pandora_console/include/config_process.php index 4eb9a9ce61..4ce3cbbba2 100644 --- a/pandora_console/include/config_process.php +++ b/pandora_console/include/config_process.php @@ -22,7 +22,7 @@ /** * Pandora build version and version */ -$build_version = 'PC151222'; +$build_version = 'PC151223'; $pandora_version = 'v6.1dev'; // Do not overwrite default timezone set if defined. diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index 25a85cdede..08bc9afac9 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -805,8 +805,8 @@ function agents_common_modules ($id_agent, $filter = false, $indexed = true, $ge * @return array An array with all agents in the group or an empty array */ function agents_get_group_agents ($id_group = 0, $search = false, - $case = "lower", $noACL = false, $childGroups = false, $serialized = false, $separator = '|') { - + $case = "lower", $noACL = false, $childGroups = false, $serialized = false, $separator = '|', $add_alert_bulk_op = false) { + global $config; $filter = array(); @@ -901,7 +901,12 @@ function agents_get_group_agents ($id_group = 0, $search = false, } unset($search['status']); } - + if ($add_alert_bulk_op) { + if (isset($search['id_agente'])) { + $filter['id_agente'] = $search['id_agente']; + } + } + if (is_metaconsole() && isset($search['id_server'])) { $filter['id_tmetaconsole_setup'] = $search['id_server']; @@ -912,10 +917,11 @@ function agents_get_group_agents ($id_group = 0, $search = false, unset ($search["id_server"]); } - - // Add the rest of the filter from the search array - foreach ($search as $key => $value) { - $filter[] = $value; + if (!$add_alert_bulk_op) { + // Add the rest of the filter from the search array + foreach ($search as $key => $value) { + $filter[] = $value; + } } } else { diff --git a/pandora_console/include/functions_groupview.php b/pandora_console/include/functions_groupview.php new file mode 100644 index 0000000000..173557fe97 --- /dev/null +++ b/pandora_console/include/functions_groupview.php @@ -0,0 +1,1117 @@ + $tags) { + if ($user_strict) { //Remove groups with tags + $groups_without_tags[$group] = $group; + } + } + + if ($user_strict) { + $user_groups_ids = implode(',', array_keys($groups_without_tags)); + } + else { + $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 = array(); + $list['_monitors_critical_'] = 0; + $list['_monitors_warning_'] = 0; + $list['_monitors_unknown_'] = 0; + $list['_monitors_not_init_'] = 0; + $list['_monitors_ok_'] = 0; + if ($list_groups == false) { + $list_groups = array(); + } + + /* + * Agent cache for metaconsole. + * Retrieve the statistic data from the cache table. + */ + if (!$user_strict && 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"; + + $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"; + $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"; + $data_stats_not_init = db_get_all_rows_sql($sql_stats_not_init); + + $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']; + $stats['monitors_ok'] = (int) $value['monitors_ok']; + $stats['monitors_warning'] = (int) $value['monitors_warning']; + $stats['monitors_critical'] = (int) $value['monitors_critical']; + $stats['monitors_unknown'] = (int) $value['monitors_unknown']; + $stats['monitors_not_init'] = (int) $value['monitors_not_init']; + $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) { + $group_id = (int) $value['id_grupo']; + if (isset($stats_by_group[$group_id])) { + $stats_by_group[$group_id]['agents_unknown'] = (int) $value['agents_unknown']; + } + } + } + if (!empty($data_stats_not_init)) { + foreach ($data_stats_not_init as $value) { + $group_id = (int) $value['id_grupo']; + if (isset($stats_by_group[$group_id])) { + $stats_by_group[$group_id]['agents_not_init'] = (int) $value['agents_not_init']; + } + } + } + if (!empty($data_stats_ok)) { + foreach ($data_stats_ok as $value) { + $group_id = (int) $value['id_grupo']; + if (isset($stats_by_group[$group_id])) { + $stats_by_group[$group_id]['agents_ok'] = (int) $value['agents_ok']; + } + } + } + if (!empty($data_stats_warning)) { + foreach ($data_stats_warning as $value) { + $group_id = (int) $value['id_grupo']; + if (isset($stats_by_group[$group_id])) { + $stats_by_group[$group_id]['agents_warning'] = (int) $value['agents_warning']; + } + } + } + if (!empty($data_stats_critical)) { + foreach ($data_stats_critical as $value) { + $group_id = (int) $value['id_grupo']; + if (isset($stats_by_group[$group_id])) { + $stats_by_group[$group_id]['agents_critical'] = (int) $value['agents_critical']; + } + } + } + } + } + } + + if (!$user_strict && is_metaconsole()) { // Agent cache + $group_stat = array(); + foreach ($list_groups as $value) { + $id = (int) $value['id_grupo']; + if (isset($stats_by_group[$id])) + $group_stat = $stats_by_group[$id]; + + $list['_agents_unknown_'] += isset($group_stat['agents_unknown']) ? $group_stat['agents_unknown'] : 0; + $list['_monitors_alerts_fired_'] += isset($group_stat['alerts_fired']) ? $group_stat['alerts_fired'] : 0; + $list['_total_agents_'] += isset($group_stat['agents_total']) ? $group_stat['agents_total'] : 0; + + // This fields are not in database + $list['_monitors_ok_'] = isset($group_stat['monitors_ok']) ? $group_stat['monitors_ok'] : 0; + $list['_monitors_critical_'] += isset($group_stat['monitors_critical']) ? $group_stat['monitors_critical'] : 0; + $list['_monitors_warning_'] += isset($group_stat['monitors_warning']) ? $group_stat['monitors_warning'] : 0; + $list['_monitors_unknown_'] += isset($group_stat['monitors_unknown']) ? $group_stat['monitors_unknown'] : 0; + $list['_monitors_not_init_'] += isset($group_stat['monitors_not_init']) ? $group_stat['monitors_not_init'] : 0; + $list['_agents_not_init_'] += isset($group_stat['agents_not_init']) ? $group_stat['agents_not_init'] : 0; + + $list['_agents_ok_'] = isset($group_stat['agents_ok']) ? $group_stat['agents_ok'] : 0; + $list['_agents_warning_'] += isset($group_stat['agents_warning']) ? $group_stat['agents_warning'] : 0; + $list['_agents_critical_'] += isset($group_stat['agents_critical']) ? $group_stat['agents_critical'] : 0; + $list['_monitors_alerts_'] += isset($group_stat['alerts']) ? $group_stat['alerts'] : 0;; + + $list["_monitor_alerts_fire_count_"] = $group_stat["alerts_fired"]; + $list["_total_checks_"] += $group_stat["modules"]; + $list["_total_alerts_"] += $group_stat["alerts"]; + } + // 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[$i]["_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[$i]["_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 if (($config["realtimestats"] == 0) && !$user_strict) { + + $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'), 'AR',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 { + if ($user_strict) { + $_tag_condition = 'AND ' . tags_get_acl_tags_module_condition($acltags,'tae'); + } + else + $_tag_condition = ''; + + $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 IN ( $user_groups_ids ) + INNER JOIN tagente_modulo tam + ON tae.id_agente_modulo = tam.id_agente_modulo + AND tam.disabled = 0 + $_tag_condition + GROUP BY estado"); + + foreach ($result_list as $result) { + switch ($result['estado']) { + case AGENT_MODULE_STATUS_CRITICAL_ALERT: + break; + case AGENT_MODULE_STATUS_CRITICAL_BAD: + $list['_monitors_critical_'] += (int)$result['contado']; + break; + case AGENT_MODULE_STATUS_WARNING_ALERT: + break; + case AGENT_MODULE_STATUS_WARNING: + $list['_monitors_warning_'] += (int)$result['contado']; + break; + case AGENT_MODULE_STATUS_UNKNOWN: + $list['_monitors_unknown_'] += (int)$result['contado']; + break; + case AGENT_MODULE_STATUS_NO_DATA: + case AGENT_MODULE_STATUS_NOT_INIT: + $list['_monitors_not_init_'] += (int)$result['contado']; + break; + case AGENT_MODULE_STATUS_NORMAL_ALERT: + break; + case AGENT_MODULE_STATUS_NORMAL: + $list['_monitors_ok_'] += (int)$result['contado']; + break; + } + } + + $list['_monitors_alerts_fired_'] = groupview_monitor_fired_alerts (explode(',',$user_groups_ids), $user_strict,explode(',',$user_groups_ids)); + $list['_monitors_alerts_'] = groupview_monitor_alerts (explode(',',$user_groups_ids), $user_strict,explode(',',$user_groups_ids)); + + $total_agentes = agents_get_agents (false, array('count(*) as total_agents'), 'AR',false, false); + $list['_total_agents_'] = $total_agentes[0]['total_agents']; + + $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_"]; + } + + return $list; +} + +function groupview_status_modules_agents($id_user = false, $user_strict = false, $access = 'AR', $force_group_and_tag = true) { + global $config; + + if ($id_user == false) { + $id_user = $config['id_user']; + } + + $acltags = tags_get_user_module_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) { + + $server_list = groupview_get_all_data($id_user, $user_strict, + $acltags); + + 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_']; + + $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_"]; + } + } + } + + return $result_list; + } + else { + + $result_list = groupview_get_all_data ($id_user, $user_strict, + $acltags); + 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 . ")"; + $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 . ")"; + + + if ($strict_user) { + $group_clause_strict = implode (",", $id_group_strict); + $group_clause_strict = "(" . $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 + AND times_fired > 0 "; + + $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 + 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 = tags_get_user_module_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 = groupview_get_data ($id_user, $user_strict, + $acltags, $returnAllGroup); + + 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_']; + } + } + metaconsole_restore_db(); + + } + + return $result_list; + } + // If using metaconsole, the not strict users will use the metaconsole's agent cache table + else { + $result_list = groupview_get_data ($id_user, $user_strict, $acltags, + $returnAllGroup); + + return $result_list; + } +} + +function groupview_get_data ($id_user = false, $user_strict = false, $acltags, $returnAllGroup = false, $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); + } + } + } + + $user_groups_ids = '0,'; + + if ($user_strict) { + $user_groups_ids .= implode(',', array_keys($groups_without_tags)); + } + else { + $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 . ") + AND id_grupo IN (SELECT id_grupo FROM tagente) + 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) + 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) + ORDER BY nombre ASC"); + break; + } + } + //html_debug_print($list_groups); + //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'=>''); + array_unshift($list_groups, $group_all); + //html_debug_print($list_groups); + //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); + //Takes the parents even without agents, complete groups + $list_father_groups = db_get_all_rows_sql(" + SELECT * + FROM tgrupo + WHERE id_grupo IN (" . $fathers_id . ") + ORDER BY nombre COLLATE utf8_general_ci ASC"); + //html_debug_print($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); + //html_debug_print($ordered_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']]['_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; + } + + if ($list_groups == false) { + $list_groups = array(); + } + + /* + * Agent cache for metaconsole. + * Retrieve the statistic data from the cache table. + */ + if (!$user_strict && 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"; + + $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"; + $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"; + $data_stats_not_init = db_get_all_rows_sql($sql_stats_not_init); + + $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']; + $stats['monitors_ok'] = (int) $value['monitors_ok']; + $stats['monitors_warning'] = (int) $value['monitors_warning']; + $stats['monitors_critical'] = (int) $value['monitors_critical']; + $stats['monitors_unknown'] = (int) $value['monitors_unknown']; + $stats['monitors_not_init'] = (int) $value['monitors_not_init']; + $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) { + $group_id = (int) $value['id_grupo']; + if (isset($stats_by_group[$group_id])) { + $stats_by_group[$group_id]['agents_unknown'] = (int) $value['agents_unknown']; + } + } + } + if (!empty($data_stats_not_init)) { + foreach ($data_stats_not_init as $value) { + $group_id = (int) $value['id_grupo']; + if (isset($stats_by_group[$group_id])) { + $stats_by_group[$group_id]['agents_not_init'] = (int) $value['agents_not_init']; + } + } + } + if (!empty($data_stats_ok)) { + foreach ($data_stats_ok as $value) { + $group_id = (int) $value['id_grupo']; + if (isset($stats_by_group[$group_id])) { + $stats_by_group[$group_id]['agents_ok'] = (int) $value['agents_ok']; + } + } + } + if (!empty($data_stats_warning)) { + foreach ($data_stats_warning as $value) { + $group_id = (int) $value['id_grupo']; + if (isset($stats_by_group[$group_id])) { + $stats_by_group[$group_id]['agents_warning'] = (int) $value['agents_warning']; + } + } + } + if (!empty($data_stats_critical)) { + foreach ($data_stats_critical as $value) { + $group_id = (int) $value['id_grupo']; + if (isset($stats_by_group[$group_id])) { + $stats_by_group[$group_id]['agents_critical'] = (int) $value['agents_critical']; + } + } + } + } + } + } + + if (!$user_strict && is_metaconsole()) { // Agent cache + $group_stat = array(); + foreach ($list_groups as $value) { + $id = (int) $value['id_grupo']; + if (isset($stats_by_group[$id])) + $group_stat = $stats_by_group[$id]; + + $list['_agents_unknown_'] += isset($group_stat['agents_unknown']) ? $group_stat['agents_unknown'] : 0; + $list['_monitors_alerts_fired_'] += isset($group_stat['alerts_fired']) ? $group_stat['alerts_fired'] : 0; + $list['_total_agents_'] += isset($group_stat['agents_total']) ? $group_stat['agents_total'] : 0; + + // This fields are not in database + $list['_monitors_ok_'] = isset($group_stat['monitors_ok']) ? $group_stat['monitors_ok'] : 0; + $list['_monitors_critical_'] += isset($group_stat['monitors_critical']) ? $group_stat['monitors_critical'] : 0; + $list['_monitors_warning_'] += isset($group_stat['monitors_warning']) ? $group_stat['monitors_warning'] : 0; + $list['_monitors_unknown_'] += isset($group_stat['monitors_unknown']) ? $group_stat['monitors_unknown'] : 0; + $list['_monitors_not_init_'] += isset($group_stat['monitors_not_init']) ? $group_stat['monitors_not_init'] : 0; + $list['_agents_not_init_'] += isset($group_stat['agents_not_init']) ? $group_stat['agents_not_init'] : 0; + + $list['_agents_ok_'] = isset($group_stat['agents_ok']) ? $group_stat['agents_ok'] : 0; + $list['_agents_warning_'] += isset($group_stat['agents_warning']) ? $group_stat['agents_warning'] : 0; + $list['_agents_critical_'] += isset($group_stat['agents_critical']) ? $group_stat['agents_critical'] : 0; + $list['_monitors_alerts_'] += isset($group_stat['alerts']) ? $group_stat['alerts'] : 0;; + + $list["_monitor_alerts_fire_count_"] = $group_stat["alerts_fired"]; + $list["_total_checks_"] += $group_stat["modules"]; + $list["_total_alerts_"] += $group_stat["alerts"]; + } + // 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[$i]["_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[$i]["_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 if (($config["realtimestats"] == 0) && !$user_strict) { + + $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'), 'AR',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 { + if ($user_strict) { + $_tag_condition = 'AND ' . tags_get_acl_tags_module_condition($acltags,'tae'); + } + else{ + $_tag_condition = ''; + } + 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 tagente WHERE id_grupo = " . $group['id_grupo'] . $_tag_condition . " 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["_monitor_checks_"] - $list["_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 tagente + WHERE id_grupo = " . $group['id_grupo'] ); + foreach ($agents as $agent) { + $total_monitors_init = $agent['warning_count'] + $agent['critical_count'] + $agent['normal_count']; + if ($total_monitors_init == $agent['notinit_count']) { + $list[$group['id_grupo']]['_agents_not_init_'] += 1; + } + if (($agent['critical_count'] == 0) && ($agent['warning_count'] == 0) && ($group_agents['disabled'] == 0)) { + if ($agent['unknown_count'] > 0) { + $list[$group['id_grupo']]['_agents_unknown_'] += 1; + } + } + } + } + } + + } + + 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 ($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 (! 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; +} + +//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) { + 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){ + foreach ($groups as $group) { + 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']; + } + } + return $ordered_ids; +} + +//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; +} + +?> diff --git a/pandora_console/include/javascript/jquery.pandora.controls.js b/pandora_console/include/javascript/jquery.pandora.controls.js index 9ef224e4e7..ac14b5488e 100644 --- a/pandora_console/include/javascript/jquery.pandora.controls.js +++ b/pandora_console/include/javascript/jquery.pandora.controls.js @@ -44,6 +44,7 @@ "filter_agents_json" : config.filter_agents_json, "disabled" : config.disabled ? 1 : 0, "status_agents" : config.status_agents, + "add_alert_bulk_op" : config.add_alert_bulk_op, "privilege" : config.privilege, // Add a key prefix to avoid auto sorting in js object conversion "keys_prefix" : "_" diff --git a/pandora_console/install.php b/pandora_console/install.php index cb8c171094..c166ae1734 100644 --- a/pandora_console/install.php +++ b/pandora_console/install.php @@ -63,7 +63,7 @@