Merge branch '3170-Cambios_custom_fields_view' into 'develop'

3170 cambios custom fields view

See merge request artica/pandorafms!2056

Former-commit-id: e1f50b89d6a04b927e8ada9f2899a16c1f7cdf59
This commit is contained in:
vgilc 2018-12-10 13:44:28 +01:00
commit 3e678f3284
3 changed files with 124 additions and 63 deletions

View File

@ -484,21 +484,23 @@ if($append_tab_filter){
$table->id = 'save_filter_form'; $table->id = 'save_filter_form';
$table->width = '100%'; $table->width = '100%';
$table->class = 'databox'; $table->class = 'databox';
$table->rowspan = array();
if($filters['id'] == 'extended_create_filter'){ if($filters['id'] == 'extended_create_filter'){
echo "<div id='msg_error_create'></div>"; echo "<div id='msg_error_create'></div>";
$table->data[0][0] = __('Filter name'); $table->data[0][0] = __('Filter name');
$table->data[0][1] = html_print_input_text('id_name', '', '', 15, 255, true); $table->data[0][1] = html_print_input_text('id_name', '', '', 15, 255, true);
$table->data[0][2] = __('Group'); $table->data[1][0] = __('Group');
$table->data[0][3] = html_print_select_groups( $table->data[1][1] = html_print_select_groups(
$config['id_user'], 'AR', true, 'group_search_cr', $config['id_user'], 'AR', true, 'group_search_cr',
0, '', '', '0', true, false, 0, '', '', '0', true, false,
false, '', false, '', false, false, false, '', false, 'width:180px;', false, false,
'id_grupo', false 'id_grupo', false
); );
$table->data[0][4] = html_print_submit_button (__('Create filter'), 'create_filter', false, 'class="sub upd"', true); $table->rowspan[0][2] = 2;
$table->data[0][2] = html_print_submit_button (__('Create filter'), 'create_filter', false, 'class="sub upd"', true);
} }
else{ else{
echo "<div id='msg_error_update'></div>"; echo "<div id='msg_error_update'></div>";
@ -516,7 +518,7 @@ if($append_tab_filter){
$table->data[1][1] = html_print_select_groups( $table->data[1][1] = html_print_select_groups(
$config['id_user'], 'AR', true, 'group_search_up', $config['id_user'], 'AR', true, 'group_search_up',
$group, '', '', '0', true, false, $group, '', '', '0', true, false,
false, '', false, '', false, false, false, '', false, 'width:180px;', false, false,
'id_grupo', false 'id_grupo', false
); );

View File

@ -193,6 +193,13 @@ function get_custom_fields_data ($custom_field_name) {
function agent_counters_custom_fields($filters){ function agent_counters_custom_fields($filters){
//filter by status agent //filter by status agent
$and_status = ""; $and_status = "";
$agent_state_normal = 0;
$agent_state_critical = 0;
$agent_state_warning = 0;
$agent_state_unknown = 0;
$agent_state_notinit = 0;
$agent_state_total = 0;
if(is_array($filters['id_status'])){ if(is_array($filters['id_status'])){
if(!in_array(-1, $filters['id_status'])){ if(!in_array(-1, $filters['id_status'])){
if(!in_array(AGENT_MODULE_STATUS_NOT_NORMAL, $filters['id_status'])){ if(!in_array(AGENT_MODULE_STATUS_NOT_NORMAL, $filters['id_status'])){
@ -200,34 +207,34 @@ function agent_counters_custom_fields($filters){
$and_status = " AND ( "; $and_status = " AND ( ";
foreach ($filters['id_status'] as $key => $value) { foreach ($filters['id_status'] as $key => $value) {
$and_status .= ($key != 0) $and_status .= ($key != 0)
? " OR (" ? " OR "
: " ("; : " ";
switch ($value) { switch ($value) {
default: default:
case AGENT_STATUS_NORMAL: case AGENT_STATUS_NORMAL:
$and_status .= " ta.critical_count = 0 $agent_state_normal = agents_get_status_clause(AGENT_STATUS_NORMAL);
AND ta.warning_count = 0 $and_status .= agents_get_status_clause(AGENT_STATUS_NORMAL);
AND ta.unknown_count = 0
AND ta.total_count <> ta.notinit_count ) ";
break; break;
case AGENT_STATUS_CRITICAL: case AGENT_STATUS_CRITICAL:
$and_status .= " ta.critical_count > 0 ) "; $and_status .= agents_get_status_clause(AGENT_STATUS_CRITICAL);
$agent_state_critical = agents_get_status_clause(AGENT_STATUS_CRITICAL);
break; break;
case AGENT_STATUS_WARNING: case AGENT_STATUS_WARNING:
$and_status .= " ta.critical_count = 0 $and_status .= agents_get_status_clause(AGENT_STATUS_WARNING);
AND ta.warning_count > 0 ) "; $agent_state_warning = agents_get_status_clause(AGENT_STATUS_WARNING);
break; break;
case AGENT_STATUS_UNKNOWN: case AGENT_STATUS_UNKNOWN:
$and_status .= " ta.critical_count = 0 $and_status .= agents_get_status_clause(AGENT_STATUS_UNKNOWN);
AND ta.warning_count = 0 $agent_state_unknown = agents_get_status_clause(AGENT_STATUS_UNKNOWN);
AND ta.unknown_count > 0 ) ";
break; break;
case AGENT_STATUS_NOT_INIT: case AGENT_STATUS_NOT_INIT:
$and_status .= " ta.total_count = ta.notinit_count ) "; $and_status .= agents_get_status_clause(AGENT_STATUS_NOT_INIT);
$agent_state_notinit = agents_get_status_clause(AGENT_STATUS_NOT_INIT);
break; break;
} }
} }
$and_status .= " ) "; $and_status .= " ) ";
$agent_state_total = agents_get_status_clause(AGENT_STATUS_ALL);
} }
} }
else{ else{
@ -237,14 +244,45 @@ function agent_counters_custom_fields($filters){
OR ( ta.critical_count = 0 AND ta.warning_count = 0 AND ta.unknown_count > 0 ) OR ( ta.critical_count = 0 AND ta.warning_count = 0 AND ta.unknown_count > 0 )
OR ( ta.total_count = ta.notinit_count ) OR ( ta.total_count = ta.notinit_count )
) "; ) ";
$agent_state_critical = agents_get_status_clause(AGENT_STATUS_CRITICAL);
$agent_state_warning = agents_get_status_clause(AGENT_STATUS_WARNING);
$agent_state_unknown = agents_get_status_clause(AGENT_STATUS_UNKNOWN);
$agent_state_notinit = agents_get_status_clause(AGENT_STATUS_NOT_INIT);
$agent_state_total = agents_get_status_clause(AGENT_STATUS_ALL);
} }
} }
else{
$agent_state_normal = agents_get_status_clause(AGENT_STATUS_NORMAL);
$agent_state_critical = agents_get_status_clause(AGENT_STATUS_CRITICAL);
$agent_state_warning = agents_get_status_clause(AGENT_STATUS_WARNING);
$agent_state_unknown = agents_get_status_clause(AGENT_STATUS_UNKNOWN);
$agent_state_notinit = agents_get_status_clause(AGENT_STATUS_NOT_INIT);
$agent_state_total = agents_get_status_clause(AGENT_STATUS_ALL);
}
} }
//filter by status module //filter by status module
$empty_agents_count = "UNION ALL
SELECT ta.id_agente,
0 AS c_m_total,
0 AS mm_normal,
0 AS mm_critical,
0 AS mm_warning,
0 AS mm_unknown,
0 AS mm_not_init,
0 AS mm_total
FROM tagente ta
LEFT JOIN tagent_secondary_group tasg
ON ta.id_agente = tasg.id_agent
WHERE ta.disabled = 0
AND ta.total_count = 0
$groups_and";
$and_module_status = ""; $and_module_status = "";
if(is_array($filters['module_status'])){ if(is_array($filters['module_status'])){
if(!in_array(-1, $filters['module_status'])){ if(!in_array(-1, $filters['module_status'])){
$empty_agents_count = "";
if(!in_array(AGENT_MODULE_STATUS_NOT_NORMAL, $filters['module_status'])){ if(!in_array(AGENT_MODULE_STATUS_NOT_NORMAL, $filters['module_status'])){
if(count($filters['module_status']) > 0){ if(count($filters['module_status']) > 0){
$and_module_status = " AND ( "; $and_module_status = " AND ( ";
@ -277,25 +315,15 @@ function agent_counters_custom_fields($filters){
else{ else{
//not normal //not normal
$and_module_status = "AND tae.estado <> 0 AND tae.estado <> 300 "; $and_module_status = "AND tae.estado <> 0 AND tae.estado <> 300 ";
$empty_agents_count = "";
} }
} }
} }
//filters module //filters module
if($filters['module_search']){ if($filters['module_search']){
$and_module_search = 'AND nombre LIKE "%' . $filters['module_search'] . '%"'; $and_module_search = 'AND tam.nombre LIKE "%' . $filters['module_search'] . '%"';
} $empty_agents_count = "";
$module_filter = "";
if($and_module_search != '' || $and_module_status != ''){
$module_filter = ' AND (
SELECT count(*) AS n
FROM tagente_modulo tam
INNER JOIN tagente_estado tae
ON tae.id_agente_modulo = tam.id_agente_modulo
WHERE tam.id_agente=ta.id_agente
'. $and_module_search . ' ' . $and_module_status .'
) > 0 ';
} }
//filter group and check ACL groups //filter group and check ACL groups
@ -359,42 +387,63 @@ function agent_counters_custom_fields($filters){
// Establishes connection // Establishes connection
if (metaconsole_load_external_db ($server_data) !== NOERR) continue; if (metaconsole_load_external_db ($server_data) !== NOERR) continue;
$query = sprintf("SELECT $query = sprintf(
tcd.description as name_data, "SELECT tcd.description AS name_data,
SUM(ta.normal_count) AS m_normal, SUM(IF($agent_state_total, 1, 0)) AS a_agents,
SUM(ta.critical_count) AS m_critical, SUM(IF($agent_state_critical, 1, 0)) AS a_critical,
SUM(ta.warning_count) AS m_warning, SUM(IF($agent_state_warning, 1, 0)) AS a_warning,
SUM(ta.unknown_count) AS m_unknown, SUM(IF($agent_state_unknown, 1, 0)) AS a_unknown,
SUM(ta.notinit_count) AS m_not_init, SUM(IF($agent_state_normal, 1, 0)) AS a_normal,
SUM(ta.fired_count) AS m_alerts, SUM(IF($agent_state_notinit, 1, 0)) AS a_not_init,
SUM(ta.total_count) AS m_total, SUM(tagent_counters.mm_normal) AS m_normal,
SUM(IF(ta.critical_count > 0, 1, 0)) AS a_critical, SUM(tagent_counters.mm_critical) AS m_critical,
SUM(IF(ta.critical_count = 0 AND ta.warning_count > 0, 1, 0)) AS a_warning, SUM(tagent_counters.mm_warning) AS m_warning,
SUM(IF(ta.critical_count = 0 AND ta.warning_count = 0 AND ta.unknown_count > 0, 1, 0)) AS a_unknown, SUM(tagent_counters.mm_unknown) AS m_unknown,
SUM(IF(ta.critical_count = 0 AND ta.warning_count = 0 AND ta.unknown_count = 0 AND ta.notinit_count <> ta.total_count, 1, 0)) AS a_normal, SUM(tagent_counters.mm_not_init) AS m_not_init,
SUM(IF(ta.total_count = ta.notinit_count, 1, 0)) AS a_not_init, SUM(tagent_counters.mm_total) AS m_total
COUNT(ta.id_agente) AS a_agents, FROM tagent_custom_data tcd
GROUP_CONCAT(DISTINCT(ta.id_agente) SEPARATOR ',') as ids
FROM tagente ta
INNER JOIN tagent_custom_data tcd
ON tcd.id_agent = ta.id_agente
INNER JOIN tagent_custom_fields tcf INNER JOIN tagent_custom_fields tcf
ON tcd.id_field = tcf.id_field ON tcd.id_field = tcf.id_field
INNER JOIN (
SELECT ta.id_agente,
ta.total_count AS c_m_total,
SUM( IF(tae.estado = 0, 1, 0) ) AS mm_normal,
SUM( IF(tae.estado = 1, 1, 0) ) AS mm_critical,
SUM( IF(tae.estado = 2, 1, 0) ) AS mm_warning,
SUM( IF(tae.estado = 3, 1, 0) ) AS mm_unknown,
SUM( IF(tae.estado = 4 OR tae.estado = 5, 1, 0) ) AS mm_not_init,
COUNT(tam.id_agente_modulo) AS mm_total
FROM tagente ta
LEFT JOIN tagent_secondary_group tasg LEFT JOIN tagent_secondary_group tasg
ON ta.id_agente = tasg.id_agent ON ta.id_agente = tasg.id_agent
INNER JOIN tagente_modulo tam
ON ta.id_agente = tam.id_agente
INNER JOIN tagente_estado tae
ON tam.id_agente = tae.id_agente
AND tam.id_agente_modulo = tae.id_agente_modulo
WHERE ta.disabled = 0 WHERE ta.disabled = 0
AND tcf.name = '%s' AND tam.disabled = 0
%s
%s
%s
%s
GROUP by ta.id_agente
%s
) AS tagent_counters
ON tcd.id_agent = tagent_counters.id_agente
INNER JOIN tagente ta
ON ta.id_agente = tagent_counters.id_agente
WHERE tcf.name = '%s'
AND tcd.description <> '' AND tcd.description <> ''
%s %s
%s
%s
%s
GROUP BY tcd.description", GROUP BY tcd.description",
$custom_field_name,
$custom_data_and,
$groups_and, $groups_and,
$and_status, $and_status,
$module_filter $and_module_search,
$and_module_status,
$empty_agents_count,
$custom_field_name,
$custom_data_and
); );
$result_meta[$server_data['id']] = db_get_all_rows_sql($query); $result_meta[$server_data['id']] = db_get_all_rows_sql($query);
@ -406,6 +455,11 @@ function agent_counters_custom_fields($filters){
FROM tagente ta FROM tagente ta
LEFT JOIN tagent_secondary_group tasg LEFT JOIN tagent_secondary_group tasg
ON ta.id_agente = tasg.id_agent ON ta.id_agente = tasg.id_agent
INNER JOIN tagente_modulo tam
ON ta.id_agente = tam.id_agente
INNER JOIN tagente_estado tae
ON tam.id_agente = tae.id_agente
AND tam.id_agente_modulo = tae.id_agente_modulo
INNER JOIN tagent_custom_data tcd INNER JOIN tagent_custom_data tcd
ON tcd.id_agent = ta.id_agente ON tcd.id_agent = ta.id_agente
INNER JOIN tagent_custom_fields tcf INNER JOIN tagent_custom_fields tcf
@ -413,22 +467,28 @@ function agent_counters_custom_fields($filters){
WHERE ta.disabled = 0 WHERE ta.disabled = 0
AND tcf.name = '%s' AND tcf.name = '%s'
AND tcd.description <> '' AND tcd.description <> ''
AND tam.disabled = 0
%s %s
%s %s
%s %s
%s %s
%s
GROUP BY ta.id_agente
", ",
$server_data['id'], $server_data['id'],
$custom_field_name, $custom_field_name,
$custom_data_and, $custom_data_and,
$groups_and, $groups_and,
$and_status, $and_status,
$module_filter $and_module_search,
$and_module_status
); );
$node_result = db_get_all_rows_sql($query_data); $node_result = db_get_all_rows_sql($query_data);
if (empty($node_result)) $node_result = array(); if (empty($node_result)) $node_result = array();
$data = array_merge($data, $node_result); $data = array_merge($data, $node_result);
// Restore connection to root node // Restore connection to root node
metaconsole_restore_db(); metaconsole_restore_db();
@ -455,7 +515,6 @@ function agent_counters_custom_fields($filters){
't_a_not_init' => 0, 't_a_not_init' => 0,
't_a_agents' => 0 't_a_agents' => 0
); );
foreach ($result_meta as $k => $nodo) { foreach ($result_meta as $k => $nodo) {
if(isset($nodo) && is_array($nodo)){ if(isset($nodo) && is_array($nodo)){
foreach ($nodo as $key => $value) { foreach ($nodo as $key => $value) {

View File

@ -10361,7 +10361,7 @@ function reporting_label_macro ($item, $label) {
case 'MTTR': case 'MTTR':
case 'automatic_graph': case 'automatic_graph':
if (preg_match("/_agent_/", $label)) { if (preg_match("/_agent_/", $label)) {
if (count($item['agents']) > 1) { if (isset($item['agents']) && count($item['agents']) > 1) {
$agent_name = count($item['agents']) . __(' agents'); $agent_name = count($item['agents']) . __(' agents');
} }
else { else {