Esempio n. 1
0
def on_tick():
    global t
    global value

    og.request(3, {
        "function" : "push",
        "id" : 0,
        "time" : t,
        "value" : value
    })
    
    value += 2 * random.uniform(-1.0, 1.0)
    t += 1.0

    if t > 300:
        og.request(3, { "function" : "clear", "id" : 0 })
        t = 0
        value = 50
Esempio n. 2
0
def on_started():
    #og.register_script("#console", 'dashboard.shell.execute')

    if len(sys.argv) == 3:
        if sys.argv[2].endswith(".json"):
            std.load_json(sys.argv[2])
        else:
            print("Unrecognized format <'" + sys.argv[2] + "'> !")

    global nodes
    for nid in og.get_node_ids():
        label = og.get_node_label(nid)
        nodes[label] = nid

    response = og.request(3, { "function" : "add" })
    global timeseries
    timeseries = response['id']
Esempio 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()