1 /******************************************************************************
3 * Copyright (C) 2012-2017 Icinga Development Team (https://www.icinga.com/) *
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/servicegroupstable.hpp"
23 #include "livestatus/hostgroupstable.hpp"
24 #include "livestatus/endpointstable.hpp"
25 #include "icinga/service.hpp"
26 #include "icinga/servicegroup.hpp"
27 #include "icinga/hostgroup.hpp"
28 #include "icinga/checkcommand.hpp"
29 #include "icinga/eventcommand.hpp"
30 #include "icinga/timeperiod.hpp"
31 #include "icinga/macroprocessor.hpp"
32 #include "icinga/icingaapplication.hpp"
33 #include "icinga/compatutility.hpp"
34 #include "base/configtype.hpp"
35 #include "base/objectlock.hpp"
36 #include "base/json.hpp"
37 #include "base/convert.hpp"
38 #include "base/utility.hpp"
39 #include <boost/tuple/tuple.hpp>
40 #include <boost/algorithm/string/replace.hpp>
42 using namespace icinga;
44 ServicesTable::ServicesTable(LivestatusGroupByType type)
51 void ServicesTable::AddColumns(Table *table, const String& prefix,
52 const Column::ObjectAccessor& objectAccessor)
54 table->AddColumn(prefix + "description", Column(&ServicesTable::ShortNameAccessor, objectAccessor));
55 table->AddColumn(prefix + "service_description", Column(&ServicesTable::ShortNameAccessor, objectAccessor)); //ugly compatibility hack
56 table->AddColumn(prefix + "display_name", Column(&ServicesTable::DisplayNameAccessor, objectAccessor));
57 table->AddColumn(prefix + "check_command", Column(&ServicesTable::CheckCommandAccessor, objectAccessor));
58 table->AddColumn(prefix + "check_command_expanded", Column(&ServicesTable::CheckCommandExpandedAccessor, objectAccessor));
59 table->AddColumn(prefix + "event_handler", Column(&ServicesTable::EventHandlerAccessor, objectAccessor));
60 table->AddColumn(prefix + "plugin_output", Column(&ServicesTable::PluginOutputAccessor, objectAccessor));
61 table->AddColumn(prefix + "long_plugin_output", Column(&ServicesTable::LongPluginOutputAccessor, objectAccessor));
62 table->AddColumn(prefix + "perf_data", Column(&ServicesTable::PerfDataAccessor, objectAccessor));
63 table->AddColumn(prefix + "notification_period", Column(&Table::EmptyStringAccessor, objectAccessor));
64 table->AddColumn(prefix + "check_period", Column(&ServicesTable::CheckPeriodAccessor, objectAccessor));
65 table->AddColumn(prefix + "notes", Column(&ServicesTable::NotesAccessor, objectAccessor));
66 table->AddColumn(prefix + "notes_expanded", Column(&ServicesTable::NotesExpandedAccessor, objectAccessor));
67 table->AddColumn(prefix + "notes_url", Column(&ServicesTable::NotesUrlAccessor, objectAccessor));
68 table->AddColumn(prefix + "notes_url_expanded", Column(&ServicesTable::NotesUrlExpandedAccessor, objectAccessor));
69 table->AddColumn(prefix + "action_url", Column(&ServicesTable::ActionUrlAccessor, objectAccessor));
70 table->AddColumn(prefix + "action_url_expanded", Column(&ServicesTable::ActionUrlExpandedAccessor, objectAccessor));
71 table->AddColumn(prefix + "icon_image", Column(&ServicesTable::IconImageAccessor, objectAccessor));
72 table->AddColumn(prefix + "icon_image_expanded", Column(&ServicesTable::IconImageExpandedAccessor, objectAccessor));
73 table->AddColumn(prefix + "icon_image_alt", Column(&ServicesTable::IconImageAltAccessor, objectAccessor));
74 table->AddColumn(prefix + "initial_state", Column(&Table::EmptyStringAccessor, objectAccessor));
75 table->AddColumn(prefix + "max_check_attempts", Column(&ServicesTable::MaxCheckAttemptsAccessor, objectAccessor));
76 table->AddColumn(prefix + "current_attempt", Column(&ServicesTable::CurrentAttemptAccessor, objectAccessor));
77 table->AddColumn(prefix + "state", Column(&ServicesTable::StateAccessor, objectAccessor));
78 table->AddColumn(prefix + "has_been_checked", Column(&ServicesTable::HasBeenCheckedAccessor, objectAccessor));
79 table->AddColumn(prefix + "last_state", Column(&ServicesTable::LastStateAccessor, objectAccessor));
80 table->AddColumn(prefix + "last_hard_state", Column(&ServicesTable::LastHardStateAccessor, objectAccessor));
81 table->AddColumn(prefix + "state_type", Column(&ServicesTable::StateTypeAccessor, objectAccessor));
82 table->AddColumn(prefix + "check_type", Column(&ServicesTable::CheckTypeAccessor, objectAccessor));
83 table->AddColumn(prefix + "acknowledged", Column(&ServicesTable::AcknowledgedAccessor, objectAccessor));
84 table->AddColumn(prefix + "acknowledgement_type", Column(&ServicesTable::AcknowledgementTypeAccessor, objectAccessor));
85 table->AddColumn(prefix + "no_more_notifications", Column(&ServicesTable::NoMoreNotificationsAccessor, objectAccessor));
86 table->AddColumn(prefix + "last_time_ok", Column(&ServicesTable::LastTimeOkAccessor, objectAccessor));
87 table->AddColumn(prefix + "last_time_warning", Column(&ServicesTable::LastTimeWarningAccessor, objectAccessor));
88 table->AddColumn(prefix + "last_time_critical", Column(&ServicesTable::LastTimeCriticalAccessor, objectAccessor));
89 table->AddColumn(prefix + "last_time_unknown", Column(&ServicesTable::LastTimeUnknownAccessor, objectAccessor));
90 table->AddColumn(prefix + "last_check", Column(&ServicesTable::LastCheckAccessor, objectAccessor));
91 table->AddColumn(prefix + "next_check", Column(&ServicesTable::NextCheckAccessor, objectAccessor));
92 table->AddColumn(prefix + "last_notification", Column(&ServicesTable::LastNotificationAccessor, objectAccessor));
93 table->AddColumn(prefix + "next_notification", Column(&ServicesTable::NextNotificationAccessor, objectAccessor));
94 table->AddColumn(prefix + "current_notification_number", Column(&ServicesTable::CurrentNotificationNumberAccessor, objectAccessor));
95 table->AddColumn(prefix + "last_state_change", Column(&ServicesTable::LastStateChangeAccessor, objectAccessor));
96 table->AddColumn(prefix + "last_hard_state_change", Column(&ServicesTable::LastHardStateChangeAccessor, objectAccessor));
97 table->AddColumn(prefix + "scheduled_downtime_depth", Column(&ServicesTable::ScheduledDowntimeDepthAccessor, objectAccessor));
98 table->AddColumn(prefix + "is_flapping", Column(&ServicesTable::IsFlappingAccessor, objectAccessor));
99 table->AddColumn(prefix + "checks_enabled", Column(&ServicesTable::ChecksEnabledAccessor, objectAccessor));
100 table->AddColumn(prefix + "accept_passive_checks", Column(&ServicesTable::AcceptPassiveChecksAccessor, objectAccessor));
101 table->AddColumn(prefix + "event_handler_enabled", Column(&ServicesTable::EventHandlerEnabledAccessor, objectAccessor));
102 table->AddColumn(prefix + "notifications_enabled", Column(&ServicesTable::NotificationsEnabledAccessor, objectAccessor));
103 table->AddColumn(prefix + "process_performance_data", Column(&ServicesTable::ProcessPerformanceDataAccessor, objectAccessor));
104 table->AddColumn(prefix + "is_executing", Column(&Table::ZeroAccessor, objectAccessor));
105 table->AddColumn(prefix + "active_checks_enabled", Column(&ServicesTable::ActiveChecksEnabledAccessor, objectAccessor));
106 table->AddColumn(prefix + "check_options", Column(&ServicesTable::CheckOptionsAccessor, objectAccessor));
107 table->AddColumn(prefix + "flap_detection_enabled", Column(&ServicesTable::FlapDetectionEnabledAccessor, objectAccessor));
108 table->AddColumn(prefix + "check_freshness", Column(&ServicesTable::CheckFreshnessAccessor, objectAccessor));
109 table->AddColumn(prefix + "obsess_over_service", Column(&Table::ZeroAccessor, objectAccessor));
110 table->AddColumn(prefix + "modified_attributes", Column(&Table::ZeroAccessor, objectAccessor));
111 table->AddColumn(prefix + "modified_attributes_list", Column(&Table::ZeroAccessor, objectAccessor));
112 table->AddColumn(prefix + "pnpgraph_present", Column(&Table::ZeroAccessor, objectAccessor));
113 table->AddColumn(prefix + "staleness", Column(&ServicesTable::StalenessAccessor, objectAccessor));
114 table->AddColumn(prefix + "check_interval", Column(&ServicesTable::CheckIntervalAccessor, objectAccessor));
115 table->AddColumn(prefix + "retry_interval", Column(&ServicesTable::RetryIntervalAccessor, objectAccessor));
116 table->AddColumn(prefix + "notification_interval", Column(&ServicesTable::NotificationIntervalAccessor, objectAccessor));
117 table->AddColumn(prefix + "first_notification_delay", Column(&Table::EmptyStringAccessor, objectAccessor));
118 table->AddColumn(prefix + "low_flap_threshold", Column(&ServicesTable::LowFlapThresholdAccessor, objectAccessor));
119 table->AddColumn(prefix + "high_flap_threshold", Column(&ServicesTable::HighFlapThresholdAccessor, objectAccessor));
120 table->AddColumn(prefix + "latency", Column(&ServicesTable::LatencyAccessor, objectAccessor));
121 table->AddColumn(prefix + "execution_time", Column(&ServicesTable::ExecutionTimeAccessor, objectAccessor));
122 table->AddColumn(prefix + "percent_state_change", Column(&ServicesTable::PercentStateChangeAccessor, objectAccessor));
123 table->AddColumn(prefix + "in_check_period", Column(&ServicesTable::InCheckPeriodAccessor, objectAccessor));
124 table->AddColumn(prefix + "in_notification_period", Column(&ServicesTable::InNotificationPeriodAccessor, objectAccessor));
125 table->AddColumn(prefix + "contacts", Column(&ServicesTable::ContactsAccessor, objectAccessor));
126 table->AddColumn(prefix + "downtimes", Column(&ServicesTable::DowntimesAccessor, objectAccessor));
127 table->AddColumn(prefix + "downtimes_with_info", Column(&ServicesTable::DowntimesWithInfoAccessor, objectAccessor));
128 table->AddColumn(prefix + "comments", Column(&ServicesTable::CommentsAccessor, objectAccessor));
129 table->AddColumn(prefix + "comments_with_info", Column(&ServicesTable::CommentsWithInfoAccessor, objectAccessor));
130 table->AddColumn(prefix + "comments_with_extra_info", Column(&ServicesTable::CommentsWithExtraInfoAccessor, objectAccessor));
131 table->AddColumn(prefix + "custom_variable_names", Column(&ServicesTable::CustomVariableNamesAccessor, objectAccessor));
132 table->AddColumn(prefix + "custom_variable_values", Column(&ServicesTable::CustomVariableValuesAccessor, objectAccessor));
133 table->AddColumn(prefix + "custom_variables", Column(&ServicesTable::CustomVariablesAccessor, objectAccessor));
134 table->AddColumn(prefix + "groups", Column(&ServicesTable::GroupsAccessor, objectAccessor));
135 table->AddColumn(prefix + "contact_groups", Column(&ServicesTable::ContactGroupsAccessor, objectAccessor));
136 table->AddColumn(prefix + "check_source", Column(&ServicesTable::CheckSourceAccessor, objectAccessor));
137 table->AddColumn(prefix + "is_reachable", Column(&ServicesTable::IsReachableAccessor, objectAccessor));
138 table->AddColumn(prefix + "cv_is_json", Column(&ServicesTable::CVIsJsonAccessor, objectAccessor));
139 table->AddColumn(prefix + "original_attributes", Column(&ServicesTable::OriginalAttributesAccessor, objectAccessor));
141 HostsTable::AddColumns(table, "host_", std::bind(&ServicesTable::HostAccessor, _1, objectAccessor));
143 /* add additional group by values received through the object accessor */
144 if (table->GetGroupByType() == LivestatusGroupByServiceGroup) {
145 /* _1 = row, _2 = groupByType, _3 = groupByObject */
146 Log(LogDebug, "Livestatus")
147 << "Processing services group by servicegroup table.";
148 ServiceGroupsTable::AddColumns(table, "servicegroup_", std::bind(&ServicesTable::ServiceGroupAccessor, _1, _2, _3));
149 } else if (table->GetGroupByType() == LivestatusGroupByHostGroup) {
150 /* _1 = row, _2 = groupByType, _3 = groupByObject */
151 Log(LogDebug, "Livestatus")
152 << "Processing services group by hostgroup table.";
153 HostGroupsTable::AddColumns(table, "hostgroup_", std::bind(&ServicesTable::HostGroupAccessor, _1, _2, _3));
157 String ServicesTable::GetName(void) const
162 String ServicesTable::GetPrefix(void) const
167 void ServicesTable::FetchRows(const AddRowFunction& addRowFn)
169 if (GetGroupByType() == LivestatusGroupByServiceGroup) {
170 for (const ServiceGroup::Ptr& sg : ConfigType::GetObjectsByType<ServiceGroup>()) {
171 for (const Service::Ptr& service : sg->GetMembers()) {
172 /* the caller must know which groupby type and value are set for this row */
173 if (!addRowFn(service, LivestatusGroupByServiceGroup, sg))
177 } else if (GetGroupByType() == LivestatusGroupByHostGroup) {
178 for (const HostGroup::Ptr& hg : ConfigType::GetObjectsByType<HostGroup>()) {
179 ObjectLock ylock(hg);
180 for (const Host::Ptr& host : hg->GetMembers()) {
181 ObjectLock ylock(host);
182 for (const Service::Ptr& service : host->GetServices()) {
183 /* the caller must know which groupby type and value are set for this row */
184 if (!addRowFn(service, LivestatusGroupByHostGroup, hg))
190 for (const Service::Ptr& service : ConfigType::GetObjectsByType<Service>()) {
191 if (!addRowFn(service, LivestatusGroupByNone, Empty))
197 Object::Ptr ServicesTable::HostAccessor(const Value& row, const Column::ObjectAccessor& parentObjectAccessor)
201 if (parentObjectAccessor)
202 service = parentObjectAccessor(row, LivestatusGroupByNone, Empty);
206 Service::Ptr svc = static_cast<Service::Ptr>(service);
211 return svc->GetHost();
214 Object::Ptr ServicesTable::ServiceGroupAccessor(const Value& row, LivestatusGroupByType groupByType, const Object::Ptr& groupByObject)
216 /* return the current group by value set from within FetchRows()
217 * this is the servicegroup object used for the table join inside
220 if (groupByType == LivestatusGroupByServiceGroup)
221 return groupByObject;
226 Object::Ptr ServicesTable::HostGroupAccessor(const Value& row, LivestatusGroupByType groupByType, const Object::Ptr& groupByObject)
228 /* return the current group by value set from within FetchRows()
229 * this is the servicegroup object used for the table join inside
232 if (groupByType == LivestatusGroupByHostGroup)
233 return groupByObject;
238 Value ServicesTable::ShortNameAccessor(const Value& row)
240 Service::Ptr service = static_cast<Service::Ptr>(row);
245 return service->GetShortName();
248 Value ServicesTable::DisplayNameAccessor(const Value& row)
250 Service::Ptr service = static_cast<Service::Ptr>(row);
255 return service->GetDisplayName();
258 Value ServicesTable::CheckCommandAccessor(const Value& row)
260 Service::Ptr service = static_cast<Service::Ptr>(row);
265 CheckCommand::Ptr checkcommand = service->GetCheckCommand();
268 return CompatUtility::GetCommandName(checkcommand) + "!" + CompatUtility::GetCheckableCommandArgs(service);
273 Value ServicesTable::CheckCommandExpandedAccessor(const Value& row)
275 Service::Ptr service = static_cast<Service::Ptr>(row);
280 CheckCommand::Ptr checkcommand = service->GetCheckCommand();
283 return CompatUtility::GetCommandName(checkcommand) + "!" + CompatUtility::GetCheckableCommandArgs(service);
288 Value ServicesTable::EventHandlerAccessor(const Value& row)
290 Service::Ptr service = static_cast<Service::Ptr>(row);
295 EventCommand::Ptr eventcommand = service->GetEventCommand();
298 return CompatUtility::GetCommandName(eventcommand);
303 Value ServicesTable::PluginOutputAccessor(const Value& row)
305 Service::Ptr service = static_cast<Service::Ptr>(row);
311 CheckResult::Ptr cr = service->GetLastCheckResult();
314 output = CompatUtility::GetCheckResultOutput(cr);
319 Value ServicesTable::LongPluginOutputAccessor(const Value& row)
321 Service::Ptr service = static_cast<Service::Ptr>(row);
327 CheckResult::Ptr cr = service->GetLastCheckResult();
330 long_output = CompatUtility::GetCheckResultLongOutput(cr);
335 Value ServicesTable::PerfDataAccessor(const Value& row)
337 Service::Ptr service = static_cast<Service::Ptr>(row);
343 CheckResult::Ptr cr = service->GetLastCheckResult();
346 perfdata = CompatUtility::GetCheckResultPerfdata(cr);
351 Value ServicesTable::CheckPeriodAccessor(const Value& row)
353 Service::Ptr service = static_cast<Service::Ptr>(row);
358 return CompatUtility::GetCheckableCheckPeriod(service);
361 Value ServicesTable::NotesAccessor(const Value& row)
363 Service::Ptr service = static_cast<Service::Ptr>(row);
368 return service->GetNotes();
371 Value ServicesTable::NotesExpandedAccessor(const Value& row)
373 Service::Ptr service = static_cast<Service::Ptr>(row);
378 MacroProcessor::ResolverList resolvers {
379 { "service", service },
380 { "host", service->GetHost() },
381 { "icinga", IcingaApplication::GetInstance() }
384 return MacroProcessor::ResolveMacros(service->GetNotes(), resolvers);
387 Value ServicesTable::NotesUrlAccessor(const Value& row)
389 Service::Ptr service = static_cast<Service::Ptr>(row);
394 return service->GetNotesUrl();
397 Value ServicesTable::NotesUrlExpandedAccessor(const Value& row)
399 Service::Ptr service = static_cast<Service::Ptr>(row);
404 MacroProcessor::ResolverList resolvers {
405 { "service", service },
406 { "host", service->GetHost() },
407 { "icinga", IcingaApplication::GetInstance() }
410 return MacroProcessor::ResolveMacros(service->GetNotesUrl(), resolvers);
413 Value ServicesTable::ActionUrlAccessor(const Value& row)
415 Service::Ptr service = static_cast<Service::Ptr>(row);
420 return service->GetActionUrl();
423 Value ServicesTable::ActionUrlExpandedAccessor(const Value& row)
425 Service::Ptr service = static_cast<Service::Ptr>(row);
430 MacroProcessor::ResolverList resolvers {
431 { "service", service },
432 { "host", service->GetHost() },
433 { "icinga", IcingaApplication::GetInstance() }
436 return MacroProcessor::ResolveMacros(service->GetActionUrl(), resolvers);
439 Value ServicesTable::IconImageAccessor(const Value& row)
441 Service::Ptr service = static_cast<Service::Ptr>(row);
446 return service->GetIconImage();
449 Value ServicesTable::IconImageExpandedAccessor(const Value& row)
451 Service::Ptr service = static_cast<Service::Ptr>(row);
456 MacroProcessor::ResolverList resolvers {
457 { "service", service },
458 { "host", service->GetHost() },
459 { "icinga", IcingaApplication::GetInstance() }
462 return MacroProcessor::ResolveMacros(service->GetIconImage(), resolvers);
465 Value ServicesTable::IconImageAltAccessor(const Value& row)
467 Service::Ptr service = static_cast<Service::Ptr>(row);
472 return service->GetIconImageAlt();
475 Value ServicesTable::MaxCheckAttemptsAccessor(const Value& row)
477 Service::Ptr service = static_cast<Service::Ptr>(row);
482 return service->GetMaxCheckAttempts();
485 Value ServicesTable::CurrentAttemptAccessor(const Value& row)
487 Service::Ptr service = static_cast<Service::Ptr>(row);
492 return service->GetCheckAttempt();
495 Value ServicesTable::StateAccessor(const Value& row)
497 Service::Ptr service = static_cast<Service::Ptr>(row);
502 return service->GetState();
505 Value ServicesTable::HasBeenCheckedAccessor(const Value& row)
507 Service::Ptr service = static_cast<Service::Ptr>(row);
512 return CompatUtility::GetCheckableHasBeenChecked(service);
515 Value ServicesTable::LastStateAccessor(const Value& row)
517 Service::Ptr service = static_cast<Service::Ptr>(row);
522 return service->GetLastState();
525 Value ServicesTable::LastHardStateAccessor(const Value& row)
527 Service::Ptr service = static_cast<Service::Ptr>(row);
532 return service->GetLastHardState();
535 Value ServicesTable::StateTypeAccessor(const Value& row)
537 Service::Ptr service = static_cast<Service::Ptr>(row);
542 return service->GetStateType();
545 Value ServicesTable::CheckTypeAccessor(const Value& row)
547 Service::Ptr service = static_cast<Service::Ptr>(row);
552 return CompatUtility::GetCheckableCheckType(service);
555 Value ServicesTable::AcknowledgedAccessor(const Value& row)
557 Service::Ptr service = static_cast<Service::Ptr>(row);
562 ObjectLock olock(service);
563 return CompatUtility::GetCheckableIsAcknowledged(service);
566 Value ServicesTable::AcknowledgementTypeAccessor(const Value& row)
568 Service::Ptr service = static_cast<Service::Ptr>(row);
573 ObjectLock olock(service);
574 return CompatUtility::GetCheckableAcknowledgementType(service);
577 Value ServicesTable::NoMoreNotificationsAccessor(const Value& row)
579 Service::Ptr service = static_cast<Service::Ptr>(row);
584 return CompatUtility::GetCheckableNoMoreNotifications(service);
587 Value ServicesTable::LastTimeOkAccessor(const Value& row)
589 Service::Ptr service = static_cast<Service::Ptr>(row);
594 return static_cast<int>(service->GetLastStateOK());
597 Value ServicesTable::LastTimeWarningAccessor(const Value& row)
599 Service::Ptr service = static_cast<Service::Ptr>(row);
604 return static_cast<int>(service->GetLastStateWarning());
607 Value ServicesTable::LastTimeCriticalAccessor(const Value& row)
609 Service::Ptr service = static_cast<Service::Ptr>(row);
614 return static_cast<int>(service->GetLastStateCritical());
617 Value ServicesTable::LastTimeUnknownAccessor(const Value& row)
619 Service::Ptr service = static_cast<Service::Ptr>(row);
624 return static_cast<int>(service->GetLastStateUnknown());
627 Value ServicesTable::LastCheckAccessor(const Value& row)
629 Service::Ptr service = static_cast<Service::Ptr>(row);
634 return static_cast<int>(service->GetLastCheck());
637 Value ServicesTable::NextCheckAccessor(const Value& row)
639 Service::Ptr service = static_cast<Service::Ptr>(row);
644 return static_cast<int>(service->GetNextCheck());
647 Value ServicesTable::LastNotificationAccessor(const Value& row)
649 Service::Ptr service = static_cast<Service::Ptr>(row);
654 return CompatUtility::GetCheckableNotificationLastNotification(service);
657 Value ServicesTable::NextNotificationAccessor(const Value& row)
659 Service::Ptr service = static_cast<Service::Ptr>(row);
664 return CompatUtility::GetCheckableNotificationNextNotification(service);
667 Value ServicesTable::CurrentNotificationNumberAccessor(const Value& row)
669 Service::Ptr service = static_cast<Service::Ptr>(row);
674 return CompatUtility::GetCheckableNotificationNotificationNumber(service);
677 Value ServicesTable::LastStateChangeAccessor(const Value& row)
679 Service::Ptr service = static_cast<Service::Ptr>(row);
684 return static_cast<int>(service->GetLastStateChange());
687 Value ServicesTable::LastHardStateChangeAccessor(const Value& row)
689 Service::Ptr service = static_cast<Service::Ptr>(row);
694 return static_cast<int>(service->GetLastHardStateChange());
697 Value ServicesTable::ScheduledDowntimeDepthAccessor(const Value& row)
699 Service::Ptr service = static_cast<Service::Ptr>(row);
704 return service->GetDowntimeDepth();
707 Value ServicesTable::IsFlappingAccessor(const Value& row)
709 Service::Ptr service = static_cast<Service::Ptr>(row);
714 return service->IsFlapping();
717 Value ServicesTable::ChecksEnabledAccessor(const Value& row)
719 Service::Ptr service = static_cast<Service::Ptr>(row);
724 return CompatUtility::GetCheckableActiveChecksEnabled(service);
727 Value ServicesTable::AcceptPassiveChecksAccessor(const Value& row)
729 Service::Ptr service = static_cast<Service::Ptr>(row);
734 return CompatUtility::GetCheckablePassiveChecksEnabled(service);
737 Value ServicesTable::EventHandlerEnabledAccessor(const Value& row)
739 Service::Ptr service = static_cast<Service::Ptr>(row);
744 return CompatUtility::GetCheckableEventHandlerEnabled(service);
747 Value ServicesTable::NotificationsEnabledAccessor(const Value& row)
749 Service::Ptr service = static_cast<Service::Ptr>(row);
754 return CompatUtility::GetCheckableNotificationsEnabled(service);
757 Value ServicesTable::ProcessPerformanceDataAccessor(const Value& row)
759 Service::Ptr service = static_cast<Service::Ptr>(row);
764 return CompatUtility::GetCheckableProcessPerformanceData(service);
767 Value ServicesTable::ActiveChecksEnabledAccessor(const Value& row)
769 Service::Ptr service = static_cast<Service::Ptr>(row);
774 return CompatUtility::GetCheckableActiveChecksEnabled(service);
777 Value ServicesTable::CheckOptionsAccessor(const Value& row)
779 /* TODO - forcexec, freshness, orphan, none */
783 Value ServicesTable::FlapDetectionEnabledAccessor(const Value& row)
785 Service::Ptr service = static_cast<Service::Ptr>(row);
790 return CompatUtility::GetCheckableFlapDetectionEnabled(service);
793 Value ServicesTable::CheckFreshnessAccessor(const Value& row)
795 Service::Ptr service = static_cast<Service::Ptr>(row);
800 return CompatUtility::GetCheckableFreshnessChecksEnabled(service);
803 Value ServicesTable::StalenessAccessor(const Value& row)
805 Service::Ptr service = static_cast<Service::Ptr>(row);
810 return CompatUtility::GetCheckableStaleness(service);
813 Value ServicesTable::CheckIntervalAccessor(const Value& row)
815 Service::Ptr service = static_cast<Service::Ptr>(row);
820 return CompatUtility::GetCheckableCheckInterval(service);
823 Value ServicesTable::RetryIntervalAccessor(const Value& row)
825 Service::Ptr service = static_cast<Service::Ptr>(row);
830 return CompatUtility::GetCheckableRetryInterval(service);
833 Value ServicesTable::NotificationIntervalAccessor(const Value& row)
835 Service::Ptr service = static_cast<Service::Ptr>(row);
840 return CompatUtility::GetCheckableNotificationNotificationInterval(service);
843 Value ServicesTable::LowFlapThresholdAccessor(const Value& row)
845 Service::Ptr service = static_cast<Service::Ptr>(row);
850 return CompatUtility::GetCheckableLowFlapThreshold(service);
853 Value ServicesTable::HighFlapThresholdAccessor(const Value& row)
855 Service::Ptr service = static_cast<Service::Ptr>(row);
860 return CompatUtility::GetCheckableHighFlapThreshold(service);
863 Value ServicesTable::LatencyAccessor(const Value& row)
865 Service::Ptr service = static_cast<Service::Ptr>(row);
870 CheckResult::Ptr cr = service->GetLastCheckResult();
875 return cr->CalculateLatency();
878 Value ServicesTable::ExecutionTimeAccessor(const Value& row)
880 Service::Ptr service = static_cast<Service::Ptr>(row);
885 CheckResult::Ptr cr = service->GetLastCheckResult();
890 return cr->CalculateExecutionTime();
893 Value ServicesTable::PercentStateChangeAccessor(const Value& row)
895 Service::Ptr service = static_cast<Service::Ptr>(row);
900 return CompatUtility::GetCheckablePercentStateChange(service);
903 Value ServicesTable::InCheckPeriodAccessor(const Value& row)
905 Service::Ptr service = static_cast<Service::Ptr>(row);
910 return CompatUtility::GetCheckableInCheckPeriod(service);
913 Value ServicesTable::InNotificationPeriodAccessor(const Value& row)
915 Service::Ptr service = static_cast<Service::Ptr>(row);
920 return CompatUtility::GetCheckableInNotificationPeriod(service);
923 Value ServicesTable::ContactsAccessor(const Value& row)
925 Service::Ptr service = static_cast<Service::Ptr>(row);
930 Array::Ptr contact_names = new Array();
932 for (const User::Ptr& user : CompatUtility::GetCheckableNotificationUsers(service)) {
933 contact_names->Add(user->GetName());
936 return contact_names;
939 Value ServicesTable::DowntimesAccessor(const Value& row)
941 Service::Ptr service = static_cast<Service::Ptr>(row);
946 Array::Ptr results = new Array();
948 for (const Downtime::Ptr& downtime : service->GetDowntimes()) {
949 if (downtime->IsExpired())
952 results->Add(downtime->GetLegacyId());
958 Value ServicesTable::DowntimesWithInfoAccessor(const Value& row)
960 Service::Ptr service = static_cast<Service::Ptr>(row);
965 Array::Ptr results = new Array();
967 for (const Downtime::Ptr& downtime : service->GetDowntimes()) {
968 if (downtime->IsExpired())
971 Array::Ptr downtime_info = new Array();
972 downtime_info->Add(downtime->GetLegacyId());
973 downtime_info->Add(downtime->GetAuthor());
974 downtime_info->Add(downtime->GetComment());
975 results->Add(downtime_info);
981 Value ServicesTable::CommentsAccessor(const Value& row)
983 Service::Ptr service = static_cast<Service::Ptr>(row);
988 Array::Ptr results = new Array();
990 for (const Comment::Ptr& comment : service->GetComments()) {
991 if (comment->IsExpired())
994 results->Add(comment->GetLegacyId());
1000 Value ServicesTable::CommentsWithInfoAccessor(const Value& row)
1002 Service::Ptr service = static_cast<Service::Ptr>(row);
1007 Array::Ptr results = new Array();
1009 for (const Comment::Ptr& comment : service->GetComments()) {
1010 if (comment->IsExpired())
1013 Array::Ptr comment_info = new Array();
1014 comment_info->Add(comment->GetLegacyId());
1015 comment_info->Add(comment->GetAuthor());
1016 comment_info->Add(comment->GetText());
1017 results->Add(comment_info);
1023 Value ServicesTable::CommentsWithExtraInfoAccessor(const Value& row)
1025 Service::Ptr service = static_cast<Service::Ptr>(row);
1030 Array::Ptr results = new Array();
1032 for (const Comment::Ptr& comment : service->GetComments()) {
1033 if (comment->IsExpired())
1036 Array::Ptr comment_info = new Array();
1037 comment_info->Add(comment->GetLegacyId());
1038 comment_info->Add(comment->GetAuthor());
1039 comment_info->Add(comment->GetText());
1040 comment_info->Add(comment->GetEntryType());
1041 comment_info->Add(static_cast<int>(comment->GetEntryTime()));
1042 results->Add(comment_info);
1048 Value ServicesTable::CustomVariableNamesAccessor(const Value& row)
1050 Service::Ptr service = static_cast<Service::Ptr>(row);
1055 Dictionary::Ptr vars;
1058 ObjectLock olock(service);
1059 vars = CompatUtility::GetCustomAttributeConfig(service);
1062 Array::Ptr cv = new Array();
1067 ObjectLock olock(vars);
1068 for (const Dictionary::Pair& kv : vars) {
1075 Value ServicesTable::CustomVariableValuesAccessor(const Value& row)
1077 Service::Ptr service = static_cast<Service::Ptr>(row);
1082 Dictionary::Ptr vars;
1085 ObjectLock olock(service);
1086 vars = CompatUtility::GetCustomAttributeConfig(service);
1089 Array::Ptr cv = new Array();
1094 ObjectLock olock(vars);
1095 for (const Dictionary::Pair& kv : vars) {
1096 if (kv.second.IsObjectType<Array>() || kv.second.IsObjectType<Dictionary>())
1097 cv->Add(JsonEncode(kv.second));
1105 Value ServicesTable::CustomVariablesAccessor(const Value& row)
1107 Service::Ptr service = static_cast<Service::Ptr>(row);
1112 Dictionary::Ptr vars;
1115 ObjectLock olock(service);
1116 vars = CompatUtility::GetCustomAttributeConfig(service);
1119 Array::Ptr cv = new Array();
1124 ObjectLock olock(vars);
1125 for (const Dictionary::Pair& kv : vars) {
1126 Array::Ptr key_val = new Array();
1127 key_val->Add(kv.first);
1129 if (kv.second.IsObjectType<Array>() || kv.second.IsObjectType<Dictionary>())
1130 key_val->Add(JsonEncode(kv.second));
1132 key_val->Add(kv.second);
1140 Value ServicesTable::CVIsJsonAccessor(const Value& row)
1142 Service::Ptr service = static_cast<Service::Ptr>(row);
1147 Dictionary::Ptr vars;
1150 ObjectLock olock(service);
1151 vars = CompatUtility::GetCustomAttributeConfig(service);
1157 bool cv_is_json = false;
1159 ObjectLock olock(vars);
1160 for (const Dictionary::Pair& kv : vars) {
1161 if (kv.second.IsObjectType<Array>() || kv.second.IsObjectType<Dictionary>())
1168 Value ServicesTable::GroupsAccessor(const Value& row)
1170 Service::Ptr service = static_cast<Service::Ptr>(row);
1175 Array::Ptr groups = service->GetGroups();
1183 Value ServicesTable::ContactGroupsAccessor(const Value& row)
1185 Service::Ptr service = static_cast<Service::Ptr>(row);
1190 Array::Ptr contactgroup_names = new Array();
1192 for (const UserGroup::Ptr& usergroup : CompatUtility::GetCheckableNotificationUserGroups(service)) {
1193 contactgroup_names->Add(usergroup->GetName());
1196 return contactgroup_names;
1199 Value ServicesTable::CheckSourceAccessor(const Value& row)
1201 Service::Ptr service = static_cast<Service::Ptr>(row);
1206 CheckResult::Ptr cr = service->GetLastCheckResult();
1209 return cr->GetCheckSource();
1214 Value ServicesTable::IsReachableAccessor(const Value& row)
1216 Service::Ptr service = static_cast<Service::Ptr>(row);
1221 return service->IsReachable();
1224 Value ServicesTable::OriginalAttributesAccessor(const Value& row)
1226 Service::Ptr service = static_cast<Service::Ptr>(row);
1231 return JsonEncode(service->GetOriginalAttributes());