import os
import sys 
#HACK
sys.path.append('/home/koraty/Documenti/master_thesis/vagrant/src')
import logging
from variables_test import DEBUG_LEVEL, PATH_TO_OSSEC_AGENT_BASE_DEFENDER, PATH_TO_OSSEC_AGENT_TEST
from wazuh_library.utils_wazuh import *
from utils import run_function_on_remote_host
# Use getattr() to dynamically access the logging level
log_level = getattr(logging, DEBUG_LEVEL, logging.INFO)  # Default to logging.INFO if not found

# Set up logging
logging.basicConfig(
    format='%(asctime)s - %(levelname)s - %(message)s',
    level=log_level,
    handlers=[logging.StreamHandler()]  # Logs to console by default
)

# Define constants
TEST_DIR_AGENT_WHO_DATA = "/etc"
TEST_FILE_AGENT_WHO_DATA = f"{TEST_DIR_AGENT_WHO_DATA}/test_file.txt"
TEST_DIR = "/var/log/fim-test"
TEST_FILE = f"{TEST_DIR}/test_file.txt"

if __name__ == "__main__":
    # Ensure the correct directory
    os.chdir('vagrant/src')

    # Define monitored paths
    monitored_path_who_data = TEST_DIR_AGENT_WHO_DATA
    monitored_path = TEST_DIR

    # Define directory tags
    directory_tag_whodata = {'text': monitored_path_who_data, 'check_all': 'yes', 'whodata': 'yes'}
    directory_tag = {'text': monitored_path, 'check_all': 'yes', 'whodata': 'yes'}

    # print("Starting FIM setup...")

    # # Add FIM configuration
    add_fim_configuration(PATH_TO_OSSEC_AGENT_TEST, [directory_tag,directory_tag_whodata],do_synchronize_with_VM=True,remote_host='wazagent1',VM_conf_path=PATH_TO_OSSEC_AGENT_BASE_DEFENDER)

    #Test FIM
    # print("Testing FIM...")
    # run_function_on_remote_host('wazagent1','simulate_file_change',monitored_path)
    # run_function_on_remote_host('wazidx1','check_fim_change',monitored_path)

    # # Test Who-Data
    # print("Testing audit...")
    # run_function_on_remote_host('wazagent1','test_who_data')
    # run_function_on_remote_host('wazidx1','check_fim_change',monitored_path_who_data)

    # print("FIM and Who-Data setup completed successfully.")
