This commit is contained in:
Yonas Habteab 2026-01-30 17:02:40 +01:00 committed by GitHub
commit bfef398299
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 37 additions and 32 deletions

View file

@ -45,6 +45,7 @@ static HANDLE l_Job;
static std::vector<String> GetLogLevelCompletionSuggestions(const String& arg)
{
std::vector<String> result;
result.reserve(5);
String debugLevel = "debug";
if (debugLevel.Find(arg) == 0)

View file

@ -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) {

View file

@ -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;

View file

@ -303,9 +303,6 @@ static void ProcessHandler()
}
count += rc;
if (rc == 0)
break;
}
String jrequest = String(mbuf, mbuf + count);

View file

@ -724,10 +724,8 @@ std::shared_ptr<X509> 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<char *>(san.CStr()));
if (subjectAltNameExt) {
X509_add_ext(cert, subjectAltNameExt, -1);

View file

@ -1041,6 +1041,8 @@ String Utility::FormatDuration(double duration)
std::vector<String> 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);

View file

@ -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);

View file

@ -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<Dictionary>()) {

View file

@ -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) {

View file

@ -171,7 +171,7 @@ std::pair<double, double> 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<double, double> ScheduledDowntime::FindNextSegment()
if (!bestSegment || begin < bestBegin) {
Log(LogDebug, "ScheduledDowntime") << "(best match yet)";
bestSegment = segment;
bestSegment = std::move(segment);
bestBegin = begin;
bestEnd = end;
}

View file

@ -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<IcingaDB>()) {
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<std::vector<String>> queries;
queries.reserve(3);
if (hasChecksum) {
queries.push_back({"HDEL", m_PrefixConfigCheckSum + redisKeyWithoutPrefix, id});

View file

@ -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) {

View file

@ -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);

View file

@ -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<String, String> 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<String, String> co = PluginUtility::ParseCheckOutput(dummyText);
cr->SetOutput(co.first);
cr->SetPerformanceData(PluginUtility::SplitPerfdata(co.second));
cr->SetState(PluginUtility::ExitStatusToState(dummyState));

View file

@ -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);
}
}

View file

@ -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);

View file

@ -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);
}

View file

@ -113,6 +113,8 @@ void PerfdataWriter::CheckResultHandler(const Checkable::Ptr& checkable, const C
host = static_pointer_cast<Host>(checkable);
MacroProcessor::ResolverList resolvers;
resolvers.reserve(3);
if (service)
resolvers.emplace_back("service", service);
resolvers.emplace_back("host", host);

View file

@ -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");