Пример #1
0
def clients_info():
    """
    Gets the information on all the currently active clients.
    Retruns:
      list of dicts containing client information
    """
    sclients = sorted_clients(models.Client.objects.exclude(status=models.Client.DOWN))
    active_clients = [] # clients that we've seen in <= 60 s
    inactive_clients = [] # clients that we've seen in > 60 s
    for c in sclients:
        d = {'pk': c.pk,
            "ip": c.ip,
            "name": c.name,
            "message": c.status_message,
            "status": c.status_str(),
            "lastseen": TimeUtils.human_time_str(c.last_seen),
            }
        if c.unseen_seconds() > 2*7*24*60*60: # 2 weeks
            # do it like this so that last_seen doesn't get updated
            models.Client.objects.filter(pk=c.pk).update(status=models.Client.DOWN)
        elif c.unseen_seconds() > 120:
            d["status_class"] = "client_NotSeen"
            inactive_clients.append(d)
        else:
            d["status_class"] = "client_%s" % c.status_slug()
            active_clients.append(d)
    clients = [] # sort these so that active clients (seen in < 60 s) are first
    for d in active_clients:
        clients.append(d)
    for d in inactive_clients:
        clients.append(d)
    return clients
Пример #2
0
 def test_human_time_str(self):
     TimeUtils.human_time_str(datetime.datetime.now())