1
0
Fork 0
mirror of https://github.com/pavel-odintsov/fastnetmon synced 2024-05-27 04:46:15 +02:00

Add ability to configure mongo host, port and database name

This commit is contained in:
Pavel Odintsov 2015-10-01 11:39:16 +02:00
parent 6b41b12918
commit 3596a4797e
3 changed files with 28 additions and 12 deletions

View File

@ -11,7 +11,7 @@ Build FastNetMon from Git's master branch.
Enable it in configuration file:
```bash
mongo_enabled = on
mongodb_enabled = on
```
Query data about attacks:

View File

@ -193,7 +193,11 @@ redis_host = 127.0.0.1
# specify a custom prefix here
redis_prefix = mydc1
mongo_enabled = off
# We could store attack information to MongoDB
mongodb_enabled = off
mongodb_host = localhost
mongodb_port = 27017
mongodb_database_name = fastnetmon
# If you are using PF_RING non ZC version you could block traffic on host with hardware filters
# Please be aware! We can not remove blocks with this action plugin

View File

@ -161,11 +161,11 @@ u_int32_t ndpi_size_id_struct = 0;
#endif
#ifdef MONGO
std::string mondodb_host = "localhost";
unsigned int mondodb_port = 27017;
bool mongo_enabled = false;
std::string mongodb_host = "localhost";
unsigned int mongodb_port = 27017;
bool mongodb_enabled = false;
std::string mongo_database_name = "fastnetmon";
std::string mongodb_database_name = "fastnetmon";
#endif
/* Configuration block, we must move it to configuration file */
@ -559,7 +559,7 @@ void store_data_in_mongo(std::string key_name, std::string attack_details_json)
mongoc_init ();
std::string collection_name = "attacks";
std::string connection_string = "mongodb://" + mondodb_host + ":" + convert_int_to_string(mondodb_port) + "/";
std::string connection_string = "mongodb://" + mongodb_host + ":" + convert_int_to_string(mongodb_port) + "/";
client = mongoc_client_new (connection_string.c_str());
@ -577,7 +577,7 @@ void store_data_in_mongo(std::string key_name, std::string attack_details_json)
// logger << log4cpp::Priority::INFO << bson_as_json(bson_data, NULL);
collection = mongoc_client_get_collection (client, mongo_database_name.c_str(), collection_name.c_str());
collection = mongoc_client_get_collection (client, mongodb_database_name.c_str(), collection_name.c_str());
doc = bson_new ();
bson_oid_init (&oid, NULL);
@ -1182,11 +1182,23 @@ bool load_configuration_file() {
#endif
#ifdef MONGO
if (configuration_map.count("mongo_enabled") != 0) {
if (configuration_map["mongo_enabled"] == "on") {
mongo_enabled = true;
if (configuration_map.count("mongodb_enabled") != 0) {
if (configuration_map["mongodb_enabled"] == "on") {
mongodb_enabled = true;
}
}
if (configuration_map.count("mongodb_host") != 0) {
mongodb_host = configuration_map["mongodb_host"];
}
if (configuration_map.count("mongodb_port") != 0) {
mongodb_port = convert_string_to_integer(configuration_map["mongodb_port"]);
}
if (configuration_map.count("mongodb_database_name") != 0) {
mongodb_database_name = configuration_map["mongodb_database_name"];
}
#endif
if (configuration_map.count("ban_details_records_count") != 0) {
@ -3101,7 +3113,7 @@ void call_ban_handlers(uint32_t client_ip, attack_details& current_attack, std::
}
#ifdef MONGO
if (mongo_enabled) {
if (mongodb_enabled) {
std::string mongo_key_name = client_ip_as_string + "_information_" +
print_time_t_in_fastnetmon_format(current_attack.ban_timestamp);