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::GetServiceNotificationNotificationPeriod(service);
286 Value ServicesTable::CheckPeriodAccessor(const Value& row)
288 Service::Ptr service = static_cast<Service::Ptr>(row);
293 return CompatUtility::GetServiceCheckPeriod(service);
296 Value ServicesTable::NotesAccessor(const Value& row)
298 Service::Ptr service = static_cast<Service::Ptr>(row);
303 return CompatUtility::GetCustomAttributeConfig(service, "notes");
306 Value ServicesTable::NotesExpandedAccessor(const Value& row)
308 Service::Ptr service = static_cast<Service::Ptr>(row);
313 std::vector<MacroResolver::Ptr> resolvers;
314 resolvers.push_back(service);
315 resolvers.push_back(service->GetHost());
316 resolvers.push_back(IcingaApplication::GetInstance());
318 Value value = CompatUtility::GetCustomAttributeConfig(service, "notes");
320 return MacroProcessor::ResolveMacros(value, resolvers, CheckResult::Ptr(), Utility::EscapeShellCmd);
323 Value ServicesTable::NotesUrlAccessor(const Value& row)
325 Service::Ptr service = static_cast<Service::Ptr>(row);
330 return CompatUtility::GetCustomAttributeConfig(service, "notes_url");
333 Value ServicesTable::NotesUrlExpandedAccessor(const Value& row)
335 Service::Ptr service = static_cast<Service::Ptr>(row);
340 std::vector<MacroResolver::Ptr> resolvers;
341 resolvers.push_back(service);
342 resolvers.push_back(service->GetHost());
343 resolvers.push_back(IcingaApplication::GetInstance());
345 Value value = CompatUtility::GetCustomAttributeConfig(service, "notes_url");
347 return MacroProcessor::ResolveMacros(value, resolvers, CheckResult::Ptr(), Utility::EscapeShellCmd);
350 Value ServicesTable::ActionUrlAccessor(const Value& row)
352 Service::Ptr service = static_cast<Service::Ptr>(row);
357 return CompatUtility::GetCustomAttributeConfig(service, "action_url");
360 Value ServicesTable::ActionUrlExpandedAccessor(const Value& row)
362 Service::Ptr service = static_cast<Service::Ptr>(row);
367 std::vector<MacroResolver::Ptr> resolvers;
368 resolvers.push_back(service);
369 resolvers.push_back(service->GetHost());
370 resolvers.push_back(IcingaApplication::GetInstance());
372 Value value = CompatUtility::GetCustomAttributeConfig(service, "action_url");
374 return MacroProcessor::ResolveMacros(value, resolvers, CheckResult::Ptr(), Utility::EscapeShellCmd);
377 Value ServicesTable::IconImageAccessor(const Value& row)
379 Service::Ptr service = static_cast<Service::Ptr>(row);
384 return CompatUtility::GetCustomAttributeConfig(service, "icon_image");
387 Value ServicesTable::IconImageExpandedAccessor(const Value& row)
389 Service::Ptr service = static_cast<Service::Ptr>(row);
394 std::vector<MacroResolver::Ptr> resolvers;
395 resolvers.push_back(service);
396 resolvers.push_back(service->GetHost());
397 resolvers.push_back(IcingaApplication::GetInstance());
399 Value value = CompatUtility::GetCustomAttributeConfig(service, "icon_image");
401 return MacroProcessor::ResolveMacros(value, resolvers, CheckResult::Ptr(), Utility::EscapeShellCmd);
404 Value ServicesTable::IconImageAltAccessor(const Value& row)
406 Service::Ptr service = static_cast<Service::Ptr>(row);
411 return CompatUtility::GetCustomAttributeConfig(service, "icon_image_alt");
414 Value ServicesTable::MaxCheckAttemptsAccessor(const Value& row)
416 Service::Ptr service = static_cast<Service::Ptr>(row);
421 return service->GetMaxCheckAttempts();
424 Value ServicesTable::CurrentAttemptAccessor(const Value& row)
426 Service::Ptr service = static_cast<Service::Ptr>(row);
431 return service->GetCheckAttempt();
434 Value ServicesTable::StateAccessor(const Value& row)
436 Service::Ptr service = static_cast<Service::Ptr>(row);
441 return CompatUtility::GetServiceCurrentState(service);
444 Value ServicesTable::HasBeenCheckedAccessor(const Value& row)
446 Service::Ptr service = static_cast<Service::Ptr>(row);
451 return CompatUtility::GetServiceHasBeenChecked(service);
454 Value ServicesTable::LastStateAccessor(const Value& row)
456 Service::Ptr service = static_cast<Service::Ptr>(row);
461 return service->GetLastState();
464 Value ServicesTable::LastHardStateAccessor(const Value& row)
466 Service::Ptr service = static_cast<Service::Ptr>(row);
471 return service->GetLastHardState();
474 Value ServicesTable::StateTypeAccessor(const Value& row)
476 Service::Ptr service = static_cast<Service::Ptr>(row);
481 return service->GetStateType();
484 Value ServicesTable::CheckTypeAccessor(const Value& row)
486 Service::Ptr service = static_cast<Service::Ptr>(row);
491 return CompatUtility::GetServiceCheckType(service);
494 Value ServicesTable::AcknowledgedAccessor(const Value& row)
496 Service::Ptr service = static_cast<Service::Ptr>(row);
502 return CompatUtility::GetServiceIsAcknowledged(service);
505 Value ServicesTable::AcknowledgementTypeAccessor(const Value& row)
507 Service::Ptr service = static_cast<Service::Ptr>(row);
512 /* important: lock acknowledgements */
513 ObjectLock olock(service);
515 return static_cast<int>(service->GetAcknowledgement());
518 Value ServicesTable::NoMoreNotificationsAccessor(const Value& row)
520 Service::Ptr service = static_cast<Service::Ptr>(row);
525 return CompatUtility::GetServiceNoMoreNotifications(service);
528 Value ServicesTable::LastTimeOkAccessor(const Value& row)
530 Service::Ptr service = static_cast<Service::Ptr>(row);
535 return static_cast<int>(service->GetLastStateOK());
538 Value ServicesTable::LastTimeWarningAccessor(const Value& row)
540 Service::Ptr service = static_cast<Service::Ptr>(row);
545 return static_cast<int>(service->GetLastStateWarning());
548 Value ServicesTable::LastTimeCriticalAccessor(const Value& row)
550 Service::Ptr service = static_cast<Service::Ptr>(row);
555 return static_cast<int>(service->GetLastStateCritical());
558 Value ServicesTable::LastTimeUnknownAccessor(const Value& row)
560 Service::Ptr service = static_cast<Service::Ptr>(row);
565 return static_cast<int>(service->GetLastStateUnknown());
568 Value ServicesTable::LastCheckAccessor(const Value& row)
570 Service::Ptr service = static_cast<Service::Ptr>(row);
575 return static_cast<int>(service->GetLastCheck());
578 Value ServicesTable::NextCheckAccessor(const Value& row)
580 Service::Ptr service = static_cast<Service::Ptr>(row);
585 return static_cast<int>(service->GetNextCheck());
588 Value ServicesTable::LastNotificationAccessor(const Value& row)
590 Service::Ptr service = static_cast<Service::Ptr>(row);
595 return CompatUtility::GetServiceNotificationLastNotification(service);
598 Value ServicesTable::NextNotificationAccessor(const Value& row)
600 Service::Ptr service = static_cast<Service::Ptr>(row);
605 return CompatUtility::GetServiceNotificationNextNotification(service);
608 Value ServicesTable::CurrentNotificationNumberAccessor(const Value& row)
610 Service::Ptr service = static_cast<Service::Ptr>(row);
615 return CompatUtility::GetServiceNotificationNotificationNumber(service);
618 Value ServicesTable::LastStateChangeAccessor(const Value& row)
620 Service::Ptr service = static_cast<Service::Ptr>(row);
625 return static_cast<int>(service->GetLastStateChange());
628 Value ServicesTable::LastHardStateChangeAccessor(const Value& row)
630 Service::Ptr service = static_cast<Service::Ptr>(row);
635 return static_cast<int>(service->GetLastHardStateChange());
638 Value ServicesTable::ScheduledDowntimeDepthAccessor(const Value& row)
640 Service::Ptr service = static_cast<Service::Ptr>(row);
645 return service->GetDowntimeDepth();
648 Value ServicesTable::IsFlappingAccessor(const Value& row)
650 Service::Ptr service = static_cast<Service::Ptr>(row);
655 return service->IsFlapping();
658 Value ServicesTable::ChecksEnabledAccessor(const Value& row)
660 Service::Ptr service = static_cast<Service::Ptr>(row);
665 return CompatUtility::GetServiceActiveChecksEnabled(service);
668 Value ServicesTable::AcceptPassiveChecksAccessor(const Value& row)
670 Service::Ptr service = static_cast<Service::Ptr>(row);
675 return CompatUtility::GetServicePassiveChecksEnabled(service);
678 Value ServicesTable::EventHandlerEnabledAccessor(const Value& row)
680 Service::Ptr service = static_cast<Service::Ptr>(row);
685 return CompatUtility::GetServiceEventHandlerEnabled(service);
688 Value ServicesTable::NotificationsEnabledAccessor(const Value& row)
690 Service::Ptr service = static_cast<Service::Ptr>(row);
695 return CompatUtility::GetServiceNotificationsEnabled(service);
698 Value ServicesTable::ProcessPerformanceDataAccessor(const Value& row)
700 Service::Ptr service = static_cast<Service::Ptr>(row);
705 return CompatUtility::GetServiceProcessPerformanceData(service);
708 Value ServicesTable::ActiveChecksEnabledAccessor(const Value& row)
710 Service::Ptr service = static_cast<Service::Ptr>(row);
715 return CompatUtility::GetServiceActiveChecksEnabled(service);
718 Value ServicesTable::CheckOptionsAccessor(const Value& row)
720 /* TODO - forcexec, freshness, orphan, none */
724 Value ServicesTable::FlapDetectionEnabledAccessor(const Value& row)
726 Service::Ptr service = static_cast<Service::Ptr>(row);
731 return CompatUtility::GetServiceFlapDetectionEnabled(service);
734 Value ServicesTable::CheckFreshnessAccessor(const Value& row)
736 Service::Ptr service = static_cast<Service::Ptr>(row);
741 return CompatUtility::GetServiceFreshnessChecksEnabled(service);
744 Value ServicesTable::ModifiedAttributesAccessor(const Value& row)
746 Service::Ptr service = static_cast<Service::Ptr>(row);
751 return service->GetModifiedAttributes();
754 Value ServicesTable::ModifiedAttributesListAccessor(const Value& row)
760 Value ServicesTable::StalenessAccessor(const Value& row)
762 Service::Ptr service = static_cast<Service::Ptr>(row);
767 return CompatUtility::GetServiceStaleness(service);
770 Value ServicesTable::CheckIntervalAccessor(const Value& row)
772 Service::Ptr service = static_cast<Service::Ptr>(row);
777 return CompatUtility::GetServiceCheckInterval(service);
780 Value ServicesTable::RetryIntervalAccessor(const Value& row)
782 Service::Ptr service = static_cast<Service::Ptr>(row);
787 return CompatUtility::GetServiceRetryInterval(service);
790 Value ServicesTable::NotificationIntervalAccessor(const Value& row)
792 Service::Ptr service = static_cast<Service::Ptr>(row);
797 return CompatUtility::GetServiceNotificationNotificationInterval(service);
800 Value ServicesTable::LowFlapThresholdAccessor(const Value& row)
802 Service::Ptr service = static_cast<Service::Ptr>(row);
807 return CompatUtility::GetServiceLowFlapThreshold(service);
810 Value ServicesTable::HighFlapThresholdAccessor(const Value& row)
812 Service::Ptr service = static_cast<Service::Ptr>(row);
817 return CompatUtility::GetServiceHighFlapThreshold(service);
820 Value ServicesTable::LatencyAccessor(const Value& row)
822 Service::Ptr service = static_cast<Service::Ptr>(row);
827 return (Service::CalculateLatency(service->GetLastCheckResult()));
830 Value ServicesTable::ExecutionTimeAccessor(const Value& row)
832 Service::Ptr service = static_cast<Service::Ptr>(row);
837 return (Service::CalculateExecutionTime(service->GetLastCheckResult()));
840 Value ServicesTable::PercentStateChangeAccessor(const Value& row)
842 Service::Ptr service = static_cast<Service::Ptr>(row);
847 return CompatUtility::GetServicePercentStateChange(service);
850 Value ServicesTable::InCheckPeriodAccessor(const Value& row)
852 Service::Ptr service = static_cast<Service::Ptr>(row);
857 return CompatUtility::GetServiceInCheckPeriod(service);
860 Value ServicesTable::InNotificationPeriodAccessor(const Value& row)
862 Service::Ptr service = static_cast<Service::Ptr>(row);
867 return CompatUtility::GetServiceInNotificationPeriod(service);
870 Value ServicesTable::ContactsAccessor(const Value& row)
872 Service::Ptr service = static_cast<Service::Ptr>(row);
877 Array::Ptr contact_names = make_shared<Array>();
879 BOOST_FOREACH(const User::Ptr& user, CompatUtility::GetServiceNotificationUsers(service)) {
880 contact_names->Add(user->GetName());
883 return contact_names;
886 Value ServicesTable::DowntimesAccessor(const Value& row)
888 Service::Ptr service = static_cast<Service::Ptr>(row);
893 Dictionary::Ptr downtimes = service->GetDowntimes();
895 Array::Ptr ids = make_shared<Array>();
897 ObjectLock olock(downtimes);
900 Downtime::Ptr downtime;
901 BOOST_FOREACH(boost::tie(id, downtime), downtimes) {
906 if (downtime->IsExpired())
909 ids->Add(downtime->GetLegacyId());
915 Value ServicesTable::DowntimesWithInfoAccessor(const Value& row)
917 Service::Ptr service = static_cast<Service::Ptr>(row);
922 Dictionary::Ptr downtimes = service->GetDowntimes();
924 Array::Ptr ids = make_shared<Array>();
926 ObjectLock olock(downtimes);
929 Downtime::Ptr downtime;
930 BOOST_FOREACH(boost::tie(id, downtime), downtimes) {
935 if (downtime->IsExpired())
938 Array::Ptr downtime_info = make_shared<Array>();
939 downtime_info->Add(downtime->GetLegacyId());
940 downtime_info->Add(downtime->GetAuthor());
941 downtime_info->Add(downtime->GetComment());
942 ids->Add(downtime_info);
948 Value ServicesTable::CommentsAccessor(const Value& row)
950 Service::Ptr service = static_cast<Service::Ptr>(row);
955 Dictionary::Ptr comments = service->GetComments();
957 Array::Ptr ids = make_shared<Array>();
959 ObjectLock olock(comments);
962 Comment::Ptr comment;
963 BOOST_FOREACH(boost::tie(id, comment), comments) {
968 if (comment->IsExpired())
971 ids->Add(comment->GetLegacyId());
977 Value ServicesTable::CommentsWithInfoAccessor(const Value& row)
979 Service::Ptr service = static_cast<Service::Ptr>(row);
984 Dictionary::Ptr comments = service->GetComments();
986 Array::Ptr ids = make_shared<Array>();
988 ObjectLock olock(comments);
991 Comment::Ptr comment;
992 BOOST_FOREACH(boost::tie(id, comment), comments) {
997 if (comment->IsExpired())
1000 Array::Ptr comment_info = make_shared<Array>();
1001 comment_info->Add(comment->GetLegacyId());
1002 comment_info->Add(comment->GetAuthor());
1003 comment_info->Add(comment->GetText());
1004 ids->Add(comment_info);
1010 Value ServicesTable::CommentsWithExtraInfoAccessor(const Value& row)
1012 Service::Ptr service = static_cast<Service::Ptr>(row);
1017 Dictionary::Ptr comments = service->GetComments();
1019 Array::Ptr ids = make_shared<Array>();
1021 ObjectLock olock(comments);
1024 Comment::Ptr comment;
1025 BOOST_FOREACH(boost::tie(id, comment), comments) {
1030 if (comment->IsExpired())
1033 Array::Ptr comment_info = make_shared<Array>();
1034 comment_info->Add(comment->GetLegacyId());
1035 comment_info->Add(comment->GetAuthor());
1036 comment_info->Add(comment->GetText());
1037 comment_info->Add(comment->GetEntryType());
1038 comment_info->Add(static_cast<int>(comment->GetEntryTime()));
1039 ids->Add(comment_info);
1045 Value ServicesTable::CustomVariableNamesAccessor(const Value& row)
1047 Service::Ptr service = static_cast<Service::Ptr>(row);
1052 Dictionary::Ptr vars;
1055 ObjectLock olock(service);
1056 vars = CompatUtility::GetCustomAttributeConfig(service);
1062 Array::Ptr cv = make_shared<Array>();
1066 BOOST_FOREACH(boost::tie(key, value), 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>();
1094 BOOST_FOREACH(boost::tie(key, value), vars) {
1101 Value ServicesTable::CustomVariablesAccessor(const Value& row)
1103 Service::Ptr service = static_cast<Service::Ptr>(row);
1108 Dictionary::Ptr vars;
1111 ObjectLock olock(service);
1112 vars = CompatUtility::GetCustomAttributeConfig(service);
1118 Array::Ptr cv = make_shared<Array>();
1122 BOOST_FOREACH(boost::tie(key, value), vars) {
1123 Array::Ptr key_val = make_shared<Array>();
1125 key_val->Add(value);
1132 Value ServicesTable::GroupsAccessor(const Value& row)
1134 Service::Ptr service = static_cast<Service::Ptr>(row);
1139 Array::Ptr groups = service->GetGroups();
1147 Value ServicesTable::ContactGroupsAccessor(const Value& row)
1149 Service::Ptr service = static_cast<Service::Ptr>(row);
1154 Array::Ptr contactgroup_names = make_shared<Array>();
1156 BOOST_FOREACH(const UserGroup::Ptr& usergroup, CompatUtility::GetServiceNotificationUserGroups(service)) {
1157 contactgroup_names->Add(usergroup->GetName());
1160 return contactgroup_names;
1163 Value ServicesTable::CheckSourceAccessor(const Value& row)
1165 Service::Ptr service = static_cast<Service::Ptr>(row);
1170 CheckResult::Ptr cr = service->GetLastCheckResult();
1173 return cr->GetCheckSource();