def wrap_rest_response(ok: int = 200, error: int = 500, logger=get_logger(__name__)): def decorator(func): @wraps(func) def wrapper(*args, **kwargs): http_status = ok result = {} try: result = func(*args, **kwargs) except AppException as ae: logger.exception(ae) result, http_status = ae.generate_response() except Exception as ex: result = {} logger.exception(ex) http_status = 500 return jsonify(result=get_valid_rest_object(result)), http_status # return jsonify(result=result), http_status return wrapper return decorator
def __init__(self): """ Parameters ---------- """ self.config_parser = ConfigParserUtil.get_config_parser( "config/env.cfg") self.mysql_database = None self.mysql_host = None self.mysql_user = None self.mysql_password = None self.mysql_args = None self.database_instance = None self.logger = get_logger(name="lhb_dfcf_data_analysis") self.parse_config() self.setup_mysql()
def __init__(self, db_args): self.db_args = db_args self.connection = None self.cursor = None log_name = "{0}_db.log".format(db_args.get('database', 'no')) self.logger = get_logger(log_name)
import threading import sys from platform import python_version from flask import Flask, jsonify, request from flask_cors import CORS, cross_origin from config.configuration import CurrentConfig from services import bot_service from utils import system_util from utils.carga_dinamica_blue_prints import registrar_blue_prints from utils.logger_util import get_logger app_name = 'ExcuseMeBot' system_util.set_logger(get_logger("system_util")) app = Flask(app_name) app.config.from_object('config.configuration.CurrentConfig') CORS(app) logger = get_logger(app_name) registrar_blue_prints(app, "api/v1") @app.route("/alive") def alive(): return jsonify(success=True, msg="Host: " + str(system_util.SystemMonitor.ip()) + ":" + str(CurrentConfig.API_PORT))
def __init__(self): super().__init__() self.parse_config() logging.basicConfig(format='%(asctime)s %(message)s') self.logger = get_logger('lhb_summary_dfcf_processor.log')
from utils.logger_util import get_logger, set_logger_level from utils.uuid_util import get_uuid SIGNAL_RECEIVED = 0 DIC_PROTOCOL_NUM = {'tcp': 6, 'udp': 17} DIC_DIRECTION_NUM = {'ingress': 0, 'egress': 1} # ip1/mask:port1:ip2/mask:port2:protocol:direction:bytes # e.g. 11.11.11.11/32:1001:11.11.11.22/32:1002:tcp:ingress:1024 FLOW_DATA_PATTERN = r'^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\/\d{1,2}:\d{1,5}:){2}\w+:(ingress|egress):\d{1,4}$' DEFAULT_FLOW_DATA = '11.11.11.11/32:1001:11.11.11.22/32:80:tcp:ingress:1024' DEFAULT_APP_HOST = '0.0.0.0' DEFAULT_APP_PORT = 15000 app = Flask(__name__) logger = get_logger('pygennf') threads_dict = collections.OrderedDict() @app.route('/pygennf/help') def help(): return jsonify({ 'Create sending task': '/pygennf/tasks/create', 'Check tasks status': '/pygennf/tasks/status', 'List tasks details': '/pygennf/tasks/detail', 'Stop the running tasks': '/pygennf/tasks/stop', 'Clear tasks': '/pygennf/tasks/clear', 'Print help info': '/pygennf/help' })
from flask import (Blueprint, jsonify, request) from utils.logger_util import get_logger from flask_cors import CORS, cross_origin from config.configuration import CurrentConfig from utils.rest_util import wrap_rest_response from model.mensaje import Mensaje from services import bot_service logger = get_logger(__name__) blue_print = Blueprint('bot', __name__, url_prefix=CurrentConfig.API_BASE_PATH + '/v1/bot') @cross_origin @blue_print.route("/mensajes", methods=['POST']) @wrap_rest_response(ok=200, logger=logger) def agregar_factor(): """Agrega un mensaje de factores""" body = request.get_json(force=True) lista_a_agregar = body["lista"] message = Mensaje(body) bot_service.agregar_mensaje(lista_a_agregar, message) @blue_print.route(f'/{CurrentConfig.TELEGRAM_TOKEN}', methods=['POST']) @wrap_rest_response(ok=200, logger=logger)
def __init__(self): super().__init__() self.parse_config() self.logger = get_logger('lhb_dfcf_processor.log')
'''Este modulo está destinado a contener las principales funciones de manejo de redis''' import json from datetime import datetime from typing import List, Dict import redis from utils.logger_util import get_logger from utils.redis.redis_singleton import redis_local_pool from utils.json_util import to_json, from_json import time redis_client = redis.StrictRedis(connection_pool=redis_local_pool) logger = get_logger('redis_manager') class RedisIsLockedException(Exception): def __init__(self): self.message = ('Redis bloqueado') def __str__(self): return self.message def _is_locked(): b = redis_client.get('asiscall_busy') return b == b'true' def _put_lock(): redis_client.set('asiscall_busy', 'true')