Livestatus: Fix missing host downtimes/comments

fixes #7064
This commit is contained in:
Michael Friedrich 2014-12-05 16:31:42 +01:00
parent 9f66587d84
commit b81035e352
7 changed files with 80 additions and 7 deletions

View 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

View 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)

View 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);

View 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)

View 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);

View File

@ -0,0 +1,4 @@
GET comments
Columns: id type is_service host_name service_description author comment
ResponseHeader: fixed16

View File

@ -0,0 +1,4 @@
GET downtimes
Columns: id type is_service host_name service_description author comment start_time end_time
ResponseHeader: fixed16