mirror of
https://github.com/Telecominfraproject/wlan-cloud-ucentralfms.git
synced 2025-11-20 20:14:50 +00:00
Finishing FMS dash board
This commit is contained in:
@@ -57,70 +57,110 @@ namespace uCentral {
|
||||
if (!IsAuthorized(Request, Response))
|
||||
return;
|
||||
|
||||
if (Request.getMethod() == Poco::Net::HTTPRequest::HTTP_POST)
|
||||
DoPost(Request, Response);
|
||||
else if(Request.getMethod()==Poco::Net::HTTPRequest::HTTP_GET)
|
||||
DoGet(Request, Response);
|
||||
|
||||
BadRequest(Request, Response);
|
||||
}
|
||||
|
||||
void RESTAPI_system_command::DoPost(Poco::Net::HTTPServerRequest &Request, Poco::Net::HTTPServerResponse &Response) {
|
||||
try {
|
||||
if (Request.getMethod() == Poco::Net::HTTPRequest::HTTP_POST) {
|
||||
Poco::JSON::Parser parser;
|
||||
auto Obj = parser.parse(Request.stream()).extract<Poco::JSON::Object::Ptr>();
|
||||
Poco::JSON::Parser parser;
|
||||
auto Obj = parser.parse(Request.stream()).extract<Poco::JSON::Object::Ptr>();
|
||||
|
||||
if (Obj->has(uCentral::RESTAPI::Protocol::COMMAND)) {
|
||||
auto Command = Poco::toLower(Obj->get(uCentral::RESTAPI::Protocol::COMMAND).toString());
|
||||
if (Command == uCentral::RESTAPI::Protocol::SETLOGLEVEL) {
|
||||
if (Obj->has(uCentral::RESTAPI::Protocol::PARAMETERS) &&
|
||||
Obj->isArray(uCentral::RESTAPI::Protocol::PARAMETERS)) {
|
||||
auto ParametersBlock = Obj->getArray(uCentral::RESTAPI::Protocol::PARAMETERS);
|
||||
for (const auto &i:*ParametersBlock) {
|
||||
Poco::JSON::Parser pp;
|
||||
auto InnerObj = pp.parse(i).extract<Poco::JSON::Object::Ptr>();
|
||||
if (InnerObj->has(uCentral::RESTAPI::Protocol::TAG) &&
|
||||
InnerObj->has(uCentral::RESTAPI::Protocol::VALUE)) {
|
||||
auto Name = GetS(uCentral::RESTAPI::Protocol::TAG, InnerObj);
|
||||
auto Value = GetS(uCentral::RESTAPI::Protocol::VALUE, InnerObj);
|
||||
Daemon()->SetSubsystemLogLevel(Name, Value);
|
||||
Logger_.information(Poco::format("Setting log level for %s at %s", Name, Value));
|
||||
}
|
||||
if (Obj->has(uCentral::RESTAPI::Protocol::COMMAND)) {
|
||||
auto Command = Poco::toLower(Obj->get(uCentral::RESTAPI::Protocol::COMMAND).toString());
|
||||
if (Command == uCentral::RESTAPI::Protocol::SETLOGLEVEL) {
|
||||
if (Obj->has(uCentral::RESTAPI::Protocol::PARAMETERS) &&
|
||||
Obj->isArray(uCentral::RESTAPI::Protocol::PARAMETERS)) {
|
||||
auto ParametersBlock = Obj->getArray(uCentral::RESTAPI::Protocol::PARAMETERS);
|
||||
for (const auto &i:*ParametersBlock) {
|
||||
Poco::JSON::Parser pp;
|
||||
auto InnerObj = pp.parse(i).extract<Poco::JSON::Object::Ptr>();
|
||||
if (InnerObj->has(uCentral::RESTAPI::Protocol::TAG) &&
|
||||
InnerObj->has(uCentral::RESTAPI::Protocol::VALUE)) {
|
||||
auto Name = GetS(uCentral::RESTAPI::Protocol::TAG, InnerObj);
|
||||
auto Value = GetS(uCentral::RESTAPI::Protocol::VALUE, InnerObj);
|
||||
Daemon()->SetSubsystemLogLevel(Name, Value);
|
||||
Logger_.information(Poco::format("Setting log level for %s at %s", Name, Value));
|
||||
}
|
||||
OK(Request, Response);
|
||||
return;
|
||||
}
|
||||
} else if (Command == uCentral::RESTAPI::Protocol::GETLOGLEVELS) {
|
||||
auto CurrentLogLevels = Daemon()->GetLogLevels();
|
||||
Poco::JSON::Object Result;
|
||||
Poco::JSON::Array Array;
|
||||
for(auto &[Name,Level]:CurrentLogLevels) {
|
||||
Poco::JSON::Object Pair;
|
||||
Pair.set( uCentral::RESTAPI::Protocol::TAG,Name);
|
||||
Pair.set(uCentral::RESTAPI::Protocol::VALUE,Level);
|
||||
Array.add(Pair);
|
||||
}
|
||||
Result.set(uCentral::RESTAPI::Protocol::TAGLIST,Array);
|
||||
ReturnObject(Request,Result,Response);
|
||||
OK(Request, Response);
|
||||
return;
|
||||
} else if (Command == uCentral::RESTAPI::Protocol::GETLOGLEVELNAMES) {
|
||||
Poco::JSON::Object Result;
|
||||
Poco::JSON::Array LevelNamesArray;
|
||||
const Types::StringVec & LevelNames = Daemon()->GetLogLevelNames();
|
||||
for(const auto &i:LevelNames)
|
||||
LevelNamesArray.add(i);
|
||||
Result.set(uCentral::RESTAPI::Protocol::LIST,LevelNamesArray);
|
||||
ReturnObject(Request,Result,Response);
|
||||
return;
|
||||
} else if (Command == uCentral::RESTAPI::Protocol::GETSUBSYSTEMNAMES) {
|
||||
Poco::JSON::Object Result;
|
||||
Poco::JSON::Array LevelNamesArray;
|
||||
const Types::StringVec & SubSystemNames = Daemon()->GetSubSystems();
|
||||
for(const auto &i:SubSystemNames)
|
||||
LevelNamesArray.add(i);
|
||||
Result.set(uCentral::RESTAPI::Protocol::LIST,LevelNamesArray);
|
||||
ReturnObject(Request,Result,Response);
|
||||
return;
|
||||
} else if (Command == uCentral::RESTAPI::Protocol::STATS) {
|
||||
|
||||
}
|
||||
} else if (Command == uCentral::RESTAPI::Protocol::GETLOGLEVELS) {
|
||||
auto CurrentLogLevels = Daemon()->GetLogLevels();
|
||||
Poco::JSON::Object Result;
|
||||
Poco::JSON::Array Array;
|
||||
for(auto &[Name,Level]:CurrentLogLevels) {
|
||||
Poco::JSON::Object Pair;
|
||||
Pair.set( uCentral::RESTAPI::Protocol::TAG,Name);
|
||||
Pair.set(uCentral::RESTAPI::Protocol::VALUE,Level);
|
||||
Array.add(Pair);
|
||||
}
|
||||
Result.set(uCentral::RESTAPI::Protocol::TAGLIST,Array);
|
||||
ReturnObject(Request,Result,Response);
|
||||
return;
|
||||
} else if (Command == uCentral::RESTAPI::Protocol::GETLOGLEVELNAMES) {
|
||||
Poco::JSON::Object Result;
|
||||
Poco::JSON::Array LevelNamesArray;
|
||||
const Types::StringVec & LevelNames = Daemon()->GetLogLevelNames();
|
||||
for(const auto &i:LevelNames)
|
||||
LevelNamesArray.add(i);
|
||||
Result.set(uCentral::RESTAPI::Protocol::LIST,LevelNamesArray);
|
||||
ReturnObject(Request,Result,Response);
|
||||
return;
|
||||
} else if (Command == uCentral::RESTAPI::Protocol::GETSUBSYSTEMNAMES) {
|
||||
Poco::JSON::Object Result;
|
||||
Poco::JSON::Array LevelNamesArray;
|
||||
const Types::StringVec & SubSystemNames = Daemon()->GetSubSystems();
|
||||
for(const auto &i:SubSystemNames)
|
||||
LevelNamesArray.add(i);
|
||||
Result.set(uCentral::RESTAPI::Protocol::LIST,LevelNamesArray);
|
||||
ReturnObject(Request,Result,Response);
|
||||
return;
|
||||
} else if (Command == uCentral::RESTAPI::Protocol::STATS) {
|
||||
|
||||
}
|
||||
}
|
||||
} catch(const Poco::Exception &E) {
|
||||
Logger_.log(E);
|
||||
}
|
||||
BadRequest(Request, Response);
|
||||
}
|
||||
|
||||
void RESTAPI_system_command::DoGet(Poco::Net::HTTPServerRequest &Request, Poco::Net::HTTPServerResponse &Response) {
|
||||
try {
|
||||
ParseParameters(Request);
|
||||
auto Command = GetParameter("command", "");
|
||||
if (!Poco::icompare(Command, "version")) {
|
||||
Poco::JSON::Object Answer;
|
||||
Answer.set("tag", "version");
|
||||
Answer.set("value", Daemon()->Version());
|
||||
ReturnObject(Request, Answer, Response);
|
||||
return;
|
||||
}
|
||||
if (!Poco::icompare(Command, "times")) {
|
||||
Poco::JSON::Array Array;
|
||||
Poco::JSON::Object Answer;
|
||||
Poco::JSON::Object UpTimeObj;
|
||||
UpTimeObj.set("tag","uptime");
|
||||
UpTimeObj.set("value", Daemon()->uptime().totalSeconds());
|
||||
Poco::JSON::Object StartObj;
|
||||
StartObj.set("tag","start");
|
||||
StartObj.set("value", Daemon()->startTime().epochTime());
|
||||
Array.add(UpTimeObj);
|
||||
Array.add(StartObj);
|
||||
Answer.set("times", Array);
|
||||
ReturnObject(Request, Answer, Response);
|
||||
return;
|
||||
}
|
||||
} catch (const Poco::Exception &E) {
|
||||
Logger_.log(E);
|
||||
}
|
||||
BadRequest(Request, Response);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user