mirror of
https://github.com//cppla/ServerStatus
synced 2025-07-05 00:45:59 +08:00
read config.
This commit is contained in:
parent
0a2a007e24
commit
a9128b137d
server
@ -1,5 +1,5 @@
|
|||||||
{"servers":
|
{
|
||||||
[
|
"servers": [
|
||||||
{
|
{
|
||||||
"username": "s01",
|
"username": "s01",
|
||||||
"name": "node1",
|
"name": "node1",
|
||||||
@ -37,5 +37,27 @@
|
|||||||
"password": "USER_DEFAULT_PASSWORD",
|
"password": "USER_DEFAULT_PASSWORD",
|
||||||
"monthstart": 1
|
"monthstart": 1
|
||||||
}
|
}
|
||||||
|
],
|
||||||
|
"watchdog": [
|
||||||
|
{
|
||||||
|
"name": "cpu high warning",
|
||||||
|
"rule": "cpu>90",
|
||||||
|
"callback": "https://yourSMSurl"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "memory high warning",
|
||||||
|
"rule": "(memory_used/memory_total)*100>90",
|
||||||
|
"callback": "https://yourSMSurl"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "ipv4 offline warning",
|
||||||
|
"rule": "online4=false",
|
||||||
|
"callback": "https://yourSMSurl"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "you can parse an expression combining any known field",
|
||||||
|
"rule": "(hdd_used/hdd_total)*100>95",
|
||||||
|
"callback": "https://yourSMSurl"
|
||||||
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -411,6 +411,25 @@ int CMain::ReadConfig()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// watch dog
|
||||||
|
// support by: https://cpp.la
|
||||||
|
ID = 0;
|
||||||
|
const json_value &jStart = (*pJsonData)["watchdog"];
|
||||||
|
if(jStart.type == json_array)
|
||||||
|
{
|
||||||
|
for(unsigned i = 0; i < jStart.u.array.length; i++)
|
||||||
|
{
|
||||||
|
if(ID < 0 || ID >= NET_MAX_CLIENTS)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
str_copy(Watchdog(ID)->m_aName, jStart[i]["name"].u.string.ptr, sizeof(Watchdog(ID)->m_aName));
|
||||||
|
str_copy(Watchdog(ID)->m_aRule, jStart[i]["rule"].u.string.ptr, sizeof(Watchdog(ID)->m_aRule));
|
||||||
|
str_copy(Watchdog(ID)->m_aCallback, jStart[i]["callback"].u.string.ptr, sizeof(Watchdog(ID)->m_aCallback));
|
||||||
|
|
||||||
|
ID++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// if file exists, read last network traffic record,reset m_LastNetworkIN and m_LastNetworkOUT
|
// if file exists, read last network traffic record,reset m_LastNetworkIN and m_LastNetworkOUT
|
||||||
// support by: https://cpp.la
|
// support by: https://cpp.la
|
||||||
IOHANDLE nFile = io_open(m_Config.m_aJSONFile, IOFLAG_READ);
|
IOHANDLE nFile = io_open(m_Config.m_aJSONFile, IOFLAG_READ);
|
||||||
|
@ -82,6 +82,12 @@ class CMain
|
|||||||
} m_Stats;
|
} m_Stats;
|
||||||
} m_aClients[NET_MAX_CLIENTS];
|
} m_aClients[NET_MAX_CLIENTS];
|
||||||
|
|
||||||
|
struct CWatchDog{
|
||||||
|
char m_aName[128];
|
||||||
|
char m_aRule[128];
|
||||||
|
char m_aCallback[128];
|
||||||
|
} m_aCWatchDogs[NET_MAX_CLIENTS];
|
||||||
|
|
||||||
struct CJSONUpdateThreadData
|
struct CJSONUpdateThreadData
|
||||||
{
|
{
|
||||||
CClient *pClients;
|
CClient *pClients;
|
||||||
@ -99,6 +105,8 @@ public:
|
|||||||
int ReadConfig();
|
int ReadConfig();
|
||||||
int Run();
|
int Run();
|
||||||
|
|
||||||
|
CWatchDog *Watchdog(int ruleID) { return &m_aCWatchDogs[ruleID]; }
|
||||||
|
|
||||||
CClient *Client(int ClientID) { return &m_aClients[ClientID]; }
|
CClient *Client(int ClientID) { return &m_aClients[ClientID]; }
|
||||||
CClient *ClientNet(int ClientNetID);
|
CClient *ClientNet(int ClientNetID);
|
||||||
const CConfig *Config() const { return &m_Config; }
|
const CConfig *Config() const { return &m_Config; }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user