templates-zabbix-itguys/simple_fix_yaml.py

49 lines
1.5 KiB
Python

import sys
TARGET_FILE = r"C:\Users\joao.goncalves\Desktop\zabbix-itguys\templates_gold\windows_active_agent\template_windows_gold_ptbr.yaml"
def simple_fix():
print(f"Reading {TARGET_FILE}...")
try:
with open(TARGET_FILE, 'r', encoding='utf-8') as f:
lines = f.readlines()
except Exception as e:
print(f"Error reading: {e}")
return
fixed_count = 0
new_lines = []
for line in lines:
stripped = line.strip()
# Check if it's a description line and ends with escaped quote
if stripped.startswith('description: "') and stripped.endswith('\\"'):
print(f"Fixing line: {stripped[-20:]}")
# Remove the backslash before the last quote
# The line ends with \"\n (or just \" if last line)
# We want to replace \"\n with "\n
# rstrip newline first
content = line.rstrip('\n')
if content.endswith('\\"'):
content = content[:-2] + '"'
fixed_count += 1
new_lines.append(content + '\n')
else:
new_lines.append(line)
else:
new_lines.append(line)
if fixed_count > 0:
try:
with open(TARGET_FILE, 'w', encoding='utf-8') as f:
f.writelines(new_lines)
print(f"Saved fixed file. Fixed {fixed_count} lines.")
except Exception as e:
print(f"Error writing: {e}")
else:
print("No lines needed fixing.")
if __name__ == "__main__":
simple_fix()