Hi Jesse, there are several possibilities to write plugin-specific data into MongoDB (none of which are documented, sorry for that).
- If you can live with the overhead, you can simply inject ClusterConfigService <https://github.com/Graylog2/graylog2-server/blob/1.2.1/graylog2-plugin-interfaces/src/main/java/org/graylog2/plugin/cluster/ClusterConfigService.java> into your plugin and create a simple POJO (don't forget the Jackson annotations) which will get persisted into MongoDB. See ClusterId <https://github.com/Graylog2/graylog2-server/blob/1.2.1/graylog2-plugin-interfaces/src/main/java/org/graylog2/plugin/cluster/ClusterId.java> and ClusterIdGeneratorPeriodical <https://github.com/Graylog2/graylog2-server/blob/1.2.1/graylog2-server/src/main/java/org/graylog2/periodical/ClusterIdGeneratorPeriodical.java> for an example. - You can inject MongoConnection <https://github.com/Graylog2/graylog2-server/blob/1.2.1/graylog2-server/src/main/java/org/graylog2/database/MongoConnection.java> into your plugin which will give you access to the Mongo <https://api.mongodb.org/java/2.13/com/mongodb/Mongo.html> and DB <https://api.mongodb.org/java/2.13/com/mongodb/DB.html> objects of the MongoDB Java driver (also take a look at PersistedImpl <https://github.com/Graylog2/graylog2-server/blob/1.2.1/graylog2-server/src/main/java/org/graylog2/database/PersistedImpl.java>). This requires you to depend on the graylog2-server artifact instead of graylog2-plugin. - You can use MongoJack <http://mongojack.org/> to access MongoDB instead of the plain MongoDB Java driver, see ClusterConfigServiceImpl <https://github.com/Graylog2/graylog2-server/blob/1.2.1/graylog2-server/src/main/java/org/graylog2/cluster/ClusterConfigServiceImpl.java> for an example. Again, you'll need to depend on graylog2-server instead of graylog2-plugin to make these classes available. HTH, Jochen On Saturday, 24 October 2015 01:06:37 UTC+2, Jesse Skrivseth wrote: > > Hello all. > > Has anyone written, or have advice pertaining to, a Graylog plugin that > writes to the embedded Mongo DB? We're trying to keep a meta data catalog - > tracking distinct values, keeping counters for certain things, etc. I'd > like to avoid having to define my own configuration in the plugin and bring > my own Mongo driver. I'd rather rest on the Mongo provider in Graylog. Does > org.graylog2.plugin.database expose this? I'll keep looking for example > code, but if anyone has pointers here, I'd appreciate it! > > -- You received this message because you are subscribed to the Google Groups "Graylog Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/graylog2/0fd5de9b-ef53-4e0c-bc79-644ffe1b50ce%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
