]> granicus.if.org Git - icinga2/blobdiff - components/livestatus/servicestable.cpp
Use legacy attribute getters in interfaces.
[icinga2] / components / livestatus / servicestable.cpp
index 92692460df77e1e579e818b18366292ad2d4b626..a6af0e09ff596d9ea962ae09c48e05e2049e2c92 100644 (file)
@@ -1,6 +1,6 @@
 /******************************************************************************
  * Icinga 2                                                                   *
- * Copyright (C) 2012-2013 Icinga Development Team (http://www.icinga.org/)   *
+ * Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org)    *
  *                                                                            *
  * This program is free software; you can redistribute it and/or              *
  * modify it under the terms of the GNU General Public License                *
@@ -19,6 +19,7 @@
 
 #include "livestatus/servicestable.h"
 #include "livestatus/hoststable.h"
+#include "livestatus/endpointstable.h"
 #include "icinga/service.h"
 #include "icinga/checkcommand.h"
 #include "icinga/eventcommand.h"
@@ -35,7 +36,6 @@
 #include <boost/algorithm/string/replace.hpp>
 
 using namespace icinga;
-using namespace livestatus;
 
 ServicesTable::ServicesTable(void)
 {
@@ -93,7 +93,7 @@ void ServicesTable::AddColumns(Table *table, const String& prefix,
        table->AddColumn(prefix + "accept_passive_checks", Column(&ServicesTable::AcceptPassiveChecksAccessor, objectAccessor));
        table->AddColumn(prefix + "event_handler_enabled", Column(&ServicesTable::EventHandlerEnabledAccessor, objectAccessor));
        table->AddColumn(prefix + "notifications_enabled", Column(&ServicesTable::NotificationsEnabledAccessor, objectAccessor));
-       table->AddColumn(prefix + "process_performance_data", Column(&Table::OneAccessor, objectAccessor));
+       table->AddColumn(prefix + "process_performance_data", Column(&ServicesTable::ProcessPerformanceDataAccessor, objectAccessor));
        table->AddColumn(prefix + "is_executing", Column(&Table::ZeroAccessor, objectAccessor));
        table->AddColumn(prefix + "active_checks_enabled", Column(&ServicesTable::ActiveChecksEnabledAccessor, objectAccessor));
        table->AddColumn(prefix + "check_options", Column(&ServicesTable::CheckOptionsAccessor, objectAccessor));
@@ -126,6 +126,7 @@ void ServicesTable::AddColumns(Table *table, const String& prefix,
        table->AddColumn(prefix + "custom_variables", Column(&ServicesTable::CustomVariablesAccessor, objectAccessor));
        table->AddColumn(prefix + "groups", Column(&ServicesTable::GroupsAccessor, objectAccessor));
        table->AddColumn(prefix + "contact_groups", Column(&ServicesTable::ContactGroupsAccessor, objectAccessor));
+       table->AddColumn(prefix + "check_source", Column(&ServicesTable::CheckSourceAccessor, objectAccessor));
 
        HostsTable::AddColumns(table, "host_", boost::bind(&ServicesTable::HostAccessor, _1, objectAccessor));
 }
@@ -201,42 +202,12 @@ Value ServicesTable::CheckCommandExpandedAccessor(const Value& row)
        if (!service)
                return Empty;
 
-        CheckCommand::Ptr commandObj = service->GetCheckCommand();
-
-       if (!commandObj)
-               return Empty;
-
-       Value raw_command = commandObj->GetCommandLine();
-
-        std::vector<MacroResolver::Ptr> resolvers;
-        resolvers.push_back(service);
-        resolvers.push_back(service->GetHost());
-        resolvers.push_back(commandObj);
-        resolvers.push_back(IcingaApplication::GetInstance());
-
-        Value commandLine = MacroProcessor::ResolveMacros(raw_command, resolvers, Dictionary::Ptr(), Utility::EscapeShellCmd);
-
-        String buf;
-        if (commandLine.IsObjectType<Array>()) {
-                Array::Ptr args = commandLine;
+       CheckCommand::Ptr checkcommand = service->GetCheckCommand();
 
-                ObjectLock olock(args);
-                String arg;
-                BOOST_FOREACH(arg, args) {
-                        // This is obviously incorrect for non-trivial cases.
-                        String argitem = " \"" + arg + "\"";
-                        boost::algorithm::replace_all(argitem, "\n", "\\n");
-                        buf += argitem;
-                }
-        } else if (!commandLine.IsEmpty()) {
-                String args = Convert::ToString(commandLine);
-                boost::algorithm::replace_all(args, "\n", "\\n");
-                buf += args;
-        } else {
-                buf += "<internal>";
-        }
+       if (checkcommand)
+               return checkcommand->GetName(); /* this is the name without '!' args */
 
