Skip to content

Commit

Permalink
DB IDO: Add endpoint id to history tables, part 1.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Friedrich committed Mar 20, 2014
1 parent e222159 commit ee05eb4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
27 changes: 16 additions & 11 deletions lib/db_ido/servicedbobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand All @@ -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));

Expand Down Expand Up @@ -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();

Expand All @@ -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;
Expand Down Expand Up @@ -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";
Expand Down
8 changes: 4 additions & 4 deletions lib/db_ido/servicedbobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ class ServiceDbObject : public DbObject
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);

Expand All @@ -88,15 +88,15 @@ class ServiceDbObject : public DbObject
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);
static void RemoveDowntime(const Service::Ptr& service, const Downtime::Ptr& downtime);
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);
Expand Down

0 comments on commit ee05eb4

Please sign in to comment.