Skip to content

Commit

Permalink
Merge pull request #140 from lbbniu/patch-2
Browse files Browse the repository at this point in the history
fix: command field is empty
  • Loading branch information
ruanshudong authored Sep 27, 2023
2 parents f06bea6 + f590310 commit 03a9155
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion NotifyServer/NotifyImp.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/**
* Tencent is pleased to support the open source community by making Tars available.
*
* Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
Expand All @@ -21,6 +21,39 @@
extern TC_Config * g_pconf;
extern TarsHashMap<NotifyKey, NotifyInfo, ThreadLockPolicy, MemStorePolicy> * g_notifyHash;

std::string Alarm = "[alarm]";
std::string Error = "[error]";
std::string Warn = "[warn]";
std::string Fail = "[fail]";
std::string Normal = "[normal]";

static std::string getNotifyLevel(const std::string& sNotifyMessage)
{

if (sNotifyMessage.find(Alarm) != std::string::npos) return Alarm;
if (sNotifyMessage.find(Error) != std::string::npos) return Error;
if (sNotifyMessage.find(Warn) != std::string::npos) return Warn;
if (sNotifyMessage.find(Fail) != std::string::npos) return Error;

return Normal;
}

static std::string getNotifyLevel(int level)
{
switch(level)
{
case NOTIFYERROR:
return Error;
case NOTIFYWARN:
return Warn;
default:
case NOTIFYNORMAL:
return Normal;
}

return Normal;
}

void NotifyImp::loadconf()
{
TC_DBConf tcDBConf;
Expand Down Expand Up @@ -321,6 +354,11 @@ void NotifyImp::reportNotifyInfo(const tars::ReportInfo & info, tars::TarsCurren
rd["set_group"] = make_pair(TC_Mysql::DB_STR, "");
}

if (info.eType == REPORT) {
rd["command"] = make_pair(TC_Mysql::DB_STR, getNotifyLevel(info.sMessage));
} else {
rd["command"] = make_pair(TC_Mysql::DB_STR, getNotifyLevel(info.eLevel));
}
rd["result"] = make_pair(TC_Mysql::DB_STR, info.sMessage);
rd["notifytime"] = make_pair(TC_Mysql::DB_INT, "now()");
string sTable = "t_server_notifys";
Expand Down

0 comments on commit 03a9155

Please sign in to comment.