mirror of https://github.com/Icinga/icinga2.git
Implement cluster events for downtimes.
This commit is contained in:
parent
a49d298b9c
commit
788104980c
|
@ -60,6 +60,8 @@ void ClusterComponent::Start(void)
|
|||
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));
|
||||
}
|
||||
|
@ -404,6 +406,44 @@ void ClusterComponent::CommentRemovedHandler(const Service::Ptr& service, const
|
|||
}
|
||||
}
|
||||
|
||||
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>()) {
|
||||
|
@ -509,6 +549,31 @@ void ClusterComponent::MessageHandler(const Endpoint::Ptr& sender, const Diction
|
|||
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());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -87,6 +87,8 @@ private:
|
|||
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);
|
||||
|
||||
};
|
||||
|
|
|
@ -50,7 +50,7 @@ CompatLog::CompatLog(void)
|
|||
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));
|
||||
|
||||
|
@ -165,69 +165,69 @@ void CompatLog::CheckResultHandler(const Service::Ptr& service, const Dictionary
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @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.
|
||||
|
|
|
@ -864,7 +864,8 @@ void ExternalCommandProcessor::ScheduleSvcDowntime(double, const std::vector<Str
|
|||
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]));
|
||||
}
|
||||
|
@ -895,7 +896,8 @@ void ExternalCommandProcessor::ScheduleHostDowntime(double, const std::vector<St
|
|||
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]));
|
||||
}
|
||||
|
@ -926,7 +928,8 @@ void ExternalCommandProcessor::ScheduleHostSvcDowntime(double, const std::vector
|
|||
|
||||
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]));
|
||||
}
|
||||
|
@ -948,7 +951,8 @@ void ExternalCommandProcessor::ScheduleHostgroupHostDowntime(double, const std::
|
|||
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]));
|
||||
}
|
||||
|
@ -981,7 +985,8 @@ void ExternalCommandProcessor::ScheduleHostgroupSvcDowntime(double, const std::v
|
|||
|
||||
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]));
|
||||
}
|
||||
|
@ -1014,7 +1019,8 @@ void ExternalCommandProcessor::ScheduleServicegroupHostDowntime(double, const st
|
|||
|
||||
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]));
|
||||
}
|
||||
|
@ -1034,7 +1040,8 @@ void ExternalCommandProcessor::ScheduleServicegroupSvcDowntime(double, const std
|
|||
|
||||
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]));
|
||||
}
|
||||
|
|
|
@ -35,8 +35,9 @@ static std::map<int, String> l_LegacyDowntimesCache;
|
|||
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)
|
||||
{
|
||||
|
@ -50,14 +51,21 @@ Dictionary::Ptr Service::GetDowntimes(void) const
|
|||
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);
|
||||
|
@ -100,23 +108,20 @@ String Service::AddDowntime(const String& author, const String& comment,
|
|||
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);
|
||||
|
||||
|
@ -128,11 +133,14 @@ void Service::RemoveDowntime(const String& id)
|
|||
if (!downtimes)
|
||||
return;
|
||||
|
||||
{
|
||||
ObjectLock olock(owner);
|
||||
|
||||
Dictionary::Ptr downtime = downtimes->Get(id);
|
||||
|
||||
String comment_id = downtime->Get("comment_id");
|
||||
|
||||
RemoveComment(comment_id);
|
||||
|
||||
int legacy_id = downtime->Get("legacy_id");
|
||||
|
||||
downtimes->Remove(id);
|
||||
|
@ -142,11 +150,8 @@ void Service::RemoveDowntime(const String& id)
|
|||
l_LegacyDowntimesCache.erase(legacy_id);
|
||||
l_DowntimesCache.erase(id);
|
||||
}
|
||||
}
|
||||
|
||||
OnDowntimeChanged(owner, DowntimeCancelled);
|
||||
|
||||
OnDowntimesChanged(owner, id, DowntimeChangedDeleted);
|
||||
OnDowntimeRemoved(owner, downtime, authority);
|
||||
}
|
||||
|
||||
void Service::TriggerDowntimes(void)
|
||||
|
@ -196,8 +201,7 @@ void Service::TriggerDowntime(const String& id)
|
|||
TriggerDowntime(tid);
|
||||
}
|
||||
|
||||
OnDowntimeChanged(owner, DowntimeStarted);
|
||||
OnDowntimesChanged(owner, Empty, DowntimeChangedUpdated);
|
||||
OnDowntimeTriggered(owner, downtime);
|
||||
}
|
||||
|
||||
String Service::GetDowntimeIDFromLegacyID(int id)
|
||||
|
|
|
@ -241,11 +241,12 @@ public:
|
|||
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;
|
||||
|
||||
|
@ -255,11 +256,12 @@ public:
|
|||
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);
|
||||
|
|
|
@ -41,7 +41,9 @@ void ServiceDbObject::StaticInitialize(void)
|
|||
{
|
||||
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)
|
||||
|
@ -250,7 +252,7 @@ void ServiceDbObject::OnConfigUpdate(void)
|
|||
|
||||
/* update comments and downtimes on config change */
|
||||
AddComments(service);
|
||||
DowntimesChangedHandler(service, Empty, DowntimeChangedUpdated);
|
||||
AddDowntimes(service);
|
||||
|
||||
/* service host config update */
|
||||
Host::Ptr host = service->GetHost();
|
||||
|
@ -373,68 +375,11 @@ void ServiceDbObject::AddCommentByType(const DynamicObject::Ptr& object, const D
|
|||
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 */
|
||||
|
@ -518,31 +463,12 @@ void ServiceDbObject::AddDowntimeByType(const DynamicObject::Ptr& object, const
|
|||
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 */
|
||||
}
|
||||
|
|
|
@ -54,14 +54,13 @@ private:
|
|||
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);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue