Skip to content

Commit

Permalink
feat: other changes
Browse files Browse the repository at this point in the history
  • Loading branch information
aritosteles committed Nov 15, 2024
1 parent 39bb85a commit d4d8005
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
7 changes: 5 additions & 2 deletions src/agent/src/agent_registration.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#include <agent_registration.hpp>

#include <boost/beast/http.hpp>
#include <iostream>
#include <config.h>
#include <nlohmann/json.hpp>

#include <iostream>

namespace http = boost::beast::http;

namespace agent_registration
Expand All @@ -16,7 +18,8 @@ namespace agent_registration
, m_configurationParser(configFile.has_value() && !configFile->empty()
? configuration::ConfigurationParser(std::filesystem::path(configFile.value()))
: configuration::ConfigurationParser())
, m_serverUrl(m_configurationParser.GetConfig<std::string>("agent", "registration_url"))
, m_serverUrl(m_configurationParser.GetConfig<std::string>("agent", "registration_url")
.value_or(config::agent::DEFAULT_REGISTRATION_URL))
, m_user(std::move(user))
, m_password(std::move(password))
{
Expand Down
4 changes: 2 additions & 2 deletions src/modules/logcollector/src/file_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ Localfile::Localfile(std::shared_ptr<std::istream> stream) :
m_stream(std::move(stream)) { }

std::string Localfile::NextLog() {
auto buffer = std::vector<char>(config::BUFFER_SIZE);
auto buffer = std::vector<char>(config::logcollector::BUFFER_SIZE);

if (m_stream->getline(buffer.data(), config::BUFFER_SIZE).good()) {
if (m_stream->getline(buffer.data(), config::logcollector::BUFFER_SIZE).good()) {
m_pos = m_stream->tellg();
return { buffer.data(), static_cast<size_t>(m_stream->gcount()) - 1 };
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/modules/logcollector/src/file_reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class FileReader : public IReader {
/// @param pattern File pattern
/// @param fileWait File wait time in milliseconds
/// @param reloadInterval Reload interval in seconds
FileReader(Logcollector& logcollector, std::string pattern, long fileWait = config::DEFAULT_FILE_WAIT, long reloadInterval = config::DEFAULT_RELOAD_INTERVAL);
FileReader(Logcollector& logcollector, std::string pattern, long fileWait = config::logcollector::DEFAULT_FILE_WAIT, long reloadInterval = config::logcollector::DEFAULT_RELOAD_INTERVAL);

/// @brief Runs the file reader
/// @return Awaitable result
Expand Down
19 changes: 10 additions & 9 deletions src/modules/logcollector/src/logcollector.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include <logcollector.hpp>
#include <logger.hpp>

#include <logger.hpp>
#include <boost/asio/co_spawn.hpp>
#include <boost/asio/detached.hpp>
#include <config.h>

#include <chrono>
#include <iomanip>
Expand All @@ -29,7 +30,7 @@ void Logcollector::EnqueueTask(boost::asio::awaitable<void> task) {

void Logcollector::Setup(const configuration::ConfigurationParser& configurationParser) {
try {
m_enabled = configurationParser.GetConfig<bool>("logcollector", "enabled");
m_enabled = configurationParser.GetConfig<bool>("logcollector", "enabled").value_or(config::logcollector::DEFAULT_ENABLED);
} catch (std::exception&) {
m_enabled = true;
}
Expand All @@ -38,23 +39,23 @@ void Logcollector::Setup(const configuration::ConfigurationParser& configuration
}

void Logcollector::SetupFileReader(const configuration::ConfigurationParser& configurationParser) {
long fileWait = config::DEFAULT_FILE_WAIT;
long reloadInterval = config::DEFAULT_RELOAD_INTERVAL;
long fileWait = config::logcollector::DEFAULT_FILE_WAIT;
long reloadInterval = config::logcollector::DEFAULT_RELOAD_INTERVAL;

try {
fileWait = configurationParser.GetConfig<long>("logcollector", "file_wait");
fileWait = configurationParser.GetConfig<long>("logcollector", "file_wait").value_or(config::logcollector::DEFAULT_FILE_WAIT);
} catch (std::exception&) {
fileWait = config::DEFAULT_FILE_WAIT;
fileWait = config::logcollector::DEFAULT_FILE_WAIT;
}

try {
reloadInterval = configurationParser.GetConfig<long>("logcollector", "reload_interval");
reloadInterval = configurationParser.GetConfig<long>("logcollector", "reload_interval").value_or(config::logcollector::DEFAULT_RELOAD_INTERVAL);
} catch (std::exception&) {
reloadInterval = config::DEFAULT_FILE_WAIT;
reloadInterval = config::logcollector::DEFAULT_FILE_WAIT;
}

try {
auto localfiles = configurationParser.GetConfig<std::vector<std::string>>("logcollector", "localfiles");
auto localfiles = configurationParser.GetConfig<std::vector<std::string>>("logcollector", "localfiles").value_or(std::vector<std::string>({config::logcollector::DEFAULT_LOCALFILES}));

for (auto& lf : localfiles) {
AddReader(std::make_shared<FileReader>(*this, lf, fileWait, reloadInterval));
Expand Down

0 comments on commit d4d8005

Please sign in to comment.