def __init__(self, hx_api_object, profile_id, intervals, objectTypes): self.logger = hxtool_logging.getLogger(__name__) self.hx_api_object = hx_api_object self.profile_id = profile_id # TEMP: drop cache hxtool_global.hxtool_db.cacheDrop(self.profile_id) for objectType in objectTypes: if objectType in intervals.keys(): try: setattr(self, objectType + "_fetcher_interval", intervals[objectType]["fetcher_interval"]) setattr(self, objectType + "_objects_per_poll", intervals[objectType]["objects_per_poll"]) setattr(self, objectType + "_refresh_interval", intervals[objectType]["refresh_interval"]) except: self.logger.error( "Missing interval settings for {}, check configuration to enable cache" .format(objectType)) exit(2) my_fetcher_task = hxtool_scheduler_task( "System", "Cache fetcher for " + objectType + " profile: " + str(self.profile_id), immutable=True) my_fetcher_task.set_schedule( seconds=intervals[objectType]["fetcher_interval"]) my_fetcher_task.add_step(self, "apicache_fetcher", kwargs={"objectType": objectType}) hxtool_global.hxtool_scheduler.add(my_fetcher_task) self.logger.info( "Apicache {} fetcher started for profile: {}.".format( objectType, self.profile_id)) stats = {} for k, v in intervals.items(): stats[k] = { "settings": v, "stats": { "records": 0, "timeline": deque([], maxlen=1000) } } hxtool_global.apicache = { "started": datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"), "types": objectTypes, "data": stats }
import threading import datetime import calendar import random from multiprocessing.pool import ThreadPool from multiprocessing import cpu_count, TimeoutError import hxtool_logging import hxtool_global from hxtool_vars import default_encoding from hx_lib import HXAPI from hxtool_util import * import hxtool_task_modules logger = hxtool_logging.getLogger(__name__) TASK_API_KEY = 'Z\\U+z$B*?AiV^Fr~agyEXL@R[vSTJ%N&'.encode(default_encoding) TASK_STATE_SCHEDULED = 0 TASK_STATE_QUEUED = 1 TASK_STATE_RUNNING = 2 TASK_STATE_COMPLETE = 3 TASK_STATE_STOPPED = 4 TASK_STATE_FAILED = 5 TASK_STATE_PENDING_DELETION = 6 task_state_description = { TASK_STATE_SCHEDULED: "Scheduled", TASK_STATE_QUEUED: "Queued", TASK_STATE_RUNNING: "Running",
from hxtool_formatting import * from hxtool_config import * from hxtool_data_models import * from hxtool_session import * from hxtool_scheduler import * from hxtool_apicache import * from hxtool_api import indicator_dict_from_indicator # Import HXTool API Flask blueprint from hxtool_api import ht_api default_encoding = hxtool_vars.default_encoding # Setup logging hxtool_logging.setLoggerClass() logger = hxtool_logging.getLogger() # Create the app app = Flask(hxtool_logging.root_logger_name, static_url_path='/static') hxtool_vars.app_instance_path = app.root_path # Register HXTool API blueprint app.register_blueprint(ht_api) ### Flask/Jinja Filters #################################### _newline_re = re.compile(r'(?:\r\n|\r|\n){1,}') @app.template_filter()
def __init__(self, parent_task): self.parent_task = parent_task self.logger = hxtool_logging.getLogger(__name__) self.enabled = True