diff --git a/components/livestatus/hoststable.cpp b/components/livestatus/hoststable.cpp index 1b71cce29..d0309804e 100644 --- a/components/livestatus/hoststable.cpp +++ b/components/livestatus/hoststable.cpp @@ -475,6 +475,7 @@ Value HostsTable::AcknowledgementTypeAccessor(const Value& row) if (!host) return Empty; + ObjectLock olock(host); return CompatUtility::GetCheckableAcknowledgementType(host); } @@ -615,6 +616,7 @@ Value HostsTable::AcknowledgedAccessor(const Value& row) if (!host) return Empty; + ObjectLock olock(host); return CompatUtility::GetCheckableIsAcknowledged(host); } diff --git a/components/livestatus/query.cpp b/components/livestatus/query.cpp index 79720b203..fdac9a7e0 100644 --- a/components/livestatus/query.cpp +++ b/components/livestatus/query.cpp @@ -194,7 +194,7 @@ Query::Query(const std::vector& lines, const String& compat_log_path) aggregators.push_back(aggregator); stats.push_back(filter); - } else if (header == "Or" || header == "And") { + } else if (header == "Or" || header == "And" || header == "StatsOr" || header == "StatsAnd") { std::deque& deq = (header == "Or" || header == "And") ? filters : stats; unsigned int num = Convert::ToLong(params); @@ -219,9 +219,16 @@ Query::Query(const std::vector& lines, const String& compat_log_path) filter->AddSubFilter(deq.back()); Log(LogDebug, "livestatus", "Add " + Convert::ToString(num) + " filter."); deq.pop_back(); + if (&deq == &stats) + aggregators.pop_back(); } deq.push_back(filter); + if (&deq == &stats) { + Aggregator::Ptr aggregator = make_shared(); + aggregator->SetFilter(filter); + aggregators.push_back(aggregator); + } } else if (header == "Negate" || header == "StatsNegate") { std::deque& deq = (header == "Negate") ? filters : stats; diff --git a/components/livestatus/servicestable.cpp b/components/livestatus/servicestable.cpp index 450def9ab..f639e0ad2 100644 --- a/components/livestatus/servicestable.cpp +++ b/components/livestatus/servicestable.cpp @@ -490,6 +490,7 @@ Value ServicesTable::AcknowledgedAccessor(const Value& row) if (!service) return Empty; + ObjectLock olock(service); return CompatUtility::GetCheckableIsAcknowledged(service); } @@ -500,10 +501,8 @@ Value ServicesTable::AcknowledgementTypeAccessor(const Value& row) if (!service) return Empty; - /* important: lock acknowledgements */ ObjectLock olock(service); - - return static_cast(service->GetAcknowledgement()); + return CompatUtility::GetCheckableAcknowledgementType(service); } Value ServicesTable::NoMoreNotificationsAccessor(const Value& row) @@ -1056,10 +1055,9 @@ Value ServicesTable::CustomVariableNamesAccessor(const Value& row) Array::Ptr cv = make_shared(); - String key; - Value value; - BOOST_FOREACH(tie(key, value), vars) { - cv->Add(key); + ObjectLock olock(vars); + BOOST_FOREACH(const Dictionary::Pair kv, vars) { + cv->Add(kv.second); } return cv; @@ -1084,10 +1082,9 @@ Value ServicesTable::CustomVariableValuesAccessor(const Value& row) Array::Ptr cv = make_shared(); - String key; - Value value; - BOOST_FOREACH(tie(key, value), vars) { - cv->Add(value); + ObjectLock olock(vars); + BOOST_FOREACH(const Dictionary::Pair& kv, vars) { + cv->Add(kv.second); } return cv; diff --git a/lib/icinga/compatutility.cpp b/lib/icinga/compatutility.cpp index e115a4fe3..b177411cc 100644 --- a/lib/icinga/compatutility.cpp +++ b/lib/icinga/compatutility.cpp @@ -62,8 +62,6 @@ String CompatUtility::GetCommandLine(const Command::Ptr& command) /* host */ String CompatUtility::GetHostAlias(const Host::Ptr& host) { - ASSERT(host->OwnsLock()); - if (!host->GetDisplayName().IsEmpty()) return host->GetName(); else @@ -72,8 +70,6 @@ String CompatUtility::GetHostAlias(const Host::Ptr& host) int CompatUtility::GetHostNotifyOnDown(const Host::Ptr& host) { - ASSERT(host->OwnsLock()); - unsigned long notification_state_filter = GetCheckableNotificationStateFilter(host); if (notification_state_filter & (1<OwnsLock()); - unsigned long notification_state_filter = GetCheckableNotificationStateFilter(host); if (notification_state_filter & (1<OwnsLock()); - return (checkable->GetEnableActiveChecks() ? 0 : 1); } double CompatUtility::GetCheckableCheckInterval(const Checkable::Ptr& checkable) { - ASSERT(checkable->OwnsLock()); - return checkable->GetCheckInterval() / 60.0; } double CompatUtility::GetCheckableRetryInterval(const Checkable::Ptr& checkable) { - ASSERT(checkable->OwnsLock()); - return checkable->GetRetryInterval() / 60.0; } String CompatUtility::GetCheckableCheckPeriod(const Checkable::Ptr& checkable) { - ASSERT(checkable->OwnsLock()); - TimePeriod::Ptr check_period = checkable->GetCheckPeriod(); if (check_period) return check_period->GetName(); @@ -130,79 +116,57 @@ String CompatUtility::GetCheckableCheckPeriod(const Checkable::Ptr& checkable) int CompatUtility::GetCheckableHasBeenChecked(const Checkable::Ptr& checkable) { - ASSERT(checkable->OwnsLock()); - return (checkable->GetLastCheckResult() ? 1 : 0); } int CompatUtility::GetCheckableProblemHasBeenAcknowledged(const Checkable::Ptr& checkable) { - ASSERT(checkable->OwnsLock()); - return (checkable->GetAcknowledgement() != AcknowledgementNone ? 1 : 0); } int CompatUtility::GetCheckableAcknowledgementType(const Checkable::Ptr& checkable) { - ASSERT(checkable->OwnsLock()); - return static_cast(checkable->GetAcknowledgement()); } int CompatUtility::GetCheckablePassiveChecksEnabled(const Checkable::Ptr& checkable) { - ASSERT(checkable->OwnsLock()); - return (checkable->GetEnablePassiveChecks() ? 1 : 0); } int CompatUtility::GetCheckableActiveChecksEnabled(const Checkable::Ptr& checkable) { - ASSERT(checkable->OwnsLock()); - return (checkable->GetEnableActiveChecks() ? 1 : 0); } int CompatUtility::GetCheckableEventHandlerEnabled(const Checkable::Ptr& checkable) { - ASSERT(checkable->OwnsLock()); - return (checkable->GetEventCommand() ? 1 : 0); } int CompatUtility::GetCheckableFlapDetectionEnabled(const Checkable::Ptr& checkable) { - ASSERT(checkable->OwnsLock()); - return (checkable->GetEnableFlapping() ? 1 : 0); } int CompatUtility::GetCheckableIsFlapping(const Checkable::Ptr& checkable) { - ASSERT(checkable->OwnsLock()); - return (checkable->IsFlapping() ? 1 : 0); } String CompatUtility::GetCheckablePercentStateChange(const Checkable::Ptr& checkable) { - ASSERT(checkable->OwnsLock()); - return Convert::ToString(checkable->GetFlappingCurrent()); } int CompatUtility::GetCheckableProcessPerformanceData(const Checkable::Ptr& checkable) { - ASSERT(checkable->OwnsLock()); - return (checkable->GetEnablePerfdata() ? 1 : 0); } String CompatUtility::GetCheckableEventHandler(const Checkable::Ptr& checkable) { - ASSERT(checkable->OwnsLock()); - String event_command_str; EventCommand::Ptr eventcommand = checkable->GetEventCommand(); @@ -214,8 +178,6 @@ String CompatUtility::GetCheckableEventHandler(const Checkable::Ptr& checkable) String CompatUtility::GetCheckableCheckCommand(const Checkable::Ptr& checkable) { - ASSERT(checkable->OwnsLock()); - String check_command_str; CheckCommand::Ptr checkcommand = checkable->GetCheckCommand(); @@ -227,43 +189,31 @@ String CompatUtility::GetCheckableCheckCommand(const Checkable::Ptr& checkable) int CompatUtility::GetCheckableIsVolatile(const Checkable::Ptr& checkable) { - ASSERT(checkable->OwnsLock()); - return (checkable->GetVolatile() ? 1 : 0); } double CompatUtility::GetCheckableLowFlapThreshold(const Checkable::Ptr& checkable) { - ASSERT(checkable->OwnsLock()); - return checkable->GetFlappingThreshold(); } double CompatUtility::GetCheckableHighFlapThreshold(const Checkable::Ptr& checkable) { - ASSERT(checkable->OwnsLock()); - return checkable->GetFlappingThreshold(); } int CompatUtility::GetCheckableFreshnessChecksEnabled(const Checkable::Ptr& checkable) { - ASSERT(checkable->OwnsLock()); - return (checkable->GetCheckInterval() > 0 ? 1 : 0); } int CompatUtility::GetCheckableFreshnessThreshold(const Checkable::Ptr& checkable) { - ASSERT(checkable->OwnsLock()); - return static_cast(checkable->GetCheckInterval()); } double CompatUtility::GetCheckableStaleness(const Checkable::Ptr& checkable) { - ASSERT(checkable->OwnsLock()); - if (checkable->HasBeenChecked() && checkable->GetLastCheck() > 0) return (Utility::GetTime() - checkable->GetLastCheck()) / (checkable->GetCheckInterval() * 3600); @@ -272,15 +222,11 @@ double CompatUtility::GetCheckableStaleness(const Checkable::Ptr& checkable) int CompatUtility::GetCheckableIsAcknowledged(const Checkable::Ptr& checkable) { - ASSERT(checkable->OwnsLock()); - return (checkable->IsAcknowledged() ? 1 : 0); } int CompatUtility::GetCheckableNoMoreNotifications(const Checkable::Ptr& checkable) { - ASSERT(checkable->OwnsLock()); - if (CompatUtility::GetCheckableNotificationNotificationInterval(checkable) == 0 && !checkable->GetVolatile()) return 1; @@ -289,8 +235,6 @@ int CompatUtility::GetCheckableNoMoreNotifications(const Checkable::Ptr& checkab int CompatUtility::GetCheckableInCheckPeriod(const Checkable::Ptr& checkable) { - ASSERT(checkable->OwnsLock()); - TimePeriod::Ptr timeperiod = checkable->GetCheckPeriod(); /* none set means always checked */ @@ -302,8 +246,6 @@ int CompatUtility::GetCheckableInCheckPeriod(const Checkable::Ptr& checkable) int CompatUtility::GetCheckableInNotificationPeriod(const Checkable::Ptr& checkable) { - ASSERT(checkable->OwnsLock()); - BOOST_FOREACH(const Notification::Ptr& notification, checkable->GetNotifications()) { ObjectLock olock(notification); @@ -352,8 +294,6 @@ bool CompatUtility::IsLegacyAttribute(DynamicObject::Ptr const& object, const St Dictionary::Ptr CompatUtility::GetCustomAttributeConfig(const DynamicObject::Ptr& object) { - ASSERT(object->OwnsLock()); - Dictionary::Ptr vars = object->GetVars(); Dictionary::Ptr varsvars = make_shared(); @@ -374,8 +314,6 @@ Dictionary::Ptr CompatUtility::GetCustomAttributeConfig(const DynamicObject::Ptr String CompatUtility::GetCustomAttributeConfig(const DynamicObject::Ptr& object, const String& name) { - ASSERT(object->OwnsLock()); - Dictionary::Ptr vars = object->GetVars(); if (!vars) @@ -443,15 +381,11 @@ Array::Ptr CompatUtility::GetModifiedAttributesList(const DynamicObject::Ptr& ob /* notifications */ int CompatUtility::GetCheckableNotificationsEnabled(const Checkable::Ptr& checkable) { - ASSERT(checkable->OwnsLock()); - return (checkable->GetEnableNotifications() ? 1 : 0); } int CompatUtility::GetCheckableNotificationLastNotification(const Checkable::Ptr& checkable) { - ASSERT(checkable->OwnsLock()); - double last_notification = 0.0; BOOST_FOREACH(const Notification::Ptr& notification, checkable->GetNotifications()) { if (notification->GetLastNotification() > last_notification) @@ -463,8 +397,6 @@ int CompatUtility::GetCheckableNotificationLastNotification(const Checkable::Ptr int CompatUtility::GetCheckableNotificationNextNotification(const Checkable::Ptr& checkable) { - ASSERT(checkable->OwnsLock()); - double next_notification = 0.0; BOOST_FOREACH(const Notification::Ptr& notification, checkable->GetNotifications()) { if (next_notification == 0 || notification->GetNextNotification() < next_notification) @@ -476,8 +408,6 @@ int CompatUtility::GetCheckableNotificationNextNotification(const Checkable::Ptr int CompatUtility::GetCheckableNotificationNotificationNumber(const Checkable::Ptr& checkable) { - ASSERT(checkable->OwnsLock()); - int notification_number = 0; BOOST_FOREACH(const Notification::Ptr& notification, checkable->GetNotifications()) { if (notification->GetNotificationNumber() > notification_number) @@ -489,8 +419,6 @@ int CompatUtility::GetCheckableNotificationNotificationNumber(const Checkable::P double CompatUtility::GetCheckableNotificationNotificationInterval(const Checkable::Ptr& checkable) { - ASSERT(checkable->OwnsLock()); - double notification_interval = -1; BOOST_FOREACH(const Notification::Ptr& notification, checkable->GetNotifications()) { @@ -506,8 +434,6 @@ double CompatUtility::GetCheckableNotificationNotificationInterval(const Checkab String CompatUtility::GetCheckableNotificationNotificationPeriod(const Checkable::Ptr& checkable) { - ASSERT(checkable->OwnsLock()); - TimePeriod::Ptr notification_period; BOOST_FOREACH(const Notification::Ptr& notification, checkable->GetNotifications()) { @@ -524,8 +450,6 @@ String CompatUtility::GetCheckableNotificationNotificationPeriod(const Checkable String CompatUtility::GetCheckableNotificationNotificationOptions(const Checkable::Ptr& checkable) { - ASSERT(checkable->OwnsLock()); - unsigned long notification_type_filter = 0; unsigned long notification_state_filter = 0; @@ -566,8 +490,6 @@ String CompatUtility::GetCheckableNotificationNotificationOptions(const Checkabl int CompatUtility::GetCheckableNotificationTypeFilter(const Checkable::Ptr& checkable) { - ASSERT(checkable->OwnsLock()); - unsigned long notification_type_filter = 0; BOOST_FOREACH(const Notification::Ptr& notification, checkable->GetNotifications()) { @@ -581,8 +503,6 @@ int CompatUtility::GetCheckableNotificationTypeFilter(const Checkable::Ptr& chec int CompatUtility::GetCheckableNotificationStateFilter(const Checkable::Ptr& checkable) { - ASSERT(checkable->OwnsLock()); - unsigned long notification_state_filter = 0; BOOST_FOREACH(const Notification::Ptr& notification, checkable->GetNotifications()) { @@ -596,8 +516,6 @@ int CompatUtility::GetCheckableNotificationStateFilter(const Checkable::Ptr& che int CompatUtility::GetCheckableNotifyOnWarning(const Checkable::Ptr& checkable) { - ASSERT(checkable->OwnsLock()); - if (GetCheckableNotificationStateFilter(checkable) & (1<OwnsLock()); - if (GetCheckableNotificationStateFilter(checkable) & (1<OwnsLock()); - if (GetCheckableNotificationStateFilter(checkable) & (1<OwnsLock()); - if (GetCheckableNotificationTypeFilter(checkable) & (1<OwnsLock()); - unsigned long notification_type_filter = GetCheckableNotificationTypeFilter(checkable); if (notification_type_filter & (1<OwnsLock()); - unsigned long notification_type_filter = GetCheckableNotificationTypeFilter(checkable); if (notification_type_filter & (1< CompatUtility::GetCheckableNotificationUsers(const Checkable::Ptr& checkable) { - ASSERT(checkable->OwnsLock()); - /* Service -> Notifications -> (Users + UserGroups -> Users) */ std::set allUsers; std::set users; @@ -687,8 +593,6 @@ std::set CompatUtility::GetCheckableNotificationUsers(const Checkable std::set CompatUtility::GetCheckableNotificationUserGroups(const Checkable::Ptr& checkable) { - ASSERT(checkable->OwnsLock()); - std::set usergroups; /* Service -> Notifications -> UserGroups */ BOOST_FOREACH(const Notification::Ptr& notification, checkable->GetNotifications()) { @@ -1152,4 +1056,3 @@ int CompatUtility::MapExternalCommandType(const String& name) return 0; } -