Allow raw ElementID in MongoDB documents
MongoDB is schema-free and full keys are stored in each document; for these reasons it makes sense to optionally store only the ID of each netflow element instead of its description, in order to reduce memory occupation and accomodate for future/unknown keys. Signed-off-by: Luca Bruno <lucab@debian.org>master
parent
4b8c7ee4ba
commit
48ee883020
|
@ -76,10 +76,12 @@
|
|||
</ipfixAggregator>
|
||||
|
||||
<ipfixDbWriterMongo id="4">
|
||||
|
||||
<host>127.0.0.1</host>
|
||||
<database>nasty</database>
|
||||
<bufferobjects>5</bufferobjects>
|
||||
<port>27017</port>
|
||||
<beautifyProperties />
|
||||
<properties>
|
||||
<name>dstIP</name>
|
||||
<name>srcIP</name>
|
||||
|
|
|
@ -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<long long int>(intdata));
|
||||
obj << prop->propertyName << static_cast<long long int>(intdata);
|
||||
msg(MSG_DEBUG, "saw ipfix id %s (element ID %d) in packet with intdata %llX", prop->propertyName,
|
||||
prop->ipfixId, static_cast<long long int>(intdata));
|
||||
if (beautyProp)
|
||||
obj << prop->propertyName << static_cast<long long int>(intdata);
|
||||
else
|
||||
obj << boost::lexical_cast<std::string>(prop->ipfixId).c_str() << static_cast<long long int>(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<string>& propertyNames)
|
||||
const vector<string>& 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;
|
||||
|
||||
|
|
|
@ -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<string>& properties);
|
||||
const vector<string>& 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);
|
||||
|
|
|
@ -39,6 +39,7 @@ IpfixDbWriterMongoCfg::IpfixDbWriterMongoCfg(XMLElement* elem)
|
|||
if (!elem) return;
|
||||
|
||||
XMLNode::XMLSet<XMLElement*> set = _elem->getElementChildren();
|
||||
beautifyProperties = false;
|
||||
for ( XMLNode::XMLSet<XMLElement*>::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;
|
||||
|
|
|
@ -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<string> properties; /**< property names */
|
||||
bool beautifyProperties; /* whether to use beautified property names or raw ipfix number */
|
||||
|
||||
void readProperties(XMLElement* elem);
|
||||
IpfixDbWriterMongoCfg(XMLElement*);
|
||||
|
|
Loading…
Reference in New Issue