1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
import sys import logging import re from splunklib.searchcommands import dispatch, StreamingCommand, Configuration, Option, validators
@Configuration() class unicode(StreamingCommand): logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s', datefmt='%a, %d %b %Y %H:%M:%S', filename='nuicode.log', filemode='a')
field = Option(name='field', require=True) def stream(self, records): logging.debug(self.field) if self.field != None: for record in records: subject = record[self.field] record[self.field] = re.sub(r'(\\u[\s\S]{4})',lambda x:x.group(1).encode("utf-8").decode("unicode-escape"),subject) yield record
dispatch(unicode, sys.argv, sys.stdin, sys.stdout, __name__)
|