misp-topcontrib/run_daily.py

40 lines
1.2 KiB
Python
Raw Normal View History

2024-11-06 14:53:19 -03:00
from defs import MISPProcessorTop
import calendar
from datetime import datetime, timedelta
max_ioc = 5000
# Obtener la fecha y hora actuales
hoy = datetime.now()
# Verificar si hoy es el primer día del mes
if hoy.day == 1:
# Si es el primer día del mes, calcular el último día del mes anterior
mes_anterior = hoy.month - 1 if hoy.month > 1 else 12
año_anterior = hoy.year if hoy.month > 1 else hoy.year - 1
ultimo_dia_mes_anterior = calendar.monthrange(año_anterior, mes_anterior)[1]
fecha_anterior = datetime(año_anterior, mes_anterior, ultimo_dia_mes_anterior)
else:
# Si no es el primer día del mes, restar un día a la fecha actual
fecha_anterior = hoy - timedelta(days=1)
fecha_anterior = fecha_anterior.strftime('%Y-%m-%d')
obj = MISPProcessorTop()
# Se llama a calcular fecha
#iocs = obj.calcula_calidad_iocs(desde_fecha, hasta_fecha, 1000)
iocs = obj.calcula_calidad_iocs(fecha_anterior, fecha_anterior, max_ioc)
if iocs:
# Solo para efectos de backup fisico por dia...
#obj.guarda_ioc_json(iocs, fecha_anterior.strftime('%Y%m%d')"_"+".json")
# Se imprime estructura
print(iocs)
# Guarda en BD (SQLite)
obj.guardar_bd(iocs,fecha_anterior)