Value ServicesTable::CurrentAttemptAccessor(const Value& row) { Service::Ptr service = static_cast<Service::Ptr>(row); if (!service) return Empty; return service->GetCheckAttempt(); }
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); }
Dictionary::Ptr ServiceDbObject::GetStatusFields(void) const { Dictionary::Ptr fields = make_shared<Dictionary>(); Service::Ptr service = static_pointer_cast<Service>(GetObject()); 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", service->GetState()); fields->Set("has_been_checked", CompatUtility::GetCheckableHasBeenChecked(service)); fields->Set("should_be_scheduled", service->GetEnableActiveChecks()); 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::GetCheckableCheckType(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::GetCheckableNotificationLastNotification(service))); fields->Set("next_notification", DbValue::FromTimestamp(CompatUtility::GetCheckableNotificationNextNotification(service))); fields->Set("no_more_notifications", Empty); fields->Set("notifications_enabled", CompatUtility::GetCheckableNotificationsEnabled(service)); fields->Set("problem_has_been_acknowledged", CompatUtility::GetCheckableProblemHasBeenAcknowledged(service)); fields->Set("acknowledgement_type", CompatUtility::GetCheckableAcknowledgementType(service)); fields->Set("current_notification_number", CompatUtility::GetCheckableNotificationNotificationNumber(service)); fields->Set("passive_checks_enabled", CompatUtility::GetCheckablePassiveChecksEnabled(service)); fields->Set("active_checks_enabled", CompatUtility::GetCheckableActiveChecksEnabled(service)); fields->Set("event_handler_enabled", CompatUtility::GetCheckableEventHandlerEnabled(service)); fields->Set("flap_detection_enabled", CompatUtility::GetCheckableFlapDetectionEnabled(service)); fields->Set("is_flapping", CompatUtility::GetCheckableIsFlapping(service)); fields->Set("percent_state_change", CompatUtility::GetCheckablePercentStateChange(service)); if (cr) { fields->Set("latency", Convert::ToString(Service::CalculateLatency(cr))); fields->Set("execution_time", Convert::ToString(Service::CalculateExecutionTime(cr))); } fields->Set("scheduled_downtime_depth", service->GetDowntimeDepth()); fields->Set("process_performance_data", CompatUtility::GetCheckableProcessPerformanceData(service)); fields->Set("event_handler", CompatUtility::GetCheckableEventHandler(service)); fields->Set("check_command", CompatUtility::GetCheckableCheckCommand(service)); fields->Set("normal_check_interval", CompatUtility::GetCheckableCheckInterval(service)); fields->Set("retry_check_interval", CompatUtility::GetCheckableRetryInterval(service)); fields->Set("check_timeperiod_object_id", service->GetCheckPeriod()); fields->Set("modified_service_attributes", service->GetModifiedAttributes()); return fields; }