#8365 Fix ncm report for multiple agents

This commit is contained in:
Jorge Rincon 2023-11-08 14:40:47 +01:00
parent 3988968198
commit 98bc73a83a
5 changed files with 54 additions and 38 deletions

View File

@ -29,6 +29,9 @@ ADD COLUMN `agent_data_cron_interval` VARCHAR(100) NULL DEFAULT '' AFTER `cron_i
ALTER TABLE `tncm_agent`
ADD COLUMN `agent_data_event_on_change` INT UNSIGNED NULL DEFAULT NULL AFTER `event_on_change`;
ALTER TABLE `treport_content`
ADD COLUMN `ncm_agents` MEDIUMTEXT NULL AFTER `status_of_check`;
-- Add new vendor and model
SET @vendor_name = 'Cisco';
SET @model_name = 'Cisco-Generic';

View File

@ -1036,12 +1036,12 @@ switch ($action) {
break;
case 'ncm':
$id_agent_ncm = $item['id_agent'];
$id_agent_ncm = json_decode($item['ncm_agents']);
$ncm_group = $item['id_group'];
break;
case 'ncm_backups':
$id_agent_ncm = $item['id_agent'];
$id_agent_ncm = json_decode($item['ncm_agents']);
$ncm_group = $item['id_group'];
break;
@ -1973,7 +1973,7 @@ if (is_metaconsole() === true) {
$all_agents = agents_get_agents_selected($ncm_group);
html_print_select(
$all_agents,
'agent_ncm',
'agent_ncm[]',
$id_agent_ncm,
'',
__('Any'),

View File

@ -2046,13 +2046,15 @@ switch ($action) {
break;
case 'ncm_backups':
$values['id_agent'] = get_parameter('agent_ncm');
$agents_ncm = get_parameter('agent_ncm');
$values['ncm_agents'] = json_encode($agents_ncm);
$values['id_group'] = get_parameter('ncm_group');
$good_format = true;
break;
case 'ncm':
$values['id_agent'] = get_parameter('agent_ncm');
$agents_ncm = get_parameter('agent_ncm');
$values['ncm_agents'] = json_encode($agents_ncm);
$values['id_group'] = get_parameter('ncm_group');
$good_format = true;
break;
@ -2996,12 +2998,15 @@ switch ($action) {
break;
case 'ncm_backups':
$values['id_agent'] = get_parameter('agent_ncm');
$agents_ncm = get_parameter('agent_ncm');
$values['ncm_agents'] = json_encode($agents_ncm);
$values['id_group'] = get_parameter('ncm_group');
$good_format = true;
break;
case 'ncm':
$agents_ncm = get_parameter('agent_ncm');
$values['ncm_agents'] = json_encode($agents_ncm);
$values['id_agent'] = get_parameter('agent_ncm');
$values['id_group'] = get_parameter('ncm_group');
$good_format = true;

View File

@ -7441,45 +7441,52 @@ function reporting_html_ncm_backups($table, $item, $pdf=0)
ui_require_javascript_file('functions_ncm', ENTERPRISE_DIR.'/include/javascript/');
// Create table diff.
$table_ncm = new stdClass();
$table_ncm->width = '100%';
$table_ncm->class = 'info_table';
$table_ncm->styleTable = 'table-layout: fixed;';
$table_ncm->headstyle[0] = 'width: 250px';
$table_ncm->head = [];
$table_ncm->head[0] = __('Date');
$table_ncm->head[1] = __('Diff');
$table_ncm->caption = $item['caption'];
$table_ncm->id = 'ncm_backups';
$table_ncm->data = [];
if ($pdf === 0) {
foreach ($item['data'] as $key => $row) {
$table_ncm->data[] = [
$row['updated_at'],
$row['diff'],
];
foreach ($item['data'] as $ncm_agent_key => $ncm_agent) {
$table_ncm = new stdClass();
if ($pdf === 1) {
$table_ncm->width = '100%';
}
$table->colspan['ncm_backups']['cell'] = 3;
$table->cellstyle['ncm_backups']['cell'] = 'text-align: left;';
$table->data['ncm_backups']['cell'] = html_print_table(
$table_ncm,
true
);
} else {
foreach ($item['data'] as $key => $row) {
$table_ncm->data[] = [
$row['updated_at'],
($row['diffstr'] === '') ? $row['diff'] : str_replace("\n", '<br>', $row['diffstr']),
];
$table_ncm->class = 'info_table';
$table_ncm->styleTable = 'table-layout: fixed;';
$table_ncm->headstyle[0] = 'width: 250px';
$table_ncm->head = [];
$table_ncm->head[0] = __('Date');
$table_ncm->head[1] = __('Diff');
$table_ncm->id = 'ncm_backups';
$table_ncm->name = 'ncm_backups';
$table_ncm->title = $ncm_agent['caption'];
$row = [];
foreach ($ncm_agent['data'] as $ncm_agent_data) {
if ($pdf === 1) {
$row[] = [
$ncm_agent_data['updated_at'],
($ncm_agent_data['diffstr'] === '') ? $ncm_agent_data['diff'] : str_replace("\n", '<br>', $ncm_agent_data['diffstr']),
];
} else {
$row[] = [
$ncm_agent_data['updated_at'],
$ncm_agent_data['diff'],
];
}
$table_ncm->data = $row;
}
return html_print_table(
$table->colspan[$ncm_agent_key]['cell'] = 3;
$table->cellstyle[$ncm_agent_key]['cell'] = 'text-align: left;';
$table->data[$ncm_agent_key]['cell'] = html_print_table(
$table_ncm,
true
);
}
if ($pdf === 1) {
$table->width = '100%';
return html_print_table(
$table,
true
);
}
}

View File

@ -1645,6 +1645,7 @@ CREATE TABLE IF NOT EXISTS `treport_content` (
`cat_security_hardening` INT NOT NULL DEFAULT 0,
`ignore_skipped` INT NOT NULL DEFAULT 0,
`status_of_check` TINYTEXT,
`ncm_agents` MEDIUMTEXT,
PRIMARY KEY(`id_rc`),
FOREIGN KEY (`id_report`) REFERENCES treport(`id_report`)
ON UPDATE CASCADE ON DELETE CASCADE