Esempio n. 1
0
def receive(uid):
    """Function for handling /receive/<uid> route.

    Args:
        uid: Unique Identifier of an Infoset Agent

    Returns:
        Text response of Received

    """
    # Read configuration
    config = Config()
    cache_dir = config.ingest_cache_directory()

    # Get Json from incoming agent POST
    data = request.json
    timestamp = data['timestamp']
    uid = data['uid']
    hostname = data['hostname']

    # Create a hash of the hostname
    host_hash = jm_general.hashstring(hostname, sha=1)
    json_path = ('%s/%s_%s_%s.json') % (cache_dir, timestamp, uid, host_hash)

    with open(json_path, "w+") as temp_file:
        json.dump(data, temp_file)
        temp_file.close()

    return "Received"
Esempio n. 2
0
def _get_yaml_hosts():
    """Get hosts listed in toplogy YAML files.

    Args:
        None

    Returns:
        hosts: Dict of hostnames

    """
    # Read configuration
    config = Config()
    topology_directory = config.topology_directory()

    hosts = {}
    for root, _, files in walk(topology_directory):
        for filename in files:
            filepath = path.join(root, filename)
            hosts[filename[:-5]] = filepath  # Add it to the list.
    return hosts