-       return buf;
+       return Empty;
 }
 
 Value ServicesTable::EventHandlerAccessor(const Value& row)
@@ -262,12 +233,10 @@ Value ServicesTable::PluginOutputAccessor(const Value& row)
                return Empty;
 
        String output;
-       Dictionary::Ptr cr = service->GetLastCheckResult();
+       CheckResult::Ptr cr = service->GetLastCheckResult();
 
-       if (cr) {
-               Dictionary::Ptr output_bag = CompatUtility::GetCheckResultOutput(cr);
-               output = output_bag->Get("output");
-       }
+       if (cr)
+               output = CompatUtility::GetCheckResultOutput(cr);
 
        return output;
 }
@@ -280,12 +249,10 @@ Value ServicesTable::LongPluginOutputAccessor(const Value& row)
                return Empty;
 
        String long_output;
-       Dictionary::Ptr cr = service->GetLastCheckResult();
+       CheckResult::Ptr cr = service->GetLastCheckResult();
 
-       if (cr) {
-               Dictionary::Ptr output_bag = CompatUtility::GetCheckResultOutput(cr);
-               long_output = output_bag->Get("long_output");
-       }
+       if (cr)
+               long_output = CompatUtility::GetCheckResultLongOutput(cr);
 
        return long_output;
 }
@@ -298,7 +265,7 @@ Value ServicesTable::PerfDataAccessor(const Value& row)
                return Empty;
 
        String perfdata;
-       Dictionary::Ptr cr = service->GetLastCheckResult();
+       CheckResult::Ptr cr = service->GetLastCheckResult();
 
        if (cr)
                perfdata = CompatUtility::GetCheckResultPerfdata(cr);
@@ -313,17 +280,7 @@ Value ServicesTable::NotificationPeriodAccessor(const Value& row)
        if (!service)
                return Empty;
 
-       BOOST_FOREACH(const Notification::Ptr& notification, service->GetNotifications()) {
-               ObjectLock olock(notification);
-
-               TimePeriod::Ptr timeperiod = notification->GetNotificationPeriod();
-
-               /* XXX first notification wins */
-               if (timeperiod)
-                       return timeperiod->GetName();
-       }
-
-       return Empty;
+       return CompatUtility::GetCheckableNotificationNotificationPeriod(service);
 }
 
 Value ServicesTable::CheckPeriodAccessor(const Value& row)
@@ -333,12 +290,7 @@ Value ServicesTable::CheckPeriodAccessor(const Value& row)
        if (!service)
                return Empty;
 
-       TimePeriod::Ptr timeperiod = service->GetCheckPeriod();
-
-       if (!timeperiod)
-               return Empty;
-
-       return timeperiod->GetName();
+       return CompatUtility::GetCheckableCheckPeriod(service);
 }
 
 Value ServicesTable::NotesAccessor(const Value& row)
@@ -348,12 +300,7 @@ Value ServicesTable::NotesAccessor(const Value& row)
        if (!service)
                return Empty;
 
-       Dictionary::Ptr custom = service->GetCustom();
-
-       if (!custom)
-               return Empty;
-
-       return custom->Get("notes");
+       return service->GetNotes();
 }
 
 Value ServicesTable::NotesExpandedAccessor(const Value& row)
@@ -363,22 +310,12 @@ Value ServicesTable::NotesExpandedAccessor(const Value& row)
        if (!service)
                return Empty;
 
-       Dictionary::Ptr custom = service->GetCustom();
-
-       if (!custom)
-               return Empty;
+       MacroProcessor::ResolverList resolvers;
+       resolvers.push_back(std::make_pair("service", service));
+       resolvers.push_back(std::make_pair("host", service->GetHost()));
+       resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance()));
 
-       std::vector<MacroResolver::Ptr> resolvers;
-       resolvers.push_back(service);
-       resolvers.push_back(service->GetHost());
-       resolvers.push_back(IcingaApplication::GetInstance());
-
-       Value value = custom->Get("notes");
-
-       Dictionary::Ptr cr;
-       Value value_expanded = MacroProcessor::ResolveMacros(value, resolvers, cr, Utility::EscapeShellCmd);
-
-       return value_expanded;
+       return MacroProcessor::ResolveMacros(service->GetNotes(), resolvers, CheckResult::Ptr(), Utility::EscapeShellCmd);
 }
 
 Value ServicesTable::NotesUrlAccessor(const Value& row)
@@ -388,12 +325,7 @@ Value ServicesTable::NotesUrlAccessor(const Value& row)
        if (!service)
                return Empty;
 
-       Dictionary::Ptr custom = service->GetCustom();
-
-       if (!custom)
-               return Empty;
-
-       return custom->Get("notes_url");
+       return service->GetNotesUrl();
 }
 
 Value ServicesTable::NotesUrlExpandedAccessor(const Value& row)
@@ -403,22 +335,12 @@ Value ServicesTable::NotesUrlExpandedAccessor(const Value& row)
        if (!service)
                return Empty;
 
-       Dictionary::Ptr custom = service->GetCustom();
+       MacroProcessor::ResolverList resolvers;
+       resolvers.push_back(std::make_pair("service", service));
+       resolvers.push_back(std::make_pair("host", service->GetHost()));
+       resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance()));
 
-       if (!custom)
-               return Empty;
-
-       std::vector<MacroResolver::Ptr> resolvers;
-       resolvers.push_back(service);
-       resolvers.push_back(service->GetHost());
-       resolvers.push_back(IcingaApplication::GetInstance());
-
-       Value value = custom->Get("notes_url");
-
-       Dictionary::Ptr cr;
-       Value value_expanded = MacroProcessor::ResolveMacros(value, resolvers, cr, Utility::EscapeShellCmd);
-
-       return value_expanded;
+       return MacroProcessor::ResolveMacros(service->GetNotesUrl(), resolvers, CheckResult::Ptr(), Utility::EscapeShellCmd);
 }
 
 Value ServicesTable::ActionUrlAccessor(const Value& row)
@@ -428,12 +350,7 @@ Value ServicesTable::ActionUrlAccessor(const Value& row)
        if (!service)
                return Empty;
 
-       Dictionary::Ptr custom = service->GetCustom();
-
-       if (!custom)
-               return Empty;
-
-       return custom->Get("action_url");
+       return service->GetActionUrl();
 }
 
 Value ServicesTable::ActionUrlExpandedAccessor(const Value& row)
@@ -443,22 +360,12 @@ Value ServicesTable::ActionUrlExpandedAccessor(const Value& row)
        if (!service)
                return Empty;
 
-       Dictionary::Ptr custom = service->GetCustom();
-
-       if (!custom)
-               return Empty;
-
-       std::vector<MacroResolver::Ptr> resolvers;
-       resolvers.push_back(service);
-       resolvers.push_back(service->GetHost());
-       resolvers.push_back(IcingaApplication::GetInstance());
+       MacroProcessor::ResolverList resolvers;
+       resolvers.push_back(std::make_pair("service", service));
+       resolvers.push_back(std::make_pair("host", service->GetHost()));
+       resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance()));
 
-       Value value = custom->Get("action_url");
-
-       Dictionary::Ptr cr;
-       Value value_expanded = MacroProcessor::ResolveMacros(value, resolvers, cr, Utility::EscapeShellCmd);
-
-       return value_expanded;
+       return MacroProcessor::ResolveMacros(service->GetActionUrl(), resolvers, CheckResult::Ptr(), Utility::EscapeShellCmd);
 }
 
 Value ServicesTable::IconImageAccessor(const Value& row)
@@ -468,12 +375,7 @@ Value ServicesTable::IconImageAccessor(const Value& row)
        if (!service)
                return Empty;
 
-       Dictionary::Ptr custom = service->GetCustom();
-
-       if (!custom)
-               return Empty;
-
-       return custom->Get("icon_image");
+       return service->GetIconImage();
 }
 
 Value ServicesTable::IconImageExpandedAccessor(const Value& row)
@@ -483,22 +385,12 @@ Value ServicesTable::IconImageExpandedAccessor(const Value& row)
        if (!service)
                return Empty;
 
-       Dictionary::Ptr custom = service->GetCustom();
-
-       if (!custom)
-               return Empty;
-
-       std::vector<MacroResolver::Ptr> resolvers;
-       resolvers.push_back(service);
-       resolvers.push_back(service->GetHost());
-       resolvers.push_back(IcingaApplication::GetInstance());
-
-       Value value = custom->Get("icon_image");
+       MacroProcessor::ResolverList resolvers;
+       resolvers.push_back(std::make_pair("service", service));
+       resolvers.push_back(std::make_pair("host", service->GetHost()));
+       resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance()));
 
