1 /******************************************************************************
3 * Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org) *
5 * This program is free software; you can redistribute it and/or *
6 * modify it under the terms of the GNU General Public License *
7 * as published by the Free Software Foundation; either version 2 *
8 * of the License, or (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software Foundation *
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ******************************************************************************/
20 #include "livestatus/servicestable.hpp"
21 #include "livestatus/hoststable.hpp"
22 #include "livestatus/endpointstable.hpp"
23 #include "icinga/service.hpp"
24 #include "icinga/checkcommand.hpp"
25 #include "icinga/eventcommand.hpp"
26 #include "icinga/timeperiod.hpp"
27 #include "icinga/macroprocessor.hpp"
28 #include "icinga/icingaapplication.hpp"
29 #include "icinga/compatutility.hpp"
30 #include "base/dynamictype.hpp"
31 #include "base/objectlock.hpp"
32 #include "base/convert.hpp"
33 #include "base/utility.hpp"
34 #include <boost/foreach.hpp>
35 #include <boost/tuple/tuple.hpp>
36 #include <boost/algorithm/string/replace.hpp>
38 using namespace icinga;
40 ServicesTable::ServicesTable(void)
45 void ServicesTable::AddColumns(Table *table, const String& prefix,
46 const Column::ObjectAccessor& objectAccessor)
48 table->AddColumn(prefix + "description", Column(&ServicesTable::ShortNameAccessor, objectAccessor));
49 table->AddColumn(prefix + "service_description", Column(&ServicesTable::ShortNameAccessor, objectAccessor)); //ugly compatibility hack
50 table->AddColumn(prefix + "display_name", Column(&ServicesTable::DisplayNameAccessor, objectAccessor));
51 table->AddColumn(prefix + "check_command", Column(&ServicesTable::CheckCommandAccessor, objectAccessor));
52 table->AddColumn(prefix + "check_command_expanded", Column(&ServicesTable::CheckCommandExpandedAccessor, objectAccessor));
53 table->AddColumn(prefix + "event_handler", Column(&ServicesTable::EventHandlerAccessor, objectAccessor));
54 table->AddColumn(prefix + "plugin_output", Column(&ServicesTable::PluginOutputAccessor, objectAccessor));
55 table->AddColumn(prefix + "long_plugin_output", Column(&ServicesTable::LongPluginOutputAccessor, objectAccessor));
56 table->AddColumn(prefix + "perf_data", Column(&ServicesTable::PerfDataAccessor, objectAccessor));
57 table->AddColumn(prefix + "notification_period", Column(&ServicesTable::NotificationPeriodAccessor, objectAccessor));
58 table->AddColumn(prefix + "check_period", Column(&ServicesTable::CheckPeriodAccessor, objectAccessor));
59 table->AddColumn(prefix + "notes", Column(&ServicesTable::NotesAccessor, objectAccessor));
60 table->AddColumn(prefix + "notes_expanded", Column(&ServicesTable::NotesExpandedAccessor, objectAccessor));
61 table->AddColumn(prefix + "notes_url", Column(&ServicesTable::NotesUrlAccessor, objectAccessor));
62 table->AddColumn(prefix + "notes_url_expanded", Column(&ServicesTable::NotesUrlExpandedAccessor, objectAccessor));
63 table->AddColumn(prefix + "action_url", Column(&ServicesTable::ActionUrlAccessor, objectAccessor));
64 table->AddColumn(prefix + "action_url_expanded", Column(&ServicesTable::ActionUrlExpandedAccessor, objectAccessor));
65 table->AddColumn(prefix + "icon_image", Column(&ServicesTable::IconImageAccessor, objectAccessor));
66 table->AddColumn(prefix + "icon_image_expanded", Column(&ServicesTable::IconImageExpandedAccessor, objectAccessor));
67 table->AddColumn(prefix + "icon_image_alt", Column(&ServicesTable::IconImageAltAccessor, objectAccessor));
68 table->AddColumn(prefix + "initial_state", Column(&Table::EmptyStringAccessor, objectAccessor));
69 table->AddColumn(prefix + "max_check_attempts", Column(&ServicesTable::MaxCheckAttemptsAccessor, objectAccessor));
70 table->AddColumn(prefix + "current_attempt", Column(&ServicesTable::CurrentAttemptAccessor, objectAccessor));
71 table->AddColumn(prefix + "state", Column(&ServicesTable::StateAccessor, objectAccessor));
72 table->AddColumn(prefix + "has_been_checked", Column(&ServicesTable::HasBeenCheckedAccessor, objectAccessor));
73 table->AddColumn(prefix + "last_state", Column(&ServicesTable::LastStateAccessor, objectAccessor));
74 table->AddColumn(prefix + "last_hard_state", Column(&ServicesTable::LastHardStateAccessor, objectAccessor));
75 table->AddColumn(prefix + "state_type", Column(&ServicesTable::StateTypeAccessor, objectAccessor));
76 table->AddColumn(prefix + "check_type", Column(&ServicesTable::CheckTypeAccessor, objectAccessor));
77 table->AddColumn(prefix + "acknowledged", Column(&ServicesTable::AcknowledgedAccessor, objectAccessor));
78 table->AddColumn(prefix + "acknowledgement_type", Column(&ServicesTable::AcknowledgementTypeAccessor, objectAccessor));
79 table->AddColumn(prefix + "no_more_notifications", Column(&ServicesTable::NoMoreNotificationsAccessor, objectAccessor));
80 table->AddColumn(prefix + "last_time_ok", Column(&ServicesTable::LastTimeOkAccessor, objectAccessor));
81 table->AddColumn(prefix + "last_time_warning", Column(&ServicesTable::LastTimeWarningAccessor, objectAccessor));
82 table->AddColumn(prefix + "last_time_critical", Column(&ServicesTable::LastTimeCriticalAccessor, objectAccessor));
83 table->AddColumn(prefix + "last_time_unknown", Column(&ServicesTable::LastTimeUnknownAccessor, objectAccessor));
84 table->AddColumn(prefix + "last_check", Column(&ServicesTable::LastCheckAccessor, objectAccessor));
85 table->AddColumn(prefix + "next_check", Column(&ServicesTable::NextCheckAccessor, objectAccessor));
86 table->AddColumn(prefix + "last_notification", Column(&ServicesTable::LastNotificationAccessor, objectAccessor));
87 table->AddColumn(prefix + "next_notification", Column(&ServicesTable::NextNotificationAccessor, objectAccessor));
88 table->AddColumn(prefix + "current_notification_number", Column(&ServicesTable::CurrentNotificationNumberAccessor, objectAccessor));
89 table->AddColumn(prefix + "last_state_change", Column(&ServicesTable::LastStateChangeAccessor, objectAccessor));
90 table->AddColumn(prefix + "last_hard_state_change", Column(&ServicesTable::LastHardStateChangeAccessor, objectAccessor));
91 table->AddColumn(prefix + "scheduled_downtime_depth", Column(&ServicesTable::ScheduledDowntimeDepthAccessor, objectAccessor));
92 table->AddColumn(prefix + "is_flapping", Column(&ServicesTable::IsFlappingAccessor, objectAccessor));
93 table->AddColumn(prefix + "checks_enabled", Column(&ServicesTable::ChecksEnabledAccessor, objectAccessor));
94 table->AddColumn(prefix + "accept_passive_checks", Column(&ServicesTable::AcceptPassiveChecksAccessor, objectAccessor));
95 table->AddColumn(prefix + "event_handler_enabled", Column(&ServicesTable::EventHandlerEnabledAccessor, objectAccessor));
96 table->AddColumn(prefix + "notifications_enabled", Column(&ServicesTable::NotificationsEnabledAccessor, objectAccessor));
97 table->AddColumn(prefix + "process_performance_data", Column(&ServicesTable::ProcessPerformanceDataAccessor, objectAccessor));
98 table->AddColumn(prefix + "is_executing", Column(&Table::ZeroAccessor, objectAccessor));
99 table->AddColumn(prefix + "active_checks_enabled", Column(&ServicesTable::ActiveChecksEnabledAccessor, objectAccessor));
100 table->AddColumn(prefix + "check_options", Column(&ServicesTable::CheckOptionsAccessor, objectAccessor));
101 table->AddColumn(prefix + "flap_detection_enabled", Column(&ServicesTable::FlapDetectionEnabledAccessor, objectAccessor));
102 table->AddColumn(prefix + "check_freshness", Column(&ServicesTable::CheckFreshnessAccessor, objectAccessor));
103 table->AddColumn(prefix + "obsess_over_service", Column(&Table::ZeroAccessor, objectAccessor));
104 table->AddColumn(prefix + "modified_attributes", Column(&ServicesTable::ModifiedAttributesAccessor, objectAccessor));
105 table->AddColumn(prefix + "modified_attributes_list", Column(&ServicesTable::ModifiedAttributesListAccessor, objectAccessor));
106 table->AddColumn(prefix + "pnpgraph_present", Column(&Table::ZeroAccessor, objectAccessor));
107 table->AddColumn(prefix + "staleness", Column(&ServicesTable::StalenessAccessor, objectAccessor));
108 table->AddColumn(prefix + "check_interval", Column(&ServicesTable::CheckIntervalAccessor, objectAccessor));
109 table->AddColumn(prefix + "retry_interval", Column(&ServicesTable::RetryIntervalAccessor, objectAccessor));
110 table->AddColumn(prefix + "notification_interval", Column(&ServicesTable::NotificationIntervalAccessor, objectAccessor));
111 table->AddColumn(prefix + "first_notification_delay", Column(&Table::EmptyStringAccessor, objectAccessor));
112 table->AddColumn(prefix + "low_flap_threshold", Column(&ServicesTable::LowFlapThresholdAccessor, objectAccessor));
113 table->AddColumn(prefix + "high_flap_threshold", Column(&ServicesTable::HighFlapThresholdAccessor, objectAccessor));
114 table->AddColumn(prefix + "latency", Column(&ServicesTable::LatencyAccessor, objectAccessor));
115 table->AddColumn(prefix + "execution_time", Column(&ServicesTable::ExecutionTimeAccessor, objectAccessor));
116 table->AddColumn(prefix + "percent_state_change", Column(&ServicesTable::PercentStateChangeAccessor, objectAccessor));
117 table->AddColumn(prefix + "in_check_period", Column(&ServicesTable::InCheckPeriodAccessor, objectAccessor));
118 table->AddColumn(prefix + "in_notification_period", Column(&ServicesTable::InNotificationPeriodAccessor, objectAccessor));
119 table->AddColumn(prefix + "contacts", Column(&ServicesTable::ContactsAccessor, objectAccessor));
120 table->AddColumn(prefix + "downtimes", Column(&ServicesTable::DowntimesAccessor, objectAccessor));
121 table->AddColumn(prefix + "downtimes_with_info", Column(&ServicesTable::DowntimesWithInfoAccessor, objectAccessor));
122 table->AddColumn(prefix + "comments", Column(&ServicesTable::CommentsAccessor, objectAccessor));
123 table->AddColumn(prefix + "comments_with_info", Column(&ServicesTable::CommentsWithInfoAccessor, objectAccessor));
124 table->AddColumn(prefix + "comments_with_extra_info", Column(&ServicesTable::CommentsWithExtraInfoAccessor, objectAccessor));
125 table->AddColumn(prefix + "custom_variable_names", Column(&ServicesTable::CustomVariableNamesAccessor, objectAccessor));
126 table->AddColumn(prefix + "custom_variable_values", Column(&ServicesTable::CustomVariableValuesAccessor, objectAccessor));
127 table->AddColumn(prefix + "custom_variables", Column(&ServicesTable::CustomVariablesAccessor, objectAccessor));
128 table->AddColumn(prefix + "groups", Column(&ServicesTable::GroupsAccessor, objectAccessor));
129 table->AddColumn(prefix + "contact_groups", Column(&ServicesTable::ContactGroupsAccessor, objectAccessor));
130 table->AddColumn(prefix + "check_source", Column(&ServicesTable::CheckSourceAccessor, objectAccessor));
131 table->AddColumn(prefix + "is_reachable", Column(&ServicesTable::IsReachableAccessor, objectAccessor));
133 HostsTable::AddColumns(table, "host_", boost::bind(&ServicesTable::HostAccessor, _1, objectAccessor));
136 String ServicesTable::GetName(void) const
141 String ServicesTable::GetPrefix(void) const
146 void ServicesTable::FetchRows(const AddRowFunction& addRowFn)
148 BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjectsByType<Service>()) {
153 Object::Ptr ServicesTable::HostAccessor(const Value& row, const Column::ObjectAccessor& parentObjectAccessor)
157 if (parentObjectAccessor)
158 service = parentObjectAccessor(row);
162 Service::Ptr svc = static_cast<Service::Ptr>(service);
165 return Object::Ptr();
167 return svc->GetHost();
170 Value ServicesTable::ShortNameAccessor(const Value& row)
172 Service::Ptr service = static_cast<Service::Ptr>(row);
177 return service->GetShortName();
180 Value ServicesTable::DisplayNameAccessor(const Value& row)
182 Service::Ptr service = static_cast<Service::Ptr>(row);
187 return service->GetDisplayName();
190 Value ServicesTable::CheckCommandAccessor(const Value& row)
192 Service::Ptr service = static_cast<Service::Ptr>(row);
197 CheckCommand::Ptr checkcommand = service->GetCheckCommand();
200 return CompatUtility::GetCommandName(checkcommand) + "!" + CompatUtility::GetCheckableCommandArgs(service);
205 Value ServicesTable::CheckCommandExpandedAccessor(const Value& row)
207 Service::Ptr service = static_cast<Service::Ptr>(row);
212 CheckCommand::Ptr checkcommand = service->GetCheckCommand();
215 return CompatUtility::GetCommandName(checkcommand) + "!" + CompatUtility::GetCheckableCommandArgs(service);
220 Value ServicesTable::EventHandlerAccessor(const Value& row)
222 Service::Ptr service = static_cast<Service::Ptr>(row);
227 EventCommand::Ptr eventcommand = service->GetEventCommand();
230 return CompatUtility::GetCommandName(eventcommand);
235 Value ServicesTable::PluginOutputAccessor(const Value& row)
237 Service::Ptr service = static_cast<Service::Ptr>(row);
243 CheckResult::Ptr cr = service->GetLastCheckResult();
246 output = CompatUtility::GetCheckResultOutput(cr);
251 Value ServicesTable::LongPluginOutputAccessor(const Value& row)
253 Service::Ptr service = static_cast<Service::Ptr>(row);
259 CheckResult::Ptr cr = service->GetLastCheckResult();
262 long_output = CompatUtility::GetCheckResultLongOutput(cr);
267 Value ServicesTable::PerfDataAccessor(const Value& row)
269 Service::Ptr service = static_cast<Service::Ptr>(row);
275 CheckResult::Ptr cr = service->GetLastCheckResult();
278 perfdata = CompatUtility::GetCheckResultPerfdata(cr);
283 Value ServicesTable::NotificationPeriodAccessor(const Value& row)
285 Service::Ptr service = static_cast<Service::Ptr>(row);
290 return CompatUtility::GetCheckableNotificationNotificationPeriod(service);
293 Value ServicesTable::CheckPeriodAccessor(const Value& row)
295 Service::Ptr service = static_cast<Service::Ptr>(row);
300 return CompatUtility::GetCheckableCheckPeriod(service);
303 Value ServicesTable::NotesAccessor(const Value& row)
305 Service::Ptr service = static_cast<Service::Ptr>(row);
310 return service->GetNotes();
313 Value ServicesTable::NotesExpandedAccessor(const Value& row)
315 Service::Ptr service = static_cast<Service::Ptr>(row);
320 MacroProcessor::ResolverList resolvers;
321 resolvers.push_back(std::make_pair("service", service));
322 resolvers.push_back(std::make_pair("host", service->GetHost()));
323 resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance()));
325 return MacroProcessor::ResolveMacros(service->GetNotes(), resolvers);
328 Value ServicesTable::NotesUrlAccessor(const Value& row)
330 Service::Ptr service = static_cast<Service::Ptr>(row);
335 return service->GetNotesUrl();
338 Value ServicesTable::NotesUrlExpandedAccessor(const Value& row)
340 Service::Ptr service = static_cast<Service::Ptr>(row);
345 MacroProcessor::ResolverList resolvers;
346 resolvers.push_back(std::make_pair("service", service));
347 resolvers.push_back(std::make_pair("host", service->GetHost()));
348 resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance()));
350 return MacroProcessor::ResolveMacros(service->GetNotesUrl(), resolvers);
353 Value ServicesTable::ActionUrlAccessor(const Value& row)
355 Service::Ptr service = static_cast<Service::Ptr>(row);
360 return service->GetActionUrl();
363 Value ServicesTable::ActionUrlExpandedAccessor(const Value& row)
365 Service::Ptr service = static_cast<Service::Ptr>(row);
370 MacroProcessor::ResolverList resolvers;
371 resolvers.push_back(std::make_pair("service", service));
372 resolvers.push_back(std::make_pair("host", service->GetHost()));
373 resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance()));
375 return MacroProcessor::ResolveMacros(service->GetActionUrl(), resolvers);
378 Value ServicesTable::IconImageAccessor(const Value& row)
380 Service::Ptr service = static_cast<Service::Ptr>(row);
385 return service->GetIconImage();
388 Value ServicesTable::IconImageExpandedAccessor(const Value& row)
390 Service::Ptr service = static_cast<Service::Ptr>(row);
395 MacroProcessor::ResolverList resolvers;
396 resolvers.push_back(std::make_pair("service", service));
397 resolvers.push_back(std::make_pair("host", service->GetHost()));
398 resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance()));
400 return MacroProcessor::ResolveMacros(service->GetIconImage(), resolvers);
403 Value ServicesTable::IconImageAltAccessor(const Value& row)
405 Service::Ptr service = static_cast<Service::Ptr>(row);
410 return service->GetIconImageAlt();
413 Value ServicesTable::MaxCheckAttemptsAccessor(const Value& row)
415 Service::Ptr service = static_cast<Service::Ptr>(row);
420 return service->GetMaxCheckAttempts();
423 Value ServicesTable::CurrentAttemptAccessor(const Value& row)
425 Service::Ptr service = static_cast<Service::Ptr>(row);
430 return service->GetCheckAttempt();
433 Value ServicesTable::StateAccessor(const Value& row)
435 Service::Ptr service = static_cast<Service::Ptr>(row);
440 return service->GetState();
443 Value ServicesTable::HasBeenCheckedAccessor(const Value& row)
445 Service::Ptr service = static_cast<Service::Ptr>(row);
450 return CompatUtility::GetCheckableHasBeenChecked(service);
453 Value ServicesTable::LastStateAccessor(const Value& row)
455 Service::Ptr service = static_cast<Service::Ptr>(row);
460 return service->GetLastState();
463 Value ServicesTable::LastHardStateAccessor(const Value& row)
465 Service::Ptr service = static_cast<Service::Ptr>(row);
470 return service->GetLastHardState();
473 Value ServicesTable::StateTypeAccessor(const Value& row)
475 Service::Ptr service = static_cast<Service::Ptr>(row);
480 return service->GetStateType();
483 Value ServicesTable::CheckTypeAccessor(const Value& row)
485 Service::Ptr service = static_cast<Service::Ptr>(row);
490 return CompatUtility::GetCheckableCheckType(service);
493 Value ServicesTable::AcknowledgedAccessor(const Value& row)
495 Service::Ptr service = static_cast<Service::Ptr>(row);
500 ObjectLock olock(service);
501 return CompatUtility::GetCheckableIsAcknowledged(service);
504 Value ServicesTable::AcknowledgementTypeAccessor(const Value& row)
506 Service::Ptr service = static_cast<Service::Ptr>(row);
511 ObjectLock olock(service);
512 return CompatUtility::GetCheckableAcknowledgementType(service);
515 Value ServicesTable::NoMoreNotificationsAccessor(const Value& row)
517 Service::Ptr service = static_cast<Service::Ptr>(row);
522 return CompatUtility::GetCheckableNoMoreNotifications(service);
525 Value ServicesTable::LastTimeOkAccessor(const Value& row)
527 Service::Ptr service = static_cast<Service::Ptr>(row);
532 return static_cast<int>(service->GetLastStateOK());
535 Value ServicesTable::LastTimeWarningAccessor(const Value& row)
537 Service::Ptr service = static_cast<Service::Ptr>(row);
542 return static_cast<int>(service->GetLastStateWarning());
545 Value ServicesTable::LastTimeCriticalAccessor(const Value& row)
547 Service::Ptr service = static_cast<Service::Ptr>(row);
552 return static_cast<int>(service->GetLastStateCritical());
555 Value ServicesTable::LastTimeUnknownAccessor(const Value& row)
557 Service::Ptr service = static_cast<Service::Ptr>(row);
562 return static_cast<int>(service->GetLastStateUnknown());
565 Value ServicesTable::LastCheckAccessor(const Value& row)
567 Service::Ptr service = static_cast<Service::Ptr>(row);
572 return static_cast<int>(service->GetLastCheck());
575 Value ServicesTable::NextCheckAccessor(const Value& row)
577 Service::Ptr service = static_cast<Service::Ptr>(row);
582 return static_cast<int>(service->GetNextCheck());
585 Value ServicesTable::LastNotificationAccessor(const Value& row)
587 Service::Ptr service = static_cast<Service::Ptr>(row);
592 return CompatUtility::GetCheckableNotificationLastNotification(service);
595 Value ServicesTable::NextNotificationAccessor(const Value& row)
597 Service::Ptr service = static_cast<Service::Ptr>(row);
602 return CompatUtility::GetCheckableNotificationNextNotification(service);
605 Value ServicesTable::CurrentNotificationNumberAccessor(const Value& row)
607 Service::Ptr service = static_cast<Service::Ptr>(row);
612 return CompatUtility::GetCheckableNotificationNotificationNumber(service);
615 Value ServicesTable::LastStateChangeAccessor(const Value& row)
617 Service::Ptr service = static_cast<Service::Ptr>(row);
622 return static_cast<int>(service->GetLastStateChange());
625 Value ServicesTable::LastHardStateChangeAccessor(const Value& row)
627 Service::Ptr service = static_cast<Service::Ptr>(row);
632 return static_cast<int>(service->GetLastHardStateChange());
635 Value ServicesTable::ScheduledDowntimeDepthAccessor(const Value& row)
637 Service::Ptr service = static_cast<Service::Ptr>(row);
642 return service->GetDowntimeDepth();
645 Value ServicesTable::IsFlappingAccessor(const Value& row)
647 Service::Ptr service = static_cast<Service::Ptr>(row);
652 return service->IsFlapping();
655 Value ServicesTable::ChecksEnabledAccessor(const Value& row)
657 Service::Ptr service = static_cast<Service::Ptr>(row);
662 return CompatUtility::GetCheckableActiveChecksEnabled(service);
665 Value ServicesTable::AcceptPassiveChecksAccessor(const Value& row)
667 Service::Ptr service = static_cast<Service::Ptr>(row);
672 return CompatUtility::GetCheckablePassiveChecksEnabled(service);
675 Value ServicesTable::EventHandlerEnabledAccessor(const Value& row)
677 Service::Ptr service = static_cast<Service::Ptr>(row);
682 return CompatUtility::GetCheckableEventHandlerEnabled(service);
685 Value ServicesTable::NotificationsEnabledAccessor(const Value& row)
687 Service::Ptr service = static_cast<Service::Ptr>(row);
692 return CompatUtility::GetCheckableNotificationsEnabled(service);
695 Value ServicesTable::ProcessPerformanceDataAccessor(const Value& row)
697 Service::Ptr service = static_cast<Service::Ptr>(row);
702 return CompatUtility::GetCheckableProcessPerformanceData(service);
705 Value ServicesTable::ActiveChecksEnabledAccessor(const Value& row)
707 Service::Ptr service = static_cast<Service::Ptr>(row);
712 return CompatUtility::GetCheckableActiveChecksEnabled(service);
715 Value ServicesTable::CheckOptionsAccessor(const Value& row)
717 /* TODO - forcexec, freshness, orphan, none */
721 Value ServicesTable::FlapDetectionEnabledAccessor(const Value& row)
723 Service::Ptr service = static_cast<Service::Ptr>(row);
728 return CompatUtility::GetCheckableFlapDetectionEnabled(service);
731 Value ServicesTable::CheckFreshnessAccessor(const Value& row)
733 Service::Ptr service = static_cast<Service::Ptr>(row);
738 return CompatUtility::GetCheckableFreshnessChecksEnabled(service);
741 Value ServicesTable::ModifiedAttributesAccessor(const Value& row)
743 Service::Ptr service = static_cast<Service::Ptr>(row);
748 return service->GetModifiedAttributes();
751 Value ServicesTable::ModifiedAttributesListAccessor(const Value& row)
753 Service::Ptr service = static_cast<Service::Ptr>(row);
758 return CompatUtility::GetModifiedAttributesList(service);
761 Value ServicesTable::StalenessAccessor(const Value& row)
763 Service::Ptr service = static_cast<Service::Ptr>(row);
768 return CompatUtility::GetCheckableStaleness(service);
771 Value ServicesTable::CheckIntervalAccessor(const Value& row)
773 Service::Ptr service = static_cast<Service::Ptr>(row);
778 return CompatUtility::GetCheckableCheckInterval(service);
781 Value ServicesTable::RetryIntervalAccessor(const Value& row)
783 Service::Ptr service = static_cast<Service::Ptr>(row);
788 return CompatUtility::GetCheckableRetryInterval(service);
791 Value ServicesTable::NotificationIntervalAccessor(const Value& row)
793 Service::Ptr service = static_cast<Service::Ptr>(row);
798 return CompatUtility::GetCheckableNotificationNotificationInterval(service);
801 Value ServicesTable::LowFlapThresholdAccessor(const Value& row)
803 Service::Ptr service = static_cast<Service::Ptr>(row);
808 return CompatUtility::GetCheckableLowFlapThreshold(service);
811 Value ServicesTable::HighFlapThresholdAccessor(const Value& row)
813 Service::Ptr service = static_cast<Service::Ptr>(row);
818 return CompatUtility::GetCheckableHighFlapThreshold(service);
821 Value ServicesTable::LatencyAccessor(const Value& row)
823 Service::Ptr service = static_cast<Service::Ptr>(row);
828 return (Service::CalculateLatency(service->GetLastCheckResult()));
831 Value ServicesTable::ExecutionTimeAccessor(const Value& row)
833 Service::Ptr service = static_cast<Service::Ptr>(row);
838 return (Service::CalculateExecutionTime(service->GetLastCheckResult()));
841 Value ServicesTable::PercentStateChangeAccessor(const Value& row)
843 Service::Ptr service = static_cast<Service::Ptr>(row);
848 return CompatUtility::GetCheckablePercentStateChange(service);
851 Value ServicesTable::InCheckPeriodAccessor(const Value& row)
853 Service::Ptr service = static_cast<Service::Ptr>(row);
858 return CompatUtility::GetCheckableInCheckPeriod(service);
861 Value ServicesTable::InNotificationPeriodAccessor(const Value& row)
863 Service::Ptr service = static_cast<Service::Ptr>(row);
868 return CompatUtility::GetCheckableInNotificationPeriod(service);
871 Value ServicesTable::ContactsAccessor(const Value& row)
873 Service::Ptr service = static_cast<Service::Ptr>(row);
878 Array::Ptr contact_names = make_shared<Array>();
880 BOOST_FOREACH(const User::Ptr& user, CompatUtility::GetCheckableNotificationUsers(service)) {
881 contact_names->Add(user->GetName());
884 return contact_names;
887 Value ServicesTable::DowntimesAccessor(const Value& row)
889 Service::Ptr service = static_cast<Service::Ptr>(row);
894 Dictionary::Ptr downtimes = service->GetDowntimes();
896 Array::Ptr ids = make_shared<Array>();
898 ObjectLock olock(downtimes);
901 Downtime::Ptr downtime;
902 BOOST_FOREACH(tie(id, downtime), downtimes) {
907 if (downtime->IsExpired())
910 ids->Add(downtime->GetLegacyId());
916 Value ServicesTable::DowntimesWithInfoAccessor(const Value& row)
918 Service::Ptr service = static_cast<Service::Ptr>(row);
923 Dictionary::Ptr downtimes = service->GetDowntimes();
925 Array::Ptr ids = make_shared<Array>();
927 ObjectLock olock(downtimes);
930 Downtime::Ptr downtime;
931 BOOST_FOREACH(tie(id, downtime), downtimes) {
936 if (downtime->IsExpired())
939 Array::Ptr downtime_info = make_shared<Array>();
940 downtime_info->Add(downtime->GetLegacyId());
941 downtime_info->Add(downtime->GetAuthor());
942 downtime_info->Add(downtime->GetComment());
943 ids->Add(downtime_info);
949 Value ServicesTable::CommentsAccessor(const Value& row)
951 Service::Ptr service = static_cast<Service::Ptr>(row);
956 Dictionary::Ptr comments = service->GetComments();
958 Array::Ptr ids = make_shared<Array>();
960 ObjectLock olock(comments);
963 Comment::Ptr comment;
964 BOOST_FOREACH(tie(id, comment), comments) {
969 if (comment->IsExpired())
972 ids->Add(comment->GetLegacyId());
978 Value ServicesTable::CommentsWithInfoAccessor(const Value& row)
980 Service::Ptr service = static_cast<Service::Ptr>(row);
985 Dictionary::Ptr comments = service->GetComments();
987 Array::Ptr ids = make_shared<Array>();
989 ObjectLock olock(comments);
992 Comment::Ptr comment;
993 BOOST_FOREACH(tie(id, comment), comments) {
998 if (comment->IsExpired())
1001 Array::Ptr comment_info = make_shared<Array>();
1002 comment_info->Add(comment->GetLegacyId());
1003 comment_info->Add(comment->GetAuthor());
1004 comment_info->Add(comment->GetText());
1005 ids->Add(comment_info);
1011 Value ServicesTable::CommentsWithExtraInfoAccessor(const Value& row)
1013 Service::Ptr service = static_cast<Service::Ptr>(row);
1018 Dictionary::Ptr comments = service->GetComments();
1020 Array::Ptr ids = make_shared<Array>();
1022 ObjectLock olock(comments);
1025 Comment::Ptr comment;
1026 BOOST_FOREACH(tie(id, comment), comments) {
1031 if (comment->IsExpired())
1034 Array::Ptr comment_info = make_shared<Array>();
1035 comment_info->Add(comment->GetLegacyId());
1036 comment_info->Add(comment->GetAuthor());
1037 comment_info->Add(comment->GetText());
1038 comment_info->Add(comment->GetEntryType());
1039 comment_info->Add(static_cast<int>(comment->GetEntryTime()));
1040 ids->Add(comment_info);
1046 Value ServicesTable::CustomVariableNamesAccessor(const Value& row)
1048 Service::Ptr service = static_cast<Service::Ptr>(row);
1053 Dictionary::Ptr vars;
1056 ObjectLock olock(service);
1057 vars = CompatUtility::GetCustomAttributeConfig(service);
1063 Array::Ptr cv = make_shared<Array>();
1065 ObjectLock olock(vars);
1066 BOOST_FOREACH(const Dictionary::Pair kv, vars) {
1073 Value ServicesTable::CustomVariableValuesAccessor(const Value& row)
1075 Service::Ptr service = static_cast<Service::Ptr>(row);
1080 Dictionary::Ptr vars;
1083 ObjectLock olock(service);
1084 vars = CompatUtility::GetCustomAttributeConfig(service);
1090 Array::Ptr cv = make_shared<Array>();
1092 ObjectLock olock(vars);
1093 BOOST_FOREACH(const Dictionary::Pair& kv, vars) {
1100 Value ServicesTable::CustomVariablesAccessor(const Value& row)
1102 Service::Ptr service = static_cast<Service::Ptr>(row);
1107 Dictionary::Ptr vars;
1110 ObjectLock olock(service);
1111 vars = CompatUtility::GetCustomAttributeConfig(service);
1117 Array::Ptr cv = make_shared<Array>();
1121 BOOST_FOREACH(tie(key, value), vars) {
1122 Array::Ptr key_val = make_shared<Array>();
1124 key_val->Add(value);
1131 Value ServicesTable::GroupsAccessor(const Value& row)
1133 Service::Ptr service = static_cast<Service::Ptr>(row);
1138 Array::Ptr groups = service->GetGroups();
1146 Value ServicesTable::ContactGroupsAccessor(const Value& row)
1148 Service::Ptr service = static_cast<Service::Ptr>(row);
1153 Array::Ptr contactgroup_names = make_shared<Array>();
1155 BOOST_FOREACH(const UserGroup::Ptr& usergroup, CompatUtility::GetCheckableNotificationUserGroups(service)) {
1156 contactgroup_names->Add(usergroup->GetName());
1159 return contactgroup_names;
1162 Value ServicesTable::CheckSourceAccessor(const Value& row)
1164 Service::Ptr service = static_cast<Service::Ptr>(row);
1169 CheckResult::Ptr cr = service->GetLastCheckResult();
1172 return cr->GetCheckSource();
1177 Value ServicesTable::IsReachableAccessor(const Value& row)
1179 Service::Ptr service = static_cast<Service::Ptr>(row);
1184 return service->IsReachable();