diff --git a/components/cluster/clusterlistener.cpp b/components/cluster/clusterlistener.cpp index 517227578..f297e1aa2 100644 --- a/components/cluster/clusterlistener.cpp +++ b/components/cluster/clusterlistener.cpp @@ -831,7 +831,7 @@ void ClusterListener::EnableFlappingChangedHandler(const Service::Ptr& service, AsyncRelayMessage(Endpoint::Ptr(), message, true); } -void ClusterListener::CommentAddedHandler(const Service::Ptr& service, const Dictionary::Ptr& comment, const String& authority) +void ClusterListener::CommentAddedHandler(const Service::Ptr& service, const Comment::Ptr& comment, const String& authority) { if (!authority.IsEmpty() && authority != GetIdentity()) return; @@ -850,14 +850,14 @@ void ClusterListener::CommentAddedHandler(const Service::Ptr& service, const Dic AsyncRelayMessage(Endpoint::Ptr(), message, true); } -void ClusterListener::CommentRemovedHandler(const Service::Ptr& service, const Dictionary::Ptr& comment, const String& authority) +void ClusterListener::CommentRemovedHandler(const Service::Ptr& service, const Comment::Ptr& comment, const String& authority) { if (!authority.IsEmpty() && authority != GetIdentity()) return; Dictionary::Ptr params = make_shared(); params->Set("service", service->GetName()); - params->Set("id", comment->Get("id")); + params->Set("id", comment->GetId()); Dictionary::Ptr message = make_shared(); message->Set("jsonrpc", "2.0"); @@ -1206,11 +1206,10 @@ void ClusterListener::MessageHandler(const Endpoint::Ptr& sender, const Dictiona return; } - Dictionary::Ptr comment = params->Get("comment"); + Comment::Ptr comment = params->Get("comment"); - long type = static_cast(comment->Get("entry_type")); - service->AddComment(static_cast(type), comment->Get("author"), - comment->Get("text"), comment->Get("expire_time"), comment->Get("id"), sender->GetName()); + service->AddComment(comment->GetEntryType(), comment->GetAuthor(), + comment->GetText(), comment->GetExpireTime(), comment->GetId(), sender->GetName()); AsyncRelayMessage(sender, message, true); } else if (message->Get("method") == "cluster::RemoveComment") { diff --git a/components/cluster/clusterlistener.h b/components/cluster/clusterlistener.h index 74650c621..8090fb451 100644 --- a/components/cluster/clusterlistener.h +++ b/components/cluster/clusterlistener.h @@ -92,8 +92,8 @@ private: void EnablePassiveChecksChangedHandler(const Service::Ptr& service, bool enabled, const String& authority); void EnableNotificationsChangedHandler(const Service::Ptr& service, bool enabled, const String& authority); void EnableFlappingChangedHandler(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 CommentAddedHandler(const Service::Ptr& service, const Comment::Ptr& comment, const String& authority); + void CommentRemovedHandler(const Service::Ptr& service, const Comment::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 AcknowledgementSetHandler(const Service::Ptr& service, const String& author, const String& comment, AcknowledgementType type, double expiry, const String& authority); diff --git a/components/compat/statusdatawriter.cpp b/components/compat/statusdatawriter.cpp index cb69a0998..8cfe29c4a 100644 --- a/components/compat/statusdatawriter.cpp +++ b/components/compat/statusdatawriter.cpp @@ -76,7 +76,7 @@ void StatusDataWriter::DumpComments(std::ostream& fp, const Service::Ptr& owner, ObjectLock olock(comments); String id; - Dictionary::Ptr comment; + Comment::Ptr comment; BOOST_FOREACH(boost::tie(id, comment), comments) { if (Service::IsCommentExpired(comment)) continue; @@ -88,14 +88,14 @@ void StatusDataWriter::DumpComments(std::ostream& fp, const Service::Ptr& owner, << "\t" << "service_description=" << owner->GetShortName() << "\n"; fp << "\t" << "host_name=" << host->GetName() << "\n" - << "\t" << "comment_id=" << static_cast(comment->Get("legacy_id")) << "\n" - << "\t" << "entry_time=" << static_cast(comment->Get("entry_time")) << "\n" - << "\t" << "entry_type=" << static_cast(comment->Get("entry_type")) << "\n" + << "\t" << "comment_id=" << comment->GetLegacyId() << "\n" + << "\t" << "entry_time=" << comment->GetEntryTime() << "\n" + << "\t" << "entry_type=" << comment->GetEntryType() << "\n" << "\t" << "persistent=" << 1 << "\n" - << "\t" << "author=" << static_cast(comment->Get("author")) << "\n" - << "\t" << "comment_data=" << static_cast(comment->Get("text")) << "\n" - << "\t" << "expires=" << (static_cast(comment->Get("expire_time")) != 0 ? 1 : 0) << "\n" - << "\t" << "expire_time=" << static_cast(comment->Get("expire_time")) << "\n" + << "\t" << "author=" << comment->GetAuthor() << "\n" + << "\t" << "comment_data=" << comment->GetText() << "\n" + << "\t" << "expires=" << (comment->GetExpireTime() != 0 ? 1 : 0) << "\n" + << "\t" << "expire_time=" << comment->GetExpireTime() << "\n" << "\t" << "}" << "\n" << "\n"; } diff --git a/components/livestatus/commentstable.cpp b/components/livestatus/commentstable.cpp index f261911f2..f58d55367 100644 --- a/components/livestatus/commentstable.cpp +++ b/components/livestatus/commentstable.cpp @@ -78,42 +78,42 @@ Object::Ptr CommentsTable::ServiceAccessor(const Value& row, const Column::Objec Value CommentsTable::AuthorAccessor(const Value& row) { - Dictionary::Ptr comment = Service::GetCommentByID(row); + Comment::Ptr comment = Service::GetCommentByID(row); if (!comment) return Empty; - return comment->Get("author"); + return comment->GetAuthor(); } Value CommentsTable::CommentAccessor(const Value& row) { - Dictionary::Ptr comment = Service::GetCommentByID(row); + Comment::Ptr comment = Service::GetCommentByID(row); if (!comment) return Empty; - return comment->Get("text"); + return comment->GetText(); } Value CommentsTable::IdAccessor(const Value& row) { - Dictionary::Ptr comment = Service::GetCommentByID(row); + Comment::Ptr comment = Service::GetCommentByID(row); if (!comment) return Empty; - return comment->Get("legacy_id"); + return comment->GetLegacyId(); } Value CommentsTable::EntryTimeAccessor(const Value& row) { - Dictionary::Ptr comment = Service::GetCommentByID(row); + Comment::Ptr comment = Service::GetCommentByID(row); if (!comment) return Empty; - return static_cast(comment->Get("entry_time")); + return static_cast(comment->GetEntryTime()); } Value CommentsTable::TypeAccessor(const Value& row) @@ -138,30 +138,30 @@ Value CommentsTable::IsServiceAccessor(const Value& row) Value CommentsTable::EntryTypeAccessor(const Value& row) { - Dictionary::Ptr comment = Service::GetCommentByID(row); + Comment::Ptr comment = Service::GetCommentByID(row); if (!comment) return Empty; - return comment->Get("entry_type"); + return comment->GetEntryType(); } Value CommentsTable::ExpiresAccessor(const Value& row) { - Dictionary::Ptr comment = Service::GetCommentByID(row); + Comment::Ptr comment = Service::GetCommentByID(row); if (!comment) return Empty; - return comment->Get("expires"); + return comment->GetExpireTime() != 0; } Value CommentsTable::ExpireTimeAccessor(const Value& row) { - Dictionary::Ptr comment = Service::GetCommentByID(row); + Comment::Ptr comment = Service::GetCommentByID(row); if (!comment) return Empty; - return static_cast(comment->Get("expire_time")); + return static_cast(comment->GetExpireTime()); } diff --git a/components/livestatus/hoststable.cpp b/components/livestatus/hoststable.cpp index efa9f88fb..45641a647 100644 --- a/components/livestatus/hoststable.cpp +++ b/components/livestatus/hoststable.cpp @@ -1493,7 +1493,7 @@ Value HostsTable::CommentsAccessor(const Value& row) ObjectLock olock(comments); String id; - Dictionary::Ptr comment; + Comment::Ptr comment; BOOST_FOREACH(boost::tie(id, comment), comments) { if (!comment) @@ -1502,7 +1502,7 @@ Value HostsTable::CommentsAccessor(const Value& row) if (Service::IsCommentExpired(comment)) continue; - ids->Add(comment->Get("legacy_id")); + ids->Add(comment->GetLegacyId()); } return ids; @@ -1528,7 +1528,7 @@ Value HostsTable::CommentsWithInfoAccessor(const Value& row) ObjectLock olock(comments); String id; - Dictionary::Ptr comment; + Comment::Ptr comment; BOOST_FOREACH(boost::tie(id, comment), comments) { if (!comment) @@ -1538,9 +1538,9 @@ Value HostsTable::CommentsWithInfoAccessor(const Value& row) continue; Array::Ptr comment_info = make_shared(); - comment_info->Add(comment->Get("legacy_id")); - comment_info->Add(comment->Get("author")); - comment_info->Add(comment->Get("text")); + comment_info->Add(comment->GetLegacyId()); + comment_info->Add(comment->GetAuthor()); + comment_info->Add(comment->GetText()); ids->Add(comment_info); } @@ -1567,7 +1567,7 @@ Value HostsTable::CommentsWithExtraInfoAccessor(const Value& row) ObjectLock olock(comments); String id; - Dictionary::Ptr comment; + Comment::Ptr comment; BOOST_FOREACH(boost::tie(id, comment), comments) { if (!comment) @@ -1577,11 +1577,11 @@ Value HostsTable::CommentsWithExtraInfoAccessor(const Value& row) continue; Array::Ptr comment_info = make_shared(); - comment_info->Add(comment->Get("legacy_id")); - comment_info->Add(comment->Get("author")); - comment_info->Add(comment->Get("text")); - comment_info->Add(comment->Get("entry_type")); - comment_info->Add(static_cast(comment->Get("entry_time"))); + comment_info->Add(comment->GetLegacyId()); + comment_info->Add(comment->GetAuthor()); + comment_info->Add(comment->GetText()); + comment_info->Add(comment->GetEntryType()); + comment_info->Add(static_cast(comment->GetEntryTime())); ids->Add(comment_info); } diff --git a/components/livestatus/servicestable.cpp b/components/livestatus/servicestable.cpp index f15e7bb88..247a55be4 100644 --- a/components/livestatus/servicestable.cpp +++ b/components/livestatus/servicestable.cpp @@ -1106,7 +1106,7 @@ Value ServicesTable::CommentsAccessor(const Value& row) ObjectLock olock(comments); String id; - Dictionary::Ptr comment; + Comment::Ptr comment; BOOST_FOREACH(boost::tie(id, comment), comments) { if (!comment) @@ -1115,7 +1115,7 @@ Value ServicesTable::CommentsAccessor(const Value& row) if (Service::IsCommentExpired(comment)) continue; - ids->Add(comment->Get("legacy_id")); + ids->Add(comment->GetLegacyId()); } return ids; @@ -1135,7 +1135,7 @@ Value ServicesTable::CommentsWithInfoAccessor(const Value& row) ObjectLock olock(comments); String id; - Dictionary::Ptr comment; + Comment::Ptr comment; BOOST_FOREACH(boost::tie(id, comment), comments) { if (!comment) @@ -1145,9 +1145,9 @@ Value ServicesTable::CommentsWithInfoAccessor(const Value& row) continue; Array::Ptr comment_info = make_shared(); - comment_info->Add(comment->Get("legacy_id")); - comment_info->Add(comment->Get("author")); - comment_info->Add(comment->Get("text")); + comment_info->Add(comment->GetLegacyId()); + comment_info->Add(comment->GetAuthor()); + comment_info->Add(comment->GetText()); ids->Add(comment_info); } @@ -1168,7 +1168,7 @@ Value ServicesTable::CommentsWithExtraInfoAccessor(const Value& row) ObjectLock olock(comments); String id; - Dictionary::Ptr comment; + Comment::Ptr comment; BOOST_FOREACH(boost::tie(id, comment), comments) { if (!comment) @@ -1178,11 +1178,11 @@ Value ServicesTable::CommentsWithExtraInfoAccessor(const Value& row) continue; Array::Ptr comment_info = make_shared(); - comment_info->Add(comment->Get("legacy_id")); - comment_info->Add(comment->Get("author")); - comment_info->Add(comment->Get("text")); - comment_info->Add(comment->Get("entry_type")); - comment_info->Add(static_cast(comment->Get("entry_time"))); + comment_info->Add(comment->GetLegacyId()); + comment_info->Add(comment->GetAuthor()); + comment_info->Add(comment->GetText()); + comment_info->Add(comment->GetEntryType()); + comment_info->Add(static_cast(comment->GetEntryTime())); ids->Add(comment_info); } diff --git a/lib/db_ido/servicedbobject.cpp b/lib/db_ido/servicedbobject.cpp index c4ab1f64a..f3507ca69 100644 --- a/lib/db_ido/servicedbobject.cpp +++ b/lib/db_ido/servicedbobject.cpp @@ -371,23 +371,23 @@ void ServiceDbObject::AddComments(const Service::Ptr& service) ObjectLock olock(comments); String comment_id; - Dictionary::Ptr comment; + Comment::Ptr comment; BOOST_FOREACH(boost::tie(comment_id, comment), comments) { AddComment(service, comment); } } -void ServiceDbObject::AddComment(const Service::Ptr& service, const Dictionary::Ptr& comment) +void ServiceDbObject::AddComment(const Service::Ptr& service, const Comment::Ptr& comment) { AddCommentInternal(service, comment, false); } -void ServiceDbObject::AddCommentHistory(const Service::Ptr& service, const Dictionary::Ptr& comment) +void ServiceDbObject::AddCommentHistory(const Service::Ptr& service, const Comment::Ptr& comment) { AddCommentInternal(service, comment, true); } -void ServiceDbObject::AddCommentInternal(const Service::Ptr& service, const Dictionary::Ptr& comment, bool historical) +void ServiceDbObject::AddCommentInternal(const Service::Ptr& service, const Comment::Ptr& comment, bool historical) { Host::Ptr host = service->GetHost(); @@ -399,48 +399,48 @@ void ServiceDbObject::AddCommentInternal(const Service::Ptr& service, const Dict return; } - Log(LogDebug, "db_ido", "adding service comment (id = " + comment->Get("legacy_id") + ") for '" + service->GetName() + "'"); + Log(LogDebug, "db_ido", "adding service comment (id = " + Convert::ToString(comment->GetLegacyId()) + ") for '" + service->GetName() + "'"); /* add the service comment */ AddCommentByType(service, comment, historical); /* add the hostcheck service comment to the host as well */ if (host->GetCheckService() == service) { - Log(LogDebug, "db_ido", "adding host comment (id = " + comment->Get("legacy_id") + ") for '" + host->GetName() + "'"); + Log(LogDebug, "db_ido", "adding host comment (id = " + Convert::ToString(comment->GetLegacyId()) + ") for '" + host->GetName() + "'"); AddCommentByType(host, comment, historical); } } -void ServiceDbObject::AddCommentByType(const DynamicObject::Ptr& object, const Dictionary::Ptr& comment, bool historical) +void ServiceDbObject::AddCommentByType(const DynamicObject::Ptr& object, const Comment::Ptr& comment, bool historical) { - unsigned long entry_time = static_cast(comment->Get("entry_time")); - unsigned long entry_time_usec = (comment->Get("entry_time") - entry_time) * 1000 * 1000; + unsigned long entry_time = static_cast(comment->GetEntryTime()); + unsigned long entry_time_usec = (comment->GetEntryTime() - entry_time) * 1000 * 1000; Dictionary::Ptr fields1 = make_shared(); fields1->Set("entry_time", DbValue::FromTimestamp(entry_time)); fields1->Set("entry_time_usec", entry_time_usec); - fields1->Set("entry_type", comment->Get("entry_type")); + fields1->Set("entry_type", comment->GetEntryType()); fields1->Set("object_id", object); if (object->GetType() == DynamicType::GetByName("Host")) { fields1->Set("comment_type", 2); /* requires idoutils 1.10 schema fix */ - fields1->Set("internal_comment_id", comment->Get("legacy_id")); + fields1->Set("internal_comment_id", comment->GetLegacyId()); } else if (object->GetType() == DynamicType::GetByName("Service")) { fields1->Set("comment_type", 1); - fields1->Set("internal_comment_id", comment->Get("legacy_id")); + fields1->Set("internal_comment_id", comment->GetLegacyId()); } else { Log(LogDebug, "db_ido", "unknown object type for adding comment."); return; } fields1->Set("comment_time", DbValue::FromTimestamp(entry_time)); /* same as entry_time */ - fields1->Set("author_name", comment->Get("author")); - fields1->Set("comment_data", comment->Get("text")); + fields1->Set("author_name", comment->GetAuthor()); + fields1->Set("comment_data", comment->GetText()); fields1->Set("is_persistent", 1); fields1->Set("comment_source", 1); /* external */ - fields1->Set("expires", (comment->Get("expire_time") > 0) ? 1 : 0); - fields1->Set("expiration_time", comment->Get("expire_time")); + fields1->Set("expires", (comment->GetExpireTime() > 0) ? 1 : 0); + fields1->Set("expiration_time", comment->GetExpireTime()); fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */ DbQuery query1; @@ -479,7 +479,7 @@ void ServiceDbObject::RemoveComments(const Service::Ptr& service) } } -void ServiceDbObject::RemoveComment(const Service::Ptr& service, const Dictionary::Ptr& comment) +void ServiceDbObject::RemoveComment(const Service::Ptr& service, const Comment::Ptr& comment) { Host::Ptr host = service->GetHost(); @@ -491,7 +491,7 @@ void ServiceDbObject::RemoveComment(const Service::Ptr& service, const Dictionar return; } - Log(LogDebug, "db_ido", "removing service comment (id = " + comment->Get("legacy_id") + ") for '" + service->GetName() + "'"); + Log(LogDebug, "db_ido", "removing service comment (id = " + Convert::ToString(comment->GetLegacyId()) + ") for '" + service->GetName() + "'"); /* Status */ DbQuery query1; @@ -500,7 +500,7 @@ void ServiceDbObject::RemoveComment(const Service::Ptr& service, const Dictionar query1.Category = DbCatComment; query1.WhereCriteria = make_shared(); query1.WhereCriteria->Set("object_id", service); - query1.WhereCriteria->Set("internal_comment_id", comment->Get("legacy_id")); + query1.WhereCriteria->Set("internal_comment_id", comment->GetLegacyId()); OnQuery(query1); /* delete hostcheck service's host comments */ @@ -510,7 +510,7 @@ void ServiceDbObject::RemoveComment(const Service::Ptr& service, const Dictionar } /* History - update deletion time for service (and host in case) */ - unsigned long entry_time = static_cast(comment->Get("entry_time")); + unsigned long entry_time = static_cast(comment->GetEntryTime()); double now = Utility::GetTime(); Dictionary::Ptr time_bag = CompatUtility::ConvertTimestamp(now); @@ -526,7 +526,7 @@ void ServiceDbObject::RemoveComment(const Service::Ptr& service, const Dictionar query2.Fields = fields2; query2.WhereCriteria = make_shared(); - query2.WhereCriteria->Set("internal_comment_id", comment->Get("legacy_id")); + query2.WhereCriteria->Set("internal_comment_id", comment->GetLegacyId()); query2.WhereCriteria->Set("comment_time", DbValue::FromTimestamp(entry_time)); query2.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */ diff --git a/lib/db_ido/servicedbobject.h b/lib/db_ido/servicedbobject.h index 6126591e3..0793fadd0 100644 --- a/lib/db_ido/servicedbobject.h +++ b/lib/db_ido/servicedbobject.h @@ -75,8 +75,8 @@ protected: virtual void OnStatusUpdate(void); private: - static void AddCommentInternal(const Service::Ptr& service, const Dictionary::Ptr& comment, bool historical); - static void AddCommentByType(const DynamicObject::Ptr& object, const Dictionary::Ptr& comment, bool historical); + 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 AddComments(const Service::Ptr& service); static void RemoveComments(const Service::Ptr& service); @@ -88,16 +88,16 @@ private: static void AddLogHistory(const Service::Ptr& service, String buffer, LogEntryType type); /* Status */ - static void AddComment(const Service::Ptr& service, const Dictionary::Ptr& comment); - static void RemoveComment(const Service::Ptr& service, const Dictionary::Ptr& comment); + static void AddComment(const Service::Ptr& service, const Comment::Ptr& comment); + static void RemoveComment(const Service::Ptr& service, const Comment::Ptr& comment); static void AddDowntime(const Service::Ptr& service, const Dictionary::Ptr& downtime); static void RemoveDowntime(const Service::Ptr& service, const Dictionary::Ptr& downtime); static void TriggerDowntime(const Service::Ptr& service, const Dictionary::Ptr& downtime); /* History */ - static void AddCommentHistory(const Service::Ptr& service, const Dictionary::Ptr& comment); - static void AddDowntimeHistory(const Service::Ptr& service, const Dictionary::Ptr& downtime); + static void AddCommentHistory(const Service::Ptr& service, const Comment::Ptr& comment); + static void AddDowntimeHistory(const Service::Ptr& service, const Dictionary::Ptr& downtime); static void AddAcknowledgementHistory(const Service::Ptr& service, const String& author, const String& comment, AcknowledgementType type, double expiry); static void AddContactNotificationHistory(const Service::Ptr& service, const User::Ptr& user); static void AddNotificationHistory(const Service::Ptr& service, const std::set& users, NotificationType type, const CheckResult::Ptr& cr, const String& author, const String& text); diff --git a/lib/icinga/CMakeLists.txt b/lib/icinga/CMakeLists.txt index d7f4bede8..dffd4d075 100644 --- a/lib/icinga/CMakeLists.txt +++ b/lib/icinga/CMakeLists.txt @@ -18,6 +18,7 @@ mkclass_target(checkcommand.ti checkcommand.th) mkclass_target(checkresult.ti checkresult.th) mkclass_target(command.ti command.th) +mkclass_target(comment.ti comment.th) mkclass_target(domain.ti domain.th) mkclass_target(eventcommand.ti eventcommand.th) mkclass_target(hostgroup.ti hostgroup.th) @@ -36,8 +37,8 @@ mkembedconfig_target(icinga-type.conf icinga-type.cpp) add_library(icinga SHARED api.cpp api.h checkcommand.cpp checkcommand.th checkresult.cpp checkresult.th - cib.cpp command.cpp command.th compatutility.cpp domain.cpp domain.th - eventcommand.cpp eventcommand.th externalcommandprocessor.cpp host.cpp + cib.cpp command.cpp command.th comment.cpp comment.th compatutility.cpp + domain.cpp domain.th eventcommand.cpp eventcommand.th externalcommandprocessor.cpp host.cpp host.th hostgroup.cpp hostgroup.th icingaapplication.cpp icingaapplication.th macroprocessor.cpp macroresolver.cpp notificationcommand.cpp notificationcommand.th notification.cpp notification.th perfdatavalue.cpp perfdatavalue.th diff --git a/lib/icinga/comment.cpp b/lib/icinga/comment.cpp new file mode 100644 index 000000000..895fcc45e --- /dev/null +++ b/lib/icinga/comment.cpp @@ -0,0 +1,25 @@ +/****************************************************************************** + * Icinga 2 * + * Copyright (C) 2012-2013 Icinga Development Team (http://www.icinga.org/) * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software Foundation * + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * + ******************************************************************************/ + +#include "icinga/comment.h" +#include "base/dynamictype.h" + +using namespace icinga; + +REGISTER_TYPE(Comment); diff --git a/lib/icinga/comment.h b/lib/icinga/comment.h new file mode 100644 index 000000000..a54a94563 --- /dev/null +++ b/lib/icinga/comment.h @@ -0,0 +1,42 @@ +/****************************************************************************** + * Icinga 2 * + * Copyright (C) 2012-2013 Icinga Development Team (http://www.icinga.org/) * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software Foundation * + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * + ******************************************************************************/ + +#ifndef COMMENT_H +#define COMMENT_H + +#include "icinga/i2-icinga.h" +#include "icinga/comment.th" + +namespace icinga +{ + +/** + * A service comment. + * + * @ingroup icinga + */ +class I2_ICINGA_API Comment : public ObjectImpl +{ +public: + DECLARE_PTR_TYPEDEFS(Comment); +}; + +} + +#endif /* COMMENT_H */ diff --git a/lib/icinga/comment.ti b/lib/icinga/comment.ti new file mode 100644 index 000000000..955832baf --- /dev/null +++ b/lib/icinga/comment.ti @@ -0,0 +1,30 @@ +namespace icinga +{ + +code {{{ +/** + * The type of a service comment. + * + * @ingroup icinga + */ +enum CommentType +{ + CommentUser = 1, + CommentDowntime = 2, + CommentFlapping = 3, + CommentAcknowledgement = 4 +}; +}}} + +class Comment +{ + [state] String id; + [state] double entry_time; + [state, enum] CommentType entry_type; + [state] String author; + [state] String text; + [state] double expire_time; + [state] int legacy_id; +}; + +} diff --git a/lib/icinga/service-comment.cpp b/lib/icinga/service-comment.cpp index 775e2ed3b..89b8c28ac 100644 --- a/lib/icinga/service-comment.cpp +++ b/lib/icinga/service-comment.cpp @@ -34,8 +34,8 @@ static std::map l_LegacyCommentsCache; static std::map l_CommentsCache; static Timer::Ptr l_CommentsExpireTimer; -boost::signals2::signal Service::OnCommentAdded; -boost::signals2::signal Service::OnCommentRemoved; +boost::signals2::signal Service::OnCommentAdded; +boost::signals2::signal Service::OnCommentRemoved; int Service::GetNextCommentID(void) { @@ -54,13 +54,13 @@ String Service::AddComment(CommentType entryType, const String& author, else uid = id; - Dictionary::Ptr comment = make_shared(); - comment->Set("id", uid); - comment->Set("entry_time", Utility::GetTime()); - comment->Set("entry_type", entryType); - comment->Set("author", author); - comment->Set("text", text); - comment->Set("expire_time", expireTime); + Comment::Ptr comment = make_shared(); + comment->SetId(uid);; + comment->SetEntryTime(Utility::GetTime()); + comment->SetEntryType(entryType); + comment->SetAuthor(author); + comment->SetText(text); + comment->SetExpireTime(expireTime); int legacy_id; @@ -69,7 +69,7 @@ String Service::AddComment(CommentType entryType, const String& author, legacy_id = l_NextCommentID++; } - comment->Set("legacy_id", legacy_id); + comment->SetLegacyId(legacy_id); GetComments()->Set(uid, comment); @@ -111,12 +111,12 @@ void Service::RemoveComment(const String& id, const String& authority) ObjectLock olock(owner); - Dictionary::Ptr comment = comments->Get(id); + Comment::Ptr comment = comments->Get(id); if (!comment) return; - int legacy_id = comment->Get("legacy_id"); + int legacy_id = comment->GetLegacyId(); comments->Remove(id); @@ -148,24 +148,24 @@ Service::Ptr Service::GetOwnerByCommentID(const String& id) return l_CommentsCache[id].lock(); } -Dictionary::Ptr Service::GetCommentByID(const String& id) +Comment::Ptr Service::GetCommentByID(const String& id) { Service::Ptr owner = GetOwnerByCommentID(id); if (!owner) - return Dictionary::Ptr(); + return Comment::Ptr(); Dictionary::Ptr comments = owner->GetComments(); if (comments) return comments->Get(id); - return Dictionary::Ptr(); + return Comment::Ptr(); } -bool Service::IsCommentExpired(const Dictionary::Ptr& comment) +bool Service::IsCommentExpired(const Comment::Ptr& comment) { - double expire_time = comment->Get("expire_time"); + double expire_time = comment->GetExpireTime(); return (expire_time != 0 && expire_time < Utility::GetTime()); } @@ -181,9 +181,9 @@ void Service::AddCommentsToCache(void) boost::mutex::scoped_lock lock(l_CommentMutex); String id; - Dictionary::Ptr comment; + Comment::Ptr comment; BOOST_FOREACH(boost::tie(id, comment), comments) { - int legacy_id = comment->Get("legacy_id"); + int legacy_id = comment->GetLegacyId(); if (legacy_id >= l_NextCommentID) l_NextCommentID = legacy_id + 1; @@ -203,9 +203,9 @@ void Service::RemoveCommentsByType(int type) ObjectLock olock(comments); String id; - Dictionary::Ptr comment; + Comment::Ptr comment; BOOST_FOREACH(boost::tie(id, comment), comments) { - if (comment->Get("entry_type") == type) + if (comment->GetEntryType() == type) removedComments.push_back(id); } } @@ -225,7 +225,7 @@ void Service::RemoveExpiredComments(void) ObjectLock olock(comments); String id; - Dictionary::Ptr comment; + Comment::Ptr comment; BOOST_FOREACH(boost::tie(id, comment), comments) { if (IsCommentExpired(comment)) expiredComments.push_back(id); diff --git a/lib/icinga/service.h b/lib/icinga/service.h index fed2bc84d..ecd0e1689 100644 --- a/lib/icinga/service.h +++ b/lib/icinga/service.h @@ -26,6 +26,7 @@ #include "icinga/host.h" #include "icinga/timeperiod.h" #include "icinga/notification.h" +#include "icinga/comment.h" #include "base/i2-base.h" #include "base/array.h" #include @@ -34,19 +35,6 @@ namespace icinga { -/** - * The type of a service comment. - * - * @ingroup icinga - */ -enum CommentType -{ - CommentUser = 1, - CommentDowntime = 2, - CommentFlapping = 3, - CommentAcknowledgement = 4 -}; - /** * The state of a service downtime. * @@ -201,8 +189,8 @@ public: static boost::signals2::signal OnNotificationsRequested; static boost::signals2::signal OnNotificationSentToUser; static boost::signals2::signal&, const NotificationType&, const CheckResult::Ptr&, const String&, const String&)> OnNotificationSentToAllUsers; - static boost::signals2::signal OnCommentAdded; - static boost::signals2::signal OnCommentRemoved; + static boost::signals2::signal OnCommentAdded; + static boost::signals2::signal OnCommentRemoved; static boost::signals2::signal OnDowntimeAdded; static boost::signals2::signal OnDowntimeRemoved; static boost::signals2::signal OnFlappingChanged; @@ -253,9 +241,9 @@ public: static String GetCommentIDFromLegacyID(int id); static Service::Ptr GetOwnerByCommentID(const String& id); - static Dictionary::Ptr GetCommentByID(const String& id); + static Comment::Ptr GetCommentByID(const String& id); - static bool IsCommentExpired(const Dictionary::Ptr& comment); + static bool IsCommentExpired(const Comment::Ptr& comment); /* Notifications */ bool GetEnableNotifications(void) const;