Ejemplo n.º 1
0
def info():
    print(
        str(graphiti.count_nodes()) + " nodes, " +
        str(graphiti.count_links()) + " links.")
Ejemplo n.º 2
0
def info():
    print (str(graphiti.count_nodes()) + " nodes, " + str(graphiti.count_edges()) + " edges.")
Ejemplo n.º 3
0
def on_idle():

    global queue
    global nodes
    global edges
    global t
    global job_id

    mutex.acquire()

    for element in queue:
        if og.count_nodes() > 1000:
            #og.register_script("#console", 'dashboard.shell.execute')
            og.remove_job(job_id)
            continue
        #print(element)

        # --- Space Document ---
        name = element['name']
        rr = element['rr']
        asn = element['geoip']['rr_asn']

        '''
        if asn is not None:
            asn = asn.split()[0][2:]
            if asn in nodes:

                t = time.time()
                r = 0.5 + math.cos(t)
                g = 0.5 + math.sin(t)
                b = 0.5 + math.sin(t + math.pi / 2)
                a = 0.5
                og.set_node_attribute(nodes[asn], 'og:space:color', 'vec4', "{0} {1} {2} {3}".format(r, g, b, a))
        '''
        
        if name not in nodes:
            nodes[name] = og.add_node(name)
            og.set_node_attribute(nodes[name], 'type', 'string', 'name')

        if rr not in nodes:
            nodes[rr] = og.add_node(rr)
            og.set_node_attribute(nodes[rr], 'type', 'string', 'ip')
        
        edge_key = "{0} -> {1}".format(name, rr)
        if edge_key not in edges:
            edges[edge_key] = og.add_edge(nodes[name], nodes[rr])
        

        # --- WorldMap + Globe Documents ---
        
        try:
            record = gi.record_by_addr(rr)
        except:
            continue
        if record is None:
            continue
        msg = {
            'function' : 'add',
            'latitude' : record['latitude'],
            'longitude' :  record['longitude'],
            'color.r' : random.uniform(0.3, 1.0),
            'color.g' : 0.0,
            'color.b' : 0.0,
            'color.a' : 0.75,
            'size' : 2.0
        }
        og.request(1, msg)
        og.request(2, msg)
        

    queue = list()
    
    mutex.release()