Skip to content

Commit

Permalink
https://telecominfraproject.atlassian.net/browse/WIFI-13280
Browse files Browse the repository at this point in the history
Signed-off-by: stephb9959 <[email protected]>
  • Loading branch information
stephb9959 committed Jan 23, 2024
1 parent d839646 commit 1acabd4
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 15 deletions.
2 changes: 1 addition & 1 deletion build
Original file line number Diff line number Diff line change
@@ -1 +1 @@
75
76
8 changes: 4 additions & 4 deletions src/AP_WS_Connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -897,25 +897,25 @@ namespace OpenWifi {
try {
Poco::JSON::Parser P;
auto Stats = P.parse(LastStats).extract<Poco::JSON::Object::Ptr>();
hasGPS_ = Stats->isObject("gps");
State_.hasGPS = Stats->isObject("gps");
auto Unit = Stats->getObject("unit");
auto Memory = Unit->getObject("memory");
std::uint64_t TotalMemory = Memory->get("total");
std::uint64_t FreeMemory = Memory->get("free");
if (TotalMemory > 0) {
memory_used_ =
State_.memoryUsed =
(100.0 * ((double)TotalMemory - (double)FreeMemory)) / (double)TotalMemory;
}
if (Unit->isArray("load")) {
Poco::JSON::Array::Ptr Load = Unit->getArray("load");
if (Load->size() > 1) {
cpu_load_ = Load->get(1);
State_.load = Load->get(1);
}
}
if (Unit->isArray("temperature")) {
Poco::JSON::Array::Ptr Temperature = Unit->getArray("temperature");
if (Temperature->size() > 1) {
temperature_ = Temperature->get(0);
State_.temperature = Temperature->get(0);
}
}
} catch (const Poco::Exception &E) {
Expand Down
1 change: 1 addition & 0 deletions src/AP_WS_Process_healthcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ namespace OpenWifi {

uint64_t UUID = ParamsObj->get(uCentralProtocol::UUID);
auto Sanity = ParamsObj->get(uCentralProtocol::SANITY);
State_.sanity = Sanity;
auto CheckData = ParamsObj->get(uCentralProtocol::DATA).toString();
if (CheckData.empty())
CheckData = uCentralProtocol::EMPTY_JSON_DOC;
Expand Down
4 changes: 2 additions & 2 deletions src/AP_WS_Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ namespace OpenWifi {
return false;
}

bool AP_WS_Server::ExtendedAttributes(const std::string &serialNumber,
/* bool AP_WS_Server::ExtendedAttributes(const std::string &serialNumber,
bool & hasGPS,
std::uint64_t &Sanity,
std::double_t &MemoryUsed,
Expand All @@ -712,6 +712,6 @@ namespace OpenWifi {
Temperature = DeviceHint->second->temperature_;
return true;
}

*/

} // namespace OpenWifi
4 changes: 2 additions & 2 deletions src/AP_WS_Server.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ namespace OpenWifi {
uint64_t &TelemetryKafkaPackets);

bool GetHealthDevices(std::uint64_t lowLimit, std::uint64_t highLimit, std::vector<std::string> & SerialNumbers);
bool ExtendedAttributes(const std::string &serialNumber, bool & hasGPS, std::uint64_t &Sanity,
std::double_t &MemoryUsed, std::double_t &Load, std::double_t &Temperature);
// bool ExtendedAttributes(const std::string &serialNumber, bool & hasGPS, std::uint64_t &Sanity,
// std::double_t &MemoryUsed, std::double_t &Load, std::double_t &Temperature);

inline void AverageDeviceStatistics(uint64_t &Connections, uint64_t &AverageConnectionTime,
uint64_t &NumberOfConnectingDevices) const {
Expand Down
58 changes: 52 additions & 6 deletions src/RESTObjects/RESTAPI_GWobjects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@

#include "Daemon.h"
#ifdef TIP_GATEWAY_SERVICE
#ifdef USE_MEDUSA_CLIENT
#include <medusa/GlobalSystem.h>
#else
#include "AP_WS_Server.h"
#endif
#include "StorageService.h"
#include "CapabilitiesCache.h"
#include "RADIUSSessionTracker.h"
#endif
Expand Down Expand Up @@ -69,8 +74,13 @@ namespace OpenWifi::GWObjects {

#ifdef TIP_GATEWAY_SERVICE
ConnectionState ConState;

if (AP_WS_Server()->GetState(SerialNumber, ConState)) {
#ifdef USE_MEDUSA_CLIENT
auto Res = GS()->GetState(SerialNumber);
if (Res.has_value()) {
Res.value().to_json(SerialNumber,Obj);
#else
if (AP_WS_Server()->GetState(SerialNumber, ConState)) {
#endif
ConState.to_json(SerialNumber,Obj);
} else {
field_to_json(Obj, "ipAddress", "");
Expand Down Expand Up @@ -280,11 +290,9 @@ namespace OpenWifi::GWObjects {
field_to_json(Obj, "uptime", uptime);

#ifdef TIP_GATEWAY_SERVICE
#ifndef USE_MEDUSA_CLIENT
hasRADIUSSessions = RADIUSSessionTracker()->HasSessions(SerialNumber);
AP_WS_Server()->ExtendedAttributes(SerialNumber, hasGPS, sanity,
memoryUsed,
load,
temperature);
#endif
#endif
field_to_json(Obj, "hasRADIUSSessions", hasRADIUSSessions );
field_to_json(Obj, "hasGPS", hasGPS);
Expand Down Expand Up @@ -316,6 +324,44 @@ namespace OpenWifi::GWObjects {
}
}

bool ConnectionState::from_json(const Poco::JSON::Object::Ptr &Obj) {
try {
field_from_json(Obj, "ipAddress", Address);
field_from_json(Obj, "txBytes", TX);
field_from_json(Obj, "rxBytes", RX);
field_from_json(Obj, "messageCount", MessageCount);
field_from_json(Obj, "UUID", UUID);
field_from_json(Obj, "connected", Connected);
field_from_json(Obj, "firmware", Firmware);
field_from_json(Obj, "lastContact", LastContact);
field_from_json(Obj, "associations_2G", Associations_2G);
field_from_json(Obj, "associations_5G", Associations_5G);
field_from_json(Obj, "associations_6G", Associations_6G);
field_from_json(Obj, "webSocketClients", webSocketClients);
field_from_json(Obj, "websocketPackets", websocketPackets);
field_from_json(Obj, "kafkaClients", kafkaClients);
field_from_json(Obj, "kafkaPackets", kafkaPackets);
field_from_json(Obj, "locale", locale);
field_from_json(Obj, "started", started);
field_from_json(Obj, "sessionId", sessionId);
field_from_json(Obj, "connectionCompletionTime", connectionCompletionTime);
field_from_json(Obj, "totalConnectionTime", totalConnectionTime);
field_from_json(Obj, "certificateExpiryDate", certificateExpiryDate);
field_from_json(Obj, "connectReason", connectReason);
field_from_json(Obj, "uptime", uptime);
field_from_json(Obj, "hasRADIUSSessions", hasRADIUSSessions );
field_from_json(Obj, "hasGPS", hasGPS);
field_from_json(Obj, "sanity", sanity);
field_from_json(Obj, "memoryUsed", memoryUsed);
field_from_json(Obj, "sanity", sanity);
field_from_json(Obj, "load", load);
field_from_json(Obj, "temperature", temperature);
return true;
} catch(const Poco::Exception &E) {
}
return false;
}

void DeviceConnectionStatistics::to_json(Poco::JSON::Object &Obj) const {
field_to_json(Obj, "averageConnectionTime", averageConnectionTime);
field_to_json(Obj, "connectedDevices", connectedDevices);
Expand Down
2 changes: 2 additions & 0 deletions src/RESTObjects/RESTAPI_GWobjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ namespace OpenWifi::GWObjects {
std::double_t temperature=0.0;
std::string connectReason;
std::uint64_t uptime=0;
std::uint64_t totalConnectionTime=0;

void to_json(const std::string &SerialNumber, Poco::JSON::Object &Obj) ;
bool from_json(const Poco::JSON::Object::Ptr &Obj);
};

struct DeviceRestrictionsKeyInfo {
Expand Down

0 comments on commit 1acabd4

Please sign in to comment.