stephb9959
2023-04-06 08:59:15 -07:00
parent 9160497b28
commit 0ae5dc5cf9
8 changed files with 71 additions and 12 deletions

2
build
View File

@@ -1 +1 @@
26 27

View File

@@ -260,6 +260,20 @@ components:
format: uuid format: uuid
restrictionDetails: restrictionDetails:
$ref: '#/components/schemas/DeviceRestrictions' $ref: '#/components/schemas/DeviceRestrictions'
hasGPS:
type: boolean
sanity:
type: integer
format: int64
memoryUsed:
type: number
format: float
load:
type: number
format: float
temperature:
type: number
format: float
DeviceList: DeviceList:
type: object type: object
@@ -329,6 +343,9 @@ components:
associations_5G: associations_5G:
type: integer type: integer
format: int64 format: int64
associations_6G:
type: integer
format: int64
verifiedCertificate: verifiedCertificate:
type: string type: string
enum: enum:

View File

@@ -66,11 +66,30 @@ namespace OpenWifi {
inline void SetLastStats(const std::string &LastStats) { inline void SetLastStats(const std::string &LastStats) {
std::unique_lock G(ConnectionMutex_); std::unique_lock G(ConnectionMutex_);
RawLastStats_ = LastStats; RawLastStats_ = LastStats;
try { try {
Poco::JSON::Parser P; Poco::JSON::Parser P;
auto Stats = P.parse(LastStats).extract<Poco::JSON::Object::Ptr>(); auto Stats = P.parse(LastStats).extract<Poco::JSON::Object::Ptr>();
hasGPS = Stats->isObject("gps"); 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_ =
(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);
}
}
if(Unit->isArray("temperature")) {
Poco::JSON::Array::Ptr Temperature = Unit->getArray("temperature");
if(Temperature->size()>1) {
temperature_ = Temperature->get(0);
}
}
} catch (...) { } catch (...) {
} }
@@ -180,6 +199,7 @@ namespace OpenWifi {
bool StopTelemetry(uint64_t RPCID); bool StopTelemetry(uint64_t RPCID);
void UpdateCounts(); void UpdateCounts();
bool hasGPS=false; bool hasGPS=false;
std::double_t memory_used_=0.0, cpu_load_ = 0.0, temperature_ = 0.0;
}; };
} // namespace OpenWifi } // namespace OpenWifi

View File

@@ -213,14 +213,24 @@ namespace OpenWifi {
return true; return true;
} }
inline bool HasGPS(const std::string &serialNumber) { inline bool ExtendedAttributes(const std::string &serialNumber,
bool & hasGPS,
std::uint64_t &Sanity,
std::double_t &MemoryUsed,
std::double_t &Load,
std::double_t &Temperature
) {
std::lock_guard G(WSServerMutex_); std::lock_guard G(WSServerMutex_);
auto session_hint = SerialNumbers_.find(Utils::SerialNumberToInt(serialNumber)); auto session_hint = SerialNumbers_.find(Utils::SerialNumberToInt(serialNumber));
if(session_hint==end(SerialNumbers_)) { if(session_hint==end(SerialNumbers_)) {
return false; return false;
} }
return session_hint->second.second->hasGPS; hasGPS = session_hint->second.second->hasGPS;
Sanity = session_hint->second.second->RawLastHealthcheck_.Sanity;
MemoryUsed = session_hint->second.second->memory_used_;
Load = session_hint->second.second->cpu_load_;
Temperature = session_hint->second.second->temperature_;
return true;
} }
private: private:

View File

