def update_status(self):
        try:
            self.update_ips()
        except RuntimeError:
            self.ip = None
        if not self.ip:
            self.clear_tracker_without_ip()
            return

        self.update_ipapi_data()
        self.last_checked = int(time())
        pp = pprint.PrettyPrinter(width=999999, compact=True)
        t1 = time()
        debug = {
            'url': self.url,
            'ip': list(self.ip)[0],
            'time': strftime("%H:%M:%S UTC", gmtime(t1))
        }
        try:
            if parse.urlparse(self.url).scheme == 'udp':
                parsed, raw, ip = scraper.announce_udp(self.url)
                self.interval = parsed['interval']
                pretty_data = pp.pformat(parsed)
                for one_ip in scraper.my_ips:
                    pretty_data = pretty_data.replace(one_ip, 'redacted')
                debug['info'] = pretty_data
                trackon.raw_data.appendleft(debug)
            else:
                response = scraper.announce_http(self.url)
                self.interval = response['interval']
                pretty_data = pp.pformat(response)
                for one_ip in scraper.my_ips:
                    pretty_data = pretty_data.replace(one_ip, 'redacted')
                debug['info'] = pretty_data
                trackon.raw_data.appendleft(debug)
            self.latency = int((time() - t1) * 1000)
            self.is_up()
            debug['status'] = 1
            print("TRACKER UP")
        except RuntimeError as e:
            logger.info('Tracker down: ' + self.url + ' Cause: ' + str(e))
            debug.update({'info': str(e), 'status': 0})
            trackon.raw_data.appendleft(debug)
            print("TRACKER DOWN")
            self.is_down()
        if self.uptime == 0:
            self.interval = 10800
        self.update_uptime()

        trackon.update_in_db(self)
Exemple #2
0
    def update_status(self):
        try:
            self.update_ips()
        except RuntimeError:
            logger.info('Hostname not found')
            return
        self.update_ipapi_data()
        print("TRACKER TO CHECK: " + self.url)
        self.last_checked = int(time())
        pp = pprint.PrettyPrinter(width=999999, compact=True)
        t1 = time()
        debug = {
            'url': self.url,
            'ip': self.ip[0],
            'time': strftime("%H:%M:%S UTC", gmtime(t1))
        }
        try:
            if urlparse(self.url).scheme == 'udp':
                parsed, raw, ip = scraper.announce_udp(self.url)
                self.interval = parsed['interval']
                pretty_data = pp.pformat(parsed)
                debug[
                    'info'] = "Hex response: " + raw + '<br>' + "Parsed: " + pretty_data
                trackon.raw_data.appendleft(debug)
            else:
                response = scraper.announce_http(self.url)
                self.interval = response['interval']
                pretty_data = pp.pformat(response)
                debug['info'] = pretty_data
                trackon.raw_data.appendleft(debug)
            self.latency = int((time() - t1) * 1000)
            self.is_up()
            debug['status'] = 1
            print("TRACKER UP")
        except RuntimeError as e:
            logger.info('Tracker down: ' + self.url + ' Cause: ' + str(e))
            debug.update({'info': str(e), 'status': 0})
            trackon.raw_data.appendleft(debug)
            print("TRACKER DOWN")
            self.is_down()
        self.update_uptime()

        trackon.update_in_db(self)
Exemple #3
0
    def update_status(self):
        try:
            self.update_ips()
        except RuntimeError:
            self.ip = None
        if not self.ip:
            self.clear_tracker_without_ip()
            return

        self.update_ipapi_data()
        self.last_checked = int(time())
        pp = pprint.PrettyPrinter(width=999999, compact=True)
        t1 = time()
        debug = {
            "url": self.url,
            "ip": list(self.ip)[0],
            "time": strftime("%H:%M:%S UTC", gmtime(t1)),
        }
        try:
            if parse.urlparse(self.url).scheme == "udp":
                response, _, _ = scraper.announce_udp(self.url)
            else:
                response = scraper.announce_http(self.url)

            self.interval = response["interval"]
            pretty_data = scraper.redact_origin(pp.pformat(response))
            debug["info"] = pretty_data
            trackon.raw_data.appendleft(debug)
            self.latency = int((time() - t1) * 1000)
            self.is_up()
            debug["status"] = 1
            logger.info(f"{self.url} status is UP")
        except RuntimeError as e:
            logger.info(f"{self.url} status is DOWN. Cause: {str(e)}")
            debug.update({"info": str(e), "status": 0})
            trackon.raw_data.appendleft(debug)
            self.is_down()
        if self.uptime == 0:
            self.interval = 10800
        self.update_uptime()

        trackon.update_in_db(self)