# -*- coding: utf-8 -*-
from os import path, mkdir
from subprocess import call
from intelmq.lib.bot import CollectorBot
from intelmq import VAR_STATE_PATH


class RsyncCollectorBot(CollectorBot):
    def init(self):
        self.rsync_data_directory = path.join(VAR_STATE_PATH, "rsync_collector")
        try:
            mkdir(self.rsync_data_directory)
        except FileExistsError:
            pass

    def process(self):
        self.logger.info("Updating file {}.".format(self.parameters.file))
        call(["rsync", path.join(self.parameters.rsync_path, self.parameters.file),
              self.rsync_data_directory])
        report = self.new_report()
        with open(path.join(self.rsync_data_directory, self.parameters.file), "r") as rsync_file:
            report.add("raw", rsync_file.read())
            self.send_message(report)


BOT = RsyncCollectorBot


# -*- coding: utf-8 -*-
from os import path, mkdir
from subprocess import call
from intelmq.lib.bot import CollectorBot
from intelmq import VAR_STATE_PATH


class RsyncCollectorBot(CollectorBot):
    def init(self):
        self.rsync_data_directory = path.join(VAR_STATE_PATH, "rsync_collector")
        try:
            mkdir(self.rsync_data_directory)
        except FileExistsError:
            pass

    def process(self):
        self.logger.info("Updating file {}.".format(self.parameters.file))
        if call(["rsync", path.join(self.parameters.rsync_path, self.parameters.file), self.rsync_data_directory]) != 0:
            self.logger.error("Rsync file {} failed.".format(self.parameters.file))
        report = self.new_report()
        with open(path.join(self.rsync_data_directory, self.parameters.file), "r") as rsync_file:
            report.add("raw", rsync_file.read())
            self.send_message(report)


BOT = RsyncCollectorBot


check whether rsync ran correctly