(self, request, tenant_id)
return json.dumps({'metadata': metadata, 'values': values})
serves the overview api call,returns all entities,checks and alarms
serves the overview api call,returns all entities,checks and alarms
serves the overview api call returns all entities checks and alarms
def overview(self, request, tenant_id):
        """
        serves the overview api call,returns all entities,checks and alarms
        """
        entity_map = self._entity_cache_for_tenant(tenant_id).entities
        all_entities = None
        if b'entityId' in request.args:
            entity_ids = [a.decode("utf-8") for a in request.args[b'entityId']]
            all_entities = [entity_map[entity_id] for entity_id in entity_ids
                            if entity_id in entity_map]
            if len(all_entities) == 0:
                err = ObjectDoesNotExist(
                    object_type='Entity', key=','.join(entity_ids))
                request.setResponseCode(err.code)
                return json.dumps(err.to_json())
        else:
            all_entities = list(entity_map.values())

        maas_store = self._entity_cache_for_tenant(tenant_id).maas_store
        page_limit = min(int(request.args.get(b'limit', [100])[0]), 1000)
        offset = 0
        current_marker = request.args.get(b'marker', [None])[0]
        if current_marker is not None:
            current_marker = current_marker.decode("utf-8")
            try:
                offset = all_entities.index(
                    Matcher(lambda entity: entity.id == current_marker))
            except ValueError:
                offset = 0

        entities = all_entities[offset:offset + page_limit]
        next_marker = None
        if offset + page_limit < len(all_entities):
            next_marker = all_entities[offset + page_limit].id

        metadata = {
            'count': len(entities),
            'marker': current_marker,
            'next_marker': next_marker,
            'limit': page_limit,
            'next_href': None
        }
        values = [{'alarms': entity.list_alarms(),
                   'checks': entity.list_checks(),
                   'entity': entity.to_json(),
                   'latest_alarm_states': [
                       state.brief_json()
                       for state in maas_store.latest_alarm_states_for_entity(entity.id)]}

                  for entity in entities]
        request.setResponseCode(200)
        return json.dumps({'metadata': metadata, 'values': values})
def overview ( self , request , tenant_id ) : entity_map = self . _entity_cache_for_tenant ( tenant_id ) . entities all_entities = None if b'entityId' in request . args : entity_ids = [ a . decode ( "utf-8" ) for a in request . args [ b'entityId' ] ] all_entities = [ entity_map [ entity_id ] for entity_id in entity_ids if entity_id in entity_map ] if len ( all_entities ) == 0 : err = ObjectDoesNotExist ( object_type = 'Entity' , key = ',' . join ( entity_ids ) ) request . setResponseCode ( err . code ) return json . dumps ( err . to_json ( ) ) else : all_entities = list ( entity_map . values ( ) ) maas_store = self . _entity_cache_for_tenant ( tenant_id ) . maas_store page_limit = min ( int ( request . args . get ( b'limit' , [ 100 ] ) [ 0 ] ) , 1000 ) offset = 0 current_marker = request . args . get ( b'marker' , [ None ] ) [ 0 ] if current_marker is not None : current_marker = current_marker . decode ( "utf-8" ) try : offset = all_entities . index ( Matcher ( lambda entity : entity . id == current_marker ) ) except ValueError : offset = 0 entities = all_entities [ offset : offset + page_limit ] next_marker = None if offset + page_limit < len ( all_entities ) : next_marker = all_entities [ offset + page_limit ] . id metadata = { 'count' : len ( entities ) , 'marker' : current_marker , 'next_marker' : next_marker , 'limit' : page_limit , 'next_href' : None } values = [ { 'alarms' : entity . list_alarms ( ) , 'checks' : entity . list_checks ( ) , 'entity' : entity . to_json ( ) , 'latest_alarm_states' : [ state . brief_json ( ) for state in maas_store . latest_alarm_states_for_entity ( entity . id ) ] } for entity in entities ] request . setResponseCode ( 200 ) return json . dumps ( { 'metadata' : metadata , 'values' : values } )