/******************************************************************************
* 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;
-DowntimesTable::DowntimesTable(void)
+DowntimesTable::DowntimesTable()
{
AddColumns(this);
}
void DowntimesTable::AddColumns(Table *table, const String& prefix,
- const Column::ObjectAccessor& objectAccessor)
+ const Column::ObjectAccessor& objectAccessor)
{
table->AddColumn(prefix + "author", Column(&DowntimesTable::AuthorAccessor, objectAccessor));
table->AddColumn(prefix + "comment", Column(&DowntimesTable::CommentAccessor, objectAccessor));
table->AddColumn(prefix + "triggered_by", Column(&DowntimesTable::TriggeredByAccessor, objectAccessor));
/* order is important - host w/o services must not be empty */
- ServicesTable::AddColumns(table, "service_", boost::bind(&DowntimesTable::ServiceAccessor, _1, objectAccessor));
- HostsTable::AddColumns(table, "host_", boost::bind(&DowntimesTable::HostAccessor, _1, objectAccessor));
+ ServicesTable::AddColumns(table, "service_", std::bind(&DowntimesTable::ServiceAccessor, _1, objectAccessor));
+ HostsTable::AddColumns(table, "host_", std::bind(&DowntimesTable::HostAccessor, _1, objectAccessor));
}
-String DowntimesTable::GetName(void) const
+String DowntimesTable::GetName() const
{
return "downtimes";
}
-String DowntimesTable::GetPrefix(void) const
+String DowntimesTable::GetPrefix() const
{
return "downtime";
}
void DowntimesTable::FetchRows(const AddRowFunction& addRowFn)
{
- BOOST_FOREACH(const Host::Ptr& host, DynamicType::GetObjectsByType<Host>()) {
- Dictionary::Ptr downtimes = host->GetDowntimes();
-
- ObjectLock olock(downtimes);
-
- String id;
- Downtime::Ptr downtime;
- BOOST_FOREACH(boost::tie(id, downtime), downtimes) {
- if (Host::GetOwnerByDowntimeID(id) == host) {
- if (!addRowFn(downtime, LivestatusGroupByNone, Empty))
- return;
- }
- }
- }
-
- BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjectsByType<Service>()) {
- Dictionary::Ptr downtimes = service->GetDowntimes();
-
- ObjectLock olock(downtimes);
-
- String id;
- Downtime::Ptr downtime;
- BOOST_FOREACH(boost::tie(id, downtime), downtimes) {
- if (Service::GetOwnerByDowntimeID(id) == service) {
- if (!addRowFn(downtime, LivestatusGroupByNone, Empty))
- return;
- }
- }
+ for (const Downtime::Ptr& downtime : ConfigType::GetObjectsByType<Downtime>()) {
+ if (!addRowFn(downtime, LivestatusGroupByNone, Empty))
+ return;
}
}
{
Downtime::Ptr downtime = static_cast<Downtime::Ptr>(row);
- Checkable::Ptr checkable = Checkable::GetOwnerByDowntimeID(downtime->GetId());
+ Checkable::Ptr checkable = downtime->GetCheckable();
Host::Ptr host;
Service::Ptr service;
{
Downtime::Ptr downtime = static_cast<Downtime::Ptr>(row);
- Checkable::Ptr checkable = Checkable::GetOwnerByDowntimeID(downtime->GetId());
+ Checkable::Ptr checkable = downtime->GetCheckable();
Host::Ptr host;
Service::Ptr service;
{
Downtime::Ptr downtime = static_cast<Downtime::Ptr>(row);
// 1 .. active, 0 .. pending
- return (downtime->IsActive() ? 1 : 0);
+ return (downtime->IsInEffect() ? 1 : 0);
}
Value DowntimesTable::IsServiceAccessor(const Value& row)
{
Downtime::Ptr downtime = static_cast<Downtime::Ptr>(row);
- Checkable::Ptr checkable = Checkable::GetOwnerByDowntimeID(downtime->GetId());
+ Checkable::Ptr checkable = downtime->GetCheckable();
return (dynamic_pointer_cast<Host>(checkable) ? 0 : 1);
}
{
Downtime::Ptr downtime = static_cast<Downtime::Ptr>(row);
- return downtime->GetTriggeredByLegacyId();
+ String triggerDowntimeName = downtime->GetTriggeredBy();
+
+ Downtime::Ptr triggerDowntime = Downtime::GetByName(triggerDowntimeName);
+
+ if (triggerDowntime)
+ return triggerDowntime->GetLegacyId();
+
+ return Empty;
}