Plugin to add graylog capability to send log messages to relational database (MySQL, PostgreSQL, etcz)
Sends log from a steam to a traditional RDMBS database via JDBC.
mvn clean package
to create JARGraylog does not ship with JDBC drivers.
You must add your driver JAR manually to plugins folder and update graylog-output-jdbc-2.5.1.jar accordingly.
Add following line to graylog2-output-jdbc-2.5.1.jar/META-INF/MANIFEST.MF
Class-Path: driver.jar
Example:
Class-Path: mysql-connector-java-8.0.17.jar
Create my-manifest.mf
and use jar tool from JDK:
jar -uvmf my-manifest.mf target/graylog-output-jdbc-2.5.1.jar
Driver class to initialize. Needed so URL can be handled properly. Recent JDK 8+ have autodiscovery of JDBC drivers so it might be not needed.
Default value: NONE
Example: com.mysql.jdbc.Driver
Fully qualified JDBC url to connect to.
Default value: NONE
Example: jdbc
//localhost:3307/graylog
Username to connect to RDBMS as. If not specified, no password will be passed to driver.
Default value: NONE
Password for user.
Default value: NONE
Comma separated list of additional attributes for Message insert query. I.e. if you have custom attribute defined in your log i.e. hostname
, specify it here and adjust a query accordingly, i.e. insert into log (message_date, message_id, source, message, hostname) values (?, ?, ?, ?, ?)
This way you don`t need to use log_attribute table, greatly increasing commit speed.
Default value: NONE
Query to execute to add log entry. Must contain required 4 columns and optional (see Additional fields). Must produce generated key (ID).
Default value: insert into log (message_date, message_id, source, message) values (?, ?, ?, ?)
If specified all attributes will be added using this query.
Default value: insert into log_attribute (log_id, name, value) values (?, ?, ?)
By default output uses table ‘log’ for main message entry and ‘log_attribute’ for attributes.
Sample table creation script (MySQL):
create table if not exists log (
id int not null auto_increment,
message_date datetime,
message_id varchar(64),
source varchar(32),
message varchar(4096) null,
PRIMARY KEY (id)
);
create table if not exists log_attribute (
id int not null auto_increment,
log_id numeric(10,0),
name varchar(255),
value varchar(4096) null,
primary key (id),
foreign key (log_id) references log(id)
);
Make sure that for table log, column ID are generated automatically. For example add ‘identity’ (MS SQL/Sybase ASE) or AUTO_INCREMENT (MySQL) into column definition.