Пример #1
0
    def start(self, logfile=None, application_name="ooniprobe"):
        from ooni.settings import config

        if not logfile:
            logfile = os.path.expanduser(config.basic.logfile)

        log_folder = os.path.dirname(logfile)
        if (not os.access(log_folder, os.W_OK) or
            (os.path.exists(logfile) and not os.access(logfile, os.W_OK))):
            # If we don't have permissions to write to the log_folder or
            # logfile.
            log_folder = config.running_path
            logfile = os.path.join(log_folder, "ooniprobe.log")

        self.log_filepath = logfile

        mkdir_p(log_folder)

        log_filename = os.path.basename(logfile)
        file_log_level = levels.get(config.basic.loglevel, levels['INFO'])
        stdout_log_level = levels['INFO']
        if config.advanced.debug:
            stdout_log_level = levels['DEBUG']

        if config.basic.rotate == 'daily':
            logfile = MyDailyLogFile(log_filename, log_folder)
        elif config.basic.rotate == 'length':
            logfile = LogFile(log_filename,
                              log_folder,
                              rotateLength=int(
                                  human_size_to_bytes(
                                      config.basic.rotate_length)),
                              maxRotatedFiles=config.basic.max_rotated_files)
        else:
            logfile = open(os.path.join(log_folder, log_filename), 'a')

        self.fileObserver = MsecLogObserver(logfile, log_level=file_log_level)
        self.stdoutObserver = StdoutStderrObserver(sys.stdout,
                                                   log_level=stdout_log_level)

        tw_log.startLoggingWithObserver(self.fileObserver.emit)
        tw_log.addObserver(self.stdoutObserver.emit)

        tw_log.msg("Starting %s on %s (%s UTC)" %
                   (application_name, otime.prettyDateNow(),
                    otime.prettyDateNowUTC()))
Пример #2
0
    def start(self, logfile=None, application_name="ooniprobe"):
        from ooni.settings import config

        if not logfile:
            logfile = os.path.expanduser(config.basic.logfile)

        log_folder = os.path.dirname(logfile)
        if (not os.access(log_folder, os.W_OK) or
            (os.path.exists(logfile) and not os.access(logfile, os.W_OK))):
            # If we don't have permissions to write to the log_folder or
            # logfile.
            log_folder = config.running_path
            logfile = os.path.join(log_folder, "ooniprobe.log")

        self.log_filepath = logfile

        mkdir_p(log_folder)

        log_filename = os.path.basename(logfile)
        file_log_level = levels.get(config.basic.loglevel,
                                    levels['INFO'])
        stdout_log_level = levels['INFO']
        if config.advanced.debug:
            stdout_log_level = levels['DEBUG']

        if config.basic.rotate == 'daily':
            logfile = MyDailyLogFile(log_filename, log_folder)
        elif config.basic.rotate == 'length':
            logfile = LogFile(log_filename, log_folder,
                              rotateLength=int(human_size_to_bytes(
                                  config.basic.rotate_length
                              )),
                              maxRotatedFiles=config.basic.max_rotated_files)
        else:
            logfile = open(os.path.join(log_folder, log_filename), 'a')

        self.fileObserver = MsecLogObserver(logfile, log_level=file_log_level)
        self.stdoutObserver = StdoutStderrObserver(sys.stdout,
                                                   log_level=stdout_log_level)

        tw_log.startLoggingWithObserver(self.fileObserver.emit)
        tw_log.addObserver(self.stdoutObserver.emit)

        tw_log.msg("Starting %s on %s (%s UTC)" % (application_name,
                                                   otime.prettyDateNow(),
                                                   otime.prettyDateNowUTC()))
Пример #3
0
def generate_deck(options):

    deck_data = {
        "name": "Default ooniprobe deck",
        "description": "Default ooniprobe deck generated on {0}".format(
                       prettyDateNowUTC()),
        "schedule": "@daily",
        "tasks": [
            {
                "ooni": {
                    "test_name": "http_invalid_request_line"
                },
            },
            {
                "ooni": {
                    "test_name": "http_header_field_manipulation"
                },
            },
            {
                "ooni": {
                    "test_name": "web_connectivity",
                    "file": "$citizenlab_${probe_cc}_urls"
                },
            },
            {
                "ooni": {
                    "test_name": "web_connectivity",
                    "file": "$citizenlab_global_urls"
                }
            }
        ]
    }
    if options["collector"] is not None:
        deck_data["collector"] = options['collector']

    if options["bouncer"] is not None:
        deck_data["bouncer"] = options['bouncer']

    deck = NGDeck(deck_data=deck_data)
    with open(options['output'], 'w+') as fw:
        deck.write(fw)

    print("Deck written to {0}".format(options['output']))
    print("Run ooniprobe like so:")
    print("ooniprobe -i {0}".format(options['output']))
Пример #4
0
def generate_deck(options):

    deck_data = {
        "name":
        "Default ooniprobe deck",
        "description":
        "Default ooniprobe deck generated on {0}".format(prettyDateNowUTC()),
        "schedule":
        "@daily",
        "tasks": [{
            "ooni": {
                "test_name": "http_invalid_request_line"
            },
        }, {
            "ooni": {
                "test_name": "http_header_field_manipulation"
            },
        }, {
            "ooni": {
                "test_name": "web_connectivity",
                "file": "$citizenlab_${probe_cc}_urls"
            },
        }, {
            "ooni": {
                "test_name": "web_connectivity",
                "file": "$citizenlab_global_urls"
            }
        }]
    }
    if options["collector"] is not None:
        deck_data["collector"] = options['collector']

    if options["bouncer"] is not None:
        deck_data["bouncer"] = options['bouncer']

    deck = NGDeck(deck_data=deck_data)
    with open(options['output'], 'w+') as fw:
        deck.write(fw)

    print("Deck written to {0}".format(options['output']))
    print("Run ooniprobe like so:")
    print("ooniprobe -i {0}".format(options['output']))
Пример #5
0
    def start(self, logfile=None, application_name="ooniprobe"):
        from ooni.settings import config

        if not logfile:
            logfile = os.path.expanduser(config.basic.logfile)

        log_folder = os.path.dirname(logfile)
        log_filename = os.path.basename(logfile)

        daily_logfile = DailyLogFile(log_filename, log_folder)

        txlog.msg("Starting %s on %s (%s UTC)" % (application_name,
                                                  otime.prettyDateNow(),
                                                  otime.prettyDateNowUTC()))

        self.fileObserver = txlog.FileLogObserver(daily_logfile)
        self.stdoutObserver = LogWithNoPrefix(sys.stdout)

        txlog.startLoggingWithObserver(self.stdoutObserver.emit)
        txlog.addObserver(self.fileObserver.emit)
Пример #6
0
    def start(self, logfile=None, application_name="ooniprobe"):
        from ooni.settings import config

        daily_logfile = None

        if not logfile:
            logfile = os.path.expanduser(config.basic.logfile)

        log_folder = os.path.dirname(logfile)
        log_filename = os.path.basename(logfile)

        daily_logfile = DailyLogFile(log_filename, log_folder)

        txlog.msg("Starting %s on %s (%s UTC)" %
                  (application_name, otime.prettyDateNow(),
                   otime.prettyDateNowUTC()))

        self.fileObserver = txlog.FileLogObserver(daily_logfile)
        self.stdoutObserver = LogWithNoPrefix(sys.stdout)

        txlog.startLoggingWithObserver(self.stdoutObserver.emit)
        txlog.addObserver(self.fileObserver.emit)