[Refactor] Downtime::GetDowntimeIDFromLegacyID(): return the Downtime itself

not just its name.
This commit is contained in:
Alexander A. Klimov 2024-04-24 13:07:18 +02:00
parent 28b0f7a48c
commit f0b5239a15
3 changed files with 90 additions and 25 deletions

View File

@ -513,16 +513,17 @@ void Downtime::SetRemovalInfo(const String& removedBy, double removeTime, const
OnRemovalInfoChanged(this, removedBy, removeTime, origin);
}
String Downtime::GetDowntimeIDFromLegacyID(int id)
Downtime::Ptr Downtime::GetDowntimeFromLegacyID(int id)
{
std::unique_lock<std::mutex> lock(l_DowntimeMutex);
auto it = l_LegacyDowntimesCache.find(id);
if (it == l_LegacyDowntimesCache.end())
return Empty;
if (it == l_LegacyDowntimesCache.end()) {
return nullptr;
}
return it->second->GetName();
return it->second;
}
void Downtime::DowntimesStartTimerHandler()

View File

@ -64,7 +64,7 @@ public:
void OnAllConfigLoaded() override;
static String GetDowntimeIDFromLegacyID(int id);
static Downtime::Ptr GetDowntimeFromLegacyID(int id);
static DowntimeChildOptions ChildOptionsFromValue(const Value& options);

View File

