int CompatUtility::GetCheckableInCheckPeriod(const Checkable::Ptr& checkable) { TimePeriod::Ptr timeperiod = checkable->GetCheckPeriod(); /* none set means always checked */ if (!timeperiod) return 1; return (timeperiod->IsInside(Utility::GetTime()) ? 1 : 0); }
int CompatUtility::GetCheckableInNotificationPeriod(const Checkable::Ptr& checkable) { for (const Notification::Ptr& notification : checkable->GetNotifications()) { TimePeriod::Ptr timeperiod = notification->GetPeriod(); if (!timeperiod || timeperiod->IsInside(Utility::GetTime())) return 1; } return 0; }
Value ContactsTable::InServiceNotificationPeriodAccessor(const Value& row) { User::Ptr user = static_cast<User::Ptr>(row); if (!user) return Empty; TimePeriod::Ptr timeperiod = user->GetPeriod(); if (!timeperiod) return Empty; return (timeperiod->IsInside(Utility::GetTime()) ? 1 : 0); }
Value ServicesTable::CheckPeriodAccessor(const Value& row) { Service::Ptr service = static_cast<Service::Ptr>(row); if (!service) return Empty; TimePeriod::Ptr checkPeriod = service->GetCheckPeriod(); if (!checkPeriod) return Empty; return checkPeriod->GetName(); }
Value ContactsTable::ServiceNotificationPeriodAccessor(const Value& row) { User::Ptr user = static_cast<User::Ptr>(row); if (!user) return Empty; TimePeriod::Ptr timeperiod = user->GetPeriod(); if (!timeperiod) return Empty; return timeperiod->GetName(); }
Value ServicesTable::InCheckPeriodAccessor(const Value& row) { Service::Ptr service = static_cast<Service::Ptr>(row); if (!service) return Empty; TimePeriod::Ptr timeperiod = service->GetCheckPeriod(); /* none set means always checked */ if (!timeperiod) return 1; return Convert::ToLong(timeperiod->IsInside(Utility::GetTime())); }
Value ServicesTable::InNotificationPeriodAccessor(const Value& row) { Service::Ptr service = static_cast<Service::Ptr>(row); if (!service) return Empty; for (const Notification::Ptr& notification : service->GetNotifications()) { TimePeriod::Ptr timeperiod = notification->GetPeriod(); if (!timeperiod || timeperiod->IsInside(Utility::GetTime())) return 1; } return 0; }
void TimePeriod::Merge(const TimePeriod::Ptr& timeperiod, bool include) { Log(LogDebug, "TimePeriod") << "Merge TimePeriod '" << GetName() << "' with '" << timeperiod->GetName() << "' " << "Method: " << (include ? "include" : "exclude"); Array::Ptr segments = timeperiod->GetSegments(); if (segments) { ObjectLock dlock(segments); ObjectLock ilock(this); for (const Dictionary::Ptr& segment : segments) { include ? AddSegment(segment) : RemoveSegment(segment); } } }
void StatusDataWriter::DumpTimePeriod(std::ostream& fp, const TimePeriod::Ptr& tp) { fp << "define timeperiod {" "\n" "\t" "timeperiod_name" "\t" << tp->GetName() << "\n" "\t" "alias" "\t" << tp->GetName() << "\n"; Dictionary::Ptr ranges = tp->GetRanges(); if (ranges) { ObjectLock olock(ranges); for (const Dictionary::Pair& kv : ranges) { fp << "\t" << kv.first << "\t" << kv.second << "\n"; } } fp << "\t" "}" "\n" "\n"; }
Array::Ptr LegacyTimePeriod::ScriptFunc(const TimePeriod::Ptr& tp, double begin, double end) { Array::Ptr segments = new Array(); Dictionary::Ptr ranges = tp->GetRanges(); if (ranges) { for (int i = 0; i <= (end - begin) / (24 * 60 * 60); i++) { time_t refts = begin + i * 24 * 60 * 60; tm reference = Utility::LocalTime(refts); #ifdef I2_DEBUG Log(LogDebug, "LegacyTimePeriod") << "Checking reference time " << refts; #endif /* I2_DEBUG */ ObjectLock olock(ranges); for (const Dictionary::Pair& kv : ranges) { if (!IsInDayDefinition(kv.first, &reference)) { #ifdef I2_DEBUG Log(LogDebug, "LegacyTimePeriod") << "Not in day definition '" << kv.first << "'."; #endif /* I2_DEBUG */ continue; } #ifdef I2_DEBUG Log(LogDebug, "LegacyTimePeriod") << "In day definition '" << kv.first << "'."; #endif /* I2_DEBUG */ ProcessTimeRanges(kv.second, &reference, segments); } } } Log(LogDebug, "LegacyTimePeriod") << "Legacy timeperiod update returned " << segments->GetLength() << " segments."; return segments; }
void CheckerComponent::CheckThreadProc() { Utility::SetThreadName("Check Scheduler"); IcingaApplication::Ptr icingaApp = IcingaApplication::GetInstance(); boost::mutex::scoped_lock lock(m_Mutex); for (;;) { typedef boost::multi_index::nth_index<CheckableSet, 1>::type CheckTimeView; CheckTimeView& idx = boost::get<1>(m_IdleCheckables); while (idx.begin() == idx.end() && !m_Stopped) m_CV.wait(lock); if (m_Stopped) break; auto it = idx.begin(); CheckableScheduleInfo csi = *it; double wait = csi.NextCheck - Utility::GetTime(); //#ifdef I2_DEBUG // Log(LogDebug, "CheckerComponent") // << "Pending checks " << Checkable::GetPendingChecks() // << " vs. max concurrent checks " << icingaApp->GetMaxConcurrentChecks() << "."; //#endif /* I2_DEBUG */ if (Checkable::GetPendingChecks() >= icingaApp->GetMaxConcurrentChecks()) wait = 0.5; if (wait > 0) { /* Wait for the next check. */ m_CV.timed_wait(lock, boost::posix_time::milliseconds(long(wait * 1000))); continue; } Checkable::Ptr checkable = csi.Object; m_IdleCheckables.erase(checkable); bool forced = checkable->GetForceNextCheck(); bool check = true; if (!forced) { if (!checkable->IsReachable(DependencyCheckExecution)) { Log(LogNotice, "CheckerComponent") << "Skipping check for object '" << checkable->GetName() << "': Dependency failed."; check = false; } Host::Ptr host; Service::Ptr service; tie(host, service) = GetHostService(checkable); if (host && !service && (!checkable->GetEnableActiveChecks() || !icingaApp->GetEnableHostChecks())) { Log(LogNotice, "CheckerComponent") << "Skipping check for host '" << host->GetName() << "': active host checks are disabled"; check = false; } if (host && service && (!checkable->GetEnableActiveChecks() || !icingaApp->GetEnableServiceChecks())) { Log(LogNotice, "CheckerComponent") << "Skipping check for service '" << service->GetName() << "': active service checks are disabled"; check = false; } TimePeriod::Ptr tp = checkable->GetCheckPeriod(); if (tp && !tp->IsInside(Utility::GetTime())) { Log(LogNotice, "CheckerComponent") << "Skipping check for object '" << checkable->GetName() << "': not in check period '" << tp->GetName() << "'"; check = false; } } /* reschedule the checkable if checks are disabled */ if (!check) { m_IdleCheckables.insert(GetCheckableScheduleInfo(checkable)); lock.unlock(); Log(LogDebug, "CheckerComponent") << "Checks for checkable '" << checkable->GetName() << "' are disabled. Rescheduling check."; checkable->UpdateNextCheck(); lock.lock(); continue; } csi = GetCheckableScheduleInfo(checkable); Log(LogDebug, "CheckerComponent") << "Scheduling info for checkable '" << checkable->GetName() << "' (" << Utility::FormatDateTime("%Y-%m-%d %H:%M:%S %z", checkable->GetNextCheck()) << "): Object '" << csi.Object->GetName() << "', Next Check: " << Utility::FormatDateTime("%Y-%m-%d %H:%M:%S %z", csi.NextCheck) << "(" << csi.NextCheck << ")."; m_PendingCheckables.insert(csi); lock.unlock(); if (forced) { ObjectLock olock(checkable); checkable->SetForceNextCheck(false); } Log(LogDebug, "CheckerComponent") << "Executing check for '" << checkable->GetName() << "'"; Checkable::IncreasePendingChecks(); Utility::QueueAsyncCallback(std::bind(&CheckerComponent::ExecuteCheckHelper, CheckerComponent::Ptr(this), checkable)); lock.lock(); } }
void StatusDataWriter::DumpCheckableStatusAttrs(std::ostream& fp, const Checkable::Ptr& checkable) { CheckResult::Ptr cr = checkable->GetLastCheckResult(); EventCommand::Ptr eventcommand = checkable->GetEventCommand(); CheckCommand::Ptr checkcommand = checkable->GetCheckCommand(); fp << "\t" << "check_command=" << CompatUtility::GetCommandName(checkcommand) << "!" << CompatUtility::GetCheckableCommandArgs(checkable) << "\n" "\t" "event_handler=" << CompatUtility::GetCommandName(eventcommand) << "\n" "\t" "check_interval=" << (checkable->GetCheckInterval() / 60.0) << "\n" "\t" "retry_interval=" << (checkable->GetRetryInterval() / 60.0) << "\n" "\t" "has_been_checked=" << Convert::ToLong(checkable->HasBeenChecked()) << "\n" "\t" "should_be_scheduled=" << checkable->GetEnableActiveChecks() << "\n" "\t" "event_handler_enabled=" << Convert::ToLong(checkable->GetEnableEventHandler()) << "\n"; TimePeriod::Ptr checkPeriod = checkable->GetCheckPeriod(); if (checkPeriod) fp << "\t" "check_period" "\t" << checkPeriod->GetName() << "\n"; if (cr) { fp << "\t" << "check_execution_time=" << Convert::ToString(cr->CalculateExecutionTime()) << "\n" "\t" "check_latency=" << Convert::ToString(cr->CalculateLatency()) << "\n"; } Host::Ptr host; Service::Ptr service; tie(host, service) = GetHostService(checkable); if (service) { fp << "\t" "current_state=" << service->GetState() << "\n" "\t" "last_hard_state=" << service->GetLastHardState() << "\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"; } else { int currentState = host->GetState(); if (currentState != HostUp && !host->IsReachable()) currentState = 2; /* hardcoded compat state */ fp << "\t" "current_state=" << currentState << "\n" "\t" "last_hard_state=" << host->GetLastHardState() << "\n" "\t" "last_time_up=" << static_cast<int>(host->GetLastStateUp()) << "\n" "\t" "last_time_down=" << static_cast<int>(host->GetLastStateDown()) << "\n"; } fp << "\t" "state_type=" << checkable->GetStateType() << "\n" "\t" "last_check=" << static_cast<long>(host->GetLastCheck()) << "\n"; if (cr) { fp << "\t" "plugin_output=" << CompatUtility::GetCheckResultOutput(cr) << "\n" "\t" "long_plugin_output=" << CompatUtility::GetCheckResultLongOutput(cr) << "\n" "\t" "performance_data=" << PluginUtility::FormatPerfdata(cr->GetPerformanceData()) << "\n"; } fp << "\t" << "next_check=" << static_cast<long>(checkable->GetNextCheck()) << "\n" "\t" "current_attempt=" << checkable->GetCheckAttempt() << "\n" "\t" "max_attempts=" << checkable->GetMaxCheckAttempts() << "\n" "\t" "last_state_change=" << static_cast<long>(checkable->GetLastStateChange()) << "\n" "\t" "last_hard_state_change=" << static_cast<long>(checkable->GetLastHardStateChange()) << "\n" "\t" "last_update=" << static_cast<long>(Utility::GetTime()) << "\n" "\t" "notifications_enabled=" << Convert::ToLong(checkable->GetEnableNotifications()) << "\n" "\t" "active_checks_enabled=" << Convert::ToLong(checkable->GetEnableActiveChecks()) << "\n" "\t" "passive_checks_enabled=" << Convert::ToLong(checkable->GetEnablePassiveChecks()) << "\n" "\t" "flap_detection_enabled=" << Convert::ToLong(checkable->GetEnableFlapping()) << "\n" "\t" "is_flapping=" << Convert::ToLong(checkable->IsFlapping()) << "\n" "\t" "percent_state_change=" << checkable->GetFlappingCurrent() << "\n" "\t" "problem_has_been_acknowledged=" << (checkable->GetAcknowledgement() != AcknowledgementNone ? 1 : 0) << "\n" "\t" "acknowledgement_type=" << checkable->GetAcknowledgement() << "\n" "\t" "acknowledgement_end_time=" << checkable->GetAcknowledgementExpiry() << "\n" "\t" "scheduled_downtime_depth=" << checkable->GetDowntimeDepth() << "\n" "\t" "last_notification=" << CompatUtility::GetCheckableNotificationLastNotification(checkable) << "\n" "\t" "next_notification=" << CompatUtility::GetCheckableNotificationNextNotification(checkable) << "\n" "\t" "current_notification_number=" << CompatUtility::GetCheckableNotificationNotificationNumber(checkable) << "\n" "\t" "is_reachable=" << Convert::ToLong(checkable->IsReachable()) << "\n"; }
void StatusDataWriter::DumpHostObject(std::ostream& fp, const Host::Ptr& host) { String notes = host->GetNotes(); String notes_url = host->GetNotesUrl(); String action_url = host->GetActionUrl(); String icon_image = host->GetIconImage(); String icon_image_alt = host->GetIconImageAlt(); String display_name = host->GetDisplayName(); String address = host->GetAddress(); String address6 = host->GetAddress6(); fp << "define host {" "\n" "\t" "host_name" "\t" << host->GetName() << "\n"; if (!display_name.IsEmpty()) { fp << "\t" "display_name" "\t" << host->GetDisplayName() << "\n" "\t" "alias" "\t" << host->GetDisplayName() << "\n"; } if (!address.IsEmpty()) fp << "\t" "address" "\t" << address << "\n"; if (!address6.IsEmpty()) fp << "\t" "address6" "\t" << address6 << "\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"; std::set<Checkable::Ptr> parents = host->GetParents(); if (!parents.empty()) { fp << "\t" "parents" "\t"; DumpNameList(fp, parents); fp << "\n"; } ObjectLock olock(host); fp << "\t" "check_interval" "\t" << (host->GetCheckInterval() / 60.0) << "\n" "\t" "retry_interval" "\t" << (host->GetRetryInterval() / 60.0) << "\n" "\t" "max_check_attempts" "\t" << host->GetMaxCheckAttempts() << "\n" "\t" "active_checks_enabled" "\t" << Convert::ToLong(host->GetEnableActiveChecks()) << "\n" "\t" "passive_checks_enabled" "\t" << Convert::ToLong(host->GetEnablePassiveChecks()) << "\n" "\t" "notifications_enabled" "\t" << Convert::ToLong(host->GetEnableNotifications()) << "\n" "\t" "notification_options" "\t" << GetNotificationOptions(host) << "\n" "\t" "notification_interval" "\t" << CompatUtility::GetCheckableNotificationNotificationInterval(host) << "\n" "\t" "event_handler_enabled" "\t" << Convert::ToLong(host->GetEnableEventHandler()) << "\n"; CheckCommand::Ptr checkcommand = host->GetCheckCommand(); if (checkcommand) fp << "\t" "check_command" "\t" << CompatUtility::GetCommandName(checkcommand) << "!" << CompatUtility::GetCheckableCommandArgs(host) << "\n"; EventCommand::Ptr eventcommand = host->GetEventCommand(); if (eventcommand && host->GetEnableEventHandler()) fp << "\t" "event_handler" "\t" << CompatUtility::GetCommandName(eventcommand) << "\n"; TimePeriod::Ptr checkPeriod = host->GetCheckPeriod(); if (checkPeriod) fp << "\t" "check_period" "\t" << checkPeriod->GetName() << "\n"; fp << "\t" "contacts" "\t"; DumpNameList(fp, CompatUtility::GetCheckableNotificationUsers(host)); fp << "\n"; fp << "\t" "contact_groups" "\t"; DumpNameList(fp, CompatUtility::GetCheckableNotificationUserGroups(host)); fp << "\n"; fp << "\t" << "initial_state" "\t" "o" "\n" "\t" "low_flap_threshold" "\t" << host->GetFlappingThresholdLow() << "\n" "\t" "high_flap_threshold" "\t" << host->GetFlappingThresholdHigh() << "\n" "\t" "process_perf_data" "\t" << Convert::ToLong(host->GetEnablePerfdata()) << "\n" "\t" "check_freshness" "\t" "1" "\n"; fp << "\t" "host_groups" "\t"; bool first = true; Array::Ptr groups = host->GetGroups(); if (groups) { ObjectLock olock(groups); for (const String& name : groups) { HostGroup::Ptr hg = HostGroup::GetByName(name); if (hg) { if (!first) fp << ","; else first = false; fp << hg->GetName(); } } } fp << "\n"; DumpCustomAttributes(fp, host); fp << "\t" "}" "\n" "\n"; }
bool Notification::CheckNotificationUserFilters(NotificationType type, const User::Ptr& user, bool force, bool reminder) { if (!force) { TimePeriod::Ptr tp = user->GetPeriod(); if (tp && !tp->IsInside(Utility::GetTime())) { Log(LogNotice, "Notification") << "Not sending " << (reminder ? "reminder " : " ") << "notifications for notification object '" << GetName() << " and user '" << user->GetName() << "': user period not in timeperiod '" << tp->GetName() << "'"; return false; } unsigned long ftype = type; Log(LogDebug, "Notification") << "User notification, Type '" << NotificationTypeToStringInternal(type) << "', TypeFilter: " << NotificationFilterToString(user->GetTypeFilter(), GetTypeFilterMap()) << " (FType=" << ftype << ", TypeFilter=" << GetTypeFilter() << ")"; if (!(ftype & user->GetTypeFilter())) { Log(LogNotice, "Notification") << "Not sending " << (reminder ? "reminder " : " ") << "notifications for notification object '" << GetName() << " and user '" << user->GetName() << "': type '" << NotificationTypeToStringInternal(type) << "' does not match type filter: " << NotificationFilterToString(user->GetTypeFilter(), GetTypeFilterMap()) << "."; return false; } /* check state filters it this is not a recovery notification */ if (type != NotificationRecovery) { Checkable::Ptr checkable = GetCheckable(); Host::Ptr host; Service::Ptr service; tie(host, service) = GetHostService(checkable); unsigned long fstate; String stateStr; if (service) { fstate = ServiceStateToFilter(service->GetState()); stateStr = NotificationServiceStateToString(service->GetState()); } else { fstate = HostStateToFilter(host->GetState()); stateStr = NotificationHostStateToString(host->GetState()); } Log(LogDebug, "Notification") << "User notification, State '" << stateStr << "', StateFilter: " << NotificationFilterToString(user->GetStateFilter(), GetStateFilterMap()) << " (FState=" << fstate << ", StateFilter=" << user->GetStateFilter() << ")"; if (!(fstate & user->GetStateFilter())) { Log(LogNotice, "Notification") << "Not " << (reminder ? "reminder " : " ") << "sending notifications for notification object '" << GetName() << " and user '" << user->GetName() << "': state '" << stateStr << "' does not match state filter: " << NotificationFilterToString(user->GetStateFilter(), GetStateFilterMap()) << "."; return false; } } } else { Log(LogNotice, "Notification") << "Not checking " << (reminder ? "reminder " : " ") << "notification filters for notification object '" << GetName() << "' and user '" << user->GetName() << "': Notification was forced."; } return true; }
void Notification::BeginExecuteNotification(NotificationType type, const CheckResult::Ptr& cr, bool force, bool reminder, const String& author, const String& text) { Log(LogNotice, "Notification") << "Attempting to send " << (reminder ? "reminder " : " ") << "notifications for notification object '" << GetName() << "'."; Checkable::Ptr checkable = GetCheckable(); if (!force) { TimePeriod::Ptr tp = GetPeriod(); if (tp && !tp->IsInside(Utility::GetTime())) { Log(LogNotice, "Notification") << "Not sending " << (reminder ? "reminder " : " ") << "notifications for notification object '" << GetName() << "': not in timeperiod '" << tp->GetName() << "'"; return; } double now = Utility::GetTime(); Dictionary::Ptr times = GetTimes(); if (times && type == NotificationProblem) { Value timesBegin = times->Get("begin"); Value timesEnd = times->Get("end"); if (timesBegin != Empty && timesBegin >= 0 && now < checkable->GetLastHardStateChange() + timesBegin) { Log(LogNotice, "Notification") << "Not sending " << (reminder ? "reminder " : " ") << "notifications for notification object '" << GetName() << "': before specified begin time (" << Utility::FormatDuration(timesBegin) << ")"; /* we need to adjust the next notification time * to now + begin delaying the first notification */ double nextProposedNotification = now + timesBegin + 1.0; if (GetNextNotification() > nextProposedNotification) SetNextNotification(nextProposedNotification); return; } if (timesEnd != Empty && timesEnd >= 0 && now > checkable->GetLastHardStateChange() + timesEnd) { Log(LogNotice, "Notification") << "Not sending " << (reminder ? "reminder " : " ") << "notifications for notification object '" << GetName() << "': after specified end time (" << Utility::FormatDuration(timesEnd) << ")"; return; } } unsigned long ftype = type; Log(LogDebug, "Notification") << "Type '" << NotificationTypeToStringInternal(type) << "', TypeFilter: " << NotificationFilterToString(GetTypeFilter(), GetTypeFilterMap()) << " (FType=" << ftype << ", TypeFilter=" << GetTypeFilter() << ")"; if (!(ftype & GetTypeFilter())) { Log(LogNotice, "Notification") << "Not sending " << (reminder ? "reminder " : " ") << "notifications for notification object '" << GetName() << "': type '" << NotificationTypeToStringInternal(type) << "' does not match type filter: " << NotificationFilterToString(GetTypeFilter(), GetTypeFilterMap()) << "."; return; } /* ensure that recovery notifications are always sent, no state filter checks necessary */ if (type != NotificationRecovery) { Host::Ptr host; Service::Ptr service; tie(host, service) = GetHostService(checkable); unsigned long fstate; String stateStr; if (service) { fstate = ServiceStateToFilter(service->GetState()); stateStr = NotificationServiceStateToString(service->GetState()); } else { fstate = HostStateToFilter(host->GetState()); stateStr = NotificationHostStateToString(host->GetState()); } Log(LogDebug, "Notification") << "State '" << stateStr << "', StateFilter: " << NotificationFilterToString(GetStateFilter(), GetStateFilterMap()) << " (FState=" << fstate << ", StateFilter=" << GetStateFilter() << ")"; if (!(fstate & GetStateFilter())) { Log(LogNotice, "Notification") << "Not sending " << (reminder ? "reminder " : " ") << "notifications for notification object '" << GetName() << "': state '" << stateStr << "' does not match state filter: " << NotificationFilterToString(GetStateFilter(), GetStateFilterMap()) << "."; return; } } } else { Log(LogNotice, "Notification") << "Not checking " << (reminder ? "reminder " : " ") << "notification filters for notification object '" << GetName() << "': Notification was forced."; } { ObjectLock olock(this); UpdateNotificationNumber(); double now = Utility::GetTime(); SetLastNotification(now); if (type == NotificationProblem && GetInterval() <= 0) SetNoMoreNotifications(true); else SetNoMoreNotifications(false); if (type == NotificationProblem && GetInterval() > 0) SetNextNotification(now + GetInterval()); if (type == NotificationProblem) SetLastProblemNotification(now); } std::set<User::Ptr> allUsers; std::set<User::Ptr> users = GetUsers(); std::copy(users.begin(), users.end(), std::inserter(allUsers, allUsers.begin())); for (const UserGroup::Ptr& ug : GetUserGroups()) { std::set<User::Ptr> members = ug->GetMembers(); std::copy(members.begin(), members.end(), std::inserter(allUsers, allUsers.begin())); } std::set<User::Ptr> allNotifiedUsers; Array::Ptr notifiedProblemUsers = GetNotifiedProblemUsers(); for (const User::Ptr& user : allUsers) { String userName = user->GetName(); if (!user->GetEnableNotifications()) { Log(LogNotice, "Notification") << "Disabled notifications for user '" << userName << "'. Not sending notification."; continue; } if (!CheckNotificationUserFilters(type, user, force, reminder)) { Log(LogNotice, "Notification") << "Notification filters for user '" << userName << "' not matched. Not sending notification."; continue; } /* on recovery, check if user was notified before */ if (type == NotificationRecovery) { if (!notifiedProblemUsers->Contains(userName)) { Log(LogNotice, "Notification") << "We did not notify user '" << userName << "' for a problem before. Not sending recovery notification."; continue; } } Log(LogInformation, "Notification") << "Sending " << (reminder ? "reminder " : "") << "'" << NotificationTypeToStringInternal(type) << "' notification '" << GetName() << " for user '" << userName << "'"; Utility::QueueAsyncCallback(boost::bind(&Notification::ExecuteNotificationHelper, this, type, user, cr, force, author, text)); /* collect all notified users */ allNotifiedUsers.insert(user); /* store all notified users for later recovery checks */ if (type == NotificationProblem && !notifiedProblemUsers->Contains(userName)) notifiedProblemUsers->Add(userName); } /* if this was a recovery notification, reset all notified users */ if (type == NotificationRecovery) notifiedProblemUsers->Clear(); /* used in db_ido for notification history */ Service::OnNotificationSentToAllUsers(this, checkable, allNotifiedUsers, type, cr, author, text, MessageOrigin::Ptr()); }
bool Dependency::IsAvailable(DependencyType dt) const { Checkable::Ptr parent = GetParent(); Host::Ptr parentHost; Service::Ptr parentService; tie(parentHost, parentService) = GetHostService(parent); /* ignore if it's the same checkable object */ if (parent == GetChild()) { Log(LogNotice, "Dependency") << "Dependency '" << GetName() << "' passed: Parent and child " << (parentService ? "service" : "host") << " are identical."; return true; } /* ignore pending */ if (!parent->GetLastCheckResult()) { Log(LogNotice, "Dependency") << "Dependency '" << GetName() << "' passed: Parent " << (parentService ? "service" : "host") << " '" << parent->GetName() << "' hasn't been checked yet."; return true; } if (GetIgnoreSoftStates()) { /* ignore soft states */ if (parent->GetStateType() == StateTypeSoft) { Log(LogNotice, "Dependency") << "Dependency '" << GetName() << "' passed: Parent " << (parentService ? "service" : "host") << " '" << parent->GetName() << "' is in a soft state."; return true; } } else { Log(LogNotice, "Dependency") << "Dependency '" << GetName() << "' failed: Parent " << (parentService ? "service" : "host") << " '" << parent->GetName() << "' is in a soft state."; } int state; if (parentService) state = ServiceStateToFilter(parentService->GetState()); else state = HostStateToFilter(parentHost->GetState()); /* check state */ if (state & GetStateFilter()) { Log(LogNotice, "Dependency") << "Dependency '" << GetName() << "' passed: Parent " << (parentService ? "service" : "host") << " '" << parent->GetName() << "' matches state filter."; return true; } /* ignore if not in time period */ TimePeriod::Ptr tp = GetPeriod(); if (tp && !tp->IsInside(Utility::GetTime())) { Log(LogNotice, "Dependency") << "Dependency '" << GetName() << "' passed: Outside time period."; return true; } if (dt == DependencyCheckExecution && !GetDisableChecks()) { Log(LogNotice, "Dependency") << "Dependency '" << GetName() << "' passed: Checks are not disabled."; return true; } else if (dt == DependencyNotification && !GetDisableNotifications()) { Log(LogNotice, "Dependency") << "Dependency '" << GetName() << "' passed: Notifications are not disabled"; return true; } Log(LogNotice, "Dependency") << "Dependency '" << GetName() << "' failed. Parent " << (parentService ? "service" : "host") << " '" << parent->GetName() << "' is " << (parentService ? Service::StateToString(parentService->GetState()) : Host::StateToString(parentHost->GetState())); return false; }
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"; }