misp-topcontrib/run_daily.py
Felipe Luis Quezada Valenzuela e1e538a3e2 #edit config
2025-01-09 10:17:54 -03:00

44 lines
No EOL
1.4 KiB
Python

from defs import MISPProcessorTop
import calendar
from config import ORG_OMITIR
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)
try:
iocs = obj.calcula_calidad_iocs(fecha_anterior, fecha_anterior, max_ioc)
print(iocs)
if iocs:
# Solo para efectos de backup fisico por dia...
#obj.guarda_ioc_json(iocs, fecha_anterior.strftime('%Y%m%d')"_"+".json")
output = []
for x in iocs:
if x['comunidad'] not in ORG_OMITIR:
output.append(x)
# Guarda en BD (SQLite)
obj.guardar_bd(output,fecha_anterior)
except Exception as e:
print(str(e))