示例#1
0
    def dispatch(self, request, *args, **kwargs):
        if is_first_run():
            return redirect('/start')

        return TemplateResponse(request,
                                'status.html',
                                context=self.get_context_data())
示例#2
0
 def retrieve(self, request, *args, **kwargs):
     if not is_first_run():
         queryset = AverageQuality.objects.latest()
         if queryset is None:
             # print('q: {0}'.format(queryset))
             serializer = ErrorMsg('', many=False)
         else:
             serializer = QualitySerializer(queryset, many=False)
     else:
         serializer = ErrorMsg('', many=False)
     return Response(serializer.data)
示例#3
0
def fill():
    if is_first_run():
        return
    speed_values = pyspeedtest.SpeedTest()
    ping = round(speed_values.ping())
    download = round(speed_values.download())
    upload = round(speed_values.upload())
    entry = Speed(time=timezone.now(),
                  server=speed_values.host,
                  ping=ping,
                  download=download,
                  upload=upload)
    entry.save()
示例#4
0
def push():
    if is_first_run() or not use_prtg():
        return

    logging.basicConfig(level=logging.DEBUG)
    queryset = Speed.objects.latest()
    prtg_settings = Settings.objects.first()

    payload = json.dumps(PrtgSpeedSerializer(queryset, many=False).data)
    resp = requests.get("{0}{1}?content={2}".format(prtg_settings.prtg_url, prtg_settings.prtg_token, payload))

    if resp.status_code == 200 and 'application/json' in resp.headers['content-type']:
        a = resp.json()
        if 'status' in a.keys() and a["status"] == "Ok":
            return 0
    return 1
示例#5
0
def calc_qos():
    if is_first_run():
        return
    last_24 = Speed.objects.all().filter(time__gte=datetime.now() -
                                         timedelta(days=1))
    avg_down = 0
    avg_up = 0
    for o in last_24:
        avg_down += o.download
        avg_up += o.upload
    avg_down /= len(last_24)
    avg_up /= len(last_24)
    qos = AverageQuality(time=timezone.now(),
                         avg_download=avg_down,
                         avg_upload=avg_up)
    qos.save()
示例#6
0
    def get(self, request):
        if is_first_run():
            return redirect('/start')

        return TemplateResponse(request, 'overview.html')