diff --git a/pandora_console/include/ajax/custom_fields.php b/pandora_console/include/ajax/custom_fields.php
index 0cb9626e7f..f67d7971bc 100644
--- a/pandora_console/include/ajax/custom_fields.php
+++ b/pandora_console/include/ajax/custom_fields.php
@@ -1,17 +1,33 @@
$value) {
- $values_insert[] = '('.$value['id_server'].', '.$value['id_agente'].", '".$value['description']."', ".$value['status'].')';
+ $values_insert[] = '('.$value['id_server'].', '.$value['id_agente'].", '".$value['description']."', '".$value['critical_count']."', '".$value['warning_count']."', '".$value['unknown_count']."', '".$value['notinit_count']."', '".$value['normal_count']."', '".$value['total_count']."', ".$value['status'].')';
}
$values_insert_implode = implode(',', $values_insert);
$query_insert = 'INSERT INTO temp_custom_fields VALUES '.$values_insert_implode;
db_process_sql($query_insert);
- // search table for alias, custom field data, server_name, direction
+ // Search table for alias, custom field data, server_name, direction.
$search_query = '';
if ($search['value'] != '') {
$search_query = ' AND (tma.alias LIKE "%'.$search['value'].'%"';
@@ -95,7 +134,61 @@ if (check_login()) {
$search_query .= ' OR temp.name_custom_fields LIKE "%'.$search['value'].'%" ) ';
}
- // query all fields result
+ // Search for status module.
+ $status_agent_search = '';
+ if (isset($id_status) === true && is_array($id_status) === true) {
+ if (in_array(-1, $id_status) === false) {
+ if (in_array(AGENT_MODULE_STATUS_NOT_NORMAL, $id_status) === false) {
+ $status_agent_search = ' AND temp.status IN ('.implode(',', $id_status).')';
+ } else {
+ // Not normal statuses.
+ $status_agent_search = ' AND temp.status IN (1,2,3,4,5)';
+ }
+ }
+ }
+
+ // Search for status module.
+ $status_module_search = '';
+ if (isset($module_status) === true && is_array($module_status) === true) {
+ if (in_array(-1, $module_status) === false) {
+ if (in_array(AGENT_MODULE_STATUS_NOT_NORMAL, $module_status) === false) {
+ if (count($module_status) > 0) {
+ $status_module_search = ' AND ( ';
+ foreach ($module_status as $key => $value) {
+ $status_module_search .= ($key != 0) ? ' OR (' : ' (';
+ switch ($value) {
+ default:
+ case AGENT_STATUS_NORMAL:
+ $status_module_search .= ' temp.critical_count = 0 AND temp.warning_count = 0 AND temp.unknown_count = 0 AND temp.notinit_count <> temp.total_count ) ';
+ break;
+ case AGENT_STATUS_CRITICAL:
+ $status_module_search .= ' temp.critical_count > 0) ';
+ break;
+
+ case AGENT_STATUS_WARNING:
+ $status_module_search .= ' temp.critical_count = 0 AND temp.warning_count > 0) ';
+ break;
+
+ case AGENT_STATUS_UNKNOWN:
+ $status_module_search .= ' temp.critical_count = 0 AND temp.warning_count = 0 AND temp.unknown_count > 0) ';
+ break;
+
+ case AGENT_STATUS_NOT_INIT:
+ $status_module_search .= ' temp.total_count = temp.notinit_count) ';
+ break;
+ }
+ }
+
+ $status_module_search .= ' ) ';
+ }
+ } else {
+ // Not normal.
+ $status_module_search = ' AND NOT ( temp.critical_count = 0 AND temp.warning_count = 0 AND temp.unknown_count = 0 AND temp.notinit_count <> temp.total_count)';
+ }
+ }
+ }
+
+ // Query all fields result.
$query = sprintf(
'SELECT
tma.id_agente,
@@ -112,10 +205,14 @@ if (check_login()) {
AND temp.id_server = tma.id_tmetaconsole_setup
WHERE tma.disabled = 0
%s
+ %s
+ %s
%s
LIMIT %d OFFSET %d
',
$search_query,
+ $status_agent_search,
+ $status_module_search,
$order_by,
$length,
$start
@@ -123,23 +220,27 @@ if (check_login()) {
$result = db_get_all_rows_sql($query);
- // query count
+ // Query count.
$query_count = sprintf(
'SELECT
COUNT(tma.id_agente) AS `count`
- FROM tmetaconsole_agent tma
- INNER JOIN temp_custom_fields temp
- ON temp.id_agent = tma.id_tagente
- AND temp.id_server = tma.id_tmetaconsole_setup
- WHERE tma.disabled = 0
- %s
- ',
- $search_query
+ FROM tmetaconsole_agent tma
+ INNER JOIN temp_custom_fields temp
+ ON temp.id_agent = tma.id_tagente
+ AND temp.id_server = tma.id_tmetaconsole_setup
+ WHERE tma.disabled = 0
+ %s
+ %s
+ %s
+ ',
+ $search_query,
+ $status_agent_search,
+ $status_module_search
);
$count = db_get_sql($query_count);
- // for link nodes.
+ // For link nodes.
$array_nodes = metaconsole_get_connections();
if (isset($array_nodes) && is_array($array_nodes)) {
$hash_array_nodes = [];
@@ -158,20 +259,20 @@ if (check_login()) {
$user_rot13 = str_rot13($config['id_user']);
$hashdata = $user.$pwd;
$hashdata = md5($hashdata);
- $url_hash = '&'.'loginhash=auto&'.'loginhash_data='.$hashdata.'&'.'loginhash_user='.$user_rot13;
+ $url_hash = '&loginhash=auto&loginhash_data='.$hashdata.'&loginhash_user='.$user_rot13;
$hash_array_nodes[$server['id']]['hashurl'] = $url_hash;
$hash_array_nodes[$server['id']]['server_url'] = $server['server_url'];
}
}
- // prepare rows for table dinamic
+ // Prepare rows for table dinamic.
$data = [];
foreach ($result as $values) {
$image_status = agents_get_image_status($values['status']);
- // link nodes
- $agent_link = '';
+ // Link nodes.
+ $agent_link = '';
$agent_alias = ui_print_truncate_text(
$values['alias'],
@@ -225,7 +326,7 @@ if (check_login()) {
$name_where = " AND tam.nombre LIKE '%".$module_search."%'";
}
- // filter by status module
+ // Filter by status module.
$and_module_status = '';
if (is_array($module_status)) {
if (!in_array(-1, $module_status)) {
@@ -260,7 +361,7 @@ if (check_login()) {
$and_module_status .= ' ) ';
}
} else {
- // not normal
+ // Not normal.
$and_module_status = 'AND tae.estado <> 0 AND tae.estado <> 300 ';
}
}
@@ -314,7 +415,12 @@ if (check_login()) {
&& $value['id_tipo_modulo'] != 23
&& $value['id_tipo_modulo'] != 33
) {
- $table_modules->data[$key][1] = remove_right_zeros(number_format($value['datos'], $config['graph_precision']));
+ $table_modules->data[$key][1] = remove_right_zeros(
+ number_format(
+ $value['datos'],
+ $config['graph_precision']
+ )
+ );
} else {
$table_modules->data[$key][1] = $value['datos'];
}
@@ -329,7 +435,10 @@ if (check_login()) {
);
$table_modules->data[$key][3] = $value['current_interval'];
- $table_modules->data[$key][4] = ui_print_timestamp($value['utimestamp'], true);
+ $table_modules->data[$key][4] = ui_print_timestamp(
+ $value['utimestamp'],
+ true
+ );
switch ($value['estado']) {
case 0:
case 300:
@@ -398,7 +507,7 @@ if (check_login()) {
}
}
- // status agents from tagente
+ // Status agents from tagente.
$sql_info_agents = 'SELECT * fROM tagente WHERE id_agente ='.$id_agent;
$info_agents = db_get_row_sql($sql_info_agents);
$status_agent = agents_get_status_from_counts($info_agents);
@@ -463,7 +572,13 @@ if (check_login()) {
false
);
- $table->data[0][3] = html_print_submit_button(__('Load filter'), 'load_filter', false, 'class="sub upd"', true);
+ $table->data[0][3] = html_print_submit_button(
+ __('Load filter'),
+ 'load_filter',
+ false,
+ 'class="sub upd"',
+ true
+ );
echo "