]> granicus.if.org Git - icinga2/commitdiff
Livestatus: Fix missing host downtimes/comments
authorMichael Friedrich <michael.friedrich@netways.de>
Fri, 5 Dec 2014 15:31:42 +0000 (16:31 +0100)
committerMichael Friedrich <michael.friedrich@netways.de>
Fri, 5 Dec 2014 15:32:14 +0000 (16:32 +0100)
fixes #7064

doc/9-appendix.md
lib/livestatus/commentstable.cpp
lib/livestatus/commentstable.hpp
lib/livestatus/downtimestable.cpp
lib/livestatus/downtimestable.hpp
test/livestatus/queries/comment/comment_short [new file with mode: 0644]
test/livestatus/queries/downtime/downtime_short [new file with mode: 0644]

index 30765d928fd55eaced819ee07dad14854db10bd5..beaea1680b544b8f9c11c4f70bb2062b3c4da585 100644 (file)
@@ -571,7 +571,8 @@ Not supported: `neb_callbacks`, `neb_callbacks_rate`, `requests`, `requests_rate
   entry_type            | int       | .
   expires               | int       | .
   expire_time           | string    | Seconds.
-  service_              | join      | Prefix for attributes from implicit join with services table (and implicit host table).
+  service_              | join      | Prefix for attributes from implicit join with services table.
+  host_                 | join      | Prefix for attributes from implicit join with hosts table.
 
 
 #### <a id="schema-livestatus-downtimes-table-attributes"></a> Livestatus Downtimes Table Attributes
@@ -582,7 +583,7 @@ Not supported: `neb_callbacks`, `neb_callbacks_rate`, `requests`, `requests_rate
   comment               | string    | .
   id                    | int       | legacy_id.
   entry_time            | string    | Seconds.
-  type                  | int       | 1=host, 2=service.
+  type                  | int       | 1=active, 0=pending.
   is_service            | int       | .
   start_time            | string    | Seconds.
   end_time              | string    | Seconds.
