Skip to content

Commit

Permalink
Merge pull request #25 from SEKOIA-IO/feat(check-intake-keys)
Browse files Browse the repository at this point in the history
feat(check-intake-keys): verify intake keys
  • Loading branch information
goudyj authored Jul 8, 2024
2 parents 00fdfa4 + ec88268 commit e3d32d2
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-docker-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ jobs:
push: true
tags: |
ghcr.io/sekoia-io/sekoiaio-docker-concentrator:latest
ghcr.io/sekoia-io/sekoiaio-docker-concentrator:2.5
ghcr.io/sekoia-io/sekoiaio-docker-concentrator:2.5.1
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes with sekoiaio concentrator will be documented in this file.

## [2.5.1]

- Check the format of Intake keys.

## [2.5]

- Added the support of multi-region
Expand Down
2 changes: 1 addition & 1 deletion docker-compose/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# version: "3.9"
services:
rsyslog:
image: ghcr.io/sekoia-io/sekoiaio-docker-concentrator:2.5
image: ghcr.io/sekoia-io/sekoiaio-docker-concentrator:2.5.1
environment:
- MEMORY_MESSAGES=2000000
- DISK_SPACE=180g
Expand Down
2 changes: 0 additions & 2 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

echo "Starting Entrypoint"
echo ""
echo "These Intakes have been set up"
echo "-----------------------------"

# Create rsyslog.conf
envsubst '${DISK_SPACE} ${MEMORY_MESSAGES}' <rsyslog.conf >/etc/rsyslog.conf
Expand Down
43 changes: 33 additions & 10 deletions generate_config.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
#!/usr/bin/env python

import os
import re

import yaml
from jinja2 import Environment, FileSystemLoader
import os


def is_intake_key(intake_key: str) -> re.Match | bool:
pattern = "^[a-zA-Z0-9]{16}"
return re.search(pattern, intake_key)


# Open input config file
with open("intakes.yaml", "r") as fyaml:
Expand All @@ -22,25 +30,40 @@
else:
endpoint = "intake.sekoia.io"

i=1
i = 1
to_print = []
to_print.append("These Intakes have been set up")
to_print.append("-----------------------------")

# Generate one file per intake
for item in data.get("intakes", []):
print("Intake name: " + str(item["name"].lower()))
print("Protocol: " + str(item["protocol"]))
print("Port: " + str(item["port"]))
print("Intake key: " + str(item["intake_key"]))
print("")
if not is_intake_key(item["intake_key"]):
print(
f"ERROR: The Intake Key provided for Intake Name {item['name'].lower()} is incorrect. Exiting..."
)
exit(0)

to_print.append("Intake name: " + str(item["name"].lower()))
to_print.append("Protocol: " + str(item["protocol"]))
to_print.append("Port: " + str(item["port"]))
to_print.append("Intake key: " + str(item["intake_key"]))
to_print.append("")
item["endpoint"] = endpoint
config = template.render(item)
filename = f"/etc/rsyslog.d/{i}_{item['name'].lower()}.conf"
# Écrire le contenu généré dans le fichier
with open(filename, "w") as f:
f.write(config)
i=i+1
i = i + 1

# Check additional conf
XTENDED_CONF="/extended_conf/"
XTENDED_CONF = "/extended_conf/"
if os.path.exists(XTENDED_CONF):
for file in os.listdir(XTENDED_CONF):
if file.endswith(".conf"):
print("Detected an additonal intake defined in file {}".format(file))
to_print.append(
"Detected an additonal intake defined in file {}".format(file)
)

for line in to_print:
print(line)

0 comments on commit e3d32d2

Please sign in to comment.