diff --git a/pandora_console/images/widgets/heatmap.png b/pandora_console/images/widgets/heatmap.png new file mode 100644 index 0000000000..f16f8eb992 Binary files /dev/null and b/pandora_console/images/widgets/heatmap.png differ diff --git a/pandora_console/include/ajax/heatmap.ajax.php b/pandora_console/include/ajax/heatmap.ajax.php index abfcd39e45..dd22fcdfef 100644 --- a/pandora_console/include/ajax/heatmap.ajax.php +++ b/pandora_console/include/ajax/heatmap.ajax.php @@ -26,6 +26,8 @@ * ============================================================================ */ +use PandoraFMS\Enterprise\Metaconsole\Node; + if (is_ajax() === true) { global $config; @@ -216,6 +218,12 @@ if (is_ajax() === true) { if ($getInfo === true) { enterprise_include_once('include/functions_agents.php'); $id = get_parameter('id', 0); + $id_server = get_parameter('id_server', 0); + if (empty($id_server) === false) { + $nd = new Node($id_server); + $nd->connect(); + } + switch ($type) { case 3: case 2: @@ -375,6 +383,10 @@ if (is_ajax() === true) { } break; } + + if (empty($id_server) === false) { + $nd->disconnect(); + } } return; diff --git a/pandora_console/include/class/Heatmap.class.php b/pandora_console/include/class/Heatmap.class.php index 8572d6cad1..de3ef90ba3 100644 --- a/pandora_console/include/class/Heatmap.class.php +++ b/pandora_console/include/class/Heatmap.class.php @@ -1,4 +1,5 @@ type = $type; $this->filter = $filter; @@ -126,6 +141,7 @@ class Heatmap $this->height = $height; $this->search = $search; $this->group = $group; + $this->dashboard = $dashboard; } @@ -148,107 +164,125 @@ class Heatmap false ), 'data' => [ - 'page' => 'operation/heatmap', - 'method' => 'showHeatmap', - 'randomId' => $this->randomId, - 'type' => $this->type, - 'filter' => $this->filter, - 'refresh' => $this->refresh, - 'search' => $this->search, - 'group' => $this->group, + 'page' => 'operation/heatmap', + 'method' => 'showHeatmap', + 'randomId' => $this->randomId, + 'type' => $this->type, + 'filter' => $this->filter, + 'refresh' => $this->refresh, + 'search' => $this->search, + 'group' => $this->group, + 'dashboard' => (int) $this->dashboard, ], ]; - echo '
'; + $style_dashboard = ''; + if ($this->dashboard === true) { + $style_dashboard = 'min-height: 0px'; + } + + echo '
'; ?> - + } + }); + } + }); + '; } @@ -336,6 +370,8 @@ class Heatmap */ protected function getAllAgents() { + global $config; + $filter['disabled'] = 0; $alias = ''; @@ -343,8 +379,16 @@ class Heatmap $alias = ' AND alias LIKE "%'.$this->search.'%"'; } + $id_user_groups = ''; + if (users_is_admin() === false) { + $user_groups = array_keys(users_get_groups($config['user'], 'AR', false)); + if (empty($user_groups) === false) { + $id_user_groups = ' AND id_grupo IN ('.implode(',', $user_groups).')'; + } + } + $id_grupo = ''; - if (empty($this->filter) === false && current($this->filter) != 0) { + if (empty($this->filter) === false && empty(current($this->filter)) === false) { $id_grupo = ' AND id_grupo IN ('.implode(',', $this->filter).')'; } @@ -354,56 +398,121 @@ class Heatmap unknown_count,notinit_count,total_count,fired_count, (SELECT last_status_change FROM tagente_estado WHERE id_agente = tagente.id_agente ORDER BY last_status_change DESC LIMIT 1) AS last_status_change - FROM tagente WHERE `disabled` = 0 %s %s ORDER BY id_grupo,id_agente ASC', + FROM tagente WHERE `disabled` = 0 %s %s %s ORDER BY id_grupo,id_agente ASC', $alias, + $id_user_groups, $id_grupo ); - $result = db_get_all_rows_sql($sql); - $agents = []; - // Agent status. - foreach ($result as $key => $agent) { - if ($agent['total_count'] === 0 || $agent['total_count'] === $agent['notinit_count']) { - $status = 'notinit'; - } else if ($agent['critical_count'] > 0) { - $status = 'critical'; - } else if ($agent['warning_count'] > 0) { - $status = 'warning'; - } else if ($agent['unknown_count'] > 0) { - $status = 'unknown'; - } else { - $status = 'normal'; - } + if (is_metaconsole() === true) { + $nodes = metaconsole_get_connections(); + $cont = 0; + foreach ($nodes as $node) { + try { + $nd = new Node($node['id']); + $nd->connect(); - if ($agent['last_status_change'] != 0) { - $seconds = (time() - $agent['last_status_change']); + $result = db_get_all_rows_sql($sql); + // Agent status. + foreach ($result as $agent) { + if ($agent['total_count'] === 0 || $agent['total_count'] === $agent['notinit_count']) { + $status = 'notinit'; + } else if ($agent['critical_count'] > 0) { + $status = 'critical'; + } else if ($agent['warning_count'] > 0) { + $status = 'warning'; + } else if ($agent['unknown_count'] > 0) { + $status = 'unknown'; + } else { + $status = 'normal'; + } - if ($seconds >= SECONDS_1DAY) { - $status .= '_10'; - } else if ($seconds >= 77760) { - $status .= '_9'; - } else if ($seconds >= 69120) { - $status .= '_8'; - } else if ($seconds >= 60480) { - $status .= '_7'; - } else if ($seconds >= 51840) { - $status .= '_6'; - } else if ($seconds >= 43200) { - $status .= '_5'; - } else if ($seconds >= 34560) { - $status .= '_4'; - } else if ($seconds >= 25920) { - $status .= '_3'; - } else if ($seconds >= 17280) { - $status .= '_2'; - } else if ($seconds >= 8640) { - $status .= '_1'; + if ($agent['last_status_change'] != 0) { + $seconds = (time() - $agent['last_status_change']); + + if ($seconds >= SECONDS_1DAY) { + $status .= '_10'; + } else if ($seconds >= 77760) { + $status .= '_9'; + } else if ($seconds >= 69120) { + $status .= '_8'; + } else if ($seconds >= 60480) { + $status .= '_7'; + } else if ($seconds >= 51840) { + $status .= '_6'; + } else if ($seconds >= 43200) { + $status .= '_5'; + } else if ($seconds >= 34560) { + $status .= '_4'; + } else if ($seconds >= 25920) { + $status .= '_3'; + } else if ($seconds >= 17280) { + $status .= '_2'; + } else if ($seconds >= 8640) { + $status .= '_1'; + } + } + + $agents[$cont] = $agent; + $agents[$cont]['status'] = $status; + $agents[$cont]['server'] = $node['id']; + + ++$cont; + } + } catch (\Exception $e) { + $nd->disconnect(); + $agents = []; + } finally { + $nd->disconnect(); } } + } else { + $result = db_get_all_rows_sql($sql); - $agents[$key] = $agent; - $agents[$key]['status'] = $status; + // Agent status. + foreach ($result as $key => $agent) { + if ($agent['total_count'] === 0 || $agent['total_count'] === $agent['notinit_count']) { + $status = 'notinit'; + } else if ($agent['critical_count'] > 0) { + $status = 'critical'; + } else if ($agent['warning_count'] > 0) { + $status = 'warning'; + } else if ($agent['unknown_count'] > 0) { + $status = 'unknown'; + } else { + $status = 'normal'; + } + + if ($agent['last_status_change'] != 0) { + $seconds = (time() - $agent['last_status_change']); + + if ($seconds >= SECONDS_1DAY) { + $status .= '_10'; + } else if ($seconds >= 77760) { + $status .= '_9'; + } else if ($seconds >= 69120) { + $status .= '_8'; + } else if ($seconds >= 60480) { + $status .= '_7'; + } else if ($seconds >= 51840) { + $status .= '_6'; + } else if ($seconds >= 43200) { + $status .= '_5'; + } else if ($seconds >= 34560) { + $status .= '_4'; + } else if ($seconds >= 25920) { + $status .= '_3'; + } else if ($seconds >= 17280) { + $status .= '_2'; + } else if ($seconds >= 8640) { + $status .= '_1'; + } + } + + $agents[$key] = $agent; + $agents[$key]['status'] = $status; + } } return $agents; @@ -417,6 +526,8 @@ class Heatmap */ protected function getAllModulesByGroup() { + global $config; + $filter_group = ''; if (empty($this->filter) === false && current($this->filter) != -1) { $filter_group = 'AND am.id_module_group IN ('.implode(',', $this->filter).')'; @@ -427,81 +538,181 @@ class Heatmap $filter_name = 'AND nombre LIKE "%'.$this->search.'%"'; } + $id_user_groups = ''; + if (users_is_admin() === false) { + $user_groups = array_keys(users_get_groups($config['user'], 'AR', false)); + if (empty($user_groups) === false) { + $id_user_groups = sprintf( + 'INNER JOIN tagente a ON a.id_agente = ae.id_agente + AND a.id_grupo IN (%s)', + implode(',', $user_groups) + ); + } + } + // All modules. $sql = sprintf( 'SELECT am.id_agente_modulo AS id, ae.estado AS `status`, am.id_module_group AS id_grupo, ae.last_status_change FROM tagente_modulo am INNER JOIN tagente_estado ae ON am.id_agente_modulo = ae.id_agente_modulo + %s WHERE am.disabled = 0 %s %s GROUP BY am.id_module_group, am.id_agente_modulo', + $id_user_groups, $filter_group, $filter_name ); - $result = db_get_all_rows_sql($sql); + if (is_metaconsole() === true) { + $nodes = metaconsole_get_connections(); + $cont = 0; + $result = []; + foreach ($nodes as $node) { + try { + $nd = new Node($node['id']); + $nd->connect(); - // Module status. - foreach ($result as $key => $module) { - $status = ''; - switch ($module['status']) { - case AGENT_MODULE_STATUS_CRITICAL_BAD: - case AGENT_MODULE_STATUS_CRITICAL_ALERT: - case 1: - case 100: - $status = 'critical'; - break; + $modules = db_get_all_rows_sql($sql); - case AGENT_MODULE_STATUS_NORMAL: - case AGENT_MODULE_STATUS_NORMAL_ALERT: - case 0: - case 300: - $status = 'normal'; - break; + // Module status. + foreach ($modules as $key => $module) { + $status = ''; + switch ($module['status']) { + case AGENT_MODULE_STATUS_CRITICAL_BAD: + case AGENT_MODULE_STATUS_CRITICAL_ALERT: + case 1: + case 100: + $status = 'critical'; + break; - case AGENT_MODULE_STATUS_WARNING: - case AGENT_MODULE_STATUS_WARNING_ALERT: - case 2: - case 200: - $status = 'warning'; - break; + case AGENT_MODULE_STATUS_NORMAL: + case AGENT_MODULE_STATUS_NORMAL_ALERT: + case 0: + case 300: + $status = 'normal'; + break; - default: - case AGENT_MODULE_STATUS_UNKNOWN: - case 3: - $status = 'unknown'; - break; - case AGENT_MODULE_STATUS_NOT_INIT: - case 5: - $status = 'notinit'; - break; - } + case AGENT_MODULE_STATUS_WARNING: + case AGENT_MODULE_STATUS_WARNING_ALERT: + case 2: + case 200: + $status = 'warning'; + break; - if ($module['last_status_change'] != 0) { - $seconds = (time() - $module['last_status_change']); + default: + case AGENT_MODULE_STATUS_UNKNOWN: + case 3: + $status = 'unknown'; + break; + case AGENT_MODULE_STATUS_NOT_INIT: + case 5: + $status = 'notinit'; + break; + } - if ($seconds >= SECONDS_1DAY) { - $status .= '_10'; - } else if ($seconds >= 77760) { - $status .= '_9'; - } else if ($seconds >= 69120) { - $status .= '_8'; - } else if ($seconds >= 60480) { - $status .= '_7'; - } else if ($seconds >= 51840) { - $status .= '_6'; - } else if ($seconds >= 43200) { - $status .= '_5'; - } else if ($seconds >= 34560) { - $status .= '_4'; - } else if ($seconds >= 25920) { - $status .= '_3'; - } else if ($seconds >= 17280) { - $status .= '_2'; - } else if ($seconds >= 8640) { - $status .= '_1'; + if ($module['last_status_change'] != 0) { + $seconds = (time() - $module['last_status_change']); + + if ($seconds >= SECONDS_1DAY) { + $status .= '_10'; + } else if ($seconds >= 77760) { + $status .= '_9'; + } else if ($seconds >= 69120) { + $status .= '_8'; + } else if ($seconds >= 60480) { + $status .= '_7'; + } else if ($seconds >= 51840) { + $status .= '_6'; + } else if ($seconds >= 43200) { + $status .= '_5'; + } else if ($seconds >= 34560) { + $status .= '_4'; + } else if ($seconds >= 25920) { + $status .= '_3'; + } else if ($seconds >= 17280) { + $status .= '_2'; + } else if ($seconds >= 8640) { + $status .= '_1'; + } + } + + $result[$cont] = $module; + $result[$cont]['status'] = $status; + $result[$cont]['server'] = $node['id']; + ++$cont; + } + } catch (\Exception $e) { + $nd->disconnect(); + } finally { + $nd->disconnect(); } } + } else { + $result = db_get_all_rows_sql($sql); - $result[$key]['status'] = $status; + // Module status. + foreach ($result as $key => $module) { + $status = ''; + switch ($module['status']) { + case AGENT_MODULE_STATUS_CRITICAL_BAD: + case AGENT_MODULE_STATUS_CRITICAL_ALERT: + case 1: + case 100: + $status = 'critical'; + break; + + case AGENT_MODULE_STATUS_NORMAL: + case AGENT_MODULE_STATUS_NORMAL_ALERT: + case 0: + case 300: + $status = 'normal'; + break; + + case AGENT_MODULE_STATUS_WARNING: + case AGENT_MODULE_STATUS_WARNING_ALERT: + case 2: + case 200: + $status = 'warning'; + break; + + default: + case AGENT_MODULE_STATUS_UNKNOWN: + case 3: + $status = 'unknown'; + break; + case AGENT_MODULE_STATUS_NOT_INIT: + case 5: + $status = 'notinit'; + break; + } + + if ($module['last_status_change'] != 0) { + $seconds = (time() - $module['last_status_change']); + + if ($seconds >= SECONDS_1DAY) { + $status .= '_10'; + } else if ($seconds >= 77760) { + $status .= '_9'; + } else if ($seconds >= 69120) { + $status .= '_8'; + } else if ($seconds >= 60480) { + $status .= '_7'; + } else if ($seconds >= 51840) { + $status .= '_6'; + } else if ($seconds >= 43200) { + $status .= '_5'; + } else if ($seconds >= 34560) { + $status .= '_4'; + } else if ($seconds >= 25920) { + $status .= '_3'; + } else if ($seconds >= 17280) { + $status .= '_2'; + } else if ($seconds >= 8640) { + $status .= '_1'; + } + } + + $result[$key]['status'] = $status; + } } return $result; @@ -515,6 +726,8 @@ class Heatmap */ protected function getAllModulesByTag() { + global $config; + $filter_tag = ''; if (empty($this->filter) === false && $this->filter[0] !== '0') { $tags = implode(',', $this->filter); @@ -526,81 +739,181 @@ class Heatmap $filter_name = 'AND nombre LIKE "%'.$this->search.'%"'; } + $id_user_groups = ''; + if (users_is_admin() === false) { + $user_groups = array_keys(users_get_groups($config['user'], 'AR', false)); + if (empty($user_groups) === false) { + $id_user_groups = sprintf( + 'INNER JOIN tagente a ON a.id_agente = ae.id_agente + AND a.id_grupo IN (%s)', + implode(',', $user_groups) + ); + } + } + // All modules. $sql = sprintf( 'SELECT ae.id_agente_modulo AS id, ae.estado AS `status`, tm.id_tag AS id_grupo, ae.last_status_change FROM tagente_estado ae + %s INNER JOIN ttag_module tm ON tm.id_agente_modulo = ae.id_agente_modulo - WHERE 1=1 %s %s GROUP BY tm.id_tag, ae.id_agente_modulo', + WHERE 1=1 %s %s GROUP BY ae.id_agente_modulo', + $id_user_groups, $filter_tag, $filter_name ); - $result = db_get_all_rows_sql($sql); + if (is_metaconsole() === true) { + $nodes = metaconsole_get_connections(); + $result = []; + $cont = 0; + foreach ($nodes as $node) { + try { + $nd = new Node($node['id']); + $nd->connect(); - // Module status. - foreach ($result as $key => $module) { - $status = ''; - switch ($module['status']) { - case AGENT_MODULE_STATUS_CRITICAL_BAD: - case AGENT_MODULE_STATUS_CRITICAL_ALERT: - case 1: - case 100: - $status = 'critical'; - break; + $modules = db_get_all_rows_sql($sql); - case AGENT_MODULE_STATUS_NORMAL: - case AGENT_MODULE_STATUS_NORMAL_ALERT: - case 0: - case 300: - $status = 'normal'; - break; + // Module status. + foreach ($modules as $key => $module) { + $status = ''; + switch ($module['status']) { + case AGENT_MODULE_STATUS_CRITICAL_BAD: + case AGENT_MODULE_STATUS_CRITICAL_ALERT: + case 1: + case 100: + $status = 'critical'; + break; - case AGENT_MODULE_STATUS_WARNING: - case AGENT_MODULE_STATUS_WARNING_ALERT: - case 2: - case 200: - $status = 'warning'; - break; + case AGENT_MODULE_STATUS_NORMAL: + case AGENT_MODULE_STATUS_NORMAL_ALERT: + case 0: + case 300: + $status = 'normal'; + break; - default: - case AGENT_MODULE_STATUS_UNKNOWN: - case 3: - $status = 'unknown'; - break; - case AGENT_MODULE_STATUS_NOT_INIT: - case 5: - $status = 'notinit'; - break; - } + case AGENT_MODULE_STATUS_WARNING: + case AGENT_MODULE_STATUS_WARNING_ALERT: + case 2: + case 200: + $status = 'warning'; + break; - if ($module['last_status_change'] != 0) { - $seconds = (time() - $module['last_status_change']); + default: + case AGENT_MODULE_STATUS_UNKNOWN: + case 3: + $status = 'unknown'; + break; + case AGENT_MODULE_STATUS_NOT_INIT: + case 5: + $status = 'notinit'; + break; + } - if ($seconds >= SECONDS_1DAY) { - $status .= '_10'; - } else if ($seconds >= 77760) { - $status .= '_9'; - } else if ($seconds >= 69120) { - $status .= '_8'; - } else if ($seconds >= 60480) { - $status .= '_7'; - } else if ($seconds >= 51840) { - $status .= '_6'; - } else if ($seconds >= 43200) { - $status .= '_5'; - } else if ($seconds >= 34560) { - $status .= '_4'; - } else if ($seconds >= 25920) { - $status .= '_3'; - } else if ($seconds >= 17280) { - $status .= '_2'; - } else if ($seconds >= 8640) { - $status .= '_1'; + if ($module['last_status_change'] != 0) { + $seconds = (time() - $module['last_status_change']); + + if ($seconds >= SECONDS_1DAY) { + $status .= '_10'; + } else if ($seconds >= 77760) { + $status .= '_9'; + } else if ($seconds >= 69120) { + $status .= '_8'; + } else if ($seconds >= 60480) { + $status .= '_7'; + } else if ($seconds >= 51840) { + $status .= '_6'; + } else if ($seconds >= 43200) { + $status .= '_5'; + } else if ($seconds >= 34560) { + $status .= '_4'; + } else if ($seconds >= 25920) { + $status .= '_3'; + } else if ($seconds >= 17280) { + $status .= '_2'; + } else if ($seconds >= 8640) { + $status .= '_1'; + } + } + + $result[$cont] = $module; + $result[$cont]['status'] = $status; + $result[$cont]['server'] = $node['id']; + ++$cont; + } + } catch (\Exception $e) { + $nd->disconnect(); + } finally { + $nd->disconnect(); } } + } else { + $result = db_get_all_rows_sql($sql); - $result[$key]['status'] = $status; + // Module status. + foreach ($result as $key => $module) { + $status = ''; + switch ($module['status']) { + case AGENT_MODULE_STATUS_CRITICAL_BAD: + case AGENT_MODULE_STATUS_CRITICAL_ALERT: + case 1: + case 100: + $status = 'critical'; + break; + + case AGENT_MODULE_STATUS_NORMAL: + case AGENT_MODULE_STATUS_NORMAL_ALERT: + case 0: + case 300: + $status = 'normal'; + break; + + case AGENT_MODULE_STATUS_WARNING: + case AGENT_MODULE_STATUS_WARNING_ALERT: + case 2: + case 200: + $status = 'warning'; + break; + + default: + case AGENT_MODULE_STATUS_UNKNOWN: + case 3: + $status = 'unknown'; + break; + case AGENT_MODULE_STATUS_NOT_INIT: + case 5: + $status = 'notinit'; + break; + } + + if ($module['last_status_change'] != 0) { + $seconds = (time() - $module['last_status_change']); + + if ($seconds >= SECONDS_1DAY) { + $status .= '_10'; + } else if ($seconds >= 77760) { + $status .= '_9'; + } else if ($seconds >= 69120) { + $status .= '_8'; + } else if ($seconds >= 60480) { + $status .= '_7'; + } else if ($seconds >= 51840) { + $status .= '_6'; + } else if ($seconds >= 43200) { + $status .= '_5'; + } else if ($seconds >= 34560) { + $status .= '_4'; + } else if ($seconds >= 25920) { + $status .= '_3'; + } else if ($seconds >= 17280) { + $status .= '_2'; + } else if ($seconds >= 8640) { + $status .= '_1'; + } + } + + $result[$key]['status'] = $status; + } } return $result; @@ -614,85 +927,187 @@ class Heatmap */ protected function getAllModulesByAgents() { + global $config; + $filter_name = ''; if (empty($this->search) === false) { $filter_name = 'AND nombre LIKE "%'.$this->search.'%"'; } + $id_user_groups = ''; + if (users_is_admin() === false) { + $user_groups = array_keys(users_get_groups($config['user'], 'AR', false)); + if (empty($user_groups) === false) { + $id_user_groups = sprintf( + 'INNER JOIN tagente a ON a.id_agente = ae.id_agente + AND a.id_grupo IN (%s)', + implode(',', $user_groups) + ); + } + } + // All modules. $sql = sprintf( 'SELECT am.id_agente_modulo AS id, ae.estado AS `status`, am.id_agente AS id_grupo, ae.last_status_change FROM tagente_modulo am INNER JOIN tagente_estado ae ON am.id_agente_modulo = ae.id_agente_modulo + %s WHERE am.disabled = 0 %s GROUP BY ae.id_agente_modulo ORDER BY id_grupo', + $id_user_groups, $filter_name ); - $result = db_get_all_rows_sql($sql); + if (is_metaconsole() === true) { + $result = []; + $nodes = metaconsole_get_connections(); + $cont = 0; + foreach ($nodes as $node) { + try { + $nd = new Node($node['id']); + $nd->connect(); - // Module status. - foreach ($result as $key => $module) { - $status = ''; - switch ($module['status']) { - case AGENT_MODULE_STATUS_CRITICAL_BAD: - case AGENT_MODULE_STATUS_CRITICAL_ALERT: - case 1: - case 100: - $status = 'critical'; - break; + $modules = db_get_all_rows_sql($sql); + // Module status. + foreach ($modules as $key => $module) { + $status = ''; + switch ($module['status']) { + case AGENT_MODULE_STATUS_CRITICAL_BAD: + case AGENT_MODULE_STATUS_CRITICAL_ALERT: + case 1: + case 100: + $status = 'critical'; + break; - case AGENT_MODULE_STATUS_NORMAL: - case AGENT_MODULE_STATUS_NORMAL_ALERT: - case 0: - case 300: - $status = 'normal'; - break; + case AGENT_MODULE_STATUS_NORMAL: + case AGENT_MODULE_STATUS_NORMAL_ALERT: + case 0: + case 300: + $status = 'normal'; + break; - case AGENT_MODULE_STATUS_WARNING: - case AGENT_MODULE_STATUS_WARNING_ALERT: - case 2: - case 200: - $status = 'warning'; - break; + case AGENT_MODULE_STATUS_WARNING: + case AGENT_MODULE_STATUS_WARNING_ALERT: + case 2: + case 200: + $status = 'warning'; + break; - default: - case AGENT_MODULE_STATUS_UNKNOWN: - case 3: - $status = 'unknown'; - break; - case AGENT_MODULE_STATUS_NOT_INIT: - case 5: - $status = 'notinit'; - break; - } + default: + case AGENT_MODULE_STATUS_UNKNOWN: + case 3: + $status = 'unknown'; + break; + case AGENT_MODULE_STATUS_NOT_INIT: + case 5: + $status = 'notinit'; + break; + } - if ($module['last_status_change'] != 0) { - $seconds = (time() - $module['last_status_change']); + if ($module['last_status_change'] != 0) { + $seconds = (time() - $module['last_status_change']); - if ($seconds >= SECONDS_1DAY) { - $status .= '_10'; - } else if ($seconds >= 77760) { - $status .= '_9'; - } else if ($seconds >= 69120) { - $status .= '_8'; - } else if ($seconds >= 60480) { - $status .= '_7'; - } else if ($seconds >= 51840) { - $status .= '_6'; - } else if ($seconds >= 43200) { - $status .= '_5'; - } else if ($seconds >= 34560) { - $status .= '_4'; - } else if ($seconds >= 25920) { - $status .= '_3'; - } else if ($seconds >= 17280) { - $status .= '_2'; - } else if ($seconds >= 8640) { - $status .= '_1'; + if ($seconds >= SECONDS_1DAY) { + $status .= '_10'; + } else if ($seconds >= 77760) { + $status .= '_9'; + } else if ($seconds >= 69120) { + $status .= '_8'; + } else if ($seconds >= 60480) { + $status .= '_7'; + } else if ($seconds >= 51840) { + $status .= '_6'; + } else if ($seconds >= 43200) { + $status .= '_5'; + } else if ($seconds >= 34560) { + $status .= '_4'; + } else if ($seconds >= 25920) { + $status .= '_3'; + } else if ($seconds >= 17280) { + $status .= '_2'; + } else if ($seconds >= 8640) { + $status .= '_1'; + } + } + + $result[$cont] = $module; + $result[$cont]['status'] = $status; + $result[$cont]['server'] = $node['id']; + ++$cont; + } + } catch (\Exception $e) { + $nd->disconnect(); + $result = []; + } finally { + $nd->disconnect(); } } + } else { + $result = db_get_all_rows_sql($sql); - $result[$key]['status'] = $status; + // Module status. + foreach ($result as $key => $module) { + $status = ''; + switch ($module['status']) { + case AGENT_MODULE_STATUS_CRITICAL_BAD: + case AGENT_MODULE_STATUS_CRITICAL_ALERT: + case 1: + case 100: + $status = 'critical'; + break; + + case AGENT_MODULE_STATUS_NORMAL: + case AGENT_MODULE_STATUS_NORMAL_ALERT: + case 0: + case 300: + $status = 'normal'; + break; + + case AGENT_MODULE_STATUS_WARNING: + case AGENT_MODULE_STATUS_WARNING_ALERT: + case 2: + case 200: + $status = 'warning'; + break; + + default: + case AGENT_MODULE_STATUS_UNKNOWN: + case 3: + $status = 'unknown'; + break; + case AGENT_MODULE_STATUS_NOT_INIT: + case 5: + $status = 'notinit'; + break; + } + + if ($module['last_status_change'] != 0) { + $seconds = (time() - $module['last_status_change']); + + if ($seconds >= SECONDS_1DAY) { + $status .= '_10'; + } else if ($seconds >= 77760) { + $status .= '_9'; + } else if ($seconds >= 69120) { + $status .= '_8'; + } else if ($seconds >= 60480) { + $status .= '_7'; + } else if ($seconds >= 51840) { + $status .= '_6'; + } else if ($seconds >= 43200) { + $status .= '_5'; + } else if ($seconds >= 34560) { + $status .= '_4'; + } else if ($seconds >= 25920) { + $status .= '_3'; + } else if ($seconds >= 17280) { + $status .= '_2'; + } else if ($seconds >= 8640) { + $status .= '_1'; + } + } + + $result[$key]['status'] = $status; + } } return $result; @@ -790,7 +1205,6 @@ class Heatmap { $yAxis = sqrt(($total / $relation)); return $yAxis; - } @@ -801,7 +1215,7 @@ class Heatmap * * @return boolean True allowed, false not. */ - public function ajaxMethod(string $method):bool + public function ajaxMethod(string $method): bool { return in_array($method, $this->AJAXMethods); } @@ -847,8 +1261,13 @@ class Heatmap $contY = 0; $cont = 1; foreach ($result as $value) { + $name = $value['id']; + if (empty($value['server']) === false) { + $name .= '|'.$value['server']; + } + echo ''; + width="1" height="1" x ="'.$contX.' "y="'.$contY.'" name="'.$name.'" />'; $contX++; if ($contX >= $Xaxis) { @@ -866,41 +1285,44 @@ class Heatmap } ?> - + }); + 1 && $this->group === 1) { + if (count($groups) > 1 && $this->group === 1 && $this->dashboard === false) { $x_back = 0; $y_back = 0; @@ -1099,7 +1521,7 @@ class Heatmap echo ''; // Dialog. - echo ''; + echo '
'; } diff --git a/pandora_console/include/javascript/pandora_dashboards.js b/pandora_console/include/javascript/pandora_dashboards.js index 6fcaf24c16..f46c64082f 100644 --- a/pandora_console/include/javascript/pandora_dashboards.js +++ b/pandora_console/include/javascript/pandora_dashboards.js @@ -1562,3 +1562,36 @@ function showManualThresholds(element) { $(".dashboard-input-threshold-critical").addClass("invisible_important"); } } + +/** + * @return {void} + */ +// eslint-disable-next-line no-unused-vars +function type_change() { + var type = document.getElementById("type").value; + + switch (type) { + case "3": + $("#li_tags").hide(); + $("#li_groups").hide(); + $("#li_module_groups").hide(); + break; + case "2": + $("#li_tags").hide(); + $("#li_groups").hide(); + $("#li_module_groups").show(); + break; + case "1": + $("#li_tags").show(); + $("#li_groups").hide(); + $("#li_module_groups").hide(); + break; + + default: + case "0": + $("#li_tags").hide(); + $("#li_groups").show(); + $("#li_module_groups").hide(); + break; + } +} diff --git a/pandora_console/include/lib/Dashboard/Widget.php b/pandora_console/include/lib/Dashboard/Widget.php index b4705007b0..ec962bb36d 100644 --- a/pandora_console/include/lib/Dashboard/Widget.php +++ b/pandora_console/include/lib/Dashboard/Widget.php @@ -426,6 +426,10 @@ class Widget $className .= '\\'.$name; break; + case 'heatmap': + $className .= '\HeatmapWidget'; + break; + default: $className = false; break; diff --git a/pandora_console/include/lib/Dashboard/Widgets/heatmap.php b/pandora_console/include/lib/Dashboard/Widgets/heatmap.php new file mode 100644 index 0000000000..2f9d9533cd --- /dev/null +++ b/pandora_console/include/lib/Dashboard/Widgets/heatmap.php @@ -0,0 +1,478 @@ +width = $width; + + // Height. + $this->height = $height; + + // Cell Id. + $this->cellId = $cellId; + + // Widget ID. + $this->widgetId = $widgetId; + + // Dashboard ID. + $this->dashboardId = $dashboardId; + + // Options. + $this->values = $this->decoders($this->getOptionsWidget()); + + // Page. + $this->page = basename(__FILE__); + + // ClassName. + $class = new \ReflectionClass($this); + $this->className = $class->getShortName(); + + // Title. + $this->title = __('Heatmap'); + + // Name. + if (empty($this->name) === true) { + $this->name = 'heatmap'; + } + } + + + /** + * Decoders hack for retrocompability. + * + * @param array $decoder Values. + * + * @return array Returns the values ​​with the correct key. + */ + public function decoders(array $decoder): array + { + $values = []; + // Retrieve global - common inputs. + $values = parent::decoders($decoder); + + if (isset($decoder['search']) === true) { + $values['search'] = $decoder['search']; + } + + if (isset($decoder['type']) === true) { + $values['type'] = $decoder['type']; + } + + if (isset($decoder['groups']) === true) { + $values['groups'] = $decoder['groups']; + } + + if (isset($decoder['tags']) === true) { + $values['tags'] = $decoder['tags']; + } + + if (isset($decoder['module_groups']) === true) { + $values['module_groups'] = $decoder['module_groups']; + } + + return $values; + } + + + /** + * Generates inputs for form (specific). + * + * @return array Of inputs. + * + * @throws Exception On error. + */ + public function getFormInputs(): array + { + global $config; + // Retrieve global - common inputs. + $inputs = parent::getFormInputs(); + + $values = $this->values; + + // Search. + $inputs[] = [ + 'label' => \__('Search'), + 'arguments' => [ + 'name' => 'search', + 'type' => 'text', + 'class' => 'event-widget-input', + 'value' => $values['search'], + 'return' => true, + 'size' => 30, + ], + ]; + + $inputs[] = [ + 'label' => __('Type'), + 'arguments' => [ + 'type' => 'select', + 'fields' => [ + 0 => __('Group agents'), + 1 => __('Group modules by tag'), + 2 => __('Group modules by module group'), + 3 => __('Group modules by agents'), + ], + 'name' => 'type', + 'selected' => $values['type'], + 'script' => 'type_change()', + 'return' => true, + ], + ]; + + // Filters. + $inputs[] = [ + 'label' => __('Groups'), + 'style' => ($values['type'] === '0') ? '' : 'display:none', + 'id' => 'li_groups', + 'arguments' => [ + 'type' => 'select_groups', + 'name' => 'groups[]', + 'returnAllGroup' => true, + 'privilege' => 'AR', + 'selected' => explode(',', $values['groups'][0]), + 'return' => true, + 'multiple' => true, + ], + ]; + + if (tags_has_user_acl_tags($config['id_user']) === false) { + $tags = db_get_all_rows_sql( + 'SELECT id_tag, name FROM ttag WHERE id_tag ORDER BY name' + ); + } else { + $user_tags = tags_get_user_tags($config['id_user'], 'AR'); + if (empty($user_tags) === false) { + $id_user_tags = array_keys($user_tags); + $tags = db_get_all_rows_sql( + 'SELECT id_tag, name FROM ttag + WHERE id_tag IN ('.implode(',', $id_user_tags).') + ORDER BY name' + ); + } else { + $tags = db_get_all_rows_sql( + 'SELECT id_tag, name FROM ttag WHERE id_tag ORDER BY name' + ); + } + } + + $inputs[] = [ + 'label' => __('Tag'), + 'style' => ($values['type'] === '1') ? '' : 'display:none', + 'id' => 'li_tags', + 'arguments' => [ + 'type' => 'select', + 'fields' => $tags, + 'name' => 'tags[]', + 'selected' => explode(',', $values['tags'][0]), + 'return' => true, + 'multiple' => true, + ], + ]; + + $module_groups_aux = db_get_all_rows_sql( + 'SELECT id_mg, name FROM tmodule_group ORDER BY name' + ); + + $module_groups = []; + foreach ($module_groups_aux as $key => $module_group) { + $module_groups[$module_group['id_mg']] = $module_group['name']; + } + + $inputs[] = [ + 'label' => __('Module group'), + 'style' => ($values['type'] === '2') ? '' : 'display:none', + 'id' => 'li_module_groups', + 'arguments' => [ + 'type' => 'select', + 'fields' => $module_groups, + 'name' => 'module_groups[]', + 'selected' => explode(',', $values['module_groups'][0]), + 'return' => true, + 'multiple' => true, + 'nothing' => __('Not assigned'), + 'nothing_value' => 0, + ], + ]; + + return $inputs; + } + + + /** + * Get Post for widget. + * + * @return array + */ + public function getPost(): array + { + // Retrieve global - common inputs. + $values = parent::getPost(); + + $values['search'] = \get_parameter('search', ''); + $values['type'] = \get_parameter('type', 0); + + switch ((int) $values['type']) { + case 2: + $values['module_groups'] = \get_parameter('module_groups', 0); + break; + + case 1: + $values['tags'] = \get_parameter('tags', 0); + break; + + case 0: + $values['groups'] = \get_parameter('groups', 0); + break; + + default: + // Do nothing. + break; + } + + return $values; + } + + + /** + * Get description. + * + * @return string. + */ + public static function getDescription() + { + return __('Heatmap'); + } + + + /** + * Get Name. + * + * @return string. + */ + public static function getName() + { + return 'heatmap'; + } + + + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => 500, + 'height' => 300, + ]; + + return $size; + } + + + /** + * Draw widget. + * + * @return string; + */ + public function load() + { + global $config; + + \ui_require_css_file('heatmap', 'include/styles/', true); + + $values = $this->values; + $search = (empty($values['search']) === false) ? $values['search'] : ''; + $type = (empty($values['type']) === false) ? $values['type'] : 0; + $filter = []; + if (isset($values['groups'])) { + $filter = explode(',', $values['groups'][0]); + } + + if (isset($values['tags'])) { + $filter = explode(',', $values['tags'][0]); + } + + if (isset($values['module_groups'])) { + $filter = explode(',', $values['module_groups'][0]); + } + + // Control call flow. + $heatmap = new Heatmap($type, $filter, null, 300, 400, 200, $search, 0, true); + // AJAX controller. + if (is_ajax() === true) { + $method = get_parameter('method'); + + if ($method === 'drawWidget') { + // Run. + $heatmap->run(); + } else { + if (method_exists($heatmap, $method) === true) { + if ($heatmap->ajaxMethod($method) === true) { + $heatmap->{$method}(); + } else { + echo 'Unavailable method'; + } + } else { + echo 'Method not found'; + } + + // Stop any execution. + exit; + } + } else { + // Run. + $heatmap->run(); + + // Dialog. + echo ''; + } + + return ''; + } + + +} diff --git a/pandora_console/operation/heatmap.php b/pandora_console/operation/heatmap.php index 1f7337aa39..1e063d3c3d 100644 --- a/pandora_console/operation/heatmap.php +++ b/pandora_console/operation/heatmap.php @@ -41,6 +41,7 @@ if ($agent_a === false && $agent_w === false) { } require_once $config['homedir'].'/include/class/Heatmap.class.php'; +use PandoraFMS\Heatmap; $pure = (bool) get_parameter('pure', false); $type = get_parameter('type', 0); @@ -61,6 +62,8 @@ if ($group_sent === true) { $group = (int) get_parameter('group', true); } +$dashboard = (bool) get_parameter('dashboard', false); + $is_ajax = is_ajax(); if ($is_ajax === false && $pure === false) { $viewtab['config'] = ''.html_print_image( @@ -191,6 +194,7 @@ if ($is_ajax === false && $pure === true) { html_print_input_hidden('type', $type); html_print_input_hidden('search', $search); html_print_input_hidden('filter', implode(',', $filter)); + html_print_input_hidden('dashboard', $dashboard); echo ''; echo '
'; echo '
'; @@ -229,7 +233,7 @@ if ($is_ajax === false && $pure === true) { // Control call flow. try { // Heatmap construct. - $heatmap = new Heatmap($type, $filter, $randomId, $refresh, $width, $height, $search, $group); + $heatmap = new Heatmap($type, $filter, $randomId, $refresh, $width, $height, $search, $group, $dashboard); } catch (Exception $e) { if (is_ajax() === true) { echo json_encode(['error' => '[Heatmap]'.$e->getMessage() ]);