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.h"
21 #include "livestatus/hoststable.h"
22 #include "livestatus/endpointstable.h"
23 #include "icinga/service.h"
24 #include "icinga/checkcommand.h"
25 #include "icinga/eventcommand.h"
26 #include "icinga/timeperiod.h"
27 #include "icinga/macroprocessor.h"
28 #include "icinga/icingaapplication.h"
29 #include "icinga/compatutility.h"
30 #include "base/dynamictype.h"
31 #include "base/objectlock.h"
32 #include "base/convert.h"
33 #include "base/utility.h"
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 + "display_name", Column(&ServicesTable::DisplayNameAccessor, objectAccessor));
50 table->AddColumn(prefix + "check_command", Column(&ServicesTable::CheckCommandAccessor, objectAccessor));
51 table->AddColumn(prefix + "check_command_expanded", Column(&ServicesTable::CheckCommandExpandedAccessor, objectAccessor));
52 table->AddColumn(prefix + "event_handler", Column(&ServicesTable::EventHandlerAccessor, objectAccessor));
53 table->AddColumn(prefix + "plugin_output", Column(&ServicesTable::PluginOutputAccessor, objectAccessor));
54 table->AddColumn(prefix + "long_plugin_output", Column(&ServicesTable::LongPluginOutputAccessor, objectAccessor));
55 table->AddColumn(prefix + "perf_data", Column(&ServicesTable::PerfDataAccessor, objectAccessor));
56 table->AddColumn(prefix + "notification_period", Column(&ServicesTable::NotificationPeriodAccessor, objectAccessor));
57 table->AddColumn(prefix + "check_period", Column(&ServicesTable::CheckPeriodAccessor, objectAccessor));
58 table->AddColumn(prefix + "notes", Column(&ServicesTable::NotesAccessor, objectAccessor));
59 table->AddColumn(prefix + "notes_expanded", Column(&ServicesTable::NotesExpandedAccessor, objectAccessor));
60 table->AddColumn(prefix + "notes_url", Column(&ServicesTable::NotesUrlAccessor, objectAccessor));
61 table->AddColumn(prefix + "notes_url_expanded", Column(&ServicesTable::NotesUrlExpandedAccessor, objectAccessor));
62 table->AddColumn(prefix + "action_url", Column(&ServicesTable::ActionUrlAccessor, objectAccessor));
63 table->AddColumn(prefix + "action_url_expanded", Column(&ServicesTable::ActionUrlExpandedAccessor, objectAccessor));
64 table->AddColumn(prefix + "icon_image", Column(&ServicesTable::IconImageAccessor, objectAccessor));
65 table->AddColumn(prefix + "icon_image_expanded", Column(&ServicesTable::IconImageExpandedAccessor, objectAccessor));
66 table->AddColumn(prefix + "icon_image_alt", Column(&ServicesTable::IconImageAltAccessor, objectAccessor));
67 table->AddColumn(prefix + "initial_state", Column(&Table::EmptyStringAccessor, objectAccessor));
68 table->AddColumn(prefix + "max_check_attempts", Column(&ServicesTable::MaxCheckAttemptsAccessor, objectAccessor));
69 table->AddColumn(prefix + "current_attempt", Column(&ServicesTable::CurrentAttemptAccessor, objectAccessor));
70 table->AddColumn(prefix + "state", Column(&ServicesTable::StateAccessor, objectAccessor));
71 table->AddColumn(prefix + "has_been_checked", Column(&ServicesTable::HasBeenCheckedAccessor, objectAccessor));
72 table->AddColumn(prefix + "last_state", Column(&ServicesTable::LastStateAccessor, objectAccessor));
73 table->AddColumn(prefix + "last_hard_state", Column(&ServicesTable::LastHardStateAccessor, objectAccessor));
74 table->AddColumn(prefix + "state_type", Column(&ServicesTable::StateTypeAccessor, objectAccessor));
75 table->AddColumn(prefix + "check_type", Column(&ServicesTable::CheckTypeAccessor, objectAccessor));
76 table->AddColumn(prefix + "acknowledged", Column(&ServicesTable::AcknowledgedAccessor, objectAccessor));
77 table->AddColumn(prefix + "acknowledgement_type", Column(&ServicesTable::AcknowledgementTypeAccessor, objectAccessor));
78 table->AddColumn(prefix + "no_more_notifications", Column(&ServicesTable::NoMoreNotificationsAccessor, objectAccessor));
79 table->AddColumn(prefix + "last_time_ok", Column(&ServicesTable::LastTimeOkAccessor, objectAccessor));
80 table->AddColumn(prefix + "last_time_warning", Column(&ServicesTable::LastTimeWarningAccessor, objectAccessor));
81 table->AddColumn(prefix + "last_time_critical", Column(&ServicesTable::LastTimeCriticalAccessor, objectAccessor));
82 table->AddColumn(prefix + "last_time_unknown", Column(&ServicesTable::LastTimeUnknownAccessor, objectAccessor));
83 table->AddColumn(prefix + "last_check", Column(&ServicesTable::LastCheckAccessor, objectAccessor));
84 table->AddColumn(prefix + "next_check", Column(&ServicesTable::NextCheckAccessor, objectAccessor));
85 table->AddColumn(prefix + "last_notification", Column(&ServicesTable::LastNotificationAccessor, objectAccessor));
86 table->AddColumn(prefix + "next_notification", Column(&ServicesTable::NextNotificationAccessor, objectAccessor));
87 table->AddColumn(prefix + "current_notification_number", Column(&ServicesTable::CurrentNotificationNumberAccessor, objectAccessor));
88 table->AddColumn(prefix + "last_state_change", Column(&ServicesTable::LastStateChangeAccessor, objectAccessor));
89 table->AddColumn(prefix + "last_hard_state_change", Column(&ServicesTable::LastHardStateChangeAccessor, objectAccessor));
90 table->AddColumn(prefix + "scheduled_downtime_depth", Column(&ServicesTable::ScheduledDowntimeDepthAccessor, objectAccessor));
91 table->AddColumn(prefix + "is_flapping", Column(&ServicesTable::IsFlappingAccessor, objectAccessor));
92 table->AddColumn(prefix + "checks_enabled", Column(&ServicesTable::ChecksEnabledAccessor, objectAccessor));
93 table->AddColumn(prefix + "accept_passive_checks", Column(&ServicesTable::AcceptPassiveChecksAccessor, objectAccessor));
94 table->AddColumn(prefix + "event_handler_enabled", Column(&ServicesTable::EventHandlerEnabledAccessor, objectAccessor));
95 table->AddColumn(prefix + "notifications_enabled", Column(&ServicesTable::NotificationsEnabledAccessor, objectAccessor));
96 table->AddColumn(prefix + "process_performance_data", Column(&ServicesTable::ProcessPerformanceDataAccessor, objectAccessor));
97 table->AddColumn(prefix + "is_executing", Column(&Table::ZeroAccessor, objectAccessor));
98 table->AddColumn(prefix + "active_checks_enabled", Column(&ServicesTable::ActiveChecksEnabledAccessor, objectAccessor));
99 table->AddColumn(prefix + "check_options", Column(&ServicesTable::CheckOptionsAccessor, objectAccessor));
100 table->AddColumn(prefix + "flap_detection_enabled", Column(&ServicesTable::FlapDetectionEnabledAccessor, objectAccessor));
101 table->AddColumn(prefix + "check_freshness", Column(&ServicesTable::CheckFreshnessAccessor, objectAccessor));
102 table->AddColumn(prefix + "obsess_over_service", Column(&Table::ZeroAccessor, objectAccessor));
103 table->AddColumn(prefix + "modified_attributes", Column(&ServicesTable::ModifiedAttributesAccessor, objectAccessor));
104 table->AddColumn(prefix + "modified_attributes_list", Column(&ServicesTable::ModifiedAttributesListAccessor, objectAccessor));
105 table->AddColumn(prefix + "pnpgraph_present", Column(&Table::ZeroAccessor, objectAccessor));
106 table->AddColumn(prefix + "staleness", Column(&ServicesTable::StalenessAccessor, objectAccessor));
107 table->AddColumn(prefix + "check_interval", Column(&ServicesTable::CheckIntervalAccessor, objectAccessor));
108 table->AddColumn(prefix + "retry_interval", Column(&ServicesTable::RetryIntervalAccessor, objectAccessor));
109 table->AddColumn(prefix + "notification_interval", Column(&ServicesTable::NotificationIntervalAccessor, objectAccessor));
110 table->AddColumn(prefix + "first_notification_delay", Column(&Table::EmptyStringAccessor, objectAccessor));
111 table->AddColumn(prefix + "low_flap_threshold", Column(&ServicesTable::LowFlapThresholdAccessor, objectAccessor));
112 table->AddColumn(prefix + "high_flap_threshold", Column(&ServicesTable::HighFlapThresholdAccessor, objectAccessor));
113 table->AddColumn(prefix + "latency", Column(&ServicesTable::LatencyAccessor, objectAccessor));
114 table->AddColumn(prefix + "execution_time", Column(&ServicesTable::ExecutionTimeAccessor, objectAccessor));
115 table->AddColumn(prefix + "percent_state_change", Column(&ServicesTable::PercentStateChangeAccessor, objectAccessor));
116 table->AddColumn(prefix + "in_check_period", Column(&ServicesTable::InCheckPeriodAccessor, objectAccessor));
117 table->AddColumn(prefix + "in_notification_period", Column(&ServicesTable::InNotificationPeriodAccessor, objectAccessor));
118 table->AddColumn(prefix + "contacts", Column(&ServicesTable::ContactsAccessor, objectAccessor));
119 table->AddColumn(prefix + "downtimes", Column(&ServicesTable::DowntimesAccessor, objectAccessor));
120 table->AddColumn(prefix + "downtimes_with_info", Column(&ServicesTable::DowntimesWithInfoAccessor, objectAccessor));
121 table->AddColumn(prefix + "comments", Column(&ServicesTable::CommentsAccessor, objectAccessor));
122 table->AddColumn(prefix + "comments_with_info", Column(&ServicesTable::CommentsWithInfoAccessor, objectAccessor));
123 table->AddColumn(prefix + "comments_with_extra_info", Column(&ServicesTable::CommentsWithExtraInfoAccessor, objectAccessor));
124 table->AddColumn(prefix + "custom_variable_names", Column(&ServicesTable::CustomVariableNamesAccessor, objectAccessor));
125 table->AddColumn(prefix + "custom_variable_values", Column(&ServicesTable::CustomVariableValuesAccessor, objectAccessor));
126 table->AddColumn(prefix + "custom_variables", Column(&ServicesTable::CustomVariablesAccessor, objectAccessor));
127 table->AddColumn(prefix + "groups", Column(&ServicesTable::GroupsAccessor, objectAccessor));
128 table->AddColumn(prefix + "contact_groups", Column(&ServicesTable::ContactGroupsAccessor, objectAccessor));
129 table->AddColumn(prefix + "check_source", Column(&ServicesTable::CheckSourceAccessor, objectAccessor));
131 HostsTable::AddColumns(table, "host_", boost::bind(&ServicesTable::HostAccessor, _1, objectAccessor));
134 String ServicesTable::GetName(void) const
139 void ServicesTable::FetchRows(const AddRowFunction& addRowFn)
141 BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjects<Service>()) {
146 Object::Ptr ServicesTable::HostAccessor(const Value& row, const Column::ObjectAccessor& parentObjectAccessor)
150 if (parentObjectAccessor)
151 service = parentObjectAccessor(row);
155 Service::Ptr svc = static_cast<Service::Ptr>(service);
158 return Object::Ptr();
160 return svc->GetHost();
163 Value ServicesTable::ShortNameAccessor(const Value& row)
165 Service::Ptr service = static_cast<Service::Ptr>(row);
170 return service->GetShortName();
173 Value ServicesTable::DisplayNameAccessor(const Value& row)
175 Service::Ptr service = static_cast<Service::Ptr>(row);
180 return service->GetDisplayName();
183 Value ServicesTable::CheckCommandAccessor(const Value& row)
185 Service::Ptr service = static_cast<Service::Ptr>(row);
190 CheckCommand::Ptr checkcommand = service->GetCheckCommand();
193 return checkcommand->GetName(); /* this is the name without '!' args */
198 Value ServicesTable::CheckCommandExpandedAccessor(const Value& row)
200 Service::Ptr service = static_cast<Service::Ptr>(row);
205 CheckCommand::Ptr checkcommand = service->GetCheckCommand();
208 return checkcommand->GetName(); /* this is the name without '!' args */
213 Value ServicesTable::EventHandlerAccessor(const Value& row)
215 Service::Ptr service = static_cast<Service::Ptr>(row);
220 EventCommand::Ptr eventcommand = service->GetEventCommand();
223 return eventcommand->GetName();
228 Value ServicesTable::PluginOutputAccessor(const Value& row)
230 Service::Ptr service = static_cast<Service::Ptr>(row);
236 CheckResult::Ptr cr = service->GetLastCheckResult();
239 output = CompatUtility::GetCheckResultOutput(cr);
244 Value ServicesTable::LongPluginOutputAccessor(const Value& row)
246 Service::Ptr service = static_cast<Service::Ptr>(row);
252 CheckResult::Ptr cr = service->GetLastCheckResult();
255 long_output = CompatUtility::GetCheckResultLongOutput(cr);
260 Value ServicesTable::PerfDataAccessor(const Value& row)
262 Service::Ptr service = static_cast<Service::Ptr>(row);
268 CheckResult::Ptr cr = service->GetLastCheckResult();
271 perfdata = CompatUtility::GetCheckResultPerfdata(cr);
276 Value ServicesTable::NotificationPeriodAccessor(const Value& row)
278 Service::Ptr service = static_cast<Service::Ptr>(row);
283 return CompatUtility::GetCheckableNotificationNotificationPeriod(service);
286 Value ServicesTable::CheckPeriodAccessor(const Value& row)
288 Service::Ptr service = static_cast<Service::Ptr>(row);
293 return CompatUtility::GetCheckableCheckPeriod(service);
296 Value ServicesTable::NotesAccessor(const Value& row)
298 Service::Ptr service = static_cast<Service::Ptr>(row);
303 return service->GetNotes();
306 Value ServicesTable::NotesExpandedAccessor(const Value& row)
308 Service::Ptr service = static_cast<Service::Ptr>(row);
313 MacroProcessor::ResolverList resolvers;
314 resolvers.push_back(std::make_pair("service", service));
315 resolvers.push_back(std::make_pair("host", service->GetHost()));
316 resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance()));
318 return MacroProcessor::ResolveMacros(service->GetNotes(), resolvers, CheckResult::Ptr(), Utility::EscapeShellCmd);
321 Value ServicesTable::NotesUrlAccessor(const Value& row)
323 Service::Ptr service = static_cast<Service::Ptr>(row);
328 return service->GetNotesUrl();
331 Value ServicesTable::NotesUrlExpandedAccessor(const Value& row)
333 Service::Ptr service = static_cast<Service::Ptr>(row);
338 MacroProcessor::ResolverList resolvers;
339 resolvers.push_back(std::make_pair("service", service));
340 resolvers.push_back(std::make_pair("host", service->GetHost()));
341 resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance()));
343 return MacroProcessor::ResolveMacros(service->GetNotesUrl(), resolvers, CheckResult::Ptr(), Utility::EscapeShellCmd);
346 Value ServicesTable::ActionUrlAccessor(const Value& row)
348 Service::Ptr service = static_cast<Service::Ptr>(row);
353 return service->GetActionUrl();
356 Value ServicesTable::ActionUrlExpandedAccessor(const Value& row)
358 Service::Ptr service = static_cast<Service::Ptr>(row);
363 MacroProcessor::ResolverList resolvers;
364 resolvers.push_back(std::make_pair("service", service));
365 resolvers.push_back(std::make_pair("host", service->GetHost()));
366 resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance()));
368 return MacroProcessor::ResolveMacros(service->GetActionUrl(), resolvers, CheckResult::Ptr(), Utility::EscapeShellCmd);
371 Value ServicesTable::IconImageAccessor(const Value& row)
373 Service::Ptr service = static_cast<Service::Ptr>(row);
378 return service->GetIconImage();
381 Value ServicesTable::IconImageExpandedAccessor(const Value& row)
383 Service::Ptr service = static_cast<Service::Ptr>(row);
388 MacroProcessor::ResolverList resolvers;
389 resolvers.push_back(std::make_pair("service", service));
390 resolvers.push_back(std::make_pair("host", service->GetHost()));
391 resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance()));
393 return MacroProcessor::ResolveMacros(service->GetIconImage(), resolvers, CheckResult::Ptr(), Utility::EscapeShellCmd);
396 Value ServicesTable::IconImageAltAccessor(const Value& row)
398 Service::Ptr service = static_cast<Service::Ptr>(row);
403 return service->GetIconImageAlt();
406 Value ServicesTable::MaxCheckAttemptsAccessor(const Value& row)
408 Service::Ptr service = static_cast<Service::Ptr>(row);
413 return service->GetMaxCheckAttempts();
416 Value ServicesTable::CurrentAttemptAccessor(const Value& row)
418 Service::Ptr service = static_cast<Service::Ptr>(row);
423 return service->GetCheckAttempt();
426 Value ServicesTable::StateAccessor(const Value& row)
428 Service::Ptr service = static_cast<Service::Ptr>(row);
433 return service->GetState();
436 Value ServicesTable::HasBeenCheckedAccessor(const Value& row)
438 Service::Ptr service = static_cast<Service::Ptr>(row);
443 return CompatUtility::GetCheckableHasBeenChecked(service);
446 Value ServicesTable::LastStateAccessor(const Value& row)
448 Service::Ptr service = static_cast<Service::Ptr>(row);
453 return service->GetLastState();
456 Value ServicesTable::LastHardStateAccessor(const Value& row)
458 Service::Ptr service = static_cast<Service::Ptr>(row);
463 return service->GetLastHardState();
466 Value ServicesTable::StateTypeAccessor(const Value& row)
468 Service::Ptr service = static_cast<Service::Ptr>(row);
473 return service->GetStateType();
476 Value ServicesTable::CheckTypeAccessor(const Value& row)
478 Service::Ptr service = static_cast<Service::Ptr>(row);
483 return CompatUtility::GetCheckableCheckType(service);
486 Value ServicesTable::AcknowledgedAccessor(const Value& row)
488 Service::Ptr service = static_cast<Service::Ptr>(row);
493 return CompatUtility::GetCheckableIsAcknowledged(service);
496 Value ServicesTable::AcknowledgementTypeAccessor(const Value& row)
498 Service::Ptr service = static_cast<Service::Ptr>(row);
503 /* important: lock acknowledgements */
504 ObjectLock olock(service);
506 return static_cast<int>(service->GetAcknowledgement());
509 Value ServicesTable::NoMoreNotificationsAccessor(const Value& row)
511 Service::Ptr service = static_cast<Service::Ptr>(row);
516 return CompatUtility::GetCheckableNoMoreNotifications(service);
519 Value ServicesTable::LastTimeOkAccessor(const Value& row)
521 Service::Ptr service = static_cast<Service::Ptr>(row);
526 return static_cast<int>(service->GetLastStateOK());
529 Value ServicesTable::LastTimeWarningAccessor(const Value& row)
531 Service::Ptr service = static_cast<Service::Ptr>(row);
536 return static_cast<int>(service->GetLastStateWarning());
539 Value ServicesTable::LastTimeCriticalAccessor(const Value& row)
541 Service::Ptr service = static_cast<Service::Ptr>(row);
546 return static_cast<int>(service->GetLastStateCritical());
549 Value ServicesTable::LastTimeUnknownAccessor(const Value& row)
551 Service::Ptr service = static_cast<Service::Ptr>(row);
556 return static_cast<int>(service->GetLastStateUnknown());
559 Value ServicesTable::LastCheckAccessor(const Value& row)
561 Service::Ptr service = static_cast<Service::Ptr>(row);
566 return static_cast<int>(service->GetLastCheck());
569 Value ServicesTable::NextCheckAccessor(const Value& row)
571 Service::Ptr service = static_cast<Service::Ptr>(row);
576 return static_cast<int>(service->GetNextCheck());
579 Value ServicesTable::LastNotificationAccessor(const Value& row)
581 Service::Ptr service = static_cast<Service::Ptr>(row);
586 return CompatUtility::GetCheckableNotificationLastNotification(service);
589 Value ServicesTable::NextNotificationAccessor(const Value& row)
591 Service::Ptr service = static_cast<Service::Ptr>(row);
596 return CompatUtility::GetCheckableNotificationNextNotification(service);
599 Value ServicesTable::CurrentNotificationNumberAccessor(const Value& row)
601 Service::Ptr service = static_cast<Service::Ptr>(row);
606 return CompatUtility::GetCheckableNotificationNotificationNumber(service);
609 Value ServicesTable::LastStateChangeAccessor(const Value& row)
611 Service::Ptr service = static_cast<Service::Ptr>(row);
616 return static_cast<int>(service->GetLastStateChange());
619 Value ServicesTable::LastHardStateChangeAccessor(const Value& row)
621 Service::Ptr service = static_cast<Service::Ptr>(row);
626 return static_cast<int>(service->GetLastHardStateChange());
629 Value ServicesTable::ScheduledDowntimeDepthAccessor(const Value& row)
631 Service::Ptr service = static_cast<Service::Ptr>(row);
636 return service->GetDowntimeDepth();
639 Value ServicesTable::IsFlappingAccessor(const Value& row)
641 Service::Ptr service = static_cast<Service::Ptr>(row);
646 return service->IsFlapping();
649 Value ServicesTable::ChecksEnabledAccessor(const Value& row)
651 Service::Ptr service = static_cast<Service::Ptr>(row);
656 return CompatUtility::GetCheckableActiveChecksEnabled(service);
659 Value ServicesTable::AcceptPassiveChecksAccessor(const Value& row)
661 Service::Ptr service = static_cast<Service::Ptr>(row);
666 return CompatUtility::GetCheckablePassiveChecksEnabled(service);
669 Value ServicesTable::EventHandlerEnabledAccessor(const Value& row)
671 Service::Ptr service = static_cast<Service::Ptr>(row);
676 return CompatUtility::GetCheckableEventHandlerEnabled(service);
679 Value ServicesTable::NotificationsEnabledAccessor(const Value& row)
681 Service::Ptr service = static_cast<Service::Ptr>(row);
686 return CompatUtility::GetCheckableNotificationsEnabled(service);
689 Value ServicesTable::ProcessPerformanceDataAccessor(const Value& row)
691 Service::Ptr service = static_cast<Service::Ptr>(row);
696 return CompatUtility::GetCheckableProcessPerformanceData(service);
699 Value ServicesTable::ActiveChecksEnabledAccessor(const Value& row)
701 Service::Ptr service = static_cast<Service::Ptr>(row);
706 return CompatUtility::GetCheckableActiveChecksEnabled(service);
709 Value ServicesTable::CheckOptionsAccessor(const Value& row)
711 /* TODO - forcexec, freshness, orphan, none */
715 Value ServicesTable::FlapDetectionEnabledAccessor(const Value& row)
717 Service::Ptr service = static_cast<Service::Ptr>(row);
722 return CompatUtility::GetCheckableFlapDetectionEnabled(service);
725 Value ServicesTable::CheckFreshnessAccessor(const Value& row)
727 Service::Ptr service = static_cast<Service::Ptr>(row);
732 return CompatUtility::GetCheckableFreshnessChecksEnabled(service);
735 Value ServicesTable::ModifiedAttributesAccessor(const Value& row)
737 Service::Ptr service = static_cast<Service::Ptr>(row);
742 return service->GetModifiedAttributes();
745 Value ServicesTable::ModifiedAttributesListAccessor(const Value& row)
751 Value ServicesTable::StalenessAccessor(const Value& row)
753 Service::Ptr service = static_cast<Service::Ptr>(row);
758 return CompatUtility::GetCheckableStaleness(service);
761 Value ServicesTable::CheckIntervalAccessor(const Value& row)
763 Service::Ptr service = static_cast<Service::Ptr>(row);
768 return CompatUtility::GetCheckableCheckInterval(service);
771 Value ServicesTable::RetryIntervalAccessor(const Value& row)
773 Service::Ptr service = static_cast<Service::Ptr>(row);
778 return CompatUtility::GetCheckableRetryInterval(service);
781 Value ServicesTable::NotificationIntervalAccessor(const Value& row)
783 Service::Ptr service = static_cast<Service::Ptr>(row);
788 return CompatUtility::GetCheckableNotificationNotificationInterval(service);
791 Value ServicesTable::LowFlapThresholdAccessor(const Value& row)
793 Service::Ptr service = static_cast<Service::Ptr>(row);
798 return CompatUtility::GetCheckableLowFlapThreshold(service);
801 Value ServicesTable::HighFlapThresholdAccessor(const Value& row)
803 Service::Ptr service = static_cast<Service::Ptr>(row);
808 return CompatUtility::GetCheckableHighFlapThreshold(service);
811 Value ServicesTable::LatencyAccessor(const Value& row)
813 Service::Ptr service = static_cast<Service::Ptr>(row);
818 return (Service::CalculateLatency(service->GetLastCheckResult()));
821 Value ServicesTable::ExecutionTimeAccessor(const Value& row)
823 Service::Ptr service = static_cast<Service::Ptr>(row);
828 return (Service::CalculateExecutionTime(service->GetLastCheckResult()));
831 Value ServicesTable::PercentStateChangeAccessor(const Value& row)
833 Service::Ptr service = static_cast<Service::Ptr>(row);
838 return CompatUtility::GetCheckablePercentStateChange(service);
841 Value ServicesTable::InCheckPeriodAccessor(const Value& row)
843 Service::Ptr service = static_cast<Service::Ptr>(row);
848 return CompatUtility::GetCheckableInCheckPeriod(service);
851 Value ServicesTable::InNotificationPeriodAccessor(const Value& row)
853 Service::Ptr service = static_cast<Service::Ptr>(row);
858 return CompatUtility::GetCheckableInNotificationPeriod(service);
861 Value ServicesTable::ContactsAccessor(const Value& row)
863 Service::Ptr service = static_cast<Service::Ptr>(row);
868 Array::Ptr contact_names = make_shared<Array>();
870 BOOST_FOREACH(const User::Ptr& user, CompatUtility::GetCheckableNotificationUsers(service)) {
871 contact_names->Add(user->GetName());
874 return contact_names;
877 Value ServicesTable::DowntimesAccessor(const Value& row)
879 Service::Ptr service = static_cast<Service::Ptr>(row);
884 Dictionary::Ptr downtimes = service->GetDowntimes();
886 Array::Ptr ids = make_shared<Array>();
888 ObjectLock olock(downtimes);
891 Downtime::Ptr downtime;
892 BOOST_FOREACH(tie(id, downtime), downtimes) {
897 if (downtime->IsExpired())
900 ids->Add(downtime->GetLegacyId());
906 Value ServicesTable::DowntimesWithInfoAccessor(const Value& row)
908 Service::Ptr service = static_cast<Service::Ptr>(row);
913 Dictionary::Ptr downtimes = service->GetDowntimes();
915 Array::Ptr ids = make_shared<Array>();
917 ObjectLock olock(downtimes);
920 Downtime::Ptr downtime;
921 BOOST_FOREACH(tie(id, downtime), downtimes) {
926 if (downtime->IsExpired())
929 Array::Ptr downtime_info = make_shared<Array>();
930 downtime_info->Add(downtime->GetLegacyId());
931 downtime_info->Add(downtime->GetAuthor());
932 downtime_info->Add(downtime->GetComment());
933 ids->Add(downtime_info);
939 Value ServicesTable::CommentsAccessor(const Value& row)
941 Service::Ptr service = static_cast<Service::Ptr>(row);
946 Dictionary::Ptr comments = service->GetComments();
948 Array::Ptr ids = make_shared<Array>();
950 ObjectLock olock(comments);
953 Comment::Ptr comment;
954 BOOST_FOREACH(tie(id, comment), comments) {
959 if (comment->IsExpired())
962 ids->Add(comment->GetLegacyId());
968 Value ServicesTable::CommentsWithInfoAccessor(const Value& row)
970 Service::Ptr service = static_cast<Service::Ptr>(row);
975 Dictionary::Ptr comments = service->GetComments();
977 Array::Ptr ids = make_shared<Array>();
979 ObjectLock olock(comments);
982 Comment::Ptr comment;
983 BOOST_FOREACH(tie(id, comment), comments) {
988 if (comment->IsExpired())
991 Array::Ptr comment_info = make_shared<Array>();
992 comment_info->Add(comment->GetLegacyId());
993 comment_info->Add(comment->GetAuthor());
994 comment_info->Add(comment->GetText());
995 ids->Add(comment_info);
1001 Value ServicesTable::CommentsWithExtraInfoAccessor(const Value& row)
1003 Service::Ptr service = static_cast<Service::Ptr>(row);
1008 Dictionary::Ptr comments = service->GetComments();
1010 Array::Ptr ids = make_shared<Array>();
1012 ObjectLock olock(comments);
1015 Comment::Ptr comment;
1016 BOOST_FOREACH(tie(id, comment), comments) {
1021 if (comment->IsExpired())
1024 Array::Ptr comment_info = make_shared<Array>();
1025 comment_info->Add(comment->GetLegacyId());
1026 comment_info->Add(comment->GetAuthor());
1027 comment_info->Add(comment->GetText());
1028 comment_info->Add(comment->GetEntryType());
1029 comment_info->Add(static_cast<int>(comment->GetEntryTime()));
1030 ids->Add(comment_info);
1036 Value ServicesTable::CustomVariableNamesAccessor(const Value& row)
1038 Service::Ptr service = static_cast<Service::Ptr>(row);
1043 Dictionary::Ptr vars;
1046 ObjectLock olock(service);
1047 vars = CompatUtility::GetCustomAttributeConfig(service);
1053 Array::Ptr cv = make_shared<Array>();
1057 BOOST_FOREACH(tie(key, value), vars) {
1064 Value ServicesTable::CustomVariableValuesAccessor(const Value& row)
1066 Service::Ptr service = static_cast<Service::Ptr>(row);
1071 Dictionary::Ptr vars;
1074 ObjectLock olock(service);
1075 vars = CompatUtility::GetCustomAttributeConfig(service);
1081 Array::Ptr cv = make_shared<Array>();
1085 BOOST_FOREACH(tie(key, value), vars) {
1092 Value ServicesTable::CustomVariablesAccessor(const Value& row)
1094 Service::Ptr service = static_cast<Service::Ptr>(row);
1099 Dictionary::Ptr vars;
1102 ObjectLock olock(service);
1103 vars = CompatUtility::GetCustomAttributeConfig(service);
1109 Array::Ptr cv = make_shared<Array>();
1113 BOOST_FOREACH(tie(key, value), vars) {
1114 Array::Ptr key_val = make_shared<Array>();
1116 key_val->Add(value);
1123 Value ServicesTable::GroupsAccessor(const Value& row)
1125 Service::Ptr service = static_cast<Service::Ptr>(row);
1130 Array::Ptr groups = service->GetGroups();
1138 Value ServicesTable::ContactGroupsAccessor(const Value& row)
1140 Service::Ptr service = static_cast<Service::Ptr>(row);
1145 Array::Ptr contactgroup_names = make_shared<Array>();
1147 BOOST_FOREACH(const UserGroup::Ptr& usergroup, CompatUtility::GetCheckableNotificationUserGroups(service)) {
1148 contactgroup_names->Add(usergroup->GetName());
1151 return contactgroup_names;
1154 Value ServicesTable::CheckSourceAccessor(const Value& row)
1156 Service::Ptr service = static_cast<Service::Ptr>(row);
1161 CheckResult::Ptr cr = service->GetLastCheckResult();
1164 return cr->GetCheckSource();