def post(self): """ Handles raw query POST, such as stenoread's "curl -d 'QUERY_STRING'" or curl -d '{ "query" : "QUERY_STRING" }' """ Config.logger.info("RAW request: {}".format(_get_request_nfo())) low = space_low() if low: from tasks import cleanup cleanup.apply_async(queue='io', kwargs={'force': True}) Config.logger.error(low) return low q = Query() q.query = '' for k, v in request.form.lists(): if k == 'query': q.query += v break elif not v or v == [u'']: q.query += k Config.logger.info("Raw query: {}".format(q.query)) return q.enqueue()
def get(self, path): """ get - build a query based on uri and enqueue it for processing - return the ID, URL needed for a future get ID/MERGED_NAME.pcap request """ Config.logger.info("URI request: {}".format(_get_request_nfo())) low = space_low() if low: from tasks import cleanup cleanup.apply_async(queue='io', kwargs={'force': True}) Config.logger.error(low) return low, 413 try: fields = parse_uri(path) q = Query(fields=fields) except BadRequest as e: return str(e), 400 except ValueError as e: return str(e), 400 result = q.enqueue() r = Response(response=dumps(result, default=json_serial), status=302, mimetype='application/json') statusUrl = '{}/#/status/{}'.format(Config.get('UI_WEB_ROOT', ''), result['id']) r.headers['Location'] = '{}'.format(statusUrl) return r
def get(self, query): Config.logger.info("RAW request: {}".format(_get_request_nfo())) low = space_low() if low: from tasks import cleanup cleanup.apply_async(queue='io', kwargs={'force': True}) Config.logger.error(low) return low from urllib import unquote_plus q = Query(unquote_plus(query)) Config.logger.info("Raw query: {}".format(q.query)) return q.enqueue()
def post(self): """ post - build a query based on submitted form or json - enqueue it for processing - return the ID, URL needed for a future get ID/MERGED_NAME.pcap request """ Config.logger.info("query request: {}".format(_get_request_nfo())) low = space_low() if low: from tasks import cleanup cleanup.apply_async(queue='io', kwargs={'force': True}) Config.logger.error(low) return low, 413 try: fields = parse_json() q = Query(fields=fields) except BadRequest as e: return str(e), 400 except ValueError as e: return str(e), 400 return q.enqueue()
def get(self, api=None, selected=None): """ inspect parameters and call the right Query method """ Config.logger.info("API request: {}".format(_get_request_nfo())) if type(selected) is str: selected = self.__class__.delims.split(selected) if api == "ids" or api == "urls": ids = Query.get_unexpired(selected) if api == "ids": return ids urls = {} for i in ids: if os.path.exists(Query.pcap_path_for_id(i)): urls[i] = Query.pcap_url_for_id(i) return urls elif api == "stats": from tasks import get_stats stats = get_stats(selected_sensors=selected) freespace = spool_space() stats['docket'] = {'Free space': freespace} return stats elif api == "status": r = Response(response=dumps(Query.status_for_ids( Query.get_unexpired(selected)), default=json_serial), mimetype="application/json") return r elif api == "clean" or api == 'cleanup': from tasks import cleanup cleanup.apply_async(queue='io', kwargs={'force': True}) return "Cleanup queued" elif api == "jobs": return Query.find({}) return "Unrecognized request: try /stats, /ids, /urls, /jobs or POST a json encoded stenographer query"