Skip to content

Commit 1aab0e4

Browse files
committed
🟢 .filebeat/filebeat.yml -> Added filebeat configuration for log file paths and logstash output.
🔴 .gitignore -> Deleted log files from gitignore. 🟢 .logstash/Dockerfile -> Added Dockerfile for logstash. 🟢 .logstash/pipeline/logstash.conf -> Added logstash pipeline configuration. 🛠️ docker-compose.yaml -> Added services for elasticsearch, kibana, logstash, and filebeat. 🟢 src/mydatabase -> Added new database file. 🛠️ src/signal_documentation/settings.py -> Modified DEBUG and PAGE_SIZE settings, added logging configuration. 🛠️ src/signals/tools.py -> Added logging for signal update process.
1 parent 08b094c commit 1aab0e4

File tree

8 files changed

+126
-4
lines changed

8 files changed

+126
-4
lines changed

.filebeat/filebeat.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
filebeat.inputs:
2+
- type: log
3+
enabled: true
4+
paths:
5+
- /usr/share/filebeat/logs/*.log
6+
7+
output.logstash:
8+
hosts: ["logstash:5044"]

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
/.vscode/
44
/src/media/
55
/src/staticfiles/
6+
*log
67
*.mo
78
*.pyc
89
htmlcov/

.logstash/Dockerfile

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM docker.elastic.co/logstash/logstash:8.13.0
2+
3+
COPY pipeline/logstash.conf /usr/share/logstash/pipeline

.logstash/pipeline/logstash.conf

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
input {
3+
beats {
4+
port => 5044
5+
ssl => false
6+
}
7+
}
8+
9+
filter{
10+
json {
11+
source => "message"
12+
target => "jsoncontent"
13+
}
14+
}
15+
16+
output {
17+
elasticsearch {
18+
hosts => "elasticsearch:9200"
19+
manage_template => false
20+
index => "elk-%{+YYYY.MM.dd}"
21+
}
22+
}

docker-compose.yaml

+45-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ services:
4949
restart: always
5050
ports:
5151
- "6379:6379"
52-
52+
5353
# Production service - "service", "image", and "container_name" should all contain the same
5454
# reference, based on the name of the service.
5555
sdnginx:
@@ -109,9 +109,53 @@ services:
109109
- celery
110110
- celery-beat
111111

112+
elasticsearch:
113+
image: docker.elastic.co/elasticsearch/elasticsearch:7.10.2
114+
container_name: signal_documentation-elasticsearch
115+
environment:
116+
- discovery.type=single-node
117+
ports:
118+
- "9200:9200"
119+
- "9300:9300"
120+
121+
kinaba:
122+
image: docker.elastic.co/kibana/kibana:7.10.2
123+
container_name: signal_documentation-kibana
124+
ports:
125+
- "5601:5601"
126+
links:
127+
- elasticsearch
128+
depends_on:
129+
- elasticsearch
130+
131+
logstash:
132+
image: logstash:latest
133+
restart: always
134+
build:
135+
context: .logstash
136+
dockerfile: Dockerfile
137+
depends_on:
138+
- elasticsearch
139+
volumes:
140+
- logs_volume:/logs:ro
141+
142+
filebeat:
143+
image: docker.elastic.co/beats/filebeat:7.10.2
144+
container_name: signal_documentation-filebeat
145+
volumes:
146+
- ./filebeat/filebeat.yml:/usr/share/filebeat/filebeat.yml
147+
- ./src/logs:/usr/share/filebeat/logs
148+
environment:
149+
LASTICSEARCH_URL: http://elasticsearch:9200
150+
links:
151+
- elasticsearch
152+
depends_on:
153+
- elasticsearch
154+
112155
volumes:
113156
mysql:
114157
sdwebapp:
115158
static:
116159
celery:
117160
celery-beat:
161+
logs_volume:

src/mydatabase

792 KB
Binary file not shown.

src/signal_documentation/settings.py

+40-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
https://docs.djangoproject.com/en/4.2/ref/settings/
1111
"""
1212
import os
13+
from distutils.util import strtobool
1314
from pathlib import Path
1415
from typing import Any
1516

@@ -43,7 +44,7 @@
4344

4445

4546
# SECURITY WARNING: don't run with debug turned on in production!
46-
DEBUG: bool = True
47+
DEBUG = bool(strtobool(os.getenv('DEBUG', 'False')))
4748

4849

4950
# SECURITY WARNING: keep the secret key used in production secret!
@@ -158,7 +159,7 @@
158159
}
159160

160161

161-
PAGE_SIZE = os.environ.get('PAGE_SIZE', 10)
162+
PAGE_SIZE: int = int(os.environ.get('PAGE_SIZE', 10))
162163

163164

164165
CRISPY_ALLOWED_TEMPLATE_PACKS = "bootstrap5"
@@ -189,6 +190,43 @@
189190
),
190191
}
191192

193+
# Logging
194+
# https://docs.djangoproject.com/en/4.2/topics/logging/
195+
196+
LOGGING = {
197+
'version': 1,
198+
'disable_existing_loggers': False,
199+
'formatters': {
200+
'simple': {
201+
'format': '[%(asctime)s] %(levelname)s | %(name)s | %(message)s',
202+
'datefmt': '%Y-%m-%d %H:%M:%S',
203+
},
204+
},
205+
'handlers': {
206+
'console': {
207+
'class': 'logging.StreamHandler',
208+
'formatter': 'simple',
209+
},
210+
'file': {
211+
'class': 'logging.handlers.RotatingFileHandler',
212+
'filename': os.path.join(BASE_DIR, 'logs', 'signal_documentation.log'),
213+
'formatter': 'simple',
214+
'maxBytes': 1024*1024*15, # 15MB
215+
'backupCount': 10,
216+
}
217+
},
218+
'loggers': {
219+
'django': {
220+
'handlers': ['file', 'console'],
221+
'level': 'INFO',
222+
},
223+
},
224+
}
225+
226+
if DEBUG:
227+
for logger in LOGGING['loggers']:
228+
LOGGING['loggers'][logger]['handlers'] = ['console']
229+
192230

193231
# DRF Spectacular settings
194232
# https://drf-spectacular.readthedocs.io/en/latest/settings.html

src/signals/tools.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
import logging
12
from datetime import datetime
23

34
from signals.models import Signal
45

6+
logger = logging.getLogger('default')
7+
58

69
class SignalLastUpdatedParser:
710

@@ -33,9 +36,12 @@ def set_data(self) -> None:
3336
try:
3437
signal = Signal.objects.get(name=signal_data['signal_basename'], source__name=signal_data['source'])
3538
except Signal.DoesNotExist:
36-
# TODO: Log this
39+
logger.warning(
40+
f"Signal {signal_data['signal_basename']} not found in db. Update failed."
41+
)
3742
continue
3843
signal.last_updated = self.format_date(str(signal_data['max_issue']))
3944
signal.from_date = self.format_date(str(signal_data['min_time']))
4045
signal.to_date = self.format_date(str(signal_data['max_time']))
4146
signal.save()
47+
logger.info(f"Signal {signal_data['signal_basename']} successfully updated.")

0 commit comments

Comments
 (0)