示例#1
0
def given_gen_monitor_data(context,var_n,var_type):
    db.session.query(Monitor_Data).delete() # Delete all current_status entries
    ctypes = var_type.split(",")
    for x in range (0,int(var_n)):
        ctype = random.choice (ctypes)
        
        assert (ctype in ['net','host','user','sensor','server','system']) == True, "Unknown type '%s'" % ctype
        entry = Monitor_Data()
        # Select a entry 
        try:
            c_id = {
                'user': str(uuid.UUID(db.session.query(Users).order_by(func.rand()).limit(1).one().serialize['uuid'])),
                'net' : str(uuid.UUID(db.session.query(Net).order_by(func.rand()).limit(1).one().serialize['id'])),
                'host': str(uuid.UUID(db.session.query(Host).order_by(func.rand()).limit(1).one().serialize['id'])),
                'sensor': str(uuid.UUID(db.session.query(Host).order_by(func.rand()).limit(1).one().serialize['id'])),
                'system': str(uuid.UUID(db.session.query(System).order_by(func.rand()).limit(1).one().serialize['uuid'])),
                'server':  str(uuid.UUID(db.session.query(Server).order_by(func.rand()).limit(1).one().serialize['id'])),

    
          }.get(ctype)
        except NoResultFound:
           assert None,"Can't load a asset of type '%s'" % ctype
       # We have now the component_id
       # Select a msg_id
        entry.component_id =  get_bytes_from_uuid (c_id)
        entry.monitor_id = 1
        entry.component_type = "system"
        sleep(1)
        entry.data = "{\"msg\": \"Texto de prueba\"}"
        db.session.begin() 
        db.session.merge(entry)
        db.session.commit()
示例#2
0
def given_gen_monitor_data(context,var_n,var_type):
    db.session.query(Monitor_Data).delete() # Delete all current_status entries
    ctypes = var_type.split(",")
    for x in range (0,int(var_n)):
        ctype = random.choice (ctypes)
        
        assert (ctype in ['net','host','user','sensor','server','system']) == True, "Unknown type '%s'" % ctype
        entry = Monitor_Data()
        # Select a entry 
        try:
            c_id = {
                'user': str(uuid.UUID(db.session.query(Users).order_by(func.rand()).limit(1).one().serialize['uuid'])),
                'net' : str(uuid.UUID(db.session.query(Net).order_by(func.rand()).limit(1).one().serialize['id'])),
                'host': str(uuid.UUID(db.session.query(Host).order_by(func.rand()).limit(1).one().serialize['id'])),
                'sensor': str(uuid.UUID(db.session.query(Host).order_by(func.rand()).limit(1).one().serialize['id'])),
                'system': str(uuid.UUID(db.session.query(System).order_by(func.rand()).limit(1).one().serialize['uuid'])),
                'server':  str(uuid.UUID(db.session.query(Server).order_by(func.rand()).limit(1).one().serialize['id'])),

    
          }.get(ctype)
        except NoResultFound:
           assert None,"Can't load a asset of type '%s'" % ctype
       # We have now the component_id
       # Select a msg_id
        entry.component_id =  get_bytes_from_uuid (c_id)
        entry.monitor_id = 1
        entry.component_type = "system"
        sleep(1)
        entry.data = "{\"msg\": \"Texto de prueba\"}"
        db.session.begin() 
        db.session.merge(entry)
        db.session.commit()
示例#3
0
def save_monitor_data(monitor_id, component_id, component_type, data):
    result = True
    try:
        db.session.begin()
        monitor_data = Monitor_Data()
        monitor_data.component_id = get_bytes_from_uuid(component_id)
        monitor_data.timestamp = datetime.now()
        monitor_data.monitor_id = monitor_id
        monitor_data.data = data
        monitor_data.component_type = component_type
        db.session.add(monitor_data)
        db.session.commit()
    except Exception:
        db.session.rollback()
        result = False

    return result
示例#4
0
def save_monitor_data(monitor_id, component_id, component_type, data):
    result = True
    try:
        db.session.begin()
        monitor_data = Monitor_Data()
        monitor_data.component_id = get_bytes_from_uuid(component_id)
        monitor_data.timestamp = datetime.now()
        monitor_data.monitor_id = monitor_id
        monitor_data.data = data
        monitor_data.component_type = component_type
        db.session.add(monitor_data)
        db.session.commit()
    except Exception:
        db.session.rollback()
        result = False

    return result
示例#5
0
 def append_monitor_object(self, component_id, component_type, data):
     """
     Save the monitor data.
     :param component_id: The component id - uuid canonical string
     :param component_type: Component type (see Component Types)
     :param data: The monitor json data.
     :return: True is successful, False otherwise
     """
     return_value = True
     try:
         monitor_data = Monitor_Data()
         monitor_data.component_id = get_bytes_from_uuid(component_id)
         monitor_data.timestamp = datetime.now()
         monitor_data.monitor_id = self.monitor_id
         monitor_data.data = data
         monitor_data.component_type = component_type
         # db.session.add(monitor_data)
         self.monitor_objects.append(monitor_data)
     except Exception:
         return_value = False
     return return_value
示例#6
0
 def append_monitor_object(self, component_id, component_type, data):
     """
     Save the monitor data.
     :param component_id: The component id - uuid canonical string
     :param component_type: Component type (see Component Types)
     :param data: The monitor json data.
     :return: True is successful, False otherwise
     """
     return_value = True
     try:
         monitor_data = Monitor_Data()
         monitor_data.component_id = get_bytes_from_uuid(component_id)
         monitor_data.timestamp = datetime.now()
         monitor_data.monitor_id = self.monitor_id
         monitor_data.data = data
         monitor_data.component_type = component_type
         #db.session.add(monitor_data)
         self.monitor_objects.append(monitor_data)
     except Exception:
         return_value = False
     return return_value