Ejemplo n.º 1
0
def ping(request, code):
    check = get_object_or_404(Check, code=code)

    check.n_pings = F("n_pings") + 1
    check.last_ping = timezone.now()
    check.last_ping_body = request.body[:10000]
    check.alert_after = check.get_alert_after()
    if check.status in ("new", "paused"):
        check.status = "up"

    check.save()
    check.refresh_from_db()

    ping = Ping(owner=check)
    headers = request.META
    ping.n = check.n_pings
    remote_addr = headers.get("HTTP_X_FORWARDED_FOR", headers["REMOTE_ADDR"])
    ping.remote_addr = remote_addr.split(",")[0]
    ping.scheme = headers.get("HTTP_X_FORWARDED_PROTO", "http")
    ping.method = headers["REQUEST_METHOD"]
    # If User-Agent is longer than 200 characters, truncate it:
    ping.ua = headers.get("HTTP_USER_AGENT", "")[:200]
    ping.save()

    response = HttpResponse("OK")
    response["Access-Control-Allow-Origin"] = "*"
    return response
Ejemplo n.º 2
0
def handle_email(request):
    if request.method != "POST":
        return HttpResponseBadRequest()

    events = json.loads(request.POST["mandrill_events"])
    for event in events:
        for recipient_address, recipient_name in event["msg"]["to"]:
            code, domain = recipient_address.split("@")
            try:
                check = Check.objects.get(code=code)
            except ValueError:
                continue
            except Check.DoesNotExist:
                continue

            check.n_pings = F("n_pings") + 1
            check.last_ping = timezone.now()
            if check.status == "new":
                check.status = "up"

            check.save()

            ping = Ping(owner=check)
            ping.scheme = "email"
            ping.save()

    response = HttpResponse("OK")
    return response
Ejemplo n.º 3
0
def handle_email(request):
    if request.method != "POST":
        return HttpResponseBadRequest()

    events = json.loads(request.POST["mandrill_events"])
    for event in events:
        for recipient_address, recipient_name in event["msg"]["to"]:
            code, domain = recipient_address.split("@")
            try:
                check = Check.objects.get(code=code)
            except ValueError:
                continue
            except Check.DoesNotExist:
                continue

            check.last_ping = timezone.now()
            if check.status == "new":
                check.status = "up"

            check.save()

            ping = Ping(owner=check)
            ping.scheme = "email"
            ping.body = event["msg"]["raw_msg"]
            ping.save()

    response = HttpResponse("OK")
    return response
Ejemplo n.º 4
0
def ping(request, code):
    try:
        check = Check.objects.get(code=code)
    except Check.DoesNotExist:
        return HttpResponseBadRequest()

    check.n_pings = F("n_pings") + 1
    check.last_ping = timezone.now()
    if check.status == "new":
        check.status = "up"

    check.save()
    check.refresh_from_db()

    ping = Ping(owner=check)
    headers = request.META
    ping.n = check.n_pings
    remote_addr = headers.get("HTTP_X_FORWARDED_FOR", headers["REMOTE_ADDR"])
    ping.remote_addr = remote_addr.split(",")[0]
    ping.scheme = headers.get("HTTP_X_FORWARDED_PROTO", "http")
    ping.method = headers["REQUEST_METHOD"]
    # If User-Agent is longer than 200 characters, truncate it:
    ping.ua = headers.get("HTTP_USER_AGENT", "")[:200]
    ping.save()

    response = HttpResponse("OK")
    response["Access-Control-Allow-Origin"] = "*"
    return response
Ejemplo n.º 5
0
def ping(request, code):
    try:
        check = Check.objects.get(code=code)
    except Check.DoesNotExist:
        return HttpResponseBadRequest()

    check.last_ping = timezone.now()
    if check.status == "new":
        check.status = "up"

    check.save()

    ping = Ping(owner=check)
    headers = request.META
    ping.remote_addr = headers.get("HTTP_X_REAL_IP", headers["REMOTE_ADDR"])
    ping.scheme = headers.get("HTTP_X_SCHEME", "http")
    ping.method = headers["REQUEST_METHOD"]
    # If User-Agent is longer than 200 characters, truncate it:
    ping.ua = headers.get("HTTP_USER_AGENT", "")[:200]
    ping.body = request.body
    ping.save()

    response = HttpResponse("OK")
    response["Access-Control-Allow-Origin"] = "*"
    return response
Ejemplo n.º 6
0
def ping(request, code):
    try:
        check = Check.objects.get(code=code)
    except Check.DoesNotExist:
        return HttpResponseBadRequest()

    check.n_pings = F("n_pings") + 1
    check.last_ping = timezone.now()
    if check.status in ("new", "paused"):
        check.status = "up"
    if check.runs_too_often() == 'over':
        check.status = "over"

    check.save()
    check.refresh_from_db()
    # check from the db send mail to user on jobs that are running too often
    check.runs_too_often()

    ping = Ping(owner=check)
    headers = request.META
    ping.n = check.n_pings
    remote_addr = headers.get("HTTP_X_FORWARDED_FOR", headers["REMOTE_ADDR"])
    ping.remote_addr = remote_addr.split(",")[0]
    ping.scheme = headers.get("HTTP_X_FORWARDED_PROTO", "http")
    ping.method = headers["REQUEST_METHOD"]
    # If User-Agent is longer than 200 characters, truncate it:
    ping.ua = headers.get("HTTP_USER_AGENT", "")[:200]
    ping.save()

    response = HttpResponse("OK" + check.status)
    response["Access-Control-Allow-Origin"] = "*"
    return response
