-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scripts for building the Filebeat module for Wazuh #2142
Open
c-bordon
wants to merge
3
commits into
master
Choose a base branch
from
1563-update-filebeat-module-for-4x-installations-tomaster
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1,117 @@ | ||
#!/bin/bash | ||
|
||
# Wazuh package generator | ||
# Copyright (C) 2023, Wazuh Inc. | ||
# | ||
# This program is a free software; you can redistribute it | ||
# and/or modify it under the terms of the GNU General Public | ||
# License (version 2) as published by the FSF - Free Software | ||
# Foundation. | ||
|
||
set -e | ||
|
||
wazuh_branch="" | ||
current_path="$( cd $(dirname $0) ; pwd -P )" | ||
dockerfile_path="${current_path}/docker" | ||
container_name="filebeat_module_builder" | ||
outdir="${current_path}/output" | ||
|
||
# ----------------------------------------------------------------------------- | ||
|
||
trap ctrl_c INT | ||
|
||
clean() { | ||
exit_code=$1 | ||
|
||
# Clean the files | ||
rm -rf ${dockerfile_path}/*.sh | ||
|
||
exit ${exit_code} | ||
} | ||
|
||
ctrl_c() { | ||
clean 1 | ||
} | ||
|
||
# ----------------------------------------------------------------------------- | ||
|
||
build() { | ||
|
||
# Copy the necessary files | ||
cp ${current_path}/build.sh ${dockerfile_path} | ||
|
||
# Build the Docker image | ||
docker build -t ${container_name} ${dockerfile_path} || return 1 | ||
|
||
docker run -t --rm -v ${outdir}/:/tmp/output:Z ${container_name} ${wazuh_branch} || return 1 | ||
|
||
echo "Filebeat module file $(ls -Art ${outdir} | tail -n 1) added to ${outdir}." | ||
|
||
return 0 | ||
} | ||
|
||
# ----------------------------------------------------------------------------- | ||
|
||
help() { | ||
echo | ||
echo -e "" | ||
echo -e "NAME" | ||
echo -e " $(basename "${0}") - Build Wazuh Filebeat module." | ||
echo -e "" | ||
echo -e "SYNOPSIS" | ||
echo -e " $(basename "${0}") [OPTIONS]" | ||
echo -e "" | ||
echo -e "DESCRIPTION" | ||
echo -e " -h, --help" | ||
echo -e " Shows help." | ||
echo -e "" | ||
echo -e " -s, --store <path>" | ||
echo -e " [Optional] Set the destination path of package. By default, an output folder will be created." | ||
echo -e "" | ||
echo -e " -w, --wazuh-branch <branch>" | ||
echo -e " Enter the branch or tag of the Wazuh repository from which you want to build the module." | ||
echo -e "" | ||
exit $1 | ||
} | ||
|
||
# ----------------------------------------------------------------------------- | ||
|
||
main() { | ||
while [ -n "${1}" ] | ||
do | ||
case "${1}" in | ||
"-h"|"--help") | ||
help 0 | ||
;; | ||
"-s"|"--store") | ||
if [ -n "${2}" ]; then | ||
outdir="${2}" | ||
shift 2 | ||
else | ||
help 1 | ||
fi | ||
;; | ||
"-w"|"--wazuh-branch") | ||
if [ -n "${2}" ]; then | ||
wazuh_branch="${2}" | ||
shift 2 | ||
else | ||
help 1 | ||
fi | ||
;; | ||
*) | ||
help 1 | ||
esac | ||
done | ||
|
||
if [ -z "${wazuh_branch}" ]; then | ||
echo "Wazuh branch cannot be empty" | ||
exit $1 | ||
fi | ||
|
||
build || clean 1 | ||
|
||
clean 0 | ||
} | ||
|
||
main "$@" |
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,41 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
w_beats_branch="v7.10.2" | ||
w_wazuh_branch=$1 | ||
w_filename="" | ||
|
||
download_sources() { | ||
cd /tmp | ||
git clone https://github.com/elastic/beats.git -b $w_beats_branch --single-branch --depth=1 > /dev/null 2>&1 | ||
cd beats/filebeat/ > /dev/null 2>&1 | ||
go get > /dev/null 2>&1 | ||
make | ||
make create-module MODULE=wazuh | ||
rm -rf module/wazuh/* | ||
|
||
# Fetch Wazuh module source files | ||
cd /tmp | ||
git clone https://github.com/wazuh/wazuh -b $w_wazuh_branch --single-branch --depth=1 > /dev/null 2>&1 | ||
w_filename="wazuh-filebeat-$(cat wazuh/src/VERSION | cut -d 'v' -f 2).tar.gz" | ||
cd /tmp/beats/filebeat | ||
cp -R /tmp/wazuh/extensions/filebeat/7.x/wazuh-module/* module/wazuh | ||
} | ||
|
||
build_module() { | ||
|
||
download_sources | ||
|
||
# Generate production files for Wazuh module | ||
make update | ||
cd build/package/module | ||
chown root:root -R wazuh/ | ||
tar -czvf $w_filename wazuh/* > /dev/null 2>&1 | ||
|
||
# Move final package to /tmp/$W_FILENAME | ||
mv $w_filename /tmp/output | ||
|
||
exit 0 | ||
} | ||
|
||
build_module |
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,34 @@ | ||
FROM rockylinux:8.5 | ||
|
||
# Install all the necessary tools to build the packages | ||
RUN yum clean all && yum update -y | ||
RUN yum install -y \ | ||
curl \ | ||
tar \ | ||
git \ | ||
make \ | ||
autoconf \ | ||
automake \ | ||
python3-devel \ | ||
python3-pip \ | ||
gcc | ||
|
||
RUN curl -so go.tar.gz "https://dl.google.com/go/go1.17.10.linux-amd64.tar.gz" > /dev/null 2>&1 && \ | ||
tar -xzf go.tar.gz > /dev/null 2>&1 && \ | ||
mv go /var/ && \ | ||
rm -f go.tar.gz > /dev/null 2>&1 | ||
|
||
ENV GOROOT "/var/go" | ||
ENV GOPATH "/var" | ||
ENV PATH "$GOPATH/bin:$GOROOT/bin:$PATH" | ||
|
||
RUN git clone https://github.com/magefile/mage && \ | ||
cd mage && \ | ||
go run bootstrap.go | ||
|
||
# Add the scripts to build the RPM package | ||
ADD build.sh /usr/local/bin/builder | ||
RUN chmod +x /usr/local/bin/builder | ||
|
||
# Set the entrypoint | ||
ENTRYPOINT ["/usr/local/bin/builder"] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to add an option to set the version of the module.