';
-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/visual_console_builder.ajax.php b/pandora_console/include/ajax/visual_console_builder.ajax.php
index d529721b93..690aa437b8 100755
--- a/pandora_console/include/ajax/visual_console_builder.ajax.php
+++ b/pandora_console/include/ajax/visual_console_builder.ajax.php
@@ -100,6 +100,7 @@ $width = get_parameter('width', null);
$height = get_parameter('height', null);
$parent = get_parameter('parent', null);
$map_linked = get_parameter('map_linked', null);
+$linked_map_node_id = get_parameter('linked_map_node_id', null);
$linked_map_status_calculation_type = get_parameter('linked_map_status_calculation_type', 'default');
$map_linked_weight = get_parameter('map_linked_weight', null);
@@ -613,6 +614,10 @@ switch ($action) {
if ($id_agent !== null) {
$values['id_agent'] = $id_agent;
}
+
+ if ($linked_map_node_id !== null) {
+ $values['linked_layout_node_id'] = (int) $linked_map_node_id;
+ }
}
else if ($id_agent == 0) {
$values['id_agent'] = 0;
@@ -1135,6 +1140,11 @@ switch ($action) {
}
$values['id_agente_modulo'] = $id_module;
$values['id_layout_linked'] = $map_linked;
+
+ if (defined('METACONSOLE') && $metaconsole) {
+ $values['linked_layout_node_id'] = (int) $linked_map_node_id;
+ }
+
$values['linked_layout_status_type'] = $linked_map_status_calculation_type;
if ($map_linked_weight !== null) {
@@ -1419,7 +1429,6 @@ if ($get_element_status) {
array('id' => $id_element));
$res = visual_map_get_status_element($layoutData);
- html_debug($res, true);
echo $res;
return;
diff --git a/pandora_console/include/class/Tree.class.php b/pandora_console/include/class/Tree.class.php
index cc80ac1686..e18cfb599e 100644
--- a/pandora_console/include/class/Tree.class.php
+++ b/pandora_console/include/class/Tree.class.php
@@ -19,6 +19,7 @@ class Tree {
protected $id = -1;
protected $rootID = -1;
protected $serverID = false;
+ protected $serverName = '';
protected $tree = array();
protected $filter = array();
protected $childrenMethod = "on_demand";
@@ -50,6 +51,9 @@ 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;
@@ -151,23 +155,23 @@ class Tree {
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 ta.warning_count > 0 AND ta.critical_count = 0"
+ '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 ta.critical_count > 0"
+ '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 ta.critical_count = 0 AND ta.warning_count = 0 AND ta.unknown_count = 0 AND ta.normal_count > 0"
+ '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 ta.critical_count = 0 AND ta.warning_count = 0 AND ta.unknown_count > 0"
+ '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' => $this->filter['show_not_init_agents'] ? "AND ta.total_count = ta.notinit_count" : " AND 1=0"
+ '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",
@@ -175,7 +179,7 @@ class Tree {
),
'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' => $this->filter['show_not_init_agents'] ? "" : "AND ta.total_count <> ta.notinit_count"
+ 'condition' => "AND " . agents_get_status_clause(AGENT_STATUS_ALL, $this->filter['show_not_init_agents'])
)
);
}
@@ -228,43 +232,9 @@ class Tree {
? $state
: $this->filter['statusModule'];
- $filter = array();
- switch ($selected_status) {
- case AGENT_MODULE_STATUS_CRITICAL_ALERT:
- case AGENT_MODULE_STATUS_CRITICAL_BAD:
- $filter[] = "(
- 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:
- $filter[] = "(
- tae.estado = ".AGENT_MODULE_STATUS_WARNING_ALERT."
- OR tae.estado = ".AGENT_MODULE_STATUS_WARNING."
- )";
- break;
- case AGENT_MODULE_STATUS_UNKNOWN:
- $filter[] = "tae.estado = ".AGENT_MODULE_STATUS_UNKNOWN." ";
- break;
- case AGENT_MODULE_STATUS_NO_DATA:
- case AGENT_MODULE_STATUS_NOT_INIT:
- $filter[] = "(
- 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:
- $filter[] = "(
- tae.estado = ".AGENT_MODULE_STATUS_NORMAL_ALERT."
- OR tae.estado = ".AGENT_MODULE_STATUS_NORMAL."
- )";
- break;
- default:
- $filter[] = "1=1";
- break;
- }
+ $filter = array(
+ modules_get_state_condition($selected_status)
+ );
if (!$this->filter['show_not_init_modules'] && $state === false) {
if (!empty($filter))
$filter[] = "(
@@ -278,7 +248,7 @@ class Tree {
: " AND $filter ";
}
- protected function getGroupAclCondition() {
+ public function getGroupAclCondition() {
if (users_can_manage_group_all("AR")) return "";
$groups_str= implode(",", $this->userGroupsArray);
@@ -301,105 +271,6 @@ class Tree {
return " AND tg.nombre LIKE '%" . $this->filter['searchGroup'] . "%'";
}
- 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 getAgentCountersSql ($agent_table) {
- global $config;
-
- $columns = $this->getAgentCounterColumnsSql($agent_table);
- $columns = "SELECT $columns FROM dual LIMIT 1";
-
- return $columns;
- }
-
static function cmpSortNames($a, $b) {
return strcmp($a["name"], $b["name"]);
}
@@ -580,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;
@@ -675,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'];
}
diff --git a/pandora_console/include/class/TreeGroup.class.php b/pandora_console/include/class/TreeGroup.class.php
index d3c4f8f506..af5542e396 100644
--- a/pandora_console/include/class/TreeGroup.class.php
+++ b/pandora_console/include/class/TreeGroup.class.php
@@ -19,6 +19,8 @@ require_once($config['homedir']."/include/class/Tree.class.php");
class TreeGroup extends Tree {
+ protected $propagateCounters = true;
+
public function __construct($type, $rootType = '', $id = -1, $rootID = -1, $serverID = false, $childrenMethod = "on_demand", $access = 'AR') {
global $config;
@@ -38,6 +40,10 @@ class TreeGroup extends Tree {
)";
}
+ public function setPropagateCounters($value) {
+ $this->propagateCounters = (bool)$value;
+ }
+
protected function getData() {
if ($this->id == -1) {
$this->getFirstLevel();
@@ -126,9 +132,13 @@ class TreeGroup extends Tree {
return !$group['have_parent'];
});
// Propagate child counters to her parents
- TreeGroup::processCounters($groups);
- // Filter groups and eliminates the reference to empty groups
- $groups = TreeGroup::deleteEmptyGroups($groups);
+ 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;
@@ -353,6 +363,32 @@ class TreeGroup extends Tree {
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) {
diff --git a/pandora_console/include/config_process.php b/pandora_console/include/config_process.php
index 5a985fae32..3fda24d3fb 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 = 'PC180906';
-$pandora_version = 'v7.0NG.726';
+$build_version = 'PC180917';
+$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 9199604b75..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 {
@@ -2742,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..322b3a7602 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 . '%"
@@ -1792,9 +1797,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 +1869,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..33118d39c2 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,
@@ -892,7 +889,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 +921,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 +962,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 +1222,7 @@ function graphic_combined_module (
}
else{
$params['stacked'] = 'area';
- $params['projection'] = $params_combined['projection'];
+ $params['projection'] = true;
}
if(!isset($params_combined['labels'])){
@@ -1512,6 +1515,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 +1589,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 +4129,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 +4155,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 +4203,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 +4268,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 +4289,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 +5111,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 443d84c07f..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,39 +1737,6 @@ 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) {
@@ -2771,7 +2180,7 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu
$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"]);
@@ -2780,7 +2189,7 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu
$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_"]
@@ -2868,77 +2277,6 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu
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;
- }
-}
-
function groups_get_group_deep ($id_group) {
global $config;
diff --git a/pandora_console/include/functions_groupview.php b/pandora_console/include/functions_groupview.php
index 0e45341ea4..15b4d577bf 100644
--- a/pandora_console/include/functions_groupview.php
+++ b/pandora_console/include/functions_groupview.php
@@ -16,801 +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, $access = 'AR') {
- global $config;
- if ($id_user == false) {
- $id_user = $config['id_user'];
- }
-
- $user_groups = users_get_groups($id_user, $access, true, false);
-
- $groups_with_privileges = implode(',', array_keys($user_groups));
-
- //change ALL for 0
- $user_groups[0] = 0;
-
- $user_groups_ids = implode(',', array_keys($user_groups));
-
- if (!empty($user_groups_ids)) {
- $table = is_metaconsole() ? 'tmetaconsole_agent' : 'tagente';
- $table_secondary = is_metaconsole()
- ? 'tmetaconsole_agent_secondary_group'
- : 'tagent_secondary_group';
-
- $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 $table WHERE disabled = 0)
- OR id_grupo IN (SELECT id_group FROM $table_secondary WHERE id_group IN ($user_groups_ids))
- )
- ORDER BY nombre COLLATE utf8_general_ci ASC"
- );
- }
-
- //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);
- }
-
- //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 00e643e7ca..f8e632dad4 100755
--- a/pandora_console/include/functions_modules.php
+++ b/pandora_console/include/functions_modules.php
@@ -2775,4 +2775,37 @@ function modules_get_counter_by_states($state) {
// 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..4cc8315b0b 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);
}
@@ -2807,18 +2807,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(
@@ -3483,79 +3482,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 +3557,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,27 +3799,27 @@ 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']
);
-
- switch ($type) {
+ switch ($type) {
case 'max':
if($content['lapse_calc'] == 0){
$value = reporting_get_agentmodule_data_max(
@@ -6344,24 +6259,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 +6378,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 +6406,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 +6429,7 @@ function reporting_get_date_text($report = null, $content = null) {
$return['to'] = $report["datetime"];
}
}
-
+
return $return;
}
@@ -6531,7 +6445,7 @@ function reporting_check_structure_report($return) {
$return['datetime'] = "";
if (!isset($return['period']))
$return['period'] = "";
-
+
return $return;
}
@@ -6551,7 +6465,7 @@ function reporting_check_structure_content($report) {
$report["date"]['from'] = "";
$report["date"]['to'] = "";
}
-
+
return $report;
}
@@ -7000,54 +6914,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_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/functions_visual_map.php b/pandora_console/include/functions_visual_map.php
index dcea41910f..b92f17e230 100755
--- a/pandora_console/include/functions_visual_map.php
+++ b/pandora_console/include/functions_visual_map.php
@@ -803,6 +803,18 @@ function visual_map_print_item($mode = "read", $layoutData,
}
break;
}
+
+ // Override url
+ if (
+ is_metaconsole() &&
+ !empty($layoutData["id_layout_linked"]) &&
+ !empty($layoutData["linked_layout_node_id"])
+ ) {
+ $url = ui_meta_get_url_console_child(
+ $layoutData['linked_layout_node_id'],
+ "network", "operation/visual_console/render_view&id=" . (int) $layoutData["id_layout_linked"]
+ );
+ }
}
// + 1 for to avoid the box and lines items are on the top of
@@ -3137,38 +3149,22 @@ function visual_map_get_status_element($layoutData) {
WHERE id_agente_modulo = ' . $layoutData['id_agente_modulo']);
//Linked to other layout ?? - Only if not module defined
- if ($layoutData['id_layout_linked'] != 0) {
- if ($layoutData['id_layout_linked_weight'] != 0) {
- $calculate_weight = true;
- }
- else {
- $calculate_weight = false;
+ if (!empty($layoutData['id_layout_linked'])) {
+ if (!empty($layoutData['linked_layout_node_id'])) {
+ //Metaconsole db connection
+ $connection = db_get_row_filter ('tmetaconsole_setup',
+ array('id' => $layoutData['linked_layout_node_id']));
+ if (metaconsole_load_external_db($connection) != NOERR) return VISUAL_MAP_STATUS_UNKNOWN;
}
+
$status = visual_map_get_layout_status($layoutData['id_layout_linked'], $layoutData);
- if ($layoutData['id_layout_linked_weight'] > 0) {
- $elements_to_compare = db_get_all_rows_sql("SELECT id, element_group FROM tlayout_data WHERE type = 0 AND id_layout = " . $layoutData['id_layout_linked']);
-
- $childs_group_acl = array();
- foreach ($elements_to_compare as $c) {
- if (check_acl ($config['id_user'], $c['element_group'], "VR")) {
- $childs_group_acl[] = $c['id'];
- }
- }
- $elements_to_compare = $childs_group_acl;
-
- $aux_weight = ($status['elements_in_critical'] / count($elements_to_compare)) * 100;
-
- if ($aux_weight >= $layoutData['id_layout_linked_weight']) {
- $status = $status['temp_total'];
- }
- else {
- $status = VISUAL_MAP_STATUS_NORMAL;
- if (count($elements_to_compare) == 0) {
- $status = VISUAL_MAP_STATUS_UNKNOWN;
- }
- }
+ if (!empty($layoutData['linked_layout_node_id'])) {
+ //Restore db connection
+ metaconsole_restore_db();
}
+
+ return $status;
}
else {
switch ($layoutData["type"]) {
@@ -3676,7 +3672,7 @@ function visual_map_translate_agent_status ($agent_status) {
}
function visual_map_translate_module_status ($module_status) {
- switch ($agent_status) {
+ switch ($module_status) {
case AGENT_MODULE_STATUS_NORMAL:
case AGENT_MODULE_STATUS_NORMAL_ALERT:
default:
@@ -3717,6 +3713,7 @@ function visual_map_get_layout_status ($layout_id, $status_data = array(), $dept
if ($depth > 10) return VISUAL_MAP_STATUS_UNKNOWN;
$layout_items = db_get_all_rows_filter("tlayout_data", array("id_layout" => $layout_id));
+
if ($layout_items === false) return VISUAL_MAP_STATUS_UNKNOWN;
// Check for valid items to retrieve the status for
@@ -3738,17 +3735,6 @@ function visual_map_get_layout_status ($layout_id, $status_data = array(), $dept
!empty($layout_item_data["id_layout_linked"]) ||
!empty($layout_item_data["id_agente_modulo"]) ||
!empty($layout_item_data["id_agent"])
- ) && (
- // Weight and service types for status calculation require STATIC_GRAPH items
- (
- $status_data["linked_layout_status_type"] !== "weight" &&
- $status_data["linked_layout_status_type"] !== "service"
- ) || (
- $layout_item_data['type'] == STATIC_GRAPH && (
- $status_data["linked_layout_status_type"] === "weight" ||
- $status_data["linked_layout_status_type"] === "service"
- )
- )
) &&
// ACL check
check_acl($config["id_user"], $layout_item_data["element_group"], "VR")
@@ -3769,21 +3755,30 @@ function visual_map_get_layout_status ($layout_id, $status_data = array(), $dept
$meta_connected_to = null;
foreach ($valid_layout_items as $layout_item_data) {
+ $node_id = null;
+
if (is_metaconsole()) {
- if (empty($layout_item_data["id_metaconsole"]) && $meta_connected_to) {
+ $node_id = (
+ !empty($layout_item_data["id_layout_linked"]) &&
+ !empty($layout_item_data["linked_layout_node_id"])
+ )
+ ? $layout_item_data["linked_layout_node_id"]
+ : $layout_item_data["id_metaconsole"];
+
+ if (empty($node_id) && $meta_connected_to) {
metaconsole_restore_db(); // Restore db connection
$meta_connected_to = null;
}
else if (
- !empty($layout_item_data["id_metaconsole"]) && (
+ !empty($node_id) && (
empty($meta_connected_to) ||
- $meta_connected_to != $layout_item_data["id_metaconsole"]
+ $meta_connected_to != $node_id
)
) {
if (!empty($meta_connected_to)) metaconsole_restore_db(); // Restore db connection
- $connection = metaconsole_get_connection_by_id($layout_item_data["id_metaconsole"]);
+ $connection = metaconsole_get_connection_by_id($node_id);
if (metaconsole_load_external_db($connection) != NOERR) continue;
- $meta_connected_to = $layout_item_data["id_metaconsole"];
+ $meta_connected_to = $node_id;
}
}
diff --git a/pandora_console/include/functions_visual_map_editor.php b/pandora_console/include/functions_visual_map_editor.php
index 3039e0dc97..675272a7f8 100755
--- a/pandora_console/include/functions_visual_map_editor.php
+++ b/pandora_console/include/functions_visual_map_editor.php
@@ -697,13 +697,88 @@ function visual_map_editor_print_item_palette($visualConsole_id, $background) {
'group_item', 'static_graph', 'percentile_bar',
'percentile_item', 'module_graph', 'simple_value',
'icon', 'label', 'datos', 'donut_graph');
- $form_items_advance['map_linked_row']['html'] = '
'.
- __('Linked map') . ' | ' .
- '
' . html_print_select_from_sql (
- 'SELECT id, name
- FROM tlayout
- WHERE id != ' . (int) $visualConsole_id, 'map_linked', 0, 'onLinkedMapChange(event)', __('None'), 0, true) .
- ' | ';
+ $visual_maps = db_get_all_rows_filter("tlayout", "id != " . (int) $visualConsole_id, array("id", "name"));
+
+ $form_items_advance['map_linked_row']['html'] = '
'
+ . __('Linked visual console')
+ . ' | '
+ . '
';
+
+ if (is_metaconsole()) {
+ $meta_servers = metaconsole_get_servers();
+ foreach ($meta_servers as $server) {
+ if (metaconsole_load_external_db($server) !== NOERR) {
+ metaconsole_restore_db();
+ continue;
+ }
+
+ $node_visual_maps = db_get_all_rows_filter("tlayout", array(), array("id", "name"));
+
+ foreach ($node_visual_maps as $node_visual_map) {
+ $node_visual_map["node_id"] = (int) $server["id"];
+ $visual_maps[] = $node_visual_map;
+ }
+
+ metaconsole_restore_db();
+ }
+
+ $meta_servers_by_id = array_reduce($meta_servers, function ($arr, $item) {
+ $arr[$item["id"]] = $item;
+ return $arr;
+ }, array());
+
+ $form_items_advance['map_linked_row']['html'] .= html_print_select_from_sql(
+ array(), 'map_linked', 0, 'onLinkedMapChange(event)', __('None'), 0, true
+ );
+ $form_items_advance['map_linked_row']['html'] .= html_print_input_hidden(
+ "linked_map_node_id", 0, true
+ );
+
+ ob_start();
+ ?>
+
+ ';
$status_type_select_items = array(
"weight" => __("By status weight"),
@@ -715,7 +790,7 @@ function visual_map_editor_print_item_palette($visualConsole_id, $background) {
'percentile_item', 'module_graph', 'simple_value',
'icon', 'label', 'datos', 'donut_graph');
$form_items_advance['linked_map_status_calculation_row']['html'] = ' | '.
- __('Type of the status calculation of the linked map') . ' | '
+ __('Type of the status calculation of the linked visual console') . ''
. '
'
. html_print_select(
$status_type_select_items,
@@ -728,6 +803,7 @@ function visual_map_editor_print_item_palette($visualConsole_id, $background) {
false,
false
)
+ . ui_print_help_icon("linked_map_status_calc", true)
. ' | ';
$form_items_advance['map_linked_weight'] = array();
@@ -736,13 +812,12 @@ function visual_map_editor_print_item_palette($visualConsole_id, $background) {
'percentile_item', 'module_graph', 'simple_value',
'icon', 'label', 'datos', 'donut_graph');
$form_items_advance['map_linked_weight']['html'] = '
'
- . __('Linked map weight') . ' | '
+ . __('Linked visual console weight') . ''
. '
'
. html_print_input_text(
'map_linked_weight', 80, '', 5, 5, true, false, false, "", "type_number percentage"
)
. '%'
- . ui_print_help_icon("linked_map_weight", true)
. ' | ';
$form_items_advance['linked_map_status_service_critical_row'] = 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/help/en/help_linked_map_status_calc.php b/pandora_console/include/help/en/help_linked_map_status_calc.php
new file mode 100644
index 0000000000..96602eb262
--- /dev/null
+++ b/pandora_console/include/help/en/help_linked_map_status_calc.php
@@ -0,0 +1,36 @@
+
+
Ways to calculate the status of the linked visual console
+
+
By Default
+
+ It calculates the status based on the status of all elements, as an agent would do.
+
+
+
By weight
+
+ It calculates the status of the elements that have a visual console, a module or an agent assigned in relation to a percentage of elements configured by the user. This percentage is the one that has to exceed the number of elements of a non-normal status with respect to the number of elements taken into account in the calculation for that status to change.
+
+
+
+ For example, given an element with a percentage of 50% and a visual console linked with 5 elements:
+
+
+ - 1 critical, 1 warning y 3 normal -> Status normal.
+ - 2 critical, 2 warning y 1 normal -> Status normal.
+ - 1 critical, 3 warning y 1 normal -> Status warning.
+ - 3 critical, 1 warning y 1 normal -> Status critical.
+ - 1 critical, 1 warning y 3 unknown -> Status unknown.
+
+
+
+ If several statuses exceed the weight, the priority is the same as in the rest of the status calculation (critical > warning > unknown). If there are no elements to perform the calculation, the status becomes unknown.
+
+
+
By critical elements
+
+ It calculates the status using the elements in critical status and the percentages of the thresholds defined by the user. If the number of elements in critical status with respect to the number of elements taken into account in the calculation exceeds the percentage assigned as warning, the status becomes warning. The same applies to the percentage assigned as critical, which also has preference.
+
diff --git a/pandora_console/include/help/es/help_linked_map_status_calc.php b/pandora_console/include/help/es/help_linked_map_status_calc.php
new file mode 100644
index 0000000000..40c5682d7a
--- /dev/null
+++ b/pandora_console/include/help/es/help_linked_map_status_calc.php
@@ -0,0 +1,36 @@
+
+
Formas de calcular el estado de la consola visual enlazada
+
+
Por defecto
+
+ Calcula el estado a partir del estado de todos los elementos, como lo haría un agente.
+
+
+
Por peso
+
+ Calcula el estado de los elementos que tienen asignados una consola visual, un módulo o un agente en relación a un porcentaje de elementos configurado por el usuario. Este porcentaje es el que tiene que superar el número de elementos de un estado no normal respecto al número de elementos tenidos en cuenta en el cálculo para que el ese estado cambie.
+
+
+
+ Por ejemplo, dado un elemento con un porcentaje del 50% y una consola visual enlazada con 5 elementos:
+
+
+ - 1 critical, 1 warning y 3 normal -> Estado normal.
+ - 2 critical, 2 warning y 1 normal -> Estado normal.
+ - 1 critical, 3 warning y 1 normal -> Estado warning.
+ - 3 critical, 1 warning y 1 normal -> Estado critical.
+ - 1 critical, 1 warning y 3 unknown -> Estado unknown.
+
+
+
+ Si varios estados superan el peso, la prioridad es igual que en el resto de cálculo de estados (critical > warning > unknown). Si no hay elementos para realizar el cálculo, el estado pasa a ser unknown.
+
+
+
Por elementos críticos
+
+ Calcula el estado usando los elementos en estado critical y los porcentajes de los umbrales definidos por el usuario. Si el número de los elementos en estado critical respecto al número de elementos tenidos en cuenta en el cálculo supera el porcentaje asignado como warning, el estado pasa a ser warning. Lo mismo para el porcentaje asignado como critical, que además tiene preferencia.
+
diff --git a/pandora_console/install.php b/pandora_console/install.php
index 091becd2b7..d70cc355fc 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 14567cc2b5..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'),'AR');
-
- 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 "
" . __("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 1c6a8d49e3..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
@@ -81,12 +80,12 @@ $agents_notinit = 0;
$all_alerts_fired = 0;
//Groups and tags
-$result_groups = groupview_get_groups_list(
+$result_groups_info = groupview_get_groups_list(
$config['id_user'],
($agent_a == true) ? 'AR' : (($agent_w == true) ? 'AW' : 'AR')
);
-
-$count = count($result_groups);
+$result_groups = $result_groups_info['groups'];
+$count = $result_groups_info['counter'];
if ($result_groups[0]["_id_"] == 0) {
$total_agentes = $result_groups[0]["_total_agents_"];
@@ -187,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
@@ -454,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 921fdf3af6..0859fb64dd 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 180906
+%define version 7.0NG.727
+%define release 180917
# 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 d0a1fa42c9..fd63d12eae 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 180906
+%define version 7.0NG.727
+%define release 180917
%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 0a0227b4ac..57c5e8b9fb 100644
--- a/pandora_console/pandoradb.sql
+++ b/pandora_console/pandoradb.sql
@@ -1242,6 +1242,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;
@@ -1381,6 +1382,7 @@ CREATE TABLE IF NOT EXISTS `tlayout_data` (
`border_color` varchar(200) DEFAULT "",
`fill_color` varchar(200) DEFAULT "",
`show_statistics` tinyint(2) NOT NULL default '0',
+ `linked_layout_node_id` INT(10) NOT NULL default 0,
`linked_layout_status_type` ENUM ('default', 'weight', 'service') DEFAULT 'default',
`id_layout_linked_weight` int(10) NOT NULL default '0',
`linked_layout_status_as_service_warning` FLOAT(20, 3) NOT NULL default 0,
@@ -2363,6 +2365,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,
@@ -3315,6 +3318,7 @@ CREATE TABLE IF NOT EXISTS `tlayout_template_data` (
`border_color` varchar(200) DEFAULT "",
`fill_color` varchar(200) DEFAULT "",
`show_statistics` tinyint(2) NOT NULL default '0',
+ `linked_layout_node_id` INT(10) NOT NULL default 0,
`linked_layout_status_type` ENUM ('default', 'weight', 'service') DEFAULT 'default',
`id_layout_linked_weight` int(10) NOT NULL default '0',
`linked_layout_status_as_service_warning` FLOAT(20, 3) NOT NULL default 0,
diff --git a/pandora_console/pandoradb_data.sql b/pandora_console/pandoradb_data.sql
index 7ab1986d09..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'),
diff --git a/pandora_server/DEBIAN/control b/pandora_server/DEBIAN/control
index 205d389bd7..a236fd3c35 100644
--- a/pandora_server/DEBIAN/control
+++ b/pandora_server/DEBIAN/control
@@ -1,5 +1,5 @@
package: pandorafms-server
-Version: 7.0NG.726-180906
+Version: 7.0NG.727-180917
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 c1337b23bf..0745faf6e3 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-180906"
+pandora_version="7.0NG.727-180917"
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 5148faa971..3614e0cade 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 = "180906";
+my $pandora_version = "7.0NG.727";
+my $pandora_build = "180917";
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 4f4a2e39b4..ff15f60fe5 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 = "180906";
+my $pandora_version = "7.0NG.727";
+my $pandora_build = "180917";
our $VERSION = $pandora_version." ".$pandora_build;
our %EXPORT_TAGS = ( 'all' => [ qw() ] );
diff --git a/pandora_server/pandora_server.redhat.spec b/pandora_server/pandora_server.redhat.spec
index c4acf995e2..143c57bf27 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 180906
+%define version 7.0NG.727
+%define release 180917
Summary: Pandora FMS Server
Name: %{name}
diff --git a/pandora_server/pandora_server.spec b/pandora_server/pandora_server.spec
index 7f338028c0..31f9abd260 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 180906
+%define version 7.0NG.727
+%define release 180917
Summary: Pandora FMS Server
Name: %{name}
diff --git a/pandora_server/pandora_server_installer b/pandora_server/pandora_server_installer
index 74036a3011..1b766a7217 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="180906"
+PI_VERSION="7.0NG.727"
+PI_BUILD="180917"
MODE=$1
if [ $# -gt 1 ]; then
diff --git a/pandora_server/util/pandora_db.pl b/pandora_server/util/pandora_db.pl
index 052fb836db..2e1a13f5f8 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 PS180906";
+my $version = "7.0NG.727 PS180917";
# Pandora server configuration
my %conf;
diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl
index b9cb771727..42732f4763 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 PS180906";
+my $version = "7.0NG.727 PS180917";
# 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