Skip to content
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

New features for Elasticsearch image: S3 repository plugin and configure_s3.sh #140

Merged
merged 5 commits into from
Mar 27, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions elasticsearch/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ ENV API_USER="foo" \

ENV XPACK_ML="true"

ENV ENABLE_CONFIGURE_S3="false"

ENV TEMPLATE_VERSION=v3.8.2

ADD https://raw.githubusercontent.com/wazuh/wazuh/$TEMPLATE_VERSION/extensions/elasticsearch/wazuh-elastic6-template-alerts.json /usr/share/elasticsearch/config
Expand All @@ -21,5 +23,10 @@ COPY --chown=elasticsearch:elasticsearch ./config/load_settings.sh ./

RUN chmod +x ./load_settings.sh

RUN elasticsearch-plugin install --batch repository-s3

COPY config/configure_s3.sh ./config/configure_s3.sh
RUN chmod 755 ./config/configure_s3.sh

ENTRYPOINT ["/entrypoint.sh"]
CMD ["elasticsearch"]
60 changes: 60 additions & 0 deletions elasticsearch/config/configure_s3.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/bash

Phandora marked this conversation as resolved.
Show resolved Hide resolved
set -e

# Check arguments
function CheckArgs()
{
if [ $1 != 4 ] && [ $1 != 5 ];then
echo "Use: configure_s3.sh <Elastic_Server_IP:Port> <Bucket> <Path> <RepositoryName> (By default <current_elasticsearch_major_version> is added to the path and the repository name)"
echo "or use: configure_s3.sh <Elastic_Server_IP:Port> <Bucket> <Path> <RepositoryName> <Elasticsearch major version>"
exit 1

fi
}

# Create repository from base_path <path>/<elasticsearch_major_version> (if there is no <Elasticsearch major version> argument, current version is added)
# Repository name would be <RepositoryName>-<elasticsearch_major_version> (if there is no <Elasticsearch major version> argument, current version is added)
function CreateRepo()
{

elastic_ip_port="$2"
bucket_name="$3"
path="$4"
repository_name="$5"

if [ $1 == 5 ];then
version="$6"
else
version=`curl -s $elastic_ip_port | grep number | cut -d"\"" -f4 | cut -c1`
Phandora marked this conversation as resolved.
Show resolved Hide resolved
fi

if ! [[ "$version" =~ ^[0-9]+$ ]];then
echo "Elasticsearch major version must be an integer"
exit 1
fi

repository="$repository_name-$version"
s3_path="$path/$version"

curl -X PUT "$elastic_ip_port/_snapshot/$repository" -H 'Content-Type: application/json' -d'
{
"type": "s3",
"settings": {
"bucket": "'$bucket_name'",
"base_path": "'$s3_path'"
}
}
'

}


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, write a comment about this function.

function Main()
{
CheckArgs $1

CreateRepo $1 $2 $3 $4 $5 $6
}

Main $# $1 $2 $3 $4 $5
19 changes: 19 additions & 0 deletions elasticsearch/config/load_settings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,25 @@ done

>&2 echo "Elastic is up - executing command"

if [ $ENABLE_CONFIGURE_S3 ]; then
#Wait for Elasticsearch to be ready to create the repository
sleep 10
Phandora marked this conversation as resolved.
Show resolved Hide resolved
IP_PORT="${ELASTICSEARCH_IP}:${ELASTICSEARCH_PORT}"

if [ "x$S3_PATH" != "x" ]; then

if [ "x$S3_ELASTIC_MAJOR" != "x" ]; then
./config/configure_s3.sh $IP_PORT $S3_BUCKET_NAME $S3_PATH $S3_REPOSITORY_NAME $S3_ELASTIC_MAJOR

else
./config/configure_s3.sh $IP_PORT $S3_BUCKET_NAME $S3_PATH $S3_REPOSITORY_NAME

fi

fi

fi

#Insert default templates

sed -i 's| "index.refresh_interval": "5s"| "index.refresh_interval": "5s", "number_of_shards" : '"${ALERTS_SHARDS}"', "number_of_replicas" : '"${ALERTS_REPLICAS}"'|' /usr/share/elasticsearch/config/wazuh-elastic6-template-alerts.json
Expand Down