# coding: utf-8 from kome.core.plugin import plugin_manager class Copy: """ 複数の出力へ出力するプラグイン """ def __init__(self, config): self._outputs = [plugin_manager.get(cfg['type'])(cfg) for cfg in config['outputs']] def emit(self, data): for out in self._outputs: out.emit(data) plugin_manager.register('copy', Copy)
self.config = { 'option': syslog.LOG_NOWAIT, 'facility': syslog.LOG_LOCAL5, 'priority': syslog.LOG_INFO, 'separator': '\t' } self.config.update(config) def emit(self, data): message = self._make_message(data) cfg = self.config syslog.openlog(cfg['app'], cfg['option'], cfg['facility']) syslog.syslog(cfg['priority'], message) syslog.closelog() def _make_message(self, data): """ 出力用のメッセージを生成 """ sep = self.config['separator'] xs = [] for (k,v) in data.items(): if k == 'time' or k == 'uid' or k == 'action': continue xs.append('[%s]%s%s' % (k, sep, repr(v))) message = '%s%s%s%s%s' % (data['action'], sep, data['uid'], sep, sep.join(xs)) return message plugin_manager.register('syslogp', Syslog)
'priority': syslog.LOG_INFO, 'separator': '\t' } self.config.update(config) def emit(self, data): message = self._make_message(data) cfg = self.config syslog.openlog(cfg['app'], cfg['option'], cfg['facility']) syslog.syslog(cfg['priority'], message) syslog.closelog() def _make_message(self, data): """ 出力用のメッセージを生成 """ sep = self.config['separator'] xs = [] for (k, v) in data.items(): if k == 'time' or k == 'uid' or k == 'action': continue xs.append('[%s]%s%s' % (k, sep, repr(v))) message = '%s%s%s%s%s' % (data['action'], sep, data['uid'], sep, sep.join(xs)) return message plugin_manager.register('syslogp', Syslog)
# coding: utf-8 from kome.core.plugin import plugin_manager class Copy: """ 複数の出力へ出力するプラグイン """ def __init__(self, config): self._outputs = [ plugin_manager.get(cfg['type'])(cfg) for cfg in config['outputs'] ] def emit(self, data): for out in self._outputs: out.emit(data) plugin_manager.register('copy', Copy)
# coding: utf-8 from kome.core.plugin import plugin_manager class Stdout: """ 標準出力へ出力するプラグイン """ def __init__(self, config): pass def emit(self, data): print data plugin_manager.register('stdout', Stdout)
# coding: utf-8 from kome.core.plugin import plugin_manager class Nullout: """ 何もしないプラグイン """ def __init__(self, config): pass def emit(self, data): pass plugin_manager.register('null', Nullout)
# 通常のアクションはこちらに流す <match kome.app.**> host 127.0.0.1 port 24224 </match> """ # default host = config.get('host', 'localhost') port = config.get('port', 24224) self._sender = fluent.sender.FluentSender('kome', host=host, port=port) self._app = config['app'].replace('.', '_') # '.' must not be included. def emit(self, data): (action, timestamp, message) = self._make_message(data) self._sender.emit_with_time('.'.join((self._app, action)), timestamp, message) def _make_message(self, data): """ 出力用のメッセージを生成 """ action = data['action'] timestamp = int(time.mktime(data['time'].timetuple())) message = dict([(k,repr(v)) for (k,v) in data.items() if k != 'uid' and k != 'time' and k != 'action']) message['uid'] = str(data['uid']) return (action, timestamp, message) plugin_manager.register('fluentp', Fluent)
host 127.0.0.1 port 24224 </match> """ # default host = config.get('host', 'localhost') port = config.get('port', 24224) self._sender = fluent.sender.FluentSender('kome', host=host, port=port) self._app = config['app'].replace('.', '_') # '.' must not be included. def emit(self, data): (action, timestamp, message) = self._make_message(data) self._sender.emit_with_time('.'.join((self._app, action)), timestamp, message) def _make_message(self, data): """ 出力用のメッセージを生成 """ action = data['action'] timestamp = int(time.mktime(data['time'].timetuple())) message = dict([(k, repr(v)) for (k, v) in data.items() if k != 'uid' and k != 'time' and k != 'action']) message['uid'] = str(data['uid']) return (action, timestamp, message) plugin_manager.register('fluentp', Fluent)