mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-23 13:45:04 +02:00
Introduce & use enum DowntimeRemovalReason
This commit is contained in:
parent
cc3965c3ce
commit
e0fd0d3df4
@ -557,7 +557,7 @@ Dictionary::Ptr ApiActions::RemoveDowntime(const ConfigObject::Ptr& object,
|
|||||||
childCount += downtime->GetChildren().size();
|
childCount += downtime->GetChildren().size();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Downtime::RemoveDowntime(downtime->GetName(), true, true, false, author);
|
Downtime::RemoveDowntime(downtime->GetName(), true, DowntimeRemovedByUser, author);
|
||||||
} catch (const invalid_downtime_removal_error& error) {
|
} catch (const invalid_downtime_removal_error& error) {
|
||||||
Log(LogWarning, "ApiActions") << error.what();
|
Log(LogWarning, "ApiActions") << error.what();
|
||||||
|
|
||||||
@ -578,7 +578,7 @@ Dictionary::Ptr ApiActions::RemoveDowntime(const ConfigObject::Ptr& object,
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
String downtimeName = downtime->GetName();
|
String downtimeName = downtime->GetName();
|
||||||
Downtime::RemoveDowntime(downtimeName, true, true, false, author);
|
Downtime::RemoveDowntime(downtimeName, true, DowntimeRemovedByUser, author);
|
||||||
|
|
||||||
return ApiActions::CreateResult(200, "Successfully removed downtime '" + downtimeName +
|
return ApiActions::CreateResult(200, "Successfully removed downtime '" + downtimeName +
|
||||||
"' and " + std::to_string(childCount) + " child downtimes.");
|
"' and " + std::to_string(childCount) + " child downtimes.");
|
||||||
|
@ -359,7 +359,7 @@ Downtime::Ptr Downtime::AddDowntime(const Checkable::Ptr& checkable, const Strin
|
|||||||
return downtime;
|
return downtime;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Downtime::RemoveDowntime(const String& id, bool includeChildren, bool cancelled, bool expired,
|
void Downtime::RemoveDowntime(const String& id, bool includeChildren, DowntimeRemovalReason removalReason,
|
||||||
const String& removedBy, const MessageOrigin::Ptr& origin)
|
const String& removedBy, const MessageOrigin::Ptr& origin)
|
||||||
{
|
{
|
||||||
Downtime::Ptr downtime = Downtime::GetByName(id);
|
Downtime::Ptr downtime = Downtime::GetByName(id);
|
||||||
@ -369,18 +369,18 @@ void Downtime::RemoveDowntime(const String& id, bool includeChildren, bool cance
|
|||||||
|
|
||||||
String config_owner = downtime->GetConfigOwner();
|
String config_owner = downtime->GetConfigOwner();
|
||||||
|
|
||||||
if (!config_owner.IsEmpty() && !expired) {
|
if (!config_owner.IsEmpty() && removalReason != DowntimeExpired) {
|
||||||
BOOST_THROW_EXCEPTION(invalid_downtime_removal_error("Cannot remove downtime '" + downtime->GetName() +
|
BOOST_THROW_EXCEPTION(invalid_downtime_removal_error("Cannot remove downtime '" + downtime->GetName() +
|
||||||
"'. It is owned by scheduled downtime object '" + config_owner + "'"));
|
"'. It is owned by scheduled downtime object '" + config_owner + "'"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (includeChildren) {
|
if (includeChildren) {
|
||||||
for (const Downtime::Ptr& child : downtime->GetChildren()) {
|
for (const Downtime::Ptr& child : downtime->GetChildren()) {
|
||||||
Downtime::RemoveDowntime(child->GetName(), true, true);
|
Downtime::RemoveDowntime(child->GetName(), true, removalReason);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cancelled) {
|
if (removalReason != DowntimeExpired) {
|
||||||
downtime->SetRemovalInfo(removedBy, Utility::GetTime());
|
downtime->SetRemovalInfo(removedBy, Utility::GetTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -396,13 +396,19 @@ void Downtime::RemoveDowntime(const String& id, bool includeChildren, bool cance
|
|||||||
}
|
}
|
||||||
|
|
||||||
String reason;
|
String reason;
|
||||||
|
switch (removalReason) {
|
||||||
if (expired) {
|
case DowntimeExpired:
|
||||||
reason = "expired at " + Utility::FormatDateTime("%Y-%m-%d %H:%M:%S %z", downtime->GetEndTime());
|
reason = "expired at " + Utility::FormatDateTime("%Y-%m-%d %H:%M:%S %z", downtime->GetEndTime());
|
||||||
} else if (cancelled) {
|
break;
|
||||||
reason = "cancelled by user";
|
case DowntimeRemovedByUser:
|
||||||
} else {
|
reason = "cancelled by user";
|
||||||
reason = "<unknown>";
|
if (!removedBy.IsEmpty()) {
|
||||||
|
reason += " '" + removedBy + "'";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case DowntimeRemovedByConfigOwner:
|
||||||
|
reason = "cancelled by '" + config_owner + "' of type 'ScheduledDowntime'";
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log msg (LogInformation, "Downtime");
|
Log msg (LogInformation, "Downtime");
|
||||||
@ -465,7 +471,7 @@ void Downtime::SetupCleanupTimer()
|
|||||||
auto downtime (Downtime::GetByName(name));
|
auto downtime (Downtime::GetByName(name));
|
||||||
|
|
||||||
if (downtime && downtime->IsExpired()) {
|
if (downtime && downtime->IsExpired()) {
|
||||||
RemoveDowntime(name, false, false, true);
|
RemoveDowntime(name, false, DowntimeExpired);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -557,7 +563,7 @@ void Downtime::DowntimesOrphanedTimerHandler()
|
|||||||
for (const Downtime::Ptr& downtime : ConfigType::GetObjectsByType<Downtime>()) {
|
for (const Downtime::Ptr& downtime : ConfigType::GetObjectsByType<Downtime>()) {
|
||||||
/* Only remove downtimes which are activated after daemon start. */
|
/* Only remove downtimes which are activated after daemon start. */
|
||||||
if (downtime->IsActive() && !downtime->HasValidConfigOwner())
|
if (downtime->IsActive() && !downtime->HasValidConfigOwner())
|
||||||
RemoveDowntime(downtime->GetName(), false, false, true);
|
RemoveDowntime(downtime->GetName(), false, DowntimeRemovedByConfigOwner);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,6 +18,13 @@ enum DowntimeChildOptions
|
|||||||
DowntimeNonTriggeredChildren
|
DowntimeNonTriggeredChildren
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum DowntimeRemovalReason
|
||||||
|
{
|
||||||
|
DowntimeExpired,
|
||||||
|
DowntimeRemovedByUser,
|
||||||
|
DowntimeRemovedByConfigOwner,
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A downtime.
|
* A downtime.
|
||||||
*
|
*
|
||||||
@ -52,7 +59,7 @@ public:
|
|||||||
const String& scheduledBy = String(), const String& parent = String(), const String& id = String(),
|
const String& scheduledBy = String(), const String& parent = String(), const String& id = String(),
|
||||||
const MessageOrigin::Ptr& origin = nullptr);
|
const MessageOrigin::Ptr& origin = nullptr);
|
||||||
|
|
||||||
static void RemoveDowntime(const String& id, bool includeChildren, bool cancelled, bool expired = false,
|
static void RemoveDowntime(const String& id, bool includeChildren, DowntimeRemovalReason removalReason,
|
||||||
const String& removedBy = "", const MessageOrigin::Ptr& origin = nullptr);
|
const String& removedBy = "", const MessageOrigin::Ptr& origin = nullptr);
|
||||||
|
|
||||||
void RegisterChild(const Downtime::Ptr& downtime);
|
void RegisterChild(const Downtime::Ptr& downtime);
|
||||||
|
@ -993,7 +993,7 @@ void ExternalCommandProcessor::DelSvcDowntime(double, const std::vector<String>&
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Downtime::RemoveDowntime(rid, false, true);
|
Downtime::RemoveDowntime(rid, false, DowntimeRemovedByUser);
|
||||||
|
|
||||||
Log(LogNotice, "ExternalCommandProcessor")
|
Log(LogNotice, "ExternalCommandProcessor")
|
||||||
<< "Removed downtime ID " << arguments[0];
|
<< "Removed downtime ID " << arguments[0];
|
||||||
@ -1112,7 +1112,7 @@ void ExternalCommandProcessor::DelHostDowntime(double, const std::vector<String>
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Downtime::RemoveDowntime(rid, false, true);
|
Downtime::RemoveDowntime(rid, false, DowntimeRemovedByUser);
|
||||||
|
|
||||||
Log(LogNotice, "ExternalCommandProcessor")
|
Log(LogNotice, "ExternalCommandProcessor")
|
||||||
<< "Removed downtime ID " << arguments[0];
|
<< "Removed downtime ID " << arguments[0];
|
||||||
@ -1147,7 +1147,7 @@ void ExternalCommandProcessor::DelDowntimeByHostName(double, const std::vector<S
|
|||||||
for (const Downtime::Ptr& downtime : host->GetDowntimes()) {
|
for (const Downtime::Ptr& downtime : host->GetDowntimes()) {
|
||||||
try {
|
try {
|
||||||
String downtimeName = downtime->GetName();
|
String downtimeName = downtime->GetName();
|
||||||
Downtime::RemoveDowntime(downtimeName, false, true);
|
Downtime::RemoveDowntime(downtimeName, false, DowntimeRemovedByUser);
|
||||||
|
|
||||||
Log(LogNotice, "ExternalCommandProcessor")
|
Log(LogNotice, "ExternalCommandProcessor")
|
||||||
<< "Removed downtime '" << downtimeName << "'.";
|
<< "Removed downtime '" << downtimeName << "'.";
|
||||||
@ -1169,7 +1169,7 @@ void ExternalCommandProcessor::DelDowntimeByHostName(double, const std::vector<S
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
String downtimeName = downtime->GetName();
|
String downtimeName = downtime->GetName();
|
||||||
Downtime::RemoveDowntime(downtimeName, false, true);
|
Downtime::RemoveDowntime(downtimeName, false, DowntimeRemovedByUser);
|
||||||
|
|
||||||
Log(LogNotice, "ExternalCommandProcessor")
|
Log(LogNotice, "ExternalCommandProcessor")
|
||||||
<< "Removed downtime '" << downtimeName << "'.";
|
<< "Removed downtime '" << downtimeName << "'.";
|
||||||
|
@ -323,7 +323,7 @@ void ScheduledDowntime::RemoveObsoleteDowntimes()
|
|||||||
auto configOwnerHash (downtime->GetConfigOwnerHash());
|
auto configOwnerHash (downtime->GetConfigOwnerHash());
|
||||||
|
|
||||||
if (!configOwnerHash.IsEmpty() && configOwnerHash != downtimeOptionsHash)
|
if (!configOwnerHash.IsEmpty() && configOwnerHash != downtimeOptionsHash)
|
||||||
Downtime::RemoveDowntime(downtime->GetName(), false, true);
|
Downtime::RemoveDowntime(downtime->GetName(), false, DowntimeRemovedByConfigOwner);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user