-       Dictionary::Ptr cr;
-       Value value_expanded = MacroProcessor::ResolveMacros(value, resolvers, cr, Utility::EscapeShellCmd);
-
-       return value_expanded;
+       return MacroProcessor::ResolveMacros(service->GetIconImage(), resolvers, CheckResult::Ptr(), Utility::EscapeShellCmd);
 }
 
 Value ServicesTable::IconImageAltAccessor(const Value& row)
@@ -508,12 +400,7 @@ Value ServicesTable::IconImageAltAccessor(const Value& row)
        if (!service)
                return Empty;
 
-       Dictionary::Ptr custom = service->GetCustom();
-
-       if (!custom)
-               return Empty;
-
-       return custom->Get("icon_image_alt");
+       return service->GetIconImageAlt();
 }
 
 Value ServicesTable::MaxCheckAttemptsAccessor(const Value& row)
@@ -553,7 +440,7 @@ Value ServicesTable::HasBeenCheckedAccessor(const Value& row)
        if (!service)
                return Empty;
 
-       return (service->HasBeenChecked() ? 1 : 0);
+       return CompatUtility::GetCheckableHasBeenChecked(service);
 }
 
 Value ServicesTable::LastStateAccessor(const Value& row)
@@ -593,7 +480,7 @@ Value ServicesTable::CheckTypeAccessor(const Value& row)
        if (!service)
                return Empty;
 
-       return (service->GetEnableActiveChecks() ? 0 : 1);
+       return CompatUtility::GetCheckableCheckType(service);
 }
 
 Value ServicesTable::AcknowledgedAccessor(const Value& row)
@@ -603,10 +490,7 @@ Value ServicesTable::AcknowledgedAccessor(const Value& row)
        if (!service)
                return Empty;
 
-       /* important: lock acknowledgements */
-       ObjectLock olock(service);
-
-       return (service->IsAcknowledged() ? 1 : 0);
+       return CompatUtility::GetCheckableIsAcknowledged(service);
 }
 
 Value ServicesTable::AcknowledgementTypeAccessor(const Value& row)
@@ -629,17 +513,7 @@ Value ServicesTable::NoMoreNotificationsAccessor(const Value& row)
        if (!service)
                return Empty;
 
-       /* XXX take the smallest notification_interval */
-        double notification_interval = -1;
-        BOOST_FOREACH(const Notification::Ptr& notification, service->GetNotifications()) {
-                if (notification_interval == -1 || notification->GetNotificationInterval() < notification_interval)
-                        notification_interval = notification->GetNotificationInterval();
-        }
-
-        if (notification_interval == 0 && !service->GetVolatile())
-                return 1;
-
-       return 0;
+        return CompatUtility::GetCheckableNoMoreNotifications(service);
 }
 
 Value ServicesTable::LastTimeOkAccessor(const Value& row)
@@ -709,14 +583,7 @@ Value ServicesTable::LastNotificationAccessor(const Value& row)
        if (!service)
                return Empty;
 
-       /* XXX Service -> Notifications, latest wins */
-       double last_notification = 0;
-       BOOST_FOREACH(const Notification::Ptr& notification, service->GetNotifications()) {
-               if (notification->GetLastNotification() > last_notification)
-                       last_notification = notification->GetLastNotification();
-       }
-
-       return static_cast<int>(last_notification);
+       return CompatUtility::GetCheckableNotificationLastNotification(service);
 }
 
 Value ServicesTable::NextNotificationAccessor(const Value& row)
@@ -726,14 +593,7 @@ Value ServicesTable::NextNotificationAccessor(const Value& row)
        if (!service)
                return Empty;
 
-       /* XXX Service -> Notifications, latest wins */
-       double next_notification = 0;
-       BOOST_FOREACH(const Notification::Ptr& notification, service->GetNotifications()) {
-               if (notification->GetNextNotification() < next_notification)
-                       next_notification = notification->GetNextNotification();
-       }
-
-       return static_cast<int>(next_notification);
+       return CompatUtility::GetCheckableNotificationNextNotification(service);
 }
 
 Value ServicesTable::CurrentNotificationNumberAccessor(const Value& row)
@@ -743,14 +603,7 @@ Value ServicesTable::CurrentNotificationNumberAccessor(const Value& row)
        if (!service)
                return Empty;
 
