38 lines
1.2 KiB
Python
38 lines
1.2 KiB
Python
#!/usr/bin/env python3
|
|
import os
|
|
import datetime
|
|
import sys
|
|
|
|
def check_backups(directory, filenames):
|
|
# Obtener la fecha actual en formato año-mes-día
|
|
today = datetime.datetime.now().strftime("%Y%m%d")
|
|
missing_files = []
|
|
|
|
# Comprobar todos los archivos esperados
|
|
for base_name in filenames:
|
|
expected_filename = f"{base_name}-{today}"
|
|
full_path = os.path.join(directory, expected_filename)
|
|
|
|
if not os.path.exists(full_path):
|
|
missing_files.append(expected_filename)
|
|
|
|
if missing_files:
|
|
print(f"CRITICAL: Missing backup files in {directory}: " + ", ".join(missing_files))
|
|
return 2 # Código de salida para CRITICAL
|
|
|
|
print("OK: All backup files exist.")
|
|
return 0 # Código de salida para OK
|
|
|
|
if __name__ == "__main__":
|
|
# Chequear si se proporcionaron suficientes argumentos
|
|
if len(sys.argv) < 3:
|
|
print("Usage: {} <directory> <filename1> [<filename2> ...]".format(sys.argv[0]))
|
|
sys.exit(3) # Código de salida para UNKNOWN
|
|
|
|
backup_directory = sys.argv[1]
|
|
filenames = sys.argv[2:]
|
|
|
|
# Llamar a la función de comprobación y salir con el código de estado adecuado
|
|
result = check_backups(backup_directory, filenames)
|
|
sys.exit(result)
|