forked from dafal/cortex-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
executable file
·107 lines (96 loc) · 2.96 KB
/
entrypoint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/bin/bash
ES_HOSTNAME=elasticsearch
CONFIG_SECRET=1
CONFIG_ES=1
CONFIG=1
CONFIG_FILE=/etc/cortex/application.conf
ANALYZER_PATH=/opt/Cortex-Analyzers/analyzers
RESPONDER_PATH=/opt/Cortex-Analyzers/responders
function usage {
cat <<- _EOF_
Available options:
--no-config | do not try to configure TheHive (add secret and elasticsearch)
--no-config-secret | do not add random secret to configuration
--no-config-es | do not add elasticsearch hosts to configuration
--es-hosts <esconfig> | use this string to configure elasticsearch hosts (format: ["host1:9300","host2:9300"])
--es-hostname <host> | resolve this hostname to find elasticseach instances
--secret <secret> | secret to secure sessions
--analyzer-path <path> | where analyzers are located
--responder-path <path> | where responders are located
_EOF_
exit 1
}
if [ ! -f $CONFIG_FILE ]; then
hocon -i /tmp/application.conf.default set search.host [\"elasticsearch\:9300\"] | \
hocon set responder.path [\"\/opt\/Cortex-Analyzers\/responders\"] | \
hocon set responder.fork-join-executor.parallelism-min 2 | \
hocon set responder.fork-join-executor.parallelism-factor 2.0 | \
hocon set responder.fork-join-executor.parallelism-max 4 | \
hocon -o /etc/cortex/application.conf set analyzer.path [\"\/opt\/Cortex-Analyzers\/analyzers\"]
fi
if [ ! -f /etc/thehive/logback.xml ]; then
cp /tmp/logback.xml.default /etc/cortex/logback.xml
fi
STOP=0
while test $# -gt 0 -o $STOP = 1
do
case "$1" in
"--no-config") CONFIG=0;;
"--no-config-secret") CONFIG_SECRET=0;;
"--no-config-es") CONFIG_ES=0;;
"--es-hosts") shift; ES_HOSTS=$1;;
"--es-hostname") shift; ES_HOSTNAME=$1;;
"--secret") shift; SECRET=$1;;
"--analyzer-path") shift; ANALYZER_PATH=$1;;
"--responder-path") shift; RESPONDER_PATH=$1;;
"--") STOP=1;;
*) usage
esac
shift
done
if test $CONFIG = 1
then
CONFIG_FILE=$(mktemp).conf
if test $CONFIG_SECRET = 1
then
if test -z "$SECRET"
then
SECRET=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 64 | head -n 1)
fi
echo Using secret: $SECRET
echo play.http.secret.key=\"$SECRET\" >> $CONFIG_FILE
fi
if test $CONFIG_ES = 1
then
if test -z "$ES_HOSTS"
then
function join_es_hosts {
echo -n "[\"$1"
shift
printf "%s:9300\"]" "${@/#/:9300\",\"}"
}
ES=$(getent ahostsv4 $ES_HOSTNAME | awk '{ print $1 }' | sort -u)
if test -z "$ES"
then
echo "Warning automatic elasticsearch host config fails"
else
ES_HOSTS=$(join_es_hosts $ES)
fi
fi
if test -n "$ES_HOSTS"
then
echo Using elasticsearch host: $ES_HOSTS
echo search.host=$ES_HOSTS >> $CONFIG_FILE
else
echo elasticsearch host not configured
fi
fi
echo analyzer.path=[\"$ANALYZER_PATH\"] >> $CONFIG_FILE
echo responder.path=[\"$RESPONDER_PATH\"] >> $CONFIG_FILE
echo 'include file("/etc/cortex/application.conf")' >> $CONFIG_FILE
fi
exec bin/cortex \
-Dconfig.file=$CONFIG_FILE \
-Dlogger.file=/etc/cortex/logback.xml \
-Dpidfile.path=/dev/null \
$@