-       /* XXX Service -> Notifications, biggest wins */
-       int notification_number = 0;
-       BOOST_FOREACH(const Notification::Ptr& notification, service->GetNotifications()) {
-               if (notification->GetNotificationNumber() > notification_number)
-                       notification_number = notification->GetNotificationNumber();
-       }
-
-       return notification_number;
+       return CompatUtility::GetCheckableNotificationNotificationNumber(service);
 }
 
 Value ServicesTable::LastStateChangeAccessor(const Value& row)
@@ -800,7 +653,7 @@ Value ServicesTable::ChecksEnabledAccessor(const Value& row)
        if (!service)
                return Empty;
 
-       return (service->GetEnableActiveChecks() ? 1 : 0);
+       return CompatUtility::GetCheckableActiveChecksEnabled(service);
 }
 
 Value ServicesTable::AcceptPassiveChecksAccessor(const Value& row)
@@ -810,7 +663,7 @@ Value ServicesTable::AcceptPassiveChecksAccessor(const Value& row)
        if (!service)
                return Empty;
 
-       return (service->GetEnablePassiveChecks() ? 1 : 0);
+       return CompatUtility::GetCheckablePassiveChecksEnabled(service);
 }
 
 Value ServicesTable::EventHandlerEnabledAccessor(const Value& row)
@@ -820,22 +673,27 @@ Value ServicesTable::EventHandlerEnabledAccessor(const Value& row)
        if (!service)
                return Empty;
 
-       EventCommand::Ptr eventcommand = service->GetEventCommand();
+       return CompatUtility::GetCheckableEventHandlerEnabled(service);
+}
 
-       if (eventcommand)
-               return 1;
+Value ServicesTable::NotificationsEnabledAccessor(const Value& row)
+{
+       Service::Ptr service = static_cast<Service::Ptr>(row);
+
+       if (!service)
+               return Empty;
 
-       return 0;
+       return CompatUtility::GetCheckableNotificationsEnabled(service);
 }
 
-Value ServicesTable::NotificationsEnabledAccessor(const Value& row)
+Value ServicesTable::ProcessPerformanceDataAccessor(const Value& row)
 {
        Service::Ptr service = static_cast<Service::Ptr>(row);
 
        if (!service)
                return Empty;
 
-       return (service->GetEnableNotifications() ? 1 : 0);
+       return CompatUtility::GetCheckableProcessPerformanceData(service);
 }
 
 Value ServicesTable::ActiveChecksEnabledAccessor(const Value& row)
@@ -845,7 +703,7 @@ Value ServicesTable::ActiveChecksEnabledAccessor(const Value& row)
        if (!service)
                return Empty;
 
-       return (service->GetEnableActiveChecks() ? 1 : 0);
+       return CompatUtility::GetCheckableActiveChecksEnabled(service);
 }
 
 Value ServicesTable::CheckOptionsAccessor(const Value& row)
@@ -861,13 +719,17 @@ Value ServicesTable::FlapDetectionEnabledAccessor(const Value& row)
        if (!service)
                return Empty;
 
-       return (service->GetEnableFlapping() ? 1 : 0);
+       return CompatUtility::GetCheckableFlapDetectionEnabled(service);
 }
 
 Value ServicesTable::CheckFreshnessAccessor(const Value& row)
 {
-       /* always enabled */
-       return 1;
+       Service::Ptr service = static_cast<Service::Ptr>(row);
+
+       if (!service)
+               return Empty;
+
+       return CompatUtility::GetCheckableFreshnessChecksEnabled(service);
 }
 
 Value ServicesTable::ModifiedAttributesAccessor(const Value& row)
@@ -893,10 +755,7 @@ Value ServicesTable::StalenessAccessor(const Value& row)
        if (!service)
                return Empty;
 
-       if (service->HasBeenChecked() && service->GetLastCheck() > 0)
-               return (Utility::GetTime() - service->GetLastCheck()) / (service->GetCheckInterval() * 3600);
-
-       return Empty;
+       return CompatUtility::GetCheckableStaleness(service);
 }
 
 Value ServicesTable::CheckIntervalAccessor(const Value& row)
@@ -906,7 +765,7 @@ Value ServicesTable::CheckIntervalAccessor(const Value& row)
        if (!service)
                return Empty;
 
-       return (service->GetCheckInterval() / 60.0);
+       return CompatUtility::GetCheckableCheckInterval(service);
 }
 
 Value ServicesTable::RetryIntervalAccessor(const Value& row)
@@ -916,7 +775,7 @@ Value ServicesTable::RetryIntervalAccessor(const Value& row)
        if (!service)
                return Empty;
 
