-
Notifications
You must be signed in to change notification settings - Fork 11
/
install-agent.sh
executable file
·227 lines (189 loc) · 6.2 KB
/
install-agent.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#!/bin/bash
# The script requires root permissions
set -e
function print_help() {
cat <<END
This is the trento-agent installer.
Trento agent is a single process that discovers information of your target SAP infrastructure and pushes them to a control plane,
your single pane of glass on your SAP Applications.
Usage:
sudo ./install-agent.sh --server-url <trento-server-url> --api-key <your-api-key> --facts-service-url <amqp-service-url>
Arguments:
--server-url The trento server url.
--facts-service-url The fact gathering service url.
--api-key The API key generated byt the trento server installation.
--rolling Use the rolling version instead of the stable one.
--use-tgz Use the trento tar.gz file from GH releases rather than the RPM.
--interval The polling interval in seconds for the discoveries.
--help Print this help.
END
}
case "$1" in
--help)
print_help
exit 0
;;
esac
if [ "$EUID" -ne 0 ]; then
echo "Please run as root."
exit
fi
ARGUMENT_LIST=(
"server-url:"
"facts-service-url"
"api-key:"
"rolling"
"use-tgz"
"interval:"
)
readonly TRENTO_VERSION=2.4.0
opts=$(
getopt \
--longoptions "$(printf "%s," "${ARGUMENT_LIST[@]}")" \
--name "$(basename "$0")" \
--options "" \
-- "$@"
)
eval set "--$opts"
while [[ $# -gt 0 ]]; do
case "$1" in
--server-url)
SERVER_URL=$2
shift 2
;;
--facts-service-url)
FACTS_SERVICE_URL=$2
shift 2
;;
--api-key)
API_KEY=$2
shift 2
;;
--rolling)
USE_ROLLING=true
shift 1
;;
--use-tgz)
USE_TGZ=true
shift 1
;;
--interval)
INTERVAL=$2
shift 2
;;
*)
break
;;
esac
done
AGENT_CONFIG_PATH="/etc/trento"
AGENT_CONFIG_FILE="$AGENT_CONFIG_PATH/agent.yaml"
AGENT_CONFIG_TEMPLATE='
server-url: @SERVER_URL@
facts-service-url: @FACTS_SERVICE_URL@
api-key: @API_KEY@
cloud-discovery-period: @INTERVAL@s
cluster-discovery-period: @INTERVAL@s
host-discovery-period: @INTERVAL@s
sapsystem-discovery-period: @INTERVAL@s
'
. /etc/os-release
if [[ ! $PRETTY_NAME =~ "SUSE" ]]; then
echo "Warning: non-SUSE operating system, forcing --use-tgz"
USE_TGZ=true
fi
echo "Installing trento-agent..."
function check_installer_deps() {
if ! which unzip >/dev/null 2>&1; then
echo "unzip is required by this script. Please install it with: zypper in -y unzip"
exit 1
fi
if ! which curl >/dev/null 2>&1; then
echo "curl is required by this script. Please install it with: zypper in -y curl"
exit 1
fi
}
function configure_installation() {
if [[ -z "$SERVER_URL" ]]; then
read -rp "Please provide the server url: " SERVER_URL </dev/tty
fi
if [[ -z "$FACTS_SERVICE_URL" ]]; then
read -rp "Please provide the facts service url: " FACTS_SERVICE_URL </dev/tty
fi
if [[ -z "$API_KEY" ]]; then
read -rp "Please provide the API key: " API_KEY </dev/tty
fi
}
function install_trento() {
if [[ -f "/usr/lib/systemd/system/trento-agent.service" ]]; then
echo "* Warning: Trento already installed. Stopping..."
systemctl stop trento-agent
fi
if [[ -n "$USE_TGZ" ]]; then
echo "* Downloading trento tar.gz from GitHub..."
install_trento_tgz
else
install_trento_rpm
fi
}
function install_trento_rpm() {
if [[ -n "$USE_ROLLING" ]]; then
TRENTO_REPO=${TRENTO_REPO:-"https://download.opensuse.org/repositories/devel:/sap:/trento:/factory/15.3/devel:sap:trento:factory.repo"}
TRENTO_REPO_KEY=${TRENTO_REPO_KEY:-"https://download.opensuse.org/repositories/devel:/sap:/trento:/factory/15.3/repodata/repomd.xml.key"}
else
TRENTO_REPO=${TRENTO_REPO:-"https://download.opensuse.org/repositories/devel:/sap:/trento/15.3/devel:sap:trento.repo"}
TRENTO_REPO_KEY=${TRENTO_REPO_KEY:-"https://download.opensuse.org/repositories/devel:/sap:/trento/15.3/repodata/repomd.xml.key"}
fi
rpm --import "${TRENTO_REPO_KEY}" >/dev/null
path=${TRENTO_REPO%/*}/
if zypper lr --details | cut -d'|' -f9 | grep "$path" >/dev/null 2>&1; then
echo "* $path repository already exists. Skipping."
else
echo "* Adding Trento repository: $path."
zypper ar "$TRENTO_REPO" >/dev/null
fi
zypper ref >/dev/null
if which trento >/dev/null 2>&1; then
echo "* Trento is already installed. Updating trento"
zypper up -y trento-agent >/dev/null
else
echo "* Installing trento"
zypper in -y trento-agent >/dev/null
fi
}
function install_trento_tgz() {
ARCH=$(uname -m | sed "s~x86_64~amd64~" | sed "s~aarch64~arm64~")
local bin_dir=${BIN_DIR:-"/usr/bin"}
local sysd_dir=${SYSD_DIR:-"/usr/lib/systemd/system"}
local repo_owner=${TRENTO_REPO_OWNER:-"trento-project"}
if [[ -n "$USE_ROLLING" ]]; then
TRENTO_TGZ_URL=https://github.com/${repo_owner}/agent/releases/download/rolling/trento-agent-${ARCH}.tgz
else
TRENTO_TGZ_URL=https://github.com/${repo_owner}/agent/releases/download/${TRENTO_VERSION}/trento-agent-${ARCH}.tgz
fi
echo "* Downloading trento from $TRENTO_TGZ_URL ..."
curl -f -sS -O -L "${TRENTO_TGZ_URL}" >/dev/null
tar -zxf trento-agent-${ARCH}.tgz
mv trento-agent ${bin_dir}/trento-agent
mv trento-agent.service ${sysd_dir}/trento-agent.service
systemctl daemon-reload
rm trento-agent-${ARCH}.tgz
}
function setup_trento() {
local interval=${INTERVAL:-"10"}
echo "* Generating trento-agent config..."
mkdir -p ${AGENT_CONFIG_PATH} && touch ${AGENT_CONFIG_FILE}
echo "$AGENT_CONFIG_TEMPLATE" |
sed "s|@SERVER_URL@|${SERVER_URL}|g" |
sed "s|@FACTS_SERVICE_URL@|${FACTS_SERVICE_URL}|g" |
sed "s|@API_KEY@|${API_KEY}|g" |
sed "s|@INTERVAL@|${interval}|g" \
>${AGENT_CONFIG_FILE}
}
check_installer_deps
configure_installation
install_trento
setup_trento
echo -e "\e[92mDone.\e[97m"
echo -e "Now you can start trento-agent with: \033[1msystemctl start trento-agent\033[0m"
echo -e "Please make sure the \033[1mserver\033[0m is running before starting the agent."