class EventProcessor(object):
    def __init__(self, options):
        self.event_parser = EventParser(options)

        output_type = options.get("output_type")
        self.output = None
        if output_type == "stdout":
            self.output = StdOutOutput()
        elif output_type == "file":
            self.output = FileOutput(options.get("outfile"))
        elif output_type == "tcp":
            (host, port) = options.get("tcpout").split(":")
            self.output = TcpOutput(host, int(port))
        elif output_type == "udp":
            (host, port) = options.get("udpout").split(":")
            self.output = UdpOutput(host, int(port))
        elif output_type == "s3":
            self.output = S3Output(options.get("s3out"), options.get("aws_key", None), options.get("aws_secret", None))
        else:
            raise ValueError("Invalid output type: %s" % output_type)

    def process_event(self, content_type, routing_key, body):
        """
        Parse an event from the Carbon Black event bus and write the resulting events to the configured output
        """

        events = self.event_parser.parse_events(content_type, routing_key, body)
        for event in events:
            try:
                json_str = json.dumps(event)
                self.output.write(json_str)
            except TypeError as e:
                LOGGER.exception("Got an exception (%s) processing event (repr: %s)" % (e, repr(event)))
Example #2
0
class EventProcessor(object):
    def __init__(self, options):
        self.event_parser = EventParser(options)

        output_type = options.get("output_type")
        self.output = None
        if output_type == "stdout":
            self.output = StdOutOutput()
        elif output_type == "file":
            self.output = FileOutput(options.get("outfile"))
        elif output_type == "tcp":
            (host, port) = options.get("tcpout").split(":")
            self.output = TcpOutput(host, int(port))
        elif output_type == "udp":
            (host, port) = options.get("udpout").split(":")
            self.output = UdpOutput(host, int(port))
        elif output_type == "s3":
            self.output = S3Output(options.get("s3out"),
                                   options.get("aws_key", None),
                                   options.get("aws_secret", None))
        else:
            raise ValueError("Invalid output type: %s" % output_type)

    def process_event(self, content_type, routing_key, body):
        """
        Parse an event from the Carbon Black event bus and write the resulting events to the configured output
        """

        events = self.event_parser.parse_events(content_type, routing_key,
                                                body)
        for event in events:
            try:
                json_str = json.dumps(event)
                self.output.write(json_str)
            except TypeError as e:
                LOGGER.exception(
                    "Got an exception (%s) processing event (repr: %s)" %
                    (e, repr(event)))