Skip to content

Commit 3e4b722

Browse files
committed
add logstash files
1 parent f5182d3 commit 3e4b722

File tree

7 files changed

+114
-0
lines changed

7 files changed

+114
-0
lines changed

logstash/db-enrichment/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
up:
2+
docker-compose up --build
3+
4+
down:
5+
docker-compose down
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
services:
2+
postgres:
3+
image: postgres:15
4+
container_name: postgres
5+
restart: always
6+
environment:
7+
POSTGRES_USER: user
8+
POSTGRES_PASSWORD: password
9+
POSTGRES_DB: main
10+
ports:
11+
- 5432:5432
12+
volumes:
13+
- ./postgres/init.sql:/docker-entrypoint-initdb.d/init.sql
14+
15+
logstash:
16+
image: docker.elastic.co/logstash/logstash:8.11.2
17+
container_name: logstash
18+
restart: always
19+
build:
20+
context: logstash
21+
environment:
22+
DB_USER: user
23+
DB_PASSWORD: password
24+
DB_JDBC_CONNECTION_STRING: jdbc:postgresql://postgres:5432/users_logs
25+
volumes:
26+
- ./logstash/pipeline:/usr/share/logstash/pipeline
27+
- ./logstash/config/logstash.yml:/usr/share/logstash/config/logstash.yml
28+
- ./logstash/config/pipelines.yml:/usr/share/logstash/config/pipelines.yml
29+
30+
adminer:
31+
image: adminer
32+
container_name: adminer
33+
restart: always
34+
ports:
35+
- "8080:8080"
36+
environment:
37+
ADMINER_DEFAULT_SERVER: postgres
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM docker.elastic.co/logstash/logstash:8.11.2
2+
3+
WORKDIR /usr/share/logstash
4+
5+
RUN curl -o /usr/share/logstash/postgresql-42.5.0.jar https://jdbc.postgresql.org/download/postgresql-42.5.0.jar
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
http.host: "0.0.0.0"
3+
config.reload.automatic: true
4+
log.level: info
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
- pipeline.id: app
2+
path.config: pipeline/pipeline.cfg
3+
pipeline.workers: 1
4+
config.reload.automatic: true
5+
config.reload.interval: 10s
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
input {
2+
generator {
3+
lines => [
4+
'{"event": "login", "user_id": 1}',
5+
'{"event": "logout", "user_id": 2}',
6+
'{"event": "purchase", "user_id": 3}'
7+
]
8+
count => 3
9+
}
10+
}
11+
12+
filter {
13+
json {
14+
source => "message"
15+
}
16+
17+
mutate {
18+
remove_field => ["message"]
19+
}
20+
21+
jdbc_streaming {
22+
jdbc_connection_string => "${DB_JDBC_CONNECTION_STRING}"
23+
jdbc_user => "${DB_USER}"
24+
jdbc_password => "${DB_PASSWORD}"
25+
jdbc_driver_library => "/usr/share/logstash/postgresql-42.5.0.jar"
26+
jdbc_driver_class => "org.postgresql.Driver"
27+
statement => "
28+
SELECT user_name, user_email, user_group
29+
FROM db_users
30+
WHERE id = :input_parameter
31+
"
32+
parameters => {
33+
"input_parameter" => "user_id"
34+
}
35+
target => "sql"
36+
}
37+
38+
}
39+
40+
output {
41+
stdout { codec => rubydebug }
42+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
CREATE DATABASE users_logs;
2+
3+
\c users_logs;
4+
5+
CREATE TABLE db_users (
6+
id SERIAL PRIMARY KEY,
7+
user_name VARCHAR(100) NOT NULL,
8+
user_email VARCHAR(100) NOT NULL UNIQUE,
9+
user_group VARCHAR(50) NOT NULL
10+
);
11+
12+
INSERT INTO db_users (user_name, user_email, user_group) VALUES
13+
('Alice Silva', '[email protected]', 'admin'),
14+
('Bruno Costa', '[email protected]', 'user'),
15+
('Carlos Mendes', '[email protected]', 'user'),
16+
('Diana Lopes', '[email protected]', 'moderator');

0 commit comments

Comments
 (0)