From 16adc9a0c57a4145f222a8bfb14a2f898540624b Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Fri, 5 Jul 2013 19:14:10 +0200 Subject: [PATCH] livestatus: add more hosttable todos refs #4372 --- components/livestatus/hoststable.cpp | 61 +++++++++++++++++++++++----- lib/icinga/host.cpp | 2 +- 2 files changed, 51 insertions(+), 12 deletions(-) diff --git a/components/livestatus/hoststable.cpp b/components/livestatus/hoststable.cpp index d5a2df3a7..46ffd06c6 100644 --- a/components/livestatus/hoststable.cpp +++ b/components/livestatus/hoststable.cpp @@ -830,7 +830,30 @@ Value HostsTable::InCheckPeriodAccessor(const Object::Ptr& object) Value HostsTable::ContactsAccessor(const Object::Ptr& object) { - /* TODO */ + /* TODO - host->service->notifications->users */ + /* use hostcheck service */ + Service::Ptr hc = static_pointer_cast(object)->GetHostCheckService(); + + if (!hc) + return Value(); + + std::set allUsers; + std::set users; + + BOOST_FOREACH(const Notification::Ptr& notification, hc->GetNotifications()) { + ObjectLock olock(notification); + + users = notification->GetUsers(); + + std::copy(users.begin(), users.end(), std::inserter(allUsers, allUsers.begin())); + + BOOST_FOREACH(const UserGroup::Ptr& ug, notification->GetGroups()) { + std::set members = ug->GetMembers(); + std::copy(members.begin(), members.end(), std::inserter(allUsers, allUsers.begin())); + } + } + + return Value(); } @@ -901,8 +924,8 @@ Value HostsTable::ChildsAccessor(const Object::Ptr& object) Value HostsTable::NumServicesAccessor(const Object::Ptr& object) { - /* TODO */ - return Value(); + /* duplicate of TotalServices */ + return static_pointer_cast(object)->GetTotalServices(); } Value HostsTable::WorstServiceStateAccessor(const Object::Ptr& object) @@ -973,37 +996,53 @@ Value HostsTable::NumServicesHardUnknownAccessor(const Object::Ptr& object) Value HostsTable::HardStateAccessor(const Object::Ptr& object) { - /* TODO */ - return Value(); + /* use hostcheck service */ + Service::Ptr hc = static_pointer_cast(object)->GetHostCheckService(); + + if (!hc) + return Value(); + + if (hc->GetState() == StateOK) + return StateOK; + if (hc->GetStateType() == StateTypeHard) + return hc->GetState(); + + return hc->GetLastHardState(); } Value HostsTable::PnpgraphPresentAccessor(const Object::Ptr& object) { - /* TODO */ + /* wtf. not supported */ return Value(); } Value HostsTable::StalenessAccessor(const Object::Ptr& object) { - /* TODO */ + /* TODO time since last check normalized on the check_interval */ return Value(); } Value HostsTable::GroupsAccessor(const Object::Ptr& object) { - /* TODO */ - return Value(); + /* TODO create array */ + /* use hostcheck service */ + Service::Ptr hc = static_pointer_cast(object)->GetHostCheckService(); + + if (!hc) + return Value(); + + return hc->GetGroups(); } Value HostsTable::ContactGroupsAccessor(const Object::Ptr& object) { - /* TODO */ + /* TODO create array */ return Value(); } Value HostsTable::ServicesAccessor(const Object::Ptr& object) { - /* TODO */ + /* TODO create array */ return Value(); } diff --git a/lib/icinga/host.cpp b/lib/icinga/host.cpp index caf39b166..635b8865d 100644 --- a/lib/icinga/host.cpp +++ b/lib/icinga/host.cpp @@ -97,7 +97,7 @@ Host::Ptr Host::GetByName(const String& name) Array::Ptr Host::GetGroups(void) const { - return m_HostGroups;; + return m_HostGroups; } Dictionary::Ptr Host::GetMacros(void) const