Merge branch 'ent-5346-Tipo-de-informe-que-obtenga-el-ultimo-valor-del-modulo' into 'develop'

New report last value

See merge request artica/pandorafms!3256
This commit is contained in:
Daniel Rodriguez 2020-06-25 12:18:37 +02:00
commit 0079f5d3b5
5 changed files with 268 additions and 3 deletions

View File

@ -484,6 +484,16 @@ switch ($action) {
$period = $item['period'];
break;
case 'last_value':
$description = $item['description'];
$idAgentModule = $item['id_agent_module'];
$idAgent = db_get_value_filter(
'id_agente',
'tagente_modulo',
['id_agente_modulo' => $idAgentModule]
);
break;
case 'alert_report_module':
$description = $item['description'];
$idAgentModule = $item['id_agent_module'];
@ -744,6 +754,7 @@ switch ($action) {
case 'historical_data':
case 'sumatory':
case 'database_serialized':
case 'last_value':
case 'monitor_report':
case 'min_value':
case 'max_value':
@ -3843,6 +3854,7 @@ $(document).ready (function () {
case 'min_value':
case 'monitor_report':
case 'database_serialized':
case 'last_value':
case 'sumatory':
case 'historical_data':
case 'agent_configuration':
@ -3884,6 +3896,7 @@ $(document).ready (function () {
case 'max_value':
case 'min_value':
case 'database_serialized':
case 'last_value':
case 'sumatory':
case 'historical_data':
case 'increment':
@ -3964,6 +3977,7 @@ $(document).ready (function () {
case 'min_value':
case 'monitor_report':
case 'database_serialized':
case 'last_value':
case 'sumatory':
case 'historical_data':
case 'agent_configuration':
@ -4003,6 +4017,7 @@ $(document).ready (function () {
case 'max_value':
case 'min_value':
case 'database_serialized':
case 'last_value':
case 'sumatory':
case 'historical_data':
case 'increment':
@ -5142,6 +5157,12 @@ function chooseType() {
$("#row_historical_db_check").hide();
break;
case 'last_value':
$("#row_description").show();
$("#row_agent").show();
$("#row_module").show();
break;
case 'alert_report_module':
$("#row_description").show();
$("#row_agent").show();

View File

@ -1631,8 +1631,10 @@ function agents_get_alias($id_agent, $case='none')
}
// Check cache.
if (isset($cache[$case][$id_agent])) {
return $cache[$case][$id_agent];
if (!is_metaconsole()) {
if (isset($cache[$case][$id_agent])) {
return $cache[$case][$id_agent];
}
}
$alias = (string) db_get_value(
@ -1656,7 +1658,10 @@ function agents_get_alias($id_agent, $case='none')
break;
}
$cache[$case][$id_agent] = $alias;
if (!is_metaconsole()) {
$cache[$case][$id_agent] = $alias;
}
return $alias;
}

View File

@ -687,6 +687,13 @@ function reporting_make_reporting_data(
);
break;
case 'last_value':
$report['contents'][] = reporting_last_value(
$report,
$content
);
break;
case 'group_report':
$report['contents'][] = reporting_group_report(
$report,
@ -3430,6 +3437,77 @@ function reporting_database_serialized($report, $content)
}
/**
* Show last value and state of module.
*
* @param array $report Data report.
* @param array $content Content report.
*
* @return array
*/
function reporting_last_value($report, $content)
{
global $config;
$return['type'] = 'last_value';
if (empty($content['name'])) {
$content['name'] = __('Last Value');
}
if (is_metaconsole()) {
$id_meta = metaconsole_get_id_server($content['server_name']);
$server = metaconsole_get_connection_by_id($id_meta);
if (metaconsole_connect($server) != NOERR) {
$result = [];
return reporting_check_structure_content($result);
}
}
$id_agent = agents_get_module_id(
$content['id_agent_module']
);
$agent_alias = agents_get_alias($id_agent);
$module_name = modules_get_agentmodule_name(
$content['id_agent_module']
);
$return['title'] = $content['name'];
$return['landscape'] = $content['landscape'];
$return['pagebreak'] = $content['pagebreak'];
$return['subtitle'] = $agent_alias.' - '.$module_name;
$return['description'] = $content['description'];
$return['date'] = reporting_get_date_text($report, $content);
$return['agent_name_db'] = agents_get_name($id_agent);
$return['agent_name'] = $agent_alias;
$return['module_name'] = $module_name;
$sql = sprintf(
'SELECT *
FROM tagente_estado
WHERE id_agente_modulo = %s',
$content['id_agent_module']
);
$result = db_get_row_sql($sql);
if ($result === false) {
$result = [];
}
$result['agent_name'] = $agent_alias;
$result['module_name'] = $module_name;
$return['data'] = $result;
if (is_metaconsole()) {
metaconsole_restore_db();
}
return reporting_check_structure_content($return);
}
function reporting_group_configuration($report, $content)
{
global $config;

View File

@ -335,6 +335,10 @@ function reporting_html_print_report($report, $mini=false, $report_info=1)
reporting_html_database_serialized($table, $item);
break;
case 'last_value':
reporting_html_last_value($table, $item);
break;
case 'group_report':
reporting_html_group_report($table, $item);
break;
@ -2257,6 +2261,159 @@ function reporting_html_database_serialized($table, $item, $pdf=0)
}
/**
* Show last value and state of module.
*
* @param object $table Head table or false if it comes from pdf.
* @param array $item Items data.
* @param boolean $pdf If it comes from pdf.
*
* @return html
*/
function reporting_html_last_value($table, $item, $pdf=0)
{
global $config;
if (empty($item['data']) === false) {
$table_data = new stdClass();
$table_data->width = '100%';
$table_data->headstyle = [];
$table_data->headstyle[0] = 'text-align: left;';
$table_data->style = [];
$table_data->style[0] = 'text-align: left;';
$table_data->head = [
__('Name'),
__('Date'),
__('Data'),
__('Status'),
];
$table_data->data = [];
$table_data->data[1][0] = $item['data']['agent_name'];
$table_data->data[1][0] .= ' / ';
$table_data->data[1][0] .= $item['data']['module_name'];
$table_data->data[1][1] = date(
'Y-m-d H:i:s',
$item['data']['utimestamp']
);
$table_data->data[1][2] = remove_right_zeros(
number_format(
$item['data']['datos'],
$config['graph_precision']
)
);
switch ($item['data']['estado']) {
case AGENT_MODULE_STATUS_CRITICAL_BAD:
$img_status = ui_print_status_image(
'module_critical.png',
$item['data']['datos'],
true,
[
'width' => '50px',
'height' => '20px',
'style' => 'border-radius:5px;',
],
'images/status_sets/default/'
);
break;
case AGENT_MODULE_STATUS_WARNING:
$img_status = ui_print_status_image(
'module_warning.png',
$item['data']['datos'],
true,
[
'width' => '50px',
'height' => '20px',
'style' => 'border-radius:5px;',
],
'images/status_sets/default/'
);
break;
case AGENT_MODULE_STATUS_UNKNOWN:
$img_status = ui_print_status_image(
'module_unknown.png',
$item['data']['datos'],
true,
[
'width' => '50px',
'height' => '20px',
'style' => 'border-radius:5px;',
],
'images/status_sets/default/'
);
break;
case AGENT_MODULE_STATUS_NORMAL_ALERT:
case AGENT_MODULE_STATUS_WARNING_ALERT:
case AGENT_MODULE_STATUS_CRITICAL_ALERT:
$img_status = ui_print_status_image(
'module_alertsfired.png',
$item['data']['datos'],
true,
[
'width' => '50px',
'height' => '20px',
'style' => 'border-radius:5px;',
],
'images/status_sets/default/'
);
break;
case 4:
$img_status = ui_print_status_image(
'module_no_data.png',
$item['data']['datos'],
true,
[
'width' => '50px',
'height' => '20px',
'style' => 'border-radius:5px;',
],
'images/status_sets/default/'
);
break;
default:
case AGENT_MODULE_STATUS_NORMAL:
$img_status = ui_print_status_image(
'module_ok.png',
$item['data']['datos'],
true,
[
'width' => '50px',
'height' => '20px',
'style' => 'border-radius:5px;',
],
'images/status_sets/default/'
);
break;
}
$table_data->data[1][3] = $img_status;
if ($pdf === 0) {
$table->colspan['last_value']['cell'] = 3;
$table->cellstyle['last_value']['cell'] = 'text-align: center;';
$table->data['last_value']['cell'] = html_print_table(
$table_data,
true
);
} else {
return html_print_table(
$table_data,
true
);
}
} else {
// TODO:XXX
}
}
/**
* Shows the data of a group and the agents that are part of them.
*

View File

@ -746,6 +746,10 @@ function reports_get_report_types($template=false, $not_editor=false)
'optgroup' => __('Modules'),
'name' => __('Increment'),
];
$types['last_value'] = [
'optgroup' => __('Modules'),
'name' => __('Last value'),
];
$types['general'] = [
'optgroup' => __('Grouped'),