proc-api/src/routes.cpp

83 lines
2.4 KiB
C++
Raw Normal View History

2022-04-29 00:39:39 +00:00
///////////////////////////////////////////////////////////////////////////////
// Tyler Perkins
// 28-4-22
// Routes implementation
//
#include "routes.hpp"
void setRoutes(crow::SimpleApp& app){
CROW_ROUTE(app, "/proc/meminfo")([](const crow::request& req){
bool status;
std::string accept = req.get_header_value("Accept");
2022-04-29 01:32:07 +00:00
std::transform(accept.begin(), accept.end(), accept.begin(), ::tolower);
if(accept == "text/plain"){
accept.clear();
status = memory::getRawProcMem(accept);
return crow::response(status ? 200 : 503, accept);
} else {
2022-04-29 17:06:51 +00:00
crow::json::wvalue json;
status = memory::getProcMem(json);
return crow::response(status ? 200 : 503, json.dump());
}
2022-04-29 00:39:39 +00:00
});
2022-04-29 17:08:43 +00:00
CROW_ROUTE(app, "/mem")([](){
2022-04-29 17:06:51 +00:00
bool status;
2022-04-29 17:08:43 +00:00
crow::json::wvalue json;
status = memory::getEasyMem(json);
return crow::response(status ? 200 : 503, json.dump());
2022-04-29 17:06:51 +00:00
});
2022-04-29 16:12:02 +00:00
CROW_ROUTE(app, "/proc/uptime")([](const crow::request& req){
2022-04-29 16:05:34 +00:00
bool status;
2022-04-29 16:12:02 +00:00
std::string accept = req.get_header_value("Accept");
2022-04-29 16:05:34 +00:00
2022-04-29 16:12:02 +00:00
std::transform(accept.begin(), accept.end(), accept.begin(), ::tolower);
2022-04-29 16:05:34 +00:00
2022-04-29 16:12:02 +00:00
if(accept == "text/plain"){
accept.clear();
status = state::getRawUptime(accept);
return crow::response(status ? 200 : 503, accept);
} else {
2022-04-29 17:06:51 +00:00
crow::json::wvalue json;
2022-04-29 16:12:02 +00:00
status = state::getUptime(json);
return crow::response(status ? 200: 503, json.dump());
}
2022-04-29 16:05:34 +00:00
});
2022-04-29 16:57:33 +00:00
CROW_ROUTE(app, "/uptime")([](){
crow::response ret;
ret.moved_perm("/proc/uptime");
return ret;
});
2022-04-29 17:34:10 +00:00
CROW_ROUTE(app, "/proc/loadavg")([](const crow::request& req){
bool status;
std::string accept = req.get_header_value("Accept");
std::transform(accept.begin(), accept.end(), accept.begin(), ::tolower);
if(accept == "text/plain"){
accept.clear();
status = state::getRawLoadAvg(accept);
return crow::response(status ? 200 : 503, accept);
} else {
crow::json::wvalue json;
status = state::getLoadAvg(json);
return crow::response(status ? 200 : 503, json.dump());
}
});
CROW_ROUTE(app, "/load")([](){
crow::response ret;
ret.moved_perm("/proc/loadavg");
return ret;
});
2022-04-29 00:39:39 +00:00
}