コード例 #1
0
def get_timeline(start=None, stop=None):
    #get user and access to mongo
    account = get_account()
    storage = get_storage(namespace='events_log')

    #get data in payload
    start = request.params.get('start', default=None)
    stop = request.params.get('stop', default=None)

    #set returned variable
    output = {}
    total = None

    #build filter for mongo request (put advanced option in it)
    mfilter = {'$and': [{'crecord_type': 'event'}]}

    if start:
        mfilter['and'].append({'timestamp': {'$gt': start}})
    if stop:
        mfilter['and'].append({'timestamp': {'$lt': stop}})

    #clean mfilter
    mfilter = clean_mfilter(mfilter)

    records = storage.find(mfilter, account=account)

    tmp_output = {}
    for record in records:
        dump = record.dump()
        if not tmp_output.has_key(dump['event_id']):
            tmp_output[dump['event_id']] = []
        tmp_output[dump['event_id']].append(dump)

    events = {}
    for tag in tmp_output.keys():
        prev_id = None
        for record in tmp_output[tag]:
            item = {}
            if (prev_id != None):
                events[prev_id]['end'] = datetime.fromtimestamp(
                    record['timestamp']).isoformat(
                    )  #strftime('%Y-%m-%d %H:%M:%S')
            item['title'] = str(dump['component'])
            if 'long_output' in record:
                item['description'] = record['long_output']
            item['start'] = datetime.fromtimestamp(
                record['timestamp']).isoformat(
                )  #strftime('%Y-%m-%d %H:%M:%S')
            item['durationEvent'] = True
            events[record['_id']] = item
            prev_id = record['_id']
    output['events'] = events.values()
    output['dateTimeFormat'] = 'iso8601'
    output['wiki-url'] = "http://simile.mit.edu/shelf/"
    output['wiki-section'] = "Simile JFK Timeline"
    #return the total, the success of function and the requested data in output
    return output
コード例 #2
0
ファイル: rest.py プロジェクト: Httqm/canopsis
def get_timeline(start=None,stop=None):
	#get user and access to mongo
	account = get_account()
	storage = get_storage(namespace='events_log')

	#get data in payload
	start = request.params.get('start', default=None)
	stop = request.params.get('stop', default=None)

	#set returned variable
	output = { } 
	total = None

	#build filter for mongo request (put advanced option in it)
	mfilter = {'$and':[{'crecord_type':'event'}]}

	if start :
		mfilter['and'].append({'timestamp': {'$gt': start}})
	if stop :
		mfilter['and'].append({'timestamp': {'$lt': stop}})
	
	#clean mfilter
	mfilter = clean_mfilter(mfilter)

	records = storage.find(mfilter, account=account)

	tmp_output = {}
	for record in records:
		dump = record.dump()
		if not tmp_output.has_key(dump['event_id']) :
			tmp_output[dump['event_id']] = []
		tmp_output[dump['event_id']].append(dump)

	events = {} 
	for tag in tmp_output.keys() :
		prev_id = None
		for record in tmp_output[tag] :
			item = {}
			if ( prev_id != None ) :
				events[prev_id]['end'] = datetime.fromtimestamp(record['timestamp']).isoformat()#strftime('%Y-%m-%d %H:%M:%S')
			item['title'] = str(dump['component'])
			if 'long_output' in record :
				item['description'] = record['long_output']
			item['start'] = datetime.fromtimestamp(record['timestamp']).isoformat()#strftime('%Y-%m-%d %H:%M:%S')
			item['durationEvent'] = True
			events[record['_id']] = item
			prev_id = record['_id'] 
	output['events'] = events.values()
	output['dateTimeFormat'] = 'iso8601'
	output['wiki-url'] = "http://simile.mit.edu/shelf/"
	output['wiki-section'] = "Simile JFK Timeline"
	#return the total, the success of function and the requested data in output
	return output
コード例 #3
0
ファイル: rest.py プロジェクト: Httqm/canopsis
				total = 0
		except Exception, err:
			logger.info('Error: %s' % err)
			total = 0
		
		if total == 0:
			return HTTPError(404, str(ids) +" Not Found")
						
	else:
		if search:
			mfilter['_id'] = { '$regex' : '.*'+search+'.*', '$options': 'i' }
		
		logger.debug(" + mfilter: "+str(mfilter))

		#clean mfilter
		mfilter = clean_mfilter(mfilter)

		records =  storage.find(mfilter, sort=msort, limit=limit, offset=start, account=account)
		total =	storage.count(mfilter, account=account)

	output = []
	
	#----------------dump record and post filtering-------
	for record in records:
		if record:
			do_dump = True

			if onlyWritable:
				if not record.check_write(account=account):
					do_dump = False
コード例 #4
0
ファイル: perfstore.py プロジェクト: moas/canopsis
			mfilter = {'$and': []}
			for word in search:
				mor = []
				for field in fields:
					mor.append({field: {'$regex': '.*%s.*' % word, '$options': 'i'}})	
				mfilter['$and'].append({'$or': mor})
	
	if not show_internals:
		if mfilter:
			mfilter = {'$and': [mfilter, {'me': {'$nin':internal_metrics  }}]}
		else:
			mfilter = {'me': {'$nin': internal_metrics  }}
		
	logger.debug(" + mfilter:  %s" % mfilter)
	
	mfilter = clean_mfilter(mfilter)

	data  = manager.find(limit=0, skip=0, mfilter=mfilter, data=False, sort=msort)
	total = data.count()
	data  = [meta for meta in data.skip(start).limit(limit)]
	
	return {'success': True, 'data' : data, 'total' : total}


### manipulating meta
@delete('/perfstore',checkAuthPlugin={'authorized_grp':group_managing_access})
@delete('/perfstore/:_id',checkAuthPlugin={'authorized_grp':group_managing_access})
def remove_meta(_id=None):
	if not _id:
		_id =  json.loads(request.body.readline())
	if not _id: