Skip to content

Commit 03a9155

Browse files
authored
Merge pull request #140 from lbbniu/patch-2
fix: command field is empty
2 parents f06bea6 + f590310 commit 03a9155

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

NotifyServer/NotifyImp.cpp

+39-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/**
22
* Tencent is pleased to support the open source community by making Tars available.
33
*
44
* Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
@@ -21,6 +21,39 @@
2121
extern TC_Config * g_pconf;
2222
extern TarsHashMap<NotifyKey, NotifyInfo, ThreadLockPolicy, MemStorePolicy> * g_notifyHash;
2323

24+
std::string Alarm = "[alarm]";
25+
std::string Error = "[error]";
26+
std::string Warn = "[warn]";
27+
std::string Fail = "[fail]";
28+
std::string Normal = "[normal]";
29+
30+
static std::string getNotifyLevel(const std::string& sNotifyMessage)
31+
{
32+
33+
if (sNotifyMessage.find(Alarm) != std::string::npos) return Alarm;
34+
if (sNotifyMessage.find(Error) != std::string::npos) return Error;
35+
if (sNotifyMessage.find(Warn) != std::string::npos) return Warn;
36+
if (sNotifyMessage.find(Fail) != std::string::npos) return Error;
37+
38+
return Normal;
39+
}
40+
41+
static std::string getNotifyLevel(int level)
42+
{
43+
switch(level)
44+
{
45+
case NOTIFYERROR:
46+
return Error;
47+
case NOTIFYWARN:
48+
return Warn;
49+
default:
50+
case NOTIFYNORMAL:
51+
return Normal;
52+
}
53+
54+
return Normal;
55+
}
56+
2457
void NotifyImp::loadconf()
2558
{
2659
TC_DBConf tcDBConf;
@@ -321,6 +354,11 @@ void NotifyImp::reportNotifyInfo(const tars::ReportInfo & info, tars::TarsCurren
321354
rd["set_group"] = make_pair(TC_Mysql::DB_STR, "");
322355
}
323356

357+
if (info.eType == REPORT) {
358+
rd["command"] = make_pair(TC_Mysql::DB_STR, getNotifyLevel(info.sMessage));
359+
} else {
360+
rd["command"] = make_pair(TC_Mysql::DB_STR, getNotifyLevel(info.eLevel));
361+
}
324362
rd["result"] = make_pair(TC_Mysql::DB_STR, info.sMessage);
325363
rd["notifytime"] = make_pair(TC_Mysql::DB_INT, "now()");
326364
string sTable = "t_server_notifys";

0 commit comments

Comments
 (0)