From 510567eaeca5403db3faef9839739140c8f27d14 Mon Sep 17 00:00:00 2001 From: cppla <i@cpp.la> Date: Wed, 3 Apr 2024 21:31:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=A9=B4=E5=A4=B4=E4=B8=8D?= =?UTF-8?q?=E5=AF=B9=E9=A9=AC=E5=98=B4=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/main.cpp | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/server/src/main.cpp b/server/src/main.cpp index 6b318da..9109606 100644 --- a/server/src/main.cpp +++ b/server/src/main.cpp @@ -119,6 +119,7 @@ void CMain::OnDelClient(int ClientNetID) } m_OfflineAlarmThreadData.pClients = m_aClients; m_OfflineAlarmThreadData.pWatchDogs = m_aCWatchDogs; + m_OfflineAlarmThreadData.m_ReloadRequired = ClientID; thread_create(offlineAlarmThread, &m_OfflineAlarmThreadData); } @@ -504,8 +505,9 @@ void CMain::offlineAlarmThread(void *pUser) CJSONUpdateThreadData *m_OfflineAlarmThreadData = (CJSONUpdateThreadData *)pUser; CClient *pClients = m_OfflineAlarmThreadData->pClients; CWatchDog *pWatchDogs = m_OfflineAlarmThreadData->pWatchDogs; + volatile short ClientID = m_OfflineAlarmThreadData->m_ReloadRequired; thread_sleep(6000); - if(!pClients->m_Connected) + if(!pClients[ClientID].m_Connected) { int ID = 0; while (strcmp(pWatchDogs[ID].m_aName, "NULL")) @@ -514,13 +516,13 @@ void CMain::offlineAlarmThread(void *pUser) typedef exprtk::expression<double> expression_t; typedef exprtk::parser<double> parser_t; const std::string expression_string = pWatchDogs[ID].m_aRule; - std::string username = pClients->m_aUsername; - std::string name = pClients->m_aName; - std::string type = pClients->m_aType; - std::string host = pClients->m_aHost; - std::string location = pClients->m_aLocation; - std::double_t online4 = pClients->m_Stats.m_Online4; - std::double_t online6 = pClients->m_Stats.m_Online6; + std::string username = pClients[ClientID].m_aUsername; + std::string name = pClients[ClientID].m_aName; + std::string type = pClients[ClientID].m_aType; + std::string host = pClients[ClientID].m_aHost; + std::string location = pClients[ClientID].m_aLocation; + std::double_t online4 = pClients[ClientID].m_Stats.m_Online4; + std::double_t online6 = pClients[ClientID].m_Stats.m_Online6; symbol_table_t symbol_table; symbol_table.add_stringvar("username", username); @@ -541,10 +543,10 @@ void CMain::offlineAlarmThread(void *pUser) if (expression.value() > 0) { time_t currentStamp = (long long)time(/*ago*/0); - if ((currentStamp-pClients->m_AlarmLastTime) > pWatchDogs[ID].m_aInterval) + if ((currentStamp-pClients[ClientID].m_AlarmLastTime) > pWatchDogs[ID].m_aInterval) { printf("客户端下线且超过阈值, Client disconnects and sends alert information\n"); - pClients->m_AlarmLastTime = currentStamp; + pClients[ClientID].m_AlarmLastTime = currentStamp; CURL *curl; CURLcode res; curl_global_init(CURL_GLOBAL_ALL); @@ -560,11 +562,11 @@ void CMain::offlineAlarmThread(void *pUser) sprintf(encodeBuffer, "【告警名称】 %s \n\n【告警时间】 %s \n\n【用户名】 %s \n\n【节点名】 %s \n\n【虚拟化】 %s \n\n【主机名】 %s \n\n【位 置】 %s", pWatchDogs[ID].m_aName, standardTime, - pClients->m_aUsername, - pClients->m_aName, - pClients->m_aType, - pClients->m_aHost, - pClients->m_aLocation); + pClients[ClientID].m_aUsername, + pClients[ClientID].m_aName, + pClients[ClientID].m_aType, + pClients[ClientID].m_aHost, + pClients[ClientID].m_aLocation); char *encodeUrl = curl_easy_escape(curl, encodeBuffer, strlen(encodeBuffer)); //standard url