-       return (service->GetRetryInterval() / 60.0);
+       return CompatUtility::GetCheckableRetryInterval(service);
 }
 
 Value ServicesTable::NotificationIntervalAccessor(const Value& row)
@@ -926,17 +785,7 @@ Value ServicesTable::NotificationIntervalAccessor(const Value& row)
        if (!service)
                return Empty;
 
-       /* XXX take the smallest notification_interval */
-        double notification_interval = -1;
-        BOOST_FOREACH(const Notification::Ptr& notification, service->GetNotifications()) {
-                if (notification_interval == -1 || notification->GetNotificationInterval() < notification_interval)
-                        notification_interval = notification->GetNotificationInterval();
-        }
-
-        if (notification_interval == -1)
-                notification_interval = 60;
-
-       return (notification_interval / 60.0);
+       return CompatUtility::GetCheckableNotificationNotificationInterval(service);
 }
 
 Value ServicesTable::LowFlapThresholdAccessor(const Value& row)
@@ -946,7 +795,7 @@ Value ServicesTable::LowFlapThresholdAccessor(const Value& row)
        if (!service)
                return Empty;
 
-       return service->GetFlappingThreshold();
+       return CompatUtility::GetCheckableLowFlapThreshold(service);
 }
 
 Value ServicesTable::HighFlapThresholdAccessor(const Value& row)
@@ -956,7 +805,7 @@ Value ServicesTable::HighFlapThresholdAccessor(const Value& row)
        if (!service)
                return Empty;
 
-       return service->GetFlappingThreshold();
+       return CompatUtility::GetCheckableHighFlapThreshold(service);
 }
 
 Value ServicesTable::LatencyAccessor(const Value& row)
@@ -986,7 +835,7 @@ Value ServicesTable::PercentStateChangeAccessor(const Value& row)
        if (!service)
                return Empty;
 
-       return service->GetFlappingCurrent();
+       return CompatUtility::GetCheckablePercentStateChange(service);
 }
 
 Value ServicesTable::InCheckPeriodAccessor(const Value& row)
@@ -996,13 +845,7 @@ Value ServicesTable::InCheckPeriodAccessor(const Value& row)
        if (!service)
                return Empty;
 
-       TimePeriod::Ptr timeperiod = service->GetCheckPeriod();
-
-       /* none set means always checked */
-       if (!timeperiod)
-               return 1;
-
-       return (timeperiod->IsInside(Utility::GetTime()) ? 1 : 0);
+       return CompatUtility::GetCheckableInCheckPeriod(service);
 }
 
 Value ServicesTable::InNotificationPeriodAccessor(const Value& row)
@@ -1012,18 +855,7 @@ Value ServicesTable::InNotificationPeriodAccessor(const Value& row)
        if (!service)
                return Empty;
 
-       BOOST_FOREACH(const Notification::Ptr& notification, service->GetNotifications()) {
-               ObjectLock olock(notification);
-
-               TimePeriod::Ptr timeperiod = notification->GetNotificationPeriod();
-
-               /* XXX first notification wins */
-               if (timeperiod)
-                       return (timeperiod->IsInside(Utility::GetTime()) ? 1 : 0);
-       }
-
-       /* none set means always notified */
-       return 1;
+       return CompatUtility::GetCheckableInNotificationPeriod(service);
 }
 
 Value ServicesTable::ContactsAccessor(const Value& row)
@@ -1033,9 +865,9 @@ Value ServicesTable::ContactsAccessor(const Value& row)
        if (!service)
                return Empty;
 
-       Array::Ptr contact_names = boost::make_shared<Array>();
+       Array::Ptr contact_names = make_shared<Array>();
 
