Use UUIDs to uniquely identify comments and downtimes.

This commit is contained in:
Gunnar Beutner 2013-01-30 09:59:22 +01:00
parent 5a96ed74e4
commit 6e119dafee
8 changed files with 138 additions and 64 deletions

View File

@ -181,6 +181,11 @@ void CompatComponent::DumpComments(ofstream& fp, const DynamicObject::Ptr& owner
String id; String id;
Dictionary::Ptr comment; Dictionary::Ptr comment;
BOOST_FOREACH(tie(id, comment), comments) { BOOST_FOREACH(tie(id, comment), comments) {
/* There's no way for us to dump comments that haven't been
* assigned a legacy ID yet. */
if (!comment->Contains("legacy_id"))
continue;
if (!service) if (!service)
fp << "hostcomment {" << "\n"; fp << "hostcomment {" << "\n";
else else
@ -188,7 +193,7 @@ void CompatComponent::DumpComments(ofstream& fp, const DynamicObject::Ptr& owner
<< "\t" << "service_description=" << service->GetAlias() << "\n"; << "\t" << "service_description=" << service->GetAlias() << "\n";
fp << "\t" << "host_name=" << host->GetName() << "\n" fp << "\t" << "host_name=" << host->GetName() << "\n"
<< "\t" << "comment_id=" << id << "\n" << "\t" << "comment_id=" << static_cast<String>(comment->Get("legacy_id")) << "\n"
<< "\t" << "entry_time=" << static_cast<double>(comment->Get("entry_time")) << "\n" << "\t" << "entry_time=" << static_cast<double>(comment->Get("entry_time")) << "\n"
<< "\t" << "entry_type=" << static_cast<long>(comment->Get("entry_type")) << "\n" << "\t" << "entry_type=" << static_cast<long>(comment->Get("entry_type")) << "\n"
<< "\t" << "persistent=" << 1 << "\n" << "\t" << "persistent=" << 1 << "\n"
@ -223,6 +228,11 @@ void CompatComponent::DumpDowntimes(ofstream& fp, const DynamicObject::Ptr& owne
String id; String id;
Dictionary::Ptr downtime; Dictionary::Ptr downtime;
BOOST_FOREACH(tie(id, downtime), downtimes) { BOOST_FOREACH(tie(id, downtime), downtimes) {
/* There's no way for us to dump downtimes that haven't been
* assigned a legacy ID yet. */
if (!downtime->Contains("legacy_id"))
continue;
if (!service) if (!service)
fp << "hostdowntime {" << "\n"; fp << "hostdowntime {" << "\n";
else else
@ -230,7 +240,7 @@ void CompatComponent::DumpDowntimes(ofstream& fp, const DynamicObject::Ptr& owne
<< "\t" << "service_description=" << service->GetAlias() << "\n"; << "\t" << "service_description=" << service->GetAlias() << "\n";
fp << "\t" << "host_name=" << host->GetName() << "\n" fp << "\t" << "host_name=" << host->GetName() << "\n"
<< "\t" << "downtime_id=" << id << "\n" << "\t" << "downtime_id=" << static_cast<String>(downtime->Get("legacy_id")) << "\n"
<< "\t" << "entry_time=" << static_cast<double>(downtime->Get("entry_time")) << "\n" << "\t" << "entry_time=" << static_cast<double>(downtime->Get("entry_time")) << "\n"
<< "\t" << "start_time=" << static_cast<double>(downtime->Get("start_time")) << "\n" << "\t" << "start_time=" << static_cast<double>(downtime->Get("start_time")) << "\n"
<< "\t" << "end_time=" << static_cast<double>(downtime->Get("end_time")) << "\n" << "\t" << "end_time=" << static_cast<double>(downtime->Get("end_time")) << "\n"

View File

@ -22,7 +22,8 @@
using namespace icinga; using namespace icinga;
int CommentProcessor::m_NextCommentID = 1; int CommentProcessor::m_NextCommentID = 1;
map<int, DynamicObject::WeakPtr> CommentProcessor::m_CommentCache; map<int, String> CommentProcessor::m_LegacyCommentCache;
map<String, DynamicObject::WeakPtr> CommentProcessor::m_CommentCache;
bool CommentProcessor::m_CommentCacheValid; bool CommentProcessor::m_CommentCacheValid;
int CommentProcessor::GetNextCommentID(void) int CommentProcessor::GetNextCommentID(void)
@ -30,7 +31,7 @@ int CommentProcessor::GetNextCommentID(void)
return m_NextCommentID; return m_NextCommentID;
} }
int CommentProcessor::AddComment(const DynamicObject::Ptr& owner, String CommentProcessor::AddComment(const DynamicObject::Ptr& owner,
CommentType entryType, const String& author, const String& text, CommentType entryType, const String& author, const String& text,
double expireTime) double expireTime)
{ {
@ -46,10 +47,12 @@ int CommentProcessor::AddComment(const DynamicObject::Ptr& owner,
if (!comments) if (!comments)
comments = boost::make_shared<Dictionary>(); comments = boost::make_shared<Dictionary>();
int id = m_NextCommentID; int legacy_id = m_NextCommentID;
m_NextCommentID++; m_NextCommentID++;
comment->Set("legacy_id", legacy_id);
comments->Set(Convert::ToString(id), comment); String id = Utility::NewUUID();
comments->Set(id, comment);
owner->Set("comments", comments); owner->Set("comments", comments);
return id; return id;
@ -60,7 +63,7 @@ void CommentProcessor::RemoveAllComments(const DynamicObject::Ptr& owner)
owner->Set("comments", Empty); owner->Set("comments", Empty);
} }
void CommentProcessor::RemoveComment(int id) void CommentProcessor::RemoveComment(const String& id)
{ {
DynamicObject::Ptr owner = GetOwnerByCommentID(id); DynamicObject::Ptr owner = GetOwnerByCommentID(id);
@ -70,19 +73,24 @@ void CommentProcessor::RemoveComment(int id)
Dictionary::Ptr comments = owner->Get("comments"); Dictionary::Ptr comments = owner->Get("comments");
if (comments) { if (comments) {
comments->Remove(Convert::ToString(id)); comments->Remove(id);
owner->Touch("comments"); owner->Touch("comments");
} }
} }
DynamicObject::Ptr CommentProcessor::GetOwnerByCommentID(int id) String CommentProcessor::GetIDFromLegacyID(int id)
{
return Convert::ToString(id);
}
DynamicObject::Ptr CommentProcessor::GetOwnerByCommentID(const String& id)
{ {
ValidateCommentCache(); ValidateCommentCache();
return m_CommentCache[id].lock(); return m_CommentCache[id].lock();
} }
Dictionary::Ptr CommentProcessor::GetCommentByID(int id) Dictionary::Ptr CommentProcessor::GetCommentByID(const String& id)
{ {
DynamicObject::Ptr owner = GetOwnerByCommentID(id); DynamicObject::Ptr owner = GetOwnerByCommentID(id);
@ -92,7 +100,7 @@ Dictionary::Ptr CommentProcessor::GetCommentByID(int id)
Dictionary::Ptr comments = owner->Get("comments"); Dictionary::Ptr comments = owner->Get("comments");
if (comments) { if (comments) {
Dictionary::Ptr comment = comments->Get(Convert::ToString(id)); Dictionary::Ptr comment = comments->Get(id);
return comment; return comment;
} }
@ -103,6 +111,7 @@ void CommentProcessor::InvalidateCommentCache(void)
{ {
m_CommentCacheValid = false; m_CommentCacheValid = false;
m_CommentCache.clear(); m_CommentCache.clear();
m_LegacyCommentCache.clear();
} }
void CommentProcessor::AddCommentsToCache(const DynamicObject::Ptr& owner) void CommentProcessor::AddCommentsToCache(const DynamicObject::Ptr& owner)
@ -112,12 +121,17 @@ void CommentProcessor::AddCommentsToCache(const DynamicObject::Ptr& owner)
if (!comments) if (!comments)
return; return;
String sid; String id;
BOOST_FOREACH(tie(sid, tuples::ignore), comments) { Dictionary::Ptr comment;
int id = Convert::ToLong(sid); BOOST_FOREACH(tie(id, comment), comments) {
if (comment->Contains("legacy_id")) {
int legacy_id = comment->Get("legacy_id");
if (id > m_NextCommentID) m_LegacyCommentCache[legacy_id] = id;
m_NextCommentID = id;
if (legacy_id > m_NextCommentID)
m_NextCommentID = legacy_id;
}
m_CommentCache[id] = owner; m_CommentCache[id] = owner;
} }
@ -129,6 +143,7 @@ void CommentProcessor::ValidateCommentCache(void)
return; return;
m_CommentCache.clear(); m_CommentCache.clear();
m_LegacyCommentCache.clear();
DynamicObject::Ptr object; DynamicObject::Ptr object;
BOOST_FOREACH(tie(tuples::ignore, object), DynamicType::GetByName("Host")->GetObjects()) { BOOST_FOREACH(tie(tuples::ignore, object), DynamicType::GetByName("Host")->GetObjects()) {

View File

@ -41,22 +41,24 @@ class I2_ICINGA_API CommentProcessor
public: public:
static int GetNextCommentID(void); static int GetNextCommentID(void);
static int AddComment(const DynamicObject::Ptr& owner, static String AddComment(const DynamicObject::Ptr& owner,
CommentType entryType, const String& author, const String& text, CommentType entryType, const String& author, const String& text,
double expireTime); double expireTime);
static void RemoveAllComments(const DynamicObject::Ptr& owner); static void RemoveAllComments(const DynamicObject::Ptr& owner);
static void RemoveComment(int id); static void RemoveComment(const String& id);
static DynamicObject::Ptr GetOwnerByCommentID(int id); static String GetIDFromLegacyID(int id);
static Dictionary::Ptr GetCommentByID(int id); static DynamicObject::Ptr GetOwnerByCommentID(const String& id);
static Dictionary::Ptr GetCommentByID(const String& id);
static void InvalidateCommentCache(void); static void InvalidateCommentCache(void);
private: private:
static int m_NextCommentID; static int m_NextCommentID;
static map<int, DynamicObject::WeakPtr> m_CommentCache; static map<int, String> m_LegacyCommentCache;
static map<String, DynamicObject::WeakPtr> m_CommentCache;
static bool m_CommentCacheValid; static bool m_CommentCacheValid;
CommentProcessor(void); CommentProcessor(void);

View File

@ -22,7 +22,8 @@
using namespace icinga; using namespace icinga;
int DowntimeProcessor::m_NextDowntimeID = 1; int DowntimeProcessor::m_NextDowntimeID = 1;
map<int, DynamicObject::WeakPtr> DowntimeProcessor::m_DowntimeCache; map<int, String> DowntimeProcessor::m_LegacyDowntimeCache;
map<String, DynamicObject::WeakPtr> DowntimeProcessor::m_DowntimeCache;
bool DowntimeProcessor::m_DowntimeCacheValid; bool DowntimeProcessor::m_DowntimeCacheValid;
int DowntimeProcessor::GetNextDowntimeID(void) int DowntimeProcessor::GetNextDowntimeID(void)
@ -30,10 +31,10 @@ int DowntimeProcessor::GetNextDowntimeID(void)
return m_NextDowntimeID; return m_NextDowntimeID;
} }
int DowntimeProcessor::AddDowntime(const DynamicObject::Ptr& owner, String DowntimeProcessor::AddDowntime(const DynamicObject::Ptr& owner,
const String& author, const String& comment, const String& author, const String& comment,
double startTime, double endTime, double startTime, double endTime,
bool fixed, int triggeredBy, double duration) bool fixed, const String& triggeredBy, double duration)
{ {
Dictionary::Ptr downtime = boost::make_shared<Dictionary>(); Dictionary::Ptr downtime = boost::make_shared<Dictionary>();
downtime->Set("entry_time", Utility::GetTime()); downtime->Set("entry_time", Utility::GetTime());
@ -51,35 +52,42 @@ int DowntimeProcessor::AddDowntime(const DynamicObject::Ptr& owner,
if (!downtimes) if (!downtimes)
downtimes = boost::make_shared<Dictionary>(); downtimes = boost::make_shared<Dictionary>();
int id = m_NextDowntimeID; int legacy_id = m_NextDowntimeID;
m_NextDowntimeID++; m_NextDowntimeID++;
downtime->Set("legacy_id", legacy_id);
downtimes->Set(Convert::ToString(id), downtime); String id = Utility::NewUUID();
downtimes->Set(id, downtime);
owner->Set("downtimes", downtimes); owner->Set("downtimes", downtimes);
return id; return id;
} }
void DowntimeProcessor::RemoveDowntime(int id) void DowntimeProcessor::RemoveDowntime(const String& id)
{ {
DynamicObject::Ptr owner = GetOwnerByDowntimeID(id); DynamicObject::Ptr owner = GetOwnerByDowntimeID(id);
Dictionary::Ptr downtimes = owner->Get("downtimes"); Dictionary::Ptr downtimes = owner->Get("downtimes");
if (downtimes) { if (downtimes) {
downtimes->Remove(Convert::ToString(id)); downtimes->Remove(id);
owner->Touch("downtimes"); owner->Touch("downtimes");
} }
} }
DynamicObject::Ptr DowntimeProcessor::GetOwnerByDowntimeID(int id) String DowntimeProcessor::GetIDFromLegacyID(int id)
{
return Convert::ToString(id);
}
DynamicObject::Ptr DowntimeProcessor::GetOwnerByDowntimeID(const String& id)
{ {
ValidateDowntimeCache(); ValidateDowntimeCache();
return m_DowntimeCache[id].lock(); return m_DowntimeCache[id].lock();
} }
Dictionary::Ptr DowntimeProcessor::GetDowntimeByID(int id) Dictionary::Ptr DowntimeProcessor::GetDowntimeByID(const String& id)
{ {
DynamicObject::Ptr owner = GetOwnerByDowntimeID(id); DynamicObject::Ptr owner = GetOwnerByDowntimeID(id);
@ -89,7 +97,7 @@ Dictionary::Ptr DowntimeProcessor::GetDowntimeByID(int id)
Dictionary::Ptr downtimes = owner->Get("downtimes"); Dictionary::Ptr downtimes = owner->Get("downtimes");
if (downtimes) { if (downtimes) {
Dictionary::Ptr downtime = downtimes->Get(Convert::ToString(id)); Dictionary::Ptr downtime = downtimes->Get(id);
return downtime; return downtime;
} }
@ -119,6 +127,7 @@ void DowntimeProcessor::InvalidateDowntimeCache(void)
{ {
m_DowntimeCacheValid = false; m_DowntimeCacheValid = false;
m_DowntimeCache.clear(); m_DowntimeCache.clear();
m_LegacyDowntimeCache.clear();
} }
void DowntimeProcessor::AddDowntimesToCache(const DynamicObject::Ptr& owner) void DowntimeProcessor::AddDowntimesToCache(const DynamicObject::Ptr& owner)
@ -128,12 +137,17 @@ void DowntimeProcessor::AddDowntimesToCache(const DynamicObject::Ptr& owner)
if (!downtimes) if (!downtimes)
return; return;
String sid; String id;
BOOST_FOREACH(tie(sid, tuples::ignore), downtimes) { Dictionary::Ptr downtime;
int id = Convert::ToLong(sid); BOOST_FOREACH(tie(id, downtime), downtimes) {
if (downtime->Contains("legacy_id")) {
int legacy_id = downtime->Get("legacy_id");
if (id > m_NextDowntimeID) m_LegacyDowntimeCache[legacy_id] = id;
m_NextDowntimeID = id;
if (legacy_id > m_NextDowntimeID)
m_NextDowntimeID = legacy_id;
}
m_DowntimeCache[id] = owner; m_DowntimeCache[id] = owner;
} }
@ -145,6 +159,7 @@ void DowntimeProcessor::ValidateDowntimeCache(void)
return; return;
m_DowntimeCache.clear(); m_DowntimeCache.clear();
m_LegacyDowntimeCache.clear();
DynamicObject::Ptr object; DynamicObject::Ptr object;
BOOST_FOREACH(tie(tuples::ignore, object), DynamicType::GetByName("Host")->GetObjects()) { BOOST_FOREACH(tie(tuples::ignore, object), DynamicType::GetByName("Host")->GetObjects()) {

View File

@ -33,15 +33,16 @@ class I2_ICINGA_API DowntimeProcessor
public: public:
static int GetNextDowntimeID(void); static int GetNextDowntimeID(void);
static int AddDowntime(const DynamicObject::Ptr& owner, static String AddDowntime(const DynamicObject::Ptr& owner,
const String& author, const String& comment, const String& author, const String& comment,
double startTime, double endTime, double startTime, double endTime,
bool fixed, int triggeredBy, double duration); bool fixed, const String& triggeredBy, double duration);
static void RemoveDowntime(int id); static void RemoveDowntime(const String& id);
static DynamicObject::Ptr GetOwnerByDowntimeID(int id); static String GetIDFromLegacyID(int id);
static Dictionary::Ptr GetDowntimeByID(int id); static DynamicObject::Ptr GetOwnerByDowntimeID(const String& id);
static Dictionary::Ptr GetDowntimeByID(const String& id);
static bool IsDowntimeActive(const Dictionary::Ptr& downtime); static bool IsDowntimeActive(const Dictionary::Ptr& downtime);
@ -50,7 +51,8 @@ public:
private: private:
static int m_NextDowntimeID; static int m_NextDowntimeID;
static map<int, DynamicObject::WeakPtr> m_DowntimeCache; static map<int, String> m_LegacyDowntimeCache;
static map<String, DynamicObject::WeakPtr> m_DowntimeCache;
static bool m_DowntimeCacheValid; static bool m_DowntimeCacheValid;
DowntimeProcessor(void); DowntimeProcessor(void);

View File

@ -622,11 +622,15 @@ void ExternalCommandProcessor::ScheduleSvcDowntime(double time, const vector<Str
Service::Ptr service = Service::GetByName(arguments[1]); Service::Ptr service = Service::GetByName(arguments[1]);
Logger::Write(LogInformation, "icinga", "Creating downtime for service " + service->GetName()); String triggeredBy;
int triggeredByLegacy = Convert::ToLong(arguments[5]);
if (triggeredByLegacy != 0)
triggeredBy = DowntimeProcessor::GetIDFromLegacyID(triggeredByLegacy);
Logger::Write(LogInformation, "icinga", "Creating downtime for service " + service->GetName());
(void) DowntimeProcessor::AddDowntime(service, arguments[7], arguments[8], (void) DowntimeProcessor::AddDowntime(service, arguments[7], arguments[8],
Convert::ToDouble(arguments[2]), Convert::ToDouble(arguments[3]), Convert::ToDouble(arguments[2]), Convert::ToDouble(arguments[3]),
Convert::ToBool(arguments[4]), Convert::ToLong(arguments[5]), Convert::ToDouble(arguments[6])); Convert::ToBool(arguments[4]), triggeredBy, Convert::ToDouble(arguments[6]));
} }
void ExternalCommandProcessor::DelSvcDowntime(double time, const vector<String>& arguments) void ExternalCommandProcessor::DelSvcDowntime(double time, const vector<String>& arguments)
@ -634,9 +638,10 @@ void ExternalCommandProcessor::DelSvcDowntime(double time, const vector<String>&
if (arguments.size() < 1) if (arguments.size() < 1)
throw_exception(invalid_argument("Expected 1 argument.")); throw_exception(invalid_argument("Expected 1 argument."));
String id = arguments[0]; int id = Convert::ToLong(arguments[0]);
Logger::Write(LogInformation, "icinga", "Removing downtime ID " + id); Logger::Write(LogInformation, "icinga", "Removing downtime ID " + arguments[0]);
DowntimeProcessor::RemoveDowntime(Convert::ToLong(id)); String rid = DowntimeProcessor::GetIDFromLegacyID(id);
DowntimeProcessor::RemoveDowntime(rid);
} }
void ExternalCommandProcessor::ScheduleHostDowntime(double time, const vector<String>& arguments) void ExternalCommandProcessor::ScheduleHostDowntime(double time, const vector<String>& arguments)
@ -649,11 +654,15 @@ void ExternalCommandProcessor::ScheduleHostDowntime(double time, const vector<St
Host::Ptr host = Host::GetByName(arguments[0]); Host::Ptr host = Host::GetByName(arguments[0]);
Logger::Write(LogInformation, "icinga", "Creating downtime for host " + host->GetName()); String triggeredBy;
int triggeredByLegacy = Convert::ToLong(arguments[4]);
if (triggeredByLegacy != 0)
triggeredBy = DowntimeProcessor::GetIDFromLegacyID(triggeredByLegacy);
Logger::Write(LogInformation, "icinga", "Creating downtime for host " + host->GetName());
(void) DowntimeProcessor::AddDowntime(host, arguments[6], arguments[7], (void) DowntimeProcessor::AddDowntime(host, arguments[6], arguments[7],
Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]), Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
Convert::ToBool(arguments[3]), Convert::ToLong(arguments[4]), Convert::ToDouble(arguments[5])); Convert::ToBool(arguments[3]), triggeredBy, Convert::ToDouble(arguments[5]));
} }
void ExternalCommandProcessor::DelHostDowntime(double time, const vector<String>& arguments) void ExternalCommandProcessor::DelHostDowntime(double time, const vector<String>& arguments)
@ -661,9 +670,10 @@ void ExternalCommandProcessor::DelHostDowntime(double time, const vector<String>
if (arguments.size() < 1) if (arguments.size() < 1)
throw_exception(invalid_argument("Expected 1 argument.")); throw_exception(invalid_argument("Expected 1 argument."));
String id = arguments[0]; int id = Convert::ToLong(arguments[0]);
Logger::Write(LogInformation, "icinga", "Removing downtime ID " + id); Logger::Write(LogInformation, "icinga", "Removing downtime ID " + arguments[0]);
DowntimeProcessor::RemoveDowntime(Convert::ToLong(id)); String rid = DowntimeProcessor::GetIDFromLegacyID(id);
DowntimeProcessor::RemoveDowntime(rid);
} }
void ExternalCommandProcessor::ScheduleHostSvcDowntime(double time, const vector<String>& arguments) void ExternalCommandProcessor::ScheduleHostSvcDowntime(double time, const vector<String>& arguments)
@ -676,16 +686,21 @@ void ExternalCommandProcessor::ScheduleHostSvcDowntime(double time, const vector
Host::Ptr host = Host::GetByName(arguments[0]); Host::Ptr host = Host::GetByName(arguments[0]);
String triggeredBy;
int triggeredByLegacy = Convert::ToLong(arguments[4]);
if (triggeredByLegacy != 0)
triggeredBy = DowntimeProcessor::GetIDFromLegacyID(triggeredByLegacy);
Logger::Write(LogInformation, "icinga", "Creating downtime for host " + host->GetName()); Logger::Write(LogInformation, "icinga", "Creating downtime for host " + host->GetName());
(void) DowntimeProcessor::AddDowntime(host, arguments[6], arguments[7], (void) DowntimeProcessor::AddDowntime(host, arguments[6], arguments[7],
Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]), Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
Convert::ToBool(arguments[3]), Convert::ToLong(arguments[4]), Convert::ToDouble(arguments[5])); Convert::ToBool(arguments[3]), triggeredBy, Convert::ToDouble(arguments[5]));
BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) { BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
Logger::Write(LogInformation, "icinga", "Creating downtime for service " + service->GetName()); Logger::Write(LogInformation, "icinga", "Creating downtime for service " + service->GetName());
(void) DowntimeProcessor::AddDowntime(service, arguments[6], arguments[7], (void) DowntimeProcessor::AddDowntime(service, arguments[6], arguments[7],
Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]), Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
Convert::ToBool(arguments[3]), Convert::ToLong(arguments[4]), Convert::ToDouble(arguments[5])); Convert::ToBool(arguments[3]), triggeredBy, Convert::ToDouble(arguments[5]));
} }
} }
@ -699,11 +714,16 @@ void ExternalCommandProcessor::ScheduleHostgroupHostDowntime(double time, const
HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]); HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
String triggeredBy;
int triggeredByLegacy = Convert::ToLong(arguments[4]);
if (triggeredByLegacy != 0)
triggeredBy = DowntimeProcessor::GetIDFromLegacyID(triggeredByLegacy);
BOOST_FOREACH(const Host::Ptr& host, hg->GetMembers()) { BOOST_FOREACH(const Host::Ptr& host, hg->GetMembers()) {
Logger::Write(LogInformation, "icinga", "Creating downtime for host " + host->GetName()); Logger::Write(LogInformation, "icinga", "Creating downtime for host " + host->GetName());
(void) DowntimeProcessor::AddDowntime(host, arguments[6], arguments[7], (void) DowntimeProcessor::AddDowntime(host, arguments[6], arguments[7],
Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]), Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
Convert::ToBool(arguments[3]), Convert::ToLong(arguments[4]), Convert::ToDouble(arguments[5])); Convert::ToBool(arguments[3]), triggeredBy, Convert::ToDouble(arguments[5]));
} }
} }
@ -727,11 +747,16 @@ void ExternalCommandProcessor::ScheduleServicegroupSvcDowntime(double time, cons
ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]); ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
String triggeredBy;
int triggeredByLegacy = Convert::ToLong(arguments[4]);
if (triggeredByLegacy != 0)
triggeredBy = DowntimeProcessor::GetIDFromLegacyID(triggeredByLegacy);
BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) { BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) {
Logger::Write(LogInformation, "icinga", "Creating downtime for service " + service->GetName()); Logger::Write(LogInformation, "icinga", "Creating downtime for service " + service->GetName());
(void) DowntimeProcessor::AddDowntime(service, arguments[6], arguments[7], (void) DowntimeProcessor::AddDowntime(service, arguments[6], arguments[7],
Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]), Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
Convert::ToBool(arguments[3]), Convert::ToLong(arguments[4]), Convert::ToDouble(arguments[5])); Convert::ToBool(arguments[3]), triggeredBy, Convert::ToDouble(arguments[5]));
} }
} }
@ -754,9 +779,10 @@ void ExternalCommandProcessor::DelHostComment(double time, const vector<String>&
if (arguments.size() < 1) if (arguments.size() < 1)
throw_exception(invalid_argument("Expected 1 argument.")); throw_exception(invalid_argument("Expected 1 argument."));
String id = arguments[0]; int id = Convert::ToLong(arguments[0]);
Logger::Write(LogInformation, "icinga", "Removing comment ID " + id); Logger::Write(LogInformation, "icinga", "Removing comment ID " + arguments[0]);
CommentProcessor::RemoveComment(Convert::ToLong(id)); String rid = CommentProcessor::GetIDFromLegacyID(id);
CommentProcessor::RemoveComment(rid);
} }
void ExternalCommandProcessor::AddSvcComment(double time, const vector<String>& arguments) void ExternalCommandProcessor::AddSvcComment(double time, const vector<String>& arguments)
@ -778,9 +804,11 @@ void ExternalCommandProcessor::DelSvcComment(double time, const vector<String>&
if (arguments.size() < 1) if (arguments.size() < 1)
throw_exception(invalid_argument("Expected 1 argument.")); throw_exception(invalid_argument("Expected 1 argument."));
String id = arguments[0]; int id = Convert::ToLong(arguments[0]);
Logger::Write(LogInformation, "icinga", "Removing comment ID " + id); Logger::Write(LogInformation, "icinga", "Removing comment ID " + arguments[0]);
CommentProcessor::RemoveComment(Convert::ToLong(id));
String rid = CommentProcessor::GetIDFromLegacyID(id);
CommentProcessor::RemoveComment(rid);
} }
void ExternalCommandProcessor::DelAllHostComments(double time, const vector<String>& arguments) void ExternalCommandProcessor::DelAllHostComments(double time, const vector<String>& arguments)

