-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #204 from whyscream/test-pipeline
test script updates
- Loading branch information
Showing
4 changed files
with
98 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
#!/bin/sh | ||
|
||
# | ||
# This script is used to test the config syntax of the 50-filter-postfix.conf file. | ||
# | ||
# The configuration file is validated using the logstash --config.test_and_exit command in a docker container. | ||
# | ||
|
||
set -eux | ||
|
||
docker run --rm -it \ | ||
--volume $(pwd)/postfix.grok:/etc/logstash/patterns.d/postfix.grok \ | ||
--volume $(pwd)/50-filter-postfix.conf:/usr/share/logstash/pipeline/50-filter-postfix.conf \ | ||
logstash:8.12.0 \ | ||
--volume "$(pwd)"/postfix.grok:/etc/logstash/patterns.d/postfix.grok \ | ||
--volume "$(pwd)"/50-filter-postfix.conf:/usr/share/logstash/pipeline/50-filter-postfix.conf \ | ||
logstash:8.14.1 \ | ||
logstash --config.test_and_exit -f /usr/share/logstash/pipeline/50-filter-postfix.conf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#!/bin/sh | ||
|
||
# | ||
# This script is used to test the logstash pipeline configuration. | ||
# | ||
# It sets up a logstash pipeline with the postfix configuration, | ||
# sends a test logline through the pipeline and checks the results. | ||
# | ||
|
||
set -eux | ||
|
||
INPUT=$(mktemp tmp.logstash.in.XXXXX) | ||
OUTPUT=$(mktemp tmp.logstash.out.XXXXX) | ||
PIPELINE=$(mktemp tmp.logstash.pipeline.XXXXX) | ||
|
||
echo Preparing input data | ||
echo "postfix/smtp[123]: 7EE668039: to=<admin@example.com>, relay=127.0.0.1[127.0.0.1]:2525, delay=3.6, delays=0.2/0.02/0.04/3.3, dsn=2.0.0, status=sent (250 2.0.0 Ok: queued as 153053D)" > "$INPUT" | ||
|
||
echo Preparing pipeline config | ||
cat > "$PIPELINE" << EOF | ||
input { | ||
file { | ||
path => "/tmp/logstash.in" | ||
start_position => beginning | ||
} | ||
} | ||
filter { | ||
dissect { | ||
mapping => { | ||
"message" => "%{program}[%{pid}]: %{message}" | ||
} | ||
} | ||
} | ||
EOF | ||
|
||
cat 50-filter-postfix.conf >> "$PIPELINE" | ||
|
||
cat >> "$PIPELINE" << EOF | ||
output { | ||
file { | ||
path => "/tmp/logstash.out" | ||
} | ||
} | ||
EOF | ||
|
||
echo Starting logstash docker container | ||
CONTAINER_ID=$(docker run --rm --detach \ | ||
--volume ./"${INPUT}":/tmp/logstash.in \ | ||
--volume ./"${OUTPUT}":/tmp/logstash.out \ | ||
--volume ./postfix.grok:/etc/logstash/patterns.d/postfix.grok \ | ||
--volume ./"${PIPELINE}":/usr/share/logstash/pipeline/pipeline.conf \ | ||
logstash:8.12.0 \ | ||
logstash -f /usr/share/logstash/pipeline/pipeline.conf) | ||
|
||
printf "Waiting for output from logstash " | ||
until test -s "$OUTPUT"; do | ||
printf "." | ||
sleep 2 | ||
done | ||
echo | ||
|
||
docker stop --time 1 "$CONTAINER_ID" > /dev/null | ||
|
||
if test "$(jq .tags[0] "$OUTPUT")" = '"_grok_postfix_success"'; then | ||
echo Grok processing successful! | ||
jq . "$OUTPUT" | ||
else | ||
echo "Grok processing failed :<" | ||
jq . "$OUTPUT" | ||
exit 1 | ||
fi | ||
|
||
echo Cleaning up | ||
rm -f "$INPUT" "$OUTPUT" "$PIPELINE" | ||
|
||
echo Done |