From df1d47a996d2f7702b2c9140aecd04e729a7c093 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Tue, 16 Jul 2013 13:18:02 +0200 Subject: [PATCH] livestatus: finish contacts table attributes refs #4372 --- components/livestatus/contactstable.cpp | 99 ++++++++++++++++++++----- 1 file changed, 80 insertions(+), 19 deletions(-) diff --git a/components/livestatus/contactstable.cpp b/components/livestatus/contactstable.cpp index e518be332..b19ba6899 100644 --- a/components/livestatus/contactstable.cpp +++ b/components/livestatus/contactstable.cpp @@ -19,8 +19,12 @@ #include "livestatus/contactstable.h" #include "icinga/user.h" +#include "icinga/timeperiod.h" #include "base/dynamictype.h" +#include "base/objectlock.h" +#include #include +#include using namespace icinga; using namespace livestatus; @@ -95,62 +99,119 @@ Value ContactsTable::PagerAccessor(const Value& row) Value ContactsTable::HostNotificationPeriodAccessor(const Value& row) { - /* TODO */ - return Empty; + /* same as service */ + TimePeriod::Ptr timeperiod = static_cast(row)->GetNotificationPeriod(); + + if (!timeperiod) + return Empty; + + return timeperiod->GetName(); } Value ContactsTable::ServiceNotificationPeriodAccessor(const Value& row) { - /* TODO */ - return Empty; + TimePeriod::Ptr timeperiod = static_cast(row)->GetNotificationPeriod(); + + if (!timeperiod) + return Empty; + + return timeperiod->GetName(); } Value ContactsTable::CanSubmitCommandsAccessor(const Value& row) { - /* TODO - default 1*/ + /* default enabled */ return 1; } Value ContactsTable::HostNotificationsEnabledAccessor(const Value& row) { - /* TODO */ - return Empty; + return (static_cast(row)->GetEnableNotifications() ? 1 : 0); } Value ContactsTable::ServiceNotificationsEnabledAccessor(const Value& row) { - /* TODO */ - return Empty; + return (static_cast(row)->GetEnableNotifications() ? 1 : 0); } Value ContactsTable::InHostNotificationPeriodAccessor(const Value& row) { - /* TODO */ - return Empty; + TimePeriod::Ptr timeperiod = static_cast(row)->GetNotificationPeriod(); + + if (!timeperiod) + return Empty; + + return timeperiod->IsInside(Utility::GetTime()); } Value ContactsTable::InServiceNotificationPeriodAccessor(const Value& row) { - /* TODO */ - return Empty; + TimePeriod::Ptr timeperiod = static_cast(row)->GetNotificationPeriod(); + + if (!timeperiod) + return Empty; + + return timeperiod->IsInside(Utility::GetTime()); } Value ContactsTable::CustomVariableNamesAccessor(const Value& row) { - /* TODO */ - return Empty; + Dictionary::Ptr custom = static_cast(row)->GetCustom(); + + if (!custom) + return Empty; + + Array::Ptr cv = boost::make_shared(); + + ObjectLock olock(custom); + String key; + Value value; + BOOST_FOREACH(boost::tie(key, value), custom) { + cv->Add(key); + } + + return cv; } Value ContactsTable::CustomVariableValuesAccessor(const Value& row) { - /* TODO */ - return Empty; + Dictionary::Ptr custom = static_cast(row)->GetCustom(); + + if (!custom) + return Empty; + + Array::Ptr cv = boost::make_shared(); + + ObjectLock olock(custom); + String key; + Value value; + BOOST_FOREACH(boost::tie(key, value), custom) { + cv->Add(value); + } + + return cv; } Value ContactsTable::CustomVariablesAccessor(const Value& row) { - /* TODO */ - return Empty; + Dictionary::Ptr custom = static_cast(row)->GetCustom(); + + if (!custom) + return Empty; + + Array::Ptr cv = boost::make_shared(); + + ObjectLock olock(custom); + String key; + Value value; + BOOST_FOREACH(boost::tie(key, value), custom) { + Array::Ptr key_val = boost::make_shared(); + key_val->Add(key); + key_val->Add(value); + cv->Add(key_val); + } + + return cv; } Value ContactsTable::ModifiedAttributesAccessor(const Value& row) -- 2.40.0