Merge branch 'ent-8338-POST-Dejar-de-codificar-los-custom-data-en-base64-eventos' into 'develop'
change storage format of custom data field in DB See merge request artica/pandorafms!4766
This commit is contained in:
commit
64947b75cd
|
@ -13441,6 +13441,9 @@ function api_set_create_event($id, $trash1, $other, $returnType)
|
|||
$values['id_extra'] = '';
|
||||
}
|
||||
|
||||
$custom_data = base64_decode($values['custom_data']);
|
||||
$custom_data = mysql_escape_string_sql($custom_data);
|
||||
|
||||
$return = events_create_event(
|
||||
$values['event'],
|
||||
$values['id_grupo'],
|
||||
|
@ -13456,7 +13459,7 @@ function api_set_create_event($id, $trash1, $other, $returnType)
|
|||
$values['unknown_instructions'],
|
||||
$values['source'],
|
||||
$values['tags'],
|
||||
$values['custom_data'],
|
||||
$custom_data,
|
||||
$values['server_id'],
|
||||
$values['id_extra']
|
||||
);
|
||||
|
|
|
@ -851,7 +851,7 @@ if ($pure) {
|
|||
|
||||
// CSV.
|
||||
$csv['active'] = false;
|
||||
$csv['text'] = '<a class="events_link" href="operation/events/export_csv.php?'.$filter_b64.'">'.html_print_image(
|
||||
$csv['text'] = '<a class="events_link" href="'.ui_get_full_url(false, false, false, false).'operation/events/export_csv.php?'.$filter_b64.'">'.html_print_image(
|
||||
'images/csv.png',
|
||||
true,
|
||||
[
|
||||
|
@ -942,7 +942,6 @@ if ($pure) {
|
|||
);
|
||||
} else {
|
||||
unset($onheader['rss']);
|
||||
unset($onheader['csv']);
|
||||
unset($onheader['sound_event']);
|
||||
unset($onheader['fullscreen']);
|
||||
ui_meta_print_header(__('Events'), $section_string, $onheader);
|
||||
|
|
|
@ -84,35 +84,66 @@ $column_names = [
|
|||
'module_status',
|
||||
];
|
||||
|
||||
$fields = [
|
||||
'te.id_evento',
|
||||
'te.evento',
|
||||
'te.timestamp',
|
||||
'te.estado',
|
||||
'te.event_type',
|
||||
'te.utimestamp',
|
||||
'te.id_agente',
|
||||
'ta.alias as agent_name',
|
||||
'te.id_usuario',
|
||||
'te.id_grupo',
|
||||
'te.id_agentmodule',
|
||||
'am.nombre as module_name',
|
||||
'te.id_alert_am',
|
||||
'te.criticity',
|
||||
'te.user_comment',
|
||||
'te.tags',
|
||||
'te.source',
|
||||
'te.id_extra',
|
||||
'te.critical_instructions',
|
||||
'te.warning_instructions',
|
||||
'te.unknown_instructions',
|
||||
'te.owner_user',
|
||||
'te.ack_utimestamp',
|
||||
'te.custom_data',
|
||||
'te.data',
|
||||
'te.module_status',
|
||||
'tg.nombre as group_name',
|
||||
];
|
||||
if (is_metaconsole() === true) {
|
||||
$fields = [
|
||||
'te.id_evento',
|
||||
'te.evento',
|
||||
'te.timestamp',
|
||||
'te.estado',
|
||||
'te.event_type',
|
||||
'te.utimestamp',
|
||||
'te.id_agente',
|
||||
'ta.alias as agent_name',
|
||||
'te.id_usuario',
|
||||
'te.id_grupo',
|
||||
'te.id_agentmodule',
|
||||
'te.id_alert_am',
|
||||
'te.criticity',
|
||||
'te.user_comment',
|
||||
'te.tags',
|
||||
'te.source',
|
||||
'te.id_extra',
|
||||
'te.critical_instructions',
|
||||
'te.warning_instructions',
|
||||
'te.unknown_instructions',
|
||||
'te.owner_user',
|
||||
'te.ack_utimestamp',
|
||||
'te.custom_data',
|
||||
'te.data',
|
||||
'te.module_status',
|
||||
'tg.nombre as group_name',
|
||||
];
|
||||
} else {
|
||||
$fields = [
|
||||
'te.id_evento',
|
||||
'te.evento',
|
||||
'te.timestamp',
|
||||
'te.estado',
|
||||
'te.event_type',
|
||||
'te.utimestamp',
|
||||
'te.id_agente',
|
||||
'ta.alias as agent_name',
|
||||
'te.id_usuario',
|
||||
'te.id_grupo',
|
||||
'te.id_agentmodule',
|
||||
'am.nombre as module_name',
|
||||
'te.id_alert_am',
|
||||
'te.criticity',
|
||||
'te.user_comment',
|
||||
'te.tags',
|
||||
'te.source',
|
||||
'te.id_extra',
|
||||
'te.critical_instructions',
|
||||
'te.warning_instructions',
|
||||
'te.unknown_instructions',
|
||||
'te.owner_user',
|
||||
'te.ack_utimestamp',
|
||||
'te.custom_data',
|
||||
'te.data',
|
||||
'te.module_status',
|
||||
'tg.nombre as group_name',
|
||||
];
|
||||
}
|
||||
|
||||
$now = date('Y-m-d');
|
||||
|
||||
|
@ -183,6 +214,33 @@ try {
|
|||
);
|
||||
break;
|
||||
|
||||
case 'custom_data':
|
||||
$custom_data_array = json_decode(
|
||||
$row[$key],
|
||||
true
|
||||
);
|
||||
|
||||
$custom_data = '';
|
||||
$separator = ($config['csv_divider'] === ';') ? ',' : ';';
|
||||
|
||||
if ($custom_data_array !== null) {
|
||||
array_walk(
|
||||
$custom_data_array,
|
||||
function (&$value, $field) {
|
||||
if (is_array($value) === true) {
|
||||
$value = '['.implode($separator, $value).']';
|
||||
}
|
||||
|
||||
$value = $field.'='.$value;
|
||||
}
|
||||
);
|
||||
|
||||
$custom_data = implode($separator, $custom_data_array);
|
||||
}
|
||||
|
||||
echo io_safe_output($custom_data);
|
||||
break;
|
||||
|
||||
default:
|
||||
echo io_safe_output($row[$key]);
|
||||
break;
|
||||
|
|
|
@ -3758,12 +3758,12 @@ Generate an event.
|
|||
|
||||
=cut
|
||||
##########################################################################
|
||||
sub pandora_event ($$$$$$$$$$;$$$$$$$$$$$) {
|
||||
sub pandora_event ($$$$$$$$$$;$$$$$$$$$$$$) {
|
||||
my ($pa_config, $evento, $id_grupo, $id_agente, $severity,
|
||||
$id_alert_am, $id_agentmodule, $event_type, $event_status, $dbh,
|
||||
$source, $user_name, $comment, $id_extra, $tags,
|
||||
$critical_instructions, $warning_instructions, $unknown_instructions, $custom_data,
|
||||
$module_data, $module_status) = @_;
|
||||
$module_data, $module_status, $server_id) = @_;
|
||||
my $event_table = is_metaconsole($pa_config) ? 'tmetaconsole_event' : 'tevento';
|
||||
|
||||
my $agent = undef;
|
||||
|
@ -3808,6 +3808,7 @@ sub pandora_event ($$$$$$$$$$;$$$$$$$$$$$) {
|
|||
$warning_instructions = '' unless defined ($warning_instructions);
|
||||
$unknown_instructions = '' unless defined ($unknown_instructions);
|
||||
$custom_data = '' unless defined ($custom_data);
|
||||
$server_id = 0 unless defined ($server_id);
|
||||
$module_data = defined($module) ? $module->{'datos'} : '' unless defined ($module_data);
|
||||
$module_status = defined($module) ? $module->{'estado'} : '' unless defined ($module_status);
|
||||
|
||||
|
@ -3829,10 +3830,17 @@ sub pandora_event ($$$$$$$$$$;$$$$$$$$$$$) {
|
|||
db_do ($dbh, 'UPDATE ' . $event_table . ' SET estado = 1, ack_utimestamp = ? WHERE estado IN (0,2) AND id_extra=?', $utimestamp, $id_extra);
|
||||
}
|
||||
|
||||
my $event_id = undef;
|
||||
|
||||
# Create the event
|
||||
logger($pa_config, "Generating event '$evento' for agent ID $id_agente module ID $id_agentmodule.", 10);
|
||||
my $event_id = db_insert ($dbh, 'id_evento','INSERT INTO ' . $event_table . ' (id_agente, id_grupo, evento, timestamp, estado, utimestamp, event_type, id_agentmodule, id_alert_am, criticity, user_comment, tags, source, id_extra, id_usuario, critical_instructions, warning_instructions, unknown_instructions, ack_utimestamp, custom_data, data, module_status)
|
||||
if (is_metaconsole($pa_config)) {
|
||||
$event_id = db_insert ($dbh, 'id_evento','INSERT INTO ' . $event_table . ' (id_agente, id_grupo, evento, timestamp, estado, utimestamp, event_type, id_agentmodule, id_alert_am, criticity, user_comment, tags, source, id_extra, id_usuario, critical_instructions, warning_instructions, unknown_instructions, ack_utimestamp, server_id, custom_data, data, module_status)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', $id_agente, $id_grupo, safe_input ($evento), $timestamp, $event_status, $utimestamp, $event_type, $id_agentmodule, $id_alert_am, $severity, $comment, $module_tags, $source, $id_extra, $user_name, $critical_instructions, $warning_instructions, $unknown_instructions, $ack_utimestamp, $server_id, $custom_data, safe_input($module_data), $module_status);
|
||||
} else {
|
||||
$event_id = db_insert ($dbh, 'id_evento','INSERT INTO ' . $event_table . ' (id_agente, id_grupo, evento, timestamp, estado, utimestamp, event_type, id_agentmodule, id_alert_am, criticity, user_comment, tags, source, id_extra, id_usuario, critical_instructions, warning_instructions, unknown_instructions, ack_utimestamp, custom_data, data, module_status)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', $id_agente, $id_grupo, safe_input ($evento), $timestamp, $event_status, $utimestamp, $event_type, $id_agentmodule, $id_alert_am, $severity, $comment, $module_tags, $source, $id_extra, $user_name, $critical_instructions, $warning_instructions, $unknown_instructions, $ack_utimestamp, $custom_data, safe_input($module_data), $module_status);
|
||||
}
|
||||
|
||||
# Do not write to the event file
|
||||
return $event_id if ($pa_config->{'event_file'} eq '');
|
||||
|
|
|
@ -4186,7 +4186,7 @@ sub cli_delete_profile() {
|
|||
##############################################################################
|
||||
|
||||
sub cli_create_event() {
|
||||
my ($event,$event_type,$group_name,$agent_name,$module_name,$event_status,$severity,$template_name, $user_name, $comment, $source, $id_extra, $tags, $custom_data,$force_create_agent,$c_instructions,$w_instructions,$u_instructions, $use_alias) = @ARGV[2..20];
|
||||
my ($event,$event_type,$group_name,$agent_name,$module_name,$event_status,$severity,$template_name, $user_name, $comment, $source, $id_extra, $tags, $custom_data,$force_create_agent,$c_instructions,$w_instructions,$u_instructions,$use_alias,$server_id) = @ARGV[2..21];
|
||||
|
||||
$event_status = 0 unless defined($event_status);
|
||||
$severity = 0 unless defined($severity);
|
||||
|
@ -4251,11 +4251,8 @@ sub cli_create_event() {
|
|||
|
||||
print_log "[INFO] Adding event '$event' for agent '$agent_name' \n\n";
|
||||
|
||||
# Base64 encode custom data
|
||||
$custom_data = encode_base64 ($custom_data, '');
|
||||
|
||||
pandora_event ($conf, $event, $id_group, $id_agent, $severity,
|
||||
$id_alert_agent_module, $id_agentmodule, $event_type, $event_status, $dbh, $source, $user_name, safe_input($comment), $id_extra, $tags, $c_instructions, $w_instructions, $u_instructions, $custom_data);
|
||||
$id_alert_agent_module, $id_agentmodule, $event_type, $event_status, $dbh, $source, $user_name, safe_input($comment), $id_extra, $tags, $c_instructions, $w_instructions, $u_instructions, $custom_data, undef, undef, $server_id);
|
||||
}
|
||||
} else {
|
||||
if (! $agent_name) {
|
||||
|
@ -4301,11 +4298,8 @@ sub cli_create_event() {
|
|||
|
||||
print_log "[INFO] Adding event '$event' for agent '$agent_name' \n\n";
|
||||
|
||||
# Base64 encode custom data
|
||||
$custom_data = encode_base64 ($custom_data, '');
|
||||
|
||||
pandora_event ($conf, $event, $id_group, $id_agent, $severity,
|
||||
$id_alert_agent_module, $id_agentmodule, $event_type, $event_status, $dbh, $source, $user_name, safe_input($comment), $id_extra, $tags, $c_instructions, $w_instructions, $u_instructions, $custom_data);
|
||||
$id_alert_agent_module, $id_agentmodule, $event_type, $event_status, $dbh, $source, $user_name, safe_input($comment), $id_extra, $tags, $c_instructions, $w_instructions, $u_instructions, $custom_data, undef, undef, $server_id);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -7605,7 +7599,7 @@ sub pandora_manage_main ($$$) {
|
|||
cli_delete_profile();
|
||||
}
|
||||
elsif ($param eq '--create_event') {
|
||||
param_check($ltotal, 19, 16);
|
||||
param_check($ltotal, 20, 17);
|
||||
cli_create_event();
|
||||
}
|
||||
elsif ($param eq '--validate_event') {
|
||||
|
|
Loading…
Reference in New Issue