pythondjangoopenstackceilometer

Django Ceilometer get events for all projects


I have a problem for getting all events for all tenants/projects in Ceilometer. When I get the event list I always get only the list of events related to project that my user assigned. The user is admin in openstack.

Explaining in more detail:

Here is my sample code:

def sync_resources():
    logger.info("Executing sync_resources")
    sync_tenants()
    tenants = Tenant.objects.all()
    managers = Manager.objects.filter(is_active=True)
    for manager in managers:
       services = manager.services.all()
       regions = manager.region_set.all()
       for region in regions:
           ceilometer_driver = CeilometerDriver(region_name=region.name, **manager.ceilometer_params)
           if ceilometer_driver.is_authenticated:
               for tenant in tenants:
                   queries = [ceilometer_driver.make_query("project_id", ceilometer_driver.EQUAL, tenant.tenant_id)]
                   resource_list = ceilometer_driver.get_event_list(query=queries)

The sample function uses a driver that I have written. And the driver first authenticates with username,password and project_id. After that it should get the list of events based on prjojects. The problem here is that even the user is admin I can only get the events that the admin is assigned as user.

For example instead of getting the events when I try to get the resource list I get all. However when I try events I get only events of projects for the user.

# returns all the resources for all tenants/projects
resource_list = ceilometer_driver.get_resource_list()

# returns only the events for user projects
resource_list = ceilometer_driver.get_event_list()

When I try it with REST API:

This gets again all resources for all projects: http://192.168.101.11:8777/v2/resources

This one gets only projects events relevant to user http://192.168.101.11:8777/v2/events

This one returns empty if the admin user is not assigned to project: http://192.168.101.11:8777/v2/events?q.field=project_id&q.value=d81584b38e56444cad4823b2bd2aab34

From terminal:

This gets again all resources for all projects:

$ ceilometer resource-list

This one gets only projects events relevant to user

$ ceilometer event-list    

Summary:

I tried it in code, REST API and terminal and all the results are the same. As admin user, when I select resources I get all; however for events I get only the events relevant to my projects.

I need a way to get all of the events for all the projects. I also do not understand why there is such a control for events!?


Solution

  • You need to make a filtering query using all_tenants eq True as documented on the bottom of the API docs.

    2) Specify the ‘all_tenants=True’ query parameter to get all events for all projects, this is only allowed by admin users.

    Note that this is a fairly recent addition to the Panko/Ceilomter API avaiable in Queens and Pike (though it's been backported to Ocata as well). This query is only available to admin users using an admin token.

    I can't speak for the python client libs and whether they expose it, but you can successfully query it straight from the API. I can confirm this works, at meshcloud we use this API in production ;-)