Пример #1
0
def db_getidxdeviceagent(value):
    """Get DeviceAgent data from the DB by idx value.

    Args:
        value: idx_deviceagent

    Returns:
        data: JSON data for the selected deviceagent

    """
    # Initialize key variables
    idx_deviceagent = int(value)

    # Get data from cache
    key = ('DB/DeviceAgent/idx_deviceagent/{}'.format(idx_deviceagent))
    cache_value = CACHE.get(key)

    # Process cache miss
    if cache_value is None:
        query = db_deviceagent.GetIDXDeviceAgent(idx_deviceagent)
        data = query.everything()
        CACHE.set(key, data)
    else:
        data = cache_value

    # Return
    return jsonify(data)
Пример #2
0
def db_deviceagent_agentindices(value):
    """Get all agent indices from the DB.

    Args:
        idx_device: Index value of device

    Returns:
        List of agent indices reporting on the device

    """
    # Initialize key variables
    idx_device = int(value)

    # Get data from cache
    key = ('DB/Device/idx_device/{}/agents'.format(idx_device))
    cache_value = CACHE.get(key)

    # Process cache miss
    if cache_value is None:
        data = db_deviceagent.agent_indices(idx_device)
        CACHE.set(key, data)
    else:
        data = cache_value

    # Return
    return jsonify(data)
Пример #3
0
def db_getidxdevice(value):
    """Get device data from the DB by idx value.

    Args:
        value: Index from the Device table

    Returns:
        Home Page

    """
    # Initialize key variables
    idx_device = int(value)

    # Get data from cache
    key = ('DB/Device/idx_device/{}'.format(idx_device))
    cache_value = CACHE.get(key)

    # Process cache miss
    if cache_value is None:
        query = db_device.GetIDXDevice(idx_device)
        data = query.everything()
        CACHE.set(key, data)
    else:
        data = cache_value

    # Return
    return jsonify(data)
Пример #4
0
def agents_query():
    """Get Agent data from the DB by id_agent value.

    Args:
        None

    Returns:
        data: JSON data for the selected agent

    """
    # Initialize key variables
    id_agent = request.args.get('id_agent')

    if bool(id_agent) is True:
        # Process id_datapoint request
        key = ('DB/Agent/id_agent/{}'.format(id_agent))
        cache_value = CACHE.get(key)

        # Process cache miss
        if cache_value is None:
            query = db_agent.GetIDAgent(id_agent)
            data = query.everything()
            CACHE.set(key, data)
        else:
            data = cache_value
    else:
        # Process general request
        key = ('DB/Agent/id_agent')
        cache_value = CACHE.get(key)

        # Process cache miss
        if cache_value is None:
            data = db_agent.get_all_agents()
            CACHE.set(key, data)
        else:
            data = cache_value

    # Return
    return jsonify(data)
Пример #5
0
def db_devagt_get_all_device_agents():
    """Get all DeviceAgent data from the DB.

    Args:
        None

    Returns:
        Agent data

    """
    # Get data from cache
    key = ('DB/DeviceAgent')
    cache_value = CACHE.get(key)

    # Process cache miss
    if cache_value is None:
        data = db_deviceagent.get_all_device_agents()
        CACHE.set(key, data)
    else:
        data = cache_value

    # Return
    return jsonify(data)
Пример #6
0
def agents(idx_agent):
    """Get Agent data from the DB by idx value.

    Args:
        idx_agent: Agent table idx_agent

    Returns:
        data: JSON data for the selected agent

    """
    # Get data from cache
    key = ('DB/Agent/idx_agent/{}'.format(idx_agent))
    cache_value = CACHE.get(key)

    # Process cache miss
    if cache_value is None:
        query = db_agent.GetIDXAgent(general.integerize(idx_agent))
        data = query.everything()
        CACHE.set(key, data)
    else:
        data = cache_value

    # Return
    return jsonify(data)