1 /******************************************************************************
3 * Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
5 * This program is free software; you can redistribute it and/or *
6 * modify it under the terms of the GNU General Public License *
7 * as published by the Free Software Foundation; either version 2 *
8 * of the License, or (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software Foundation *
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ******************************************************************************/
20 #include "livestatus/servicestable.h"
21 #include "livestatus/hoststable.h"
22 #include "icinga/service.h"
23 #include "icinga/checkcommand.h"
24 #include "icinga/eventcommand.h"
25 #include "icinga/timeperiod.h"
26 #include "icinga/macroprocessor.h"
27 #include "icinga/icingaapplication.h"
28 #include "base/dynamictype.h"
29 #include "base/objectlock.h"
30 #include "base/convert.h"
31 #include <boost/foreach.hpp>
32 #include <boost/tuple/tuple.hpp>
34 using namespace icinga;
35 using namespace livestatus;
37 ServicesTable::ServicesTable(void)
42 void ServicesTable::AddColumns(Table *table, const String& prefix,
43 const Column::ObjectAccessor& objectAccessor)
45 table->AddColumn(prefix + "description", Column(&ServicesTable::ShortNameAccessor, objectAccessor));
46 table->AddColumn(prefix + "display_name", Column(&ServicesTable::DisplayNameAccessor, objectAccessor));
47 table->AddColumn(prefix + "check_command", Column(&ServicesTable::CheckCommandAccessor, objectAccessor));
48 table->AddColumn(prefix + "check_command_expanded", Column(&ServicesTable::CheckCommandExpandedAccessor, objectAccessor));
49 table->AddColumn(prefix + "event_handler", Column(&ServicesTable::EventHandlerAccessor, objectAccessor));
50 table->AddColumn(prefix + "plugin_output", Column(&ServicesTable::PluginOutputAccessor, objectAccessor));
51 table->AddColumn(prefix + "long_plugin_output", Column(&ServicesTable::LongPluginOutputAccessor, objectAccessor));
52 table->AddColumn(prefix + "perf_data", Column(&ServicesTable::PerfDataAccessor, objectAccessor));
53 table->AddColumn(prefix + "notification_period", Column(&ServicesTable::NotificationPeriodAccessor, objectAccessor));
54 table->AddColumn(prefix + "check_period", Column(&ServicesTable::CheckPeriodAccessor, objectAccessor));
55 table->AddColumn(prefix + "notes", Column(&ServicesTable::NotesAccessor, objectAccessor));
56 table->AddColumn(prefix + "notes_expanded", Column(&ServicesTable::NotesExpandedAccessor, objectAccessor));
57 table->AddColumn(prefix + "notes_url", Column(&ServicesTable::NotesUrlAccessor, objectAccessor));
58 table->AddColumn(prefix + "notes_url_expanded", Column(&ServicesTable::NotesUrlExpandedAccessor, objectAccessor));
59 table->AddColumn(prefix + "action_url", Column(&ServicesTable::ActionUrlAccessor, objectAccessor));
60 table->AddColumn(prefix + "action_url_expanded", Column(&ServicesTable::ActionUrlExpandedAccessor, objectAccessor));
61 table->AddColumn(prefix + "icon_image", Column(&ServicesTable::IconImageAccessor, objectAccessor));
62 table->AddColumn(prefix + "icon_image_expanded", Column(&ServicesTable::IconImageExpandedAccessor, objectAccessor));
63 table->AddColumn(prefix + "icon_image_alt", Column(&ServicesTable::IconImageAltAccessor, objectAccessor));
64 table->AddColumn(prefix + "initial_state", Column(&ServicesTable::InitialStateAccessor, objectAccessor));
65 table->AddColumn(prefix + "max_check_attempts", Column(&ServicesTable::MaxCheckAttemptsAccessor, objectAccessor));
66 table->AddColumn(prefix + "current_attempt", Column(&ServicesTable::CurrentAttemptAccessor, objectAccessor));
67 table->AddColumn(prefix + "state", Column(&ServicesTable::StateAccessor, objectAccessor));
68 table->AddColumn(prefix + "has_been_checked", Column(&ServicesTable::HasBeenCheckedAccessor, objectAccessor));
69 table->AddColumn(prefix + "last_state", Column(&ServicesTable::LastStateAccessor, objectAccessor));
70 table->AddColumn(prefix + "last_hard_state", Column(&ServicesTable::LastHardStateAccessor, objectAccessor));
71 table->AddColumn(prefix + "state_type", Column(&ServicesTable::StateTypeAccessor, objectAccessor));
72 table->AddColumn(prefix + "check_type", Column(&ServicesTable::CheckTypeAccessor, objectAccessor));
73 table->AddColumn(prefix + "acknowledged", Column(&ServicesTable::AcknowledgedAccessor, objectAccessor));
74 table->AddColumn(prefix + "acknowledgement_type", Column(&ServicesTable::AcknowledgementTypeAccessor, objectAccessor));
75 table->AddColumn(prefix + "no_more_notifications", Column(&ServicesTable::NoMoreNotificationsAccessor, objectAccessor));
76 table->AddColumn(prefix + "last_time_ok", Column(&ServicesTable::LastTimeOkAccessor, objectAccessor));
77 table->AddColumn(prefix + "last_time_warning", Column(&ServicesTable::LastTimeWarningAccessor, objectAccessor));
78 table->AddColumn(prefix + "last_time_critical", Column(&ServicesTable::LastTimeCriticalAccessor, objectAccessor));
79 table->AddColumn(prefix + "last_time_unknown", Column(&ServicesTable::LastTimeUnknownAccessor, objectAccessor));
80 table->AddColumn(prefix + "last_check", Column(&ServicesTable::LastCheckAccessor, objectAccessor));
81 table->AddColumn(prefix + "next_check", Column(&ServicesTable::NextCheckAccessor, objectAccessor));
82 table->AddColumn(prefix + "last_notification", Column(&ServicesTable::LastNotificationAccessor, objectAccessor));
83 table->AddColumn(prefix + "next_notification", Column(&ServicesTable::NextNotificationAccessor, objectAccessor));
84 table->AddColumn(prefix + "current_notification_number", Column(&ServicesTable::CurrentNotificationNumberAccessor, objectAccessor));
85 table->AddColumn(prefix + "last_state_change", Column(&ServicesTable::LastStateChangeAccessor, objectAccessor));
86 table->AddColumn(prefix + "last_hard_state_change", Column(&ServicesTable::LastHardStateChangeAccessor, objectAccessor));
87 table->AddColumn(prefix + "scheduled_downtime_depth", Column(&ServicesTable::ScheduledDowntimeDepthAccessor, objectAccessor));
88 table->AddColumn(prefix + "is_flapping", Column(&ServicesTable::IsFlappingAccessor, objectAccessor));
89 table->AddColumn(prefix + "checks_enabled", Column(&ServicesTable::ChecksEnabledAccessor, objectAccessor));
90 table->AddColumn(prefix + "accept_passive_checks", Column(&ServicesTable::AcceptPassiveChecksAccessor, objectAccessor));
91 table->AddColumn(prefix + "event_handler_enabled", Column(&ServicesTable::EventHandlerEnabledAccessor, objectAccessor));
92 table->AddColumn(prefix + "notifications_enabled", Column(&ServicesTable::NotificationsEnabledAccessor, objectAccessor));
93 table->AddColumn(prefix + "process_performance_data", Column(&ServicesTable::ProcessPerformanceDataAccessor, objectAccessor));
94 table->AddColumn(prefix + "is_executing", Column(&ServicesTable::IsExecutingAccessor, objectAccessor));
95 table->AddColumn(prefix + "active_checks_enabled", Column(&ServicesTable::ActiveChecksEnabledAccessor, objectAccessor));
96 table->AddColumn(prefix + "check_options", Column(&ServicesTable::CheckOptionsAccessor, objectAccessor));
97 table->AddColumn(prefix + "flap_detection_enabled", Column(&ServicesTable::FlapDetectionEnabledAccessor, objectAccessor));
98 table->AddColumn(prefix + "check_freshness", Column(&ServicesTable::CheckFreshnessAccessor, objectAccessor));
99 table->AddColumn(prefix + "obsess_over_service", Column(&ServicesTable::ObsessOverServiceAccessor, objectAccessor));
100 table->AddColumn(prefix + "modified_attributes", Column(&ServicesTable::ModifiedAttributesAccessor, objectAccessor));
101 table->AddColumn(prefix + "modified_attributes_list", Column(&ServicesTable::ModifiedAttributesListAccessor, objectAccessor));
102 table->AddColumn(prefix + "pnpgraph_present", Column(&ServicesTable::PnpgraphPresentAccessor, objectAccessor));
103 table->AddColumn(prefix + "check_interval", Column(&ServicesTable::CheckIntervalAccessor, objectAccessor));
104 table->AddColumn(prefix + "retry_interval", Column(&ServicesTable::RetryIntervalAccessor, objectAccessor));
105 table->AddColumn(prefix + "notification_interval", Column(&ServicesTable::NotificationIntervalAccessor, objectAccessor));
106 table->AddColumn(prefix + "first_notification_delay", Column(&ServicesTable::FirstNotificationDelayAccessor, objectAccessor));
107 table->AddColumn(prefix + "low_flap_threshold", Column(&ServicesTable::LowFlapThresholdAccessor, objectAccessor));
108 table->AddColumn(prefix + "high_flap_threshold", Column(&ServicesTable::HighFlapThresholdAccessor, objectAccessor));
109 table->AddColumn(prefix + "latency", Column(&ServicesTable::LatencyAccessor, objectAccessor));
110 table->AddColumn(prefix + "execution_time", Column(&ServicesTable::ExecutionTimeAccessor, objectAccessor));
111 table->AddColumn(prefix + "percent_state_change", Column(&ServicesTable::PercentStateChangeAccessor, objectAccessor));
112 table->AddColumn(prefix + "in_check_period", Column(&ServicesTable::InCheckPeriodAccessor, objectAccessor));
113 table->AddColumn(prefix + "in_notification_period", Column(&ServicesTable::InNotificationPeriodAccessor, objectAccessor));
114 table->AddColumn(prefix + "contacts", Column(&ServicesTable::ContactsAccessor, objectAccessor));
115 table->AddColumn(prefix + "downtimes", Column(&ServicesTable::DowntimesAccessor, objectAccessor));
116 table->AddColumn(prefix + "downtimes_with_info", Column(&ServicesTable::DowntimesWithInfoAccessor, objectAccessor));
117 table->AddColumn(prefix + "comments", Column(&ServicesTable::CommentsAccessor, objectAccessor));
118 table->AddColumn(prefix + "comments_with_info", Column(&ServicesTable::CommentsWithInfoAccessor, objectAccessor));
119 table->AddColumn(prefix + "comments_with_extra_info", Column(&ServicesTable::CommentsWithExtraInfoAccessor, objectAccessor));
120 table->AddColumn(prefix + "custom_variable_names", Column(&ServicesTable::CustomVariableNamesAccessor, objectAccessor));
121 table->AddColumn(prefix + "custom_variable_values", Column(&ServicesTable::CustomVariableValuesAccessor, objectAccessor));
122 table->AddColumn(prefix + "custom_variables", Column(&ServicesTable::CustomVariablesAccessor, objectAccessor));
123 table->AddColumn(prefix + "groups", Column(&ServicesTable::GroupsAccessor, objectAccessor));
124 table->AddColumn(prefix + "contact_groups", Column(&ServicesTable::ContactGroupsAccessor, objectAccessor));
126 HostsTable::AddColumns(table, "host_", boost::bind(&ServicesTable::HostAccessor, _1, objectAccessor));
129 String ServicesTable::GetName(void) const
134 void ServicesTable::FetchRows(const AddRowFunction& addRowFn)
136 BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Service")) {
141 Object::Ptr ServicesTable::HostAccessor(const Value& row, const Column::ObjectAccessor& parentObjectAccessor)
145 if (parentObjectAccessor)
146 service = parentObjectAccessor(row);
150 return static_cast<Service::Ptr>(service)->GetHost();
153 Value ServicesTable::ShortNameAccessor(const Value& row)
155 return static_cast<Service::Ptr>(row)->GetShortName();
158 Value ServicesTable::DisplayNameAccessor(const Value& row)
160 return static_cast<Service::Ptr>(row)->GetDisplayName();
163 Value ServicesTable::CheckCommandAccessor(const Value& row)
165 CheckCommand::Ptr checkcommand = static_cast<Service::Ptr>(row)->GetCheckCommand();
168 return checkcommand->GetName(); /* this is the name without '!' args */
173 Value ServicesTable::CheckCommandExpandedAccessor(const Value& row)
175 Service::Ptr service = static_cast<Service::Ptr>(row);
177 CheckCommand::Ptr commandObj = service->GetCheckCommand();
182 Value raw_command = commandObj->GetCommandLine();
184 std::vector<MacroResolver::Ptr> resolvers;
185 resolvers.push_back(commandObj);
186 resolvers.push_back(service);
187 resolvers.push_back(service->GetHost());
188 resolvers.push_back(IcingaApplication::GetInstance());
190 Value commandLine = MacroProcessor::ResolveMacros(raw_command, resolvers, Dictionary::Ptr(), Utility::EscapeShellCmd);
193 if (commandLine.IsObjectType<Array>()) {
194 Array::Ptr args = commandLine;
196 ObjectLock olock(args);
198 BOOST_FOREACH(arg, args) {
199 // This is obviously incorrect for non-trivial cases.
200 String argitem = " \"" + arg + "\"";
201 boost::algorithm::replace_all(argitem, "\n", "\\n");
204 } else if (!commandLine.IsEmpty()) {
205 String args = Convert::ToString(commandLine);
206 boost::algorithm::replace_all(args, "\n", "\\n");
215 Value ServicesTable::EventHandlerAccessor(const Value& row)
217 EventCommand::Ptr eventcommand = static_cast<Service::Ptr>(row)->GetEventCommand();
220 return eventcommand->GetName();
225 Value ServicesTable::PluginOutputAccessor(const Value& row)
227 return static_cast<Service::Ptr>(row)->GetLastCheckOutput();
230 Value ServicesTable::LongPluginOutputAccessor(const Value& row)
232 return static_cast<Service::Ptr>(row)->GetLastCheckLongOutput();
235 Value ServicesTable::PerfDataAccessor(const Value& row)
237 return static_cast<Service::Ptr>(row)->GetLastCheckPerfData();
240 Value ServicesTable::NotificationPeriodAccessor(const Value& row)
242 BOOST_FOREACH(const Notification::Ptr& notification, static_cast<Service::Ptr>(row)->GetNotifications()) {
243 ObjectLock olock(notification);
245 TimePeriod::Ptr timeperiod = notification->GetNotificationPeriod();
247 /* XXX first notification wins */
249 return timeperiod->GetName();
255 Value ServicesTable::CheckPeriodAccessor(const Value& row)
257 TimePeriod::Ptr timeperiod = static_cast<Service::Ptr>(row)->GetCheckPeriod();
262 return timeperiod->GetName();
265 Value ServicesTable::NotesAccessor(const Value& row)
267 Dictionary::Ptr custom = static_cast<Service::Ptr>(row)->GetCustom();
272 return custom->Get("notes");
275 Value ServicesTable::NotesExpandedAccessor(const Value& row)
277 Service::Ptr service = static_cast<Service::Ptr>(row);
278 Dictionary::Ptr custom = service->GetCustom();
283 std::vector<MacroResolver::Ptr> resolvers;
284 resolvers.push_back(service);
285 resolvers.push_back(service->GetHost());
286 resolvers.push_back(IcingaApplication::GetInstance());
288 Value value = custom->Get("notes");
291 Value value_expanded = MacroProcessor::ResolveMacros(value, resolvers, cr, Utility::EscapeShellCmd);
293 return value_expanded;
296 Value ServicesTable::NotesUrlAccessor(const Value& row)
298 Dictionary::Ptr custom = static_cast<Service::Ptr>(row)->GetCustom();
303 return custom->Get("notes_url");
306 Value ServicesTable::NotesUrlExpandedAccessor(const Value& row)
308 Service::Ptr service = static_cast<Service::Ptr>(row);
309 Dictionary::Ptr custom = service->GetCustom();
314 std::vector<MacroResolver::Ptr> resolvers;
315 resolvers.push_back(service);
316 resolvers.push_back(service->GetHost());
317 resolvers.push_back(IcingaApplication::GetInstance());
319 Value value = custom->Get("notes_url");
322 Value value_expanded = MacroProcessor::ResolveMacros(value, resolvers, cr, Utility::EscapeShellCmd);
324 return value_expanded;
327 Value ServicesTable::ActionUrlAccessor(const Value& row)
329 Dictionary::Ptr custom = static_cast<Service::Ptr>(row)->GetCustom();
334 return custom->Get("action_url");
337 Value ServicesTable::ActionUrlExpandedAccessor(const Value& row)
339 Service::Ptr service = static_cast<Service::Ptr>(row);
340 Dictionary::Ptr custom = service->GetCustom();
345 std::vector<MacroResolver::Ptr> resolvers;
346 resolvers.push_back(service);
347 resolvers.push_back(service->GetHost());
348 resolvers.push_back(IcingaApplication::GetInstance());
350 Value value = custom->Get("action_url");
353 Value value_expanded = MacroProcessor::ResolveMacros(value, resolvers, cr, Utility::EscapeShellCmd);
355 return value_expanded;
358 Value ServicesTable::IconImageAccessor(const Value& row)
360 Dictionary::Ptr custom = static_cast<Service::Ptr>(row)->GetCustom();
365 return custom->Get("icon_image");
368 Value ServicesTable::IconImageExpandedAccessor(const Value& row)
370 Service::Ptr service = static_cast<Service::Ptr>(row);
371 Dictionary::Ptr custom = service->GetCustom();
376 std::vector<MacroResolver::Ptr> resolvers;
377 resolvers.push_back(service);
378 resolvers.push_back(service->GetHost());
379 resolvers.push_back(IcingaApplication::GetInstance());
381 Value value = custom->Get("icon_image");
384 Value value_expanded = MacroProcessor::ResolveMacros(value, resolvers, cr, Utility::EscapeShellCmd);
386 return value_expanded;
389 Value ServicesTable::IconImageAltAccessor(const Value& row)
391 Dictionary::Ptr custom = static_cast<Service::Ptr>(row)->GetCustom();
396 return custom->Get("icon_image_alt");
399 Value ServicesTable::InitialStateAccessor(const Value& row)
405 Value ServicesTable::MaxCheckAttemptsAccessor(const Value& row)
407 return static_cast<Service::Ptr>(row)->GetMaxCheckAttempts();
410 Value ServicesTable::CurrentAttemptAccessor(const Value& row)
412 return static_cast<Service::Ptr>(row)->GetCurrentCheckAttempt();
415 Value ServicesTable::StateAccessor(const Value& row)
417 return static_cast<Service::Ptr>(row)->GetState();
420 Value ServicesTable::HasBeenCheckedAccessor(const Value& row)
422 return (static_cast<Service::Ptr>(row)->HasBeenChecked() ? 1 : 0);
425 Value ServicesTable::LastStateAccessor(const Value& row)
427 return static_cast<Service::Ptr>(row)->GetLastState();
430 Value ServicesTable::LastHardStateAccessor(const Value& row)
432 return static_cast<Service::Ptr>(row)->GetLastHardState();
435 Value ServicesTable::StateTypeAccessor(const Value& row)
437 return static_cast<Service::Ptr>(row)->GetStateType();
440 Value ServicesTable::CheckTypeAccessor(const Value& row)
442 return (static_cast<Service::Ptr>(row)->GetEnableActiveChecks() ? 0 : 1);
445 Value ServicesTable::AcknowledgedAccessor(const Value& row)
447 Service::Ptr service = static_cast<Service::Ptr>(row);
449 /* important: lock acknowledgements */
450 ObjectLock olock(service);
452 return (service->IsAcknowledged() ? 1 : 0);
455 Value ServicesTable::AcknowledgementTypeAccessor(const Value& row)
457 Service::Ptr service = static_cast<Service::Ptr>(row);
459 /* important: lock acknowledgements */
460 ObjectLock olock(service);
462 return static_cast<int>(service->GetAcknowledgement());
465 Value ServicesTable::NoMoreNotificationsAccessor(const Value& row)
467 Service::Ptr service = static_cast<Service::Ptr>(row);
469 /* XXX take the smallest notification_interval */
470 double notification_interval = -1;
471 BOOST_FOREACH(const Notification::Ptr& notification, service->GetNotifications()) {
472 if (notification_interval == -1 || notification->GetNotificationInterval() < notification_interval)
473 notification_interval = notification->GetNotificationInterval();
476 if (notification_interval == 0 && !service->IsVolatile())
482 Value ServicesTable::LastTimeOkAccessor(const Value& row)
484 return static_cast<int>(static_cast<Service::Ptr>(row)->GetLastStateOK());
487 Value ServicesTable::LastTimeWarningAccessor(const Value& row)
489 return static_cast<int>(static_cast<Service::Ptr>(row)->GetLastStateWarning());
492 Value ServicesTable::LastTimeCriticalAccessor(const Value& row)
494 return static_cast<int>(static_cast<Service::Ptr>(row)->GetLastStateCritical());
497 Value ServicesTable::LastTimeUnknownAccessor(const Value& row)
499 return static_cast<int>(static_cast<Service::Ptr>(row)->GetLastStateUnknown());
502 Value ServicesTable::LastCheckAccessor(const Value& row)
504 return static_cast<int>(static_cast<Service::Ptr>(row)->GetLastCheck());
507 Value ServicesTable::NextCheckAccessor(const Value& row)
509 return static_cast<int>(static_cast<Service::Ptr>(row)->GetNextCheck());
512 Value ServicesTable::LastNotificationAccessor(const Value& row)
514 Service::Ptr service = static_cast<Service::Ptr>(row);
516 /* XXX Service -> Notifications, latest wins */
517 double last_notification = 0;
518 BOOST_FOREACH(const Notification::Ptr& notification, service->GetNotifications()) {
519 if (notification->GetLastNotification() > last_notification)
520 last_notification = notification->GetLastNotification();
523 return static_cast<int>(last_notification);
526 Value ServicesTable::NextNotificationAccessor(const Value& row)
528 Service::Ptr service = static_cast<Service::Ptr>(row);
530 /* XXX Service -> Notifications, latest wins */
531 double next_notification = 0;
532 BOOST_FOREACH(const Notification::Ptr& notification, service->GetNotifications()) {
533 if (notification->GetNextNotification() < next_notification)
534 next_notification = notification->GetNextNotification();
537 return static_cast<int>(next_notification);
540 Value ServicesTable::CurrentNotificationNumberAccessor(const Value& row)
542 Service::Ptr service = static_cast<Service::Ptr>(row);
544 /* XXX Service -> Notifications, biggest wins */
545 int notification_number = 0;
546 BOOST_FOREACH(const Notification::Ptr& notification, service->GetNotifications()) {
547 if (notification->GetNotificationNumber() > notification_number)
548 notification_number = notification->GetNotificationNumber();
551 return notification_number;
554 Value ServicesTable::LastStateChangeAccessor(const Value& row)
556 return static_cast<int>(static_cast<Service::Ptr>(row)->GetLastStateChange());
559 Value ServicesTable::LastHardStateChangeAccessor(const Value& row)
561 return static_cast<int>(static_cast<Service::Ptr>(row)->GetLastHardStateChange());
564 Value ServicesTable::ScheduledDowntimeDepthAccessor(const Value& row)
566 return static_cast<Service::Ptr>(row)->GetDowntimeDepth();
569 Value ServicesTable::IsFlappingAccessor(const Value& row)
571 return static_cast<Service::Ptr>(row)->IsFlapping();
574 Value ServicesTable::ChecksEnabledAccessor(const Value& row)
576 return (static_cast<Service::Ptr>(row)->GetEnableActiveChecks() ? 1 : 0);
579 Value ServicesTable::AcceptPassiveChecksAccessor(const Value& row)
581 return (static_cast<Service::Ptr>(row)->GetEnablePassiveChecks() ? 1 : 0);
584 Value ServicesTable::EventHandlerEnabledAccessor(const Value& row)
586 /* TODO always enabled*/
590 Value ServicesTable::NotificationsEnabledAccessor(const Value& row)
592 return (static_cast<Service::Ptr>(row)->GetEnableNotifications() ? 1 : 0);
595 Value ServicesTable::ProcessPerformanceDataAccessor(const Value& row)
597 /* TODO always enabled */
601 Value ServicesTable::IsExecutingAccessor(const Value& row)
603 /* TODO does that make sense with Icinga2? */
607 Value ServicesTable::ActiveChecksEnabledAccessor(const Value& row)
609 return (static_cast<Service::Ptr>(row)->GetEnableActiveChecks() ? 1 : 0);
612 Value ServicesTable::CheckOptionsAccessor(const Value& row)
614 /* TODO - forcexec, freshness, orphan, none */
618 Value ServicesTable::FlapDetectionEnabledAccessor(const Value& row)
620 return (static_cast<Service::Ptr>(row)->GetEnableFlapping() ? 1 : 0);
623 Value ServicesTable::CheckFreshnessAccessor(const Value& row)
629 Value ServicesTable::ObsessOverServiceAccessor(const Value& row)
635 Value ServicesTable::ModifiedAttributesAccessor(const Value& row)
641 Value ServicesTable::ModifiedAttributesListAccessor(const Value& row)
647 Value ServicesTable::PnpgraphPresentAccessor(const Value& row)
653 Value ServicesTable::CheckIntervalAccessor(const Value& row)
655 return (static_cast<Service::Ptr>(row)->GetCheckInterval() / 60.0);
658 Value ServicesTable::RetryIntervalAccessor(const Value& row)
660 return (static_cast<Service::Ptr>(row)->GetRetryInterval() / 60.0);
663 Value ServicesTable::NotificationIntervalAccessor(const Value& row)
665 Service::Ptr service = static_cast<Service::Ptr>(row);
667 /* XXX take the smallest notification_interval */
668 double notification_interval = -1;
669 BOOST_FOREACH(const Notification::Ptr& notification, service->GetNotifications()) {
670 if (notification_interval == -1 || notification->GetNotificationInterval() < notification_interval)
671 notification_interval = notification->GetNotificationInterval();
674 if (notification_interval == -1)
675 notification_interval = 60;
677 return (notification_interval / 60.0);
680 Value ServicesTable::FirstNotificationDelayAccessor(const Value& row)
686 Value ServicesTable::LowFlapThresholdAccessor(const Value& row)
692 Value ServicesTable::HighFlapThresholdAccessor(const Value& row)
698 Value ServicesTable::LatencyAccessor(const Value& row)
700 return (Service::CalculateLatency(static_cast<Service::Ptr>(row)->GetLastCheckResult()));
703 Value ServicesTable::ExecutionTimeAccessor(const Value& row)
705 return (Service::CalculateExecutionTime(static_cast<Service::Ptr>(row)->GetLastCheckResult()));
708 Value ServicesTable::PercentStateChangeAccessor(const Value& row)
710 return static_cast<Service::Ptr>(row)->GetFlappingCurrent();
713 Value ServicesTable::InCheckPeriodAccessor(const Value& row)
715 TimePeriod::Ptr timeperiod = static_cast<Service::Ptr>(row)->GetCheckPeriod();
720 return (timeperiod->IsInside(Utility::GetTime()) ? 1 : 0);
723 Value ServicesTable::InNotificationPeriodAccessor(const Value& row)
725 BOOST_FOREACH(const Notification::Ptr& notification, static_cast<Service::Ptr>(row)->GetNotifications()) {
726 ObjectLock olock(notification);
728 TimePeriod::Ptr timeperiod = notification->GetNotificationPeriod();
730 /* XXX first notification wins */
732 return (timeperiod->IsInside(Utility::GetTime()) ? 1 : 0);
738 Value ServicesTable::ContactsAccessor(const Value& row)
740 /* XXX Service -> Notifications -> (Users + UserGroups -> Users) */
741 std::set<User::Ptr> allUsers;
742 std::set<User::Ptr> users;
743 Array::Ptr contacts = boost::make_shared<Array>();
745 BOOST_FOREACH(const Notification::Ptr& notification, static_cast<Service::Ptr>(row)->GetNotifications()) {
746 ObjectLock olock(notification);
748 users = notification->GetUsers();
750 std::copy(users.begin(), users.end(), std::inserter(allUsers, allUsers.begin()));
752 BOOST_FOREACH(const UserGroup::Ptr& ug, notification->GetGroups()) {
753 std::set<User::Ptr> members = ug->GetMembers();
754 std::copy(members.begin(), members.end(), std::inserter(allUsers, allUsers.begin()));
758 BOOST_FOREACH(const User::Ptr& user, allUsers) {
759 contacts->Add(user->GetName());
765 Value ServicesTable::DowntimesAccessor(const Value& row)
767 Dictionary::Ptr downtimes = static_cast<Service::Ptr>(row)->GetDowntimes();
772 Array::Ptr ids = boost::make_shared<Array>();
774 ObjectLock olock(downtimes);
777 Dictionary::Ptr downtime;
778 BOOST_FOREACH(boost::tie(id, downtime), downtimes) {
783 if (Service::IsDowntimeExpired(downtime))
786 ids->Add(downtime->Get("legacy_id"));
792 Value ServicesTable::DowntimesWithInfoAccessor(const Value& row)
794 Dictionary::Ptr downtimes = static_cast<Service::Ptr>(row)->GetDowntimes();
799 Array::Ptr ids = boost::make_shared<Array>();
801 ObjectLock olock(downtimes);
804 Dictionary::Ptr downtime;
805 BOOST_FOREACH(boost::tie(id, downtime), downtimes) {
810 if (Service::IsDowntimeExpired(downtime))
813 Array::Ptr downtime_info = boost::make_shared<Array>();
814 downtime_info->Add(downtime->Get("legacy_id"));
815 downtime_info->Add(downtime->Get("author"));
816 downtime_info->Add(downtime->Get("comment"));
817 ids->Add(downtime_info);
823 Value ServicesTable::CommentsAccessor(const Value& row)
825 Dictionary::Ptr comments = static_cast<Service::Ptr>(row)->GetComments();
830 Array::Ptr ids = boost::make_shared<Array>();
832 ObjectLock olock(comments);
835 Dictionary::Ptr comment;
836 BOOST_FOREACH(boost::tie(id, comment), comments) {
841 if (Service::IsCommentExpired(comment))
844 ids->Add(comment->Get("legacy_id"));
850 Value ServicesTable::CommentsWithInfoAccessor(const Value& row)
852 Dictionary::Ptr comments = static_cast<Service::Ptr>(row)->GetComments();
857 Array::Ptr ids = boost::make_shared<Array>();
859 ObjectLock olock(comments);
862 Dictionary::Ptr comment;
863 BOOST_FOREACH(boost::tie(id, comment), comments) {
868 if (Service::IsCommentExpired(comment))
871 Array::Ptr comment_info = boost::make_shared<Array>();
872 comment_info->Add(comment->Get("legacy_id"));
873 comment_info->Add(comment->Get("author"));
874 comment_info->Add(comment->Get("text"));
875 ids->Add(comment_info);
881 Value ServicesTable::CommentsWithExtraInfoAccessor(const Value& row)
883 Dictionary::Ptr comments = static_cast<Service::Ptr>(row)->GetComments();
888 Array::Ptr ids = boost::make_shared<Array>();
890 ObjectLock olock(comments);
893 Dictionary::Ptr comment;
894 BOOST_FOREACH(boost::tie(id, comment), comments) {
899 if (Service::IsCommentExpired(comment))
902 Array::Ptr comment_info = boost::make_shared<Array>();
903 comment_info->Add(comment->Get("legacy_id"));
904 comment_info->Add(comment->Get("author"));
905 comment_info->Add(comment->Get("text"));
906 comment_info->Add(comment->Get("entry_type"));
907 comment_info->Add(static_cast<int>(comment->Get("entry_time")));
908 ids->Add(comment_info);
914 Value ServicesTable::CustomVariableNamesAccessor(const Value& row)
916 Dictionary::Ptr custom = static_cast<Service::Ptr>(row)->GetCustom();
921 Array::Ptr cv = boost::make_shared<Array>();
923 ObjectLock olock(custom);
926 BOOST_FOREACH(boost::tie(key, value), custom) {
927 if (key == "notes" ||
928 key == "action_url" ||
929 key == "notes_url" ||
930 key == "icon_image" ||
931 key == "icon_image_alt" ||
932 key == "statusmap_image" ||
942 Value ServicesTable::CustomVariableValuesAccessor(const Value& row)
944 Dictionary::Ptr custom = static_cast<Service::Ptr>(row)->GetCustom();
949 Array::Ptr cv = boost::make_shared<Array>();
951 ObjectLock olock(custom);
954 BOOST_FOREACH(boost::tie(key, value), custom) {
955 if (key == "notes" ||
956 key == "action_url" ||
957 key == "notes_url" ||
958 key == "icon_image" ||
959 key == "icon_image_alt" ||
960 key == "statusmap_image" ||
970 Value ServicesTable::CustomVariablesAccessor(const Value& row)
972 Dictionary::Ptr custom = static_cast<Service::Ptr>(row)->GetCustom();
977 Array::Ptr cv = boost::make_shared<Array>();
979 ObjectLock olock(custom);
982 BOOST_FOREACH(boost::tie(key, value), custom) {
983 if (key == "notes" ||
984 key == "action_url" ||
985 key == "notes_url" ||
986 key == "icon_image" ||
987 key == "icon_image_alt" ||
988 key == "statusmap_image" ||
992 Array::Ptr key_val = boost::make_shared<Array>();
1001 Value ServicesTable::GroupsAccessor(const Value& row)
1003 Array::Ptr groups = static_cast<Service::Ptr>(row)->GetGroups();
1011 Value ServicesTable::ContactGroupsAccessor(const Value& row)
1013 /* XXX Service -> Notifications -> UserGroups */
1014 Array::Ptr contactgroups = boost::make_shared<Array>();
1016 BOOST_FOREACH(const Notification::Ptr& notification, static_cast<Service::Ptr>(row)->GetNotifications()) {
1017 ObjectLock olock(notification);
1019 BOOST_FOREACH(const UserGroup::Ptr& ug, notification->GetGroups()) {
1020 contactgroups->Add(ug->GetName());
1024 return contactgroups;