1############################################################################# 2# Copyright (c) 2015-2016 Balabit 3# 4# This program is free software; you can redistribute it and/or modify it 5# under the terms of the GNU General Public License version 2 as published 6# by the Free Software Foundation, or (at your option) any later version. 7# 8# This program is distributed in the hope that it will be useful, 9# but WITHOUT ANY WARRANTY; without even the implied warranty of 10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11# GNU General Public License for more details. 12# 13# You should have received a copy of the GNU General Public License 14# along with this program; if not, write to the Free Software 15# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16# 17# As an additional exemption you are allowed to compile & link against the 18# OpenSSL libraries as published by the OpenSSL project. See the file 19# COPYING for details. 20# 21############################################################################# 22 23class LogDestination(object): 24 25 def open(self): 26 """Open a connection to the target service""" 27 return True 28 29 def close(self): 30 """Close the connection to the target service""" 31 pass 32 33 def is_opened(self): 34 """Check if the connection to the target is able to receive messages""" 35 return True 36 37 def init(self, options): 38 """This method is called at initialization time""" 39 return True 40 41 def deinit(self): 42 """This method is called at deinitialization time""" 43 pass 44 45 def send(self, msg): 46 """Send a message to the target service 47 48 It can return either a boolean or integer. 49 Boolean: True to indicate success, False will suspend the 50 destination for a period specified by the time-reopen() option. 51 After that the same message is retried until retries() times. 52 53 Integer: 54 self.SUCCESS: message sending was successful (same as boolean True) 55 self.ERROR: message sending was unsuccessful. Same message is retried. 56 (same as boolean False) 57 self.DROP: message cannot be sent, it should be dropped immediately. 58 self.QUEUED: message is not sent immediately, it will be sent with the flush method. 59 self.NOT_CONNECTED: message is put back to the queue, open method will be called until success. 60 self.RETRY: message is put back to the queue, try to send again until 3 times, then fallback to self.NOT_CONNECTED.""" 61 62 pass 63 64 def flush(self): 65 """Flush the queued messages 66 67 It can return either a boolean or integer. 68 Boolean: True to indicate that the batch is successfully sent. 69 False indicates error while sending the batch. The destination is suspended 70 for time-reopen period. The messages in the batch are passed again to send, one by one. 71 72 Integer: 73 self.SUCCESS: batch sending was successful (same as boolean True) 74 self.ERROR: batch sending was unsuccessful. (same as boolean False) 75 self.DROP: batch cannot be sent, the messages should be dropped immediately. 76 self.NOT_CONNECTED: the messages in the batch is put back to the queue, 77 open method will be called until success. 78 self.RETRY: message is put back to the queue, try to send again until 3 times, then fallback to self.NOT_CONNECTED.""" 79 80 pass 81 82class DummyPythonDest(object): 83 def send(self, msg): 84 print('queue', msg) 85 return self.SUCCESS 86 87class DummyBatchDestination(object): 88 def init(self, options): 89 self.bulk = list() 90 return True 91 92 def send(self, msg): 93 self.bulk.append(msg["MSG"].decode()) 94 return self.QUEUED 95 96 def flush(self): 97 print("flushing: " + ",".join(self.bulk)) 98 self.bulk = list() 99 return self.SUCCESS 100