@@ -591,7 +592,8 @@ Not supported: `neb_callbacks`, `neb_callbacks_rate`, `requests`, `requests_rate
   triggered_by          | int       | legacy_id.
   triggers              | int       | NEW in Icinga 2.
   trigger_time          | string    | NEW in Icinga 2.
-  service_              | join      | Prefix for attributes from implicit join with services table (and implicit host table).
+  service_              | join      | Prefix for attributes from implicit join with services table.
+  host_                 | join      | Prefix for attributes from implicit join with hosts table.
 
 
 #### <a id="schema-livestatus-timeperiod-table-attributes"></a> Livestatus Timeperiod Table Attributes
index 71cf399f55f62184464732e5079c284c62a01e0d..bf2910bda7d982fda2c5b7e761bf780aaa4db215 100644 (file)
@@ -18,6 +18,7 @@
  ******************************************************************************/
 
 #include "livestatus/commentstable.hpp"
+#include "livestatus/hoststable.hpp"
 #include "livestatus/servicestable.hpp"
 #include "icinga/service.hpp"
 #include "base/dynamictype.hpp"
@@ -47,7 +48,9 @@ void CommentsTable::AddColumns(Table *table, const String& prefix,
        table->AddColumn(prefix + "expires", Column(&CommentsTable::ExpiresAccessor, 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));
 }
 
 String CommentsTable::GetName(void) const
@@ -70,7 +73,8 @@ void CommentsTable::FetchRows(const AddRowFunction& addRowFn)
                String id;
                Comment::Ptr comment;
                BOOST_FOREACH(tie(id, comment), comments) {
-                       addRowFn(comment);
+                       if (Host::GetOwnerByCommentID(id) == host)
+                               addRowFn(comment);
                }
        }
 
@@ -82,15 +86,36 @@ void CommentsTable::FetchRows(const AddRowFunction& addRowFn)
                String id;
                Comment::Ptr comment;
                BOOST_FOREACH(tie(id, comment), comments) {
-                       addRowFn(comment);
+                       if (Service::GetOwnerByCommentID(id) == service)
+                               addRowFn(comment);
                }
        }
 }
 
+Object::Ptr CommentsTable::HostAccessor(const Value& row, const Column::ObjectAccessor&)
+{
+       Comment::Ptr comment = static_cast<Comment::Ptr>(row);
+
+       Checkable::Ptr checkable = Checkable::GetOwnerByCommentID(comment->GetId());
+
+        Host::Ptr host;
+        Service::Ptr service;
+        tie(host, service) = GetHostService(checkable);
+
+       return host;
+}
+
 Object::Ptr CommentsTable::ServiceAccessor(const Value& row, const Column::ObjectAccessor&)
 {
        Comment::Ptr comment = static_cast<Comment::Ptr>(row);
-       return Checkable::GetOwnerByCommentID(comment->GetId()); // XXX: this might return a Host object
+
+       Checkable::Ptr checkable = Checkable::GetOwnerByCommentID(comment->GetId());
+
+        Host::Ptr host;
+        Service::Ptr service;
+        tie(host, service) = GetHostService(checkable);
+
+       return service;
 }
 
 Value CommentsTable::AuthorAccessor(const Value& row)
index 0918c59f946f979488cfbe672491604edb91c306..b6fb6ca4c45fca54c096d196ce40e511d91d915c 100644 (file)
@@ -47,6 +47,7 @@ protected:
        virtual void FetchRows(const AddRowFunction& addRowFn);
 
 private:
+       static Object::Ptr HostAccessor(const Value& row, const Column::ObjectAccessor& parentObjectAccessor);
        static Object::Ptr ServiceAccessor(const Value& row, const Column::ObjectAccessor& parentObjectAccessor);
 
        static Value AuthorAccessor(const Value& row);
index 829261c49689c2f0413e2af2b02740ee29295de8..8d9521ebad851e44ea6bec6cf3da764fca9ca7d1 100644 (file)
@@ -18,6 +18,7 @@
  ******************************************************************************/
 
 #include "livestatus/downtimestable.hpp"
+#include "livestatus/hoststable.hpp"
 #include "livestatus/servicestable.hpp"
 #include "icinga/service.hpp"
 #include "base/dynamictype.hpp"
@@ -47,7 +48,9 @@ void DowntimesTable::AddColumns(Table *table, const String& prefix,
        table->AddColumn(prefix + "duration", Column(&DowntimesTable::DurationAccessor, 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));
 }
 
 String DowntimesTable::GetName(void) const
@@ -62,6 +65,19 @@ String DowntimesTable::GetPrefix(void) const
 
 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)
+                               addRowFn(downtime);
+               }
+       }
+
        BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjectsByType<Service>()) {
                Dictionary::Ptr downtimes = service->GetDowntimes();
 
@@ -76,10 +92,30 @@ void DowntimesTable::FetchRows(const AddRowFunction& addRowFn)
        }
 }
 
+Object::Ptr DowntimesTable::HostAccessor(const Value& row, const Column::ObjectAccessor&)
+{
+       Downtime::Ptr downtime = static_cast<Downtime::Ptr>(row);
+
+       Checkable::Ptr checkable = Checkable::GetOwnerByDowntimeID(downtime->GetId());
+
+        Host::Ptr host;
+        Service::Ptr service;
+        tie(host, service) = GetHostService(checkable);
+
+       return host;
+}
+
 Object::Ptr DowntimesTable::ServiceAccessor(const Value& row, const Column::ObjectAccessor&)
 {
        Downtime::Ptr downtime = static_cast<Downtime::Ptr>(row);
-       return Service::GetOwnerByDowntimeID(downtime->GetId());
+
+       Checkable::Ptr checkable = Checkable::GetOwnerByDowntimeID(downtime->GetId());
+
+        Host::Ptr host;
+        Service::Ptr service;
+        tie(host, service) = GetHostService(checkable);
+
+       return service;
 }
 
 Value DowntimesTable::AuthorAccessor(const Value& row)
index 29435346dbf15e111430d9704ddccfc2cbd66f2f..e92db4eac50d7ea8e5e7e33b31d41c7da062ddb2 100644 (file)
@@ -47,6 +47,7 @@ protected:
        virtual void FetchRows(const AddRowFunction& addRowFn);
 
 private:
+       static Object::Ptr HostAccessor(const Value& row, const Column::ObjectAccessor& parentObjectAccessor);
        static Object::Ptr ServiceAccessor(const Value& row, const Column::ObjectAccessor& parentObjectAccessor);
 
        static Value AuthorAccessor(const Value& row);
diff --git a/test/livestatus/queries/comment/comment_short b/test/livestatus/queries/comment/comment_short
new file mode 100644 (file)
index 0000000..e5c0072
--- /dev/null
@@ -0,0 +1,4 @@
+GET comments
+Columns: id type is_service host_name service_description author comment 
+ResponseHeader: fixed16
+
diff --git a/test/livestatus/queries/downtime/downtime_short b/test/livestatus/queries/downtime/downtime_short
new file mode 100644 (file)
index 0000000..c2e1cf5
--- /dev/null
@@ -0,0 +1,4 @@
+GET downtimes
+Columns: id type is_service host_name service_description author comment start_time end_time
+ResponseHeader: fixed16
+