#8533 added show module data (report)

This commit is contained in:
Daniel Maya 2022-03-23 16:59:15 +01:00
parent ff60967bdf
commit 98aebc4587
6 changed files with 299 additions and 223 deletions

View File

@ -760,6 +760,11 @@ switch ($action) {
);
$selection_a_m = get_parameter('selection');
if (isset($es['show_type']) === true) {
$show_type = $es['show_type'];
}
$recursion = $item['recursion'];
$group = $item['id_group'];
@ -1833,6 +1838,33 @@ $class = 'databox filters';
</td>
</tr>
<tr id="row_type_show" class="datos">
<td class="bolder"><?php echo __('Information to be show'); ?></td>
<td>
<?php
$show_select = [
0 => __('Show module status'),
1 => __('Show module data'),
];
html_print_select(
$show_select,
'show_type',
$show_type,
'',
'',
0,
false,
false,
true,
'',
false,
'min-width: 180px'
);
?>
</td>
</tr>
<tr id="row_alert_templates" class="datos">
<td class="bolder"><?php echo __('Templates'); ?></td>
<td>
@ -5925,6 +5957,7 @@ function chooseType() {
$("#row_agent_not_assigned_to_ip").hide();
$("#row_show_summary").hide();
$("#row_group_by").hide();
$("#row_type_show").hide();
// SLA list default state.
$("#sla_list").hide();
@ -6438,6 +6471,7 @@ function chooseType() {
case 'agent_module':
$("#row_module_group").show();
$("#row_type_show").show();
case 'agent_module_status':
$("#row_description").show();
$("#row_group").show();

View File

@ -1677,6 +1677,7 @@ switch ($action) {
// Encode json modules and agents.
$es['module'] = base64_encode(json_encode($es['module']));
$es['id_agents'] = base64_encode(json_encode($agents_to_report));
$es['show_type'] = get_parameter('show_type', 0);
$values['external_source'] = json_encode($es);
$good_format = true;
@ -2480,6 +2481,7 @@ switch ($action) {
// Encode json modules and agents.
$es['module'] = base64_encode(json_encode($es['module']));
$es['id_agents'] = base64_encode(json_encode($agents_to_report));
$es['show_type'] = get_parameter('show_type', 0);
$values['external_source'] = json_encode($es);
$good_format = true;

View File

@ -2802,6 +2802,12 @@ function reporting_agent_module($report, $content)
true
);
if (isset($external_source['show_type']) === true) {
$show_type = $external_source['show_type'];
} else {
$show_type = 0;
}
$return['type'] = 'agent_module';
if (empty($content['name'])) {
@ -2838,6 +2844,10 @@ function reporting_agent_module($report, $content)
modules_get_agentmodule_name($modul_id)
);
$modules_by_name[$cont]['id'] = $modul_id;
if ($show_type === '1') {
$modules_by_name[$cont]['unit'] = modules_get_unit($modul_id);
}
$cont++;
}
@ -2853,7 +2863,18 @@ function reporting_agent_module($report, $content)
$row['modules'] = [];
foreach ($modules_by_name as $module) {
if (array_key_exists($module['id'], $agent_modules)) {
$row['modules'][$module['name']] = modules_get_agentmodule_status($module['id']);
if ($show_type === '1') {
$module_last_value = modules_get_last_value($module['id']);
if (!is_numeric($module_last_value)) {
$module_last_value = htmlspecialchars($module_last_value);
}
$module['datos'] = $module_last_value;
$row['modules'][$module['name']] = modules_get_agentmodule_data_for_humans($module);
$row['show_type'] = $show_type;
} else {
$row['modules'][$module['name']] = modules_get_agentmodule_status($module['id']);
}
} else {
if (!array_key_exists($module['name'], $row['modules'])) {
$row['modules'][$module['name']] = null;

View File

@ -1872,111 +1872,115 @@ function reporting_html_agent_module($table, $item)
$table_data .= "<td class='bg_dd;'></td>";
} else {
$table_data .= "<td class='center bg_ddd'>";
switch ($module) {
default:
case AGENT_STATUS_NORMAL:
$table_data .= ui_print_status_image(
'module_ok.png',
__(
'%s in %s : NORMAL',
$module_name,
$row['agent_name']
),
true,
[
'width' => '20px',
'height' => '20px',
],
'images/status_sets/default/'
);
break;
if (isset($row['show_type']) === true && $row['show_type'] === '1') {
$table_data .= $module;
} else {
switch ($module) {
case AGENT_STATUS_CRITICAL:
$table_data .= ui_print_status_image(
'module_critical.png',
__(
'%s in %s : CRITICAL',
$module_name,
$row['agent_name']
),
true,
[
'width' => '20px',
'height' => '20px',
],
'images/status_sets/default/'
);
break;
case AGENT_STATUS_CRITICAL:
$table_data .= ui_print_status_image(
'module_critical.png',
__(
'%s in %s : CRITICAL',
$module_name,
$row['agent_name']
),
true,
[
'width' => '20px',
'height' => '20px',
],
'images/status_sets/default/'
);
break;
case AGENT_STATUS_WARNING:
$table_data .= ui_print_status_image(
'module_warning.png',
__(
'%s in %s : WARNING',
$module_name,
$row['agent_name']
),
true,
[
'width' => '20px',
'height' => '20px',
],
'images/status_sets/default/'
);
break;
case AGENT_STATUS_WARNING:
$table_data .= ui_print_status_image(
'module_warning.png',
__(
'%s in %s : WARNING',
$module_name,
$row['agent_name']
),
true,
[
'width' => '20px',
'height' => '20px',
],
'images/status_sets/default/'
);
break;
case AGENT_STATUS_UNKNOWN:
$table_data .= ui_print_status_image(
'module_unknown.png',
__(
'%s in %s : UNKNOWN',
$module_name,
$row['agent_name']
),
true,
[
'width' => '20px',
'height' => '20px',
],
'images/status_sets/default/'
);
break;
case AGENT_STATUS_UNKNOWN:
$table_data .= ui_print_status_image(
'module_unknown.png',
__(
'%s in %s : UNKNOWN',
$module_name,
$row['agent_name']
),
true,
[
'width' => '20px',
'height' => '20px',
],
'images/status_sets/default/'
);
break;
case AGENT_MODULE_STATUS_NORMAL_ALERT:
case AGENT_MODULE_STATUS_WARNING_ALERT:
case AGENT_MODULE_STATUS_CRITICAL_ALERT:
$table_data .= ui_print_status_image(
'module_alertsfired.png',
__(
'%s in %s : ALERTS FIRED',
$module_name,
$row['agent_name']
),
true,
[
'width' => '20px',
'height' => '20px',
],
'images/status_sets/default/'
);
break;
case AGENT_MODULE_STATUS_NORMAL_ALERT:
case AGENT_MODULE_STATUS_WARNING_ALERT:
case AGENT_MODULE_STATUS_CRITICAL_ALERT:
$table_data .= ui_print_status_image(
'module_alertsfired.png',
__(
'%s in %s : ALERTS FIRED',
$module_name,
$row['agent_name']
),
true,
[
'width' => '20px',
'height' => '20px',
],
'images/status_sets/default/'
);
break;
case 4:
$table_data .= ui_print_status_image(
'module_no_data.png',
__(
'%s in %s : Not initialize',
$module_name,
$row['agent_name']
),
true,
[
'width' => '20px',
'height' => '20px',
],
'images/status_sets/default/'
);
break;
case 4:
$table_data .= ui_print_status_image(
'module_no_data.png',
__(
'%s in %s : Not initialize',
$module_name,
$row['agent_name']
),
true,
[
'width' => '20px',
'height' => '20px',
],
'images/status_sets/default/'
);
break;
default:
case AGENT_STATUS_NORMAL:
$table_data .= ui_print_status_image(
'module_ok.png',
__(
'%s in %s : NORMAL',
$module_name,
$row['agent_name']
),
true,
[
'width' => '20px',
'height' => '20px',
],
'images/status_sets/default/'
);
break;
}
}
$table_data .= '</td>';
@ -1986,18 +1990,19 @@ function reporting_html_agent_module($table, $item)
$table_data .= '</table>';
$table_data .= "<div class='legend_basic w96p'>";
$table_data .= '<table>';
$table_data .= "<tr><td colspan='2' class='pdd_b_10px'><b>".__('Legend').'</b></td></tr>';
$table_data .= "<tr><td class='legend_square_simple'><div style='background-color: ".COL_ALERTFIRED.";'></div></td><td>".__('Orange cell when the module has fired alerts').'</td></tr>';
$table_data .= "<tr><td class='legend_square_simple'><div style='background-color: ".COL_CRITICAL.";'></div></td><td>".__('Red cell when the module has a critical status').'</td></tr>';
$table_data .= "<tr><td class='legend_square_simple'><div style='background-color: ".COL_WARNING.";'></div></td><td>".__('Yellow cell when the module has a warning status').'</td></tr>';
$table_data .= "<tr><td class='legend_square_simple'><div style='background-color: ".COL_NORMAL.";'></div></td><td>".__('Green cell when the module has a normal status').'</td></tr>';
$table_data .= "<tr><td class='legend_square_simple'><div style='background-color: ".COL_UNKNOWN.";'></div></td><td>".__('Grey cell when the module has an unknown status').'</td></tr>';
$table_data .= "<tr><td class='legend_square_simple'><div style='background-color: ".COL_NOTINIT.";'></div></td><td>".__("Cell turns grey when the module is in 'not initialize' status").'</td></tr>';
$table_data .= '</table>';
$table_data .= '</div>';
if (isset($row['show_type']) === false) {
$table_data .= "<div class='legend_basic w96p'>";
$table_data .= '<table>';
$table_data .= "<tr><td colspan='2' class='pdd_b_10px'><b>".__('Legend').'</b></td></tr>';
$table_data .= "<tr><td class='legend_square_simple'><div style='background-color: ".COL_ALERTFIRED.";'></div></td><td>".__('Orange cell when the module has fired alerts').'</td></tr>';
$table_data .= "<tr><td class='legend_square_simple'><div style='background-color: ".COL_CRITICAL.";'></div></td><td>".__('Red cell when the module has a critical status').'</td></tr>';
$table_data .= "<tr><td class='legend_square_simple'><div style='background-color: ".COL_WARNING.";'></div></td><td>".__('Yellow cell when the module has a warning status').'</td></tr>';
$table_data .= "<tr><td class='legend_square_simple'><div style='background-color: ".COL_NORMAL.";'></div></td><td>".__('Green cell when the module has a normal status').'</td></tr>';
$table_data .= "<tr><td class='legend_square_simple'><div style='background-color: ".COL_UNKNOWN.";'></div></td><td>".__('Grey cell when the module has an unknown status').'</td></tr>';
$table_data .= "<tr><td class='legend_square_simple'><div style='background-color: ".COL_NOTINIT.";'></div></td><td>".__("Cell turns grey when the module is in 'not initialize' status").'</td></tr>';
$table_data .= '</table>';
$table_data .= '</div>';
}
$table->data['agent_module']['cell'] = $table_data;
}

View File

@ -232,7 +232,6 @@ function fmModuleChange(uniqId, isMeta) {
selection: showCommonModules
},
function(data) {
debugger;
$("#filtered-module-modules-" + uniqId).html("");
if (data) {
jQuery.each(data, function(id, value) {

View File

@ -505,118 +505,126 @@ class AgentModuleWidget extends Widget
}
foreach ($row['modules'] as $module_name => $module) {
if ($module === null) {
if (in_array($module_name, $allModules) === true) {
$style = 'background-color: transparent;';
$table_data .= "<td style='".$style."'>";
$table_data .= '</td>';
} else {
continue;
}
} else {
if ($this->values['mTypeShow'] === '1') {
$style = 'text-align: center;';
$style .= ' background-color: transparent;';
$table_data .= "<td style='".$style."'>";
switch ($module) {
case AGENT_STATUS_NORMAL:
$table_data .= \ui_print_status_image(
'module_ok.png',
__(
'%s in %s : NORMAL',
$module_name,
$row['agent_alias']
),
true,
[
'width' => '20px',
'height' => '20px',
]
);
break;
case AGENT_STATUS_CRITICAL:
$table_data .= \ui_print_status_image(
'module_critical.png',
__(
'%s in %s : CRITICAL',
$module_name,
$row['agent_alias']
),
true,
[
'width' => '20px',
'height' => '20px',
]
);
break;
case AGENT_STATUS_WARNING:
$table_data .= \ui_print_status_image(
'module_warning.png',
__(
'%s in %s : WARNING',
$module_name,
$row['agent_alias']
),
true,
[
'width' => '20px',
'height' => '20px',
]
);
break;
case AGENT_STATUS_UNKNOWN:
$table_data .= \ui_print_status_image(
'module_unknown.png',
__(
'%s in %s : UNKNOWN',
$module_name,
$row['agent_alias']
),
true,
[
'width' => '20px',
'height' => '20px',
]
);
break;
case 4:
$table_data .= \ui_print_status_image(
'module_no_data.png',
__(
'%s in %s : Not initialize',
$module_name,
$row['agent_alias']
),
true,
[
'width' => '20px',
'height' => '20px',
]
);
break;
case AGENT_STATUS_ALERT_FIRED:
default:
$table_data .= \ui_print_status_image(
'module_alertsfired.png',
__(
'%s in %s : ALERTS FIRED',
$module_name,
$row['agent_alias']
),
true,
[
'width' => '20px',
'height' => '20px',
]
);
break;
}
$table_data .= $module;
$table_data .= '</td>';
} else {
if ($module === null) {
if (in_array($module_name, $allModules) === true) {
$style = 'background-color: transparent;';
$table_data .= "<td style='".$style."'>";
$table_data .= '</td>';
} else {
continue;
}
} else {
$style = 'text-align: center;';
$style .= ' background-color: transparent;';
$table_data .= "<td style='".$style."'>";
switch ($module) {
case AGENT_STATUS_NORMAL:
$table_data .= \ui_print_status_image(
'module_ok.png',
__(
'%s in %s : NORMAL',
$module_name,
$row['agent_alias']
),
true,
[
'width' => '20px',
'height' => '20px',
]
);
break;
case AGENT_STATUS_CRITICAL:
$table_data .= \ui_print_status_image(
'module_critical.png',
__(
'%s in %s : CRITICAL',
$module_name,
$row['agent_alias']
),
true,
[
'width' => '20px',
'height' => '20px',
]
);
break;
case AGENT_STATUS_WARNING:
$table_data .= \ui_print_status_image(
'module_warning.png',
__(
'%s in %s : WARNING',
$module_name,
$row['agent_alias']
),
true,
[
'width' => '20px',
'height' => '20px',
]
);
break;
case AGENT_STATUS_UNKNOWN:
$table_data .= \ui_print_status_image(
'module_unknown.png',
__(
'%s in %s : UNKNOWN',
$module_name,
$row['agent_alias']
),
true,
[
'width' => '20px',
'height' => '20px',
]
);
break;
case 4:
$table_data .= \ui_print_status_image(
'module_no_data.png',
__(
'%s in %s : Not initialize',
$module_name,
$row['agent_alias']
),
true,
[
'width' => '20px',
'height' => '20px',
]
);
break;
case AGENT_STATUS_ALERT_FIRED:
default:
$table_data .= \ui_print_status_image(
'module_alertsfired.png',
__(
'%s in %s : ALERTS FIRED',
$module_name,
$row['agent_alias']
),
true,
[
'width' => '20px',
'height' => '20px',
]
);
break;
}
$table_data .= '</td>';
}
}
}
@ -783,7 +791,14 @@ class AgentModuleWidget extends Widget
continue;
}
$visualData[$agent_id]['modules'][$module->name()] = $module->getStatus()->estado();
if ($this->values['mTypeShow'] === '1') {
$mod = $module->toArray();
$mod['datos'] = $module->lastValue();
$module_last_value = modules_get_agentmodule_data_for_humans($mod);
$visualData[$agent_id]['modules'][$module->name()] = $module_last_value;
} else {
$visualData[$agent_id]['modules'][$module->name()] = $module->getStatus()->estado();
}
}
if ((bool) is_metaconsole() === true) {