Value ServicesTable::ProcessPerformanceDataAccessor(const Value& row) { Service::Ptr service = static_cast<Service::Ptr>(row); if (!service) return Empty; return Convert::ToLong(service->GetEnablePerfdata()); }
void GraphiteWriter::CheckResultHandler(const Service::Ptr& service, const CheckResult::Ptr& cr) { if (!IcingaApplication::GetInstance()->GetEnablePerfdata() || !service->GetEnablePerfdata()) return; /* TODO: sanitize host and service names */ String hostName = service->GetHost()->GetName(); String serviceName = service->GetShortName(); SanitizeMetric(hostName); SanitizeMetric(serviceName); String prefix = "icinga." + hostName + "." + serviceName; /* basic metrics */ SendMetric(prefix, "current_attempt", service->GetCheckAttempt()); SendMetric(prefix, "max_check_attempts", service->GetMaxCheckAttempts()); SendMetric(prefix, "state_type", service->GetStateType()); SendMetric(prefix, "state", service->GetState()); SendMetric(prefix, "latency", Service::CalculateLatency(cr)); SendMetric(prefix, "execution_time", Service::CalculateExecutionTime(cr)); Value pdv = cr->GetPerformanceData(); if (!pdv.IsObjectType<Dictionary>()) return; Dictionary::Ptr perfdata = pdv; ObjectLock olock(perfdata); BOOST_FOREACH(const Dictionary::Pair& kv, perfdata) { double valueNum; if (!kv.second.IsObjectType<PerfdataValue>()) valueNum = kv.second; else valueNum = static_cast<PerfdataValue::Ptr>(kv.second)->GetValue(); String escaped_key = kv.first; SanitizeMetric(escaped_key); boost::algorithm::replace_all(escaped_key, "::", "."); SendMetric(prefix, escaped_key, valueNum); }
void StatusDataWriter::DumpServiceObject(std::ostream& fp, const Service::Ptr& service) { Host::Ptr host = service->GetHost(); { ObjectLock olock(service); fp << "define service {" "\n" "\t" "host_name" "\t" << host->GetName() << "\n" "\t" "service_description" "\t" << service->GetShortName() << "\n" "\t" "display_name" "\t" << service->GetDisplayName() << "\n" "\t" "check_interval" "\t" << (service->GetCheckInterval() / 60.0) << "\n" "\t" "retry_interval" "\t" << (service->GetRetryInterval() / 60.0) << "\n" "\t" "max_check_attempts" "\t" << service->GetMaxCheckAttempts() << "\n" "\t" "active_checks_enabled" "\t" << Convert::ToLong(service->GetEnableActiveChecks()) << "\n" "\t" "passive_checks_enabled" "\t" << Convert::ToLong(service->GetEnablePassiveChecks()) << "\n" "\t" "flap_detection_enabled" "\t" << Convert::ToLong(service->GetEnableFlapping()) << "\n" "\t" "is_volatile" "\t" << Convert::ToLong(service->GetVolatile()) << "\n" "\t" "notifications_enabled" "\t" << Convert::ToLong(service->GetEnableNotifications()) << "\n" "\t" "notification_options" "\t" << GetNotificationOptions(service) << "\n" "\t" "notification_interval" "\t" << CompatUtility::GetCheckableNotificationNotificationInterval(service) << "\n" "\t" "notification_period" "\t" << "" << "\n" "\t" "event_handler_enabled" "\t" << Convert::ToLong(service->GetEnableEventHandler()) << "\n"; CheckCommand::Ptr checkcommand = service->GetCheckCommand(); if (checkcommand) fp << "\t" "check_command" "\t" << CompatUtility::GetCommandName(checkcommand) << "!" << CompatUtility::GetCheckableCommandArgs(service)<< "\n"; EventCommand::Ptr eventcommand = service->GetEventCommand(); if (eventcommand && service->GetEnableEventHandler()) fp << "\t" "event_handler" "\t" << CompatUtility::GetCommandName(eventcommand) << "\n"; TimePeriod::Ptr checkPeriod = service->GetCheckPeriod(); if (checkPeriod) fp << "\t" "check_period" "\t" << checkPeriod->GetName() << "\n"; fp << "\t" "contacts" "\t"; DumpNameList(fp, CompatUtility::GetCheckableNotificationUsers(service)); fp << "\n"; fp << "\t" "contact_groups" "\t"; DumpNameList(fp, CompatUtility::GetCheckableNotificationUserGroups(service)); fp << "\n"; String notes = service->GetNotes(); String notes_url = service->GetNotesUrl(); String action_url = service->GetActionUrl(); String icon_image = service->GetIconImage(); String icon_image_alt = service->GetIconImageAlt(); fp << "\t" "initial_state" "\t" "o" "\n" "\t" "low_flap_threshold" "\t" << service->GetFlappingThresholdLow() << "\n" "\t" "high_flap_threshold" "\t" << service->GetFlappingThresholdHigh() << "\n" "\t" "process_perf_data" "\t" << Convert::ToLong(service->GetEnablePerfdata()) << "\n" "\t" "check_freshness" << "\t" "1" "\n"; if (!notes.IsEmpty()) fp << "\t" "notes" "\t" << notes << "\n"; if (!notes_url.IsEmpty()) fp << "\t" "notes_url" "\t" << notes_url << "\n"; if (!action_url.IsEmpty()) fp << "\t" "action_url" "\t" << action_url << "\n"; if (!icon_image.IsEmpty()) fp << "\t" "icon_image" "\t" << icon_image << "\n"; if (!icon_image_alt.IsEmpty()) fp << "\t" "icon_image_alt" "\t" << icon_image_alt << "\n"; } fp << "\t" "service_groups" "\t"; bool first = true; Array::Ptr groups = service->GetGroups(); if (groups) { ObjectLock olock(groups); for (const String& name : groups) { ServiceGroup::Ptr sg = ServiceGroup::GetByName(name); if (sg) { if (!first) fp << ","; else first = false; fp << sg->GetName(); } } } fp << "\n"; DumpCustomAttributes(fp, service); fp << "\t" "}" "\n" "\n"; }