}
String output;
- if (cr) {
- std::pair<String, String> output_bag = CompatUtility::GetCheckResultOutput(cr);
- output = output_bag.first;
- }
+ if (cr)
+ output = CompatUtility::GetCheckResultOutput(cr);
std::ostringstream msgbuf;
msgbuf << "SERVICE ALERT: "
return;
String output;
- if (cr) {
- std::pair<String, String> output_bag = CompatUtility::GetCheckResultOutput(cr);
- output = output_bag.first;
- }
+ if (cr)
+ output = CompatUtility::GetCheckResultOutput(cr);
std::ostringstream msgbuf;
msgbuf << "SERVICE NOTIFICATION: "
String output;
CheckResult::Ptr cr = hc->GetLastCheckResult();
- if (cr) {
- std::pair<String, String> output_bag = CompatUtility::GetCheckResultOutput(cr);
- output = output_bag.first;
- }
+ if (cr)
+ output = CompatUtility::GetCheckResultOutput(cr);
std::ostringstream msgbuf;
msgbuf << "CURRENT HOST STATE: "
String output;
CheckResult::Ptr cr = service->GetLastCheckResult();
- if (cr) {
- std::pair<String, String> output_bag = CompatUtility::GetCheckResultOutput(cr);
- output = output_bag.first;
- }
+ if (cr)
+ output = CompatUtility::GetCheckResultOutput(cr);
std::ostringstream msgbuf;
msgbuf << "CURRENT SERVICE STATE: "
fp << "define host {" << "\n"
<< "\t" << "host_name" << "\t" << host->GetName() << "\n"
<< "\t" << "display_name" << "\t" << host->GetDisplayName() << "\n"
- << "\t" << "alias" << "\t" << host->GetDisplayName() << "\n";
-
- Dictionary::Ptr macros = host->GetMacros();
-
- if (macros) {
- fp << "\t" << "address" << "\t" << macros->Get("address") << "\n"
- << "\t" << "address6" << "\t" << macros->Get("address6") << "\n";
- }
+ << "\t" << "alias" << "\t" << host->GetDisplayName() << "\n"
+ << "\t" << "address" << "\t" << CompatUtility::GetHostAddress(host) << "\n"
+ << "\t" << "address6" << "\t" << CompatUtility::GetHostAddress6(host) << "\n"
+ << "\t" << "notes" << "\t" << CompatUtility::GetCustomAttributeConfig(host, "notes") << "\n"
+ << "\t" << "notes_url" << "\t" << CompatUtility::GetCustomAttributeConfig(host, "notes_url") << "\n"
+ << "\t" << "action_url" << "\t" << CompatUtility::GetCustomAttributeConfig(host, "action_url") << "\n"
+ << "\t" << "icon_image" << "\t" << CompatUtility::GetCustomAttributeConfig(host, "icon_image") << "\n"
+ << "\t" << "icon_image_alt" << "\t" << CompatUtility::GetCustomAttributeConfig(host, "icon_image_alt") << "\n"
+ << "\t" << "statusmap_image" << "\t" << CompatUtility::GetCustomAttributeConfig(host, "statusmap_image") << "\n";
std::set<Host::Ptr> parents = host->GetParentHosts();
if (hc) {
ObjectLock olock(hc);
- fp << "\t" << "check_interval" << "\t" << hc->GetCheckInterval() / 60.0 << "\n"
- << "\t" << "retry_interval" << "\t" << hc->GetRetryInterval() / 60.0 << "\n"
+ fp << "\t" << "check_interval" << "\t" << CompatUtility::GetServiceCheckInterval(hc) << "\n"
+ << "\t" << "retry_interval" << "\t" << CompatUtility::GetServiceRetryInterval(hc) << "\n"
<< "\t" << "max_check_attempts" << "\t" << hc->GetMaxCheckAttempts() << "\n"
<< "\t" << "active_checks_enabled" << "\t" << (hc->GetEnableActiveChecks() ? 1 : 0) << "\n"
<< "\t" << "passive_checks_enabled" << "\t" << (hc->GetEnablePassiveChecks() ? 1 : 0) << "\n"
<< "\t" << "notifications_enabled" << "\t" << (hc->GetEnableNotifications() ? 1 : 0) << "\n"
<< "\t" << "notification_options" << "\t" << "d,u,r" << "\n"
- << "\t" << "notification_interval" << "\t" << 1 << "\n"
+ << "\t" << "notification_interval" << "\t" << CompatUtility::GetServiceNotificationNotificationInterval(hc) << "\n"
<< "\t" << "event_handler_enabled" << "\t" << (hc->GetEnableEventHandler() ? 1 : 0) << "\n";
CheckCommand::Ptr checkcommand = hc->GetCheckCommand();
if (eventcommand)
fp << "\t" << "event_handler" << "\t" << "event_" << eventcommand->GetName() << "\n";
- TimePeriod::Ptr check_period = hc->GetCheckPeriod();
- if (check_period)
- fp << "\t" << "check_period" << "\t" << check_period->GetName() << "\n";
+ fp << "\t" << "check_period" << "\t" << CompatUtility::GetServiceCheckPeriod(hc) << "\n";
fp << "\t" << "contacts" << "\t";
DumpNameList(fp, CompatUtility::GetServiceNotificationUsers(hc));
void StatusDataWriter::DumpServiceStatusAttrs(std::ostream& fp, const Service::Ptr& service, CompatObjectType type)
{
- Dictionary::Ptr attrs = CompatUtility::GetServiceStatusAttributes(service, type);
-
- fp << "\t" << "check_command=" << attrs->Get("check_command") << "\n"
- << "\t" << "event_handler=" << attrs->Get("event_handler") << "\n"
- << "\t" << "check_period=" << attrs->Get("check_period") << "\n"
- << "\t" << "check_interval=" << static_cast<double>(attrs->Get("check_interval")) << "\n"
- << "\t" << "retry_interval=" << static_cast<double>(attrs->Get("retry_interval")) << "\n"
- << "\t" << "has_been_checked=" << attrs->Get("has_been_checked") << "\n"
- << "\t" << "should_be_scheduled=" << attrs->Get("should_be_scheduled") << "\n"
- << "\t" << "check_execution_time=" << static_cast<double>(attrs->Get("check_execution_time")) << "\n"
- << "\t" << "check_latency=" << static_cast<double>(attrs->Get("check_latency")) << "\n"
- << "\t" << "current_state=" << attrs->Get("current_state") << "\n"
- << "\t" << "state_type=" << attrs->Get("state_type") << "\n"
- << "\t" << "plugin_output=" << attrs->Get("plugin_output") << "\n"
- << "\t" << "long_plugin_output=" << attrs->Get("long_plugin_output") << "\n"
- << "\t" << "performance_data=" << attrs->Get("performance_data") << "\n"
- << "\t" << "check_source=" << attrs->Get("check_source") << "\n"
- << "\t" << "last_check=" << static_cast<long>(attrs->Get("last_check")) << "\n"
- << "\t" << "next_check=" << static_cast<long>(attrs->Get("next_check")) << "\n"
- << "\t" << "current_attempt=" << attrs->Get("current_attempt") << "\n"
- << "\t" << "max_attempts=" << attrs->Get("max_attempts") << "\n"
- << "\t" << "last_state_change=" << static_cast<long>(attrs->Get("last_state_change")) << "\n"
- << "\t" << "last_hard_state_change=" << static_cast<long>(attrs->Get("last_hard_state_change")) << "\n"
- << "\t" << "last_time_ok=" << static_cast<long>(attrs->Get("last_time_ok")) << "\n"
- << "\t" << "last_time_warn=" << static_cast<long>(attrs->Get("last_time_warn")) << "\n"
- << "\t" << "last_time_critical=" << static_cast<long>(attrs->Get("last_time_critical")) << "\n"
- << "\t" << "last_time_unknown=" << static_cast<long>(attrs->Get("last_time_unknown")) << "\n"
- << "\t" << "last_update=" << static_cast<long>(attrs->Get("last_update")) << "\n"
- << "\t" << "notifications_enabled=" << attrs->Get("notifications_enabled") << "\n"
- << "\t" << "active_checks_enabled=" << attrs->Get("active_checks_enabled") << "\n"
- << "\t" << "passive_checks_enabled=" << attrs->Get("passive_checks_enabled") << "\n"
- << "\t" << "flap_detection_enabled=" << attrs->Get("flap_detection_enabled") << "\n"
- << "\t" << "is_flapping=" << attrs->Get("is_flapping") << "\n"
- << "\t" << "percent_state_change=" << attrs->Get("percent_state_change") << "\n"
- << "\t" << "problem_has_been_acknowledged=" << attrs->Get("problem_has_been_acknowledged") << "\n"
- << "\t" << "acknowledgement_type=" << attrs->Get("acknowledgement_type") << "\n"
- << "\t" << "acknowledgement_end_time=" << attrs->Get("acknowledgement_end_time") << "\n"
- << "\t" << "scheduled_downtime_depth=" << attrs->Get("scheduled_downtime_depth") << "\n"
- << "\t" << "last_notification=" << static_cast<long>(attrs->Get("last_notification")) << "\n"
- << "\t" << "next_notification=" << static_cast<long>(attrs->Get("next_notification")) << "\n"
- << "\t" << "current_notification_number=" << attrs->Get("current_notification_number") << "\n"
- << "\t" << "modified_attributes=" << attrs->Get("modified_attributes") << "\n";
+ CheckResult::Ptr cr = service->GetLastCheckResult();
+
+ fp << "\t" << "check_command=check_" << CompatUtility::GetServiceCheckCommand(service) << "\n"
+ << "\t" << "event_handler=event_" << CompatUtility::GetServiceEventHandler(service) << "\n"
+ << "\t" << "check_period=" << CompatUtility::GetServiceCheckPeriod(service) << "\n"
+ << "\t" << "check_interval=" << CompatUtility::GetServiceCheckInterval(service) << "\n"
+ << "\t" << "retry_interval=" << CompatUtility::GetServiceRetryInterval(service) << "\n"
+ << "\t" << "has_been_checked=" << CompatUtility::GetServiceHasBeenChecked(service) << "\n"
+ << "\t" << "should_be_scheduled=" << CompatUtility::GetServiceShouldBeScheduled(service) << "\n";
+
+ if (cr) {
+ fp << "\t" << "check_execution_time=" << static_cast<double>(Service::CalculateExecutionTime(cr)) << "\n"
+ << "\t" << "check_latency=" << static_cast<double>(Service::CalculateLatency(cr)) << "\n";
+ }
+
+ fp << "\t" << "current_state=" << CompatUtility::GetServiceCurrentState(service) << "\n"
+ << "\t" << "state_type=" << service->GetStateType() << "\n"
+ << "\t" << "plugin_output=" << CompatUtility::GetCheckResultOutput(cr) << "\n"
+ << "\t" << "long_plugin_output=" << CompatUtility::GetCheckResultLongOutput(cr) << "\n"
+ << "\t" << "performance_data=" << CompatUtility::GetCheckResultPerfdata(cr) << "\n";
+
+ if (cr) {
+ fp << "\t" << "check_source=" << cr->GetCheckSource() << "\n"
+ << "\t" << "last_check=" << static_cast<long>(cr->GetScheduleEnd()) << "\n";
+ }
+
+ fp << "\t" << "next_check=" << static_cast<long>(service->GetNextCheck()) << "\n"
+ << "\t" << "current_attempt=" << service->GetCheckAttempt() << "\n"
+ << "\t" << "max_attempts=" << service->GetMaxCheckAttempts() << "\n"
+ << "\t" << "last_state_change=" << static_cast<long>(service->GetLastStateChange()) << "\n"
+ << "\t" << "last_hard_state_change=" << static_cast<long>(service->GetLastHardStateChange()) << "\n"
+ << "\t" << "last_time_ok=" << static_cast<int>(service->GetLastStateOK()) << "\n"
+ << "\t" << "last_time_warn=" << static_cast<int>(service->GetLastStateWarning()) << "\n"
+ << "\t" << "last_time_critical=" << static_cast<int>(service->GetLastStateCritical()) << "\n"
+ << "\t" << "last_time_unknown=" << static_cast<int>(service->GetLastStateUnknown()) << "\n"
+ << "\t" << "last_update=" << static_cast<long>(time(NULL)) << "\n"
+ << "\t" << "notifications_enabled=" << CompatUtility::GetServiceNotificationsEnabled(service) << "\n"
+ << "\t" << "active_checks_enabled=" << CompatUtility::GetServiceActiveChecksEnabled(service) << "\n"
+ << "\t" << "passive_checks_enabled=" << CompatUtility::GetServicePassiveChecksEnabled(service) << "\n"
+ << "\t" << "flap_detection_enabled=" << CompatUtility::GetServiceFlapDetectionEnabled(service) << "\n"
+ << "\t" << "is_flapping=" << CompatUtility::GetServiceIsFlapping(service) << "\n"
+ << "\t" << "percent_state_change=" << CompatUtility::GetServicePercentStateChange(service) << "\n"
+ << "\t" << "problem_has_been_acknowledged=" << CompatUtility::GetServiceProblemHasBeenAcknowledged(service) << "\n"
+ << "\t" << "acknowledgement_type=" << CompatUtility::GetServiceAcknowledgementType(service) << "\n"
+ << "\t" << "acknowledgement_end_time=" << service->GetAcknowledgementExpiry() << "\n"
+ << "\t" << "scheduled_downtime_depth=" << service->GetDowntimeDepth() << "\n"
+ << "\t" << "last_notification=" << CompatUtility::GetServiceNotificationLastNotification(service) << "\n"
+ << "\t" << "next_notification=" << CompatUtility::GetServiceNotificationNextNotification(service) << "\n"
+ << "\t" << "current_notification_number=" << CompatUtility::GetServiceNotificationNotificationNumber(service) << "\n"
+ << "\t" << "modified_attributes=" << service->GetModifiedAttributes() << "\n";
}
void StatusDataWriter::DumpServiceStatus(std::ostream& fp, const Service::Ptr& service)
{
Host::Ptr host = service->GetHost();
- String check_period_str;
- TimePeriod::Ptr check_period = service->GetCheckPeriod();
- if (check_period)
- check_period_str = check_period->GetName();
- else
- check_period_str = "24x7";
-
- 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;
-
{
ObjectLock olock(service);
<< "\t" << "host_name" << "\t" << host->GetName() << "\n"
<< "\t" << "service_description" << "\t" << service->GetShortName() << "\n"
<< "\t" << "display_name" << "\t" << service->GetDisplayName() << "\n"
- << "\t" << "check_period" << "\t" << check_period_str << "\n"
- << "\t" << "check_interval" << "\t" << service->GetCheckInterval() / 60.0 << "\n"
- << "\t" << "retry_interval" << "\t" << service->GetRetryInterval() / 60.0 << "\n"
+ << "\t" << "check_period" << "\t" << CompatUtility::GetServiceCheckPeriod(service) << "\n"
+ << "\t" << "check_interval" << "\t" << CompatUtility::GetServiceCheckInterval(service) << "\n"
+ << "\t" << "retry_interval" << "\t" << CompatUtility::GetServiceRetryInterval(service) << "\n"
<< "\t" << "max_check_attempts" << "\t" << service->GetMaxCheckAttempts() << "\n"
<< "\t" << "active_checks_enabled" << "\t" << (service->GetEnableActiveChecks() ? 1 : 0) << "\n"
<< "\t" << "passive_checks_enabled" << "\t" << (service->GetEnablePassiveChecks() ? 1 : 0) << "\n"
<< "\t" << "flap_detection_enabled" << "\t" << (service->GetEnableFlapping() ? 1 : 0) << "\n"
<< "\t" << "is_volatile" << "\t" << (service->GetVolatile() ? 1 : 0) << "\n"
<< "\t" << "notifications_enabled" << "\t" << (service->GetEnableNotifications() ? 1 : 0) << "\n"
- << "\t" << "notification_options" << "\t" << "u,w,c,r" << "\n"
- << "\t" << "notification_interval" << "\t" << notification_interval / 60.0 << "\n"
+ << "\t" << "notification_options" << "\t" << CompatUtility::GetServiceNotificationNotificationOptions(service) << "\n"
+ << "\t" << "notification_interval" << "\t" << CompatUtility::GetServiceNotificationNotificationInterval(service) << "\n"
+ << "\t" << "notification_period" << "\t" << CompatUtility::GetServiceNotificationNotificationPeriod(service) << "\n"
<< "\t" << "event_handler_enabled" << "\t" << (service->GetEnableEventHandler() ? 1 : 0) << "\n";
CheckCommand::Ptr checkcommand = service->GetCheckCommand();
if (eventcommand)
fp << "\t" << "event_handler" << "\t" << "event_" << eventcommand->GetName() << "\n";
- TimePeriod::Ptr check_period = service->GetCheckPeriod();
- if (check_period)
- fp << "\t" << "check_period" << "\t" << check_period->GetName() << "\n";
-
fp << "\t" << "contacts" << "\t";
DumpNameList(fp, CompatUtility::GetServiceNotificationUsers(service));
fp << "\n";
<< "\t" << "low_flap_threshold" << "\t" << service->GetFlappingThreshold() << "\n"
<< "\t" << "high_flap_threshold" << "\t" << service->GetFlappingThreshold() << "\n"
<< "\t" << "process_perf_data" << "\t" << 1 << "\n"
- << "\t" << "check_freshness" << "\t" << 1 << "\n";
+ << "\t" << "check_freshness" << "\t" << 1 << "\n"
+ << "\t" << "notes" << "\t" << CompatUtility::GetCustomAttributeConfig(service, "notes") << "\n"
+ << "\t" << "notes_url" << "\t" << CompatUtility::GetCustomAttributeConfig(service, "notes_url") << "\n"
+ << "\t" << "action_url" << "\t" << CompatUtility::GetCustomAttributeConfig(service, "action_url") << "\n"
+ << "\t" << "icon_image" << "\t" << CompatUtility::GetCustomAttributeConfig(service, "icon_image") << "\n"
+ << "\t" << "icon_image_alt" << "\t" << CompatUtility::GetCustomAttributeConfig(service, "icon_image_alt") << "\n";
}
fp << "\t" << "service_groups" << "\t";
{
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
return host->GetName();
}
{
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
return host->GetDisplayName();
}
{
Host::Ptr host = static_cast<Host::Ptr>(row);
- Dictionary::Ptr macros = host->GetMacros();
-
- if (!macros)
+ if (!host)
return Empty;
- return macros->Get("address");
+
+ return CompatUtility::GetHostAddress(host);
}
Value HostsTable::Address6Accessor(const Value& row)
{
Host::Ptr host = static_cast<Host::Ptr>(row);
- Dictionary::Ptr macros = host->GetMacros();
-
- if (!macros)
+ if (!host)
return Empty;
- return macros->Get("address6");
+ return CompatUtility::GetHostAddress6(host);
}
Value HostsTable::CheckCommandAccessor(const Value& row)
{
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
/* use hostcheck service */
Service::Ptr hc = host->GetCheckService();
/* use hostcheck service */
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Service::Ptr hc = host->GetCheckService();
if (!hc)
/* use hostcheck service */
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Service::Ptr hc = host->GetCheckService();
if (!hc)
/* use hostcheck service */
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Service::Ptr hc = host->GetCheckService();
if (!hc)
return Empty;
- BOOST_FOREACH(const Notification::Ptr& notification, hc->GetNotifications()) {
- ObjectLock olock(notification);
-
- TimePeriod::Ptr timeperiod = notification->GetNotificationPeriod();
-
- /* XXX first notification wins */
- if (timeperiod)
- return timeperiod->GetName();
- }
-
- return Empty;
+ return CompatUtility::GetServiceNotificationNotificationPeriod(hc);
}
Value HostsTable::CheckPeriodAccessor(const Value& row)
/* use hostcheck service */
Host::Ptr host = static_cast<Host::Ptr>(row);
- Service::Ptr hc = host->GetCheckService();
-
- if (!hc)
+ if (!host)
return Empty;
- TimePeriod::Ptr timeperiod = hc->GetCheckPeriod();
+ Service::Ptr hc = host->GetCheckService();
- if (!timeperiod)
+ if (!hc)
return Empty;
- return timeperiod->GetName();
+ return CompatUtility::GetServiceCheckPeriod(hc);
}
Value HostsTable::NotesAccessor(const Value& row)
{
Host::Ptr host = static_cast<Host::Ptr>(row);
- Dictionary::Ptr custom = host->GetCustom();
-
- if (!custom)
+ if (!host)
return Empty;
- return custom->Get("notes");
+ return CompatUtility::GetCustomAttributeConfig(host, "notes");
}
Value HostsTable::NotesExpandedAccessor(const Value& row)
{
Host::Ptr host = static_cast<Host::Ptr>(row);
- Service::Ptr service = host->GetCheckService();
-
- if (!service)
+ if (!host)
return Empty;
- Dictionary::Ptr custom = host->GetCustom();
+ Service::Ptr service = host->GetCheckService();
- if (!custom)
+ if (!service)
return Empty;
std::vector<MacroResolver::Ptr> resolvers;
resolvers.push_back(host);
resolvers.push_back(IcingaApplication::GetInstance());
- Value value = custom->Get("notes");
+ Value value = CompatUtility::GetCustomAttributeConfig(host, "notes");
return MacroProcessor::ResolveMacros(value, resolvers, CheckResult::Ptr(), Utility::EscapeShellCmd);
}
{
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Dictionary::Ptr custom = host->GetCustom();
if (!custom)
return Empty;
- return custom->Get("notes_url");
+ return CompatUtility::GetCustomAttributeConfig(host, "notes_url");
}
Value HostsTable::NotesUrlExpandedAccessor(const Value& row)
{
Host::Ptr host = static_cast<Host::Ptr>(row);
- Service::Ptr service = host->GetCheckService();
-
- if (!service)
+ if (!host)
return Empty;
- Dictionary::Ptr custom = host->GetCustom();
+ Service::Ptr service = host->GetCheckService();
- if (!custom)
+ if (!service)
return Empty;
std::vector<MacroResolver::Ptr> resolvers;
resolvers.push_back(host);
resolvers.push_back(IcingaApplication::GetInstance());
- Value value = custom->Get("notes_url");
+ Value value = CompatUtility::GetCustomAttributeConfig(host, "notes_url");
return MacroProcessor::ResolveMacros(value, resolvers, CheckResult::Ptr(), Utility::EscapeShellCmd);
}
{
Host::Ptr host = static_cast<Host::Ptr>(row);
- Dictionary::Ptr custom = host->GetCustom();
-
- if (!custom)
+ if (!host)
return Empty;
- return custom->Get("action_url");
+ return CompatUtility::GetCustomAttributeConfig(host, "action_url");
}
Value HostsTable::ActionUrlExpandedAccessor(const Value& row)
{
Host::Ptr host = static_cast<Host::Ptr>(row);
- Service::Ptr service = host->GetCheckService();
-
- if (!service)
+ if (!host)
return Empty;
- Dictionary::Ptr custom = host->GetCustom();
+ Service::Ptr service = host->GetCheckService();
- if (!custom)
+ if (!service)
return Empty;
std::vector<MacroResolver::Ptr> resolvers;
resolvers.push_back(host);
resolvers.push_back(IcingaApplication::GetInstance());
- Value value = custom->Get("action_url");
+ Value value = CompatUtility::GetCustomAttributeConfig(host, "action_url");
return MacroProcessor::ResolveMacros(value, resolvers, CheckResult::Ptr(), Utility::EscapeShellCmd);
}
/* use hostcheck service */
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Service::Ptr hc = host->GetCheckService();
String output;
if(hc) {
- String output;
CheckResult::Ptr cr = hc->GetLastCheckResult();
- if (cr) {
- std::pair<String, String> output_bag = CompatUtility::GetCheckResultOutput(cr);
- output = output_bag.first;
- }
+ if (cr)
+ output = CompatUtility::GetCheckResultOutput(cr);
}
return output;
/* use hostcheck service */
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Service::Ptr hc = host->GetCheckService();
String perfdata;
/* use hostcheck service */
Host::Ptr host = static_cast<Host::Ptr>(row);
- Dictionary::Ptr custom = host->GetCustom();
-
- if (!custom)
+ if (!host)
return Empty;
- return custom->Get("icon_image");
+ return CompatUtility::GetCustomAttributeConfig(host, "icon_image");
}
Value HostsTable::IconImageExpandedAccessor(const Value& row)
{
Host::Ptr host = static_cast<Host::Ptr>(row);
- Service::Ptr service = host->GetCheckService();
-
- if (!service)
+ if (!host)
return Empty;
- Dictionary::Ptr custom = host->GetCustom();
+ Service::Ptr service = host->GetCheckService();
- if (!custom)
+ if (!service)
return Empty;
std::vector<MacroResolver::Ptr> resolvers;
resolvers.push_back(host);
resolvers.push_back(IcingaApplication::GetInstance());
- Value value = custom->Get("icon_image");
+ Value value = CompatUtility::GetCustomAttributeConfig(host, "icon_image");
return MacroProcessor::ResolveMacros(value, resolvers, CheckResult::Ptr(), Utility::EscapeShellCmd);
}
{
Host::Ptr host = static_cast<Host::Ptr>(row);
- Dictionary::Ptr custom = host->GetCustom();
-
- if (!custom)
+ if (!host)
return Empty;
- return custom->Get("icon_image_alt");
+ return CompatUtility::GetCustomAttributeConfig(host, "icon_image_alt");
}
Value HostsTable::StatusmapImageAccessor(const Value& row)
{
Host::Ptr host = static_cast<Host::Ptr>(row);
- Dictionary::Ptr custom = host->GetCustom();
-
- if (!custom)
+ if (!host)
return Empty;
- return custom->Get("statusmap_image");
+ return CompatUtility::GetCustomAttributeConfig(host, "statusmap_image");
}
Value HostsTable::LongPluginOutputAccessor(const Value& row)
/* use hostcheck service */
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Service::Ptr hc = host->GetCheckService();
String long_output;
if (hc) {
- String long_output;
CheckResult::Ptr cr = hc->GetLastCheckResult();
- if (cr) {
- std::pair<String, String> output_bag = CompatUtility::GetCheckResultOutput(cr);
- long_output = output_bag.second;
- }
+ if (cr)
+ long_output = CompatUtility::GetCheckResultLongOutput(cr);
}
return long_output;
/* use hostcheck service */
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Service::Ptr hc = host->GetCheckService();
if (!hc)
/* use hostcheck service */
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Service::Ptr hc = host->GetCheckService();
if (!hc)
return Empty;
- return (hc->GetEnableFlapping() ? 1 : 0);
+ return CompatUtility::GetServiceFlapDetectionEnabled(hc);
}
Value HostsTable::AcceptPassiveChecksAccessor(const Value& row)
/* use hostcheck service */
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Service::Ptr hc = host->GetCheckService();
if (!hc)
return Empty;
- return (hc->GetEnablePassiveChecks() ? 1 : 0);
+ return CompatUtility::GetServicePassiveChecksEnabled(hc);
}
Value HostsTable::EventHandlerEnabledAccessor(const Value& row)
/* use hostcheck service */
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Service::Ptr hc = host->GetCheckService();
if (!hc)
return Empty;
- EventCommand::Ptr eventcommand = hc->GetEventCommand();
- if (eventcommand)
- return 1;
-
- return 0;
+ return CompatUtility::GetServiceEventHandlerEnabled(hc);
}
Value HostsTable::AcknowledgementTypeAccessor(const Value& row)
/* use hostcheck service */
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Service::Ptr hc = host->GetCheckService();
if (!hc)
return Empty;
- /* important: lock acknowledgements */
- ObjectLock olock(hc);
-
- return static_cast<int>(hc->GetAcknowledgement());
+ return CompatUtility::GetServiceAcknowledgementType(hc);
}
Value HostsTable::CheckTypeAccessor(const Value& row)
/* use hostcheck service */
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Service::Ptr hc = host->GetCheckService();
if (!hc)
return Empty;
- return (hc->GetEnableActiveChecks() ? 0 : 1);
+ return CompatUtility::GetServiceCheckType(hc);
}
Value HostsTable::LastStateAccessor(const Value& row)
{
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
return host->GetLastState();
}
{
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
return host->GetLastHardState();
}
/* use hostcheck service */
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Service::Ptr hc = host->GetCheckService();
if (!hc)
/* use hostcheck service */
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Service::Ptr hc = host->GetCheckService();
if (!hc)
return Empty;
- /* XXX Service -> Notifications, latest wins */
- double last_notification = 0;
- BOOST_FOREACH(const Notification::Ptr& notification, hc->GetNotifications()) {
- if (notification->GetLastNotification() > last_notification)
- last_notification = notification->GetLastNotification();
- }
-
- return static_cast<int>(last_notification);
+ return CompatUtility::GetServiceNotificationLastNotification(hc);
}
Value HostsTable::NextNotificationAccessor(const Value& row)
/* use hostcheck service */
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Service::Ptr hc = host->GetCheckService();
if (!hc)
return Empty;
- /* XXX Service -> Notifications, latest wins */
- double next_notification = 0;
- BOOST_FOREACH(const Notification::Ptr& notification, hc->GetNotifications()) {
- if (notification->GetNextNotification() < next_notification)
- next_notification = notification->GetNextNotification();
- }
-
- return static_cast<int>(next_notification);
+ return CompatUtility::GetServiceNotificationNextNotification(hc);
}
Value HostsTable::NextCheckAccessor(const Value& row)
/* use hostcheck service */
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Service::Ptr hc = host->GetCheckService();
if (!hc)
/* use hostcheck service */
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Service::Ptr hc = host->GetCheckService();
if (!hc)
/* use hostcheck service */
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Service::Ptr hc = host->GetCheckService();
if (!hc)
return Empty;
- return (hc->HasBeenChecked() ? 1 : 0);
+ return CompatUtility::GetServiceHasBeenChecked(hc);
}
Value HostsTable::CurrentNotificationNumberAccessor(const Value& row)
/* use hostcheck service */
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Service::Ptr hc = host->GetCheckService();
if (!hc)
return Empty;
- /* XXX Service -> Notifications, biggest wins */
- int notification_number = 0;
- BOOST_FOREACH(const Notification::Ptr& notification, hc->GetNotifications()) {
- if (notification->GetNotificationNumber() > notification_number)
- notification_number = notification->GetNotificationNumber();
- }
-
- return notification_number;
-
+ return CompatUtility::GetServiceNotificationNotificationNumber(hc);
}
Value HostsTable::TotalServicesAccessor(const Value& row)
{
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
return host->GetTotalServices();
}
/* use hostcheck service */
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Service::Ptr hc = host->GetCheckService();
if (!hc)
return Empty;
- return (hc->GetEnableActiveChecks() ? 1 : 0);
+ return CompatUtility::GetServiceActiveChecksEnabled(hc);
}
Value HostsTable::NotificationsEnabledAccessor(const Value& row)
/* use hostcheck service */
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Service::Ptr hc = host->GetCheckService();
if (!hc)
return Empty;
- return (hc->GetEnableNotifications() ? 1 : 0);
+ return CompatUtility::GetServiceNotificationsEnabled(hc);
}
Value HostsTable::AcknowledgedAccessor(const Value& row)
/* use hostcheck service */
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Service::Ptr hc = host->GetCheckService();
if (!hc)
return Empty;
- /* important: lock acknowledgements */
- ObjectLock olock(hc);
-
- return (hc->IsAcknowledged() ? 1 : 0);
+ return CompatUtility::GetServiceIsAcknowledged(hc);
}
Value HostsTable::StateAccessor(const Value& row)
/* use hostcheck service */
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
return host->GetState();
}
/* use hostcheck service */
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
return host->GetStateType();
}
/* use hostcheck service */
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Service::Ptr hc = host->GetCheckService();
if (!hc)
return Empty;
- /* XXX take the smallest notification_interval */
- double notification_interval = -1;
- BOOST_FOREACH(const Notification::Ptr& notification, hc->GetNotifications()) {
- if (notification_interval == -1 || notification->GetNotificationInterval() < notification_interval)
- notification_interval = notification->GetNotificationInterval();
- }
-
- if (notification_interval == 0 && !hc->GetVolatile())
- return 1;
-
- return 0;
+ return CompatUtility::GetServiceNoMoreNotifications(hc);
}
Value HostsTable::LastCheckAccessor(const Value& row)
/* use hostcheck service */
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Service::Ptr hc = host->GetCheckService();
if (!hc)
/* use hostcheck service */
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
return static_cast<int>(host->GetLastStateChange());
}
/* use hostcheck service */
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
return static_cast<int>(host->GetLastStateUp());
}
/* use hostcheck service */
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
return static_cast<int>(host->GetLastStateDown());
}
/* use hostcheck service */
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
return static_cast<int>(host->GetLastStateUnreachable());
}
/* use hostcheck service */
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Service::Ptr hc = host->GetCheckService();
if (!hc)
/* use hostcheck service */
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Service::Ptr hc = host->GetCheckService();
if (!hc)
/* use hostcheck service */
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Service::Ptr hc = host->GetCheckService();
if (!hc)
return Empty;
- return (hc->GetEnableActiveChecks() ? 1 : 0);
+ return CompatUtility::GetServiceActiveChecksEnabled(hc);
}
Value HostsTable::CheckOptionsAccessor(const Value& row)
/* use hostcheck service */
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Service::Ptr hc = host->GetCheckService();
if (!hc)
/* use hostcheck service */
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Service::Ptr hc = host->GetCheckService();
if (!hc)
return Empty;
- return (hc->GetCheckInterval() / 60.0);
+ return CompatUtility::GetServiceCheckInterval(hc);
}
Value HostsTable::RetryIntervalAccessor(const Value& row)
/* use hostcheck service */
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Service::Ptr hc = host->GetCheckService();
if (!hc)
return Empty;
- return (hc->GetRetryInterval() / 60.0);
+ return CompatUtility::GetServiceRetryInterval(hc);
}
Value HostsTable::NotificationIntervalAccessor(const Value& row)
/* use hostcheck service */
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Service::Ptr hc = host->GetCheckService();
if (!hc)
return Empty;
- /* XXX take the smallest notification_interval */
- double notification_interval = -1;
- BOOST_FOREACH(const Notification::Ptr& notification, hc->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);
+ return CompatUtility::GetServiceNotificationNotificationInterval(hc);
}
Value HostsTable::LowFlapThresholdAccessor(const Value& row)
/* use hostcheck service */
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Service::Ptr hc = host->GetCheckService();
if (!hc)
return Empty;
- return hc->GetFlappingThreshold();
+ return CompatUtility::GetServiceLowFlapThreshold(hc);
}
Value HostsTable::HighFlapThresholdAccessor(const Value& row)
/* use hostcheck service */
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Service::Ptr hc = host->GetCheckService();
if (!hc)
return Empty;
- return hc->GetFlappingThreshold();
+ return CompatUtility::GetServiceHighFlapThreshold(hc);
}
Value HostsTable::X2dAccessor(const Value& row)
{
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Dictionary::Ptr custom = host->GetCustom();
if (!custom)
{
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Dictionary::Ptr custom = host->GetCustom();
if (!custom)
/* use hostcheck service */
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Service::Ptr hc = host->GetCheckService();
if (!hc)
/* use hostcheck service */
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Service::Ptr hc = host->GetCheckService();
if (!hc)
/* use hostcheck service */
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Service::Ptr hc = host->GetCheckService();
if (!hc)
return Empty;
- return hc->GetFlappingCurrent();
+ return CompatUtility::GetServicePercentStateChange(hc);
}
Value HostsTable::InNotificationPeriodAccessor(const Value& row)
/* use hostcheck service */
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Service::Ptr hc = host->GetCheckService();
if (!hc)
return Empty;
- BOOST_FOREACH(const Notification::Ptr& notification, hc->GetNotifications()) {
- ObjectLock olock(notification);
-
- TimePeriod::Ptr timeperiod = notification->GetNotificationPeriod();
-
- /* XXX first notification wins */
- if (timeperiod)
- return (timeperiod->IsInside(Utility::GetTime()) ? 1 : 0);
- }
-
- /* none set means always notified */
- return 1;
+ return CompatUtility::GetServiceInNotificationPeriod(hc);
}
Value HostsTable::InCheckPeriodAccessor(const Value& row)
/* use hostcheck service */
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Service::Ptr hc = host->GetCheckService();
if (!hc)
return Empty;
- TimePeriod::Ptr timeperiod = hc->GetCheckPeriod();
-
- /* none set means always checked */
- if (!timeperiod)
- return 1;
-
- return (timeperiod->IsInside(Utility::GetTime()) ? 1 : 0);
+ return CompatUtility::GetServiceInCheckPeriod(hc);
}
Value HostsTable::ContactsAccessor(const Value& row)
/* use hostcheck service */
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Service::Ptr hc = host->GetCheckService();
if (!hc)
/* use hostcheck service */
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Service::Ptr hc = host->GetCheckService();
if (!hc)
/* use hostcheck service */
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Service::Ptr hc = host->GetCheckService();
if (!hc)
/* use hostcheck service */
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Service::Ptr hc = host->GetCheckService();
if (!hc)
/* use hostcheck service */
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Service::Ptr hc = host->GetCheckService();
if (!hc)
/* use hostcheck service */
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Service::Ptr hc = host->GetCheckService();
if (!hc)
{
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Dictionary::Ptr customvars;
{
{
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Dictionary::Ptr customvars;
{
{
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Dictionary::Ptr customvars;
{
{
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Array::Ptr parents = make_shared<Array>();
BOOST_FOREACH(const Host::Ptr& parent, host->GetParentHosts()) {
{
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Array::Ptr childs = make_shared<Array>();
BOOST_FOREACH(const Host::Ptr& child, host->GetChildHosts()) {
/* duplicate of TotalServices */
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
return host->GetTotalServices();
}
{
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Value worst_service = StateOK;
BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
{
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
int num_services = 0;
BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
{
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
int num_services = 0;
BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
{
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
int num_services = 0;
BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
{
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
int num_services = 0;
BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
{
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
int num_services = 0;
BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
{
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Value worst_service = StateOK;
BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
{
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
int num_services = 0;
BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
{
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
int num_services = 0;
BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
{
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
int num_services = 0;
BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
{
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
int num_services = 0;
BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
/* use hostcheck service */
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Service::Ptr hc = host->GetCheckService();
if (!hc)
/* use hostcheck service */
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Service::Ptr hc = host->GetCheckService();
if (!hc)
return Empty;
- if (hc->HasBeenChecked() && hc->GetLastCheck() > 0)
- return (Utility::GetTime() - hc->GetLastCheck()) / (hc->GetCheckInterval() * 3600);
-
- return Empty;
+ return CompatUtility::GetServiceStaleness(hc);
}
Value HostsTable::GroupsAccessor(const Value& row)
{
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Array::Ptr groups = host->GetGroups();
if (!groups)
/* use hostcheck service */
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Service::Ptr hc = host->GetCheckService();
if (!hc)
{
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Array::Ptr services = make_shared<Array>();
BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
{
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Array::Ptr services = make_shared<Array>();
BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
{
Host::Ptr host = static_cast<Host::Ptr>(row);
+ if (!host)
+ return Empty;
+
Array::Ptr services = make_shared<Array>();
BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
String output;
CheckResult::Ptr cr = service->GetLastCheckResult();
- if (cr) {
- std::pair<String, String> output_bag = CompatUtility::GetCheckResultOutput(cr);
- output = output_bag.first;
- }
+ if (cr)
+ output = CompatUtility::GetCheckResultOutput(cr);
svc_add->Add(output);
services->Add(svc_add);
String output;
CheckResult::Ptr cr = service->GetLastCheckResult();
- if (cr) {
- std::pair<String, String> output_bag = CompatUtility::GetCheckResultOutput(cr);
- output = output_bag.first;
- }
+ if (cr)
+ output = CompatUtility::GetCheckResultOutput(cr);
return output;
}
String long_output;
CheckResult::Ptr cr = service->GetLastCheckResult();
- if (cr) {
- std::pair<String, String> output_bag = CompatUtility::GetCheckResultOutput(cr);
- long_output = output_bag.second;
- }
+ if (cr)
+ long_output = CompatUtility::GetCheckResultLongOutput(cr);
return long_output;
}
if (!service)
return Empty;
- BOOST_FOREACH(const Notification::Ptr& notification, service->GetNotifications()) {
- ObjectLock olock(notification);
-
- TimePeriod::Ptr timeperiod = notification->GetNotificationPeriod();
-
- /* XXX first notification wins */
- if (timeperiod)
- return timeperiod->GetName();
- }
-
- return Empty;
+ return CompatUtility::GetServiceNotificationNotificationPeriod(service);
}
Value ServicesTable::CheckPeriodAccessor(const Value& row)
if (!service)
return Empty;
- TimePeriod::Ptr timeperiod = service->GetCheckPeriod();
-
- if (!timeperiod)
- return Empty;
-
- return timeperiod->GetName();
+ return CompatUtility::GetServiceCheckPeriod(service);
}
Value ServicesTable::NotesAccessor(const Value& row)
if (!service)
return Empty;
- Dictionary::Ptr custom = service->GetCustom();
-
- if (!custom)
- return Empty;
-
- return custom->Get("notes");
+ return CompatUtility::GetCustomAttributeConfig(service, "notes");
}
Value ServicesTable::NotesExpandedAccessor(const Value& row)
if (!service)
return Empty;
- 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");
+ Value value = CompatUtility::GetCustomAttributeConfig(service, "notes");
return MacroProcessor::ResolveMacros(value, resolvers, CheckResult::Ptr(), Utility::EscapeShellCmd);
}
if (!service)
return Empty;
- Dictionary::Ptr custom = service->GetCustom();
-
- if (!custom)
- return Empty;
-
- return custom->Get("notes_url");
+ return CompatUtility::GetCustomAttributeConfig(service, "notes_url");
}
Value ServicesTable::NotesUrlExpandedAccessor(const Value& row)
if (!service)
return Empty;
- 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");
+ Value value = CompatUtility::GetCustomAttributeConfig(service, "notes_url");
return MacroProcessor::ResolveMacros(value, resolvers, CheckResult::Ptr(), Utility::EscapeShellCmd);
}
if (!service)
return Empty;
- Dictionary::Ptr custom = service->GetCustom();
-
- if (!custom)
- return Empty;
-
- return custom->Get("action_url");
+ return CompatUtility::GetCustomAttributeConfig(service, "action_url");
}
Value ServicesTable::ActionUrlExpandedAccessor(const Value& row)
if (!service)
return Empty;
- 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");
+ Value value = CompatUtility::GetCustomAttributeConfig(service, "action_url");
return MacroProcessor::ResolveMacros(value, resolvers, CheckResult::Ptr(), Utility::EscapeShellCmd);
}
if (!service)
return Empty;
- Dictionary::Ptr custom = service->GetCustom();
-
- if (!custom)
- return Empty;
-
- return custom->Get("icon_image");
+ return CompatUtility::GetCustomAttributeConfig(service, "icon_image");
}
Value ServicesTable::IconImageExpandedAccessor(const Value& row)
if (!service)
return Empty;
- 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");
+ Value value = CompatUtility::GetCustomAttributeConfig(service, "icon_image");
return MacroProcessor::ResolveMacros(value, resolvers, CheckResult::Ptr(), Utility::EscapeShellCmd);
}
if (!service)
return Empty;
- Dictionary::Ptr custom = service->GetCustom();
-
- if (!custom)
- return Empty;
-
- return custom->Get("icon_image_alt");
+ return CompatUtility::GetCustomAttributeConfig(service, "icon_image_alt");
}
Value ServicesTable::MaxCheckAttemptsAccessor(const Value& row)
if (!service)
return Empty;
- return service->GetState();
+ return CompatUtility::GetServiceCurrentState(service);
}
Value ServicesTable::HasBeenCheckedAccessor(const Value& row)
if (!service)
return Empty;
- return (service->HasBeenChecked() ? 1 : 0);
+ return CompatUtility::GetServiceHasBeenChecked(service);
}
Value ServicesTable::LastStateAccessor(const Value& row)
if (!service)
return Empty;
- return (service->GetEnableActiveChecks() ? 0 : 1);
+ return CompatUtility::GetServiceCheckType(service);
}
Value ServicesTable::AcknowledgedAccessor(const Value& row)
if (!service)
return Empty;
- /* important: lock acknowledgements */
- ObjectLock olock(service);
- return (service->IsAcknowledged() ? 1 : 0);
+ return CompatUtility::GetServiceIsAcknowledged(service);
}
Value ServicesTable::AcknowledgementTypeAccessor(const Value& row)
if (!service)
return Empty;
- /* 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->GetVolatile())
- return 1;
-
- return 0;
+ return CompatUtility::GetServiceNoMoreNotifications(service);
}
Value ServicesTable::LastTimeOkAccessor(const Value& row)
if (!service)
return Empty;
- /* 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);
+ return CompatUtility::GetServiceNotificationLastNotification(service);
}
Value ServicesTable::NextNotificationAccessor(const Value& row)
if (!service)
return Empty;
- /* 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);
+ return CompatUtility::GetServiceNotificationNextNotification(service);
}
Value ServicesTable::CurrentNotificationNumberAccessor(const Value& row)
if (!service)
return Empty;
- /* 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;
+ return CompatUtility::GetServiceNotificationNotificationNumber(service);
}
Value ServicesTable::LastStateChangeAccessor(const Value& row)
if (!service)
return Empty;
- return (service->GetEnableActiveChecks() ? 1 : 0);
+ return CompatUtility::GetServiceActiveChecksEnabled(service);
}
Value ServicesTable::AcceptPassiveChecksAccessor(const Value& row)
if (!service)
return Empty;
- return (service->GetEnablePassiveChecks() ? 1 : 0);
+ return CompatUtility::GetServicePassiveChecksEnabled(service);
}
Value ServicesTable::EventHandlerEnabledAccessor(const Value& row)
if (!service)
return Empty;
- EventCommand::Ptr eventcommand = service->GetEventCommand();
-
- if (eventcommand)
- return 1;
-
- return 0;
+ return CompatUtility::GetServiceEventHandlerEnabled(service);
}
Value ServicesTable::NotificationsEnabledAccessor(const Value& row)
if (!service)
return Empty;
- return (service->GetEnableNotifications() ? 1 : 0);
+ return CompatUtility::GetServiceNotificationsEnabled(service);
}
Value ServicesTable::ActiveChecksEnabledAccessor(const Value& row)
if (!service)
return Empty;
- return (service->GetEnableActiveChecks() ? 1 : 0);
+ return CompatUtility::GetServiceActiveChecksEnabled(service);
}
Value ServicesTable::CheckOptionsAccessor(const Value& row)
if (!service)
return Empty;
- return (service->GetEnableFlapping() ? 1 : 0);
+ return CompatUtility::GetServiceFlapDetectionEnabled(service);
}
Value ServicesTable::CheckFreshnessAccessor(const Value& row)
{
- /* always enabled */
- return 1;
+ Service::Ptr service = static_cast<Service::Ptr>(row);
+
+ if (!service)
+ return Empty;
+
+ return CompatUtility::GetServiceFreshnessChecksEnabled(service);
}
Value ServicesTable::ModifiedAttributesAccessor(const Value& row)
if (!service)
return Empty;
- if (service->HasBeenChecked() && service->GetLastCheck() > 0)
- return (Utility::GetTime() - service->GetLastCheck()) / (service->GetCheckInterval() * 3600);
-
- return Empty;
+ return CompatUtility::GetServiceStaleness(service);
}
Value ServicesTable::CheckIntervalAccessor(const Value& row)
if (!service)
return Empty;
- return (service->GetCheckInterval() / 60.0);
+ return CompatUtility::GetServiceCheckInterval(service);
}
Value ServicesTable::RetryIntervalAccessor(const Value& row)
if (!service)
return Empty;
- return (service->GetRetryInterval() / 60.0);
+ return CompatUtility::GetServiceRetryInterval(service);
}
Value ServicesTable::NotificationIntervalAccessor(const Value& row)
if (!service)
return Empty;
- /* 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);
+ return CompatUtility::GetServiceNotificationNotificationInterval(service);
}
Value ServicesTable::LowFlapThresholdAccessor(const Value& row)
if (!service)
return Empty;
- return service->GetFlappingThreshold();
+ return CompatUtility::GetServiceLowFlapThreshold(service);
}
Value ServicesTable::HighFlapThresholdAccessor(const Value& row)
if (!service)
return Empty;
- return service->GetFlappingThreshold();
+ return CompatUtility::GetServiceHighFlapThreshold(service);
}
Value ServicesTable::LatencyAccessor(const Value& row)
if (!service)
return Empty;
- return service->GetFlappingCurrent();
+ return CompatUtility::GetServicePercentStateChange(service);
}
Value ServicesTable::InCheckPeriodAccessor(const Value& row)
if (!service)
return Empty;
- TimePeriod::Ptr timeperiod = service->GetCheckPeriod();
-
- /* none set means always checked */
- if (!timeperiod)
- return 1;
-
- return (timeperiod->IsInside(Utility::GetTime()) ? 1 : 0);
+ return CompatUtility::GetServiceInCheckPeriod(service);
}
Value ServicesTable::InNotificationPeriodAccessor(const Value& row)
if (!service)
return Empty;
- BOOST_FOREACH(const Notification::Ptr& notification, service->GetNotifications()) {
- ObjectLock olock(notification);
-
- TimePeriod::Ptr timeperiod = notification->GetNotificationPeriod();
-
- /* XXX first notification wins */
- if (timeperiod)
- return (timeperiod->IsInside(Utility::GetTime()) ? 1 : 0);
- }
-
- /* none set means always notified */
- return 1;
+ return CompatUtility::GetServiceInNotificationPeriod(service);
}
Value ServicesTable::ContactsAccessor(const Value& row)
Dictionary::Ptr fields = make_shared<Dictionary>();
Command::Ptr command = static_pointer_cast<Command>(GetObject());
- Dictionary::Ptr attrs;
-
- attrs = CompatUtility::GetCommandConfigAttributes(command);
-
- fields->Set("command_line", attrs->Get("command_line"));
+ fields->Set("command_line", CompatUtility::GetCommandLine(command));
return fields;
}
Service::Ptr service = host->GetCheckService();
- Dictionary::Ptr attrs;
-
- {
- ObjectLock olock(host);
- attrs = CompatUtility::GetHostConfigAttributes(host);
- }
-
- fields->Set("alias", attrs->Get("alias"));
+ fields->Set("alias", CompatUtility::GetHostAlias(host));
fields->Set("display_name", host->GetDisplayName());
-
- fields->Set("address", attrs->Get("address"));
- fields->Set("address6", attrs->Get("address6"));
+ fields->Set("address", CompatUtility::GetHostAddress(host));
+ fields->Set("address6", CompatUtility::GetHostAddress6(host));
if (service) {
fields->Set("check_command_object_id", service->GetCheckCommand());
fields->Set("check_command_args", Empty);
fields->Set("eventhandler_command_object_id", service->GetEventCommand());
fields->Set("eventhandler_command_args", Empty);
+ fields->Set("notification_timeperiod_object_id", Notification::GetByName(CompatUtility::GetServiceNotificationNotificationPeriod(service)));
+ fields->Set("check_timeperiod_object_id", service->GetCheckPeriod());
+ fields->Set("failure_prediction_options", Empty);
+ fields->Set("check_interval", CompatUtility::GetServiceCheckInterval(service));
+ fields->Set("retry_interval", CompatUtility::GetServiceRetryInterval(service));
+ fields->Set("max_check_attempts", service->GetMaxCheckAttempts());
+
+ fields->Set("first_notification_delay", Empty);
+
+ fields->Set("notification_interval", CompatUtility::GetServiceNotificationNotificationInterval(service));
+ /* requires host check service */
+ fields->Set("notify_on_down", CompatUtility::GetHostNotifyOnDown(host));
+ fields->Set("notify_on_unreachable", CompatUtility::GetHostNotifyOnDown(host));
+
+ fields->Set("notify_on_recovery", CompatUtility::GetServiceNotifyOnRecovery(service));
+ fields->Set("notify_on_flapping", CompatUtility::GetServiceNotifyOnFlapping(service));
+ fields->Set("notify_on_downtime", CompatUtility::GetServiceNotifyOnDowntime(service));
+
+ fields->Set("stalk_on_up", Empty);
+ fields->Set("stalk_on_down", Empty);
+ fields->Set("stalk_on_unreachable", Empty);
+
+ fields->Set("flap_detection_enabled", CompatUtility::GetServiceFlapDetectionEnabled(service));
+ fields->Set("flap_detection_on_up", Empty);
+ fields->Set("flap_detection_on_down", Empty);
+ fields->Set("flap_detection_on_unreachable", Empty);
+ fields->Set("low_flap_threshold", CompatUtility::GetServiceLowFlapThreshold(service));
+ fields->Set("high_flap_threshold", CompatUtility::GetServiceHighFlapThreshold(service));
}
- fields->Set("notification_timeperiod_object_id", Notification::GetByName(attrs->Get("notification_period")));
+ fields->Set("process_performance_data", 0);
- if (service)
- fields->Set("check_timeperiod_object_id", service->GetCheckPeriod());
+ if (service) {
+ fields->Set("freshness_checks_enabled", CompatUtility::GetServiceFreshnessChecksEnabled(service));
+ fields->Set("freshness_threshold", CompatUtility::GetServiceFreshnessThreshold(service));
+ fields->Set("passive_checks_enabled", CompatUtility::GetServicePassiveChecksEnabled(service));
+ fields->Set("event_handler_enabled", CompatUtility::GetServiceEventHandlerEnabled(service));
+ fields->Set("active_checks_enabled", CompatUtility::GetServiceActiveChecksEnabled(service));
+ }
- fields->Set("failure_prediction_options", Empty);
-
- fields->Set("check_interval", attrs->Get("check_interval"));
- fields->Set("retry_interval", attrs->Get("retry_interval"));
- fields->Set("max_check_attempts", attrs->Get("max_check_attempts"));
-
- fields->Set("first_notification_delay", Empty);
- fields->Set("notification_interval", attrs->Get("notification_interval"));
- fields->Set("notify_on_down", attrs->Get("notify_on_down"));
- fields->Set("notify_on_unreachable", attrs->Get("notify_on_unreachable"));
- fields->Set("notify_on_recovery", attrs->Get("notify_on_recovery"));
- fields->Set("notify_on_flapping", attrs->Get("notify_on_flapping"));
- fields->Set("notify_on_downtime", attrs->Get("notify_on_downtime"));
-
- fields->Set("stalk_on_up", Empty);
- fields->Set("stalk_on_down", Empty);
- fields->Set("stalk_on_unreachable", Empty);
-
- fields->Set("flap_detection_enabled", attrs->Get("flap_detection_enabled"));
- fields->Set("flap_detection_on_up", Empty);
- fields->Set("flap_detection_on_down", Empty);
- fields->Set("flap_detection_on_unreachable", Empty);
- fields->Set("low_flap_threshold", attrs->Get("low_flap_threshold"));
- fields->Set("high_flap_threshold", attrs->Get("high_flap_threshold"));
- fields->Set("process_performance_data", attrs->Get("process_performance_data"));
- fields->Set("freshness_checks_enabled", attrs->Get("check_freshness"));
- fields->Set("freshness_threshold", Empty);
- fields->Set("passive_checks_enabled", attrs->Get("passive_checks_enabled"));
- fields->Set("event_handler_enabled", attrs->Get("event_handler_enabled"));
- fields->Set("active_checks_enabled", attrs->Get("active_checks_enabled"));
fields->Set("retain_status_information", 1);
fields->Set("retain_nonstatus_information", 1);
- fields->Set("notifications_enabled", attrs->Get("notifications_enabled"));
+
+ if (service)
+ fields->Set("notifications_enabled", CompatUtility::GetServiceNotificationsEnabled(service));
+
fields->Set("obsess_over_host", 0);
fields->Set("failure_prediction_enabled", 0);
- fields->Set("notes", attrs->Get("notes"));
- fields->Set("notes_url", attrs->Get("notes_url"));
- fields->Set("action_url", attrs->Get("action_url"));
- fields->Set("icon_image", attrs->Get("icon_image"));
- fields->Set("icon_image_alt", attrs->Get("icon_image_alt"));
- fields->Set("statusmap_image", attrs->Get("statusmap_image"));
- fields->Set("have_2d_coords", attrs->Get("have_2d_coords"));
- fields->Set("x_2d", attrs->Get("x_2d"));
- fields->Set("y_2d", attrs->Get("y_2d"));
+ fields->Set("notes", CompatUtility::GetCustomAttributeConfig(host, "notes"));
+ fields->Set("notes_url", CompatUtility::GetCustomAttributeConfig(host, "notes_url"));
+ fields->Set("action_url", CompatUtility::GetCustomAttributeConfig(host, "action_url"));
+ fields->Set("icon_image", CompatUtility::GetCustomAttributeConfig(host, "icon_image"));
+ fields->Set("icon_image_alt", CompatUtility::GetCustomAttributeConfig(host, "icon_image_alt"));
+ fields->Set("statusmap_image", CompatUtility::GetCustomAttributeConfig(host, "statusmap_image"));
+
+ Host2dCoords coords = CompatUtility::GetHost2dCoords(host);
+
+ fields->Set("have_2d_coords", coords.have_2d_coords);
+
+ if (coords.have_2d_coords) {
+ fields->Set("x_2d", coords.x_2d);
+ fields->Set("y_2d", coords.y_2d);
+ }
+
/* deprecated in 1.x */
fields->Set("have_3d_coords", 0);
Host::Ptr host = static_pointer_cast<Host>(GetObject());
Service::Ptr service = host->GetCheckService();
- Dictionary::Ptr attrs;
-
/* fetch service status, or dump a pending hoststatus */
if (service) {
- ObjectLock olock(service);
- attrs = CompatUtility::GetServiceStatusAttributes(service, CompatTypeHost);
-
- fields->Set("output", attrs->Get("plugin_output"));
- fields->Set("long_output", attrs->Get("long_plugin_output"));
- fields->Set("perfdata", attrs->Get("performance_data"));
- fields->Set("check_source", attrs->Get("check_source"));
- fields->Set("current_state", attrs->Get("current_state"));
- fields->Set("has_been_checked", attrs->Get("has_been_checked"));
- fields->Set("should_be_scheduled", attrs->Get("should_be_scheduled"));
- fields->Set("current_check_attempt", attrs->Get("current_attempt"));
- fields->Set("max_check_attempts", attrs->Get("max_attempts"));
- fields->Set("last_check", DbValue::FromTimestamp(attrs->Get("last_check")));
- fields->Set("next_check", DbValue::FromTimestamp(attrs->Get("next_check")));
- fields->Set("check_type", attrs->Get("check_type"));
- fields->Set("last_state_change", DbValue::FromTimestamp(attrs->Get("last_state_change")));
- fields->Set("last_hard_state_change", DbValue::FromTimestamp(attrs->Get("last_hard_state_change")));
- fields->Set("last_time_up", DbValue::FromTimestamp(attrs->Get("last_time_up")));
- fields->Set("last_time_down", DbValue::FromTimestamp(attrs->Get("last_time_down")));
- fields->Set("last_time_unreachable", DbValue::FromTimestamp(attrs->Get("last_time_unreachable")));
- fields->Set("state_type", attrs->Get("state_type"));
- fields->Set("last_notification", DbValue::FromTimestamp(attrs->Get("last_notification")));
- fields->Set("next_notification", DbValue::FromTimestamp(attrs->Get("next_notification")));
+ CheckResult::Ptr cr = service->GetLastCheckResult();
+
+ if (cr) {
+ fields->Set("output", CompatUtility::GetCheckResultOutput(cr));
+ fields->Set("long_output", CompatUtility::GetCheckResultLongOutput(cr));
+ fields->Set("perfdata", CompatUtility::GetCheckResultPerfdata(cr));
+ fields->Set("check_source", cr->GetCheckSource());
+ }
+
+ fields->Set("current_state", host->GetState());
+ fields->Set("has_been_checked", CompatUtility::GetServiceHasBeenChecked(service));
+ fields->Set("should_be_scheduled", CompatUtility::GetServiceShouldBeScheduled(service));
+ fields->Set("current_check_attempt", service->GetCheckAttempt());
+ fields->Set("max_check_attempts", service->GetMaxCheckAttempts());
+
+ if (cr)
+ fields->Set("last_check", DbValue::FromTimestamp(cr->GetScheduleEnd()));
+
+ fields->Set("next_check", DbValue::FromTimestamp(service->GetNextCheck()));
+ fields->Set("check_type", CompatUtility::GetServiceCheckType(service));
+ fields->Set("last_state_change", DbValue::FromTimestamp(service->GetLastStateChange()));
+ fields->Set("last_hard_state_change", DbValue::FromTimestamp(service->GetLastHardStateChange()));
+ fields->Set("last_time_up", DbValue::FromTimestamp(static_cast<int>(host->GetLastStateUp())));
+ fields->Set("last_time_down", DbValue::FromTimestamp(static_cast<int>(host->GetLastStateDown())));
+ fields->Set("last_time_unreachable", DbValue::FromTimestamp(static_cast<int>(host->GetLastStateUnreachable())));
+ fields->Set("state_type", service->GetStateType());
+ fields->Set("last_notification", DbValue::FromTimestamp(CompatUtility::GetServiceNotificationLastNotification(service)));
+ fields->Set("next_notification", DbValue::FromTimestamp(CompatUtility::GetServiceNotificationNextNotification(service)));
fields->Set("no_more_notifications", Empty);
- fields->Set("notifications_enabled", attrs->Get("notifications_enabled"));
- fields->Set("problem_has_been_acknowledged", attrs->Get("problem_has_been_acknowledged"));
- fields->Set("acknowledgement_type", attrs->Get("acknowledgement_type"));
- fields->Set("current_notification_number", attrs->Get("current_notification_number"));
- fields->Set("passive_checks_enabled", attrs->Get("passive_checks_enabled"));
- fields->Set("active_checks_enabled", attrs->Get("active_checks_enabled"));
- fields->Set("eventhandler_enabled", attrs->Get("eventhandler_enabled"));
- fields->Set("flap_detection_enabled", attrs->Get("flap_detection_enabled"));
- fields->Set("is_flapping", attrs->Get("is_flapping"));
- fields->Set("percent_state_change", attrs->Get("percent_state_change"));
- fields->Set("latency", attrs->Get("check_latency"));
- fields->Set("execution_time", attrs->Get("check_execution_time"));
- fields->Set("scheduled_downtime_depth", attrs->Get("scheduled_downtime_depth"));
+ fields->Set("notifications_enabled", CompatUtility::GetServiceNotificationsEnabled(service));
+ fields->Set("problem_has_been_acknowledged", CompatUtility::GetServiceProblemHasBeenAcknowledged(service));
+ fields->Set("acknowledgement_type", CompatUtility::GetServiceAcknowledgementType(service));
+ fields->Set("current_notification_number", CompatUtility::GetServiceNotificationNotificationNumber(service));
+ fields->Set("passive_checks_enabled", CompatUtility::GetServicePassiveChecksEnabled(service));
+ fields->Set("active_checks_enabled", CompatUtility::GetServiceActiveChecksEnabled(service));
+ fields->Set("event_handler_enabled", CompatUtility::GetServiceEventHandlerEnabled(service));
+ fields->Set("flap_detection_enabled", CompatUtility::GetServiceFlapDetectionEnabled(service));
+ fields->Set("is_flapping", CompatUtility::GetServiceIsFlapping(service));
+ fields->Set("percent_state_change", CompatUtility::GetServicePercentStateChange(service));
+
+ if (cr) {
+ fields->Set("latency", Service::CalculateLatency(cr));
+ fields->Set("execution_time", Service::CalculateExecutionTime(cr));
+ }
+ fields->Set("scheduled_downtime_depth", service->GetDowntimeDepth());
fields->Set("failure_prediction_enabled", Empty);
- fields->Set("process_performance_data", attrs->Get("process_performance_data"));
+ fields->Set("process_performance_data", 0); /* this is a host which does not process any perf data */
fields->Set("obsess_over_host", Empty);
- fields->Set("modified_host_attributes", attrs->Get("modified_attributes"));
- fields->Set("event_handler", attrs->Get("event_handler"));
- fields->Set("check_command", attrs->Get("check_command"));
- fields->Set("normal_check_interval", attrs->Get("check_interval"));
- fields->Set("retry_check_interval", attrs->Get("retry_interval"));
+ fields->Set("modified_host_attributes", service->GetModifiedAttributes());
+ fields->Set("event_handler", CompatUtility::GetServiceEventHandler(service));
+ fields->Set("check_command", CompatUtility::GetServiceCheckCommand(service));
+ fields->Set("normal_check_interval", CompatUtility::GetServiceCheckInterval(service));
+ fields->Set("retry_check_interval", CompatUtility::GetServiceRetryInterval(service));
fields->Set("check_timeperiod_object_id", service->GetCheckPeriod());
}
else {
{
Dictionary::Ptr fields = make_shared<Dictionary>();
Service::Ptr service = static_pointer_cast<Service>(GetObject());
-
Host::Ptr host = service->GetHost();
- Dictionary::Ptr attrs;
-
- {
- ObjectLock olock(service);
- attrs = CompatUtility::GetServiceConfigAttributes(service);
- }
-
fields->Set("host_object_id", host);
fields->Set("display_name", service->GetDisplayName());
fields->Set("check_command_object_id", service->GetCheckCommand());
fields->Set("check_command_args", Empty);
fields->Set("eventhandler_command_object_id", service->GetEventCommand());
fields->Set("eventhandler_command_args", Empty);
- fields->Set("notification_timeperiod_object_id", Notification::GetByName(attrs->Get("notification_period")));
+ fields->Set("notification_timeperiod_object_id", Notification::GetByName(CompatUtility::GetServiceNotificationNotificationPeriod(service)));
fields->Set("check_timeperiod_object_id", service->GetCheckPeriod());
fields->Set("failure_prediction_options", Empty);
- fields->Set("check_interval", attrs->Get("check_interval"));
- fields->Set("retry_interval", attrs->Get("retry_interval"));
- fields->Set("max_check_attempts", attrs->Get("max_check_attempts"));
+ fields->Set("check_interval", CompatUtility::GetServiceCheckInterval(service));
+ fields->Set("retry_interval", CompatUtility::GetServiceRetryInterval(service));
+ fields->Set("max_check_attempts", service->GetMaxCheckAttempts());
fields->Set("first_notification_delay", Empty);
- fields->Set("notification_interval", attrs->Get("notification_interval"));
- fields->Set("notify_on_warning", attrs->Get("notify_on_warning"));
- fields->Set("notify_on_unknown", attrs->Get("notify_on_unknown"));
- fields->Set("notify_on_critical", attrs->Get("notify_on_critical"));
- fields->Set("notify_on_recovery", attrs->Get("notify_on_recovery"));
- fields->Set("notify_on_flapping", attrs->Get("notify_on_flapping"));
- fields->Set("notify_on_downtime", attrs->Get("notify_on_downtime"));
+ fields->Set("notification_interval", CompatUtility::GetServiceNotificationNotificationInterval(service));
+ fields->Set("notify_on_warning", CompatUtility::GetServiceNotifyOnWarning(service));
+ fields->Set("notify_on_unknown", CompatUtility::GetServiceNotifyOnUnknown(service));
+ fields->Set("notify_on_critical", CompatUtility::GetServiceNotifyOnCritical(service));
+ fields->Set("notify_on_recovery", CompatUtility::GetServiceNotifyOnRecovery(service));
+ fields->Set("notify_on_flapping", CompatUtility::GetServiceNotifyOnFlapping(service));
+ fields->Set("notify_on_downtime", CompatUtility::GetServiceNotifyOnDowntime(service));
fields->Set("stalk_on_ok", 0);
fields->Set("stalk_on_warning", 0);
fields->Set("stalk_on_unknown", 0);
fields->Set("stalk_on_critical", 0);
- fields->Set("is_volatile", attrs->Get("is_volatile"));
- fields->Set("flap_detection_enabled", attrs->Get("flap_detection_enabled"));
+ fields->Set("is_volatile", CompatUtility::GetServiceIsVolatile(service));
+ fields->Set("flap_detection_enabled", CompatUtility::GetServiceFlapDetectionEnabled(service));
fields->Set("flap_detection_on_ok", Empty);
fields->Set("flap_detection_on_warning", Empty);
fields->Set("flap_detection_on_unknown", Empty);
fields->Set("flap_detection_on_critical", Empty);
- fields->Set("low_flap_threshold", attrs->Get("low_flap_threshold"));
- fields->Set("high_flap_threshold", attrs->Get("high_flap_threshold"));
- fields->Set("process_performance_data", attrs->Get("process_performance_data"));
- fields->Set("freshness_checks_enabled", attrs->Get("freshness_checks_enabled"));
- fields->Set("freshness_threshold", Empty);
- fields->Set("passive_checks_enabled", attrs->Get("passive_checks_enabled"));
- fields->Set("event_handler_enabled", attrs->Get("event_handler_enabled"));
- fields->Set("active_checks_enabled", attrs->Get("active_checks_enabled"));
+ fields->Set("low_flap_threshold", CompatUtility::GetServiceLowFlapThreshold(service));
+ fields->Set("high_flap_threshold", CompatUtility::GetServiceHighFlapThreshold(service));
+ fields->Set("process_performance_data", CompatUtility::GetServiceProcessPerformanceData(service));
+ fields->Set("freshness_checks_enabled", CompatUtility::GetServiceFreshnessChecksEnabled(service));
+ fields->Set("freshness_threshold", CompatUtility::GetServiceFreshnessThreshold(service));
+ fields->Set("passive_checks_enabled", CompatUtility::GetServicePassiveChecksEnabled(service));
+ fields->Set("event_handler_enabled", CompatUtility::GetServiceEventHandlerEnabled(service));
+ fields->Set("active_checks_enabled", CompatUtility::GetServiceActiveChecksEnabled(service));
fields->Set("retain_status_information", Empty);
fields->Set("retain_nonstatus_information", Empty);
- fields->Set("notifications_enabled", attrs->Get("notifications_enabled"));
+ fields->Set("notifications_enabled", CompatUtility::GetServiceNotificationsEnabled(service));
fields->Set("obsess_over_service", Empty);
fields->Set("failure_prediction_enabled", Empty);
- fields->Set("notes", attrs->Get("notes"));
- fields->Set("notes_url", attrs->Get("notes_url"));
- fields->Set("action_url", attrs->Get("action_url"));
- fields->Set("icon_image", attrs->Get("icon_image"));
- fields->Set("icon_image_alt", attrs->Get("icon_image_alt"));
+ fields->Set("notes", CompatUtility::GetCustomAttributeConfig(service, "notes"));
+ fields->Set("notes_url", CompatUtility::GetCustomAttributeConfig(service, "notes_url"));
+ fields->Set("action_url", CompatUtility::GetCustomAttributeConfig(service, "action_url"));
+ fields->Set("icon_image", CompatUtility::GetCustomAttributeConfig(service, "icon_image"));
+ fields->Set("icon_image_alt", CompatUtility::GetCustomAttributeConfig(service, "icon_image_alt"));
return fields;
}
{
Dictionary::Ptr fields = make_shared<Dictionary>();
Service::Ptr service = static_pointer_cast<Service>(GetObject());
- Dictionary::Ptr attrs;
+ CheckResult::Ptr cr = service->GetLastCheckResult();
- {
- ObjectLock olock(service);
- attrs = CompatUtility::GetServiceStatusAttributes(service, CompatTypeService);
+ if (cr) {
+ fields->Set("output", CompatUtility::GetCheckResultOutput(cr));
+ fields->Set("long_output", CompatUtility::GetCheckResultLongOutput(cr));
+ fields->Set("perfdata", CompatUtility::GetCheckResultPerfdata(cr));
+ fields->Set("check_source", cr->GetCheckSource());
}
- fields->Set("output", attrs->Get("plugin_output"));
- fields->Set("long_output", attrs->Get("long_plugin_output"));
- fields->Set("perfdata", attrs->Get("performance_data"));
- fields->Set("check_source", attrs->Get("check_source"));
- fields->Set("current_state", attrs->Get("current_state"));
- fields->Set("has_been_checked", attrs->Get("has_been_checked"));
- fields->Set("should_be_scheduled", attrs->Get("should_be_scheduled"));
- fields->Set("current_check_attempt", attrs->Get("current_attempt"));
- fields->Set("max_check_attempts", attrs->Get("max_attempts"));
- fields->Set("last_check", DbValue::FromTimestamp(attrs->Get("last_check")));
- fields->Set("next_check", DbValue::FromTimestamp(attrs->Get("next_check")));
- fields->Set("check_type", attrs->Get("check_type"));
- fields->Set("last_state_change", DbValue::FromTimestamp(attrs->Get("last_state_change")));
- fields->Set("last_hard_state_change", DbValue::FromTimestamp(attrs->Get("last_hard_state_change")));
- fields->Set("last_time_ok", DbValue::FromTimestamp(attrs->Get("last_time_ok")));
- fields->Set("last_time_warning", DbValue::FromTimestamp(attrs->Get("last_time_warn")));
- fields->Set("last_time_critical", DbValue::FromTimestamp(attrs->Get("last_time_critical")));
- fields->Set("last_time_unknown", DbValue::FromTimestamp(attrs->Get("last_time_unknown")));
- fields->Set("state_type", attrs->Get("state_type"));
- fields->Set("last_notification", DbValue::FromTimestamp(attrs->Get("last_notification")));
- fields->Set("next_notification", DbValue::FromTimestamp(attrs->Get("next_notification")));
+ fields->Set("current_state", CompatUtility::GetServiceCurrentState(service));
+ fields->Set("has_been_checked", CompatUtility::GetServiceHasBeenChecked(service));
+ fields->Set("should_be_scheduled", CompatUtility::GetServiceShouldBeScheduled(service));
+ fields->Set("current_check_attempt", service->GetCheckAttempt());
+ fields->Set("max_check_attempts", service->GetMaxCheckAttempts());
+
+ if (cr)
+ fields->Set("last_check", DbValue::FromTimestamp(cr->GetScheduleEnd()));
+
+ fields->Set("next_check", DbValue::FromTimestamp(service->GetNextCheck()));
+ fields->Set("check_type", CompatUtility::GetServiceCheckType(service));
+ fields->Set("last_state_change", DbValue::FromTimestamp(service->GetLastStateChange()));
+ fields->Set("last_hard_state_change", DbValue::FromTimestamp(service->GetLastHardStateChange()));
+ fields->Set("last_time_ok", DbValue::FromTimestamp(static_cast<int>(service->GetLastStateOK())));
+ fields->Set("last_time_warning", DbValue::FromTimestamp(static_cast<int>(service->GetLastStateWarning())));
+ fields->Set("last_time_critical", DbValue::FromTimestamp(static_cast<int>(service->GetLastStateCritical())));
+ fields->Set("last_time_unknown", DbValue::FromTimestamp(static_cast<int>(service->GetLastStateUnknown())));
+ fields->Set("state_type", service->GetStateType());
+ fields->Set("last_notification", DbValue::FromTimestamp(CompatUtility::GetServiceNotificationLastNotification(service)));
+ fields->Set("next_notification", DbValue::FromTimestamp(CompatUtility::GetServiceNotificationNextNotification(service)));
fields->Set("no_more_notifications", Empty);
- fields->Set("notifications_enabled", attrs->Get("notifications_enabled"));
- fields->Set("problem_has_been_acknowledged", attrs->Get("problem_has_been_acknowledged"));
- fields->Set("acknowledgement_type", attrs->Get("acknowledgement_type"));
- fields->Set("current_notification_number", attrs->Get("current_notification_number"));
- fields->Set("passive_checks_enabled", attrs->Get("passive_checks_enabled"));
- fields->Set("active_checks_enabled", attrs->Get("active_checks_enabled"));
- fields->Set("event_handler_enabled", attrs->Get("event_handler_enabled"));
- fields->Set("flap_detection_enabled", attrs->Get("flap_detection_enabled"));
- fields->Set("is_flapping", attrs->Get("is_flapping"));
- fields->Set("percent_state_change", attrs->Get("percent_state_change"));
- fields->Set("latency", attrs->Get("check_latency"));
- fields->Set("execution_time", attrs->Get("check_execution_time"));
- fields->Set("scheduled_downtime_depth", attrs->Get("scheduled_downtime_depth"));
- fields->Set("process_performance_data", attrs->Get("process_performance_data"));
- fields->Set("event_handler", attrs->Get("event_handler"));
- fields->Set("check_command", attrs->Get("check_command"));
- fields->Set("normal_check_interval", attrs->Get("check_interval"));
- fields->Set("retry_check_interval", attrs->Get("retry_interval"));
+ fields->Set("notifications_enabled", CompatUtility::GetServiceNotificationsEnabled(service));
+ fields->Set("problem_has_been_acknowledged", CompatUtility::GetServiceProblemHasBeenAcknowledged(service));
+ fields->Set("acknowledgement_type", CompatUtility::GetServiceAcknowledgementType(service));
+ fields->Set("current_notification_number", CompatUtility::GetServiceNotificationNotificationNumber(service));
+ fields->Set("passive_checks_enabled", CompatUtility::GetServicePassiveChecksEnabled(service));
+ fields->Set("active_checks_enabled", CompatUtility::GetServiceActiveChecksEnabled(service));
+ fields->Set("event_handler_enabled", CompatUtility::GetServiceEventHandlerEnabled(service));
+ fields->Set("flap_detection_enabled", CompatUtility::GetServiceFlapDetectionEnabled(service));
+ fields->Set("is_flapping", CompatUtility::GetServiceIsFlapping(service));
+ fields->Set("percent_state_change", CompatUtility::GetServicePercentStateChange(service));
+
+ if (cr) {
+ fields->Set("latency", Service::CalculateLatency(cr));
+ fields->Set("execution_time", Service::CalculateExecutionTime(cr));
+ }
+
+ fields->Set("scheduled_downtime_depth", service->GetDowntimeDepth());
+ fields->Set("process_performance_data", CompatUtility::GetServiceProcessPerformanceData(service));
+ fields->Set("event_handler", CompatUtility::GetServiceEventHandler(service));
+ fields->Set("check_command", CompatUtility::GetServiceCheckCommand(service));
+ fields->Set("normal_check_interval", CompatUtility::GetServiceCheckInterval(service));
+ fields->Set("retry_check_interval", CompatUtility::GetServiceRetryInterval(service));
fields->Set("check_timeperiod_object_id", service->GetCheckPeriod());
- fields->Set("modified_service_attributes", attrs->Get("modified_attributes"));
+ fields->Set("modified_service_attributes", service->GetModifiedAttributes());
return fields;
}
fields1->Set("entry_time_usec", time_bag.second);
fields1->Set("acknowledgement_type", type);
fields1->Set("object_id", service);
- fields1->Set("state", service->GetState());
+ fields1->Set("state", CompatUtility::GetServiceCurrentState(service));
fields1->Set("author_name", author);
fields1->Set("comment_data", comment);
fields1->Set("is_sticky", type == AcknowledgementSticky ? 1 : 0);
fields1->Set("start_time_usec", time_bag.second);
fields1->Set("end_time", DbValue::FromTimestamp(time_bag.first));
fields1->Set("end_time_usec", time_bag.second);
- fields1->Set("state", service->GetState());
+ fields1->Set("state", CompatUtility::GetServiceCurrentState(service));
if (cr) {
- std::pair<String, String> output_bag = CompatUtility::GetCheckResultOutput(cr);
- fields1->Set("output", output_bag.first);
- fields1->Set("long_output", output_bag.second);
+ fields1->Set("output", CompatUtility::GetCheckResultOutput(cr));
+ fields1->Set("long_output", CompatUtility::GetCheckResultLongOutput(cr));
}
fields1->Set("escalated", 0);
fields1->Set("state_time_usec", time_bag.second);
fields1->Set("object_id", service);
fields1->Set("state_change", 1); /* service */
- fields1->Set("state", service->GetState());
+ fields1->Set("state", CompatUtility::GetServiceCurrentState(service));
fields1->Set("state_type", service->GetStateType());
fields1->Set("current_check_attempt", service->GetCheckAttempt());
fields1->Set("max_check_attempts", service->GetMaxCheckAttempts());
fields1->Set("last_hard_state", service->GetLastHardState());
if (cr) {
- std::pair<String, String> output_bag = CompatUtility::GetCheckResultOutput(cr);
- fields1->Set("output", output_bag.first);
- fields1->Set("long_output", output_bag.second);
+ fields1->Set("output", CompatUtility::GetCheckResultOutput(cr));
+ fields1->Set("long_output", CompatUtility::GetCheckResultLongOutput(cr));
}
fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
String output;
- if (cr) {
- std::pair<String, String> output_bag = CompatUtility::GetCheckResultOutput(cr);
- output = output_bag.first;
- }
+ if (cr)
+ output = CompatUtility::GetCheckResultOutput(cr);
std::ostringstream msgbuf;
msgbuf << "SERVICE ALERT: "
String output;
- if (cr) {
- std::pair<String, String> output_bag = CompatUtility::GetCheckResultOutput(cr);
- output = output_bag.first;
- }
+ if (cr)
+ output = CompatUtility::GetCheckResultOutput(cr);
std::ostringstream msgbuf;
msgbuf << "SERVICE NOTIFICATION: "
/* servicechecks */
void ServiceDbObject::AddServiceCheckHistory(const Service::Ptr& service, const CheckResult::Ptr &cr)
{
+ if (!cr)
+ return;
+
Host::Ptr host = service->GetHost();
Log(LogDebug, "db_ido", "add service check history for '" + service->GetName() + "'");
query1.Category = DbCatCheck;
Dictionary::Ptr fields1 = make_shared<Dictionary>();
- Dictionary::Ptr attrs;
-
- {
- ObjectLock olock(service);
- attrs = CompatUtility::GetServiceStatusAttributes(service, CompatTypeService);
- }
+ double execution_time = Service::CalculateExecutionTime(cr);
- fields1->Set("check_type", attrs->Get("check_type"));
- fields1->Set("current_check_attempt", attrs->Get("current_attempt"));
- fields1->Set("max_check_attempts", attrs->Get("max_attempts"));
- fields1->Set("state", attrs->Get("current_state"));
- fields1->Set("state_type", attrs->Get("state_type"));
+ fields1->Set("check_type", CompatUtility::GetServiceCheckType(service));
+ fields1->Set("current_check_attempt", service->GetCheckAttempt());
+ fields1->Set("max_check_attempts", service->GetMaxCheckAttempts());
+ fields1->Set("state", CompatUtility::GetServiceCurrentState(service));
+ fields1->Set("state_type", service->GetStateType());
double now = Utility::GetTime();
std::pair<unsigned long, unsigned long> time_bag = CompatUtility::ConvertTimestamp(now);
- double end = now + attrs->Get("check_execution_time");
- std::pair<unsigned long, unsigned long> time_bag_end = CompatUtility::ConvertTimestamp(now);
+ double end = now + execution_time;
+ std::pair<unsigned long, unsigned long> time_bag_end = CompatUtility::ConvertTimestamp(end);
fields1->Set("start_time", DbValue::FromTimestamp(time_bag.first));
fields1->Set("start_time_usec", time_bag.second);
- fields1->Set("end_time", DbValue::FromTimestamp(time_bag.first));
- fields1->Set("end_time_usec", time_bag.second);
+ fields1->Set("end_time", DbValue::FromTimestamp(time_bag_end.first));
+ fields1->Set("end_time_usec", time_bag_end.second);
fields1->Set("command_object_id", service->GetCheckCommand());
fields1->Set("command_args", Empty);
fields1->Set("command_line", cr->GetCommand());
- fields1->Set("execution_time", attrs->Get("check_execution_time"));
- fields1->Set("latency", attrs->Get("check_latency"));
+ fields1->Set("execution_time", execution_time);
+ fields1->Set("latency", Service::CalculateLatency(cr));
fields1->Set("return_code", cr->GetExitStatus());
- fields1->Set("output", attrs->Get("plugin_output"));
- fields1->Set("long_output", attrs->Get("long_plugin_output"));
- fields1->Set("perfdata", attrs->Get("performance_data"));
+ fields1->Set("output", CompatUtility::GetCheckResultOutput(cr));
+ fields1->Set("long_output", CompatUtility::GetCheckResultLongOutput(cr));
+ fields1->Set("perfdata", CompatUtility::GetCheckResultPerfdata(cr));
fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
fields1->Set("eventhandler_type", 1); /* service */
fields1->Set("object_id", service);
- fields1->Set("state", service->GetState());
+ fields1->Set("state", CompatUtility::GetServiceCurrentState(service));
fields1->Set("state_type", service->GetStateType());
fields1->Set("start_time", DbValue::FromTimestamp(time_bag.first));
#include "icinga/checkcommand.h"
#include "icinga/eventcommand.h"
#include "icinga/pluginutility.h"
+#include "base/utility.h"
#include "base/dynamictype.h"
#include "base/objectlock.h"
#include "base/debug.h"
using namespace icinga;
-Dictionary::Ptr CompatUtility::GetHostConfigAttributes(const Host::Ptr& host)
+/* command */
+String CompatUtility::GetCommandLine(const Command::Ptr& command)
{
- Dictionary::Ptr attr = make_shared<Dictionary>();
- Dictionary::Ptr service_attr = make_shared<Dictionary>();
+ Value commandLine = command->GetCommandLine();
+
+ String commandline;
+ 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.
+ commandline = " \"" + EscapeString(arg) + "\"";
+ }
+ } else if (!commandLine.IsEmpty()) {
+ commandline = EscapeString(Convert::ToString(commandLine));
+ } else {
+ commandline = "<internal>";
+ }
+
+ return commandline;
+}
+
+/* host */
+String CompatUtility::GetHostAlias(const Host::Ptr& host)
+{
ASSERT(host->OwnsLock());
- /* host config attributes */
- Dictionary::Ptr custom;
- Dictionary::Ptr macros;
- std::vector<String> notification_options;
+ if (!host->GetDisplayName().IsEmpty())
+ return host->GetName();
+ else
+ return host->GetDisplayName();
+}
+
+String CompatUtility::GetHostAddress(const Host::Ptr& host)
+{
+ ASSERT(host->OwnsLock());
- /* dicts */
- macros = host->GetMacros();
- custom = host->GetCustom();
+ Dictionary::Ptr macros = host->GetMacros();
+
+ String address;
if (macros) {
- attr->Set("address", macros->Get("address"));
- attr->Set("address6", macros->Get("address6"));
+ address = macros->Get("address");
}
+ return address;
+}
+
+String CompatUtility::GetHostAddress6(const Host::Ptr& host)
+{
+ ASSERT(host->OwnsLock());
+
+ Dictionary::Ptr macros = host->GetMacros();
+
+ String address6;
+
+ if (macros) {
+ address6 = macros->Get("address6");
+ }
+
+ return address6;
+}
+
+Host2dCoords CompatUtility::GetHost2dCoords(const Host::Ptr& host)
+{
+ ASSERT(host->OwnsLock());
+
+ Dictionary::Ptr custom = host->GetCustom();
+ Host2dCoords bag;
+
if (custom) {
- attr->Set("notes", custom->Get("notes"));
- attr->Set("notes_url", custom->Get("notes_url"));
- attr->Set("action_url", custom->Get("action_url"));
- attr->Set("icon_image", custom->Get("icon_image"));
- attr->Set("icon_image_alt", custom->Get("icon_image_alt"));
-
- attr->Set("statusmap_image", custom->Get("statusmap_image"));
- attr->Set("2d_coords", custom->Get("2d_coords"));
-
- if (!custom->Get("2d_coords").IsEmpty()) {
- std::vector<String> tokens;
- String coords = custom->Get("2d_coords");
- boost::algorithm::split(tokens, coords, boost::is_any_of(","));
-
- if (tokens.size() == 2) {
- attr->Set("have_2d_coords", 1);
- attr->Set("x_2d", tokens[0]);
- attr->Set("y_2d", tokens[1]);
- }
- else
- attr->Set("have_2d_coords", 0);
+ bag.have_2d_coords = (custom->Get("x_2d") && custom->Get("y_2d") ? 1 : 0);
+
+ if (bag.have_2d_coords == 1) {
+ bag.x_2d = custom->Get("x_2d");
+ bag.y_2d = custom->Get("y_2d");
}
- else
- attr->Set("have_2d_coords", 0);
-
- /* deprecated in 1.x, but empty */
- attr->Set("vrml_image", Empty);
- attr->Set("3d_coords", Empty);
- attr->Set("have_3d_coords", 0);
- attr->Set("x_3d", Empty);
- attr->Set("y_3d", Empty);
- attr->Set("z_3d", Empty);
+ } else {
+ bag.have_2d_coords = 0;
}
- /* alias */
- if (!host->GetDisplayName().IsEmpty())
- attr->Set("alias", host->GetName());
- else
- attr->Set("alias", host->GetDisplayName());
+ return bag;
+}
+
+int CompatUtility::GetHostNotifyOnDown(const Host::Ptr& host)
+{
+ ASSERT(host->OwnsLock());
- /* get additonal attributes from check service */
Service::Ptr service = host->GetCheckService();
- if (service) {
- unsigned long notification_type_filter = 0;
- unsigned long notification_state_filter = 0;
+ if (!service)
+ return 0;
- ObjectLock olock(service);
+ unsigned long notification_state_filter = GetServiceNotificationStateFilter(service);
- BOOST_FOREACH(const Notification::Ptr& notification, service->GetNotifications()) {
- if (notification->GetNotificationTypeFilter())
- notification_type_filter = notification->GetNotificationTypeFilter();
+ if (notification_state_filter & (1<<StateCritical) ||
+ notification_state_filter & (1<<StateWarning))
+ return 1;
- if (notification->GetNotificationStateFilter())
- notification_state_filter = notification->GetNotificationStateFilter();
- }
+ return 0;
+}
- /* notification state filters */
- if (notification_state_filter & (1<<StateWarning) ||
- notification_state_filter & (1<<StateCritical)) {
- attr->Set("notify_on_down", 1);
- notification_options.push_back("d");
- }
+int CompatUtility::GetHostNotifyOnUnreachable(const Host::Ptr& host)
+{
+ ASSERT(host->OwnsLock());
- /* notification type filters */
- if (notification_type_filter & (1<<NotificationRecovery)) {
- attr->Set("notify_on_recovery", 1);
- notification_options.push_back("r");
- }
- if (notification_type_filter & (1<<NotificationFlappingStart) ||
- notification_type_filter & (1<<NotificationFlappingEnd)) {
- attr->Set("notify_on_flapping", 1);
- notification_options.push_back("f");
- }
- if (notification_type_filter & (1<<NotificationDowntimeStart) ||
- notification_type_filter & (1<<NotificationDowntimeEnd) ||
- notification_type_filter & (1<<NotificationDowntimeRemoved)) {
- attr->Set("notify_on_downtime", 1);
- notification_options.push_back("s");
- }
+ Service::Ptr service = host->GetCheckService();
- service_attr = CompatUtility::GetServiceConfigAttributes(service);
-
- attr->Set("check_period", service_attr->Get("check_period"));
- attr->Set("check_interval", service_attr->Get("check_interval"));
- attr->Set("retry_interval", service_attr->Get("retry_interval"));
- attr->Set("max_check_attempts", service_attr->Get("max_check_attempts"));
- attr->Set("active_checks_enabled", service_attr->Get("active_checks_enabled"));
- attr->Set("passive_checks_enabled", service_attr->Get("passive_checks_enabled"));
- attr->Set("flap_detection_enabled", service_attr->Get("flap_detection_enabled"));
- attr->Set("low_flap_threshold", service_attr->Get("low_flap_threshold"));
- attr->Set("high_flap_threshold", service_attr->Get("high_flap_threshold"));
- attr->Set("notifications_enabled", service_attr->Get("notifications_enabled"));
- attr->Set("eventhandler_enabled", service_attr->Get("eventhandler_enabled"));
- attr->Set("is_volatile", service_attr->Get("is_volatile"));
- attr->Set("notifications_enabled", service_attr->Get("notifications_enabled"));
- attr->Set("notification_options", boost::algorithm::join(notification_options, ","));
- attr->Set("notification_interval", service_attr->Get("notification_interval"));
- attr->Set("process_performance_data", service_attr->Get("process_performance_data"));
- attr->Set("notification_period", service_attr->Get("notification_period"));
- attr->Set("check_freshness", service_attr->Get("check_freshness"));
- attr->Set("check_command", service_attr->Get("check_command"));
- attr->Set("event_handler", service_attr->Get("event_handler"));
- }
+ if (!service)
+ return 0;
+
+ unsigned long notification_state_filter = GetServiceNotificationStateFilter(service);
+
+ if (notification_state_filter & (1<<StateUnknown))
+ return 1;
- return attr;
+ return 0;
}
-Dictionary::Ptr CompatUtility::GetServiceStatusAttributes(const Service::Ptr& service, CompatObjectType type)
+/* service */
+int CompatUtility::GetServiceCurrentState(const Service::Ptr& service)
{
- Dictionary::Ptr attr = make_shared<Dictionary>();
+ ASSERT(service->OwnsLock());
+
+ int state = service->GetState();
+
+ if (state > StateUnknown)
+ return StateUnknown;
+ return state;
+}
+
+int CompatUtility::GetServiceShouldBeScheduled(const Service::Ptr& service)
+{
ASSERT(service->OwnsLock());
- String raw_output;
- String output;
- String long_output;
- String perfdata;
- String check_source;
- double schedule_end = -1;
+ return (service->GetEnableActiveChecks() ? 1 : 0);
+}
+
+int CompatUtility::GetServiceCheckType(const Service::Ptr& service)
+{
+ ASSERT(service->OwnsLock());
+
+ return (service->GetEnableActiveChecks() ? 0 : 1);
+}
+
+double CompatUtility::GetServiceCheckInterval(const Service::Ptr& service)
+{
+ ASSERT(service->OwnsLock());
+
+ return service->GetCheckInterval() / 60.0;
+}
+
+double CompatUtility::GetServiceRetryInterval(const Service::Ptr& service)
+{
+ ASSERT(service->OwnsLock());
+
+ return service->GetRetryInterval() / 60.0;
+}
+
+String CompatUtility::GetServiceCheckPeriod(const Service::Ptr& service)
+{
+ ASSERT(service->OwnsLock());
- String check_period_str;
TimePeriod::Ptr check_period = service->GetCheckPeriod();
if (check_period)
- check_period_str = check_period->GetName();
+ return check_period->GetName();
else
- check_period_str = "24x7";
+ return "24x7";
+}
+
+int CompatUtility::GetServiceHasBeenChecked(const Service::Ptr& service)
+{
+ ASSERT(service->OwnsLock());
+
+ return (service->GetLastCheckResult() ? 1 : 0);
+}
+
+
+int CompatUtility::GetServiceProblemHasBeenAcknowledged(const Service::Ptr& service)
+{
+ ASSERT(service->OwnsLock());
+
+ return (service->GetAcknowledgement() != AcknowledgementNone ? 1 : 0);
+}
+
+int CompatUtility::GetServiceAcknowledgementType(const Service::Ptr& service)
+{
+ ASSERT(service->OwnsLock());
+
+ return static_cast<int>(service->GetAcknowledgement());
+}
+
+int CompatUtility::GetServicePassiveChecksEnabled(const Service::Ptr& service)
+{
+ ASSERT(service->OwnsLock());
+
+ return (service->GetEnablePassiveChecks() ? 1 : 0);
+}
- CheckResult::Ptr cr = service->GetLastCheckResult();
+int CompatUtility::GetServiceActiveChecksEnabled(const Service::Ptr& service)
+{
+ ASSERT(service->OwnsLock());
+
+ return (service->GetEnableActiveChecks() ? 1 : 0);
+}
+
+int CompatUtility::GetServiceEventHandlerEnabled(const Service::Ptr& service)
+{
+ ASSERT(service->OwnsLock());
+
+ return (service->GetEventCommand() ? 1 : 0);
+}
+
+int CompatUtility::GetServiceFlapDetectionEnabled(const Service::Ptr& service)
+{
+ ASSERT(service->OwnsLock());
+
+ return (service->GetEnableFlapping() ? 1 : 0);
+}
+
+int CompatUtility::GetServiceIsFlapping(const Service::Ptr& service)
+{
+ ASSERT(service->OwnsLock());
+
+ return (service->IsFlapping() ? 1 : 0);
+}
+
+String CompatUtility::GetServicePercentStateChange(const Service::Ptr& service)
+{
+ ASSERT(service->OwnsLock());
+
+ return Convert::ToString(service->GetFlappingCurrent());
+}
+
+int CompatUtility::GetServiceProcessPerformanceData(const Service::Ptr& service)
+{
+ ASSERT(service->OwnsLock());
+
+ return (service->GetEnablePerfdata() ? 1 : 0);
+}
+
+String CompatUtility::GetServiceEventHandler(const Service::Ptr& service)
+{
+ ASSERT(service->OwnsLock());
+
+ String event_command_str;
+ EventCommand::Ptr eventcommand = service->GetEventCommand();
+
+ if (eventcommand)
+ event_command_str = eventcommand->GetName();
+
+ return event_command_str;
+}
+
+String CompatUtility::GetServiceCheckCommand(const Service::Ptr& service)
+{
+ ASSERT(service->OwnsLock());
+
+ String check_command_str;
+ CheckCommand::Ptr checkcommand = service->GetCheckCommand();
+
+ if (checkcommand)
+ check_command_str = checkcommand->GetName();
+
+ return check_command_str;
+}
+
+int CompatUtility::GetServiceIsVolatile(const Service::Ptr& service)
+{
+ ASSERT(service->OwnsLock());
+
+ return (service->GetVolatile() ? 1 : 0);
+}
+
+double CompatUtility::GetServiceLowFlapThreshold(const Service::Ptr& service)
+{
+ ASSERT(service->OwnsLock());
+
+ return service->GetFlappingThreshold();
+}
- if (cr) {
- std::pair<String, String> output_bag = GetCheckResultOutput(cr);
- output = output_bag.first;
- long_output = output_bag.second;
+double CompatUtility::GetServiceHighFlapThreshold(const Service::Ptr& service)
+{
+ ASSERT(service->OwnsLock());
+
+ return service->GetFlappingThreshold();
+}
+
+int CompatUtility::GetServiceFreshnessChecksEnabled(const Service::Ptr& service)
+{
+ ASSERT(service->OwnsLock());
+
+ return (service->GetCheckInterval() > 0 ? 1 : 0);
+}
+
+int CompatUtility::GetServiceFreshnessThreshold(const Service::Ptr& service)
+{
+ ASSERT(service->OwnsLock());
- check_source = cr->GetCheckSource();
+ return static_cast<int>(service->GetCheckInterval());
+}
+
+double CompatUtility::GetServiceStaleness(const Service::Ptr& service)
+{
+ ASSERT(service->OwnsLock());
+
+ if (service->HasBeenChecked() && service->GetLastCheck() > 0)
+ return (Utility::GetTime() - service->GetLastCheck()) / (service->GetCheckInterval() * 3600);
+
+ return 0.0;
+}
+
+int CompatUtility::GetServiceIsAcknowledged(const Service::Ptr& service)
+{
+ ASSERT(service->OwnsLock());
+
+ return (service->IsAcknowledged() ? 1 : 0);
+}
+
+int CompatUtility::GetServiceNoMoreNotifications(const Service::Ptr& service)
+{
+ ASSERT(service->OwnsLock());
+
+ if (CompatUtility::GetServiceNotificationNotificationInterval(service) == 0 && !service->GetVolatile())
+ return 1;
+
+ return 0;
+}
- perfdata = GetCheckResultPerfdata(cr);
- schedule_end = cr->GetScheduleEnd();
+int CompatUtility::GetServiceInCheckPeriod(const Service::Ptr& service)
+{
+ ASSERT(service->OwnsLock());
+
+ TimePeriod::Ptr timeperiod = service->GetCheckPeriod();
+
+ /* none set means always checked */
+ if (!timeperiod)
+ return 1;
+
+ return (timeperiod->IsInside(Utility::GetTime()) ? 1 : 0);
+}
+
+int CompatUtility::GetServiceInNotificationPeriod(const Service::Ptr& service)
+{
+ ASSERT(service->OwnsLock());
+
+ BOOST_FOREACH(const Notification::Ptr& notification, service->GetNotifications()) {
+ ObjectLock olock(notification);
+
+ TimePeriod::Ptr timeperiod = notification->GetNotificationPeriod();
+
+ /* first notification wins */
+ if (timeperiod)
+ return (timeperiod->IsInside(Utility::GetTime()) ? 1 : 0);
}
- int state = service->GetState();
+ /* none set means always notified */
+ return 1;
+}
- if (state > StateUnknown)
- state = StateUnknown;
+//fixme structs
+/* custom attr */
+Dictionary::Ptr CompatUtility::GetCustomVariableConfig(const DynamicObject::Ptr& object)
+{
+ ASSERT(service->OwnsLock());
- if (type == CompatTypeHost) {
- if (state == StateOK || state == StateWarning)
- state = 0; /* UP */
- else
- state = 1; /* DOWN */
+ Dictionary::Ptr custom;
- Host::Ptr host = service->GetHost();
+ if (object->GetType() == DynamicType::GetByName("Host")) {
+ custom = static_pointer_cast<Host>(object)->GetCustom();
+ } else if (object->GetType() == DynamicType::GetByName("Service")) {
+ custom = static_pointer_cast<Service>(object)->GetCustom();
+ } else if (object->GetType() == DynamicType::GetByName("User")) {
+ custom = static_pointer_cast<User>(object)->GetCustom();
+ } else {
+ Log(LogDebug, "icinga", "unknown object type for custom vars");
+ return Dictionary::Ptr();
+ }
- ASSERT(host);
+ Dictionary::Ptr customvars = make_shared<Dictionary>();
- if (!host->IsReachable())
- state = 2; /* UNREACHABLE */
+ if (!custom)
+ return Dictionary::Ptr();
- attr->Set("last_time_up", host->GetLastStateUp());
- attr->Set("last_time_down", host->GetLastStateDown());
- attr->Set("last_time_unreachable", host->GetLastStateUnreachable());
+ ObjectLock olock(custom);
+ String key;
+ Value value;
+ BOOST_FOREACH(const Dictionary::Pair& kv, custom) {
+ if (kv.first == "notes" ||
+ kv.first == "action_url" ||
+ kv.first == "notes_url" ||
+ kv.first == "icon_image" ||
+ kv.first == "icon_image_alt" ||
+ kv.first == "statusmap_image" ||
+ kv.first == "2d_coords")
+ continue;
+
+ customvars->Set(key, value);
+ }
+
+ return customvars;
+}
+
+String CompatUtility::GetCustomAttributeConfig(const DynamicObject::Ptr& object, const String& name)
+{
+ ASSERT(service->OwnsLock());
+
+ Dictionary::Ptr custom;
+
+ if (object->GetType() == DynamicType::GetByName("Host")) {
+ custom = static_pointer_cast<Host>(object)->GetCustom();
+ } else if (object->GetType() == DynamicType::GetByName("Service")) {
+ custom = static_pointer_cast<Service>(object)->GetCustom();
+ } else if (object->GetType() == DynamicType::GetByName("User")) {
+ custom = static_pointer_cast<User>(object)->GetCustom();
} else {
- attr->Set("last_time_ok", service->GetLastStateOK());
- attr->Set("last_time_warn", service->GetLastStateWarning());
- attr->Set("last_time_critical", service->GetLastStateCritical());
- attr->Set("last_time_unknown", service->GetLastStateUnknown());
+ Log(LogDebug, "icinga", "unknown object type for custom attributes");
+ return Empty;
}
- double last_notification = 0;
- double next_notification = 0;
- int notification_number = 0;
+ if (!custom)
+ return Empty;
+
+ return custom->Get(name);
+}
+
+/* notifications */
+int CompatUtility::GetServiceNotificationsEnabled(const Service::Ptr& service)
+{
+ ASSERT(service->OwnsLock());
+
+ return (service->GetEnableNotifications() ? 1 : 0);
+}
+
+int CompatUtility::GetServiceNotificationLastNotification(const Service::Ptr& service)
+{
+ ASSERT(service->OwnsLock());
+
+ double last_notification = 0.0;
BOOST_FOREACH(const Notification::Ptr& notification, service->GetNotifications()) {
if (notification->GetLastNotification() > last_notification)
last_notification = notification->GetLastNotification();
+ }
+
+ return static_cast<int>(last_notification);
+}
+
+int CompatUtility::GetServiceNotificationNextNotification(const Service::Ptr& service)
+{
+ ASSERT(service->OwnsLock());
+ double next_notification = 0.0;
+ BOOST_FOREACH(const Notification::Ptr& notification, service->GetNotifications()) {
if (notification->GetNextNotification() < next_notification)
next_notification = notification->GetNextNotification();
+ }
+
+ return static_cast<int>(next_notification);
+}
+
+int CompatUtility::GetServiceNotificationNotificationNumber(const Service::Ptr& service)
+{
+ ASSERT(service->OwnsLock());
+ int notification_number = 0;
+ BOOST_FOREACH(const Notification::Ptr& notification, service->GetNotifications()) {
if (notification->GetNotificationNumber() > notification_number)
notification_number = notification->GetNotificationNumber();
}
- CheckCommand::Ptr checkcommand = service->GetCheckCommand();
- if (checkcommand)
- attr->Set("check_command", "check_" + checkcommand->GetName());
+ return notification_number;
+}
- EventCommand::Ptr eventcommand = service->GetEventCommand();
- if (eventcommand)
- attr->Set("event_handler", "event_" + eventcommand->GetName());
-
- attr->Set("check_period", check_period_str);
- attr->Set("check_interval", service->GetCheckInterval() / 60.0);
- attr->Set("retry_interval", service->GetRetryInterval() / 60.0);
- attr->Set("has_been_checked", (service->GetLastCheckResult() ? 1 : 0));
- attr->Set("should_be_scheduled", 1);
- attr->Set("check_execution_time", Service::CalculateExecutionTime(cr));
- attr->Set("check_latency", Service::CalculateLatency(cr));
- attr->Set("current_state", state);
- attr->Set("state_type", service->GetStateType());
- attr->Set("plugin_output", output);
- attr->Set("long_plugin_output", long_output);
- attr->Set("performance_data", perfdata);
- attr->Set("check_source", check_source);
- attr->Set("check_type", (service->GetEnableActiveChecks() ? 0 : 1));
- attr->Set("last_check", schedule_end);
- attr->Set("next_check", service->GetNextCheck());
- attr->Set("current_attempt", service->GetCheckAttempt());
- attr->Set("max_attempts", service->GetMaxCheckAttempts());
- attr->Set("last_state_change", service->GetLastStateChange());
- attr->Set("last_hard_state_change", service->GetLastHardStateChange());
- attr->Set("last_update", static_cast<long>(time(NULL)));
- attr->Set("process_performance_data", 1); /* always enabled */
- attr->Set("freshness_checks_enabled", 1); /* always enabled */
- attr->Set("notifications_enabled", (service->GetEnableNotifications() ? 1 : 0));
- attr->Set("event_handler_enabled", 1); /* always enabled */
- attr->Set("active_checks_enabled", (service->GetEnableActiveChecks() ? 1 : 0));
- attr->Set("passive_checks_enabled", (service->GetEnablePassiveChecks() ? 1 : 0));
- attr->Set("flap_detection_enabled", (service->GetEnableFlapping() ? 1 : 0));
- attr->Set("is_flapping", (service->IsFlapping() ? 1 : 0));
- attr->Set("percent_state_change", Convert::ToString(service->GetFlappingCurrent()));
- attr->Set("problem_has_been_acknowledged", (service->GetAcknowledgement() != AcknowledgementNone ? 1 : 0));
- attr->Set("acknowledgement_type", static_cast<int>(service->GetAcknowledgement()));
- attr->Set("acknowledgement_end_time", service->GetAcknowledgementExpiry());
- attr->Set("scheduled_downtime_depth", (service->IsInDowntime() ? 1 : 0));
- attr->Set("last_notification", last_notification);
- attr->Set("next_notification", next_notification);
- attr->Set("current_notification_number", notification_number);
- attr->Set("modified_attributes", service->GetModifiedAttributes());
-
- return attr;
-}
-
-Dictionary::Ptr CompatUtility::GetServiceConfigAttributes(const Service::Ptr& service)
-{
- Dictionary::Ptr attr = make_shared<Dictionary>();
-
- ASSERT(service->OwnsLock());
-
- Host::Ptr host = service->GetHost();
-
- String check_period_str;
- TimePeriod::Ptr check_period = service->GetCheckPeriod();
- if (check_period)
- check_period_str = check_period->GetName();
- else
- check_period_str = "24x7";
+double CompatUtility::GetServiceNotificationNotificationInterval(const Service::Ptr& service)
+{
+ ASSERT(service->OwnsLock());
double notification_interval = -1;
- String notification_period;
- unsigned long notification_type_filter = 0;
- unsigned long notification_state_filter = 0;
BOOST_FOREACH(const Notification::Ptr& notification, service->GetNotifications()) {
if (notification_interval == -1 || notification->GetNotificationInterval() < notification_interval)
notification_interval = notification->GetNotificationInterval();
+ }
- if (notification->GetNotificationPeriod())
- notification_period = notification->GetNotificationPeriod()->GetName();
+ if (notification_interval == -1)
+ notification_interval = 60;
- if (notification->GetNotificationTypeFilter())
- notification_type_filter = notification->GetNotificationTypeFilter();
+ return notification_interval / 60.0;
+}
- if (notification->GetNotificationStateFilter())
- notification_state_filter = notification->GetNotificationStateFilter();
+String CompatUtility::GetServiceNotificationNotificationPeriod(const Service::Ptr& service)
+{
+ ASSERT(service->OwnsLock());
+
+ TimePeriod::Ptr notification_period;
+
+ BOOST_FOREACH(const Notification::Ptr& notification, service->GetNotifications()) {
- Log(LogDebug, "icinga", "notification_type_filter: " + Convert::ToString(notification_type_filter) + " notification_state_filter: " + Convert::ToString(notification_state_filter));
+ if (notification->GetNotificationPeriod())
+ notification_period = notification->GetNotificationPeriod();
}
+ if (!notification_period)
+ return Empty;
- if (notification_interval == -1)
- notification_interval = 60;
+ return notification_period->GetName();
+}
- String check_command_str;
- String event_command_str;
- CheckCommand::Ptr checkcommand = service->GetCheckCommand();
- EventCommand::Ptr eventcommand = service->GetEventCommand();
+String CompatUtility::GetServiceNotificationNotificationOptions(const Service::Ptr& service)
+{
+ ASSERT(service->OwnsLock());
- if (checkcommand)
- check_command_str = checkcommand->GetName();
+ bool is_hostcheck = (service->GetHost()->GetCheckService() == service);
- if (eventcommand)
- event_command_str = eventcommand->GetName();
+ unsigned long notification_type_filter = 0;
+ unsigned long notification_state_filter = 0;
- Dictionary::Ptr custom;
- Dictionary::Ptr macros;
- std::vector<String> notification_options;
+ BOOST_FOREACH(const Notification::Ptr& notification, service->GetNotifications()) {
+ if (notification->GetNotificationTypeFilter())
+ notification_type_filter = notification->GetNotificationTypeFilter();
+
+ if (notification->GetNotificationStateFilter())
+ notification_state_filter = notification->GetNotificationStateFilter();
+ }
- /* dicts */
- custom = service->GetCustom();
- macros = service->GetMacros();
+ std::vector<String> notification_options;
/* notification state filters */
if (notification_state_filter & (1<<StateWarning)) {
- attr->Set("notify_on_warning", 1);
notification_options.push_back("w");
}
if (notification_state_filter & (1<<StateUnknown)) {
- attr->Set("notify_on_unknown", 1);
notification_options.push_back("u");
}
if (notification_state_filter & (1<<StateCritical)) {
- attr->Set("notify_on_critical", 1);
notification_options.push_back("c");
}
/* notification type filters */
if (notification_type_filter & (1<<NotificationRecovery)) {
- attr->Set("notify_on_recovery", 1);
notification_options.push_back("r");
}
if (notification_type_filter & (1<<NotificationFlappingStart) ||
notification_type_filter & (1<<NotificationFlappingEnd)) {
- attr->Set("notify_on_flapping", 1);
notification_options.push_back("f");
}
if (notification_type_filter & (1<<NotificationDowntimeStart) ||
notification_type_filter & (1<<NotificationDowntimeEnd) ||
notification_type_filter & (1<<NotificationDowntimeRemoved)) {
- attr->Set("notify_on_downtime", 1);
notification_options.push_back("s");
}
- attr->Set("check_period", check_period_str);
- attr->Set("check_interval", service->GetCheckInterval() / 60.0);
- attr->Set("retry_interval", service->GetRetryInterval() / 60.0);
- attr->Set("max_check_attempts", service->GetMaxCheckAttempts());
- attr->Set("active_checks_enabled", (service->GetEnableActiveChecks() ? 1 : 0));
- attr->Set("passive_checks_enabled", (service->GetEnablePassiveChecks() ? 1 : 0));
- attr->Set("flap_detection_enabled", (service->GetEnableFlapping() ? 1 : 0));
- attr->Set("low_flap_threshold", service->GetFlappingThreshold());
- attr->Set("high_flap_threshold", service->GetFlappingThreshold());
- attr->Set("notifications_enabled", (service->GetEnableNotifications() ? 1 : 0));
- attr->Set("eventhandler_enabled", 1); /* always 1 */
- attr->Set("is_volatile", (service->GetVolatile() ? 1 : 0));
- attr->Set("notifications_enabled", (service->GetEnableNotifications() ? 1 : 0));
- attr->Set("notification_options", boost::algorithm::join(notification_options, ","));
- attr->Set("notification_interval", notification_interval / 60.0);
- attr->Set("process_performance_data", 1); /* always 1 */
- attr->Set("notification_period", notification_period);
- attr->Set("check_freshness", 1); /* always 1 */
- attr->Set("check_command", check_command_str);
- attr->Set("event_handler", event_command_str);
-
- /* custom attr */
- if (custom) {
- attr->Set("notes", custom->Get("notes"));
- attr->Set("notes_url", custom->Get("notes_url"));
- attr->Set("action_url", custom->Get("action_url"));
- attr->Set("icon_image", custom->Get("icon_image"));
- attr->Set("icon_image_alt", custom->Get("icon_image_alt"));
- }
+ return boost::algorithm::join(notification_options, ",");
+}
- return attr;
+int CompatUtility::GetServiceNotificationTypeFilter(const Service::Ptr& service)
+{
+ ASSERT(service->OwnsLock());
+
+ unsigned long notification_type_filter = 0;
+ BOOST_FOREACH(const Notification::Ptr& notification, service->GetNotifications()) {
+ ObjectLock olock(notification);
+
+ if (notification->GetNotificationTypeFilter())
+ notification_type_filter = notification->GetNotificationTypeFilter();
+ }
+
+ return notification_type_filter;
}
-Dictionary::Ptr CompatUtility::GetCommandConfigAttributes(const Command::Ptr& command)
+int CompatUtility::GetServiceNotificationStateFilter(const Service::Ptr& service)
{
- Dictionary::Ptr attr = make_shared<Dictionary>();
+ ASSERT(service->OwnsLock());
- Value commandLine = command->GetCommandLine();
+ unsigned long notification_state_filter = 0;
- String commandline;
- if (commandLine.IsObjectType<Array>()) {
- Array::Ptr args = commandLine;
+ BOOST_FOREACH(const Notification::Ptr& notification, service->GetNotifications()) {
+ ObjectLock olock(notification);
- ObjectLock olock(args);
- String arg;
- BOOST_FOREACH(arg, args) {
- // This is obviously incorrect for non-trivial cases.
- commandline = " \"" + EscapeString(arg) + "\"";
- }
- } else if (!commandLine.IsEmpty()) {
- commandline = EscapeString(Convert::ToString(commandLine));
- } else {
- commandline = "<internal>";
+ if (notification->GetNotificationStateFilter())
+ notification_state_filter = notification->GetNotificationStateFilter();
}
- attr->Set("command_line", commandline);
+ return notification_state_filter;
+}
+
+int CompatUtility::GetServiceNotifyOnWarning(const Service::Ptr& service)
+{
+ ASSERT(service->OwnsLock());
- return attr;
+ if (GetServiceNotificationStateFilter(service) & (1<<StateWarning))
+ return 1;
+
+ return 0;
}
+int CompatUtility::GetServiceNotifyOnCritical(const Service::Ptr& service)
+{
+ ASSERT(service->OwnsLock());
+
+ if (GetServiceNotificationStateFilter(service) & (1<<StateCritical))
+ return 1;
-Dictionary::Ptr CompatUtility::GetCustomVariableConfig(const DynamicObject::Ptr& object)
+ return 0;
+}
+
+int CompatUtility::GetServiceNotifyOnUnknown(const Service::Ptr& service)
{
- Dictionary::Ptr custom;
+ ASSERT(service->OwnsLock());
- if (object->GetType() == DynamicType::GetByName("Host")) {
- custom = static_pointer_cast<Host>(object)->GetCustom();
- } else if (object->GetType() == DynamicType::GetByName("Service")) {
- custom = static_pointer_cast<Service>(object)->GetCustom();
- } else if (object->GetType() == DynamicType::GetByName("User")) {
- custom = static_pointer_cast<User>(object)->GetCustom();
- } else {
- Log(LogDebug, "icinga", "unknown object type for custom vars");
- return Dictionary::Ptr();
- }
+ if (GetServiceNotificationStateFilter(service) & (1<<StateUnknown))
+ return 1;
- Dictionary::Ptr customvars = make_shared<Dictionary>();
+ return 0;
+}
- if (!custom)
- return Dictionary::Ptr();
+int CompatUtility::GetServiceNotifyOnRecovery(const Service::Ptr& service)
+{
+ ASSERT(service->OwnsLock());
- ObjectLock olock(custom);
- String key;
- Value value;
- BOOST_FOREACH(const Dictionary::Pair& kv, custom) {
- if (kv.first == "notes" ||
- kv.first == "action_url" ||
- kv.first == "notes_url" ||
- kv.first == "icon_image" ||
- kv.first == "icon_image_alt" ||
- kv.first == "statusmap_image" ||
- kv.first == "2d_coords")
- continue;
+ if (GetServiceNotificationTypeFilter(service) & (1<<NotificationRecovery))
+ return 1;
- customvars->Set(key, value);
- }
+ return 0;
+}
- return customvars;
+int CompatUtility::GetServiceNotifyOnFlapping(const Service::Ptr& service)
+{
+ ASSERT(service->OwnsLock());
+
+ unsigned long notification_type_filter = GetServiceNotificationTypeFilter(service);
+
+ if (notification_type_filter & (1<<NotificationFlappingStart) ||
+ notification_type_filter & (1<<NotificationFlappingEnd))
+ return 1;
+
+ return 0;
+}
+
+int CompatUtility::GetServiceNotifyOnDowntime(const Service::Ptr& service)
+{
+ ASSERT(service->OwnsLock());
+
+ unsigned long notification_type_filter = GetServiceNotificationTypeFilter(service);
+
+ if (notification_type_filter & (1<<NotificationDowntimeStart) ||
+ notification_type_filter & (1<<NotificationDowntimeEnd) ||
+ notification_type_filter & (1<<NotificationDowntimeRemoved))
+ return 1;
+
+ return 0;
}
std::set<User::Ptr> CompatUtility::GetServiceNotificationUsers(const Service::Ptr& service)
{
+ ASSERT(service->OwnsLock());
+
/* Service -> Notifications -> (Users + UserGroups -> Users) */
std::set<User::Ptr> allUsers;
std::set<User::Ptr> users;
std::set<UserGroup::Ptr> CompatUtility::GetServiceNotificationUserGroups(const Service::Ptr& service)
{
+ ASSERT(service->OwnsLock());
+
std::set<UserGroup::Ptr> usergroups;
/* Service -> Notifications -> UserGroups */
BOOST_FOREACH(const Notification::Ptr& notification, service->GetNotifications()) {
return usergroups;
}
-std::pair<String, String> CompatUtility::GetCheckResultOutput(const CheckResult::Ptr& cr)
+String CompatUtility::GetCheckResultOutput(const CheckResult::Ptr& cr)
{
if (!cr)
- return std::make_pair(Empty, Empty);
+ return Empty;
- String long_output;
String output;
String raw_output = cr->GetOutput();
size_t line_end = raw_output.Find("\n");
- output = raw_output.SubStr(0, line_end);
+ return raw_output.SubStr(0, line_end);
+}
+
+String CompatUtility::GetCheckResultLongOutput(const CheckResult::Ptr& cr)
+{
+ if (!cr)
+ return Empty;
+
+ String long_output;
+ String output;
+
+ String raw_output = cr->GetOutput();
+
+ /*
+ * replace semi-colons with colons in output
+ * semi-colon is used as delimiter in various interfaces
+ */
+ boost::algorithm::replace_all(raw_output, ";", ":");
+
+ size_t line_end = raw_output.Find("\n");
if (line_end > 0 && line_end != String::NPos) {
long_output = raw_output.SubStr(line_end+1, raw_output.GetLength());
- long_output = EscapeString(long_output);
+ return EscapeString(long_output);
}
- output = EscapeString(output);
-
- return std::make_pair(output, long_output);
+ return Empty;
}
String CompatUtility::GetCheckResultPerfdata(const CheckResult::Ptr& cr)
if (name == "SET_SVC_NOTIFICATION_NUMBER")
return 143;
if (name == "CHANGE_HOST_CHECK_TIMEPERIOD")
- return 144;
+ return 144;
if (name == "CHANGE_SVC_CHECK_TIMEPERIOD")
return 145;
if (name == "PROCESS_FILE")
CompatTypeHost
};
+typedef struct {
+ int have_2d_coords;
+ String x_2d;
+ String y_2d;
+} Host2dCoords;
+
/**
* Compatibility utility functions.
*
class I2_ICINGA_API CompatUtility
{
public:
- static Dictionary::Ptr GetHostConfigAttributes(const Host::Ptr& host);
-
- static Dictionary::Ptr GetServiceStatusAttributes(const Service::Ptr& service, CompatObjectType type);
- static Dictionary::Ptr GetServiceConfigAttributes(const Service::Ptr& service);
- static Dictionary::Ptr GetCommandConfigAttributes(const Command::Ptr& command);
-
- static Dictionary::Ptr GetCustomVariableConfig(const DynamicObject::Ptr& object);
+ /* host */
+ static String GetHostAlias(const Host::Ptr& host);
+ static String GetHostAddress(const Host::Ptr& host);
+ static String GetHostAddress6(const Host::Ptr& host);
+ static Host2dCoords GetHost2dCoords(const Host::Ptr& host);
+ static int GetHostNotifyOnDown(const Host::Ptr& host);
+ static int GetHostNotifyOnUnreachable(const Host::Ptr& host);
+
+ /* service */
+ static int GetServiceCurrentState(const Service::Ptr& service);
+ static int GetServiceShouldBeScheduled(const Service::Ptr& service);
+ static int GetServiceCheckType(const Service::Ptr& service);
+ static double GetServiceCheckInterval(const Service::Ptr& service);
+ static double GetServiceRetryInterval(const Service::Ptr& service);
+ static String GetServiceCheckPeriod(const Service::Ptr& service);
+ static int GetServiceHasBeenChecked(const Service::Ptr& service);
+ static int GetServiceProblemHasBeenAcknowledged(const Service::Ptr& service);
+ static int GetServiceAcknowledgementType(const Service::Ptr& service);
+ static int GetServicePassiveChecksEnabled(const Service::Ptr& service);
+ static int GetServiceActiveChecksEnabled(const Service::Ptr& service);
+ static int GetServiceEventHandlerEnabled(const Service::Ptr& service);
+ static int GetServiceFlapDetectionEnabled(const Service::Ptr& service);
+ static int GetServiceIsFlapping(const Service::Ptr& service);
+ static String GetServicePercentStateChange(const Service::Ptr& service);
+ static int GetServiceProcessPerformanceData(const Service::Ptr& service);
+
+ static String GetServiceEventHandler(const Service::Ptr& service);
+ static String GetServiceCheckCommand(const Service::Ptr& service);
+
+ static int GetServiceIsVolatile(const Service::Ptr& service);
+ static double GetServiceLowFlapThreshold(const Service::Ptr& service);
+ static double GetServiceHighFlapThreshold(const Service::Ptr& service);
+ static int GetServiceFreshnessChecksEnabled(const Service::Ptr& service);
+ static int GetServiceFreshnessThreshold(const Service::Ptr& service);
+ static double GetServiceStaleness(const Service::Ptr& service);
+ static int GetServiceIsAcknowledged(const Service::Ptr& service);
+ static int GetServiceNoMoreNotifications(const Service::Ptr& service);
+ static int GetServiceInCheckPeriod(const Service::Ptr& service);
+ static int GetServiceInNotificationPeriod(const Service::Ptr& service);
+
+ /* notification */
+ static int GetServiceNotificationsEnabled(const Service::Ptr& service);
+ static int GetServiceNotificationLastNotification(const Service::Ptr& service);
+ static int GetServiceNotificationNextNotification(const Service::Ptr& service);
+ static int GetServiceNotificationNotificationNumber(const Service::Ptr& service);
+ static double GetServiceNotificationNotificationInterval(const Service::Ptr& service);
+ static String GetServiceNotificationNotificationPeriod(const Service::Ptr& service);
+ static String GetServiceNotificationNotificationOptions(const Service::Ptr& service);
+ static int GetServiceNotificationTypeFilter(const Service::Ptr& service);
+ static int GetServiceNotificationStateFilter(const Service::Ptr& service);
+ static int GetServiceNotifyOnWarning(const Service::Ptr& service);
+ static int GetServiceNotifyOnCritical(const Service::Ptr& service);
+ static int GetServiceNotifyOnUnknown(const Service::Ptr& service);
+ static int GetServiceNotifyOnRecovery(const Service::Ptr& service);
+ static int GetServiceNotifyOnFlapping(const Service::Ptr& service);
+ static int GetServiceNotifyOnDowntime(const Service::Ptr& service);
static std::set<User::Ptr> GetServiceNotificationUsers(const Service::Ptr& service);
static std::set<UserGroup::Ptr> GetServiceNotificationUserGroups(const Service::Ptr& service);
- static std::pair<String, String> GetCheckResultOutput(const CheckResult::Ptr& cr);
+ /* command */
+ static String GetCommandLine(const Command::Ptr& command);
+
+ /* custom attribute */
+ static String GetCustomAttributeConfig(const DynamicObject::Ptr& object, const String& name);
+ static Dictionary::Ptr GetCustomVariableConfig(const DynamicObject::Ptr& object);
+
+ /* check result */
+ static String GetCheckResultOutput(const CheckResult::Ptr& cr);
+ static String GetCheckResultLongOutput(const CheckResult::Ptr& cr);
static String GetCheckResultPerfdata(const CheckResult::Ptr& cr);
+ /* misc */
static std::pair<unsigned long, unsigned long> ConvertTimestamp(double time);
static int MapNotificationReasonType(NotificationType type);