1 /******************************************************************************
3 * Copyright (C) 2012-2018 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(&Table::EmptyStringAccessor, 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() const
162 String ServicesTable::GetPrefix() 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 Convert::ToLong(service->HasBeenChecked());
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 (service->GetEnableActiveChecks() ? 0 : 1); /* 0 .. active, 1 .. passive */
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 service->GetAcknowledgement();
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 Convert::ToLong(service->GetEnableActiveChecks());
727 Value ServicesTable::AcceptPassiveChecksAccessor(const Value& row)
729 Service::Ptr service = static_cast<Service::Ptr>(row);
734 return Convert::ToLong(service->GetEnablePassiveChecks());
737 Value ServicesTable::EventHandlerEnabledAccessor(const Value& row)
739 Service::Ptr service = static_cast<Service::Ptr>(row);
744 return Convert::ToLong(service->GetEnableEventHandler());
747 Value ServicesTable::NotificationsEnabledAccessor(const Value& row)
749 Service::Ptr service = static_cast<Service::Ptr>(row);
754 return Convert::ToLong(service->GetEnableNotifications());
757 Value ServicesTable::ProcessPerformanceDataAccessor(const Value& row)
759 Service::Ptr service = static_cast<Service::Ptr>(row);
764 return Convert::ToLong(service->GetEnablePerfdata());
767 Value ServicesTable::ActiveChecksEnabledAccessor(const Value& row)
769 Service::Ptr service = static_cast<Service::Ptr>(row);
774 return Convert::ToLong(service->GetEnableActiveChecks());
777 Value ServicesTable::FlapDetectionEnabledAccessor(const Value& row)
779 Service::Ptr service = static_cast<Service::Ptr>(row);
784 return Convert::ToLong(service->GetEnableFlapping());
787 Value ServicesTable::CheckFreshnessAccessor(const Value& row)
789 Service::Ptr service = static_cast<Service::Ptr>(row);
794 return CompatUtility::GetCheckableFreshnessChecksEnabled(service);
797 Value ServicesTable::StalenessAccessor(const Value& row)
799 Service::Ptr service = static_cast<Service::Ptr>(row);
804 return CompatUtility::GetCheckableStaleness(service);
807 Value ServicesTable::CheckIntervalAccessor(const Value& row)
809 Service::Ptr service = static_cast<Service::Ptr>(row);
814 return CompatUtility::GetCheckableCheckInterval(service);
817 Value ServicesTable::RetryIntervalAccessor(const Value& row)
819 Service::Ptr service = static_cast<Service::Ptr>(row);
824 return CompatUtility::GetCheckableRetryInterval(service);
827 Value ServicesTable::NotificationIntervalAccessor(const Value& row)
829 Service::Ptr service = static_cast<Service::Ptr>(row);
834 return CompatUtility::GetCheckableNotificationNotificationInterval(service);
837 Value ServicesTable::LowFlapThresholdAccessor(const Value& row)
839 Service::Ptr service = static_cast<Service::Ptr>(row);
844 return CompatUtility::GetCheckableLowFlapThreshold(service);
847 Value ServicesTable::HighFlapThresholdAccessor(const Value& row)
849 Service::Ptr service = static_cast<Service::Ptr>(row);
854 return CompatUtility::GetCheckableHighFlapThreshold(service);
857 Value ServicesTable::LatencyAccessor(const Value& row)
859 Service::Ptr service = static_cast<Service::Ptr>(row);
864 CheckResult::Ptr cr = service->GetLastCheckResult();
869 return cr->CalculateLatency();
872 Value ServicesTable::ExecutionTimeAccessor(const Value& row)
874 Service::Ptr service = static_cast<Service::Ptr>(row);
879 CheckResult::Ptr cr = service->GetLastCheckResult();
884 return cr->CalculateExecutionTime();
887 Value ServicesTable::PercentStateChangeAccessor(const Value& row)
889 Service::Ptr service = static_cast<Service::Ptr>(row);
894 return service->GetFlappingCurrent();
897 Value ServicesTable::InCheckPeriodAccessor(const Value& row)
899 Service::Ptr service = static_cast<Service::Ptr>(row);
904 return CompatUtility::GetCheckableInCheckPeriod(service);
907 Value ServicesTable::InNotificationPeriodAccessor(const Value& row)
909 Service::Ptr service = static_cast<Service::Ptr>(row);
914 return CompatUtility::GetCheckableInNotificationPeriod(service);
917 Value ServicesTable::ContactsAccessor(const Value& row)
919 Service::Ptr service = static_cast<Service::Ptr>(row);
924 Array::Ptr contact_names = new Array();
926 for (const User::Ptr& user : CompatUtility::GetCheckableNotificationUsers(service)) {
927 contact_names->Add(user->GetName());
930 return contact_names;
933 Value ServicesTable::DowntimesAccessor(const Value& row)
935 Service::Ptr service = static_cast<Service::Ptr>(row);
940 Array::Ptr results = new Array();
942 for (const Downtime::Ptr& downtime : service->GetDowntimes()) {
943 if (downtime->IsExpired())
946 results->Add(downtime->GetLegacyId());
952 Value ServicesTable::DowntimesWithInfoAccessor(const Value& row)
954 Service::Ptr service = static_cast<Service::Ptr>(row);
959 Array::Ptr results = new Array();
961 for (const Downtime::Ptr& downtime : service->GetDowntimes()) {
962 if (downtime->IsExpired())
965 Array::Ptr downtime_info = new Array();
966 downtime_info->Add(downtime->GetLegacyId());
967 downtime_info->Add(downtime->GetAuthor());
968 downtime_info->Add(downtime->GetComment());
969 results->Add(downtime_info);
975 Value ServicesTable::CommentsAccessor(const Value& row)
977 Service::Ptr service = static_cast<Service::Ptr>(row);
982 Array::Ptr results = new Array();
984 for (const Comment::Ptr& comment : service->GetComments()) {
985 if (comment->IsExpired())
988 results->Add(comment->GetLegacyId());
994 Value ServicesTable::CommentsWithInfoAccessor(const Value& row)
996 Service::Ptr service = static_cast<Service::Ptr>(row);
1001 Array::Ptr results = new Array();
1003 for (const Comment::Ptr& comment : service->GetComments()) {
1004 if (comment->IsExpired())
1007 Array::Ptr comment_info = new Array();
1008 comment_info->Add(comment->GetLegacyId());
1009 comment_info->Add(comment->GetAuthor());
1010 comment_info->Add(comment->GetText());
1011 results->Add(comment_info);
1017 Value ServicesTable::CommentsWithExtraInfoAccessor(const Value& row)
1019 Service::Ptr service = static_cast<Service::Ptr>(row);
1024 Array::Ptr results = new Array();
1026 for (const Comment::Ptr& comment : service->GetComments()) {
1027 if (comment->IsExpired())
1030 Array::Ptr comment_info = new Array();
1031 comment_info->Add(comment->GetLegacyId());
1032 comment_info->Add(comment->GetAuthor());
1033 comment_info->Add(comment->GetText());
1034 comment_info->Add(comment->GetEntryType());
1035 comment_info->Add(static_cast<int>(comment->GetEntryTime()));
1036 results->Add(comment_info);
1042 Value ServicesTable::CustomVariableNamesAccessor(const Value& row)
1044 Service::Ptr service = static_cast<Service::Ptr>(row);
1049 Dictionary::Ptr vars;
1052 ObjectLock olock(service);
1053 vars = CompatUtility::GetCustomAttributeConfig(service);
1056 Array::Ptr cv = new Array();
1061 ObjectLock olock(vars);
1062 for (const Dictionary::Pair& kv : vars) {
1069 Value ServicesTable::CustomVariableValuesAccessor(const Value& row)
1071 Service::Ptr service = static_cast<Service::Ptr>(row);
1076 Dictionary::Ptr vars;
1079 ObjectLock olock(service);
1080 vars = CompatUtility::GetCustomAttributeConfig(service);
1083 Array::Ptr cv = new Array();
1088 ObjectLock olock(vars);
1089 for (const Dictionary::Pair& kv : vars) {
1090 if (kv.second.IsObjectType<Array>() || kv.second.IsObjectType<Dictionary>())
1091 cv->Add(JsonEncode(kv.second));
1099 Value ServicesTable::CustomVariablesAccessor(const Value& row)
1101 Service::Ptr service = static_cast<Service::Ptr>(row);
1106 Dictionary::Ptr vars;
1109 ObjectLock olock(service);
1110 vars = CompatUtility::GetCustomAttributeConfig(service);
1113 Array::Ptr cv = new Array();
1118 ObjectLock olock(vars);
1119 for (const Dictionary::Pair& kv : vars) {
1120 Array::Ptr key_val = new Array();
1121 key_val->Add(kv.first);
1123 if (kv.second.IsObjectType<Array>() || kv.second.IsObjectType<Dictionary>())
1124 key_val->Add(JsonEncode(kv.second));
1126 key_val->Add(kv.second);
1134 Value ServicesTable::CVIsJsonAccessor(const Value& row)
1136 Service::Ptr service = static_cast<Service::Ptr>(row);
1141 Dictionary::Ptr vars;
1144 ObjectLock olock(service);
1145 vars = CompatUtility::GetCustomAttributeConfig(service);
1151 bool cv_is_json = false;
1153 ObjectLock olock(vars);
1154 for (const Dictionary::Pair& kv : vars) {
1155 if (kv.second.IsObjectType<Array>() || kv.second.IsObjectType<Dictionary>())
1162 Value ServicesTable::GroupsAccessor(const Value& row)
1164 Service::Ptr service = static_cast<Service::Ptr>(row);
1169 Array::Ptr groups = service->GetGroups();
1177 Value ServicesTable::ContactGroupsAccessor(const Value& row)
1179 Service::Ptr service = static_cast<Service::Ptr>(row);
1184 Array::Ptr contactgroup_names = new Array();
1186 for (const UserGroup::Ptr& usergroup : CompatUtility::GetCheckableNotificationUserGroups(service)) {
1187 contactgroup_names->Add(usergroup->GetName());
1190 return contactgroup_names;
1193 Value ServicesTable::CheckSourceAccessor(const Value& row)
1195 Service::Ptr service = static_cast<Service::Ptr>(row);
1200 CheckResult::Ptr cr = service->GetLastCheckResult();
1203 return cr->GetCheckSource();
1208 Value ServicesTable::IsReachableAccessor(const Value& row)
1210 Service::Ptr service = static_cast<Service::Ptr>(row);
1215 return service->IsReachable();
1218 Value ServicesTable::OriginalAttributesAccessor(const Value& row)
1220 Service::Ptr service = static_cast<Service::Ptr>(row);
1225 return JsonEncode(service->GetOriginalAttributes());