1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
3 #include "livestatus/servicestable.hpp"
4 #include "livestatus/hoststable.hpp"
5 #include "livestatus/servicegroupstable.hpp"
6 #include "livestatus/hostgroupstable.hpp"
7 #include "livestatus/endpointstable.hpp"
8 #include "icinga/service.hpp"
9 #include "icinga/servicegroup.hpp"
10 #include "icinga/hostgroup.hpp"
11 #include "icinga/checkcommand.hpp"
12 #include "icinga/eventcommand.hpp"
13 #include "icinga/timeperiod.hpp"
14 #include "icinga/macroprocessor.hpp"
15 #include "icinga/icingaapplication.hpp"
16 #include "icinga/compatutility.hpp"
17 #include "icinga/pluginutility.hpp"
18 #include "base/configtype.hpp"
19 #include "base/objectlock.hpp"
20 #include "base/json.hpp"
21 #include "base/convert.hpp"
22 #include "base/utility.hpp"
23 #include <boost/algorithm/string/replace.hpp>
25 using namespace icinga;
27 ServicesTable::ServicesTable(LivestatusGroupByType type)
34 void ServicesTable::AddColumns(Table *table, const String& prefix,
35 const Column::ObjectAccessor& objectAccessor)
37 table->AddColumn(prefix + "description", Column(&ServicesTable::ShortNameAccessor, objectAccessor));
38 table->AddColumn(prefix + "service_description", Column(&ServicesTable::ShortNameAccessor, objectAccessor)); //ugly compatibility hack
39 table->AddColumn(prefix + "display_name", Column(&ServicesTable::DisplayNameAccessor, objectAccessor));
40 table->AddColumn(prefix + "check_command", Column(&ServicesTable::CheckCommandAccessor, objectAccessor));
41 table->AddColumn(prefix + "check_command_expanded", Column(&ServicesTable::CheckCommandExpandedAccessor, objectAccessor));
42 table->AddColumn(prefix + "event_handler", Column(&ServicesTable::EventHandlerAccessor, objectAccessor));
43 table->AddColumn(prefix + "plugin_output", Column(&ServicesTable::PluginOutputAccessor, objectAccessor));
44 table->AddColumn(prefix + "long_plugin_output", Column(&ServicesTable::LongPluginOutputAccessor, objectAccessor));
45 table->AddColumn(prefix + "perf_data", Column(&ServicesTable::PerfDataAccessor, objectAccessor));
46 table->AddColumn(prefix + "notification_period", Column(&Table::EmptyStringAccessor, objectAccessor));
47 table->AddColumn(prefix + "check_period", Column(&ServicesTable::CheckPeriodAccessor, objectAccessor));
48 table->AddColumn(prefix + "notes", Column(&ServicesTable::NotesAccessor, objectAccessor));
49 table->AddColumn(prefix + "notes_expanded", Column(&ServicesTable::NotesExpandedAccessor, objectAccessor));
50 table->AddColumn(prefix + "notes_url", Column(&ServicesTable::NotesUrlAccessor, objectAccessor));
51 table->AddColumn(prefix + "notes_url_expanded", Column(&ServicesTable::NotesUrlExpandedAccessor, objectAccessor));
52 table->AddColumn(prefix + "action_url", Column(&ServicesTable::ActionUrlAccessor, objectAccessor));
53 table->AddColumn(prefix + "action_url_expanded", Column(&ServicesTable::ActionUrlExpandedAccessor, objectAccessor));
54 table->AddColumn(prefix + "icon_image", Column(&ServicesTable::IconImageAccessor, objectAccessor));
55 table->AddColumn(prefix + "icon_image_expanded", Column(&ServicesTable::IconImageExpandedAccessor, objectAccessor));
56 table->AddColumn(prefix + "icon_image_alt", Column(&ServicesTable::IconImageAltAccessor, objectAccessor));
57 table->AddColumn(prefix + "initial_state", Column(&Table::EmptyStringAccessor, objectAccessor));
58 table->AddColumn(prefix + "max_check_attempts", Column(&ServicesTable::MaxCheckAttemptsAccessor, objectAccessor));
59 table->AddColumn(prefix + "current_attempt", Column(&ServicesTable::CurrentAttemptAccessor, objectAccessor));
60 table->AddColumn(prefix + "state", Column(&ServicesTable::StateAccessor, objectAccessor));
61 table->AddColumn(prefix + "has_been_checked", Column(&ServicesTable::HasBeenCheckedAccessor, objectAccessor));
62 table->AddColumn(prefix + "last_state", Column(&ServicesTable::LastStateAccessor, objectAccessor));
63 table->AddColumn(prefix + "last_hard_state", Column(&ServicesTable::LastHardStateAccessor, objectAccessor));
64 table->AddColumn(prefix + "state_type", Column(&ServicesTable::StateTypeAccessor, objectAccessor));
65 table->AddColumn(prefix + "check_type", Column(&ServicesTable::CheckTypeAccessor, objectAccessor));
66 table->AddColumn(prefix + "acknowledged", Column(&ServicesTable::AcknowledgedAccessor, objectAccessor));
67 table->AddColumn(prefix + "acknowledgement_type", Column(&ServicesTable::AcknowledgementTypeAccessor, objectAccessor));
68 table->AddColumn(prefix + "no_more_notifications", Column(&ServicesTable::NoMoreNotificationsAccessor, objectAccessor));
69 table->AddColumn(prefix + "last_time_ok", Column(&ServicesTable::LastTimeOkAccessor, objectAccessor));
70 table->AddColumn(prefix + "last_time_warning", Column(&ServicesTable::LastTimeWarningAccessor, objectAccessor));
71 table->AddColumn(prefix + "last_time_critical", Column(&ServicesTable::LastTimeCriticalAccessor, objectAccessor));
72 table->AddColumn(prefix + "last_time_unknown", Column(&ServicesTable::LastTimeUnknownAccessor, objectAccessor));
73 table->AddColumn(prefix + "last_check", Column(&ServicesTable::LastCheckAccessor, objectAccessor));
74 table->AddColumn(prefix + "next_check", Column(&ServicesTable::NextCheckAccessor, objectAccessor));
75 table->AddColumn(prefix + "last_notification", Column(&ServicesTable::LastNotificationAccessor, objectAccessor));
76 table->AddColumn(prefix + "next_notification", Column(&ServicesTable::NextNotificationAccessor, objectAccessor));
77 table->AddColumn(prefix + "current_notification_number", Column(&ServicesTable::CurrentNotificationNumberAccessor, objectAccessor));
78 table->AddColumn(prefix + "last_state_change", Column(&ServicesTable::LastStateChangeAccessor, objectAccessor));
79 table->AddColumn(prefix + "last_hard_state_change", Column(&ServicesTable::LastHardStateChangeAccessor, objectAccessor));
80 table->AddColumn(prefix + "scheduled_downtime_depth", Column(&ServicesTable::ScheduledDowntimeDepthAccessor, objectAccessor));
81 table->AddColumn(prefix + "is_flapping", Column(&ServicesTable::IsFlappingAccessor, objectAccessor));
82 table->AddColumn(prefix + "checks_enabled", Column(&ServicesTable::ChecksEnabledAccessor, objectAccessor));
83 table->AddColumn(prefix + "accept_passive_checks", Column(&ServicesTable::AcceptPassiveChecksAccessor, objectAccessor));
84 table->AddColumn(prefix + "event_handler_enabled", Column(&ServicesTable::EventHandlerEnabledAccessor, objectAccessor));
85 table->AddColumn(prefix + "notifications_enabled", Column(&ServicesTable::NotificationsEnabledAccessor, objectAccessor));
86 table->AddColumn(prefix + "process_performance_data", Column(&ServicesTable::ProcessPerformanceDataAccessor, objectAccessor));
87 table->AddColumn(prefix + "is_executing", Column(&Table::ZeroAccessor, objectAccessor));
88 table->AddColumn(prefix + "active_checks_enabled", Column(&ServicesTable::ActiveChecksEnabledAccessor, objectAccessor));
89 table->AddColumn(prefix + "check_options", Column(&Table::EmptyStringAccessor, objectAccessor));
90 table->AddColumn(prefix + "flap_detection_enabled", Column(&ServicesTable::FlapDetectionEnabledAccessor, objectAccessor));
91 table->AddColumn(prefix + "check_freshness", Column(&Table::OneAccessor, objectAccessor));
92 table->AddColumn(prefix + "obsess_over_service", Column(&Table::ZeroAccessor, objectAccessor));
93 table->AddColumn(prefix + "modified_attributes", Column(&Table::ZeroAccessor, objectAccessor));
94 table->AddColumn(prefix + "modified_attributes_list", Column(&Table::ZeroAccessor, objectAccessor));
95 table->AddColumn(prefix + "pnpgraph_present", Column(&Table::ZeroAccessor, objectAccessor));
96 table->AddColumn(prefix + "staleness", Column(&ServicesTable::StalenessAccessor, objectAccessor));
97 table->AddColumn(prefix + "check_interval", Column(&ServicesTable::CheckIntervalAccessor, objectAccessor));
98 table->AddColumn(prefix + "retry_interval", Column(&ServicesTable::RetryIntervalAccessor, objectAccessor));
99 table->AddColumn(prefix + "notification_interval", Column(&ServicesTable::NotificationIntervalAccessor, objectAccessor));
100 table->AddColumn(prefix + "first_notification_delay", Column(&Table::EmptyStringAccessor, objectAccessor));
101 table->AddColumn(prefix + "low_flap_threshold", Column(&ServicesTable::LowFlapThresholdAccessor, objectAccessor));
102 table->AddColumn(prefix + "high_flap_threshold", Column(&ServicesTable::HighFlapThresholdAccessor, objectAccessor));
103 table->AddColumn(prefix + "latency", Column(&ServicesTable::LatencyAccessor, objectAccessor));
104 table->AddColumn(prefix + "execution_time", Column(&ServicesTable::ExecutionTimeAccessor, objectAccessor));
105 table->AddColumn(prefix + "percent_state_change", Column(&ServicesTable::PercentStateChangeAccessor, objectAccessor));
106 table->AddColumn(prefix + "in_check_period", Column(&ServicesTable::InCheckPeriodAccessor, objectAccessor));
107 table->AddColumn(prefix + "in_notification_period", Column(&ServicesTable::InNotificationPeriodAccessor, objectAccessor));
108 table->AddColumn(prefix + "contacts", Column(&ServicesTable::ContactsAccessor, objectAccessor));
109 table->AddColumn(prefix + "downtimes", Column(&ServicesTable::DowntimesAccessor, objectAccessor));
110 table->AddColumn(prefix + "downtimes_with_info", Column(&ServicesTable::DowntimesWithInfoAccessor, objectAccessor));
111 table->AddColumn(prefix + "comments", Column(&ServicesTable::CommentsAccessor, objectAccessor));
112 table->AddColumn(prefix + "comments_with_info", Column(&ServicesTable::CommentsWithInfoAccessor, objectAccessor));
113 table->AddColumn(prefix + "comments_with_extra_info", Column(&ServicesTable::CommentsWithExtraInfoAccessor, objectAccessor));
114 table->AddColumn(prefix + "custom_variable_names", Column(&ServicesTable::CustomVariableNamesAccessor, objectAccessor));
115 table->AddColumn(prefix + "custom_variable_values", Column(&ServicesTable::CustomVariableValuesAccessor, objectAccessor));
116 table->AddColumn(prefix + "custom_variables", Column(&ServicesTable::CustomVariablesAccessor, objectAccessor));
117 table->AddColumn(prefix + "groups", Column(&ServicesTable::GroupsAccessor, objectAccessor));
118 table->AddColumn(prefix + "contact_groups", Column(&ServicesTable::ContactGroupsAccessor, objectAccessor));
119 table->AddColumn(prefix + "check_source", Column(&ServicesTable::CheckSourceAccessor, objectAccessor));
120 table->AddColumn(prefix + "is_reachable", Column(&ServicesTable::IsReachableAccessor, objectAccessor));
121 table->AddColumn(prefix + "cv_is_json", Column(&ServicesTable::CVIsJsonAccessor, objectAccessor));
122 table->AddColumn(prefix + "original_attributes", Column(&ServicesTable::OriginalAttributesAccessor, objectAccessor));
124 HostsTable::AddColumns(table, "host_", std::bind(&ServicesTable::HostAccessor, _1, objectAccessor));
126 /* add additional group by values received through the object accessor */
127 if (table->GetGroupByType() == LivestatusGroupByServiceGroup) {
128 /* _1 = row, _2 = groupByType, _3 = groupByObject */
129 Log(LogDebug, "Livestatus")
130 << "Processing services group by servicegroup table.";
131 ServiceGroupsTable::AddColumns(table, "servicegroup_", std::bind(&ServicesTable::ServiceGroupAccessor, _1, _2, _3));
132 } else if (table->GetGroupByType() == LivestatusGroupByHostGroup) {
133 /* _1 = row, _2 = groupByType, _3 = groupByObject */
134 Log(LogDebug, "Livestatus")
135 << "Processing services group by hostgroup table.";
136 HostGroupsTable::AddColumns(table, "hostgroup_", std::bind(&ServicesTable::HostGroupAccessor, _1, _2, _3));
140 String ServicesTable::GetName() const
145 String ServicesTable::GetPrefix() const
150 void ServicesTable::FetchRows(const AddRowFunction& addRowFn)
152 if (GetGroupByType() == LivestatusGroupByServiceGroup) {
153 for (const ServiceGroup::Ptr& sg : ConfigType::GetObjectsByType<ServiceGroup>()) {
154 for (const Service::Ptr& service : sg->GetMembers()) {
155 /* the caller must know which groupby type and value are set for this row */
156 if (!addRowFn(service, LivestatusGroupByServiceGroup, sg))
160 } else if (GetGroupByType() == LivestatusGroupByHostGroup) {
161 for (const HostGroup::Ptr& hg : ConfigType::GetObjectsByType<HostGroup>()) {
162 ObjectLock ylock(hg);
163 for (const Host::Ptr& host : hg->GetMembers()) {
164 ObjectLock ylock(host);
165 for (const Service::Ptr& service : host->GetServices()) {
166 /* the caller must know which groupby type and value are set for this row */
167 if (!addRowFn(service, LivestatusGroupByHostGroup, hg))
173 for (const Service::Ptr& service : ConfigType::GetObjectsByType<Service>()) {
174 if (!addRowFn(service, LivestatusGroupByNone, Empty))
180 Object::Ptr ServicesTable::HostAccessor(const Value& row, const Column::ObjectAccessor& parentObjectAccessor)
184 if (parentObjectAccessor)
185 service = parentObjectAccessor(row, LivestatusGroupByNone, Empty);
189 Service::Ptr svc = static_cast<Service::Ptr>(service);
194 return svc->GetHost();
197 Object::Ptr ServicesTable::ServiceGroupAccessor(const Value& row, LivestatusGroupByType groupByType, const Object::Ptr& groupByObject)
199 /* return the current group by value set from within FetchRows()
200 * this is the servicegroup object used for the table join inside
203 if (groupByType == LivestatusGroupByServiceGroup)
204 return groupByObject;
209 Object::Ptr ServicesTable::HostGroupAccessor(const Value& row, LivestatusGroupByType groupByType, const Object::Ptr& groupByObject)
211 /* return the current group by value set from within FetchRows()
212 * this is the servicegroup object used for the table join inside
215 if (groupByType == LivestatusGroupByHostGroup)
216 return groupByObject;
221 Value ServicesTable::ShortNameAccessor(const Value& row)
223 Service::Ptr service = static_cast<Service::Ptr>(row);
228 return service->GetShortName();
231 Value ServicesTable::DisplayNameAccessor(const Value& row)
233 Service::Ptr service = static_cast<Service::Ptr>(row);
238 return service->GetDisplayName();
241 Value ServicesTable::CheckCommandAccessor(const Value& row)
243 Service::Ptr service = static_cast<Service::Ptr>(row);
248 CheckCommand::Ptr checkcommand = service->GetCheckCommand();
251 return CompatUtility::GetCommandName(checkcommand) + "!" + CompatUtility::GetCheckableCommandArgs(service);
256 Value ServicesTable::CheckCommandExpandedAccessor(const Value& row)
258 Service::Ptr service = static_cast<Service::Ptr>(row);
263 CheckCommand::Ptr checkcommand = service->GetCheckCommand();
266 return CompatUtility::GetCommandName(checkcommand) + "!" + CompatUtility::GetCheckableCommandArgs(service);
271 Value ServicesTable::EventHandlerAccessor(const Value& row)
273 Service::Ptr service = static_cast<Service::Ptr>(row);
278 EventCommand::Ptr eventcommand = service->GetEventCommand();
281 return CompatUtility::GetCommandName(eventcommand);
286 Value ServicesTable::PluginOutputAccessor(const Value& row)
288 Service::Ptr service = static_cast<Service::Ptr>(row);
294 CheckResult::Ptr cr = service->GetLastCheckResult();
297 output = CompatUtility::GetCheckResultOutput(cr);
302 Value ServicesTable::LongPluginOutputAccessor(const Value& row)
304 Service::Ptr service = static_cast<Service::Ptr>(row);
310 CheckResult::Ptr cr = service->GetLastCheckResult();
313 long_output = CompatUtility::GetCheckResultLongOutput(cr);
318 Value ServicesTable::PerfDataAccessor(const Value& row)
320 Service::Ptr service = static_cast<Service::Ptr>(row);
326 CheckResult::Ptr cr = service->GetLastCheckResult();
331 return PluginUtility::FormatPerfdata(cr->GetPerformanceData());
334 Value ServicesTable::CheckPeriodAccessor(const Value& row)
336 Service::Ptr service = static_cast<Service::Ptr>(row);
341 TimePeriod::Ptr checkPeriod = service->GetCheckPeriod();
346 return checkPeriod->GetName();
349 Value ServicesTable::NotesAccessor(const Value& row)
351 Service::Ptr service = static_cast<Service::Ptr>(row);
356 return service->GetNotes();
359 Value ServicesTable::NotesExpandedAccessor(const Value& row)
361 Service::Ptr service = static_cast<Service::Ptr>(row);
366 MacroProcessor::ResolverList resolvers {
367 { "service", service },
368 { "host", service->GetHost() },
369 { "icinga", IcingaApplication::GetInstance() }
372 return MacroProcessor::ResolveMacros(service->GetNotes(), resolvers);
375 Value ServicesTable::NotesUrlAccessor(const Value& row)
377 Service::Ptr service = static_cast<Service::Ptr>(row);
382 return service->GetNotesUrl();
385 Value ServicesTable::NotesUrlExpandedAccessor(const Value& row)
387 Service::Ptr service = static_cast<Service::Ptr>(row);
392 MacroProcessor::ResolverList resolvers {
393 { "service", service },
394 { "host", service->GetHost() },
395 { "icinga", IcingaApplication::GetInstance() }
398 return MacroProcessor::ResolveMacros(service->GetNotesUrl(), resolvers);
401 Value ServicesTable::ActionUrlAccessor(const Value& row)
403 Service::Ptr service = static_cast<Service::Ptr>(row);
408 return service->GetActionUrl();
411 Value ServicesTable::ActionUrlExpandedAccessor(const Value& row)
413 Service::Ptr service = static_cast<Service::Ptr>(row);
418 MacroProcessor::ResolverList resolvers {
419 { "service", service },
420 { "host", service->GetHost() },
421 { "icinga", IcingaApplication::GetInstance() }
424 return MacroProcessor::ResolveMacros(service->GetActionUrl(), resolvers);
427 Value ServicesTable::IconImageAccessor(const Value& row)
429 Service::Ptr service = static_cast<Service::Ptr>(row);
434 return service->GetIconImage();
437 Value ServicesTable::IconImageExpandedAccessor(const Value& row)
439 Service::Ptr service = static_cast<Service::Ptr>(row);
444 MacroProcessor::ResolverList resolvers {
445 { "service", service },
446 { "host", service->GetHost() },
447 { "icinga", IcingaApplication::GetInstance() }
450 return MacroProcessor::ResolveMacros(service->GetIconImage(), resolvers);
453 Value ServicesTable::IconImageAltAccessor(const Value& row)
455 Service::Ptr service = static_cast<Service::Ptr>(row);
460 return service->GetIconImageAlt();
463 Value ServicesTable::MaxCheckAttemptsAccessor(const Value& row)
465 Service::Ptr service = static_cast<Service::Ptr>(row);
470 return service->GetMaxCheckAttempts();
473 Value ServicesTable::CurrentAttemptAccessor(const Value& row)
475 Service::Ptr service = static_cast<Service::Ptr>(row);
480 return service->GetCheckAttempt();
483 Value ServicesTable::StateAccessor(const Value& row)
485 Service::Ptr service = static_cast<Service::Ptr>(row);
490 return service->GetState();
493 Value ServicesTable::HasBeenCheckedAccessor(const Value& row)
495 Service::Ptr service = static_cast<Service::Ptr>(row);
500 return Convert::ToLong(service->HasBeenChecked());
503 Value ServicesTable::LastStateAccessor(const Value& row)
505 Service::Ptr service = static_cast<Service::Ptr>(row);
510 return service->GetLastState();
513 Value ServicesTable::LastHardStateAccessor(const Value& row)
515 Service::Ptr service = static_cast<Service::Ptr>(row);
520 return service->GetLastHardState();
523 Value ServicesTable::StateTypeAccessor(const Value& row)
525 Service::Ptr service = static_cast<Service::Ptr>(row);
530 return service->GetStateType();
533 Value ServicesTable::CheckTypeAccessor(const Value& row)
535 Service::Ptr service = static_cast<Service::Ptr>(row);
540 return (service->GetEnableActiveChecks() ? 0 : 1); /* 0 .. active, 1 .. passive */
543 Value ServicesTable::AcknowledgedAccessor(const Value& row)
545 Service::Ptr service = static_cast<Service::Ptr>(row);
550 ObjectLock olock(service);
551 return service->IsAcknowledged();
554 Value ServicesTable::AcknowledgementTypeAccessor(const Value& row)
556 Service::Ptr service = static_cast<Service::Ptr>(row);
561 ObjectLock olock(service);
562 return service->GetAcknowledgement();
565 Value ServicesTable::NoMoreNotificationsAccessor(const Value& row)
567 Service::Ptr service = static_cast<Service::Ptr>(row);
572 return (CompatUtility::GetCheckableNotificationNotificationInterval(service) == 0 && !service->GetVolatile()) ? 1 : 0;
575 Value ServicesTable::LastTimeOkAccessor(const Value& row)
577 Service::Ptr service = static_cast<Service::Ptr>(row);
582 return static_cast<int>(service->GetLastStateOK());
585 Value ServicesTable::LastTimeWarningAccessor(const Value& row)
587 Service::Ptr service = static_cast<Service::Ptr>(row);
592 return static_cast<int>(service->GetLastStateWarning());
595 Value ServicesTable::LastTimeCriticalAccessor(const Value& row)
597 Service::Ptr service = static_cast<Service::Ptr>(row);
602 return static_cast<int>(service->GetLastStateCritical());
605 Value ServicesTable::LastTimeUnknownAccessor(const Value& row)
607 Service::Ptr service = static_cast<Service::Ptr>(row);
612 return static_cast<int>(service->GetLastStateUnknown());
615 Value ServicesTable::LastCheckAccessor(const Value& row)
617 Service::Ptr service = static_cast<Service::Ptr>(row);
622 return static_cast<int>(service->GetLastCheck());
625 Value ServicesTable::NextCheckAccessor(const Value& row)
627 Service::Ptr service = static_cast<Service::Ptr>(row);
632 return static_cast<int>(service->GetNextCheck());
635 Value ServicesTable::LastNotificationAccessor(const Value& row)
637 Service::Ptr service = static_cast<Service::Ptr>(row);
642 return CompatUtility::GetCheckableNotificationLastNotification(service);
645 Value ServicesTable::NextNotificationAccessor(const Value& row)
647 Service::Ptr service = static_cast<Service::Ptr>(row);
652 return CompatUtility::GetCheckableNotificationNextNotification(service);
655 Value ServicesTable::CurrentNotificationNumberAccessor(const Value& row)
657 Service::Ptr service = static_cast<Service::Ptr>(row);
662 return CompatUtility::GetCheckableNotificationNotificationNumber(service);
665 Value ServicesTable::LastStateChangeAccessor(const Value& row)
667 Service::Ptr service = static_cast<Service::Ptr>(row);
672 return static_cast<int>(service->GetLastStateChange());
675 Value ServicesTable::LastHardStateChangeAccessor(const Value& row)
677 Service::Ptr service = static_cast<Service::Ptr>(row);
682 return static_cast<int>(service->GetLastHardStateChange());
685 Value ServicesTable::ScheduledDowntimeDepthAccessor(const Value& row)
687 Service::Ptr service = static_cast<Service::Ptr>(row);
692 return service->GetDowntimeDepth();
695 Value ServicesTable::IsFlappingAccessor(const Value& row)
697 Service::Ptr service = static_cast<Service::Ptr>(row);
702 return service->IsFlapping();
705 Value ServicesTable::ChecksEnabledAccessor(const Value& row)
707 Service::Ptr service = static_cast<Service::Ptr>(row);
712 return Convert::ToLong(service->GetEnableActiveChecks());
715 Value ServicesTable::AcceptPassiveChecksAccessor(const Value& row)
717 Service::Ptr service = static_cast<Service::Ptr>(row);
722 return Convert::ToLong(service->GetEnablePassiveChecks());
725 Value ServicesTable::EventHandlerEnabledAccessor(const Value& row)
727 Service::Ptr service = static_cast<Service::Ptr>(row);
732 return Convert::ToLong(service->GetEnableEventHandler());
735 Value ServicesTable::NotificationsEnabledAccessor(const Value& row)
737 Service::Ptr service = static_cast<Service::Ptr>(row);
742 return Convert::ToLong(service->GetEnableNotifications());
745 Value ServicesTable::ProcessPerformanceDataAccessor(const Value& row)
747 Service::Ptr service = static_cast<Service::Ptr>(row);
752 return Convert::ToLong(service->GetEnablePerfdata());
755 Value ServicesTable::ActiveChecksEnabledAccessor(const Value& row)
757 Service::Ptr service = static_cast<Service::Ptr>(row);
762 return Convert::ToLong(service->GetEnableActiveChecks());
765 Value ServicesTable::FlapDetectionEnabledAccessor(const Value& row)
767 Service::Ptr service = static_cast<Service::Ptr>(row);
772 return Convert::ToLong(service->GetEnableFlapping());
775 Value ServicesTable::StalenessAccessor(const Value& row)
777 Service::Ptr service = static_cast<Service::Ptr>(row);
782 if (service->HasBeenChecked() && service->GetLastCheck() > 0)
783 return (Utility::GetTime() - service->GetLastCheck()) / (service->GetCheckInterval() * 3600);
788 Value ServicesTable::CheckIntervalAccessor(const Value& row)
790 Service::Ptr service = static_cast<Service::Ptr>(row);
795 return service->GetCheckInterval() / LIVESTATUS_INTERVAL_LENGTH;
798 Value ServicesTable::RetryIntervalAccessor(const Value& row)
800 Service::Ptr service = static_cast<Service::Ptr>(row);
805 return service->GetRetryInterval() / LIVESTATUS_INTERVAL_LENGTH;
808 Value ServicesTable::NotificationIntervalAccessor(const Value& row)
810 Service::Ptr service = static_cast<Service::Ptr>(row);
815 return CompatUtility::GetCheckableNotificationNotificationInterval(service);
818 Value ServicesTable::LowFlapThresholdAccessor(const Value& row)
820 Service::Ptr service = static_cast<Service::Ptr>(row);
825 return service->GetFlappingThresholdLow();
828 Value ServicesTable::HighFlapThresholdAccessor(const Value& row)
830 Service::Ptr service = static_cast<Service::Ptr>(row);
835 return service->GetFlappingThresholdHigh();
838 Value ServicesTable::LatencyAccessor(const Value& row)
840 Service::Ptr service = static_cast<Service::Ptr>(row);
845 CheckResult::Ptr cr = service->GetLastCheckResult();
850 return cr->CalculateLatency();
853 Value ServicesTable::ExecutionTimeAccessor(const Value& row)
855 Service::Ptr service = static_cast<Service::Ptr>(row);
860 CheckResult::Ptr cr = service->GetLastCheckResult();
865 return cr->CalculateExecutionTime();
868 Value ServicesTable::PercentStateChangeAccessor(const Value& row)
870 Service::Ptr service = static_cast<Service::Ptr>(row);
875 return service->GetFlappingCurrent();
878 Value ServicesTable::InCheckPeriodAccessor(const Value& row)
880 Service::Ptr service = static_cast<Service::Ptr>(row);
885 TimePeriod::Ptr timeperiod = service->GetCheckPeriod();
887 /* none set means always checked */
891 return Convert::ToLong(timeperiod->IsInside(Utility::GetTime()));
894 Value ServicesTable::InNotificationPeriodAccessor(const Value& row)
896 Service::Ptr service = static_cast<Service::Ptr>(row);
901 for (const Notification::Ptr& notification : service->GetNotifications()) {
902 TimePeriod::Ptr timeperiod = notification->GetPeriod();
904 if (!timeperiod || timeperiod->IsInside(Utility::GetTime()))
911 Value ServicesTable::ContactsAccessor(const Value& row)
913 Service::Ptr service = static_cast<Service::Ptr>(row);
920 for (const User::Ptr& user : CompatUtility::GetCheckableNotificationUsers(service)) {
921 result.push_back(user->GetName());
924 return new Array(std::move(result));
927 Value ServicesTable::DowntimesAccessor(const Value& row)
929 Service::Ptr service = static_cast<Service::Ptr>(row);
936 for (const Downtime::Ptr& downtime : service->GetDowntimes()) {
937 if (downtime->IsExpired())
940 result.push_back(downtime->GetLegacyId());
943 return new Array(std::move(result));
946 Value ServicesTable::DowntimesWithInfoAccessor(const Value& row)
948 Service::Ptr service = static_cast<Service::Ptr>(row);
955 for (const Downtime::Ptr& downtime : service->GetDowntimes()) {
956 if (downtime->IsExpired())
959 result.push_back(new Array({
960 downtime->GetLegacyId(),
961 downtime->GetAuthor(),
962 downtime->GetComment()
966 return new Array(std::move(result));
969 Value ServicesTable::CommentsAccessor(const Value& row)
971 Service::Ptr service = static_cast<Service::Ptr>(row);
978 for (const Comment::Ptr& comment : service->GetComments()) {
979 if (comment->IsExpired())
982 result.push_back(comment->GetLegacyId());
985 return new Array(std::move(result));
988 Value ServicesTable::CommentsWithInfoAccessor(const Value& row)
990 Service::Ptr service = static_cast<Service::Ptr>(row);
997 for (const Comment::Ptr& comment : service->GetComments()) {
998 if (comment->IsExpired())
1001 result.push_back(new Array({
1002 comment->GetLegacyId(),
1003 comment->GetAuthor(),
1008 return new Array(std::move(result));
1011 Value ServicesTable::CommentsWithExtraInfoAccessor(const Value& row)
1013 Service::Ptr service = static_cast<Service::Ptr>(row);
1020 for (const Comment::Ptr& comment : service->GetComments()) {
1021 if (comment->IsExpired())
1024 result.push_back(new Array({
1025 comment->GetLegacyId(),
1026 comment->GetAuthor(),
1028 comment->GetEntryType(),
1029 static_cast<int>(comment->GetEntryTime())
1033 return new Array(std::move(result));
1036 Value ServicesTable::CustomVariableNamesAccessor(const Value& row)
1038 Service::Ptr service = static_cast<Service::Ptr>(row);
1043 Dictionary::Ptr vars = service->GetVars();
1048 ObjectLock olock(vars);
1049 for (const Dictionary::Pair& kv : vars) {
1050 result.push_back(kv.first);
1054 return new Array(std::move(result));
1057 Value ServicesTable::CustomVariableValuesAccessor(const Value& row)
1059 Service::Ptr service = static_cast<Service::Ptr>(row);
1064 Dictionary::Ptr vars = service->GetVars();
1069 ObjectLock olock(vars);
1070 for (const Dictionary::Pair& kv : vars) {
1071 if (kv.second.IsObjectType<Array>() || kv.second.IsObjectType<Dictionary>())
1072 result.push_back(JsonEncode(kv.second));
1074 result.push_back(kv.second);
1078 return new Array(std::move(result));
1081 Value ServicesTable::CustomVariablesAccessor(const Value& row)
1083 Service::Ptr service = static_cast<Service::Ptr>(row);
1088 Dictionary::Ptr vars = service->GetVars();
1093 ObjectLock olock(vars);
1094 for (const Dictionary::Pair& kv : vars) {
1097 if (kv.second.IsObjectType<Array>() || kv.second.IsObjectType<Dictionary>())
1098 val = JsonEncode(kv.second);
1102 result.push_back(new Array({
1109 return new Array(std::move(result));
1112 Value ServicesTable::CVIsJsonAccessor(const Value& row)
1114 Service::Ptr service = static_cast<Service::Ptr>(row);
1119 Dictionary::Ptr vars = service->GetVars();
1124 bool cv_is_json = false;
1126 ObjectLock olock(vars);
1127 for (const Dictionary::Pair& kv : vars) {
1128 if (kv.second.IsObjectType<Array>() || kv.second.IsObjectType<Dictionary>())
1135 Value ServicesTable::GroupsAccessor(const Value& row)
1137 Service::Ptr service = static_cast<Service::Ptr>(row);
1142 Array::Ptr groups = service->GetGroups();
1150 Value ServicesTable::ContactGroupsAccessor(const Value& row)
1152 Service::Ptr service = static_cast<Service::Ptr>(row);
1159 for (const UserGroup::Ptr& usergroup : CompatUtility::GetCheckableNotificationUserGroups(service)) {
1160 result.push_back(usergroup->GetName());
1163 return new Array(std::move(result));
1166 Value ServicesTable::CheckSourceAccessor(const Value& row)
1168 Service::Ptr service = static_cast<Service::Ptr>(row);
1173 CheckResult::Ptr cr = service->GetLastCheckResult();
1176 return cr->GetCheckSource();
1181 Value ServicesTable::IsReachableAccessor(const Value& row)
1183 Service::Ptr service = static_cast<Service::Ptr>(row);
1188 return service->IsReachable();
1191 Value ServicesTable::OriginalAttributesAccessor(const Value& row)
1193 Service::Ptr service = static_cast<Service::Ptr>(row);
1198 return JsonEncode(service->GetOriginalAttributes());