Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions daemon/main/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,14 @@ Options::OptEntry* Options::OptEntries::FindOption(const char* name)
return nullptr;
}


const Options::Category* Options::Categories::FindCategory(const char* name, bool searchAliases) const
Options::Category* Options::Categories::FindCategory(const char* name, bool searchAliases)
{
if (!name)
{
return nullptr;
}

for (const Category& category : *this)
for (Category& category : this)
{
if (!strcasecmp(category.GetName(), name))
{
Expand All @@ -119,9 +118,9 @@ const Options::Category* Options::Categories::FindCategory(const char* name, boo

if (searchAliases)
{
for (const Category& category : *this)
for (Category& category : this)
{
for (const CString& alias : *category.GetAliases())
for (CString& alias : category.GetAliases())
{
WildMask mask(alias);
if (mask.Match(name))
Expand All @@ -135,13 +134,6 @@ const Options::Category* Options::Categories::FindCategory(const char* name, boo
return nullptr;
}

Options::Category* Options::Categories::FindCategory(const char* name, bool searchAliases)
{
const Category* result =
static_cast<const Categories*>(this)->FindCategory(name, searchAliases);
return const_cast<Category*>(result);
}

Options::Options(const char* exeName, const char* configFilename, bool noConfig,
CmdOptList* commandLineOptions, Extender* extender)
{
Expand Down
1 change: 0 additions & 1 deletion daemon/main/Options.h
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,6 @@ class Options
Categories* GetCategories() { return &m_categories; }
const Categories* GetCategories() const { return &m_categories; }
Category* FindCategory(const char* name, bool searchAliases) { return m_categories.FindCategory(name, searchAliases); }
const Category* FindCategory(const char* name, bool searchAliases) const { return m_categories.FindCategory(name, searchAliases); }

// Current state
void SetServerMode(bool serverMode) { m_serverMode = serverMode; }
Expand Down
14 changes: 14 additions & 0 deletions daemon/main/nzbget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@


#include "nzbget.h"

#include "ServerPool.h"
#include "Log.h"
#include "NzbFile.h"
Expand Down Expand Up @@ -57,6 +58,7 @@
#include "YEncode.h"
#include "ExtensionManager.h"
#include "SystemInfo.h"
#include "SystemHealth.h"

#ifdef WIN32
#include "WinService.h"
Expand Down Expand Up @@ -100,6 +102,7 @@ ScriptConfig* g_ScriptConfig;
CommandScriptLog* g_CommandScriptLog;
ExtensionManager::Manager* g_ExtensionManager;
System::SystemInfo* g_SystemInfo;
SystemHealth::Service* g_SystemHealth;

#ifdef WIN32
WinConsole* g_WinConsole;
Expand Down Expand Up @@ -216,6 +219,7 @@ class NZBGet : public Options::Extender
std::unique_ptr<CommandScriptLog> m_commandScriptLog;
std::unique_ptr<ExtensionManager::Manager> m_extensionManager;
std::unique_ptr<System::SystemInfo> m_systemInfo;
std::unique_ptr<SystemHealth::Service> m_systemHealth;

#ifdef WIN32
std::unique_ptr<WinConsole> m_winConsole;
Expand Down Expand Up @@ -285,6 +289,16 @@ void NZBGet::Init()

BootConfig();

m_systemHealth = std::make_unique<SystemHealth::Service>(
*g_Options,
*g_ServerPool->GetServers(),
*g_FeedCoordinator->GetFeeds(),
m_scheduler->GetTasks());
g_SystemHealth = m_systemHealth.get();

const auto report = m_systemHealth->Diagnose();
SystemHealth::Log(report);

#ifndef WIN32
mode_t uMask = static_cast<mode_t>(m_options->GetUMask());
if (uMask < 01000)
Expand Down
1 change: 1 addition & 0 deletions daemon/main/nzbget.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <iterator>
#include <algorithm>
#include <numeric>
Expand Down
80 changes: 51 additions & 29 deletions daemon/remote/XmlRpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "NetworkSpeedTest.h"
#include "Xml.h"
#include "Unpack.h"
#include "SystemHealth.h"

extern void ExitProc();
extern void Reload();
Expand Down Expand Up @@ -133,6 +134,12 @@ class SysInfoXmlCommand: public SafeXmlCommand
void Execute() override;
};

class SystemHealthXmlCommand : public SafeXmlCommand
{
public:
void Execute() override;
};

class LogXmlCommand: public SafeXmlCommand
{
public:
Expand Down Expand Up @@ -437,7 +444,6 @@ class TestDiskSpeedXmlCommand final : public SafeXmlCommand
Xml::AddNewNode(structNode, "DurationMS", "double", durationMS.c_str());

xmlAddChild(rootNode, structNode);

std::string result = Xml::Serialize(rootNode);

xmlFreeNode(rootNode);
Expand Down Expand Up @@ -470,7 +476,6 @@ class TestNetworkSpeedXmlCommand final : public SafeXmlCommand
Xml::AddNewNode(structNode, "SpeedMbps", "double", speedMbpsStr.c_str());

xmlAddChild(rootNode, structNode);

std::string result = Xml::Serialize(rootNode);

xmlFreeNode(rootNode);
Expand Down Expand Up @@ -783,6 +788,10 @@ std::unique_ptr<XmlCommand> XmlRpcProcessor::CreateCommand(const char* methodNam
{
command = std::make_unique<SysInfoXmlCommand>();
}
else if (!strcasecmp(methodName, "systemhealth"))
{
command = std::make_unique<SystemHealthXmlCommand>();
}
else if (!strcasecmp(methodName, "log"))
{
command = std::make_unique<LogXmlCommand>();
Expand Down Expand Up @@ -1650,19 +1659,23 @@ void StatusXmlCommand::Execute()
postJobCount, postJobCount, urlCount, upTimeSec, downloadTimeSec,
BoolToStr(downloadPaused), BoolToStr(downloadPaused), BoolToStr(downloadPaused),
BoolToStr(serverStandBy), BoolToStr(postPaused), BoolToStr(scanPaused), BoolToStr(quotaReached),
freeDiskSpaceLo,
freeDiskSpaceHi,
freeDiskSpaceMB,
totalDiskSpaceLo,
totalDiskSpaceHi,
freeDiskSpaceLo,
freeDiskSpaceHi,
freeDiskSpaceMB,
totalDiskSpaceLo,
totalDiskSpaceHi,
totalDiskSpaceMB,
freeInterDiskSpaceLo,
freeInterDiskSpaceHi,
freeInterDiskSpaceMB,
totalInterDiskSpaceLo,
totalInterDiskSpaceHi,
freeInterDiskSpaceLo,
freeInterDiskSpaceHi,
freeInterDiskSpaceMB,
totalInterDiskSpaceLo,
totalInterDiskSpaceHi,
totalInterDiskSpaceMB,
serverTime, resumeTime, BoolToStr(feedActive), queuedScripts);
serverTime,
resumeTime,
BoolToStr(feedActive),
queuedScripts
);

int index = 0;
for (NewsServer* server : g_ServerPool->GetServers())
Expand All @@ -1684,6 +1697,15 @@ void SysInfoXmlCommand::Execute()
AppendResponse(response.c_str());
}

void SystemHealthXmlCommand::Execute()
{
const auto report = g_SystemHealth->Diagnose();
const std::string response =
IsJson() ? SystemHealth::ToJsonStr(report) : SystemHealth::ToXmlStr(report);

AppendResponse(response.c_str());
}

// struct[] log(idfrom, entries)
void LogXmlCommand::Execute()
{
Expand Down Expand Up @@ -2278,7 +2300,7 @@ void ListGroupsXmlCommand::Execute()
const char* ListGroupsXmlCommand::DetectStatus(NzbInfo* nzbInfo)
{
const char* postStageName[] = { "PP_QUEUED", "LOADING_PARS", "VERIFYING_SOURCES", "REPAIRING",
"VERIFYING_REPAIRED", "RENAMING", "RENAMING", "UNPACKING", "MOVING", "MOVING", "POST_UNPACK_RENAMING",
"VERIFYING_REPAIRED", "RENAMING", "RENAMING", "UNPACKING", "MOVING", "MOVING", "POST_UNPACK_RENAMING",
"EXECUTING_SCRIPT", "PP_FINISHED" };

const char* status = nullptr;
Expand Down Expand Up @@ -3028,7 +3050,7 @@ void LoadExtensionsXmlCommand::Execute()
{
BuildErrorResponse(3, error.value().c_str());
return;
}
}
}

AppendResponse(isJson ? "[\n" : "<array><data>\n");
Expand Down Expand Up @@ -3185,7 +3207,7 @@ void SaveConfigXmlCommand::Execute()
char* dummy;
while ((IsJson() && NextParamAsStr(&dummy) && NextParamAsStr(&name) &&
NextParamAsStr(&dummy) && NextParamAsStr(&value)) ||
(!IsJson() && NextParamAsStr(&name) && NextParamAsStr(&value)))
(!IsJson() && NextParamAsStr(&name) && NextParamAsStr(&value)))
{
DecodeStr(name);
DecodeStr(value);
Expand Down Expand Up @@ -3670,7 +3692,7 @@ void ServerVolumesXmlCommand::Execute()
&& NextParamAsBool(&BytesPer[2])
&& NextParamAsBool(&BytesPer[3]);

bool articlesPerDays = true;
bool articlesPerDays = true;
NextParamAsBool(&articlesPerDays);

int index = 0;
Expand Down Expand Up @@ -3700,11 +3722,11 @@ void ServerVolumesXmlCommand::Execute()
serverVolume.GetDaySlot()
);

ServerVolume::VolumeArray* VolumeArrays[] = {
ServerVolume::VolumeArray* VolumeArrays[] = {
serverVolume.BytesPerSeconds(),
serverVolume.BytesPerMinutes(),
serverVolume.BytesPerHours(),
serverVolume.BytesPerDays()
serverVolume.BytesPerMinutes(),
serverVolume.BytesPerHours(),
serverVolume.BytesPerDays()
};
const char* VolumeNames[] = {
"BytesPerSeconds",
Expand Down Expand Up @@ -3743,12 +3765,12 @@ void ServerVolumesXmlCommand::Execute()
{
AppendCondResponse(",\n", IsJson());
AppendFmtResponse(IsJson() ? JSON_ARRAY_START : XML_ARRAY_START, "ArticlesPerDays");

const auto& articles = serverVolume.GetArticlesPerDays();
for (size_t i = 0; i < articles.size(); ++i)
{
AppendFmtResponse(IsJson() ? JSON_ARTICLES_ARRAY_ITEM : XML_ARTICLES_ARRAY_ITEM,
articles[i].failed,
articles[i].failed,
articles[i].success
);

Expand Down Expand Up @@ -3868,13 +3890,13 @@ void TestServerXmlCommand::Execute()
if (!jsonResult)
{
BuildErrorResponse(2, "Invalid JSON");
return;
return;
}
auto paramsResult = ParseRequestParams(*jsonResult);
if (!paramsResult)
{
BuildErrorResponse(2, "Invalid parameters");
return;
return;
}
params = std::move(*paramsResult);
}
Expand Down Expand Up @@ -4042,12 +4064,12 @@ void TestDiskSpeedXmlCommand::Execute()
{
size_t bufferSizeBytes = writeBufferKiB * 1024;
uint64_t maxFileSizeBytes = maxFileSizeGiB * 1024ull * 1024ull * 1024ull;

Benchmark::DiskBenchmark db;
auto [size, time] = db.Run(
dirPath,
bufferSizeBytes,
maxFileSizeBytes,
dirPath,
bufferSizeBytes,
maxFileSizeBytes,
std::chrono::seconds(timeoutSec)
);

Expand Down
25 changes: 25 additions & 0 deletions daemon/sources.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,30 @@ set(SRC
${CMAKE_SOURCE_DIR}/daemon/system/OS.cpp
${CMAKE_SOURCE_DIR}/daemon/system/CPU.cpp
${CMAKE_SOURCE_DIR}/daemon/system/Network.cpp

${CMAKE_SOURCE_DIR}/daemon/systemhealth/SystemHealthService.cpp
${CMAKE_SOURCE_DIR}/daemon/systemhealth/Status.cpp
${CMAKE_SOURCE_DIR}/daemon/systemhealth/Validators.cpp
${CMAKE_SOURCE_DIR}/daemon/systemhealth/SectionValidator.cpp
${CMAKE_SOURCE_DIR}/daemon/systemhealth/SectionGroupValidator.cpp
${CMAKE_SOURCE_DIR}/daemon/systemhealth/PathsValidator.cpp
${CMAKE_SOURCE_DIR}/daemon/systemhealth/NewsServerValidator.cpp
${CMAKE_SOURCE_DIR}/daemon/systemhealth/NewsServersValidator.cpp
${CMAKE_SOURCE_DIR}/daemon/systemhealth/SchedulerTasksValidator.cpp
${CMAKE_SOURCE_DIR}/daemon/systemhealth/SchedulerTaskValidator.cpp
${CMAKE_SOURCE_DIR}/daemon/systemhealth/LoggingValidator.cpp
${CMAKE_SOURCE_DIR}/daemon/systemhealth/ExtensionScriptsValidator.cpp
${CMAKE_SOURCE_DIR}/daemon/systemhealth/UnpackValidator.cpp
${CMAKE_SOURCE_DIR}/daemon/systemhealth/SecurityValidator.cpp
${CMAKE_SOURCE_DIR}/daemon/systemhealth/IncomingNzbValidator.cpp
${CMAKE_SOURCE_DIR}/daemon/systemhealth/FeedValidator.cpp
${CMAKE_SOURCE_DIR}/daemon/systemhealth/FeedsValidator.cpp
${CMAKE_SOURCE_DIR}/daemon/systemhealth/DownloadQueueValidator.cpp
${CMAKE_SOURCE_DIR}/daemon/systemhealth/CheckAndRepairValidator.cpp
${CMAKE_SOURCE_DIR}/daemon/systemhealth/CategoryValidator.cpp
${CMAKE_SOURCE_DIR}/daemon/systemhealth/CategoriesValidator.cpp
${CMAKE_SOURCE_DIR}/daemon/systemhealth/ConnectionValidator.cpp
${CMAKE_SOURCE_DIR}/daemon/systemhealth/DisplayValidator.cpp
)

set(WIN32_SRC
Expand Down Expand Up @@ -134,4 +158,5 @@ set(INCLUDES ${INCLUDES}
${CMAKE_SOURCE_DIR}/daemon/remote
${CMAKE_SOURCE_DIR}/daemon/system
${CMAKE_SOURCE_DIR}/daemon/util
${CMAKE_SOURCE_DIR}/daemon/systemhealth
)
2 changes: 1 addition & 1 deletion daemon/system/SystemInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ namespace System
return std::nullopt;
}

std::optional<std::string> SystemInfo::GetPythonVersion(const std::string path) const
std::optional<std::string> SystemInfo::GetPythonVersion(const std::string& path) const
{
std::string cmd = FileSystem::EscapePathForShell(path) + " --version 2>&1";
{
Expand Down
4 changes: 2 additions & 2 deletions daemon/system/SystemInfo.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of nzbget. See <https://nzbget.com>.
*
* Copyright (C) 2024 Denis <denis@nzbget.com>
* Copyright (C) 2024-2025 Denis <denis@nzbget.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -62,7 +62,7 @@ namespace System
std::string GetToolPath(const char* cmd) const;
std::string GetUnpackerVersion(const std::string& path, const char* marker) const;\
std::optional<std::string> FindPython() const;
std::optional<std::string> GetPythonVersion(const std::string path) const;
std::optional<std::string> GetPythonVersion(const std::string& path) const;

CPU m_cpu;
OS m_os;
Expand Down
Loading