String id;
Dictionary::Ptr comment;
BOOST_FOREACH(tie(id, comment), comments) {
+ if (CommentProcessor::IsCommentExpired(comment))
+ continue;
+
/* There's no way for us to dump comments that haven't been
* assigned a legacy ID yet. */
if (!comment->Contains("legacy_id"))
String id;
Dictionary::Ptr downtime;
BOOST_FOREACH(tie(id, downtime), downtimes) {
+ if (DowntimeProcessor::IsDowntimeExpired(downtime))
+ continue;
+
/* There's no way for us to dump downtimes that haven't been
* assigned a legacy ID yet. */
if (!downtime->Contains("legacy_id"))
map<int, String> CommentProcessor::m_LegacyCommentCache;
map<String, DynamicObject::WeakPtr> CommentProcessor::m_CommentCache;
bool CommentProcessor::m_CommentCacheValid;
+Timer::Ptr CommentProcessor::m_CommentExpireTimer;
int CommentProcessor::GetNextCommentID(void)
{
return Dictionary::Ptr();
}
+bool CommentProcessor::IsCommentExpired(const Dictionary::Ptr& comment)
+{
+ double expire_time = comment->Get("expire_time");
+
+ return (expire_time != 0 && expire_time < Utility::GetTime());
+}
+
void CommentProcessor::InvalidateCommentCache(void)
{
m_CommentCacheValid = false;
}
m_CommentCacheValid = true;
+
+ if (!m_CommentExpireTimer) {
+ m_CommentExpireTimer = boost::make_shared<Timer>();
+ m_CommentExpireTimer->SetInterval(300);
+ m_CommentExpireTimer->OnTimerExpired.connect(boost::bind(&CommentProcessor::CommentExpireTimerHandler));
+ m_CommentExpireTimer->Start();
+ }
+}
+
+void CommentProcessor::RemoveExpiredComments(const DynamicObject::Ptr& owner)
+{
+ Dictionary::Ptr comments = owner->Get("comments");
+
+ if (!comments)
+ return;
+
+ vector<String> expiredComments;
+
+ String id;
+ Dictionary::Ptr comment;
+ BOOST_FOREACH(tie(id, comment), comments) {
+ if (IsCommentExpired(comment))
+ expiredComments.push_back(id);
+ }
+
+ if (expiredComments.size() > 0) {
+ BOOST_FOREACH(id, expiredComments) {
+ comments->Remove(id);
+ }
+
+ owner->Touch("comments");
+ }
+}
+
+void CommentProcessor::CommentExpireTimerHandler(void)
+{
+ DynamicObject::Ptr object;
+ BOOST_FOREACH(tie(tuples::ignore, object), DynamicType::GetByName("Host")->GetObjects()) {
+ RemoveExpiredComments(object);
+ }
+
+ BOOST_FOREACH(tie(tuples::ignore, object), DynamicType::GetByName("Service")->GetObjects()) {
+ RemoveExpiredComments(object);
+ }
}
static DynamicObject::Ptr GetOwnerByCommentID(const String& id);
static Dictionary::Ptr GetCommentByID(const String& id);
+ static bool IsCommentExpired(const Dictionary::Ptr& comment);
+
static void InvalidateCommentCache(void);
static void ValidateCommentCache(void);
static map<int, String> m_LegacyCommentCache;
static map<String, DynamicObject::WeakPtr> m_CommentCache;
static bool m_CommentCacheValid;
+ static Timer::Ptr m_CommentExpireTimer;
CommentProcessor(void);
+ static void CommentExpireTimerHandler(void);
+
static void AddCommentsToCache(const DynamicObject::Ptr& owner);
+ static void RemoveExpiredComments(const DynamicObject::Ptr& owner);
};
}
map<int, String> DowntimeProcessor::m_LegacyDowntimeCache;
map<String, DynamicObject::WeakPtr> DowntimeProcessor::m_DowntimeCache;
bool DowntimeProcessor::m_DowntimeCacheValid;
+Timer::Ptr DowntimeProcessor::m_DowntimeExpireTimer;
int DowntimeProcessor::GetNextDowntimeID(void)
{
{
double now = Utility::GetTime();
- if (now < static_cast<double>(downtime->Get("start_time")) ||
- now > static_cast<double>(downtime->Get("end_time")))
+ if (now < downtime->Get("start_time") ||
+ now > downtime->Get("end_time"))
return false;
if (static_cast<bool>(downtime->Get("fixed")))
return true;
- double triggerTime = static_cast<double>(downtime->Get("trigger_time"));
+ double triggerTime = downtime->Get("trigger_time");
if (triggerTime == 0)
return false;
- return (triggerTime + static_cast<double>(downtime->Get("duration")) < now);
+ return (triggerTime + downtime->Get("duration") < now);
+}
+
+bool DowntimeProcessor::IsDowntimeExpired(const Dictionary::Ptr& downtime)
+{
+ return (downtime->Get("end_time") < Utility::GetTime());
}
void DowntimeProcessor::InvalidateDowntimeCache(void)
String id;
Dictionary::Ptr downtime;
BOOST_FOREACH(tie(id, downtime), downtimes) {
+ double end_time = downtime->Get("end_time");
+
int legacy_id;
if (!downtime->Contains("legacy_id")) {
}
m_DowntimeCacheValid = true;
+
+ if (!m_DowntimeExpireTimer) {
+ m_DowntimeExpireTimer = boost::make_shared<Timer>();
+ m_DowntimeExpireTimer->SetInterval(300);
+ m_DowntimeExpireTimer->OnTimerExpired.connect(boost::bind(&DowntimeProcessor::DowntimeExpireTimerHandler));
+ m_DowntimeExpireTimer->Start();
+ }
+}
+
+void DowntimeProcessor::RemoveExpiredDowntimes(const DynamicObject::Ptr& owner)
+{
+ Dictionary::Ptr downtimes = owner->Get("downtimes");
+
+ if (!downtimes)
+ return;
+
+ vector<String> expiredDowntimes;
+
+ String id;
+ Dictionary::Ptr downtime;
+ BOOST_FOREACH(tie(id, downtime), downtimes) {
+ if (IsDowntimeExpired(downtime))
+ expiredDowntimes.push_back(id);
+ }
+
+ if (expiredDowntimes.size() > 0) {
+ BOOST_FOREACH(id, expiredDowntimes) {
+ downtimes->Remove(id);
+ }
+
+ owner->Touch("downtimes");
+ }
+}
+
+void DowntimeProcessor::DowntimeExpireTimerHandler(void)
+{
+ DynamicObject::Ptr object;
+ BOOST_FOREACH(tie(tuples::ignore, object), DynamicType::GetByName("Host")->GetObjects()) {
+ RemoveExpiredDowntimes(object);
+ }
+
+ BOOST_FOREACH(tie(tuples::ignore, object), DynamicType::GetByName("Service")->GetObjects()) {
+ RemoveExpiredDowntimes(object);
+ }
}
static Dictionary::Ptr GetDowntimeByID(const String& id);
static bool IsDowntimeActive(const Dictionary::Ptr& downtime);
+ static bool IsDowntimeExpired(const Dictionary::Ptr& downtime);
static void InvalidateDowntimeCache(void);
static void ValidateDowntimeCache(void);
static map<int, String> m_LegacyDowntimeCache;
static map<String, DynamicObject::WeakPtr> m_DowntimeCache;
static bool m_DowntimeCacheValid;
+ static Timer::Ptr m_DowntimeExpireTimer;
DowntimeProcessor(void);
+ static void DowntimeExpireTimerHandler(void);
+
static void AddDowntimesToCache(const DynamicObject::Ptr& owner);
+ static void RemoveExpiredDowntimes(const DynamicObject::Ptr& owner);
};
}