Service::OnEnablePassiveChecksChanged.connect(bind(&ClusterComponent::EnablePassiveChecksChangedHandler, this, _1, _2, _3));
Service::OnCommentAdded.connect(bind(&ClusterComponent::CommentAddedHandler, this, _1, _2, _3));
Service::OnCommentRemoved.connect(bind(&ClusterComponent::CommentRemovedHandler, this, _1, _2, _3));
+ Service::OnDowntimeAdded.connect(bind(&ClusterComponent::DowntimeAddedHandler, this, _1, _2, _3));
+ Service::OnDowntimeRemoved.connect(bind(&ClusterComponent::DowntimeRemovedHandler, this, _1, _2, _3));
Endpoint::OnMessageReceived.connect(bind(&ClusterComponent::MessageHandler, this, _1, _2));
}
}
}
+void ClusterComponent::DowntimeAddedHandler(const Service::Ptr& service, const Dictionary::Ptr& downtime, const String& authority)
+{
+ if (!authority.IsEmpty() && authority != GetIdentity())
+ return;
+
+ Dictionary::Ptr params = boost::make_shared<Dictionary>();
+ params->Set("service", service->GetName());
+ params->Set("downtime", downtime);
+
+ Dictionary::Ptr message = boost::make_shared<Dictionary>();
+ message->Set("jsonrpc", "2.0");
+ message->Set("method", "cluster::AddDowntime");
+ message->Set("params", params);
+
+ BOOST_FOREACH(const Endpoint::Ptr& endpoint, DynamicType::GetObjects<Endpoint>()) {
+ endpoint->SendMessage(message);
+ }
+}
+
+void ClusterComponent::DowntimeRemovedHandler(const Service::Ptr& service, const Dictionary::Ptr& downtime, const String& authority)
+{
+ if (!authority.IsEmpty() && authority != GetIdentity())
+ return;
+
+ Dictionary::Ptr params = boost::make_shared<Dictionary>();
+ params->Set("service", service->GetName());
+ params->Set("id", downtime->Get("id"));
+
+ Dictionary::Ptr message = boost::make_shared<Dictionary>();
+ message->Set("jsonrpc", "2.0");
+ message->Set("method", "cluster::RemoveDowntime");
+ message->Set("params", params);
+
+ BOOST_FOREACH(const Endpoint::Ptr& endpoint, DynamicType::GetObjects<Endpoint>()) {
+ endpoint->SendMessage(message);
+ }
+}
+
void ClusterComponent::MessageHandler(const Endpoint::Ptr& sender, const Dictionary::Ptr& message)
{
BOOST_FOREACH(const Endpoint::Ptr& endpoint, DynamicType::GetObjects<Endpoint>()) {
String id = params->Get("id");
service->RemoveComment(id, sender->GetName());
+ } else if (message->Get("method") == "cluster::AddDowntime") {
+ String svc = params->Get("service");
+
+ Service::Ptr service = Service::GetByName(svc);
+
+ if (!service)
+ return;
+
+ Dictionary::Ptr downtime = params->Get("downtime");
+
+ service->AddDowntime(downtime->Get("comment_id"),
+ downtime->Get("start_time"), downtime->Get("end_time"),
+ downtime->Get("fixed"), downtime->Get("triggered_by"),
+ downtime->Get("duration"), downtime->Get("id"), sender->GetName());
+ } else if (message->Get("method") == "cluster::RemoveDowntime") {
+ String svc = params->Get("service");
+
+ Service::Ptr service = Service::GetByName(svc);
+
+ if (!service)
+ return;
+
+ String id = params->Get("id");
+
+ service->RemoveDowntime(id, sender->GetName());
}
}
void EnablePassiveChecksChangedHandler(const Service::Ptr& service, bool enabled, const String& authority);
void CommentAddedHandler(const Service::Ptr& service, const Dictionary::Ptr& comment, const String& authority);
void CommentRemovedHandler(const Service::Ptr& service, const Dictionary::Ptr& comment, const String& authority);
+ void DowntimeAddedHandler(const Service::Ptr& service, const Dictionary::Ptr& downtime, const String& authority);
+ void DowntimeRemovedHandler(const Service::Ptr& service, const Dictionary::Ptr& downtime, const String& authority);
void MessageHandler(const Endpoint::Ptr& sender, const Dictionary::Ptr& message);
};
void CompatLog::Start(void)
{
Service::OnNewCheckResult.connect(bind(&CompatLog::CheckResultHandler, this, _1, _2));
- Service::OnDowntimeChanged.connect(bind(&CompatLog::DowntimeHandler, this, _1, _2));
+// Service::OnDowntimeTriggered.connect(bind(&CompatLog::DowntimeHandler, this, _1));
Service::OnNotificationSentChanged.connect(bind(&CompatLog::NotificationSentHandler, this, _1, _2, _3, _4, _5, _6));
Service::OnFlappingChanged.connect(bind(&CompatLog::FlappingHandler, this, _1, _2));
}
}
-/**
- * @threadsafety Always.
- */
-void CompatLog::DowntimeHandler(const Service::Ptr& service, DowntimeState downtime_state)
-{
- Host::Ptr host = service->GetHost();
-
- if (!host)
- return;
-
- String downtime_state_str;
- String downtime_output;
-
- switch (downtime_state) {
- case DowntimeStarted:
- downtime_output = "Service has entered a period of scheduled downtime.";
- downtime_state_str = "STARTED";
- break;
- case DowntimeStopped:
- downtime_output = "Service has exited from a period of scheduled downtime.";
- downtime_state_str = "STOPPED";
- break;
- case DowntimeCancelled:
- downtime_output = "Scheduled downtime for service has been cancelled.";
- downtime_state_str = "CANCELLED";
- break;
- default:
- Log(LogCritical, "compat", "Unknown downtime state: " + Convert::ToString(downtime_state));
- return;
- }
-
- std::ostringstream msgbuf;
- msgbuf << "SERVICE DOWNTIME ALERT: "
- << host->GetName() << ";"
- << service->GetShortName() << ";"
- << downtime_state_str << "; "
- << downtime_output
- << "";
-
- {
- ObjectLock oLock(this);
- WriteLine(msgbuf.str());
- }
-
- if (service == host->GetHostCheckService()) {
- std::ostringstream msgbuf;
- msgbuf << "HOST DOWNTIME ALERT: "
- << host->GetName() << ";"
- << downtime_state_str << "; "
- << downtime_output
- << "";
-
- {
- ObjectLock oLock(this);
- WriteLine(msgbuf.str());
- }
- }
-
- {
- ObjectLock oLock(this);
- Flush();
- }
-}
+///**
+// * @threadsafety Always.
+// */
+//void CompatLog::DowntimeHandler(const Service::Ptr& service)
+//{
+// Host::Ptr host = service->GetHost();
+//
+// if (!host)
+// return;
+//
+// String downtime_state_str;
+// String downtime_output;
+//
+// switch (downtime_state) {
+// case DowntimeStarted:
+// downtime_output = "Service has entered a period of scheduled downtime.";
+// downtime_state_str = "STARTED";
+// break;
+// case DowntimeStopped:
+// downtime_output = "Service has exited from a period of scheduled downtime.";
+// downtime_state_str = "STOPPED";
+// break;
+// case DowntimeCancelled:
+// downtime_output = "Scheduled downtime for service has been cancelled.";
+// downtime_state_str = "CANCELLED";
+// break;
+// default:
+// Log(LogCritical, "compat", "Unknown downtime state: " + Convert::ToString(downtime_state));
+// return;
+// }
+//
+// std::ostringstream msgbuf;
+// msgbuf << "SERVICE DOWNTIME ALERT: "
+// << host->GetName() << ";"
+// << service->GetShortName() << ";"
+// << downtime_state_str << "; "
+// << downtime_output
+// << "";
+//
+// {
+// ObjectLock oLock(this);
+// WriteLine(msgbuf.str());
+// }
+//
+// if (service == host->GetHostCheckService()) {
+// std::ostringstream msgbuf;
+// msgbuf << "HOST DOWNTIME ALERT: "
+// << host->GetName() << ";"
+// << downtime_state_str << "; "
+// << downtime_output
+// << "";
+//
+// {
+// ObjectLock oLock(this);
+// WriteLine(msgbuf.str());
+// }
+// }
+//
+// {
+// ObjectLock oLock(this);
+// Flush();
+// }
+//}
/**
* @threadsafety Always.
triggeredBy = Service::GetDowntimeIDFromLegacyID(triggeredByLegacy);
Log(LogInformation, "icinga", "Creating downtime for service " + service->GetName());
- (void) service->AddDowntime(arguments[7], arguments[8],
+ String comment_id = service->AddComment(CommentDowntime, arguments[7], arguments[8], Convert::ToDouble(arguments[3]));
+ (void) service->AddDowntime(comment_id,
Convert::ToDouble(arguments[2]), Convert::ToDouble(arguments[3]),
Convert::ToBool(arguments[4]), triggeredBy, Convert::ToDouble(arguments[6]));
}
Log(LogInformation, "icinga", "Creating downtime for host " + host->GetName());
Service::Ptr service = host->GetHostCheckService();
if (service) {
- (void) service->AddDowntime(arguments[6], arguments[7],
+ String comment_id = service->AddComment(CommentDowntime, arguments[6], arguments[7], Convert::ToDouble(arguments[2]));
+ (void) service->AddDowntime(comment_id,
Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
Convert::ToBool(arguments[3]), triggeredBy, Convert::ToDouble(arguments[5]));
}
BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
Log(LogInformation, "icinga", "Creating downtime for service " + service->GetName());
- (void) service->AddDowntime(arguments[6], arguments[7],
+ String comment_id = service->AddComment(CommentDowntime, arguments[6], arguments[7], Convert::ToDouble(arguments[2]));
+ (void) service->AddDowntime(comment_id,
Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
Convert::ToBool(arguments[3]), triggeredBy, Convert::ToDouble(arguments[5]));
}
Log(LogInformation, "icinga", "Creating downtime for host " + host->GetName());
Service::Ptr service = host->GetHostCheckService();
if (service) {
- (void) service->AddDowntime(arguments[6], arguments[7],
+ String comment_id = service->AddComment(CommentDowntime, arguments[6], arguments[7], Convert::ToDouble(arguments[2]));
+ (void) service->AddDowntime(comment_id,
Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
Convert::ToBool(arguments[3]), triggeredBy, Convert::ToDouble(arguments[5]));
}
BOOST_FOREACH(const Service::Ptr& service, services) {
Log(LogInformation, "icinga", "Creating downtime for service " + service->GetName());
- (void) service->AddDowntime(arguments[6], arguments[7],
+ String comment_id = service->AddComment(CommentDowntime, arguments[6], arguments[7], Convert::ToDouble(arguments[2]));
+ (void) service->AddDowntime(comment_id,
Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
Convert::ToBool(arguments[3]), triggeredBy, Convert::ToDouble(arguments[5]));
}
BOOST_FOREACH(const Service::Ptr& service, services) {
Log(LogInformation, "icinga", "Creating downtime for service " + service->GetName());
- (void) service->AddDowntime(arguments[6], arguments[7],
+ String comment_id = service->AddComment(CommentDowntime, arguments[6], arguments[7], Convert::ToDouble(arguments[2]));
+ (void) service->AddDowntime(comment_id,
Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
Convert::ToBool(arguments[3]), triggeredBy, Convert::ToDouble(arguments[5]));
}
BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) {
Log(LogInformation, "icinga", "Creating downtime for service " + service->GetName());
- (void) service->AddDowntime(arguments[6], arguments[7],
+ String comment_id = service->AddComment(CommentDowntime, arguments[6], arguments[7], Convert::ToDouble(arguments[2]));
+ (void) service->AddDowntime(comment_id,
Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
Convert::ToBool(arguments[3]), triggeredBy, Convert::ToDouble(arguments[5]));
}
static std::map<String, Service::WeakPtr> l_DowntimesCache;
static Timer::Ptr l_DowntimesExpireTimer;
-boost::signals2::signal<void (const Service::Ptr&, DowntimeState)> Service::OnDowntimeChanged;
-boost::signals2::signal<void (const Service::Ptr&, const String&, DowntimeChangedType)> Service::OnDowntimesChanged;
+boost::signals2::signal<void (const Service::Ptr&, const Dictionary::Ptr&, const String&)> Service::OnDowntimeAdded;
+boost::signals2::signal<void (const Service::Ptr&, const Dictionary::Ptr&, const String&)> Service::OnDowntimeRemoved;
+boost::signals2::signal<void (const Service::Ptr&, const Dictionary::Ptr&)> Service::OnDowntimeTriggered;
int Service::GetNextDowntimeID(void)
{
return m_Downtimes;
}
-String Service::AddDowntime(const String& author, const String& comment,
+String Service::AddDowntime(const String& comment_id,
double startTime, double endTime, bool fixed,
- const String& triggeredBy, double duration)
+ const String& triggeredBy, double duration, const String& id, const String& authority)
{
+ String uid;
+
+ if (id.IsEmpty())
+ uid = Utility::NewUniqueID();
+ else
+ uid = id;
+
Dictionary::Ptr downtime = boost::make_shared<Dictionary>();
+ downtime->Set("id", uid);
downtime->Set("entry_time", Utility::GetTime());
- downtime->Set("author", author);
- downtime->Set("comment", comment);
+ downtime->Set("comment_id", comment_id);
downtime->Set("start_time", startTime);
downtime->Set("end_time", endTime);
downtime->Set("fixed", fixed);
m_Downtimes = downtimes;
}
- String id = Utility::NewUniqueID();
- downtimes->Set(id, downtime);
-
- (void) AddComment(CommentDowntime, author, comment, endTime);
+ downtimes->Set(uid, downtime);
{
boost::mutex::scoped_lock lock(l_DowntimeMutex);
- l_LegacyDowntimesCache[legacy_id] = id;
- l_DowntimesCache[id] = GetSelf();
+ l_LegacyDowntimesCache[legacy_id] = uid;
+ l_DowntimesCache[uid] = GetSelf();
}
- OnDowntimesChanged(GetSelf(), id, DowntimeChangedAdded);
+ OnDowntimeAdded(GetSelf(), downtime, authority);
- return id;
+ return uid;
}
-void Service::RemoveDowntime(const String& id)
+void Service::RemoveDowntime(const String& id, const String& authority)
{
Service::Ptr owner = GetOwnerByDowntimeID(id);
if (!downtimes)
return;
- {
- ObjectLock olock(owner);
+ ObjectLock olock(owner);
- Dictionary::Ptr downtime = downtimes->Get(id);
+ Dictionary::Ptr downtime = downtimes->Get(id);
- int legacy_id = downtime->Get("legacy_id");
+ String comment_id = downtime->Get("comment_id");
+
+ RemoveComment(comment_id);
- downtimes->Remove(id);
+ int legacy_id = downtime->Get("legacy_id");
- {
- boost::mutex::scoped_lock lock(l_DowntimeMutex);
- l_LegacyDowntimesCache.erase(legacy_id);
- l_DowntimesCache.erase(id);
- }
- }
+ downtimes->Remove(id);
- OnDowntimeChanged(owner, DowntimeCancelled);
+ {
+ boost::mutex::scoped_lock lock(l_DowntimeMutex);
+ l_LegacyDowntimesCache.erase(legacy_id);
+ l_DowntimesCache.erase(id);
+ }
- OnDowntimesChanged(owner, id, DowntimeChangedDeleted);
+ OnDowntimeRemoved(owner, downtime, authority);
}
void Service::TriggerDowntimes(void)
TriggerDowntime(tid);
}
- OnDowntimeChanged(owner, DowntimeStarted);
- OnDowntimesChanged(owner, Empty, DowntimeChangedUpdated);
+ OnDowntimeTriggered(owner, downtime);
}
String Service::GetDowntimeIDFromLegacyID(int id)
static boost::signals2::signal<void (const Service::Ptr&, const Dictionary::Ptr&, const String&)> OnNewCheckResult;
static boost::signals2::signal<void (const Service::Ptr&, NotificationType, const Dictionary::Ptr&, const String&, const String&)> OnNotificationsRequested;
static boost::signals2::signal<void (const Service::Ptr&, const User::Ptr&, const NotificationType&, const Dictionary::Ptr&, const String&, const String&)> OnNotificationSentChanged;
- static boost::signals2::signal<void (const Service::Ptr&, DowntimeState)> OnDowntimeChanged;
static boost::signals2::signal<void (const Service::Ptr&, FlappingState)> OnFlappingChanged;
static boost::signals2::signal<void (const Service::Ptr&, const Dictionary::Ptr&, const String&)> OnCommentAdded;
static boost::signals2::signal<void (const Service::Ptr&, const Dictionary::Ptr&, const String&)> OnCommentRemoved;
- static boost::signals2::signal<void (const Service::Ptr&, const String&, DowntimeChangedType)> OnDowntimesChanged;
+ static boost::signals2::signal<void (const Service::Ptr&, const Dictionary::Ptr&, const String&)> OnDowntimeAdded;
+ static boost::signals2::signal<void (const Service::Ptr&, const Dictionary::Ptr&, const String&)> OnDowntimeRemoved;
+ static boost::signals2::signal<void (const Service::Ptr&, const Dictionary::Ptr&)> OnDowntimeTriggered;
virtual bool ResolveMacro(const String& macro, const Dictionary::Ptr& cr, String *result) const;
Dictionary::Ptr GetDowntimes(void) const;
int GetDowntimeDepth(void) const;
- String AddDowntime(const String& author, const String& comment,
+ String AddDowntime(const String& comment_id,
double startTime, double endTime, bool fixed,
- const String& triggeredBy, double duration);
+ const String& triggeredBy, double duration,
+ const String& id = String(), const String& authority = String());
- static void RemoveDowntime(const String& id);
+ static void RemoveDowntime(const String& id, const String& = String());
void TriggerDowntimes(void);
static void TriggerDowntime(const String& id);
{
Service::OnCommentAdded.connect(boost::bind(&ServiceDbObject::AddComment, _1, _2));
Service::OnCommentRemoved.connect(boost::bind(&ServiceDbObject::RemoveComment, _1, _2));
- Service::OnDowntimesChanged.connect(boost::bind(&ServiceDbObject::DowntimesChangedHandler, _1, _2, _3));
+ Service::OnDowntimeAdded.connect(boost::bind(&ServiceDbObject::AddDowntime, _1, _2));
+ Service::OnDowntimeRemoved.connect(boost::bind(&ServiceDbObject::RemoveDowntime, _1, _2));
+ Service::OnDowntimeTriggered.connect(boost::bind(&ServiceDbObject::TriggerDowntime, _1, _2));
}
ServiceDbObject::ServiceDbObject(const DbType::Ptr& type, const String& name1, const String& name2)
/* update comments and downtimes on config change */
AddComments(service);
- DowntimesChangedHandler(service, Empty, DowntimeChangedUpdated);
-
+ AddDowntimes(service);
+
/* service host config update */
Host::Ptr host = service->GetHost();
OnQuery(query1);
}
-void ServiceDbObject::RemoveComments(const Service::Ptr& service)
-{
- /* remove all comments associated for this host/service */
- Log(LogDebug, "ido", "remove comments for '" + service->GetName() + "'");
-
- Host::Ptr host = service->GetHost();
-
- if (!host)
- return;
-
- DbQuery query1;
- query1.Table = "comments";
- query1.Type = DbQueryDelete;
- query1.WhereCriteria = boost::make_shared<Dictionary>();
- query1.WhereCriteria->Set("object_id", service);
- OnQuery(query1);
-
- /* remove hostcheck service's host comments */
- if (host->GetHostCheckService() == service) {
- DbQuery query2;
- query2.Table = "comments";
- query2.Type = DbQueryDelete;
- query2.WhereCriteria = boost::make_shared<Dictionary>();
- query2.WhereCriteria->Set("object_id", host);
- OnQuery(query2);
- }
-}
-
void ServiceDbObject::RemoveComment(const Service::Ptr& service, const Dictionary::Ptr& comment)
{
/* TODO: implement */
}
-void ServiceDbObject::DowntimesChangedHandler(const Service::Ptr& svcfilter, const String& id, DowntimeChangedType type)
-{
- if (type == DowntimeChangedUpdated || type == DowntimeChangedDeleted) {
- /* we cannot determine which downtime id is deleted
- * id cache may not be in sync
- */
- BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjects<Service>()) {
- if (svcfilter && svcfilter != service)
- continue;
-
- Host::Ptr host = service->GetHost();
-
- if (!host)
- continue;
-
- /* delete all downtimes associated for this host/service */
- DeleteDowntimes(service);
-
- /* dump all downtimes */
- AddDowntimes(service);
- }
- } else if (type == DowntimeChangedAdded) {
- Dictionary::Ptr downtime = Service::GetDowntimeByID(id);
- AddDowntime(svcfilter, downtime);
- } else {
- Log(LogDebug, "ido", "invalid downtime change type: " + type);
- }
-}
-
void ServiceDbObject::AddDowntimes(const Service::Ptr& service)
{
/* dump all downtimes */
OnQuery(query1);
}
-void ServiceDbObject::DeleteDowntimes(const Service::Ptr& service)
+void ServiceDbObject::RemoveDowntime(const Service::Ptr& service, const Dictionary::Ptr& downtime)
{
- /* delete all downtimes associated for this host/service */
- Log(LogDebug, "ido", "delete downtimes for '" + service->GetName() + "'");
-
- Host::Ptr host = service->GetHost();
-
- if (!host)
- return;
-
- DbQuery query1;
- query1.Table = "scheduleddowntime";
- query1.Type = DbQueryDelete;
- query1.WhereCriteria = boost::make_shared<Dictionary>();
- query1.WhereCriteria->Set("object_id", service);
- OnQuery(query1);
-
- /* delete hostcheck service's host downtimes */
- if (host->GetHostCheckService() == service) {
- DbQuery query2;
- query2.Table = "scheduleddowntime";
- query2.Type = DbQueryDelete;
- query2.WhereCriteria = boost::make_shared<Dictionary>();
- query2.WhereCriteria->Set("object_id", host);
- OnQuery(query2);
- }
+ /* TODO: implement */
}
+void ServiceDbObject::TriggerDowntime(const Service::Ptr& service, const Dictionary::Ptr& downtime)
+{
+ /* TODO: implement */
+}
static void AddComments(const Service::Ptr& service);
static void AddComment(const Service::Ptr& service, const Dictionary::Ptr& comment);
static void AddCommentByType(const DynamicObject::Ptr& object, const Dictionary::Ptr& comment);
- static void RemoveComments(const Service::Ptr& service);
static void RemoveComment(const Service::Ptr& service, const Dictionary::Ptr& comment);
- static void DowntimesChangedHandler(const Service::Ptr& service, const String& id, DowntimeChangedType type);
static void AddDowntimes(const Service::Ptr& service);
static void AddDowntime(const Service::Ptr& service, const Dictionary::Ptr& downtime);
static void AddDowntimeByType(const DynamicObject::Ptr& object, const Dictionary::Ptr& downtime);
- static void DeleteDowntimes(const Service::Ptr& service);
+ static void RemoveDowntime(const Service::Ptr& service, const Dictionary::Ptr& downtime);
+ static void TriggerDowntime(const Service::Ptr& service, const Dictionary::Ptr& downtime);
};
}