示例#1
0
文件: copy.py 项目: subc/anchovy
# 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)
示例#2
0
文件: syslogp.py 项目: subc/anchovy
        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)
示例#3
0
            '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)
示例#4
0
文件: copy.py 项目: arpsabbir/anchovy
# 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)
示例#5
0
# 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)
示例#6
0
文件: null.py 项目: arpsabbir/anchovy
# 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)
示例#7
0
文件: fluentp.py 项目: subc/anchovy
            # 通常のアクションはこちらに流す
            <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)
示例#8
0
                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)
示例#9
0
文件: null.py 项目: subc/anchovy
# 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)
示例#10
0
文件: stdout.py 项目: subc/anchovy
# 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)