View File

@ -31,7 +31,8 @@ static AttributeDescription hostAttributes[] = {
{ "hostchecks", Attribute_Config }, { "hostchecks", Attribute_Config },
{ "acknowledgement", Attribute_Replicated }, { "acknowledgement", Attribute_Replicated },
{ "acknowledgement_expiry", Attribute_Replicated }, { "acknowledgement_expiry", Attribute_Replicated },
{ "downtimes", Attribute_Replicated } { "downtimes", Attribute_Replicated },
{ "comments", Attribute_Replicated }
}; };
REGISTER_TYPE(Host, hostAttributes); REGISTER_TYPE(Host, hostAttributes);

View File

@ -48,7 +48,8 @@ static AttributeDescription serviceAttributes[] = {
{ "force_next_check", Attribute_Replicated }, { "force_next_check", Attribute_Replicated },
{ "acknowledgement", Attribute_Replicated }, { "acknowledgement", Attribute_Replicated },
{ "acknowledgement_expiry", Attribute_Replicated }, { "acknowledgement_expiry", Attribute_Replicated },
{ "downtimes", Attribute_Replicated } { "downtimes", Attribute_Replicated },
{ "comments", Attribute_Replicated }
}; };
REGISTER_TYPE(Service, serviceAttributes); REGISTER_TYPE(Service, serviceAttributes);