Skip to content
This repository was archived by the owner on Oct 7, 2025. It is now read-only.

New segment mongodb - #81

Merged
ynHuber merged 2 commits into
BelWue:masterfrom
ynHuber:mongodb_output
Feb 3, 2025
Merged

ynHuber merged 2 commits into
BelWue:masterfrom
ynHuber:mongodb_output

Conversation

@ynHuber

@ynHuber ynHuber commented Oct 29, 2024

Copy link
Copy Markdown
Collaborator

Allows exporting to an external mongoDb.
By using capped collections, the disk size used by the flowpipeline output can be limited to a fixed size.
Example usage:

  • segment: mongodb
    config:
    mongodb_uri: "mongodb://localhost:27017/"
    max_disk_usage: 1 GB
    database: "flowmonitoring"
    collection: "flowdata"
    fields: "SrcAddr,DstAddr"

Allows exporting to an external mongoDb.
By using capped collections, the disk size used by flowpipeline can be limited to a fixed size

@debugloop debugloop left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀


client, err := mongo.Connect(ctx, options.Client().ApplyURI(segment.mongodbUri))
if err != nil {
log.Panic(err) // this has already been checked in New

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could still fail though ;)

Comment on lines +102 to +125
if config == nil {
return newsegment, errors.New("missing configuration for segment mongodb")
}

if config["mongodb_uri"] == "" {
return newsegment, errors.New("mongoDB: mongodb_uri not defined")
}
newsegment.mongodbUri = config["mongodb_uri"]

if config["database"] == "" {
log.Println("[INFO] mongoDB: no database defined - using default value (flowdata)")
config["database"] = "flowdata"
}
newsegment.databaseName = config["database"]

if config["collection"] == "" {
log.Println("[INFO] mongoDB: no collection defined - using default value (ringbuffer)")
config["collection"] = "ringbuffer"
}
newsegment.collectionName = config["collection"]

var ringbufferSize int64 = 10737418240
if config["max_disk_usage"] == "" {
log.Println("[INFO] mongoDB: no ring buffer size defined - using default value (10GB)")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be time to rethink config parsing or even add some config parsing library in the future. I did not know enough about Go back in the day, but this sure is a lot of manual work.

@ynHuber ynHuber mentioned this pull request Jan 29, 2025
@ynHuber
ynHuber merged commit 5d8a137 into BelWue:master Feb 3, 2025
ynHuber added a commit that referenced this pull request Feb 3, 2025
New Major Version v2

### Maintenance
- Moved GitHub orgs from bwNetFlow to BelWue @9er  #89
- Upgraded golang version to 1.23.2

### Bug fixes
- waitgroup in lumberjack segment. (@JustKiddingCode #79)
-  vacuum_interval for prometheus Export (@ynHuber #85)

### New segments
- diskbuffer (@JustKiddingCode #78)
- mongodb (@ynHuber #81)

### Breaking Changes:
- Protobuffer upgrade to match changes [introduced  in goflow2 v2.2.1](netsampler/goflow2@3326554) (@ynHuber  #86)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

⌂ 换网址