]> granicus.if.org Git - icinga2/commitdiff
livestatus: finish contacts table attributes
authorMichael Friedrich <michael.friedrich@netways.de>
Tue, 16 Jul 2013 11:18:02 +0000 (13:18 +0200)
committerMichael Friedrich <michael.friedrich@netways.de>
Tue, 16 Jul 2013 11:18:02 +0000 (13:18 +0200)
refs #4372

components/livestatus/contactstable.cpp

index e518be3328d60038e84e8cf70eb77fd5259a6fb3..b19ba6899680b3b87563bb10136d7a3a69e4a9d1 100644 (file)
 
 #include "livestatus/contactstable.h"
 #include "icinga/user.h"
+#include "icinga/timeperiod.h"
 #include "base/dynamictype.h"
+#include "base/objectlock.h"
+#include <boost/smart_ptr/make_shared.hpp>
 #include <boost/foreach.hpp>
+#include <boost/tuple/tuple.hpp>
 
 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<User::Ptr>(row)->GetNotificationPeriod();
+
+       if (!timeperiod)
+               return Empty;
+
+       return timeperiod->GetName();
 }
 
 Value ContactsTable::ServiceNotificationPeriodAccessor(const Value& row)
 {
-       /* TODO */
-       return Empty;
+       TimePeriod::Ptr timeperiod = static_cast<User::Ptr>(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<User::Ptr>(row)->GetEnableNotifications() ? 1 : 0);
 }
 
 Value ContactsTable::ServiceNotificationsEnabledAccessor(const Value& row)
 {
-       /* TODO */
-       return Empty;
+       return (static_cast<User::Ptr>(row)->GetEnableNotifications() ? 1 : 0);
 }
 
 Value ContactsTable::InHostNotificationPeriodAccessor(const Value& row)
 {
-       /* TODO */
-       return Empty;
+       TimePeriod::Ptr timeperiod = static_cast<User::Ptr>(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<User::Ptr>(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<User::Ptr>(row)->GetCustom();
+
+       if (!custom)
+               return Empty;
+
+       Array::Ptr cv = boost::make_shared<Array>();
+
+       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<User::Ptr>(row)->GetCustom();
+
+       if (!custom)
+               return Empty;
+
+       Array::Ptr cv = boost::make_shared<Array>();
+
+       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<User::Ptr>(row)->GetCustom();
+
+       if (!custom)
+               return Empty;
+
+       Array::Ptr cv = boost::make_shared<Array>();
+
+       ObjectLock olock(custom);
+       String key;
+       Value value;
+       BOOST_FOREACH(boost::tie(key, value), custom) {
+               Array::Ptr key_val = boost::make_shared<Array>();
+               key_val->Add(key);
+               key_val->Add(value);
+               cv->Add(key_val);
+       }
+
+       return cv;
 }
 
 Value ContactsTable::ModifiedAttributesAccessor(const Value& row)