-       BOOST_FOREACH(const User::Ptr& user, CompatUtility::GetServiceNotificationUsers(service)) {
+       BOOST_FOREACH(const User::Ptr& user, CompatUtility::GetCheckableNotificationUsers(service)) {
                contact_names->Add(user->GetName());
        }
 
@@ -1051,21 +883,21 @@ Value ServicesTable::DowntimesAccessor(const Value& row)
 
        Dictionary::Ptr downtimes = service->GetDowntimes();
 
-       Array::Ptr ids = boost::make_shared<Array>();
+       Array::Ptr ids = make_shared<Array>();
 
        ObjectLock olock(downtimes);
 
        String id;
-       Dictionary::Ptr downtime;
-       BOOST_FOREACH(boost::tie(id, downtime), downtimes) {
+       Downtime::Ptr downtime;
+       BOOST_FOREACH(tie(id, downtime), downtimes) {
 
                if (!downtime)
                        continue;
 
-               if (Service::IsDowntimeExpired(downtime))
+               if (downtime->IsExpired())
                        continue;
 
-               ids->Add(downtime->Get("legacy_id"));
+               ids->Add(downtime->GetLegacyId());
        }
 
        return ids;
@@ -1080,24 +912,24 @@ Value ServicesTable::DowntimesWithInfoAccessor(const Value& row)
 
        Dictionary::Ptr downtimes = service->GetDowntimes();
 
-       Array::Ptr ids = boost::make_shared<Array>();
+       Array::Ptr ids = make_shared<Array>();
 
        ObjectLock olock(downtimes);
 
        String id;
-       Dictionary::Ptr downtime;
-       BOOST_FOREACH(boost::tie(id, downtime), downtimes) {
+       Downtime::Ptr downtime;
+       BOOST_FOREACH(tie(id, downtime), downtimes) {
 
                if (!downtime)
                        continue;
 
-               if (Service::IsDowntimeExpired(downtime))
+               if (downtime->IsExpired())
                        continue;
 
-               Array::Ptr downtime_info = boost::make_shared<Array>();
-               downtime_info->Add(downtime->Get("legacy_id"));
-               downtime_info->Add(downtime->Get("author"));
-               downtime_info->Add(downtime->Get("comment"));
+               Array::Ptr downtime_info = make_shared<Array>();
+               downtime_info->Add(downtime->GetLegacyId());
+               downtime_info->Add(downtime->GetAuthor());
+               downtime_info->Add(downtime->GetComment());
                ids->Add(downtime_info);
        }
 
@@ -1113,21 +945,21 @@ Value ServicesTable::CommentsAccessor(const Value& row)
 
        Dictionary::Ptr comments = service->GetComments();
 
-       Array::Ptr ids = boost::make_shared<Array>();
+       Array::Ptr ids = make_shared<Array>();
 
        ObjectLock olock(comments);
 
        String id;
-       Dictionary::Ptr comment;
-       BOOST_FOREACH(boost::tie(id, comment), comments) {
+       Comment::Ptr comment;
+       BOOST_FOREACH(tie(id, comment), comments) {
 
                if (!comment)
                        continue;
 
-               if (Service::IsCommentExpired(comment))
+               if (comment->IsExpired())
                        continue;
 
-               ids->Add(comment->Get("legacy_id"));
+               ids->Add(comment->GetLegacyId());
        }
 
        return ids;
@@ -1142,24 +974,24 @@ Value ServicesTable::CommentsWithInfoAccessor(const Value& row)
 
        Dictionary::Ptr comments = service->GetComments();
 
-       Array::Ptr ids = boost::make_shared<Array>();
+       Array::Ptr ids = make_shared<Array>();
 
        ObjectLock olock(comments);
 
        String id;
-       Dictionary::Ptr comment;
-       BOOST_FOREACH(boost::tie(id, comment), comments) {
+       Comment::Ptr comment;
+       BOOST_FOREACH(tie(id, comment), comments) {
 
                if (!comment)
                        continue;
 
-               if (Service::IsCommentExpired(comment))
+               if (comment->IsExpired())
                        continue;
 
-               Array::Ptr comment_info = boost::make_shared<Array>();
-               comment_info->Add(comment->Get("legacy_id"));
-               comment_info->Add(comment->Get("author"));
-               comment_info->Add(comment->Get("text"));
+               Array::Ptr comment_info = make_shared<Array>();
+               comment_info->Add(comment->GetLegacyId());
+               comment_info->Add(comment->GetAuthor());
+               comment_info->Add(comment->GetText());
                ids->Add(comment_info);
        }
 
@@ -1175,26 +1007,26 @@ Value ServicesTable::CommentsWithExtraInfoAccessor(const Value& row)
 
        Dictionary::Ptr comments = service->GetComments();
 
-       Array::Ptr ids = boost::make_shared<Array>();
+       Array::Ptr ids = make_shared<Array>();
 
        ObjectLock olock(comments);
 
        String id;
-       Dictionary::Ptr comment;
-       BOOST_FOREACH(boost::tie(id, comment), comments) {
+       Comment::Ptr comment;
+       BOOST_FOREACH(tie(id, comment), comments) {
 
                if (!comment)
                        continue;
 
-               if (Service::IsCommentExpired(comment))
+               if (comment->IsExpired())
                        continue;
 
-               Array::Ptr comment_info = boost::make_shared<Array>();
-               comment_info->Add(comment->Get("legacy_id"));
-               comment_info->Add(comment->Get("author"));
-               comment_info->Add(comment->Get("text"));
-               comment_info->Add(comment->Get("entry_type"));
-               comment_info->Add(static_cast<int>(comment->Get("entry_time")));
+               Array::Ptr comment_info = make_shared<Array>();
+               comment_info->Add(comment->GetLegacyId());
+               comment_info->Add(comment->GetAuthor());
+               comment_info->Add(comment->GetText());
+               comment_info->Add(comment->GetEntryType());
+               comment_info->Add(static_cast<int>(comment->GetEntryTime()));
                ids->Add(comment_info);
        }
 
@@ -1208,21 +1040,21 @@ Value ServicesTable::CustomVariableNamesAccessor(const Value& row)
        if (!service)
                return Empty;
 
-       Dictionary::Ptr customvars;
+       Dictionary::Ptr vars;
 
        {
                ObjectLock olock(service);
-               customvars = CompatUtility::GetCustomVariableConfig(service);
+               vars = CompatUtility::GetCustomAttributeConfig(service);
        }
 
-       if (!customvars)
+       if (!vars)
                return Empty;
 
-       Array::Ptr cv = boost::make_shared<Array>();
+       Array::Ptr cv = make_shared<Array>();
 
        String key;
        Value value;
-       BOOST_FOREACH(boost::tie(key, value), customvars) {
+       BOOST_FOREACH(tie(key, value), vars) {
                cv->Add(key);
        }
 
@@ -1236,21 +1068,21 @@ Value ServicesTable::CustomVariableValuesAccessor(const Value& row)
        if (!service)
                return Empty;
 
-       Dictionary::Ptr customvars;
+       Dictionary::Ptr vars;
 
        {
                ObjectLock olock(service);
-               customvars = CompatUtility::GetCustomVariableConfig(service);
+               vars = CompatUtility::GetCustomAttributeConfig(service);
        }
 
-       if (!customvars)
+       if (!vars)
                return Empty;
 
-       Array::Ptr cv = boost::make_shared<Array>();
+       Array::Ptr cv = make_shared<Array>();
 
        String key;
        Value value;
-       BOOST_FOREACH(boost::tie(key, value), customvars) {
+       BOOST_FOREACH(tie(key, value), vars) {
                cv->Add(value);
        }
 
@@ -1264,22 +1096,22 @@ Value ServicesTable::CustomVariablesAccessor(const Value& row)
        if (!service)
                return Empty;
 
-       Dictionary::Ptr customvars;
+       Dictionary::Ptr vars;
 
        {
                ObjectLock olock(service);
-               customvars = CompatUtility::GetCustomVariableConfig(service);
+               vars = CompatUtility::GetCustomAttributeConfig(service);
        }
 
-       if (!customvars)
+       if (!vars)
                return Empty;
 
-       Array::Ptr cv = boost::make_shared<Array>();
+       Array::Ptr cv = make_shared<Array>();
 
        String key;
        Value value;
-       BOOST_FOREACH(boost::tie(key, value), customvars) {
-               Array::Ptr key_val = boost::make_shared<Array>();
+       BOOST_FOREACH(tie(key, value), vars) {
+               Array::Ptr key_val = make_shared<Array>();
                key_val->Add(key);
                key_val->Add(value);
                cv->Add(key_val);
@@ -1310,13 +1142,28 @@ Value ServicesTable::ContactGroupsAccessor(const Value& row)
        if (!service)
                return Empty;
 
-       Array::Ptr contactgroup_names = boost::make_shared<Array>();
+       Array::Ptr contactgroup_names = make_shared<Array>();
 
-       BOOST_FOREACH(const UserGroup::Ptr& usergroup, CompatUtility::GetServiceNotificationUserGroups(service)) {
+       BOOST_FOREACH(const UserGroup::Ptr& usergroup, CompatUtility::GetCheckableNotificationUserGroups(service)) {
                contactgroup_names->Add(usergroup->GetName());
        }
 
        return contactgroup_names;
 }
 
+Value ServicesTable::CheckSourceAccessor(const Value& row)
+{
+       Service::Ptr service = static_cast<Service::Ptr>(row);
+
+       if (!service)
+               return Empty;
+
+       CheckResult::Ptr cr = service->GetLastCheckResult();
+
+       if (cr)
+               return cr->GetCheckSource();
+
+       return Empty;
+}
+