2014-04-03 15:36:13 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* Icinga 2 *
|
2016-01-12 08:29:59 +01:00
|
|
|
* Copyright (C) 2012-2016 Icinga Development Team (https://www.icinga.org/) *
|
2014-04-03 15:36:13 +02:00
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU General Public License *
|
|
|
|
* as published by the Free Software Foundation; either version 2 *
|
|
|
|
* of the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the Free Software Foundation *
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
|
|
|
******************************************************************************/
|
|
|
|
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "icinga/checkable.hpp"
|
2015-03-28 11:04:42 +01:00
|
|
|
#include "icinga/checkable.tcpp"
|
2015-04-20 14:16:19 +02:00
|
|
|
#include "icinga/host.hpp"
|
|
|
|
#include "icinga/service.hpp"
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "base/objectlock.hpp"
|
|
|
|
#include "base/utility.hpp"
|
2014-12-18 15:43:01 +01:00
|
|
|
#include "base/exception.hpp"
|
2014-04-03 15:36:13 +02:00
|
|
|
#include <boost/foreach.hpp>
|
|
|
|
#include <boost/bind/apply.hpp>
|
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
2016-08-08 14:14:45 +02:00
|
|
|
REGISTER_TYPE_WITH_PROTOTYPE(Checkable, Checkable::GetPrototype());
|
2016-08-10 12:28:41 +02:00
|
|
|
INITIALIZE_ONCE(&Checkable::StaticInitialize);
|
2014-04-03 15:36:13 +02:00
|
|
|
|
2015-08-04 14:47:44 +02:00
|
|
|
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;
|
2014-04-03 15:36:13 +02:00
|
|
|
|
2016-08-10 12:28:41 +02:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2014-04-03 15:36:13 +02:00
|
|
|
Checkable::Checkable(void)
|
|
|
|
: m_CheckRunning(false)
|
2015-03-02 09:58:29 +01:00
|
|
|
{
|
|
|
|
SetSchedulingOffset(Utility::Random());
|
|
|
|
}
|
2014-04-03 15:36:13 +02:00
|
|
|
|
2015-08-20 17:18:48 +02:00
|
|
|
void Checkable::Start(bool runtimeCreated)
|
2014-04-03 15:36:13 +02:00
|
|
|
{
|
|
|
|
double now = Utility::GetTime();
|
|
|
|
|
|
|
|
if (GetNextCheck() < now + 300)
|
|
|
|
UpdateNextCheck();
|
|
|
|
|
2015-08-20 17:18:48 +02:00
|
|
|
ObjectImpl<Checkable>::Start(runtimeCreated);
|
2014-04-03 15:36:13 +02:00
|
|
|
}
|
|
|
|
|
2014-05-01 23:53:08 +02:00
|
|
|
void Checkable::AddGroup(const String& name)
|
|
|
|
{
|
|
|
|
boost::mutex::scoped_lock lock(m_CheckableMutex);
|
|
|
|
|
2015-04-20 14:16:19 +02:00
|
|
|
Array::Ptr groups;
|
|
|
|
Host *host = dynamic_cast<Host *>(this);
|
|
|
|
|
|
|
|
if (host)
|
|
|
|
groups = host->GetGroups();
|
|
|
|
else
|
|
|
|
groups = static_cast<Service *>(this)->GetGroups();
|
2014-05-01 23:53:08 +02:00
|
|
|
|
2014-05-02 00:38:46 +02:00
|
|
|
if (groups && groups->Contains(name))
|
|
|
|
return;
|
|
|
|
|
2014-05-01 23:53:08 +02:00
|
|
|
if (!groups)
|
2014-11-08 21:17:16 +01:00
|
|
|
groups = new Array();
|
2014-05-01 23:53:08 +02:00
|
|
|
|
|
|
|
groups->Add(name);
|
|
|
|
}
|
|
|
|
|
2014-04-03 15:36:13 +02:00
|
|
|
AcknowledgementType Checkable::GetAcknowledgement(void)
|
|
|
|
{
|
|
|
|
AcknowledgementType avalue = static_cast<AcknowledgementType>(GetAcknowledgementRaw());
|
|
|
|
|
|
|
|
if (avalue != AcknowledgementNone) {
|
|
|
|
double expiry = GetAcknowledgementExpiry();
|
|
|
|
|
|
|
|
if (expiry != 0 && expiry < Utility::GetTime()) {
|
|
|
|
avalue = AcknowledgementNone;
|
|
|
|
ClearAcknowledgement();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return avalue;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Checkable::IsAcknowledged(void)
|
|
|
|
{
|
|
|
|
return GetAcknowledgement() != AcknowledgementNone;
|
|
|
|
}
|
|
|
|
|
2015-08-04 14:47:44 +02:00
|
|
|
void Checkable::AcknowledgeProblem(const String& author, const String& comment, AcknowledgementType type, bool notify, double expiry, const MessageOrigin::Ptr& origin)
|
2014-04-03 15:36:13 +02:00
|
|
|
{
|
2015-04-27 10:59:53 +02:00
|
|
|
SetAcknowledgementRaw(type);
|
|
|
|
SetAcknowledgementExpiry(expiry);
|
2014-04-03 15:36:13 +02:00
|
|
|
|
2016-06-07 12:44:12 +02:00
|
|
|
if (notify && !IsPaused())
|
|
|
|
OnNotificationsRequested(this, NotificationAcknowledgement, GetLastCheckResult(), author, comment, MessageOrigin::Ptr());
|
2014-04-03 15:36:13 +02:00
|
|
|
|
2015-02-07 21:39:19 +01:00
|
|
|
OnAcknowledgementSet(this, author, comment, type, notify, expiry, origin);
|
2014-04-03 15:36:13 +02:00
|
|
|
}
|
|
|
|
|
2015-08-04 14:47:44 +02:00
|
|
|
void Checkable::ClearAcknowledgement(const MessageOrigin::Ptr& origin)
|
2014-04-03 15:36:13 +02:00
|
|
|
{
|
|
|
|
SetAcknowledgementRaw(AcknowledgementNone);
|
|
|
|
SetAcknowledgementExpiry(0);
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
OnAcknowledgementCleared(this, origin);
|
2014-04-03 15:36:13 +02:00
|
|
|
}
|
|
|
|
|
2014-11-13 11:23:57 +01:00
|
|
|
Endpoint::Ptr Checkable::GetCommandEndpoint(void) const
|
|
|
|
{
|
|
|
|
return Endpoint::GetByName(GetCommandEndpointRaw());
|
|
|
|
}
|
2014-12-05 12:59:57 +01:00
|
|
|
|
2016-08-10 12:28:41 +02:00
|
|
|
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)
|
|
|
|
{
|
2016-08-10 17:14:10 +02:00
|
|
|
/* don't send notifications for flexible downtimes which never triggered */
|
|
|
|
if (!downtime->GetFixed() && !downtime->IsTriggered())
|
|
|
|
return;
|
|
|
|
|
2016-08-10 12:28:41 +02:00
|
|
|
Checkable::Ptr checkable = downtime->GetCheckable();
|
|
|
|
|
|
|
|
if (!checkable->IsPaused())
|
|
|
|
OnNotificationsRequested(checkable, NotificationDowntimeEnd, checkable->GetLastCheckResult(), downtime->GetAuthor(), downtime->GetComment(), MessageOrigin::Ptr());
|
|
|
|
}
|
|
|
|
|
2015-08-04 14:47:44 +02:00
|
|
|
void Checkable::ValidateCheckInterval(double value, const ValidationUtils& utils)
|
2014-12-05 12:59:57 +01:00
|
|
|
{
|
2015-08-04 14:47:44 +02:00
|
|
|
ObjectImpl<Checkable>::ValidateCheckInterval(value, utils);
|
2014-11-30 23:32:13 +01:00
|
|
|
|
|
|
|
if (value <= 0)
|
|
|
|
BOOST_THROW_EXCEPTION(ValidationError(this, boost::assign::list_of("check_interval"), "Interval must be greater than 0."));
|
2014-12-05 12:59:57 +01:00
|
|
|
}
|