def _get_events(check, limit):
    pings = Ping.objects.filter(owner=check).order_by('-id')[:limit]
    pings = list(pings)
    prev = None
    for ping in reversed(pings):
        if ((ping.kind != 'start') and prev and (prev.kind == 'start')):
            delta = (ping.created - prev.created)
            if (delta < MAX_DELTA):
                setattr(ping, 'delta', delta)
        prev = ping
    alerts = []
    if len(pings):
        cutoff = pings[(- 1)].created
        alerts = Notification.objects.select_related('channel').filter(owner=check, check_status='down', created__gt=cutoff)
    events = (pings + list(alerts))
    events.sort(key=(lambda el: el.created), reverse=True)
    return events
def _get_events(check, limit):
    pings = Ping.objects.filter(owner=check).order_by('-id')[:limit]
    pings = list(pings)
    prev = None
    for ping in reversed(pings):
        if ((ping.kind != 'start') and prev and (prev.kind == 'start')):
            delta = (ping.created - prev.created)
            if (delta < MAX_DELTA):
                setattr(ping, 'delta', delta)
        prev = ping
    alerts = []
    if len(pings):
        cutoff = pings[(- 1)].created
        alerts = Notification.objects.select_related('channel').filter(owner=check, check_status='down', created__gt=cutoff)
    events = (pings + list(alerts))
    events.sort(key=(lambda el: el.created), reverse=True)
    return events