@@ -309,7 +309,7 @@ namespace OpenWifi {
if (AP_WS_Server()->GetState(SerialNumber_, State)) { if (AP_WS_Server()->GetState(SerialNumber_, State)) {
Poco::JSON::Object RetObject; Poco::JSON::Object RetObject;
State.to_json(RetObject); State.to_json(SerialNumber_, RetObject);
return ReturnObject(RetObject); return ReturnObject(RetObject);
} else { } else {
Poco::JSON::Object RetObject; Poco::JSON::Object RetObject;

View File

@@ -23,7 +23,7 @@ namespace OpenWifi {
Device.to_json(DeviceInfo); Device.to_json(DeviceInfo);
Answer.set("deviceInfo", DeviceInfo); Answer.set("deviceInfo", DeviceInfo);
Poco::JSON::Object CSInfo; Poco::JSON::Object CSInfo;
CS.to_json(CSInfo); CS.to_json(Device.SerialNumber, CSInfo);
Answer.set("connectionInfo", CSInfo); Answer.set("connectionInfo", CSInfo);
Poco::JSON::Object HCInfo; Poco::JSON::Object HCInfo;
HC.to_json(HCInfo); HC.to_json(HCInfo);

View File

@@ -30,8 +30,6 @@ namespace OpenWifi::GWObjects {
field_to_json(Obj, "serialNumber", SerialNumber); field_to_json(Obj, "serialNumber", SerialNumber);
#ifdef TIP_GATEWAY_SERVICE #ifdef TIP_GATEWAY_SERVICE
field_to_json(Obj, "deviceType", CapabilitiesCache::instance()->GetPlatform(Compatible)); field_to_json(Obj, "deviceType", CapabilitiesCache::instance()->GetPlatform(Compatible));
field_to_json(Obj, "hasRADIUSSessions", RADIUSSessionTracker()->HasSessions(SerialNumber));
field_to_json(Obj, "hasGPS", AP_WS_Server()->HasGPS(SerialNumber));
#endif #endif
field_to_json(Obj, "macAddress", MACAddress); field_to_json(Obj, "macAddress", MACAddress);
field_to_json(Obj, "manufacturer", Manufacturer); field_to_json(Obj, "manufacturer", Manufacturer);
@@ -67,7 +65,7 @@ namespace OpenWifi::GWObjects {
ConnectionState ConState; ConnectionState ConState;
if (AP_WS_Server()->GetState(SerialNumber, ConState)) { if (AP_WS_Server()->GetState(SerialNumber, ConState)) {
ConState.to_json(Obj); ConState.to_json(SerialNumber,Obj);
} else { } else {
field_to_json(Obj, "ipAddress", ""); field_to_json(Obj, "ipAddress", "");
field_to_json(Obj, "txBytes", (uint64_t)0); field_to_json(Obj, "txBytes", (uint64_t)0);
@@ -81,6 +79,11 @@ namespace OpenWifi::GWObjects {
field_to_json(Obj, "associations_6G", (uint64_t)0); field_to_json(Obj, "associations_6G", (uint64_t)0);
field_to_json(Obj, "hasRADIUSSessions", false); field_to_json(Obj, "hasRADIUSSessions", false);
field_to_json(Obj, "hasGPS", false); field_to_json(Obj, "hasGPS", false);
field_to_json(Obj, "sanity", ConState.sanity);
field_to_json(Obj, "memoryUsed", ConState.memoryUsed);
field_to_json(Obj, "sanity", ConState.sanity);
field_to_json(Obj, "load", ConState.load);
field_to_json(Obj, "temperature", ConState.temperature);
} }
#endif #endif
} }
@@ -216,7 +219,7 @@ namespace OpenWifi::GWObjects {
return false; return false;
} }
void ConnectionState::to_json(Poco::JSON::Object &Obj) const { void ConnectionState::to_json(const std::string &SerialNumber, Poco::JSON::Object &Obj) {
field_to_json(Obj, "ipAddress", Address); field_to_json(Obj, "ipAddress", Address);
field_to_json(Obj, "txBytes", TX); field_to_json(Obj, "txBytes", TX);
field_to_json(Obj, "rxBytes", RX); field_to_json(Obj, "rxBytes", RX);
@@ -239,6 +242,11 @@ namespace OpenWifi::GWObjects {
field_to_json(Obj, "totalConnectionTime", Utils::Now() - started); field_to_json(Obj, "totalConnectionTime", Utils::Now() - started);
field_to_json(Obj, "certificateExpiryDate", certificateExpiryDate); field_to_json(Obj, "certificateExpiryDate", certificateExpiryDate);
AP_WS_Server()->ExtendedAttributes(SerialNumber, hasGPS, sanity,
memoryUsed,
load,
temperature);
switch (VerifiedCertificate) { switch (VerifiedCertificate) {
case NO_CERTIFICATE: case NO_CERTIFICATE:
field_to_json(Obj, "verifiedCertificate", "NO_CERTIFICATE"); field_to_json(Obj, "verifiedCertificate", "NO_CERTIFICATE");

View File

@@ -44,8 +44,12 @@ namespace OpenWifi::GWObjects {
std::uint64_t certificateExpiryDate = 0; std::uint64_t certificateExpiryDate = 0;
bool hasRADIUSSessions = false; bool hasRADIUSSessions = false;
bool hasGPS = false; bool hasGPS = false;
std::uint64_t sanity=0;
std::double_t memoryUsed=0.0;
std::double_t load=0.0;
std::double_t temperature=0.0;
void to_json(Poco::JSON::Object &Obj) const; void to_json(const std::string &SerialNumber, Poco::JSON::Object &Obj) ;
}; };
struct DeviceRestrictionsKeyInfo { struct DeviceRestrictionsKeyInfo {