Exemple #1
0
def addnode(request):
    """
    Add a new node to Node class. If it is already exists the fields "timestamp" and "checked" are updated only.
    """
    ip_address = request.META.get("REMOTE_ADDR")
    hostname = ""
    if (request.GET.has_key('url')):
        hostname = str(request.GET['url'])
        nodestat = getNodeStats(hostname + "/stats/get")
        if (nodestat is not ""):
            nodes = Node.objects.filter(hostname=hostname)
            if (nodes.count() == 0):
                node = Node()
                node.hostname = hostname
                node.ip = ip_address
            else:
                node = nodes[0]
            
            node.timestamp = datetime.now()
            node.checked = True
            node.save()
            collectnodestats(node)
            return HttpResponse({'success': True})
            
    return HttpResponse({'fail': True})
Exemple #2
0
def addnode(request):
    """
    Add a new node to Node class. If it is already exists the fields "timestamp" and "checked" are updated only.
    """
    ip_address = request.META.get("REMOTE_ADDR")
    hostname = ""
    if (request.GET.has_key('url')):
        hostname = str(request.GET['url'])
        nodestat = getNodeStats(hostname + "/stats/get")
        if (len(nodestat) == 1 and nodestat[0]['date'] is not None and nodestat[0]['lrview'] is not None):
            nodes = Node.objects.filter(hostname=hostname)
            if (nodes.count() == 0):
                node = Node()
                node.hostname = hostname
                node.ip = ip_address
            else:
                node = nodes[0]
            
            nodes = Node.objects.filter(ip__contains=ip_address).exclude(hostname=hostname)
            if (nodes.count() > 0):
                node.suspected = node.suspected + 1
                
            if (ip_address not in node.ip):
                node.ip = node.ip + " " + ip_address
            node.timestamp = datetime.now()
            node.checked = True
            node.save()
            
            #if (node.suspected == 0):
            collectnodestats(node)
            return HttpResponse({'success': True})
        else:
            print "Excluded node: " + hostname
            Node.objects.filter(hostname=hostname).delete()
            
    return HttpResponse({'fail': True})
Exemple #3
0
def addnode(request):
    ip_address = request.META.get("REMOTE_ADDR")
    hostname = ""
    if (request.GET.has_key('url')):
        hostname = str(request.GET['url'])
        code = urlopen(hostname + "/stats/days").code
        if (code / 100 < 4):
            nodes = Node.objects.filter(hostname=hostname)
            if (nodes.count() == 0):
                node = Node()
                node.hostname = hostname
                node.ip = ip_address
            else:
                node = nodes[0]
            
            node.timestamp = datetime.now()
            node.checked = True
            node.save()
            collectnodestats(node)
            return HttpResponse({'success': True})
        
    return HttpResponse({'fail': True})