]> granicus.if.org Git - icinga2/commitdiff
Improve logging for downtime/ack events (add, remove, expire) 7399/head
authorMichael Friedrich <michael.friedrich@icinga.com>
Tue, 6 Aug 2019 11:28:13 +0000 (13:28 +0200)
committerMichael Friedrich <michael.friedrich@icinga.com>
Tue, 6 Aug 2019 11:28:58 +0000 (13:28 +0200)
fixes #7374

lib/icinga/checkable.cpp
lib/icinga/downtime.cpp
lib/remote/configobjectutility.cpp

index c4265d05f266ecb766577e6da45bc24488d7f9c1..55bbfeb160f80c26ef56a1e22610993738310b5b 100644 (file)
@@ -130,6 +130,9 @@ void Checkable::AcknowledgeProblem(const String& author, const String& comment,
        if (notify && !IsPaused())
                OnNotificationsRequested(this, NotificationAcknowledgement, GetLastCheckResult(), author, comment, nullptr);
 
+       Log(LogInformation, "Checkable")
+               << "Acknowledgement set for checkable '" << GetName() << "'.";
+
        OnAcknowledgementSet(this, author, comment, type, notify, persistent, expiry, origin);
 }
 
@@ -138,6 +141,9 @@ void Checkable::ClearAcknowledgement(const MessageOrigin::Ptr& origin)
        SetAcknowledgementRaw(AcknowledgementNone);
        SetAcknowledgementExpiry(0);
 
+       Log(LogInformation, "Checkable")
+               << "Acknowledgement cleared for checkable '" << GetName() << "'.";
+
        OnAcknowledgementCleared(this, origin);
 }
 
index 856ac9b10555fb0b614bdb5f06f74781765ff7ae..f003bc746ac131b307bc596570aa2845c0e46a55 100644 (file)
@@ -298,10 +298,11 @@ String Downtime::AddDowntime(const Checkable::Ptr& checkable, const String& auth
        if (!downtime)
                BOOST_THROW_EXCEPTION(std::runtime_error("Could not create downtime object."));
 
-       Log(LogNotice, "Downtime")
+       Log(LogInformation, "Downtime")
                << "Added downtime '" << downtime->GetName()
                << "' between '" << Utility::FormatDateTime("%Y-%m-%d %H:%M:%S", startTime)
-               << "' and '" << Utility::FormatDateTime("%Y-%m-%d %H:%M:%S", endTime) << "'.";
+               << "' and '" << Utility::FormatDateTime("%Y-%m-%d %H:%M:%S", endTime) << "', author: '"
+               << author << "', " << (fixed ? "fixed" : "flexible with " + Convert::ToString(duration) + "s duration");
 
        return fullName;
 }
@@ -323,9 +324,6 @@ void Downtime::RemoveDowntime(const String& id, bool cancelled, bool expired, co
 
        downtime->SetWasCancelled(cancelled);
 
-       Log(LogNotice, "Downtime")
-               << "Removed downtime '" << downtime->GetName() << "' from object '" << downtime->GetCheckable()->GetName() << "'.";
-
        Array::Ptr errors = new Array();
 
        if (!ConfigObjectUtility::DeleteObject(downtime, false, errors, nullptr)) {
@@ -336,6 +334,21 @@ void Downtime::RemoveDowntime(const String& id, bool cancelled, bool expired, co
 
                BOOST_THROW_EXCEPTION(std::runtime_error("Could not remove downtime."));
        }
+
+       String reason;
+
+       if (expired) {
+               reason = "expired at " + Utility::FormatDateTime("%Y-%m-%d %H:%M:%S %z", downtime->GetEndTime());
+       } else if (cancelled) {
+               reason = "cancelled by user";
+       } else {
+               reason = "<unknown>";
+       }
+
+       Log(LogInformation, "Downtime")
+               << "Removed downtime '" << downtime->GetName() << "' from checkable '"
+               << downtime->GetCheckable()->GetName() << "' (Reason: " << reason << ").";
+
 }
 
 bool Downtime::CanBeTriggered()
@@ -359,8 +372,10 @@ void Downtime::TriggerDowntime()
        if (!CanBeTriggered())
                return;
 
-       Log(LogNotice, "Downtime")
-               << "Triggering downtime '" << GetName() << "'.";
+       Checkable::Ptr checkable = GetCheckable();
+
+       Log(LogInformation, "Downtime")
+               << "Triggering downtime '" << GetName() << "' for checkable '" << checkable->GetName() << "'.";
 
        if (GetTriggerTime() == 0)
                SetTriggerTime(Utility::GetTime());
index 6b83eb2cf714120a1a99e8beaf3bba62a8c4c8b3..f7c405e86f3231e016e2fb60098a78510ad5bc4d 100644 (file)
@@ -292,6 +292,9 @@ bool ConfigObjectUtility::DeleteObjectHelper(const ConfigObject::Ptr& object, bo
 
        Utility::Remove(path);
 
+       Log(LogInformation, "ConfigObjectUtility")
+               << "Deleted object '" << name << "' of type '" << type->GetName() << "'.";
+
        return true;
 }