diff --git a/icinga-app/icinga.cpp b/icinga-app/icinga.cpp index f5ebe8918..4b0f00057 100644 --- a/icinga-app/icinga.cpp +++ b/icinga-app/icinga.cpp @@ -45,6 +45,7 @@ static HANDLE l_Job; static std::vector GetLogLevelCompletionSuggestions(const String& arg) { std::vector result; + result.reserve(5); String debugLevel = "debug"; if (debugLevel.Find(arg) == 0) diff --git a/lib/base/array-script.cpp b/lib/base/array-script.cpp index a97668350..177a75d08 100644 --- a/lib/base/array-script.cpp +++ b/lib/base/array-script.cpp @@ -128,6 +128,7 @@ static Array::Ptr ArrayMap(const Function::Ptr& function) BOOST_THROW_EXCEPTION(ScriptError("Map function must be side-effect free.")); ArrayData result; + result.reserve(self->GetLength()); ObjectLock olock(self); for (const Value& item : self) { diff --git a/lib/base/configobject.cpp b/lib/base/configobject.cpp index f71043d4b..5265d246e 100644 --- a/lib/base/configobject.cpp +++ b/lib/base/configobject.cpp @@ -212,8 +212,6 @@ void ConfigObject::RestoreAttribute(const String& attr, bool updateVersion) int fid = type->GetFieldId(fieldName); - Value currentValue = GetField(fid); - Dictionary::Ptr original_attributes = GetOriginalAttributes(); if (!original_attributes) @@ -223,6 +221,7 @@ void ConfigObject::RestoreAttribute(const String& attr, bool updateVersion) Value newValue; if (tokens.size() > 1) { + Value currentValue = GetField(fid); newValue = currentValue.Clone(); Value current = newValue; diff --git a/lib/base/process.cpp b/lib/base/process.cpp index 8a51e475b..509ef5416 100644 --- a/lib/base/process.cpp +++ b/lib/base/process.cpp @@ -303,9 +303,6 @@ static void ProcessHandler() } count += rc; - - if (rc == 0) - break; } String jrequest = String(mbuf, mbuf + count); diff --git a/lib/base/tlsutility.cpp b/lib/base/tlsutility.cpp index 3c4244cc5..8455717a5 100644 --- a/lib/base/tlsutility.cpp +++ b/lib/base/tlsutility.cpp @@ -724,10 +724,8 @@ std::shared_ptr CreateCert( X509_EXTENSION_free(basicConstraintsExt); } - String cn = GetX509NameCN(subject); - if (!ca) { - String san = "DNS:" + cn; + String san = "DNS:" + GetX509NameCN(subject); X509_EXTENSION *subjectAltNameExt = X509V3_EXT_conf_nid(nullptr, &ctx, NID_subject_alt_name, const_cast(san.CStr())); if (subjectAltNameExt) { X509_add_ext(cert, subjectAltNameExt, -1); diff --git a/lib/base/utility.cpp b/lib/base/utility.cpp index df1dae063..2eb5ae347 100644 --- a/lib/base/utility.cpp +++ b/lib/base/utility.cpp @@ -1041,6 +1041,8 @@ String Utility::FormatDuration(double duration) std::vector tokens; String result; + tokens.reserve(4); + if (duration >= 86400) { int days = duration / 86400; tokens.emplace_back(Convert::ToString(days) + (days != 1 ? " days" : " day")); @@ -1064,7 +1066,7 @@ String Utility::FormatDuration(double duration) tokens.emplace_back(Convert::ToString(seconds) + (seconds != 1 ? " seconds" : " second")); } - if (tokens.size() == 0) { + if (tokens.empty()) { int milliseconds = std::floor(duration * 1000); if (milliseconds >= 1) tokens.emplace_back(Convert::ToString(milliseconds) + (milliseconds != 1 ? " milliseconds" : " millisecond")); @@ -1661,7 +1663,7 @@ static bool ReleaseHelper(String *platformName, String *platformVersion) if (release.is_open()) { std::string release_line; while (getline(release, release_line)) { - std::string::size_type pos = release_line.find("="); + std::string::size_type pos = release_line.find('='); if (pos == std::string::npos) continue; @@ -1669,12 +1671,12 @@ static bool ReleaseHelper(String *platformName, String *platformVersion) std::string key = release_line.substr(0, pos); std::string value = release_line.substr(pos + 1); - std::string::size_type firstQuote = value.find("\""); + std::string::size_type firstQuote = value.find('"'); if (firstQuote != std::string::npos) value.erase(0, firstQuote + 1); - std::string::size_type lastQuote = value.rfind("\""); + std::string::size_type lastQuote = value.rfind('"'); if (lastQuote != std::string::npos) value.erase(lastQuote); diff --git a/lib/db_ido/idochecktask.cpp b/lib/db_ido/idochecktask.cpp index d3b93e37b..421c68402 100644 --- a/lib/db_ido/idochecktask.cpp +++ b/lib/db_ido/idochecktask.cpp @@ -52,6 +52,7 @@ void IdoCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult tie(host, service) = GetHostService(checkable); MacroProcessor::ResolverList resolvers; + resolvers.reserve(5); if (MacroResolver::OverrideMacros) resolvers.emplace_back("override", MacroResolver::OverrideMacros); diff --git a/lib/icinga/apiactions.cpp b/lib/icinga/apiactions.cpp index 3bc1dcc9e..e5e0d1072 100644 --- a/lib/icinga/apiactions.cpp +++ b/lib/icinga/apiactions.cpp @@ -698,6 +698,8 @@ Dictionary::Ptr ApiActions::ExecuteCommand(const ConfigObject::Ptr& object, cons MacroProcessor::ResolverList resolvers; Value macros; + resolvers.reserve(4); + if (params->Contains("macros")) { macros = HttpUtility::GetLastParameter(params, "macros"); if (macros.IsObjectType()) { diff --git a/lib/icinga/compatutility.cpp b/lib/icinga/compatutility.cpp index a985b90f5..bde8f233e 100644 --- a/lib/icinga/compatutility.cpp +++ b/lib/icinga/compatutility.cpp @@ -69,14 +69,13 @@ String CompatUtility::GetCheckableCommandArgs(const Checkable::Ptr& checkable) { CheckCommand::Ptr command = checkable->GetCheckCommand(); - Dictionary::Ptr args = new Dictionary(); - if (command) { Host::Ptr host; Service::Ptr service; tie(host, service) = GetHostService(checkable); String command_line = GetCommandLine(command); + Dictionary::Ptr args = new Dictionary(); Dictionary::Ptr command_vars = command->GetVars(); if (command_vars) { diff --git a/lib/icinga/scheduleddowntime.cpp b/lib/icinga/scheduleddowntime.cpp index 3447b2a19..b0a62840d 100644 --- a/lib/icinga/scheduleddowntime.cpp +++ b/lib/icinga/scheduleddowntime.cpp @@ -171,7 +171,7 @@ std::pair ScheduledDowntime::FindRunningSegment(double minEnd) if (!bestSegment || end > bestEnd) { Log(LogDebug, "ScheduledDowntime") << "(best match yet)"; - bestSegment = segment; + bestSegment = std::move(segment); bestBegin = begin; bestEnd = end; } @@ -227,7 +227,7 @@ std::pair ScheduledDowntime::FindNextSegment() if (!bestSegment || begin < bestBegin) { Log(LogDebug, "ScheduledDowntime") << "(best match yet)"; - bestSegment = segment; + bestSegment = std::move(segment); bestBegin = begin; bestEnd = end; } diff --git a/lib/icingadb/icingadb-objects.cpp b/lib/icingadb/icingadb-objects.cpp index 26aa58b92..d4658cede 100644 --- a/lib/icingadb/icingadb-objects.cpp +++ b/lib/icingadb/icingadb-objects.cpp @@ -492,11 +492,11 @@ void IcingaDB::UpdateAllConfigObjects() } } - if (delChecksum.size()) { + if (!delChecksum.empty()) { flushDels(); } - if (setChecksum.size()) { + if (!setChecksum.empty()) { flushSets(); } @@ -1315,15 +1315,16 @@ void IcingaDB::UpdateState(const Checkable::Ptr& checkable, StateUpdate mode) return; String objectType = GetLowerCaseTypeNameDB(checkable); - String objectKey = GetObjectIdentifier(checkable); Dictionary::Ptr stateAttrs = SerializeState(checkable); String redisStateKey = m_PrefixConfigObject + objectType + ":state"; - String redisChecksumKey = m_PrefixConfigCheckSum + objectType + ":state"; String checksum = HashValue(stateAttrs); if (mode & StateUpdate::Volatile) { + String objectKey = GetObjectIdentifier(checkable); + String redisChecksumKey = m_PrefixConfigCheckSum + objectType + ":state"; + m_Rcon->FireAndForgetQueries({ {"HSET", redisStateKey, objectKey, JsonEncode(stateAttrs)}, {"HSET", redisChecksumKey, objectKey, JsonEncode(new Dictionary({{"checksum", checksum}}))}, @@ -3211,10 +3212,7 @@ void IcingaDB::NewCheckResultHandler(const Checkable::Ptr& checkable) void IcingaDB::NextCheckUpdatedHandler(const Checkable::Ptr& checkable) { - for (auto& rw : ConfigType::GetObjectsByType()) { - rw->UpdateState(checkable, StateUpdate::Volatile); - rw->SendNextUpdate(checkable); - } + NewCheckResultHandler(checkable); } void IcingaDB::DependencyGroupChildRegisteredHandler(const Checkable::Ptr& child, const DependencyGroup::Ptr& dependencyGroup) @@ -3335,6 +3333,7 @@ void IcingaDB::DeleteRelationship(const String& id, const String& redisKeyWithou String redisKey = m_PrefixConfigObject + redisKeyWithoutPrefix; std::vector> queries; + queries.reserve(3); if (hasChecksum) { queries.push_back({"HDEL", m_PrefixConfigCheckSum + redisKeyWithoutPrefix, id}); diff --git a/lib/icingadb/icingadbchecktask.cpp b/lib/icingadb/icingadbchecktask.cpp index 54e76e894..97a3c5839 100644 --- a/lib/icingadb/icingadbchecktask.cpp +++ b/lib/icingadb/icingadbchecktask.cpp @@ -54,6 +54,8 @@ void IcingadbCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckR MacroProcessor::ResolverList resolvers; String silenceMissingMacroWarning; + resolvers.reserve(5); + if (MacroResolver::OverrideMacros) resolvers.emplace_back("override", MacroResolver::OverrideMacros); @@ -210,7 +212,7 @@ void IcingadbCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckR critmsgs << " ERROR: " << errMsg << "!"; } - perfdata->Add(new PerfdataValue("error_for", errFor * (err ? 1 : -1), false, "seconds", Empty, errForCritical, 0)); + perfdata->Add(new PerfdataValue("error_for", errFor, false, "seconds", Empty, errForCritical, 0)); } if (!down) { diff --git a/lib/methods/clusterzonechecktask.cpp b/lib/methods/clusterzonechecktask.cpp index d7c99138c..f87ca9b06 100644 --- a/lib/methods/clusterzonechecktask.cpp +++ b/lib/methods/clusterzonechecktask.cpp @@ -55,6 +55,7 @@ void ClusterZoneCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const Che tie(host, service) = GetHostService(checkable); MacroProcessor::ResolverList resolvers; + resolvers.reserve(5); if (MacroResolver::OverrideMacros) resolvers.emplace_back("override", MacroResolver::OverrideMacros); diff --git a/lib/methods/dummychecktask.cpp b/lib/methods/dummychecktask.cpp index 85ef33d9a..d06c47248 100644 --- a/lib/methods/dummychecktask.cpp +++ b/lib/methods/dummychecktask.cpp @@ -28,6 +28,7 @@ void DummyCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResu tie(host, service) = GetHostService(checkable); MacroProcessor::ResolverList resolvers; + resolvers.reserve(5); if (MacroResolver::OverrideMacros) resolvers.emplace_back("override", MacroResolver::OverrideMacros); @@ -46,9 +47,6 @@ void DummyCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResu if (resolvedMacros && !useResolvedMacros) return; - /* Parse output and performance data. */ - std::pair co = PluginUtility::ParseCheckOutput(dummyText); - double now = Utility::GetTime(); String commandName = command->GetName(); @@ -62,6 +60,9 @@ void DummyCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResu Checkable::ExecuteCommandProcessFinishedHandler(commandName, pr); } else { + /* Parse output and performance data. */ + std::pair co = PluginUtility::ParseCheckOutput(dummyText); + cr->SetOutput(co.first); cr->SetPerformanceData(PluginUtility::SplitPerfdata(co.second)); cr->SetState(PluginUtility::ExitStatusToState(dummyState)); diff --git a/lib/methods/exceptionchecktask.cpp b/lib/methods/exceptionchecktask.cpp index 645a751bd..18700eaec 100644 --- a/lib/methods/exceptionchecktask.cpp +++ b/lib/methods/exceptionchecktask.cpp @@ -36,6 +36,6 @@ void ExceptionCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const Check Checkable::ExecuteCommandProcessFinishedHandler("", pr); } else { - BOOST_THROW_EXCEPTION(ScriptError("Test") << boost::errinfo_api_function("Test")); + BOOST_THROW_EXCEPTION(scriptError); } } diff --git a/lib/methods/icingachecktask.cpp b/lib/methods/icingachecktask.cpp index 3a8e9fbce..244de53f6 100644 --- a/lib/methods/icingachecktask.cpp +++ b/lib/methods/icingachecktask.cpp @@ -32,6 +32,7 @@ void IcingaCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckRes tie(host, service) = GetHostService(checkable); MacroProcessor::ResolverList resolvers; + resolvers.reserve(5); if (MacroResolver::OverrideMacros) resolvers.emplace_back("override", MacroResolver::OverrideMacros); diff --git a/lib/methods/sleepchecktask.cpp b/lib/methods/sleepchecktask.cpp index 975fde697..aeeca6756 100644 --- a/lib/methods/sleepchecktask.cpp +++ b/lib/methods/sleepchecktask.cpp @@ -45,7 +45,6 @@ void SleepCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResu double now = Utility::GetTime(); CheckCommand::Ptr command = checkable->GetCheckCommand(); - String commandName = command->GetName(); if (Checkable::ExecuteCommandProcessFinishedHandler) { ProcessResult pr; @@ -60,7 +59,7 @@ void SleepCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResu cr->SetOutput(output); cr->SetExecutionStart(now); cr->SetExecutionEnd(now); - cr->SetCommand(commandName); + cr->SetCommand(command->GetName()); checkable->ProcessCheckResult(cr, producer); } diff --git a/lib/perfdata/perfdatawriter.cpp b/lib/perfdata/perfdatawriter.cpp index 849f19ed6..2e9bb25ea 100644 --- a/lib/perfdata/perfdatawriter.cpp +++ b/lib/perfdata/perfdatawriter.cpp @@ -113,6 +113,8 @@ void PerfdataWriter::CheckResultHandler(const Checkable::Ptr& checkable, const C host = static_pointer_cast(checkable); MacroProcessor::ResolverList resolvers; + resolvers.reserve(3); + if (service) resolvers.emplace_back("service", service); resolvers.emplace_back("host", host); diff --git a/lib/remote/httphandler.cpp b/lib/remote/httphandler.cpp index 0dafad4c8..2fc803e22 100644 --- a/lib/remote/httphandler.cpp +++ b/lib/remote/httphandler.cpp @@ -33,7 +33,7 @@ void HttpHandler::Register(const Url::Ptr& url, const HttpHandler::Ptr& handler) children->Set(elem, sub_node); } - node = sub_node; + node = std::move(sub_node); } Array::Ptr handlers = node->Get("handlers");