From 1ad7d8a1d39c2a037600f95b77ba573d595dda22 Mon Sep 17 00:00:00 2001 From: acidvegas Date: Mon, 11 Mar 2024 23:30:48 -0400 Subject: [PATCH] Fixed logger again --- .gitignore | 1 + eris.py | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 9 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..333c1e9 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +logs/ diff --git a/eris.py b/eris.py index 5ef4e0c..70f8e59 100644 --- a/eris.py +++ b/eris.py @@ -35,7 +35,7 @@ class ElasticIndexer: # Sniffing disabled due to an issue with the elasticsearch 8.x client (https://github.com/elastic/elasticsearch-py/issues/2005) es_config = { #'hosts' : [f'{args.host}:{args.port}'], - 'hosts' : [f'{args.host}:{port}' for port in ('9200', '9201', '9202')], # Temporary alternative to sniffing + 'hosts' : [f'{args.host}:{port}' for port in ('9002', '9003', '9004')], # Temporary alternative to sniffing 'verify_certs' : args.self_signed, 'ssl_show_warn' : args.self_signed, 'request_timeout' : args.timeout, @@ -93,6 +93,8 @@ class ElasticIndexer: async def get_cluster_health(self) -> dict: '''Get the health of the Elasticsearch cluster.''' + + return await self.es.cluster.health() @@ -139,20 +141,21 @@ class ElasticIndexer: raise Exception(f'Failed to index records to {self.es_index} from {file_path} ({e})') -def setup_logger(name: str, level: int = logging.INFO, to_file: bool = False, max_bytes: int = 250000, backups: int = 7) -> logging.Logger: +def setup_logger(level: int = logging.INFO, to_file: bool = False, max_bytes: int = 250000, backups: int = 7) -> logging.Logger: ''' Setup a custom logger with options for console and file logging. - :param name: Name of the logger. :param level: Logging level. :param to_file: Whether to log to a file. :param max_bytes: Maximum size in bytes before rotating log file. :param backups: Number of backup files to keep. ''' - logger = logging.getLogger(name) + logger = logging.getLogger() logger.setLevel(level) + logger.handlers.clear() + formatter_console = logging.Formatter('%(asctime)s | %(levelname)9s | %(message)s', '%I:%M:%S') formatter_file = logging.Formatter('%(asctime)s | %(levelname)9s | %(filename)s.%(funcName)s | %(message)s', '%Y-%m-%d %I:%M:%S') @@ -166,8 +169,6 @@ def setup_logger(name: str, level: int = logging.INFO, to_file: bool = False, ma fh.setFormatter(formatter_file) logger.addHandler(fh) - return logger - async def main(): '''Main function when running this script directly.''' @@ -233,7 +234,7 @@ async def main(): else: raise ValueError('No ingestor specified') - health = await edx.get_cluster_health() + health = await edx.es.cluster.health() logging.info(health) await asyncio.sleep(5) # Delay to allow time for sniffing to complete @@ -267,10 +268,10 @@ async def main(): if __name__ == '__main__': - setup_logger('eris', level=logging.INFO, to_file=True) + setup_logger(to_file=True) print('') print('┏┓┳┓┳┏┓ Elasticsearch Recon Ingestion Scripts') print('┣ ┣┫┃┗┓ Developed by Acidvegas in Python') print('┗┛┛┗┻┗┛ https://git.acid.vegas/eris') print('') - asyncio.run(main()) + asyncio.run(main()) \ No newline at end of file