2013-03-10 22:20:13 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* Icinga 2 *
|
2013-09-25 07:43:57 +02:00
|
|
|
* Copyright (C) 2012-2013 Icinga Development Team (http://www.icinga.org/) *
|
2013-03-10 22:20:13 +01:00
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU General Public License *
|
|
|
|
* as published by the Free Software Foundation; either version 2 *
|
|
|
|
* of the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the Free Software Foundation *
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
|
|
|
******************************************************************************/
|
|
|
|
|
2013-03-17 20:19:29 +01:00
|
|
|
#include "livestatus/servicestable.h"
|
|
|
|
#include "livestatus/hoststable.h"
|
|
|
|
#include "icinga/service.h"
|
2013-07-08 17:09:15 +02:00
|
|
|
#include "icinga/checkcommand.h"
|
|
|
|
#include "icinga/eventcommand.h"
|
|
|
|
#include "icinga/timeperiod.h"
|
2013-07-16 17:58:23 +02:00
|
|
|
#include "icinga/macroprocessor.h"
|
|
|
|
#include "icinga/icingaapplication.h"
|
2013-10-01 15:37:50 +02:00
|
|
|
#include "icinga/compatutility.h"
|
2013-03-16 21:18:53 +01:00
|
|
|
#include "base/dynamictype.h"
|
2013-07-08 17:09:15 +02:00
|
|
|
#include "base/objectlock.h"
|
2013-07-16 17:58:23 +02:00
|
|
|
#include "base/convert.h"
|
2013-07-22 14:55:35 +02:00
|
|
|
#include "base/utility.h"
|
2013-03-16 21:18:53 +01:00
|
|
|
#include <boost/foreach.hpp>
|
2013-07-16 17:58:23 +02:00
|
|
|
#include <boost/tuple/tuple.hpp>
|
2013-07-30 22:38:33 +02:00
|
|
|
#include <boost/algorithm/string/replace.hpp>
|
2013-03-10 22:20:13 +01:00
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
using namespace livestatus;
|
|
|
|
|
|
|
|
ServicesTable::ServicesTable(void)
|
|
|
|
{
|
|
|
|
AddColumns(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ServicesTable::AddColumns(Table *table, const String& prefix,
|
|
|
|
const Column::ObjectAccessor& objectAccessor)
|
|
|
|
{
|
|
|
|
table->AddColumn(prefix + "description", Column(&ServicesTable::ShortNameAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "display_name", Column(&ServicesTable::DisplayNameAccessor, objectAccessor));
|
2013-07-08 17:09:15 +02:00
|
|
|
table->AddColumn(prefix + "check_command", Column(&ServicesTable::CheckCommandAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "check_command_expanded", Column(&ServicesTable::CheckCommandExpandedAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "event_handler", Column(&ServicesTable::EventHandlerAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "plugin_output", Column(&ServicesTable::PluginOutputAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "long_plugin_output", Column(&ServicesTable::LongPluginOutputAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "perf_data", Column(&ServicesTable::PerfDataAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "notification_period", Column(&ServicesTable::NotificationPeriodAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "check_period", Column(&ServicesTable::CheckPeriodAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "notes", Column(&ServicesTable::NotesAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "notes_expanded", Column(&ServicesTable::NotesExpandedAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "notes_url", Column(&ServicesTable::NotesUrlAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "notes_url_expanded", Column(&ServicesTable::NotesUrlExpandedAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "action_url", Column(&ServicesTable::ActionUrlAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "action_url_expanded", Column(&ServicesTable::ActionUrlExpandedAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "icon_image", Column(&ServicesTable::IconImageAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "icon_image_expanded", Column(&ServicesTable::IconImageExpandedAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "icon_image_alt", Column(&ServicesTable::IconImageAltAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "initial_state", Column(&ServicesTable::InitialStateAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "max_check_attempts", Column(&ServicesTable::MaxCheckAttemptsAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "current_attempt", Column(&ServicesTable::CurrentAttemptAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "state", Column(&ServicesTable::StateAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "has_been_checked", Column(&ServicesTable::HasBeenCheckedAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "last_state", Column(&ServicesTable::LastStateAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "last_hard_state", Column(&ServicesTable::LastHardStateAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "state_type", Column(&ServicesTable::StateTypeAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "check_type", Column(&ServicesTable::CheckTypeAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "acknowledged", Column(&ServicesTable::AcknowledgedAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "acknowledgement_type", Column(&ServicesTable::AcknowledgementTypeAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "no_more_notifications", Column(&ServicesTable::NoMoreNotificationsAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "last_time_ok", Column(&ServicesTable::LastTimeOkAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "last_time_warning", Column(&ServicesTable::LastTimeWarningAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "last_time_critical", Column(&ServicesTable::LastTimeCriticalAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "last_time_unknown", Column(&ServicesTable::LastTimeUnknownAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "last_check", Column(&ServicesTable::LastCheckAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "next_check", Column(&ServicesTable::NextCheckAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "last_notification", Column(&ServicesTable::LastNotificationAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "next_notification", Column(&ServicesTable::NextNotificationAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "current_notification_number", Column(&ServicesTable::CurrentNotificationNumberAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "last_state_change", Column(&ServicesTable::LastStateChangeAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "last_hard_state_change", Column(&ServicesTable::LastHardStateChangeAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "scheduled_downtime_depth", Column(&ServicesTable::ScheduledDowntimeDepthAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "is_flapping", Column(&ServicesTable::IsFlappingAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "checks_enabled", Column(&ServicesTable::ChecksEnabledAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "accept_passive_checks", Column(&ServicesTable::AcceptPassiveChecksAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "event_handler_enabled", Column(&ServicesTable::EventHandlerEnabledAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "notifications_enabled", Column(&ServicesTable::NotificationsEnabledAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "process_performance_data", Column(&ServicesTable::ProcessPerformanceDataAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "is_executing", Column(&ServicesTable::IsExecutingAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "active_checks_enabled", Column(&ServicesTable::ActiveChecksEnabledAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "check_options", Column(&ServicesTable::CheckOptionsAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "flap_detection_enabled", Column(&ServicesTable::FlapDetectionEnabledAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "check_freshness", Column(&ServicesTable::CheckFreshnessAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "obsess_over_service", Column(&ServicesTable::ObsessOverServiceAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "modified_attributes", Column(&ServicesTable::ModifiedAttributesAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "modified_attributes_list", Column(&ServicesTable::ModifiedAttributesListAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "pnpgraph_present", Column(&ServicesTable::PnpgraphPresentAccessor, objectAccessor));
|
2013-07-19 14:19:09 +02:00
|
|
|
table->AddColumn(prefix + "staleness", Column(&ServicesTable::StalenessAccessor, objectAccessor));
|
2013-07-08 17:09:15 +02:00
|
|
|
table->AddColumn(prefix + "check_interval", Column(&ServicesTable::CheckIntervalAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "retry_interval", Column(&ServicesTable::RetryIntervalAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "notification_interval", Column(&ServicesTable::NotificationIntervalAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "first_notification_delay", Column(&ServicesTable::FirstNotificationDelayAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "low_flap_threshold", Column(&ServicesTable::LowFlapThresholdAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "high_flap_threshold", Column(&ServicesTable::HighFlapThresholdAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "latency", Column(&ServicesTable::LatencyAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "execution_time", Column(&ServicesTable::ExecutionTimeAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "percent_state_change", Column(&ServicesTable::PercentStateChangeAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "in_check_period", Column(&ServicesTable::InCheckPeriodAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "in_notification_period", Column(&ServicesTable::InNotificationPeriodAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "contacts", Column(&ServicesTable::ContactsAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "downtimes", Column(&ServicesTable::DowntimesAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "downtimes_with_info", Column(&ServicesTable::DowntimesWithInfoAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "comments", Column(&ServicesTable::CommentsAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "comments_with_info", Column(&ServicesTable::CommentsWithInfoAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "comments_with_extra_info", Column(&ServicesTable::CommentsWithExtraInfoAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "custom_variable_names", Column(&ServicesTable::CustomVariableNamesAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "custom_variable_values", Column(&ServicesTable::CustomVariableValuesAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "custom_variables", Column(&ServicesTable::CustomVariablesAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "groups", Column(&ServicesTable::GroupsAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "contact_groups", Column(&ServicesTable::ContactGroupsAccessor, objectAccessor));
|
2013-03-10 22:20:13 +01:00
|
|
|
|
2013-07-10 16:11:40 +02:00
|
|
|
HostsTable::AddColumns(table, "host_", boost::bind(&ServicesTable::HostAccessor, _1, objectAccessor));
|
2013-03-10 22:20:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
String ServicesTable::GetName(void) const
|
|
|
|
{
|
|
|
|
return "services";
|
|
|
|
}
|
|
|
|
|
2013-03-15 18:21:29 +01:00
|
|
|
void ServicesTable::FetchRows(const AddRowFunction& addRowFn)
|
2013-03-10 22:20:13 +01:00
|
|
|
{
|
2013-08-20 11:06:04 +02:00
|
|
|
BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjects<Service>()) {
|
|
|
|
addRowFn(service);
|
2013-03-10 22:20:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-10 16:11:40 +02:00
|
|
|
Object::Ptr ServicesTable::HostAccessor(const Value& row, const Column::ObjectAccessor& parentObjectAccessor)
|
2013-03-10 22:20:13 +01:00
|
|
|
{
|
2013-07-11 08:40:02 +02:00
|
|
|
Value service;
|
|
|
|
|
|
|
|
if (parentObjectAccessor)
|
|
|
|
service = parentObjectAccessor(row);
|
|
|
|
else
|
|
|
|
service = row;
|
|
|
|
|
|
|
|
return static_cast<Service::Ptr>(service)->GetHost();
|
2013-03-10 22:20:13 +01:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::ShortNameAccessor(const Value& row)
|
2013-03-10 22:20:13 +01:00
|
|
|
{
|
2013-07-10 14:06:46 +02:00
|
|
|
return static_cast<Service::Ptr>(row)->GetShortName();
|
2013-03-10 22:20:13 +01:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::DisplayNameAccessor(const Value& row)
|
2013-03-10 22:20:13 +01:00
|
|
|
{
|
2013-07-10 14:06:46 +02:00
|
|
|
return static_cast<Service::Ptr>(row)->GetDisplayName();
|
2013-03-10 22:20:13 +01:00
|
|
|
}
|
2013-07-08 17:09:15 +02:00
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::CheckCommandAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-10 14:06:46 +02:00
|
|
|
CheckCommand::Ptr checkcommand = static_cast<Service::Ptr>(row)->GetCheckCommand();
|
2013-07-08 17:09:15 +02:00
|
|
|
|
|
|
|
if (checkcommand)
|
|
|
|
return checkcommand->GetName(); /* this is the name without '!' args */
|
|
|
|
|
2013-07-12 19:20:12 +02:00
|
|
|
return Empty;
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::CheckCommandExpandedAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-16 17:58:23 +02:00
|
|
|
Service::Ptr service = static_cast<Service::Ptr>(row);
|
2013-07-08 17:09:15 +02:00
|
|
|
|
2013-07-16 17:58:23 +02:00
|
|
|
CheckCommand::Ptr commandObj = service->GetCheckCommand();
|
2013-07-08 17:09:15 +02:00
|
|
|
|
2013-07-16 17:58:23 +02:00
|
|
|
if (!commandObj)
|
|
|
|
return Empty;
|
|
|
|
|
|
|
|
Value raw_command = commandObj->GetCommandLine();
|
|
|
|
|
|
|
|
std::vector<MacroResolver::Ptr> resolvers;
|
|
|
|
resolvers.push_back(service);
|
|
|
|
resolvers.push_back(service->GetHost());
|
2013-09-10 10:37:30 +02:00
|
|
|
resolvers.push_back(commandObj);
|
2013-07-16 17:58:23 +02:00
|
|
|
resolvers.push_back(IcingaApplication::GetInstance());
|
|
|
|
|
|
|
|
Value commandLine = MacroProcessor::ResolveMacros(raw_command, resolvers, Dictionary::Ptr(), Utility::EscapeShellCmd);
|
|
|
|
|
|
|
|
String buf;
|
|
|
|
if (commandLine.IsObjectType<Array>()) {
|
|
|
|
Array::Ptr args = commandLine;
|
|
|
|
|
|
|
|
ObjectLock olock(args);
|
|
|
|
String arg;
|
|
|
|
BOOST_FOREACH(arg, args) {
|
|
|
|
// This is obviously incorrect for non-trivial cases.
|
|
|
|
String argitem = " \"" + arg + "\"";
|
|
|
|
boost::algorithm::replace_all(argitem, "\n", "\\n");
|
|
|
|
buf += argitem;
|
|
|
|
}
|
|
|
|
} else if (!commandLine.IsEmpty()) {
|
|
|
|
String args = Convert::ToString(commandLine);
|
|
|
|
boost::algorithm::replace_all(args, "\n", "\\n");
|
|
|
|
buf += args;
|
|
|
|
} else {
|
|
|
|
buf += "<internal>";
|
|
|
|
}
|
|
|
|
|
|
|
|
return buf;
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::EventHandlerAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-10 14:06:46 +02:00
|
|
|
EventCommand::Ptr eventcommand = static_cast<Service::Ptr>(row)->GetEventCommand();
|
2013-07-08 17:09:15 +02:00
|
|
|
|
|
|
|
if (eventcommand)
|
|
|
|
return eventcommand->GetName();
|
|
|
|
|
2013-07-12 19:20:12 +02:00
|
|
|
return Empty;
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::PluginOutputAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-10 14:06:46 +02:00
|
|
|
return static_cast<Service::Ptr>(row)->GetLastCheckOutput();
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::LongPluginOutputAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-10 14:06:46 +02:00
|
|
|
return static_cast<Service::Ptr>(row)->GetLastCheckLongOutput();
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::PerfDataAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-10 14:06:46 +02:00
|
|
|
return static_cast<Service::Ptr>(row)->GetLastCheckPerfData();
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::NotificationPeriodAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-16 17:58:23 +02:00
|
|
|
BOOST_FOREACH(const Notification::Ptr& notification, static_cast<Service::Ptr>(row)->GetNotifications()) {
|
|
|
|
ObjectLock olock(notification);
|
|
|
|
|
|
|
|
TimePeriod::Ptr timeperiod = notification->GetNotificationPeriod();
|
|
|
|
|
|
|
|
/* XXX first notification wins */
|
|
|
|
if (timeperiod)
|
|
|
|
return timeperiod->GetName();
|
|
|
|
}
|
|
|
|
|
2013-07-12 19:20:12 +02:00
|
|
|
return Empty;
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::CheckPeriodAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-10 14:06:46 +02:00
|
|
|
TimePeriod::Ptr timeperiod = static_cast<Service::Ptr>(row)->GetCheckPeriod();
|
2013-07-08 17:09:15 +02:00
|
|
|
|
|
|
|
if (!timeperiod)
|
2013-07-12 19:20:12 +02:00
|
|
|
return Empty;
|
2013-07-08 17:09:15 +02:00
|
|
|
|
|
|
|
return timeperiod->GetName();
|
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::NotesAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-10 14:06:46 +02:00
|
|
|
Dictionary::Ptr custom = static_cast<Service::Ptr>(row)->GetCustom();
|
2013-07-08 17:09:15 +02:00
|
|
|
|
|
|
|
if (!custom)
|
2013-07-12 19:20:12 +02:00
|
|
|
return Empty;
|
2013-07-08 17:09:15 +02:00
|
|
|
|
|
|
|
return custom->Get("notes");
|
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::NotesExpandedAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-16 17:58:23 +02:00
|
|
|
Service::Ptr service = static_cast<Service::Ptr>(row);
|
|
|
|
Dictionary::Ptr custom = service->GetCustom();
|
|
|
|
|
|
|
|
if (!custom)
|
|
|
|
return Empty;
|
|
|
|
|
|
|
|
std::vector<MacroResolver::Ptr> resolvers;
|
|
|
|
resolvers.push_back(service);
|
|
|
|
resolvers.push_back(service->GetHost());
|
|
|
|
resolvers.push_back(IcingaApplication::GetInstance());
|
|
|
|
|
|
|
|
Value value = custom->Get("notes");
|
|
|
|
|
|
|
|
Dictionary::Ptr cr;
|
|
|
|
Value value_expanded = MacroProcessor::ResolveMacros(value, resolvers, cr, Utility::EscapeShellCmd);
|
|
|
|
|
|
|
|
return value_expanded;
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::NotesUrlAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-10 14:06:46 +02:00
|
|
|
Dictionary::Ptr custom = static_cast<Service::Ptr>(row)->GetCustom();
|
2013-07-08 17:09:15 +02:00
|
|
|
|
|
|
|
if (!custom)
|
2013-07-12 19:20:12 +02:00
|
|
|
return Empty;
|
2013-07-08 17:09:15 +02:00
|
|
|
|
|
|
|
return custom->Get("notes_url");
|
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::NotesUrlExpandedAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-16 17:58:23 +02:00
|
|
|
Service::Ptr service = static_cast<Service::Ptr>(row);
|
|
|
|
Dictionary::Ptr custom = service->GetCustom();
|
|
|
|
|
|
|
|
if (!custom)
|
|
|
|
return Empty;
|
|
|
|
|
|
|
|
std::vector<MacroResolver::Ptr> resolvers;
|
|
|
|
resolvers.push_back(service);
|
|
|
|
resolvers.push_back(service->GetHost());
|
|
|
|
resolvers.push_back(IcingaApplication::GetInstance());
|
|
|
|
|
|
|
|
Value value = custom->Get("notes_url");
|
|
|
|
|
|
|
|
Dictionary::Ptr cr;
|
|
|
|
Value value_expanded = MacroProcessor::ResolveMacros(value, resolvers, cr, Utility::EscapeShellCmd);
|
|
|
|
|
|
|
|
return value_expanded;
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::ActionUrlAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-10 14:06:46 +02:00
|
|
|
Dictionary::Ptr custom = static_cast<Service::Ptr>(row)->GetCustom();
|
2013-07-08 17:09:15 +02:00
|
|
|
|
|
|
|
if (!custom)
|
2013-07-12 19:20:12 +02:00
|
|
|
return Empty;
|
2013-07-08 17:09:15 +02:00
|
|
|
|
|
|
|
return custom->Get("action_url");
|
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::ActionUrlExpandedAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-16 17:58:23 +02:00
|
|
|
Service::Ptr service = static_cast<Service::Ptr>(row);
|
|
|
|
Dictionary::Ptr custom = service->GetCustom();
|
|
|
|
|
|
|
|
if (!custom)
|
|
|
|
return Empty;
|
|
|
|
|
|
|
|
std::vector<MacroResolver::Ptr> resolvers;
|
|
|
|
resolvers.push_back(service);
|
|
|
|
resolvers.push_back(service->GetHost());
|
|
|
|
resolvers.push_back(IcingaApplication::GetInstance());
|
|
|
|
|
|
|
|
Value value = custom->Get("action_url");
|
|
|
|
|
|
|
|
Dictionary::Ptr cr;
|
|
|
|
Value value_expanded = MacroProcessor::ResolveMacros(value, resolvers, cr, Utility::EscapeShellCmd);
|
|
|
|
|
|
|
|
return value_expanded;
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::IconImageAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-10 14:06:46 +02:00
|
|
|
Dictionary::Ptr custom = static_cast<Service::Ptr>(row)->GetCustom();
|
2013-07-08 17:09:15 +02:00
|
|
|
|
|
|
|
if (!custom)
|
2013-07-12 19:20:12 +02:00
|
|
|
return Empty;
|
2013-07-08 17:09:15 +02:00
|
|
|
|
|
|
|
return custom->Get("icon_image");
|
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::IconImageExpandedAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-16 17:58:23 +02:00
|
|
|
Service::Ptr service = static_cast<Service::Ptr>(row);
|
|
|
|
Dictionary::Ptr custom = service->GetCustom();
|
|
|
|
|
|
|
|
if (!custom)
|
|
|
|
return Empty;
|
|
|
|
|
|
|
|
std::vector<MacroResolver::Ptr> resolvers;
|
|
|
|
resolvers.push_back(service);
|
|
|
|
resolvers.push_back(service->GetHost());
|
|
|
|
resolvers.push_back(IcingaApplication::GetInstance());
|
|
|
|
|
|
|
|
Value value = custom->Get("icon_image");
|
|
|
|
|
|
|
|
Dictionary::Ptr cr;
|
|
|
|
Value value_expanded = MacroProcessor::ResolveMacros(value, resolvers, cr, Utility::EscapeShellCmd);
|
|
|
|
|
|
|
|
return value_expanded;
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::IconImageAltAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-10 14:06:46 +02:00
|
|
|
Dictionary::Ptr custom = static_cast<Service::Ptr>(row)->GetCustom();
|
2013-07-08 17:09:15 +02:00
|
|
|
|
|
|
|
if (!custom)
|
2013-07-12 19:20:12 +02:00
|
|
|
return Empty;
|
2013-07-08 17:09:15 +02:00
|
|
|
|
|
|
|
return custom->Get("icon_image_alt");
|
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::InitialStateAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
|
|
|
/* not supported */
|
2013-07-12 19:20:12 +02:00
|
|
|
return Empty;
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::MaxCheckAttemptsAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-10 14:06:46 +02:00
|
|
|
return static_cast<Service::Ptr>(row)->GetMaxCheckAttempts();
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::CurrentAttemptAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-10 14:06:46 +02:00
|
|
|
return static_cast<Service::Ptr>(row)->GetCurrentCheckAttempt();
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::StateAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-10 14:06:46 +02:00
|
|
|
return static_cast<Service::Ptr>(row)->GetState();
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::HasBeenCheckedAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-10 14:06:46 +02:00
|
|
|
return (static_cast<Service::Ptr>(row)->HasBeenChecked() ? 1 : 0);
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::LastStateAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-10 14:06:46 +02:00
|
|
|
return static_cast<Service::Ptr>(row)->GetLastState();
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::LastHardStateAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-10 14:06:46 +02:00
|
|
|
return static_cast<Service::Ptr>(row)->GetLastHardState();
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::StateTypeAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-10 14:06:46 +02:00
|
|
|
return static_cast<Service::Ptr>(row)->GetStateType();
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::CheckTypeAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-11 11:55:32 +02:00
|
|
|
return (static_cast<Service::Ptr>(row)->GetEnableActiveChecks() ? 0 : 1);
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::AcknowledgedAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-10 14:06:46 +02:00
|
|
|
Service::Ptr service = static_cast<Service::Ptr>(row);
|
2013-07-08 17:09:15 +02:00
|
|
|
|
|
|
|
/* important: lock acknowledgements */
|
|
|
|
ObjectLock olock(service);
|
|
|
|
|
|
|
|
return (service->IsAcknowledged() ? 1 : 0);
|
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::AcknowledgementTypeAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-10 14:06:46 +02:00
|
|
|
Service::Ptr service = static_cast<Service::Ptr>(row);
|
2013-07-08 17:09:15 +02:00
|
|
|
|
|
|
|
/* important: lock acknowledgements */
|
|
|
|
ObjectLock olock(service);
|
|
|
|
|
|
|
|
return static_cast<int>(service->GetAcknowledgement());
|
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::NoMoreNotificationsAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-16 17:58:23 +02:00
|
|
|
Service::Ptr service = static_cast<Service::Ptr>(row);
|
|
|
|
|
|
|
|
/* XXX take the smallest notification_interval */
|
|
|
|
double notification_interval = -1;
|
|
|
|
BOOST_FOREACH(const Notification::Ptr& notification, service->GetNotifications()) {
|
|
|
|
if (notification_interval == -1 || notification->GetNotificationInterval() < notification_interval)
|
|
|
|
notification_interval = notification->GetNotificationInterval();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (notification_interval == 0 && !service->IsVolatile())
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::LastTimeOkAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-18 18:17:25 +02:00
|
|
|
return static_cast<int>(static_cast<Service::Ptr>(row)->GetLastStateOK());
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::LastTimeWarningAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-18 18:17:25 +02:00
|
|
|
return static_cast<int>(static_cast<Service::Ptr>(row)->GetLastStateWarning());
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::LastTimeCriticalAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-18 18:17:25 +02:00
|
|
|
return static_cast<int>(static_cast<Service::Ptr>(row)->GetLastStateCritical());
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::LastTimeUnknownAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-18 18:17:25 +02:00
|
|
|
return static_cast<int>(static_cast<Service::Ptr>(row)->GetLastStateUnknown());
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::LastCheckAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-11 10:57:21 +02:00
|
|
|
return static_cast<int>(static_cast<Service::Ptr>(row)->GetLastCheck());
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::NextCheckAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-11 10:57:21 +02:00
|
|
|
return static_cast<int>(static_cast<Service::Ptr>(row)->GetNextCheck());
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::LastNotificationAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-16 17:58:23 +02:00
|
|
|
Service::Ptr service = static_cast<Service::Ptr>(row);
|
|
|
|
|
|
|
|
/* XXX Service -> Notifications, latest wins */
|
|
|
|
double last_notification = 0;
|
|
|
|
BOOST_FOREACH(const Notification::Ptr& notification, service->GetNotifications()) {
|
|
|
|
if (notification->GetLastNotification() > last_notification)
|
|
|
|
last_notification = notification->GetLastNotification();
|
|
|
|
}
|
|
|
|
|
|
|
|
return static_cast<int>(last_notification);
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::NextNotificationAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-16 17:58:23 +02:00
|
|
|
Service::Ptr service = static_cast<Service::Ptr>(row);
|
|
|
|
|
|
|
|
/* XXX Service -> Notifications, latest wins */
|
|
|
|
double next_notification = 0;
|
|
|
|
BOOST_FOREACH(const Notification::Ptr& notification, service->GetNotifications()) {
|
|
|
|
if (notification->GetNextNotification() < next_notification)
|
|
|
|
next_notification = notification->GetNextNotification();
|
|
|
|
}
|
|
|
|
|
|
|
|
return static_cast<int>(next_notification);
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::CurrentNotificationNumberAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-18 17:24:14 +02:00
|
|
|
Service::Ptr service = static_cast<Service::Ptr>(row);
|
|
|
|
|
|
|
|
/* XXX Service -> Notifications, biggest wins */
|
|
|
|
int notification_number = 0;
|
|
|
|
BOOST_FOREACH(const Notification::Ptr& notification, service->GetNotifications()) {
|
|
|
|
if (notification->GetNotificationNumber() > notification_number)
|
|
|
|
notification_number = notification->GetNotificationNumber();
|
|
|
|
}
|
|
|
|
|
|
|
|
return notification_number;
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::LastStateChangeAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-11 10:57:21 +02:00
|
|
|
return static_cast<int>(static_cast<Service::Ptr>(row)->GetLastStateChange());
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::LastHardStateChangeAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-11 10:57:21 +02:00
|
|
|
return static_cast<int>(static_cast<Service::Ptr>(row)->GetLastHardStateChange());
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::ScheduledDowntimeDepthAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-10 14:06:46 +02:00
|
|
|
return static_cast<Service::Ptr>(row)->GetDowntimeDepth();
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::IsFlappingAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-10 14:06:46 +02:00
|
|
|
return static_cast<Service::Ptr>(row)->IsFlapping();
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::ChecksEnabledAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-10 14:06:46 +02:00
|
|
|
return (static_cast<Service::Ptr>(row)->GetEnableActiveChecks() ? 1 : 0);
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::AcceptPassiveChecksAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-10 14:06:46 +02:00
|
|
|
return (static_cast<Service::Ptr>(row)->GetEnablePassiveChecks() ? 1 : 0);
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::EventHandlerEnabledAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-19 13:59:39 +02:00
|
|
|
/* always enabled */
|
|
|
|
return 1;
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::NotificationsEnabledAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-10 14:06:46 +02:00
|
|
|
return (static_cast<Service::Ptr>(row)->GetEnableNotifications() ? 1 : 0);
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::ProcessPerformanceDataAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-19 13:59:39 +02:00
|
|
|
/* always enabled */
|
|
|
|
return 1;
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::IsExecutingAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-19 13:59:39 +02:00
|
|
|
/* not supported */
|
2013-07-12 19:20:12 +02:00
|
|
|
return Empty;
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::ActiveChecksEnabledAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-10 14:06:46 +02:00
|
|
|
return (static_cast<Service::Ptr>(row)->GetEnableActiveChecks() ? 1 : 0);
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::CheckOptionsAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
|
|
|
/* TODO - forcexec, freshness, orphan, none */
|
2013-07-12 19:20:12 +02:00
|
|
|
return Empty;
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::FlapDetectionEnabledAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-10 14:06:46 +02:00
|
|
|
return (static_cast<Service::Ptr>(row)->GetEnableFlapping() ? 1 : 0);
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::CheckFreshnessAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-19 13:59:39 +02:00
|
|
|
/* always enabled */
|
|
|
|
return 1;
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::ObsessOverServiceAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
|
|
|
/* not supported */
|
2013-07-12 19:20:12 +02:00
|
|
|
return Empty;
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::ModifiedAttributesAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
|
|
|
/* not supported */
|
2013-07-12 19:20:12 +02:00
|
|
|
return Empty;
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::ModifiedAttributesListAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
|
|
|
/* not supported */
|
2013-07-12 19:20:12 +02:00
|
|
|
return Empty;
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::PnpgraphPresentAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
|
|
|
/* not supported */
|
2013-07-12 19:20:12 +02:00
|
|
|
return Empty;
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-19 14:19:09 +02:00
|
|
|
Value ServicesTable::StalenessAccessor(const Value& row)
|
|
|
|
{
|
|
|
|
Service::Ptr service = static_cast<Service::Ptr>(row);
|
|
|
|
|
|
|
|
if (service->HasBeenChecked() && service->GetLastCheck() > 0)
|
|
|
|
return (Utility::GetTime() - service->GetLastCheck()) / (service->GetCheckInterval() * 3600);
|
|
|
|
|
|
|
|
return Empty;
|
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::CheckIntervalAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-10 14:06:46 +02:00
|
|
|
return (static_cast<Service::Ptr>(row)->GetCheckInterval() / 60.0);
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::RetryIntervalAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-10 14:06:46 +02:00
|
|
|
return (static_cast<Service::Ptr>(row)->GetRetryInterval() / 60.0);
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::NotificationIntervalAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-16 17:58:23 +02:00
|
|
|
Service::Ptr service = static_cast<Service::Ptr>(row);
|
|
|
|
|
|
|
|
/* XXX take the smallest notification_interval */
|
|
|
|
double notification_interval = -1;
|
|
|
|
BOOST_FOREACH(const Notification::Ptr& notification, service->GetNotifications()) {
|
|
|
|
if (notification_interval == -1 || notification->GetNotificationInterval() < notification_interval)
|
|
|
|
notification_interval = notification->GetNotificationInterval();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (notification_interval == -1)
|
|
|
|
notification_interval = 60;
|
|
|
|
|
|
|
|
return (notification_interval / 60.0);
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::FirstNotificationDelayAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
|
|
|
/* not supported */
|
2013-07-12 19:20:12 +02:00
|
|
|
return Empty;
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::LowFlapThresholdAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-19 13:59:39 +02:00
|
|
|
return static_cast<Service::Ptr>(row)->GetFlappingThreshold();
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::HighFlapThresholdAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-19 13:59:39 +02:00
|
|
|
return static_cast<Service::Ptr>(row)->GetFlappingThreshold();
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::LatencyAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-10 14:06:46 +02:00
|
|
|
return (Service::CalculateLatency(static_cast<Service::Ptr>(row)->GetLastCheckResult()));
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::ExecutionTimeAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-10 14:06:46 +02:00
|
|
|
return (Service::CalculateExecutionTime(static_cast<Service::Ptr>(row)->GetLastCheckResult()));
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::PercentStateChangeAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-10 14:06:46 +02:00
|
|
|
return static_cast<Service::Ptr>(row)->GetFlappingCurrent();
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::InCheckPeriodAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-16 17:58:23 +02:00
|
|
|
TimePeriod::Ptr timeperiod = static_cast<Service::Ptr>(row)->GetCheckPeriod();
|
|
|
|
|
2013-07-19 13:59:39 +02:00
|
|
|
/* none set means always checked */
|
2013-07-16 17:58:23 +02:00
|
|
|
if (!timeperiod)
|
2013-07-19 13:59:39 +02:00
|
|
|
return 1;
|
2013-07-16 17:58:23 +02:00
|
|
|
|
|
|
|
return (timeperiod->IsInside(Utility::GetTime()) ? 1 : 0);
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::InNotificationPeriodAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-16 17:58:23 +02:00
|
|
|
BOOST_FOREACH(const Notification::Ptr& notification, static_cast<Service::Ptr>(row)->GetNotifications()) {
|
|
|
|
ObjectLock olock(notification);
|
|
|
|
|
|
|
|
TimePeriod::Ptr timeperiod = notification->GetNotificationPeriod();
|
|
|
|
|
|
|
|
/* XXX first notification wins */
|
|
|
|
if (timeperiod)
|
|
|
|
return (timeperiod->IsInside(Utility::GetTime()) ? 1 : 0);
|
|
|
|
}
|
|
|
|
|
2013-07-19 13:59:39 +02:00
|
|
|
/* none set means always notified */
|
|
|
|
return 1;
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::ContactsAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-10-01 16:32:29 +02:00
|
|
|
Array::Ptr contacts = CompatUtility::GetServiceNotificationUsers(static_cast<Service::Ptr>(row));
|
|
|
|
Array::Ptr contact_names = boost::make_shared<Array>();
|
|
|
|
|
|
|
|
ObjectLock olock(contacts);
|
|
|
|
BOOST_FOREACH(const User::Ptr& user, contacts) {
|
|
|
|
contact_names->Add(user->GetName());
|
|
|
|
}
|
|
|
|
|
|
|
|
return contact_names;
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::DowntimesAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-16 17:58:23 +02:00
|
|
|
Dictionary::Ptr downtimes = static_cast<Service::Ptr>(row)->GetDowntimes();
|
|
|
|
|
|
|
|
if (!downtimes)
|
|
|
|
return Empty;
|
|
|
|
|
|
|
|
Array::Ptr ids = boost::make_shared<Array>();
|
|
|
|
|
|
|
|
ObjectLock olock(downtimes);
|
|
|
|
|
|
|
|
String id;
|
|
|
|
Dictionary::Ptr downtime;
|
|
|
|
BOOST_FOREACH(boost::tie(id, downtime), downtimes) {
|
|
|
|
|
|
|
|
if (!downtime)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (Service::IsDowntimeExpired(downtime))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
ids->Add(downtime->Get("legacy_id"));
|
|
|
|
}
|
|
|
|
|
|
|
|
return ids;
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::DowntimesWithInfoAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-16 17:58:23 +02:00
|
|
|
Dictionary::Ptr downtimes = static_cast<Service::Ptr>(row)->GetDowntimes();
|
|
|
|
|
|
|
|
if (!downtimes)
|
|
|
|
return Empty;
|
|
|
|
|
|
|
|
Array::Ptr ids = boost::make_shared<Array>();
|
|
|
|
|
|
|
|
ObjectLock olock(downtimes);
|
|
|
|
|
|
|
|
String id;
|
|
|
|
Dictionary::Ptr downtime;
|
|
|
|
BOOST_FOREACH(boost::tie(id, downtime), downtimes) {
|
|
|
|
|
|
|
|
if (!downtime)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (Service::IsDowntimeExpired(downtime))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
Array::Ptr downtime_info = boost::make_shared<Array>();
|
|
|
|
downtime_info->Add(downtime->Get("legacy_id"));
|
|
|
|
downtime_info->Add(downtime->Get("author"));
|
|
|
|
downtime_info->Add(downtime->Get("comment"));
|
|
|
|
ids->Add(downtime_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ids;
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::CommentsAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-16 17:58:23 +02:00
|
|
|
Dictionary::Ptr comments = static_cast<Service::Ptr>(row)->GetComments();
|
|
|
|
|
|
|
|
if (!comments)
|
|
|
|
return Empty;
|
|
|
|
|
|
|
|
Array::Ptr ids = boost::make_shared<Array>();
|
|
|
|
|
|
|
|
ObjectLock olock(comments);
|
|
|
|
|
|
|
|
String id;
|
|
|
|
Dictionary::Ptr comment;
|
|
|
|
BOOST_FOREACH(boost::tie(id, comment), comments) {
|
|
|
|
|
|
|
|
if (!comment)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (Service::IsCommentExpired(comment))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
ids->Add(comment->Get("legacy_id"));
|
|
|
|
}
|
|
|
|
|
|
|
|
return ids;
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::CommentsWithInfoAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-16 17:58:23 +02:00
|
|
|
Dictionary::Ptr comments = static_cast<Service::Ptr>(row)->GetComments();
|
|
|
|
|
|
|
|
if (!comments)
|
|
|
|
return Empty;
|
|
|
|
|
|
|
|
Array::Ptr ids = boost::make_shared<Array>();
|
|
|
|
|
|
|
|
ObjectLock olock(comments);
|
|
|
|
|
|
|
|
String id;
|
|
|
|
Dictionary::Ptr comment;
|
|
|
|
BOOST_FOREACH(boost::tie(id, comment), comments) {
|
|
|
|
|
|
|
|
if (!comment)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (Service::IsCommentExpired(comment))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
Array::Ptr comment_info = boost::make_shared<Array>();
|
|
|
|
comment_info->Add(comment->Get("legacy_id"));
|
|
|
|
comment_info->Add(comment->Get("author"));
|
|
|
|
comment_info->Add(comment->Get("text"));
|
|
|
|
ids->Add(comment_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ids;
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::CommentsWithExtraInfoAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-16 17:58:23 +02:00
|
|
|
Dictionary::Ptr comments = static_cast<Service::Ptr>(row)->GetComments();
|
|
|
|
|
|
|
|
if (!comments)
|
|
|
|
return Empty;
|
|
|
|
|
|
|
|
Array::Ptr ids = boost::make_shared<Array>();
|
|
|
|
|
|
|
|
ObjectLock olock(comments);
|
|
|
|
|
|
|
|
String id;
|
|
|
|
Dictionary::Ptr comment;
|
|
|
|
BOOST_FOREACH(boost::tie(id, comment), comments) {
|
|
|
|
|
|
|
|
if (!comment)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (Service::IsCommentExpired(comment))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
Array::Ptr comment_info = boost::make_shared<Array>();
|
|
|
|
comment_info->Add(comment->Get("legacy_id"));
|
|
|
|
comment_info->Add(comment->Get("author"));
|
|
|
|
comment_info->Add(comment->Get("text"));
|
|
|
|
comment_info->Add(comment->Get("entry_type"));
|
|
|
|
comment_info->Add(static_cast<int>(comment->Get("entry_time")));
|
|
|
|
ids->Add(comment_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ids;
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::CustomVariableNamesAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-16 17:58:23 +02:00
|
|
|
Dictionary::Ptr custom = static_cast<Service::Ptr>(row)->GetCustom();
|
|
|
|
|
|
|
|
if (!custom)
|
|
|
|
return Empty;
|
|
|
|
|
|
|
|
Array::Ptr cv = boost::make_shared<Array>();
|
|
|
|
|
|
|
|
ObjectLock olock(custom);
|
|
|
|
String key;
|
|
|
|
Value value;
|
|
|
|
BOOST_FOREACH(boost::tie(key, value), custom) {
|
|
|
|
if (key == "notes" ||
|
|
|
|
key == "action_url" ||
|
|
|
|
key == "notes_url" ||
|
|
|
|
key == "icon_image" ||
|
|
|
|
key == "icon_image_alt" ||
|
|
|
|
key == "statusmap_image" ||
|
|
|
|
key == "2d_coords")
|
|
|
|
continue;
|
|
|
|
|
|
|
|
cv->Add(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
return cv;
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::CustomVariableValuesAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-16 17:58:23 +02:00
|
|
|
Dictionary::Ptr custom = static_cast<Service::Ptr>(row)->GetCustom();
|
|
|
|
|
|
|
|
if (!custom)
|
|
|
|
return Empty;
|
|
|
|
|
|
|
|
Array::Ptr cv = boost::make_shared<Array>();
|
|
|
|
|
|
|
|
ObjectLock olock(custom);
|
|
|
|
String key;
|
|
|
|
Value value;
|
|
|
|
BOOST_FOREACH(boost::tie(key, value), custom) {
|
|
|
|
if (key == "notes" ||
|
|
|
|
key == "action_url" ||
|
|
|
|
key == "notes_url" ||
|
|
|
|
key == "icon_image" ||
|
|
|
|
key == "icon_image_alt" ||
|
|
|
|
key == "statusmap_image" ||
|
|
|
|
key == "2d_coords")
|
|
|
|
continue;
|
|
|
|
|
|
|
|
cv->Add(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
return cv;
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::CustomVariablesAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-16 17:58:23 +02:00
|
|
|
Dictionary::Ptr custom = static_cast<Service::Ptr>(row)->GetCustom();
|
2013-07-09 17:15:38 +02:00
|
|
|
|
|
|
|
if (!custom)
|
2013-07-12 19:20:12 +02:00
|
|
|
return Empty;
|
2013-07-09 17:15:38 +02:00
|
|
|
|
2013-07-16 17:58:23 +02:00
|
|
|
Array::Ptr cv = boost::make_shared<Array>();
|
|
|
|
|
|
|
|
ObjectLock olock(custom);
|
|
|
|
String key;
|
|
|
|
Value value;
|
|
|
|
BOOST_FOREACH(boost::tie(key, value), custom) {
|
|
|
|
if (key == "notes" ||
|
|
|
|
key == "action_url" ||
|
|
|
|
key == "notes_url" ||
|
|
|
|
key == "icon_image" ||
|
|
|
|
key == "icon_image_alt" ||
|
|
|
|
key == "statusmap_image" ||
|
|
|
|
key == "2d_coords")
|
|
|
|
continue;
|
|
|
|
|
|
|
|
Array::Ptr key_val = boost::make_shared<Array>();
|
|
|
|
key_val->Add(key);
|
|
|
|
key_val->Add(value);
|
|
|
|
cv->Add(key_val);
|
|
|
|
}
|
|
|
|
|
|
|
|
return cv;
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::GroupsAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-07-16 17:58:23 +02:00
|
|
|
Array::Ptr groups = static_cast<Service::Ptr>(row)->GetGroups();
|
|
|
|
|
|
|
|
if (!groups)
|
|
|
|
return Empty;
|
|
|
|
|
|
|
|
return groups;
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServicesTable::ContactGroupsAccessor(const Value& row)
|
2013-07-08 17:09:15 +02:00
|
|
|
{
|
2013-10-01 16:32:29 +02:00
|
|
|
Array::Ptr contactgroups = CompatUtility::GetServiceNotificationUserGroups(static_cast<Service::Ptr>(row));
|
|
|
|
|
|
|
|
Array::Ptr contactgroup_names = boost::make_shared<Array>();
|
|
|
|
|
|
|
|
ObjectLock olock(contactgroups);
|
|
|
|
BOOST_FOREACH(const UserGroup::Ptr& usergroup, contactgroups) {
|
|
|
|
contactgroup_names->Add(usergroup->GetName());
|
|
|
|
}
|
|
|
|
|
|
|
|
return contactgroup_names;
|
2013-07-08 17:09:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|