Ejemplo n.º 7
0
def ping(request, code):
    try:
        check = Check.objects.get(code=code)
    except Check.DoesNotExist:
        return HttpResponseBadRequest()

    check.n_pings = F("n_pings") + 1
    if check.last_ping:
        now = timezone.now()
        reverse_grace = check.timeout - check.grace
        if reverse_grace <= td(seconds=0):
            too_early = now
        else:
            too_early = check.last_ping + reverse_grace
        if now <= too_early:
            check.often = True
        else:
            check.often = False

    check.last_ping = timezone.now()
    if check.status in ("new", "paused"):
        check.status = "up"

    check.save()
    check.refresh_from_db()

    if check.often:
        check.send_alert()

    ping = Ping(owner=check)
    headers = request.META
    ping.n = check.n_pings
    remote_addr = headers.get("HTTP_X_FORWARDED_FOR", headers["REMOTE_ADDR"])
    ping.remote_addr = remote_addr.split(",")[0]
    ping.scheme = headers.get("HTTP_X_FORWARDED_PROTO", "http")
    ping.method = headers["REQUEST_METHOD"]
    # If User-Agent is longer than 200 characters, truncate it:
    ping.ua = headers.get("HTTP_USER_AGENT", "")[:200]
    ping.save()

    response = HttpResponse("OK")
    response["Access-Control-Allow-Origin"] = "*"
    return response
Ejemplo n.º 8
0
def _ping(headers, check):
    check.n_pings = F("n_pings") + 1
    check.last_ping = timezone.now()
    if check.status == "new":
        check.status = "up"

    check.save()
    check.refresh_from_db()

    ping = Ping(owner=check)
    ping.n = check.n_pings
    remote_addr = headers.get("HTTP_X_FORWARDED_FOR", headers["REMOTE_ADDR"])
    ping.remote_addr = remote_addr.split(",")[0]
    ping.scheme = headers.get("HTTP_X_FORWARDED_PROTO", "http")
    ping.method = headers["REQUEST_METHOD"]
    # If User-Agent is longer than 200 characters, truncate it:
    ping.ua = headers.get("HTTP_USER_AGENT", "")[:200]
    ping.save()
    return
Ejemplo n.º 9
0
def ping(request, code):
    try:
        check = Check.objects.get(code=code)
    except Check.DoesNotExist:
        return HttpResponseBadRequest()

    if check.status in ("new", "paused"):
        check.status = "up"

    # only confirm if a check is too_often if the check is not in down-wise statuses
    if check.status not in ("down"):
        if check.running_too_often():
            check.status = "too often"
        else:
            check.status = "up"

    now = timezone.now()
    check.n_pings = F("n_pings") + 1
    check.last_ping = now
    # store expected time for next ping
    check.next_ping = now + check.timeout

    check.save()
    check.refresh_from_db()

    ping = Ping(owner=check)
    headers = request.META
    ping.n = check.n_pings
    remote_addr = headers.get("HTTP_X_FORWARDED_FOR", headers["REMOTE_ADDR"])
    ping.remote_addr = remote_addr.split(",")[0]
    ping.scheme = headers.get("HTTP_X_FORWARDED_PROTO", "http")
    ping.method = headers["REQUEST_METHOD"]
    # If User-Agent is longer than 200 characters, truncate it:
    ping.ua = headers.get("HTTP_USER_AGENT", "")[:200]
    ping.save()

    response = HttpResponse("OK")
    response["Access-Control-Allow-Origin"] = "*"
    return response
Ejemplo n.º 10
0
def ping(request, code):
    try:
        check = Check.objects.get(code=code)
    except Check.DoesNotExist:
        return HttpResponseBadRequest()

    # num_pings= Ping.objects.filter(owner=check).filter(created__range=(check.prev_ping,deadline))
    # import pdb; pdb.set_trace()
    # if len(num_pings) > 1:
    if check.last_ping:
        deadline = check.last_ping + check.timeout - check.grace
        if timezone.now() > check.last_ping and timezone.now() < deadline:
            check.often = True
        else:
            check.often = False

    check.n_pings = F("n_pings") + 1
    check.last_ping = timezone.now()
    if check.status in ("new", "paused"):
        check.status = "up"

    check.save()
    check.refresh_from_db()
    if check.often:
        check.often_alert()
    ping = Ping(owner=check)
    headers = request.META
    ping.n = check.n_pings
    remote_addr = headers.get("HTTP_X_FORWARDED_FOR", headers["REMOTE_ADDR"])
    ping.remote_addr = remote_addr.split(",")[0]
    ping.scheme = headers.get("HTTP_X_FORWARDED_PROTO", "http")
    ping.method = headers["REQUEST_METHOD"]
    # If User-Agent is longer than 200 characters, truncate it:
    ping.ua = headers.get("HTTP_USER_AGENT", "")[:200]
    ping.save()

    response = HttpResponse("OK")
    response["Access-Control-Allow-Origin"] = "*"
    return response