Esempio n. 1
0
def get_processes():
  """Computes the response of the '/cluster/resources/processes' endpoint.

  Returns:
    The processes of the context graph.
  """
  processes = []

  gs = app.context_graph_global_state
  try:
    for node in kubernetes.get_nodes(gs):
      node_id = node['id']
      docker_host = node_id
      for container in docker.get_containers(gs, docker_host):
        container_id = container['id']
        processes.extend(docker.get_processes(gs, docker_host, container_id))

  except collector_error.CollectorError as e:
    return flask.jsonify(utilities.make_error(str(e)))
  except:
    msg = 'get_processes() failed with exception %s' % sys.exc_info()[0]
    app.logger.exception(msg)
    return flask.jsonify(utilities.make_error(msg))

  return flask.jsonify(utilities.make_response(processes, 'resources'))
Esempio n. 2
0
def get_processes():
    """Computes the response of the '/cluster/resources/processes' endpoint.

  Returns:
    The processes of the context graph.
  """
    processes = []

    gs = app.context_graph_global_state
    try:
        for node in kubernetes.get_nodes(gs):
            node_id = node['id']
            docker_host = node_id
            for container in docker.get_containers(gs, docker_host):
                container_id = container['id']
                processes.extend(
                    docker.get_processes(gs, docker_host, container_id))

    except collector_error.CollectorError as e:
        return flask.jsonify(utilities.make_error(str(e)))
    except:
        msg = 'get_processes() failed with exception %s' % sys.exc_info()[0]
        app.logger.exception(msg)
        return flask.jsonify(utilities.make_error(msg))

    return flask.jsonify(utilities.make_response(processes, 'resources'))
Esempio n. 3
0
def _do_compute_container(gs, docker_host, pod_guid, container, g):
  assert isinstance(gs, global_state.GlobalState)
  assert utilities.valid_string(docker_host)
  assert utilities.valid_string(pod_guid)
  assert utilities.is_wrapped_object(container, 'Container')
  assert isinstance(g, ContextGraph)

  container_id = container['id']
  container_guid = 'Container:' + container_id
  # TODO(vasbala): container_id is too verbose?
  g.add_resource(container_guid, container['annotations'],
                 'Container', container['timestamp'],
                 container['properties'])

  # Pod contains Container
  g.add_relation(pod_guid, container_guid, 'contains')

  # Processes in a Container
  for process in docker.get_processes(gs, docker_host, container_id):
    process_id = process['id']
    process_guid = 'Process:' + process_id
    g.add_resource(process_guid, process['annotations'],
                   'Process', process['timestamp'], process['properties'])

    # Container contains Process
    g.add_relation(container_guid, process_guid, 'contains')

  # Image from which this Container was created
  image_id = utilities.get_attribute(
      container, ['properties', 'Config', 'Image'])
  if not utilities.valid_string(image_id):
    # Image ID not found
    return
  image = docker.get_image(gs, docker_host, image_id)
  if image is None:
    # image not found
    return

  image_guid = 'Image:' + image['id']
  # Add the image to the graph only if we have not added it before.
  g.add_resource(image_guid, image['annotations'], 'Image',
                 image['timestamp'], image['properties'])

  # Container createdFrom Image
  g.add_relation(container_guid, image_guid, 'createdFrom')
Esempio n. 4
0
def _do_compute_container(gs, docker_host, pod_guid, container, g):
    assert isinstance(gs, global_state.GlobalState)
    assert utilities.valid_string(docker_host)
    assert utilities.valid_string(pod_guid)
    assert utilities.is_wrapped_object(container, 'Container')
    assert isinstance(g, ContextGraph)

    container_id = container['id']
    container_guid = 'Container:' + container_id
    # TODO(vasbala): container_id is too verbose?
    g.add_resource(container_guid, container['annotations'], 'Container',
                   container['timestamp'], container['properties'])

    # Pod contains Container
    g.add_relation(pod_guid, container_guid, 'contains')

    # Processes in a Container
    for process in docker.get_processes(gs, docker_host, container_id):
        process_id = process['id']
        process_guid = 'Process:' + process_id
        g.add_resource(process_guid, process['annotations'], 'Process',
                       process['timestamp'], process['properties'])

        # Container contains Process
        g.add_relation(container_guid, process_guid, 'contains')

    image = docker.get_image(gs, docker_host, container)
    if image is None:
        # image not found
        return

    image_guid = 'Image:' + image['id']
    # Add the image to the graph only if we have not added it before.
    g.add_resource(image_guid, image['annotations'], 'Image',
                   image['timestamp'], image['properties'])

    # Container createdFrom Image
    g.add_relation(container_guid, image_guid, 'createdFrom')