/******************************************************************************
* Icinga 2 *
- * Copyright (C) 2012-2015 Icinga Development Team (http://www.icinga.org) *
+ * Copyright (C) 2012-2018 Icinga Development Team (https://www.icinga.com/) *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
#include "livestatus/hoststable.hpp"
#include "livestatus/servicestable.hpp"
#include "icinga/service.hpp"
-#include "base/dynamictype.hpp"
+#include "base/configtype.hpp"
#include "base/objectlock.hpp"
#include <boost/tuple/tuple.hpp>
-#include <boost/foreach.hpp>
using namespace icinga;
-CommentsTable::CommentsTable(void)
+CommentsTable::CommentsTable()
{
AddColumns(this);
}
void CommentsTable::AddColumns(Table *table, const String& prefix,
- const Column::ObjectAccessor& objectAccessor)
+ const Column::ObjectAccessor& objectAccessor)
{
table->AddColumn(prefix + "author", Column(&CommentsTable::AuthorAccessor, objectAccessor));
table->AddColumn(prefix + "comment", Column(&CommentsTable::CommentAccessor, objectAccessor));
table->AddColumn(prefix + "expire_time", Column(&CommentsTable::ExpireTimeAccessor, objectAccessor));
/* order is important - host w/o services must not be empty */
- ServicesTable::AddColumns(table, "service_", boost::bind(&CommentsTable::ServiceAccessor, _1, objectAccessor));
- HostsTable::AddColumns(table, "host_", boost::bind(&CommentsTable::HostAccessor, _1, objectAccessor));
+ ServicesTable::AddColumns(table, "service_", std::bind(&CommentsTable::ServiceAccessor, _1, objectAccessor));
+ HostsTable::AddColumns(table, "host_", std::bind(&CommentsTable::HostAccessor, _1, objectAccessor));
}
-String CommentsTable::GetName(void) const
+String CommentsTable::GetName() const
{
return "comments";
}
-String CommentsTable::GetPrefix(void) const
+String CommentsTable::GetPrefix() const
{
return "comment";
}
void CommentsTable::FetchRows(const AddRowFunction& addRowFn)
{
- BOOST_FOREACH(const Host::Ptr& host, DynamicType::GetObjectsByType<Host>()) {
- Dictionary::Ptr comments = host->GetComments();
-
- ObjectLock olock(comments);
-
- String id;
- Comment::Ptr comment;
- BOOST_FOREACH(tie(id, comment), comments) {
- if (Host::GetOwnerByCommentID(id) == host) {
- if (!addRowFn(comment, LivestatusGroupByNone, Empty))
- return;
- }
- }
- }
-
- BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjectsByType<Service>()) {
- Dictionary::Ptr comments = service->GetComments();
-
- ObjectLock olock(comments);
-
- String id;
- Comment::Ptr comment;
- BOOST_FOREACH(tie(id, comment), comments) {
- if (Service::GetOwnerByCommentID(id) == service) {
- if (!addRowFn(comment, LivestatusGroupByNone, Empty))
- return;
- }
- }
+ for (const Comment::Ptr& comment : ConfigType::GetObjectsByType<Comment>()) {
+ if (!addRowFn(comment, LivestatusGroupByNone, Empty))
+ return;
}
}
{
Comment::Ptr comment = static_cast<Comment::Ptr>(row);
- Checkable::Ptr checkable = Checkable::GetOwnerByCommentID(comment->GetId());
+ Checkable::Ptr checkable = comment->GetCheckable();
Host::Ptr host;
Service::Ptr service;
{
Comment::Ptr comment = static_cast<Comment::Ptr>(row);
- Checkable::Ptr checkable = Checkable::GetOwnerByCommentID(comment->GetId());
+ Checkable::Ptr checkable = comment->GetCheckable();
Host::Ptr host;
Service::Ptr service;
Value CommentsTable::TypeAccessor(const Value& row)
{
Comment::Ptr comment = static_cast<Comment::Ptr>(row);
- Checkable::Ptr checkable = Checkable::GetOwnerByCommentID(comment->GetId());
+ Checkable::Ptr checkable = comment->GetCheckable();
if (!checkable)
return Empty;
Value CommentsTable::IsServiceAccessor(const Value& row)
{
Comment::Ptr comment = static_cast<Comment::Ptr>(row);
- Checkable::Ptr checkable = Checkable::GetOwnerByCommentID(comment->GetId());
+ Checkable::Ptr checkable = comment->GetCheckable();
if (!checkable)
return Empty;