Skip to content

Commit e37c691

Browse files
vmalaviya-splunkakaila-splunk
authored andcommitted
Changes added to preserve the custom field
1 parent ad5f21e commit e37c691

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

‎splunklib/searchcommands/internals.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,7 @@ def __init__(self, ofile, maxresultrows=None):
508508
self._chunk_count = 0
509509
self._pending_record_count = 0
510510
self._committed_record_count = 0
511+
self.custom_fields = set()
511512

512513
@property
513514
def is_flushed(self):
@@ -593,6 +594,8 @@ def _write_record(self, record):
593594

594595
if fieldnames is None:
595596
self._fieldnames = fieldnames = list(record.keys())
597+
self._fieldnames.extend(self.custom_fields)
598+
fieldnames.extend(self.custom_fields)
596599
value_list = imap(lambda fn: (str(fn), str('__mv_') + str(fn)), fieldnames)
597600
self._writerow(list(chain.from_iterable(value_list)))
598601

‎splunklib/searchcommands/search_command.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,11 @@ def logging_level(self, value):
173173
raise ValueError('Unrecognized logging level: {}'.format(value))
174174
self._logger.setLevel(level)
175175

176+
def add_field(self, current_record, field_name, field_value):
177+
self._record_writer.custom_fields.add(field_name)
178+
current_record[field_name] = field_value
179+
return current_record
180+
176181
record = Option(doc='''
177182
**Syntax: record=<bool>
178183

0 commit comments

Comments
 (0)