mirror of https://github.com/Icinga/icinga2.git
DB IDO: Add endpoint id to history tables, part 1.
This commit is contained in:
parent
dbee02a23a
commit
a29b50cad4
|
@ -31,6 +31,7 @@
|
|||
#include "icinga/externalcommandprocessor.h"
|
||||
#include "icinga/compatutility.h"
|
||||
#include "icinga/icingaapplication.h"
|
||||
#include "remote/endpoint.h"
|
||||
#include <boost/foreach.hpp>
|
||||
#include <boost/algorithm/string/join.hpp>
|
||||
|
||||
|
@ -43,14 +44,14 @@ INITIALIZE_ONCE(&ServiceDbObject::StaticInitialize);
|
|||
void ServiceDbObject::StaticInitialize(void)
|
||||
{
|
||||
/* Status */
|
||||
Service::OnCommentAdded.connect(boost::bind(&ServiceDbObject::AddComment, _1, _2));
|
||||
Service::OnCommentAdded.connect(boost::bind(&ServiceDbObject::AddComment, _1, _2, _3));
|
||||
Service::OnCommentRemoved.connect(boost::bind(&ServiceDbObject::RemoveComment, _1, _2));
|
||||
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));
|
||||
|
||||
/* History */
|
||||
Service::OnCommentAdded.connect(boost::bind(&ServiceDbObject::AddCommentHistory, _1, _2));
|
||||
Service::OnCommentAdded.connect(boost::bind(&ServiceDbObject::AddCommentHistory, _1, _2, _3));
|
||||
Service::OnDowntimeAdded.connect(boost::bind(&ServiceDbObject::AddDowntimeHistory, _1, _2));
|
||||
Service::OnAcknowledgementSet.connect(boost::bind(&ServiceDbObject::AddAcknowledgementHistory, _1, _2, _3, _4, _5));
|
||||
|
||||
|
@ -331,21 +332,21 @@ void ServiceDbObject::AddComments(const Service::Ptr& service)
|
|||
ObjectLock olock(comments);
|
||||
|
||||
BOOST_FOREACH(const Dictionary::Pair& kv, comments) {
|
||||
AddComment(service, kv.second);
|
||||
AddComment(service, kv.second, String());
|
||||
}
|
||||
}
|
||||
|
||||
void ServiceDbObject::AddComment(const Service::Ptr& service, const Comment::Ptr& comment)
|
||||
void ServiceDbObject::AddComment(const Service::Ptr& service, const Comment::Ptr& comment, const String& authority)
|
||||
{
|
||||
AddCommentInternal(service, comment, false);
|
||||
AddCommentInternal(service, comment, false, authority);
|
||||
}
|
||||
|
||||
void ServiceDbObject::AddCommentHistory(const Service::Ptr& service, const Comment::Ptr& comment)
|
||||
void ServiceDbObject::AddCommentHistory(const Service::Ptr& service, const Comment::Ptr& comment, const String& authority)
|
||||
{
|
||||
AddCommentInternal(service, comment, true);
|
||||
AddCommentInternal(service, comment, true, authority);
|
||||
}
|
||||
|
||||
void ServiceDbObject::AddCommentInternal(const Service::Ptr& service, const Comment::Ptr& comment, bool historical)
|
||||
void ServiceDbObject::AddCommentInternal(const Service::Ptr& service, const Comment::Ptr& comment, bool historical, const String& authority)
|
||||
{
|
||||
Host::Ptr host = service->GetHost();
|
||||
|
||||
|
@ -357,16 +358,16 @@ void ServiceDbObject::AddCommentInternal(const Service::Ptr& service, const Comm
|
|||
Log(LogDebug, "db_ido", "adding service comment (id = " + Convert::ToString(comment->GetLegacyId()) + ") for '" + service->GetName() + "'");
|
||||
|
||||
/* add the service comment */
|
||||
AddCommentByType(service, comment, historical);
|
||||
AddCommentByType(service, comment, historical, authority);
|
||||
|
||||
/* add the hostcheck service comment to the host as well */
|
||||
if (host->GetCheckService() == service) {
|
||||
Log(LogDebug, "db_ido", "adding host comment (id = " + Convert::ToString(comment->GetLegacyId()) + ") for '" + host->GetName() + "'");
|
||||
AddCommentByType(host, comment, historical);
|
||||
AddCommentByType(host, comment, historical, authority);
|
||||
}
|
||||
}
|
||||
|
||||
void ServiceDbObject::AddCommentByType(const DynamicObject::Ptr& object, const Comment::Ptr& comment, bool historical)
|
||||
void ServiceDbObject::AddCommentByType(const DynamicObject::Ptr& object, const Comment::Ptr& comment, bool historical, const String& authority)
|
||||
{
|
||||
unsigned long entry_time = static_cast<long>(comment->GetEntryTime());
|
||||
unsigned long entry_time_usec = (comment->GetEntryTime() - entry_time) * 1000 * 1000;
|
||||
|
@ -398,6 +399,10 @@ void ServiceDbObject::AddCommentByType(const DynamicObject::Ptr& object, const C
|
|||
fields1->Set("expiration_time", DbValue::FromTimestamp(comment->GetExpireTime()));
|
||||
fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
||||
|
||||
Endpoint::Ptr endpoint = Endpoint::GetByName(authority);
|
||||
if (endpoint)
|
||||
fields1->Set("endpoint_object_id", endpoint);
|
||||
|
||||
DbQuery query1;
|
||||
if (!historical) {
|
||||
query1.Table = "comments";
|
||||
|
|
|
@ -75,8 +75,8 @@ protected:
|
|||
virtual void OnStatusUpdate(void);
|
||||
|
||||
private:
|
||||
static void AddCommentInternal(const Service::Ptr& service, const Comment::Ptr& comment, bool historical);
|
||||
static void AddCommentByType(const DynamicObject::Ptr& object, const Comment::Ptr& comment, bool historical);
|
||||
static void AddCommentInternal(const Service::Ptr& service, const Comment::Ptr& comment, bool historical, const String& authority);
|
||||
static void AddCommentByType(const DynamicObject::Ptr& object, const Comment::Ptr& comment, bool historical, const String& authority);
|
||||
static void AddComments(const Service::Ptr& service);
|
||||
static void RemoveComments(const Service::Ptr& service);
|
||||
|
||||
|
@ -88,7 +88,7 @@ private:
|
|||
static void AddLogHistory(const Service::Ptr& service, String buffer, LogEntryType type);
|
||||
|
||||
/* Status */
|
||||
static void AddComment(const Service::Ptr& service, const Comment::Ptr& comment);
|
||||
static void AddComment(const Service::Ptr& service, const Comment::Ptr& comment, const String& authority);
|
||||
static void RemoveComment(const Service::Ptr& service, const Comment::Ptr& comment);
|
||||
|
||||
static void AddDowntime(const Service::Ptr& service, const Downtime::Ptr& downtime);
|
||||
|
@ -96,7 +96,7 @@ private:
|
|||
static void TriggerDowntime(const Service::Ptr& service, const Downtime::Ptr& downtime);
|
||||
|
||||
/* comment, downtime, acknowledgement history */
|
||||
static void AddCommentHistory(const Service::Ptr& service, const Comment::Ptr& comment);
|
||||
static void AddCommentHistory(const Service::Ptr& service, const Comment::Ptr& comment, const String& authority);
|
||||
static void AddDowntimeHistory(const Service::Ptr& service, const Downtime::Ptr& downtime);
|
||||
static void AddAcknowledgementHistory(const Service::Ptr& service, const String& author, const String& comment,
|
||||
AcknowledgementType type, double expiry);
|
||||
|
|
Loading…
Reference in New Issue