diff --git a/configs/mongo/mongow.xml b/configs/mongo/mongow.xml index 8d7fbc1..fcef107 100644 --- a/configs/mongo/mongow.xml +++ b/configs/mongo/mongow.xml @@ -76,10 +76,12 @@ + 127.0.0.1 nasty 5 27017 + dstIP srcIP diff --git a/src/modules/ipfix/IpfixDbWriterMongo.cpp b/src/modules/ipfix/IpfixDbWriterMongo.cpp index a95e97c..52e664a 100644 --- a/src/modules/ipfix/IpfixDbWriterMongo.cpp +++ b/src/modules/ipfix/IpfixDbWriterMongo.cpp @@ -327,9 +327,12 @@ mongo::BSONObj IpfixDbWriterMongo::getInsertObj(const IpfixRecord::SourceID& sou } } - msg(MSG_DEBUG, "saw ipfix id %s in packet with intdata %llX", prop->propertyName, - static_cast(intdata)); - obj << prop->propertyName << static_cast(intdata); + msg(MSG_DEBUG, "saw ipfix id %s (element ID %d) in packet with intdata %llX", prop->propertyName, + prop->ipfixId, static_cast(intdata)); + if (beautyProp) + obj << prop->propertyName << static_cast(intdata); + else + obj << boost::lexical_cast(prop->ipfixId).c_str() << static_cast(intdata); } if (flowstartsec == 0) { @@ -459,9 +462,10 @@ void IpfixDbWriterMongo::onDataRecord(IpfixDataRecord* record) IpfixDbWriterMongo::IpfixDbWriterMongo(const string& hostname, const string& database, const string& username, const string& password, unsigned port, uint32_t observationDomainId, uint16_t maxStatements, - const vector& propertyNames) + const vector& propertyNames, bool beautifyProperties) : currentExporter(NULL), numberOfInserts(0), maxInserts(maxStatements), - dbHost(hostname), dbName(database), dbUser(username), dbPassword(password), dbPort(port), con(0) + dbHost(hostname), dbName(database), dbUser(username), dbPassword(password), dbPort(port), con(0), + beautyProp(beautifyProperties) { int i; diff --git a/src/modules/ipfix/IpfixDbWriterMongo.hpp b/src/modules/ipfix/IpfixDbWriterMongo.hpp index 7c6fb97..614d277 100644 --- a/src/modules/ipfix/IpfixDbWriterMongo.hpp +++ b/src/modules/ipfix/IpfixDbWriterMongo.hpp @@ -64,7 +64,7 @@ class IpfixDbWriterMongo IpfixDbWriterMongo(const string& hostname, const string& database, const string& username, const string& password, unsigned port, uint32_t observationDomainId, uint16_t maxStatements, - const vector& properties); + const vector& properties, bool beautifyProperties); ~IpfixDbWriterMongo(); void onDataRecord(IpfixDataRecord* record); @@ -106,6 +106,7 @@ class IpfixDbWriterMongo string dbHost, dbName, dbUser, dbPassword, dbCollectionFlows, dbCollectionExporters, dbCollectionCounters; unsigned dbPort; mongo::DBClientConnection con; + bool beautyProp; bool dbError; // db error flag mongo::BSONObj getInsertObj(const IpfixRecord::SourceID& sourceID, TemplateInfo& dataTemplateInfo,uint16_t length, IpfixRecord::Data* data); diff --git a/src/modules/ipfix/IpfixDbWriterMongoCfg.cpp b/src/modules/ipfix/IpfixDbWriterMongoCfg.cpp index 67ab206..ef0425d 100644 --- a/src/modules/ipfix/IpfixDbWriterMongoCfg.cpp +++ b/src/modules/ipfix/IpfixDbWriterMongoCfg.cpp @@ -39,6 +39,7 @@ IpfixDbWriterMongoCfg::IpfixDbWriterMongoCfg(XMLElement* elem) if (!elem) return; XMLNode::XMLSet set = _elem->getElementChildren(); + beautifyProperties = false; for ( XMLNode::XMLSet::iterator it = set.begin(); it != set.end(); it++) { @@ -60,6 +61,8 @@ IpfixDbWriterMongoCfg::IpfixDbWriterMongoCfg(XMLElement* elem) readProperties(e); } else if (e->matches("observationDomainId")) { observationDomainId = getInt("observationDomainId"); + } else if (e->matches("beautifyProperties")) { + beautifyProperties = true; } else if (e->matches("next")) { // ignore next } else { msg(MSG_FATAL, "Unknown IpfixDbWriterMongo config statement %s\n", e->getName().c_str()); @@ -95,7 +98,7 @@ IpfixDbWriterMongoCfg::~IpfixDbWriterMongoCfg() IpfixDbWriterMongo* IpfixDbWriterMongoCfg::createInstance() { - instance = new IpfixDbWriterMongo(hostname, database, user, password, port, observationDomainId, bufferObjects, properties); + instance = new IpfixDbWriterMongo(hostname, database, user, password, port, observationDomainId, bufferObjects, properties, beautifyProperties); msg(MSG_DEBUG, "IpfixDbWriterMongo configuration host %s collection %s user %s password %s port %i observationDomainId %i bufferRecords %i\n", hostname.c_str(), database.c_str(), user.c_str(), password.c_str(), port, observationDomainId, bufferObjects); return instance; diff --git a/src/modules/ipfix/IpfixDbWriterMongoCfg.h b/src/modules/ipfix/IpfixDbWriterMongoCfg.h index fd13fd9..60f419a 100644 --- a/src/modules/ipfix/IpfixDbWriterMongoCfg.h +++ b/src/modules/ipfix/IpfixDbWriterMongoCfg.h @@ -55,6 +55,7 @@ protected: uint16_t bufferObjects; /**< amount of records to buffer until they are written to database */ uint32_t observationDomainId; /**< default observation domain id (overrides the one received in the records */ vector properties; /**< property names */ + bool beautifyProperties; /* whether to use beautified property names or raw ipfix number */ void readProperties(XMLElement* elem); IpfixDbWriterMongoCfg(XMLElement*);