Loading notifications.mk to python then to json

Continuing the discussion from How to load rules.mk in python scripts?:

CMK version: 1.4.0p31.cre
OS version:

Error message:

Output of “cmk --debug -vvn hostname”: (If it is a problem with checks or plugins)

Finally I could load the notification rules frem mk file to json (you have to clean the file deleting the string "notification_rules += " from the begining.

Then, using this python you can get a pretty json file

import ast
import pprint
import json



# Ruta al archivo de texto que contiene la sección de configuración
archivo_configuracion = './notifications.mk'

# Lee el contenido del archivo
with open(archivo_configuracion, 'r') as archivo:
    config_section = archivo.read()

# Convierte el contenido del archivo a una estructura de datos en Python
config_data = ast.literal_eval(config_section)

# Ahora config_data contiene tu sección de configuración como una lista de diccionarios en Python
# Puedes acceder a elementos individuales como antes
#print(config_data[0]['description'])  # Imprime la descripción del primer elemento en la lista
#print(config_data[1]['description'])  # Imprime la descripción del primer elemento en la lista
#print(config_data[2]['description'])  # Imprime la descripción del primer elemento en la lista

#pprint.pprint(config_data)

config_json = json.dumps(config_data, indent=4)
print(config_json)

Geting this:

Maybe you can use this method for parsing other files and getting a json if you dont have an API available to export the rules