@ -970,8 +970,14 @@ void ExternalCommandProcessor::ScheduleSvcDowntime(double, const std::vector<Str
String triggeredBy;
int triggeredByLegacy = Convert::ToLong(arguments[5]);
int is_fixed = Convert::ToLong(arguments[4]);
if (triggeredByLegacy != 0)
triggeredBy = Downtime::GetDowntimeIDFromLegacyID(triggeredByLegacy);
if (triggeredByLegacy != 0) {
auto trigger (Downtime::GetDowntimeFromLegacyID(triggeredByLegacy));
if (trigger) {
triggeredBy = trigger->GetName();
}
}
Log(LogNotice, "ExternalCommandProcessor")
<< "Creating downtime for service " << service->GetName();
@ -983,7 +989,12 @@ void ExternalCommandProcessor::ScheduleSvcDowntime(double, const std::vector<Str
void ExternalCommandProcessor::DelSvcDowntime(double, const std::vector<String>& arguments)
{
int id = Convert::ToLong(arguments[0]);
String rid = Downtime::GetDowntimeIDFromLegacyID(id);
String rid;
auto dt (Downtime::GetDowntimeFromLegacyID(id));
if (dt) {
rid = dt->GetName();
}
try {
Downtime::RemoveDowntime(rid, false, true);
@ -1005,8 +1016,14 @@ void ExternalCommandProcessor::ScheduleHostDowntime(double, const std::vector<St
String triggeredBy;
int triggeredByLegacy = Convert::ToLong(arguments[4]);
int is_fixed = Convert::ToLong(arguments[3]);
if (triggeredByLegacy != 0)
triggeredBy = Downtime::GetDowntimeIDFromLegacyID(triggeredByLegacy);
if (triggeredByLegacy != 0) {
auto trigger (Downtime::GetDowntimeFromLegacyID(triggeredByLegacy));
if (trigger) {
triggeredBy = trigger->GetName();
}
}
Log(LogNotice, "ExternalCommandProcessor")
<< "Creating downtime for host " << host->GetName();
@ -1026,8 +1043,14 @@ void ExternalCommandProcessor::ScheduleAndPropagateHostDowntime(double, const st
String triggeredBy;
int triggeredByLegacy = Convert::ToLong(arguments[4]);
int is_fixed = Convert::ToLong(arguments[3]);
if (triggeredByLegacy != 0)
triggeredBy = Downtime::GetDowntimeIDFromLegacyID(triggeredByLegacy);
if (triggeredByLegacy != 0) {
auto trigger (Downtime::GetDowntimeFromLegacyID(triggeredByLegacy));
if (trigger) {
triggeredBy = trigger->GetName();
}
}
Log(LogNotice, "ExternalCommandProcessor")
<< "Creating downtime for host " << host->GetName();
@ -1062,8 +1085,14 @@ void ExternalCommandProcessor::ScheduleAndPropagateTriggeredHostDowntime(double,
String triggeredBy;
int triggeredByLegacy = Convert::ToLong(arguments[4]);
int is_fixed = Convert::ToLong(arguments[3]);
if (triggeredByLegacy != 0)
triggeredBy = Downtime::GetDowntimeIDFromLegacyID(triggeredByLegacy);
if (triggeredByLegacy != 0) {
auto trigger (Downtime::GetDowntimeFromLegacyID(triggeredByLegacy));
if (trigger) {
triggeredBy = trigger->GetName();
}
}
Log(LogNotice, "ExternalCommandProcessor")
<< "Creating downtime for host " << host->GetName();
@ -1091,7 +1120,12 @@ void ExternalCommandProcessor::ScheduleAndPropagateTriggeredHostDowntime(double,
void ExternalCommandProcessor::DelHostDowntime(double, const std::vector<String>& arguments)
{
int id = Convert::ToLong(arguments[0]);
String rid = Downtime::GetDowntimeIDFromLegacyID(id);
String rid;
auto dt (Downtime::GetDowntimeFromLegacyID(id));
if (dt) {
rid = dt->GetName();
}
try {
Downtime::RemoveDowntime(rid, false, true);
@ -1172,8 +1206,14 @@ void ExternalCommandProcessor::ScheduleHostSvcDowntime(double, const std::vector
String triggeredBy;
int triggeredByLegacy = Convert::ToLong(arguments[4]);
int is_fixed = Convert::ToLong(arguments[3]);
if (triggeredByLegacy != 0)
triggeredBy = Downtime::GetDowntimeIDFromLegacyID(triggeredByLegacy);
if (triggeredByLegacy != 0) {
auto trigger (Downtime::GetDowntimeFromLegacyID(triggeredByLegacy));
if (trigger) {
triggeredBy = trigger->GetName();
}
}
Log(LogNotice, "ExternalCommandProcessor")
<< "Creating downtime for host " << host->GetName();
@ -1201,8 +1241,14 @@ void ExternalCommandProcessor::ScheduleHostgroupHostDowntime(double, const std::
String triggeredBy;
int triggeredByLegacy = Convert::ToLong(arguments[4]);
int is_fixed = Convert::ToLong(arguments[3]);
if (triggeredByLegacy != 0)
triggeredBy = Downtime::GetDowntimeIDFromLegacyID(triggeredByLegacy);
if (triggeredByLegacy != 0) {
auto trigger (Downtime::GetDowntimeFromLegacyID(triggeredByLegacy));
if (trigger) {
triggeredBy = trigger->GetName();
}
}
for (const Host::Ptr& host : hg->GetMembers()) {
Log(LogNotice, "ExternalCommandProcessor")
@ -1224,8 +1270,14 @@ void ExternalCommandProcessor::ScheduleHostgroupSvcDowntime(double, const std::v
String triggeredBy;
int triggeredByLegacy = Convert::ToLong(arguments[4]);
int is_fixed = Convert::ToLong(arguments[3]);
if (triggeredByLegacy != 0)
triggeredBy = Downtime::GetDowntimeIDFromLegacyID(triggeredByLegacy);
if (triggeredByLegacy != 0) {
auto trigger (Downtime::GetDowntimeFromLegacyID(triggeredByLegacy));
if (trigger) {
triggeredBy = trigger->GetName();
}
}
/* Note: we can't just directly create downtimes for all the services by iterating
* over all hosts in the host group - otherwise we might end up creating multiple
@ -1258,8 +1310,14 @@ void ExternalCommandProcessor::ScheduleServicegroupHostDowntime(double, const st
String triggeredBy;
int triggeredByLegacy = Convert::ToLong(arguments[4]);
int is_fixed = Convert::ToLong(arguments[3]);
if (triggeredByLegacy != 0)
triggeredBy = Downtime::GetDowntimeIDFromLegacyID(triggeredByLegacy);
if (triggeredByLegacy != 0) {
auto trigger (Downtime::GetDowntimeFromLegacyID(triggeredByLegacy));
if (trigger) {
triggeredBy = trigger->GetName();
}
}
/* Note: we can't just directly create downtimes for all the hosts by iterating
* over all services in the service group - otherwise we might end up creating multiple
@ -1291,8 +1349,14 @@ void ExternalCommandProcessor::ScheduleServicegroupSvcDowntime(double, const std
String triggeredBy;
int triggeredByLegacy = Convert::ToLong(arguments[4]);
int is_fixed = Convert::ToLong(arguments[3]);
if (triggeredByLegacy != 0)
triggeredBy = Downtime::GetDowntimeIDFromLegacyID(triggeredByLegacy);
if (triggeredByLegacy != 0) {
auto trigger (Downtime::GetDowntimeFromLegacyID(triggeredByLegacy));
if (trigger) {
triggeredBy = trigger->GetName();
}
}
for (const Service::Ptr& service : sg->GetMembers()) {
Log(LogNotice, "ExternalCommandProcessor")