]> granicus.if.org Git - icinga2/blobdiff - lib/livestatus/downtimestable.cpp
Merge pull request #6531 from Icinga/feature/zone-all_parents
[icinga2] / lib / livestatus / downtimestable.cpp
index e9b8ed7c9eb3e13461c60bc0528fc58028e07d00..008a391acdaaa676e5f50ab7db9d3e4cb8cf1f49 100644 (file)
@@ -1,6 +1,6 @@
 /******************************************************************************
  * 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));
@@ -49,50 +48,25 @@ void DowntimesTable::AddColumns(Table *table, const String& prefix,
        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;
        }
 }
 
@@ -100,7 +74,7 @@ Object::Ptr DowntimesTable::HostAccessor(const Value& row, const Column::ObjectA
 {
        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;
@@ -113,7 +87,7 @@ Object::Ptr DowntimesTable::ServiceAccessor(const Value& row, const Column::Obje
 {
        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;
@@ -154,13 +128,13 @@ Value DowntimesTable::TypeAccessor(const Value& row)
 {
        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);
 }
@@ -197,5 +171,12 @@ Value DowntimesTable::TriggeredByAccessor(const Value& row)
 {
        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;
 }