String id;
Dictionary::Ptr comment;
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)
fp << "hostcomment {" << "\n";
else
<< "\t" << "service_description=" << service->GetAlias() << "\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_type=" << static_cast<long>(comment->Get("entry_type")) << "\n"
<< "\t" << "persistent=" << 1 << "\n"
String id;
Dictionary::Ptr downtime;
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)
fp << "hostdowntime {" << "\n";
else
<< "\t" << "service_description=" << service->GetAlias() << "\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" << "start_time=" << static_cast<double>(downtime->Get("start_time")) << "\n"
<< "\t" << "end_time=" << static_cast<double>(downtime->Get("end_time")) << "\n"
using namespace icinga;
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;
int CommentProcessor::GetNextCommentID(void)
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,
double expireTime)
{
if (!comments)
comments = boost::make_shared<Dictionary>();
- int id = m_NextCommentID;
+ int legacy_id = 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);
return id;
owner->Set("comments", Empty);
}
-void CommentProcessor::RemoveComment(int id)
+void CommentProcessor::RemoveComment(const String& id)
{
DynamicObject::Ptr owner = GetOwnerByCommentID(id);
Dictionary::Ptr comments = owner->Get("comments");
if (comments) {
- comments->Remove(Convert::ToString(id));
+ comments->Remove(id);
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();
return m_CommentCache[id].lock();
}
-Dictionary::Ptr CommentProcessor::GetCommentByID(int id)
+Dictionary::Ptr CommentProcessor::GetCommentByID(const String& id)
{
DynamicObject::Ptr owner = GetOwnerByCommentID(id);
Dictionary::Ptr comments = owner->Get("comments");
if (comments) {
- Dictionary::Ptr comment = comments->Get(Convert::ToString(id));
+ Dictionary::Ptr comment = comments->Get(id);
return comment;
}
{
m_CommentCacheValid = false;
m_CommentCache.clear();
+ m_LegacyCommentCache.clear();
}
void CommentProcessor::AddCommentsToCache(const DynamicObject::Ptr& owner)
if (!comments)
return;
- String sid;
- BOOST_FOREACH(tie(sid, tuples::ignore), comments) {
- int id = Convert::ToLong(sid);
+ String id;
+ Dictionary::Ptr comment;
+ BOOST_FOREACH(tie(id, comment), comments) {
+ if (comment->Contains("legacy_id")) {
+ int legacy_id = comment->Get("legacy_id");
+
+ m_LegacyCommentCache[legacy_id] = id;
- if (id > m_NextCommentID)
- m_NextCommentID = id;
+ if (legacy_id > m_NextCommentID)
+ m_NextCommentID = legacy_id;
+ }
m_CommentCache[id] = owner;
}
return;
m_CommentCache.clear();
+ m_LegacyCommentCache.clear();
DynamicObject::Ptr object;
BOOST_FOREACH(tie(tuples::ignore, object), DynamicType::GetByName("Host")->GetObjects()) {
public:
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,
double expireTime);
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 Dictionary::Ptr GetCommentByID(int id);
+ static String GetIDFromLegacyID(int id);
+ static DynamicObject::Ptr GetOwnerByCommentID(const String& id);
+ static Dictionary::Ptr GetCommentByID(const String& id);
static void InvalidateCommentCache(void);
private:
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;
CommentProcessor(void);
using namespace icinga;
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;
int DowntimeProcessor::GetNextDowntimeID(void)
return m_NextDowntimeID;
}
-int DowntimeProcessor::AddDowntime(const DynamicObject::Ptr& owner,
+String DowntimeProcessor::AddDowntime(const DynamicObject::Ptr& owner,
const String& author, const String& comment,
double startTime, double endTime,
- bool fixed, int triggeredBy, double duration)
+ bool fixed, const String& triggeredBy, double duration)
{
Dictionary::Ptr downtime = boost::make_shared<Dictionary>();
downtime->Set("entry_time", Utility::GetTime());
if (!downtimes)
downtimes = boost::make_shared<Dictionary>();
- int id = m_NextDowntimeID;
+ int legacy_id = 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);
return id;
}
-void DowntimeProcessor::RemoveDowntime(int id)
+void DowntimeProcessor::RemoveDowntime(const String& id)
{
DynamicObject::Ptr owner = GetOwnerByDowntimeID(id);
Dictionary::Ptr downtimes = owner->Get("downtimes");
if (downtimes) {
- downtimes->Remove(Convert::ToString(id));
+ downtimes->Remove(id);
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();
return m_DowntimeCache[id].lock();
}
-Dictionary::Ptr DowntimeProcessor::GetDowntimeByID(int id)
+Dictionary::Ptr DowntimeProcessor::GetDowntimeByID(const String& id)
{
DynamicObject::Ptr owner = GetOwnerByDowntimeID(id);
Dictionary::Ptr downtimes = owner->Get("downtimes");
if (downtimes) {
- Dictionary::Ptr downtime = downtimes->Get(Convert::ToString(id));
+ Dictionary::Ptr downtime = downtimes->Get(id);
return downtime;
}
{
m_DowntimeCacheValid = false;
m_DowntimeCache.clear();
+ m_LegacyDowntimeCache.clear();
}
void DowntimeProcessor::AddDowntimesToCache(const DynamicObject::Ptr& owner)
if (!downtimes)
return;
- String sid;
- BOOST_FOREACH(tie(sid, tuples::ignore), downtimes) {
- int id = Convert::ToLong(sid);
+ String id;
+ Dictionary::Ptr downtime;
+ BOOST_FOREACH(tie(id, downtime), downtimes) {
+ if (downtime->Contains("legacy_id")) {
+ int legacy_id = downtime->Get("legacy_id");
+
+ m_LegacyDowntimeCache[legacy_id] = id;
- if (id > m_NextDowntimeID)
- m_NextDowntimeID = id;
+ if (legacy_id > m_NextDowntimeID)
+ m_NextDowntimeID = legacy_id;
+ }
m_DowntimeCache[id] = owner;
}
return;
m_DowntimeCache.clear();
+ m_LegacyDowntimeCache.clear();
DynamicObject::Ptr object;
BOOST_FOREACH(tie(tuples::ignore, object), DynamicType::GetByName("Host")->GetObjects()) {
public:
static int GetNextDowntimeID(void);
- static int AddDowntime(const DynamicObject::Ptr& owner,
+ static String AddDowntime(const DynamicObject::Ptr& owner,
const String& author, const String& comment,
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 Dictionary::Ptr GetDowntimeByID(int id);
+ static String GetIDFromLegacyID(int id);
+ static DynamicObject::Ptr GetOwnerByDowntimeID(const String& id);
+ static Dictionary::Ptr GetDowntimeByID(const String& id);
static bool IsDowntimeActive(const Dictionary::Ptr& downtime);
private:
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;
DowntimeProcessor(void);
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],
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)
if (arguments.size() < 1)
throw_exception(invalid_argument("Expected 1 argument."));
- String id = arguments[0];
- Logger::Write(LogInformation, "icinga", "Removing downtime ID " + id);
- DowntimeProcessor::RemoveDowntime(Convert::ToLong(id));
+ int id = Convert::ToLong(arguments[0]);
+ Logger::Write(LogInformation, "icinga", "Removing downtime ID " + arguments[0]);
+ String rid = DowntimeProcessor::GetIDFromLegacyID(id);
+ DowntimeProcessor::RemoveDowntime(rid);
}
void ExternalCommandProcessor::ScheduleHostDowntime(double time, const vector<String>& arguments)
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],
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)
if (arguments.size() < 1)
throw_exception(invalid_argument("Expected 1 argument."));
- String id = arguments[0];
- Logger::Write(LogInformation, "icinga", "Removing downtime ID " + id);
- DowntimeProcessor::RemoveDowntime(Convert::ToLong(id));
+ int id = Convert::ToLong(arguments[0]);
+ Logger::Write(LogInformation, "icinga", "Removing downtime ID " + arguments[0]);
+ String rid = DowntimeProcessor::GetIDFromLegacyID(id);
+ DowntimeProcessor::RemoveDowntime(rid);
}
void ExternalCommandProcessor::ScheduleHostSvcDowntime(double time, const vector<String>& arguments)
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());
(void) DowntimeProcessor::AddDowntime(host, arguments[6], arguments[7],
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()) {
Logger::Write(LogInformation, "icinga", "Creating downtime for service " + service->GetName());
(void) DowntimeProcessor::AddDowntime(service, arguments[6], arguments[7],
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]));
}
}
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()) {
Logger::Write(LogInformation, "icinga", "Creating downtime for host " + host->GetName());
(void) DowntimeProcessor::AddDowntime(host, arguments[6], arguments[7],
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]));
}
}
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()) {
Logger::Write(LogInformation, "icinga", "Creating downtime for service " + service->GetName());
(void) DowntimeProcessor::AddDowntime(service, arguments[6], arguments[7],
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]));
}
}
if (arguments.size() < 1)
throw_exception(invalid_argument("Expected 1 argument."));
- String id = arguments[0];
- Logger::Write(LogInformation, "icinga", "Removing comment ID " + id);
- CommentProcessor::RemoveComment(Convert::ToLong(id));
+ int id = Convert::ToLong(arguments[0]);
+ Logger::Write(LogInformation, "icinga", "Removing comment ID " + arguments[0]);
+ String rid = CommentProcessor::GetIDFromLegacyID(id);
+ CommentProcessor::RemoveComment(rid);
}
void ExternalCommandProcessor::AddSvcComment(double time, const vector<String>& arguments)
if (arguments.size() < 1)
throw_exception(invalid_argument("Expected 1 argument."));
- String id = arguments[0];
- Logger::Write(LogInformation, "icinga", "Removing comment ID " + id);
- CommentProcessor::RemoveComment(Convert::ToLong(id));
+ int id = Convert::ToLong(arguments[0]);
+ Logger::Write(LogInformation, "icinga", "Removing comment ID " + arguments[0]);
+
+ String rid = CommentProcessor::GetIDFromLegacyID(id);
+ CommentProcessor::RemoveComment(rid);
}
void ExternalCommandProcessor::DelAllHostComments(double time, const vector<String>& arguments)
{ "hostchecks", Attribute_Config },
{ "acknowledgement", Attribute_Replicated },
{ "acknowledgement_expiry", Attribute_Replicated },
- { "downtimes", Attribute_Replicated }
+ { "downtimes", Attribute_Replicated },
+ { "comments", Attribute_Replicated }
};
REGISTER_TYPE(Host, hostAttributes);
{ "force_next_check", Attribute_Replicated },
{ "acknowledgement", Attribute_Replicated },
{ "acknowledgement_expiry", Attribute_Replicated },
- { "downtimes", Attribute_Replicated }
+ { "downtimes", Attribute_Replicated },
+ { "comments", Attribute_Replicated }
};
REGISTER_TYPE(Service, serviceAttributes);