diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d7a26d8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + + diff --git a/README b/README new file mode 100644 index 0000000..ae173c2 --- /dev/null +++ b/README @@ -0,0 +1,2 @@ +# Python Nginx Log Analyzer + diff --git a/main.py b/main.py index 30d74d2..af07038 100644 --- a/main.py +++ b/main.py @@ -1 +1,48 @@ -test \ No newline at end of file +################################################################################################################# +## +## Python Log Analyser for Nginx ProxyManager +## Including import to Database File & Filter Option for duplicating Entrys +## +## by H4nSolo (Christian Bergs) +## Version: 0.3a +## +## Git: http://github.com/H4nSolo/Python_Log_Analyser_for_Nginx_Proxy_Manager +## +################################################################################################################# + +## Import Libaries & Local Modules +import logging +from modules.class_import_dotenv import ImportDotenv + +## Run Script +if __name__ == "__main__": + + # Import .ENV Informations from Module + dotenv_importer = ImportDotenv() + variables = dotenv_importer.get_dotenv_vars() + + # Run Main Script + try: + # Set Debug for Level 1 (Logging Mode) + if variables["LOG_MODE"] == "1": + logging.basicConfig(filename=variables['LOG_FILE'], level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') + + # Create Database (SQLite DB) + + # Check SSH Connection + + # Download Log Files + + # Analyse Log Files (incl. Archive Log Files) & Insert into Database + # Use Regex & Filter for Duplicated Entries + + + + except Exception as e: + if variables["LOG_MODE"] == "1": + logging.error(f"Fehler beim Ausführen des Skripts: {str(e)}") + elif variables["LOG_MODE"] == "2": + print(f"Fehler beim Ausführen des Skripts: {str(e)}") + + + diff --git a/modules/__pycache__/class_import_dotenv.cpython-312.pyc b/modules/__pycache__/class_import_dotenv.cpython-312.pyc new file mode 100644 index 0000000..2d96bae Binary files /dev/null and b/modules/__pycache__/class_import_dotenv.cpython-312.pyc differ diff --git a/modules/class_database.py b/modules/class_database.py new file mode 100644 index 0000000..08923b7 --- /dev/null +++ b/modules/class_database.py @@ -0,0 +1,12 @@ +import sqlite3 + +class LogDatabase(): + + def __init__(self,database_host,database_username, database_password, database_name): + + self.database_host = database_host + self.database_username = database_username + self.database_password = database_password + self.database_name = database_name + + \ No newline at end of file diff --git a/modules/class_download_logs.py b/modules/class_download_logs.py new file mode 100644 index 0000000..e69de29 diff --git a/modules/class_import_dotenv.py b/modules/class_import_dotenv.py new file mode 100644 index 0000000..8bf0812 --- /dev/null +++ b/modules/class_import_dotenv.py @@ -0,0 +1,28 @@ +from dotenv import load_dotenv +import os + +class ImportDotenv: + + def __init__(self): + # Load Environment Variables from .env File + load_dotenv() + + # Load Global Variable from .env File + self.dotenv_vars = { + # SSH Connection Variables + "REMOTE_HOST": os.getenv('REMOTE_HOST'), + "REMOTE_PORT": int(os.getenv('REMOTE_PORT')), + "REMOTE_USERNAME": os.getenv('REMOTE_USERNAME'), + "REMOTE_PASSWORD": os.getenv('REMOTE_PASSWORD'), + "REMOTE_LOG_DIR": os.getenv('REMOTE_LOG_DIR'), + "LOCAL_LOG_DIR": os.getenv('LOCAL_LOG_DIR'), + + # Local Environments Variables + "DATABASE_FILE": os.getenv('DATABASE_FILE'), + "LOG_MODE": os.getenv('LOG_MODE'), + "LOG_FILE": os.getenv('LOG_FILE') + } + + def get_dotenv_vars(self): + return self.dotenv_vars + \ No newline at end of file