Skip to content

Instantly share code, notes, and snippets.

@famousgarkin
Last active July 1, 2023 10:15
Show Gist options
  • Save famousgarkin/3c93ab8a0c36c4118a63bea054c6fc56 to your computer and use it in GitHub Desktop.
Save famousgarkin/3c93ab8a0c36c4118a63bea054c6fc56 to your computer and use it in GitHub Desktop.
Fluentd out exec filter
<source>
type http
port 8888
bind 127.0.0.1
</source>
<match test.**>
type copy
<store>
type stdout
</store>
<store>
type exec_filter
command python fluentd-out-exec-filter.py
in_format json
out_format json
tag_key fluentd_tag
time_key fluentd_time
</store>
</match>
import sys
import json
import time
import logging
logging.basicConfig(filename=__file__ + '.log', level=logging.DEBUG)
logger = logging.getLogger(__name__)
class Event(dict):
def __init__(self, data):
super(Event, self).__init__(data)
def process(self):
pass
logger.info('loop started ...')
while 1:
line = sys.stdin.readline()
if not line:
time.sleep(5)
continue
logger.debug('line in: {}'.format(line))
data = json.loads(line)
logger.debug('data in: {}'.format(data))
event = Event(data)
event.process()
data = json.dumps(event)
sys.stdout.write(data)
logger.info('loop exited')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment