Last active
July 1, 2023 10:15
-
-
Save famousgarkin/3c93ab8a0c36c4118a63bea054c6fc56 to your computer and use it in GitHub Desktop.
Fluentd out exec filter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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