mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-27 07:34:15 +02:00
parent
ec1a7bbfcb
commit
e2292ce5f7
@ -78,7 +78,7 @@ void StatusDataWriter::DumpComments(std::ostream& fp, const Service::Ptr& owner,
|
|||||||
String id;
|
String id;
|
||||||
Comment::Ptr comment;
|
Comment::Ptr comment;
|
||||||
BOOST_FOREACH(boost::tie(id, comment), comments) {
|
BOOST_FOREACH(boost::tie(id, comment), comments) {
|
||||||
if (Service::IsCommentExpired(comment))
|
if (comment->IsExpired())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (type == CompatTypeHost)
|
if (type == CompatTypeHost)
|
||||||
@ -177,7 +177,7 @@ void StatusDataWriter::DumpDowntimes(std::ostream& fp, const Service::Ptr& owner
|
|||||||
String id;
|
String id;
|
||||||
Downtime::Ptr downtime;
|
Downtime::Ptr downtime;
|
||||||
BOOST_FOREACH(boost::tie(id, downtime), downtimes) {
|
BOOST_FOREACH(boost::tie(id, downtime), downtimes) {
|
||||||
if (Service::IsDowntimeExpired(downtime))
|
if (downtime->IsExpired())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (type == CompatTypeHost)
|
if (type == CompatTypeHost)
|
||||||
@ -199,7 +199,7 @@ void StatusDataWriter::DumpDowntimes(std::ostream& fp, const Service::Ptr& owner
|
|||||||
<< "\t" << "triggered_by=" << triggeredByLegacy << "\n"
|
<< "\t" << "triggered_by=" << triggeredByLegacy << "\n"
|
||||||
<< "\t" << "fixed=" << static_cast<long>(downtime->GetFixed()) << "\n"
|
<< "\t" << "fixed=" << static_cast<long>(downtime->GetFixed()) << "\n"
|
||||||
<< "\t" << "duration=" << static_cast<long>(downtime->GetDuration()) << "\n"
|
<< "\t" << "duration=" << static_cast<long>(downtime->GetDuration()) << "\n"
|
||||||
<< "\t" << "is_in_effect=" << (Service::IsDowntimeActive(downtime) ? 1 : 0) << "\n"
|
<< "\t" << "is_in_effect=" << (downtime->IsActive() ? 1 : 0) << "\n"
|
||||||
<< "\t" << "author=" << downtime->GetAuthor() << "\n"
|
<< "\t" << "author=" << downtime->GetAuthor() << "\n"
|
||||||
<< "\t" << "comment=" << downtime->GetComment() << "\n"
|
<< "\t" << "comment=" << downtime->GetComment() << "\n"
|
||||||
<< "\t" << "trigger_time=" << downtime->GetTriggerTime() << "\n"
|
<< "\t" << "trigger_time=" << downtime->GetTriggerTime() << "\n"
|
||||||
|
@ -108,7 +108,7 @@ Value DowntimesTable::TypeAccessor(const Value& row)
|
|||||||
{
|
{
|
||||||
Downtime::Ptr downtime = Service::GetDowntimeByID(row);
|
Downtime::Ptr downtime = Service::GetDowntimeByID(row);
|
||||||
// 1 .. active, 0 .. pending
|
// 1 .. active, 0 .. pending
|
||||||
return (Service::IsDowntimeActive(downtime) ? 1 : 0);
|
return (downtime->IsActive() ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
Value DowntimesTable::IsServiceAccessor(const Value& row)
|
Value DowntimesTable::IsServiceAccessor(const Value& row)
|
||||||
|
@ -1425,7 +1425,7 @@ Value HostsTable::DowntimesAccessor(const Value& row)
|
|||||||
if (!downtime)
|
if (!downtime)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (Service::IsDowntimeExpired(downtime))
|
if (downtime->IsExpired())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
ids->Add(downtime->GetLegacyId());
|
ids->Add(downtime->GetLegacyId());
|
||||||
@ -1460,7 +1460,7 @@ Value HostsTable::DowntimesWithInfoAccessor(const Value& row)
|
|||||||
if (!downtime)
|
if (!downtime)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (Service::IsDowntimeExpired(downtime))
|
if (downtime->IsExpired())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Array::Ptr downtime_info = make_shared<Array>();
|
Array::Ptr downtime_info = make_shared<Array>();
|
||||||
@ -1499,7 +1499,7 @@ Value HostsTable::CommentsAccessor(const Value& row)
|
|||||||
if (!comment)
|
if (!comment)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (Service::IsCommentExpired(comment))
|
if (comment->IsExpired())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
ids->Add(comment->GetLegacyId());
|
ids->Add(comment->GetLegacyId());
|
||||||
@ -1534,7 +1534,7 @@ Value HostsTable::CommentsWithInfoAccessor(const Value& row)
|
|||||||
if (!comment)
|
if (!comment)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (Service::IsCommentExpired(comment))
|
if (comment->IsExpired())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Array::Ptr comment_info = make_shared<Array>();
|
Array::Ptr comment_info = make_shared<Array>();
|
||||||
@ -1573,7 +1573,7 @@ Value HostsTable::CommentsWithExtraInfoAccessor(const Value& row)
|
|||||||
if (!comment)
|
if (!comment)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (Service::IsCommentExpired(comment))
|
if (comment->IsExpired())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Array::Ptr comment_info = make_shared<Array>();
|
Array::Ptr comment_info = make_shared<Array>();
|
||||||
|
@ -1050,7 +1050,7 @@ Value ServicesTable::DowntimesAccessor(const Value& row)
|
|||||||
if (!downtime)
|
if (!downtime)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (Service::IsDowntimeExpired(downtime))
|
if (downtime->IsExpired())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
ids->Add(downtime->GetLegacyId());
|
ids->Add(downtime->GetLegacyId());
|
||||||
@ -1079,7 +1079,7 @@ Value ServicesTable::DowntimesWithInfoAccessor(const Value& row)
|
|||||||
if (!downtime)
|
if (!downtime)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (Service::IsDowntimeExpired(downtime))
|
if (downtime->IsExpired())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Array::Ptr downtime_info = make_shared<Array>();
|
Array::Ptr downtime_info = make_shared<Array>();
|
||||||
@ -1112,7 +1112,7 @@ Value ServicesTable::CommentsAccessor(const Value& row)
|
|||||||
if (!comment)
|
if (!comment)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (Service::IsCommentExpired(comment))
|
if (comment->IsExpired())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
ids->Add(comment->GetLegacyId());
|
ids->Add(comment->GetLegacyId());
|
||||||
@ -1141,7 +1141,7 @@ Value ServicesTable::CommentsWithInfoAccessor(const Value& row)
|
|||||||
if (!comment)
|
if (!comment)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (Service::IsCommentExpired(comment))
|
if (comment->IsExpired())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Array::Ptr comment_info = make_shared<Array>();
|
Array::Ptr comment_info = make_shared<Array>();
|
||||||
@ -1174,7 +1174,7 @@ Value ServicesTable::CommentsWithExtraInfoAccessor(const Value& row)
|
|||||||
if (!comment)
|
if (!comment)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (Service::IsCommentExpired(comment))
|
if (comment->IsExpired())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Array::Ptr comment_info = make_shared<Array>();
|
Array::Ptr comment_info = make_shared<Array>();
|
||||||
|
@ -18,8 +18,16 @@
|
|||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
#include "icinga/comment.h"
|
#include "icinga/comment.h"
|
||||||
|
#include "base/utility.h"
|
||||||
#include "base/dynamictype.h"
|
#include "base/dynamictype.h"
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
REGISTER_TYPE(Comment);
|
REGISTER_TYPE(Comment);
|
||||||
|
|
||||||
|
bool Comment::IsExpired(void) const
|
||||||
|
{
|
||||||
|
double expire_time = GetExpireTime();
|
||||||
|
|
||||||
|
return (expire_time != 0 && expire_time < Utility::GetTime());
|
||||||
|
}
|
||||||
|
@ -35,6 +35,8 @@ class I2_ICINGA_API Comment : public ObjectImpl<Comment>
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DECLARE_PTR_TYPEDEFS(Comment);
|
DECLARE_PTR_TYPEDEFS(Comment);
|
||||||
|
|
||||||
|
bool IsExpired(void) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,8 +18,42 @@
|
|||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
#include "icinga/downtime.h"
|
#include "icinga/downtime.h"
|
||||||
|
#include "base/utility.h"
|
||||||
#include "base/dynamictype.h"
|
#include "base/dynamictype.h"
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
REGISTER_TYPE(Downtime);
|
REGISTER_TYPE(Downtime);
|
||||||
|
|
||||||
|
bool Downtime::IsActive(void) const
|
||||||
|
{
|
||||||
|
double now = Utility::GetTime();
|
||||||
|
|
||||||
|
if (now < GetStartTime() ||
|
||||||
|
now > GetEndTime())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (GetFixed())
|
||||||
|
return true;
|
||||||
|
|
||||||
|
double triggerTime = GetTriggerTime();
|
||||||
|
|
||||||
|
if (triggerTime == 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return (triggerTime + GetDuration() < now);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Downtime::IsTriggered(void) const
|
||||||
|
{
|
||||||
|
double now = Utility::GetTime();
|
||||||
|
|
||||||
|
double triggerTime = GetTriggerTime();
|
||||||
|
|
||||||
|
return (triggerTime > 0 && triggerTime <= now);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Downtime::IsExpired(void) const
|
||||||
|
{
|
||||||
|
return (GetEndTime() < Utility::GetTime());
|
||||||
|
}
|
||||||
|
@ -35,6 +35,11 @@ class I2_ICINGA_API Downtime : public ObjectImpl<Downtime>
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DECLARE_PTR_TYPEDEFS(Downtime);
|
DECLARE_PTR_TYPEDEFS(Downtime);
|
||||||
|
|
||||||
|
bool IsActive(void) const;
|
||||||
|
bool IsTriggered(void) const;
|
||||||
|
bool IsExpired(void) const;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -163,13 +163,6 @@ Comment::Ptr Service::GetCommentByID(const String& id)
|
|||||||
return Comment::Ptr();
|
return Comment::Ptr();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Service::IsCommentExpired(const Comment::Ptr& comment)
|
|
||||||
{
|
|
||||||
double expire_time = comment->GetExpireTime();
|
|
||||||
|
|
||||||
return (expire_time != 0 && expire_time < Utility::GetTime());
|
|
||||||
}
|
|
||||||
|
|
||||||
void Service::AddCommentsToCache(void)
|
void Service::AddCommentsToCache(void)
|
||||||
{
|
{
|
||||||
Log(LogDebug, "icinga", "Updating Service comments cache.");
|
Log(LogDebug, "icinga", "Updating Service comments cache.");
|
||||||
@ -227,7 +220,7 @@ void Service::RemoveExpiredComments(void)
|
|||||||
String id;
|
String id;
|
||||||
Comment::Ptr comment;
|
Comment::Ptr comment;
|
||||||
BOOST_FOREACH(boost::tie(id, comment), comments) {
|
BOOST_FOREACH(boost::tie(id, comment), comments) {
|
||||||
if (IsCommentExpired(comment))
|
if (comment->IsExpired())
|
||||||
expiredComments.push_back(id);
|
expiredComments.push_back(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -163,26 +163,20 @@ void Service::TriggerDowntime(const String& id)
|
|||||||
if (!downtime)
|
if (!downtime)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (IsDowntimeActive(downtime) && IsDowntimeTriggered(downtime)) {
|
if (downtime->IsActive() && downtime->IsTriggered()) {
|
||||||
Log(LogDebug, "icinga", "Not triggering downtime with ID '" + Convert::ToString(downtime->GetLegacyId()) + "': already triggered.");
|
Log(LogDebug, "icinga", "Not triggering downtime with ID '" + Convert::ToString(downtime->GetLegacyId()) + "': already triggered.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsDowntimeExpired(downtime)) {
|
if (downtime->IsExpired()) {
|
||||||
Log(LogDebug, "icinga", "Not triggering downtime with ID '" + Convert::ToString(downtime->GetLegacyId()) + "': expired.");
|
Log(LogDebug, "icinga", "Not triggering downtime with ID '" + Convert::ToString(downtime->GetLegacyId()) + "': expired.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
double now = Utility::GetTime();
|
|
||||||
|
|
||||||
if (now < downtime->GetStartTime() ||
|
|
||||||
now > downtime->GetEndTime())
|
|
||||||
return;
|
|
||||||
|
|
||||||
Log(LogDebug, "icinga", "Triggering downtime with ID '" + Convert::ToString(downtime->GetLegacyId()) + "'.");
|
Log(LogDebug, "icinga", "Triggering downtime with ID '" + Convert::ToString(downtime->GetLegacyId()) + "'.");
|
||||||
|
|
||||||
if (downtime->GetTriggerTime() == 0)
|
if (downtime->GetTriggerTime() == 0)
|
||||||
downtime->SetTriggerTime(now);
|
downtime->SetTriggerTime(Utility::GetTime());
|
||||||
|
|
||||||
Dictionary::Ptr triggers = downtime->GetTriggers();
|
Dictionary::Ptr triggers = downtime->GetTriggers();
|
||||||
ObjectLock olock(triggers);
|
ObjectLock olock(triggers);
|
||||||
@ -227,39 +221,6 @@ Downtime::Ptr Service::GetDowntimeByID(const String& id)
|
|||||||
return Downtime::Ptr();
|
return Downtime::Ptr();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Service::IsDowntimeActive(const Downtime::Ptr& downtime)
|
|
||||||
{
|
|
||||||
double now = Utility::GetTime();
|
|
||||||
|
|
||||||
if (now < downtime->GetStartTime() ||
|
|
||||||
now > downtime->GetEndTime())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (downtime->GetFixed())
|
|
||||||
return true;
|
|
||||||
|
|
||||||
double triggerTime = downtime->GetTriggerTime();
|
|
||||||
|
|
||||||
if (triggerTime == 0)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return (triggerTime + downtime->GetDuration() < now);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Service::IsDowntimeTriggered(const Downtime::Ptr& downtime)
|
|
||||||
{
|
|
||||||
double now = Utility::GetTime();
|
|
||||||
|
|
||||||
double triggerTime = downtime->GetTriggerTime();
|
|
||||||
|
|
||||||
return (triggerTime > 0 && triggerTime <= now);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Service::IsDowntimeExpired(const Downtime::Ptr& downtime)
|
|
||||||
{
|
|
||||||
return (downtime->GetEndTime() < Utility::GetTime());
|
|
||||||
}
|
|
||||||
|
|
||||||
void Service::StartDowntimesExpiredTimer(void)
|
void Service::StartDowntimesExpiredTimer(void)
|
||||||
{
|
{
|
||||||
if (!l_DowntimesExpireTimer) {
|
if (!l_DowntimesExpireTimer) {
|
||||||
@ -305,7 +266,7 @@ void Service::RemoveExpiredDowntimes(void)
|
|||||||
String id;
|
String id;
|
||||||
Downtime::Ptr downtime;
|
Downtime::Ptr downtime;
|
||||||
BOOST_FOREACH(boost::tie(id, downtime), downtimes) {
|
BOOST_FOREACH(boost::tie(id, downtime), downtimes) {
|
||||||
if (IsDowntimeExpired(downtime))
|
if (downtime->IsExpired())
|
||||||
expiredDowntimes.push_back(id);
|
expiredDowntimes.push_back(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -330,7 +291,7 @@ bool Service::IsInDowntime(void) const
|
|||||||
|
|
||||||
Downtime::Ptr downtime;
|
Downtime::Ptr downtime;
|
||||||
BOOST_FOREACH(boost::tie(boost::tuples::ignore, downtime), downtimes) {
|
BOOST_FOREACH(boost::tie(boost::tuples::ignore, downtime), downtimes) {
|
||||||
if (Service::IsDowntimeActive(downtime))
|
if (downtime->IsActive())
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -346,7 +307,7 @@ int Service::GetDowntimeDepth(void) const
|
|||||||
|
|
||||||
Downtime::Ptr downtime;
|
Downtime::Ptr downtime;
|
||||||
BOOST_FOREACH(boost::tie(boost::tuples::ignore, downtime), downtimes) {
|
BOOST_FOREACH(boost::tie(boost::tuples::ignore, downtime), downtimes) {
|
||||||
if (Service::IsDowntimeActive(downtime))
|
if (downtime->IsActive())
|
||||||
downtime_depth++;
|
downtime_depth++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,10 +197,6 @@ public:
|
|||||||
static Service::Ptr GetOwnerByDowntimeID(const String& id);
|
static Service::Ptr GetOwnerByDowntimeID(const String& id);
|
||||||
static Downtime::Ptr GetDowntimeByID(const String& id);
|
static Downtime::Ptr GetDowntimeByID(const String& id);
|
||||||
|
|
||||||
static bool IsDowntimeActive(const Downtime::Ptr& downtime);
|
|
||||||
static bool IsDowntimeTriggered(const Downtime::Ptr& downtime);
|
|
||||||
static bool IsDowntimeExpired(const Downtime::Ptr& downtime);
|
|
||||||
|
|
||||||
void StartDowntimesExpiredTimer(void);
|
void StartDowntimesExpiredTimer(void);
|
||||||
|
|
||||||
bool IsInDowntime(void) const;
|
bool IsInDowntime(void) const;
|
||||||
@ -220,8 +216,6 @@ public:
|
|||||||
static Service::Ptr GetOwnerByCommentID(const String& id);
|
static Service::Ptr GetOwnerByCommentID(const String& id);
|
||||||
static Comment::Ptr GetCommentByID(const String& id);
|
static Comment::Ptr GetCommentByID(const String& id);
|
||||||
|
|
||||||
static bool IsCommentExpired(const Comment::Ptr& comment);
|
|
||||||
|
|
||||||
/* Notifications */
|
/* Notifications */
|
||||||
bool GetEnableNotifications(void) const;
|
bool GetEnableNotifications(void) const;
|
||||||
void SetEnableNotifications(bool enabled, const String& authority = String());
|
void SetEnableNotifications(bool enabled, const String& authority = String());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user