Adding WebSocketNotification.

This commit is contained in:
stephb9959
2022-04-04 18:27:00 -07:00
parent 266266481e
commit b0775f19f9
4 changed files with 16 additions and 15 deletions

2
build
View File

@@ -1 +1 @@
85
86

View File

@@ -864,6 +864,7 @@ namespace OpenWifi::ProvObjects {
RESTAPI_utils::field_to_json(Obj,"errors",errors);
RESTAPI_utils::field_to_json(Obj,"warnings",warnings);
RESTAPI_utils::field_to_json(Obj,"timeStamp",timeStamp);
RESTAPI_utils::field_to_json(Obj,"details",details);
}
bool WebSocketNotificationContent::from_json(const Poco::JSON::Object::Ptr &Obj) {
@@ -874,6 +875,7 @@ namespace OpenWifi::ProvObjects {
RESTAPI_utils::field_from_json(Obj,"errors",errors);
RESTAPI_utils::field_from_json(Obj,"warnings",warnings);
RESTAPI_utils::field_from_json(Obj,"timeStamp",timeStamp);
RESTAPI_utils::field_from_json(Obj,"details",details);
return true;
} catch(...) {

View File

@@ -500,7 +500,8 @@ namespace OpenWifi::ProvObjects {
struct WebSocketNotificationContent {
std::string title,
type;
type,
details;
std::vector<std::string> success,
errors,
warnings;

View File

@@ -59,6 +59,9 @@ namespace OpenWifi {
if(When_ && When_>OpenWifi::Now())
Poco::Thread::trySleep( (long) (When_ - OpenWifi::Now()) * 1000 );
ProvObjects::WebSocketNotification N;
N.content.type = "configuration_update";
Logger().information(fmt::format("Job {} Starting.", JobId_));
ProvObjects::Venue Venue;
@@ -66,8 +69,8 @@ namespace OpenWifi {
if(StorageService()->VenueDB().GetRecord("id",VenueUUID_,Venue)) {
for(const Types::UUID_t &uuid:Venue.devices) {
ProvObjects::InventoryTag Device;
if(StorageService()->InventoryDB().GetRecord("id",uuid,Device)) {
N.content.title = "Venue Configuration Updater: " + Venue.info.name;
Logger().debug(fmt::format("{}: Computing configuration.",Device.serialNumber));
auto DeviceConfig = std::make_shared<APConfig>(Device.serialNumber, Device.deviceType, Logger(), false);
auto Configuration = Poco::makeShared<Poco::JSON::Object>();
@@ -85,34 +88,29 @@ namespace OpenWifi {
Results.errorCode = 0;
Logger().information(fmt::format("Device {} updated.", Device.serialNumber));
Updated++;
N.content.success.push_back(Device.serialNumber);
} else {
Logger().information(fmt::format("Device {} was not updated.", Device.serialNumber));
Results.errorCode = 1;
Failed++;
N.content.warnings.push_back(Device.serialNumber);
}
} else {
Logger().debug(fmt::format("{}: Configuration is bad.",Device.serialNumber));
Results.errorCode = 1;
N.content.errors.push_back(Device.serialNumber);
BadConfigs++;
}
}
}
N.content.details = fmt::format("Job {} Completed: {} updated, {} failed to update{} , {} bad configurations. ",
JobId_, Updated ,Failed, BadConfigs);
} else {
Logger().warning(fmt::format("Venue {} no longer exists.",VenueUUID_));
N.content.details = fmt::format("Venue {} no longer exists.",VenueUUID_);
Logger().warning(N.content.details);
}
ProvObjects::WebSocketNotification N;
N.content.title = "Bulk Configuration Updater";
N.content.type = "configuration_update";
N.content.success.push_back(fmt::format("Successfully updated {} devices.",Updated));
if(Failed>0)
N.content.warnings.push_back(fmt::format("Could not update {} devices.",Failed));
if(BadConfigs>0)
N.content.errors.push_back(fmt::format("Bad configuration for {} devices.",BadConfigs));
auto Sent = WebSocketClientServer()->SendUserNotification(UI_.email,N);
Logger().information(fmt::format("Job {} Completed: {} updated, {} failed to update{} , {} bad configurations. Notification was send={}",
JobId_, Updated ,Failed, BadConfigs, Sent));
delete this;