import json from jagereye.util import logging from jagereye.util import static_util with open(static_util.get_path('messaging.json'), 'r') as f: MESSAGES = json.loads(f.read()) class InvalidRequestType(Exception): pass class InvalidRequestFormat(Exception): pass class API(): def __init__(self, typename): self._typename = typename self._msg = MESSAGES['ch_api_brain'] self._msg_r = MESSAGES['ch_api_brain_reply'] def validate(self, request): # TODO: Add error messages to describe the invalid format try: if request['command'] == self._msg['START_ANALYZER']: if self._typename != request['params']['type']: raise InvalidRequestType if not request['params']['source'] or \ not request['params']['pipelines']: raise InvalidRequestFormat
import aioredis import json, os, time from jsonschema import Draft4Validator as Validator from bson.objectid import ObjectId from jagereye.util import logging from jagereye.util import static_util from jagereye.util.generic import get_func_name from jagereye.brain.status_enum import WorkerStatus from jagereye.brain.utils import jsonify # create worker schema validator with open(static_util.get_path('worker.json'), 'r') as f: validator = Validator(json.loads(f.read())) class WorkerAgent(object): def __init__(self, typename, mem_db, db): self._typename = typename self._mem_db = mem_db self._db = db def _get_anal_key(self, anal_id): return '{}:anal:{}'.format(self._typename, anal_id) def _get_worker_key(self, worker_id, field): # TODO(Ray): field only allow 'status', 'pipelines', 'hbeat', 'analyzerId' return '{}:worker:{}:{}'.format(self._typename, worker_id, field) async def get_all_anal_and_worker_ids(self): search_key = self._get_anal_key('*')
def get_config(config_file='./config.yml'): with open(static_util.get_path(config_file), 'r') as f: return yaml.load(f)
import aioredis import json import os, datetime from pymongo.errors import OperationFailure as MongoOperationFailure from jsonschema import Draft4Validator as Validator from jagereye.brain.utils import jsonify from jagereye.util import logging from jagereye.util import static_util # create event schema validator with open(static_util.get_path('event.json'), 'r') as f: validator = Validator(json.loads(f.read())) class EventAgent(object): def __init__(self, typename, mem_db, event_db, app_event_db): self._typename = typename self._mem_db = mem_db self._event_db = event_db self._app_event_db = app_event_db def save_in_db(self, events, analyzer_id): """Save events into presistent db Args: events:(list of dict): the list of event analyzer_id:(string): the analyzer ID of the events Raises: