aops-zeus/0008-bugfix-email-config-does-not-take-effect.patch
2023-11-14 16:22:39 +08:00

76 lines
3.0 KiB
Diff

From 2ccba1565c7d2ad5e4bb821f05f09a3b63edbd8b Mon Sep 17 00:00:00 2001
From: rabbitali <wenxin32@foxmail.com>
Date: Tue, 31 Oct 2023 18:03:40 +0800
Subject: [PATCH] bugfix: email config does not take effect
---
zeus/vulnerability_manage/view.py | 31 ++++++++++++++++++-------------
1 file changed, 18 insertions(+), 13 deletions(-)
diff --git a/zeus/vulnerability_manage/view.py b/zeus/vulnerability_manage/view.py
index c56f672..34a33c9 100644
--- a/zeus/vulnerability_manage/view.py
+++ b/zeus/vulnerability_manage/view.py
@@ -15,7 +15,7 @@ import time
import threading
from typing import Dict, Tuple
-from flask import Response
+from flask import Response, request
import sqlalchemy
import gevent
@@ -301,14 +301,13 @@ class ExecuteCveScanTask(BaseResponse, BaseExcuteTask):
you can turn it off by modifying email config configuration in aops-private-config.ini, but it will still be
triggered during scheduled cve scan.
"""
- if configuration.email.get("ENABLED") or self._header.get("exempt_authentication"):
- self.get_response(
- "post",
- f'http://{configuration.apollo.get("IP")}:{ configuration.apollo.get("PORT")}{VUL_TASK_CVE_SCAN_NOTICE}',
- {},
- self._header,
- timeout=10,
- )
+ self.get_response(
+ "post",
+ f'http://{configuration.apollo.get("IP")}:{ configuration.apollo.get("PORT")}{VUL_TASK_CVE_SCAN_NOTICE}',
+ {},
+ self._header,
+ timeout=10,
+ )
@BaseResponse.handle(schema=CveScanSchema)
def post(self, **params) -> Response:
@@ -330,6 +329,13 @@ class ExecuteCveScanTask(BaseResponse, BaseExcuteTask):
Returns:
response body
"""
+
+ def execute_task(host_infos, need_to_send_email):
+ gevent.joinall([gevent.spawn(self._execute_task, host) for host in host_infos])
+ if need_to_send_email:
+ LOGGER.info("Plan to request the interface for sending emails")
+ self._execute_send_email()
+
# Query host basic info from database
status_code, host_infos = query_host_basic_info(params.get('total_hosts'), params.get('username'))
if status_code != state.SUCCEED:
@@ -340,10 +346,9 @@ class ExecuteCveScanTask(BaseResponse, BaseExcuteTask):
self._task_id = params.get("task_id")
self._check_items = params.get('check_items')
# Execute task
- threading.Thread(
- target=lambda: gevent.joinall([gevent.spawn(self._execute_task, host) for host in host_infos.values()])
- ).start()
- threading.Thread(target=self._execute_send_email).start()
+ need_to_send_email = request.headers.get("exempt_authentication") or configuration.email.get("ENABLED")
+ threading.Thread(target=execute_task, args=(host_infos.values(), need_to_send_email)).start()
+
return self.response(code=state.SUCCEED)
--
Gitee