2019-02-25 08:48:22 -05:00
|
|
|
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
|
2013-01-29 08:50:51 -05:00
|
|
|
|
2014-05-25 10:23:35 -04:00
|
|
|
#include "icinga/service.hpp"
|
2015-08-15 14:28:05 -04:00
|
|
|
#include "base/configtype.hpp"
|
2014-05-25 10:23:35 -04:00
|
|
|
#include "base/objectlock.hpp"
|
2014-10-19 08:21:12 -04:00
|
|
|
#include "base/logger.hpp"
|
2014-05-25 10:23:35 -04:00
|
|
|
#include "base/utility.hpp"
|
|
|
|
|
#include "base/convert.hpp"
|
2013-01-29 08:50:51 -05:00
|
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
|
2021-12-08 05:49:42 -05:00
|
|
|
void Checkable::TriggerDowntimes(double triggerTime)
|
2013-01-31 07:57:14 -05:00
|
|
|
{
|
2016-08-25 00:19:44 -04:00
|
|
|
for (const Downtime::Ptr& downtime : GetDowntimes()) {
|
2021-12-08 05:49:42 -05:00
|
|
|
downtime->TriggerDowntime(triggerTime);
|
2013-01-30 08:28:13 -05:00
|
|
|
}
|
2013-01-29 08:50:51 -05:00
|
|
|
}
|
2013-02-09 11:27:32 -05:00
|
|
|
|
2018-01-03 22:25:35 -05:00
|
|
|
bool Checkable::IsInDowntime() const
|
2013-02-09 11:27:32 -05:00
|
|
|
{
|
2016-08-25 00:19:44 -04:00
|
|
|
for (const Downtime::Ptr& downtime : GetDowntimes()) {
|
2016-05-02 09:32:46 -04:00
|
|
|
if (downtime->IsInEffect())
|
2013-02-09 11:27:32 -05:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2013-07-05 03:35:49 -04:00
|
|
|
|
2018-01-03 22:25:35 -05:00
|
|
|
int Checkable::GetDowntimeDepth() const
|
2013-07-05 03:35:49 -04:00
|
|
|
{
|
|
|
|
|
int downtime_depth = 0;
|
2013-11-30 11:42:50 -05:00
|
|
|
|
2016-08-25 00:19:44 -04:00
|
|
|
for (const Downtime::Ptr& downtime : GetDowntimes()) {
|
2016-05-02 09:32:46 -04:00
|
|
|
if (downtime->IsInEffect())
|
2013-07-05 03:35:49 -04:00
|
|
|
downtime_depth++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return downtime_depth;
|
|
|
|
|
}
|
2013-11-13 08:56:31 -05:00
|
|
|
|
2018-01-03 22:25:35 -05:00
|
|
|
std::set<Downtime::Ptr> Checkable::GetDowntimes() const
|
2015-08-20 11:18:48 -04:00
|
|
|
{
|
2021-02-02 04:16:04 -05:00
|
|
|
std::unique_lock<std::mutex> lock(m_DowntimeMutex);
|
2015-08-20 11:18:48 -04:00
|
|
|
return m_Downtimes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Checkable::RegisterDowntime(const Downtime::Ptr& downtime)
|
|
|
|
|
{
|
2021-02-02 04:16:04 -05:00
|
|
|
std::unique_lock<std::mutex> lock(m_DowntimeMutex);
|
2015-08-20 11:18:48 -04:00
|
|
|
m_Downtimes.insert(downtime);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Checkable::UnregisterDowntime(const Downtime::Ptr& downtime)
|
|
|
|
|
{
|
2021-02-02 04:16:04 -05:00
|
|
|
std::unique_lock<std::mutex> lock(m_DowntimeMutex);
|
2015-08-20 11:18:48 -04:00
|
|
|
m_Downtimes.erase(downtime);
|
|
|
|
|
}
|