Skip to content

Commit

Permalink
FHOSTLOOKUP:: FIX ABSENT FEED_NAME IN CASE OF NON-TEXT DB (#202)
Browse files Browse the repository at this point in the history
* FHOSTLOOKUP:: FIX ABSENT FEED_NAME IN CASE OF NON-TEXT DB

* HOSTLOOKUP:: LOAD FEED NAME AS FILENAME ONLY FOR TEXT AND RSYSLOG DBS
  • Loading branch information
frikilax authored Sep 17, 2020
1 parent b51901c commit 85d1e64
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
17 changes: 9 additions & 8 deletions samples/fhostlookup/Generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ bool Generator::LoadConfig(const rapidjson::Document &configuration) {
return this->LoadTextFile(db);
} else {
DARWIN_LOG_CRITICAL("HostLookup:: Generator:: Unknown 'db_type'");
return false;
}
return false; // Put it there just in case.

return false;
}

bool Generator::LoadTextFile(const std::string& filename) {
Expand All @@ -95,13 +95,8 @@ bool Generator::LoadTextFile(const std::string& filename) {
_database.insert({buf,{"", 100}});
}
}
this->LoadFeedNameFromFile(filename);
file.close();

// Get feed name from file name
buf = darwin::files_utils::GetNameFromPath(filename); // Filename already proven valid
darwin::files_utils::ReplaceExtension(buf, "");
this->_feed_name = buf;

return true;
}

Expand All @@ -126,12 +121,18 @@ bool Generator::LoadJsonFile(const std::string& filename, const db_type type) {
if (type == db_type::json) {
ret = this->LoadJsonDatabase(database);
} else if (type == db_type::rsyslog) {
this->LoadFeedNameFromFile(filename);
ret = this->LoadRsyslogDatabase(database);
}
file.close();
return ret;
}

void Generator::LoadFeedNameFromFile(const std::string& filename) {
this->_feed_name = darwin::files_utils::GetNameFromPath(filename);
darwin::files_utils::ReplaceExtension(this->_feed_name, "");
}

bool Generator::LoadJsonDatabase(const rapidjson::Document& database) {
DARWIN_LOGGER;
if (not database.HasMember("feed_name") or not database["feed_name"].IsString()) {
Expand Down
1 change: 1 addition & 0 deletions samples/fhostlookup/Generator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class Generator: public AGenerator {

bool LoadTextFile(const std::string& filename);
bool LoadJsonFile(const std::string& filename, const db_type type);
void LoadFeedNameFromFile(const std::string& filename);
bool LoadJsonDatabase(const rapidjson::Document& database);
bool LoadJsonEntry(const rapidjson::Value& entry);
bool LoadRsyslogDatabase(const rapidjson::Document& database);
Expand Down

0 comments on commit 85d1e64

Please sign in to comment.