MCPcopy Create free account
hub / github.com/cppla/ServerStatus / offlineAlarmThread

Method offlineAlarmThread

server/src/main.cpp:703–804  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

701}
702
703void CMain::offlineAlarmThread(void *pUser)
704{
705 CJSONUpdateThreadData *m_OfflineAlarmThreadData = (CJSONUpdateThreadData *)pUser;
706 CClient *pClients = m_OfflineAlarmThreadData->pClients;
707 CWatchDog *pWatchDogs = m_OfflineAlarmThreadData->pWatchDogs;
708 volatile short ClientID = m_OfflineAlarmThreadData->m_ReloadRequired;
709 thread_sleep(25000);
710 if(!pClients[ClientID].m_Connected)
711 {
712 int ID = 0;
713 while (strcmp(pWatchDogs[ID].m_aName, "NULL"))
714 {
715 typedef exprtk::symbol_table<double> symbol_table_t;
716 typedef exprtk::expression<double> expression_t;
717 typedef exprtk::parser<double> parser_t;
718 const std::string expression_string = pWatchDogs[ID].m_aRule;
719 std::string username = pClients[ClientID].m_aUsername;
720 std::string name = pClients[ClientID].m_aName;
721 std::string type = pClients[ClientID].m_aType;
722 std::string host = pClients[ClientID].m_aHost;
723 std::string location = pClients[ClientID].m_aLocation;
724 std::double_t online4 = pClients[ClientID].m_Stats.m_Online4;
725 std::double_t online6 = pClients[ClientID].m_Stats.m_Online6;
726
727 symbol_table_t symbol_table;
728 symbol_table.add_stringvar("username", username);
729 symbol_table.add_stringvar("name", name);
730 symbol_table.add_stringvar("type", type);
731 symbol_table.add_stringvar("host", host);
732 symbol_table.add_stringvar("location", location);
733 symbol_table.add_variable("online4",online4);
734 symbol_table.add_variable("online6",online6);
735 symbol_table.add_constants();
736
737 expression_t expression;
738 expression.register_symbol_table(symbol_table);
739
740 parser_t parser;
741 parser.compile(expression_string,expression);
742
743 if (expression.value() > 0)
744 {
745 time_t currentStamp = (long long)time(/*ago*/0);
746 if ((currentStamp-pClients[ClientID].m_AlarmLastTime) > pWatchDogs[ID].m_aInterval)
747 {
748 printf("客户端下线且超过阈值, Client disconnects and sends alert information\n");
749 pClients[ClientID].m_AlarmLastTime = currentStamp;
750 CURL *curl;
751 CURLcode res;
752 curl_global_init(CURL_GLOBAL_ALL);
753
754 curl = curl_easy_init();
755 if(curl) {
756 //standard time
757 char standardTime[32]= { 0 };
758 strftime(standardTime, sizeof(standardTime), "%Y-%m-%d %H:%M:%S",localtime(&currentStamp));
759
760 //url encode, Rules conflict with url special characters,eg:&, del rules, by https://cpp.la, 2023-10-09

Callers

nothing calls this directly

Calls 1

thread_sleepFunction · 0.85

Tested by

no test coverage detected