Untitled
unknown
plain_text
2 years ago
1.9 kB
5
Indexable
# Define the log file path log_file = '/home/CAPEUSER/Python/logs/dataflow_syslog_transfer_script.csv' # Configure the logging format as ERROR which includes both ERROR as well as INFO logging.basicConfig(filename=log_file, format='%(asctime)s - %(levelname)s - %(message)s', level=logging.ERROR) # Declaring Files agent_file='/APP_PROD/Dev_App/jar/properties/agent.properties' bookmark_file='/App/jar/KPI/bookmark_log.properties' important_words_file='/home/CAPEUSER/Python/CAPE_SYSLOG_INTEGRATION/Code/important_words.txt' output_folder='/var/log/syslog/' #Program Execution import time start_time = time.time() # Example INFO log message logging.info("This is an INFO level log message") # Example ERROR log message logging.error("This is an ERROR level log message") ##Caching the VMList so that even if subsequent calls, it returns the cached VM list without needing to read the file again. vm_list_cache = None def get_VMList(): global vm_list_cache if vm_list_cache is None: try: with open(agent_file,'rt',encoding='latin-1') as file: for line in file: if 'VMList' in line: vm_list = str(line.split('=')) vm_list = re.findall(r'\d+', vm_list) vm_list_cache = list(map(int, vm_list)) break except FileNotFoundError: print(f"{agent_file} not found") logging.error("Agent file not found %s", agent_file) except Exception as e: print(f"An error occurred while reading the file: {str(e)}") logging.error("Error occured while reading the file %s", e) vm_list_cache = [] return vm_list_cache print("The VM List is : ",get_VMList()) logging.info("The VM List is: %s", get_VMList())
Editor is loading...