Fix downtime notification events and missing author/comment

fixes #12333
fixes #11851
This commit is contained in:
Michael Friedrich 2016-08-10 12:28:41 +02:00
parent 54bbaf9f7d
commit 42818ab758
3 changed files with 51 additions and 4 deletions

View File

@ -291,7 +291,6 @@ void Checkable::ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrig
if (is_volatile && IsStateOK(old_state) && IsStateOK(new_state))
send_notification = false; /* Don't send notifications for volatile OK -> OK changes. */
bool send_downtime_notification = (GetLastInDowntime() != in_downtime);
SetLastInDowntime(in_downtime);
olock.Unlock();
@ -365,9 +364,6 @@ void Checkable::ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrig
(is_volatile && !(IsStateOK(old_state) && IsStateOK(new_state))))
ExecuteEventHandler();
if (send_downtime_notification && IsActive())
OnNotificationsRequested(this, in_downtime ? NotificationDowntimeStart : NotificationDowntimeEnd, cr, "", "", MessageOrigin::Ptr());
/* Flapping start/end notifications */
if (!was_flapping && is_flapping) {
if (!IsPaused())

View File

@ -30,10 +30,21 @@
using namespace icinga;
REGISTER_TYPE_WITH_PROTOTYPE(Checkable, Checkable::GetPrototype());
INITIALIZE_ONCE(&Checkable::StaticInitialize);
boost::signals2::signal<void (const Checkable::Ptr&, const String&, const String&, AcknowledgementType, bool, double, const MessageOrigin::Ptr&)> Checkable::OnAcknowledgementSet;
boost::signals2::signal<void (const Checkable::Ptr&, const MessageOrigin::Ptr&)> Checkable::OnAcknowledgementCleared;
void Checkable::StaticInitialize(void)
{
/* fixed downtime start */
Downtime::OnDowntimeAdded.connect(boost::bind(&Checkable::NotifyFixedDowntimeStart, _1));
/* flexible downtime start */
Downtime::OnDowntimeTriggered.connect(boost::bind(&Checkable::NotifyFlexibleDowntimeStart, _1));
/* fixed/flexible downtime end */
Downtime::OnDowntimeRemoved.connect(boost::bind(&Checkable::NotifyDowntimeEnd, _1));
}
Checkable::Checkable(void)
: m_CheckRunning(false)
{
@ -116,6 +127,38 @@ Endpoint::Ptr Checkable::GetCommandEndpoint(void) const
return Endpoint::GetByName(GetCommandEndpointRaw());
}
void Checkable::NotifyFixedDowntimeStart(const Downtime::Ptr& downtime)
{
if (!downtime->GetFixed())
return;
NotifyDowntimeInternal(downtime);
}
void Checkable::NotifyFlexibleDowntimeStart(const Downtime::Ptr& downtime)
{
if (downtime->GetFixed())
return;
NotifyDowntimeInternal(downtime);
}
void Checkable::NotifyDowntimeInternal(const Downtime::Ptr& downtime)
{
Checkable::Ptr checkable = downtime->GetCheckable();
if (!checkable->IsPaused())
OnNotificationsRequested(checkable, NotificationDowntimeStart, checkable->GetLastCheckResult(), downtime->GetAuthor(), downtime->GetComment(), MessageOrigin::Ptr());
}
void Checkable::NotifyDowntimeEnd(const Downtime::Ptr& downtime)
{
Checkable::Ptr checkable = downtime->GetCheckable();
if (!checkable->IsPaused())
OnNotificationsRequested(checkable, NotificationDowntimeEnd, checkable->GetLastCheckResult(), downtime->GetAuthor(), downtime->GetComment(), MessageOrigin::Ptr());
}
void Checkable::ValidateCheckInterval(double value, const ValidationUtils& utils)
{
ObjectImpl<Checkable>::ValidateCheckInterval(value, utils);

View File

@ -68,6 +68,8 @@ public:
DECLARE_OBJECT(Checkable);
DECLARE_OBJECTNAME(Checkable);
static void StaticInitialize(void);
Checkable(void);
std::set<Checkable::Ptr> GetParents(void) const;
@ -196,6 +198,12 @@ private:
std::set<Downtime::Ptr> m_Downtimes;
mutable boost::mutex m_DowntimeMutex;
static void NotifyFixedDowntimeStart(const Downtime::Ptr& downtime);
static void NotifyFlexibleDowntimeStart(const Downtime::Ptr& downtime);
static void NotifyDowntimeInternal(const Downtime::Ptr& downtime);
static void NotifyDowntimeEnd(const Downtime::Ptr& downtime);
/* Comments */
std::set<Comment::Ptr> m_Comments;
mutable boost::mutex m_CommentMutex;