forked from signalfx/splunk-otel-collector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·1087 lines (960 loc) · 35.3 KB
/
install.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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/sh
# Copyright 2020 Splunk, Inc.
# Copyright The OpenTelemetry Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# A convenience script to install the collector package on any of our supported
# distros. Please refer to
# https://github.com/signalfx/splunk-otel-collector/tree/main/deployments for
# other installation methods (ansible, chef, puppet, etc.) that are
# more suitable for production environments.
set -euf
get_distro() {
local distro="$(. /etc/os-release 2>/dev/null && echo ${ID:-} || true)"
echo "$distro"
}
get_distro_version() {
local version="$(. /etc/os-release 2>/dev/null && echo ${VERSION_ID:-} || true)"
echo "$version"
}
get_distro_codename() {
local distro="$( get_distro )"
local codename="$(. /etc/os-release 2>/dev/null && echo ${VERSION_CODENAME:-} || true)"
if [ "$distro" = "debian" ] && [ -z "$codename" ]; then
case "$( get_distro_version )" in
9)
codename="stretch"
;;
10)
codename="buster"
;;
11)
codename="bullseye"
;;
*)
codename=""
;;
esac
fi
echo "$codename"
}
collector_config_dir="/etc/otel/collector"
agent_config_path="${collector_config_dir}/agent_config.yaml"
gateway_config_path="${collector_config_dir}/gateway_config.yaml"
old_config_path="${collector_config_dir}/splunk_config_linux.yaml"
collector_env_path="${collector_config_dir}/splunk-otel-collector.conf"
collector_env_old_path="${collector_config_dir}/splunk_env"
collector_bundle_dir="/usr/lib/splunk-otel-collector/agent-bundle"
collectd_config_dir="${collector_bundle_dir}/run/collectd"
distro="$( get_distro )"
distro_codename="$( get_distro_codename )"
distro_version="$( get_distro_version )"
repo_base="https://splunk.jfrog.io/splunk"
deb_repo_base="${repo_base}/otel-collector-deb"
debian_gpg_key_url="${deb_repo_base}/splunk-B3CD4420.gpg"
rpm_repo_base="${repo_base}/otel-collector-rpm"
yum_gpg_key_url="${rpm_repo_base}/splunk-B3CD4420.pub"
fluent_capng_c_version="0.2.2"
fluent_config_dir="${collector_config_dir}/fluentd"
fluent_config_path="${fluent_config_dir}/fluent.conf"
fluent_plugin_systemd_version="1.0.1"
journald_config_path="${fluent_config_dir}/conf.d/journald.conf"
td_agent_repo_base="https://packages.treasuredata.com"
td_agent_gpg_key_url="${td_agent_repo_base}/GPG-KEY-td-agent"
default_stage="release"
default_realm="us0"
default_memory_size="512"
default_collector_version="latest"
default_td_agent_version="4.3.2"
default_td_agent_version_stretch="3.7.1-0"
default_service_user="splunk-otel-collector"
default_service_group="splunk-otel-collector"
if [ "$distro_codename" = "stretch" ]; then
default_td_agent_version="$default_td_agent_version_stretch"
fi
default_instrumentation_version="latest"
default_deployment_environment=""
instrumentation_config_path="/usr/lib/splunk-instrumentation/instrumentation.conf"
instrumentation_so_path="/usr/lib/splunk-instrumentation/libsplunk.so"
instrumentation_jar_path="/usr/lib/splunk-instrumentation/splunk-otel-javaagent.jar"
repo_for_stage() {
local repo_url=$1
local stage=$2
echo "$repo_url/$stage"
}
download_file_to_stdout() {
local url=$1
if command -v curl > /dev/null; then
curl -sSL $url
elif command -v wget > /dev/null; then
wget -O - -o /dev/null $url
else
echo "Either curl or wget must be installed to download $url" >&2
exit 1
fi
}
request_access_token() {
local access_token=
while [ -z "$access_token" ]; do
read -p "Please enter your Splunk access token: " access_token
done
echo "$access_token"
}
verify_access_token() {
local access_token="$1"
local ingest_url="$2"
local insecure="$3"
if command -v curl > /dev/null; then
api_output=$(curl \
-d '[]' \
-H "X-Sf-Token: $access_token" \
-H "Content-Type:application/json" \
-X POST \
$([ "$insecure" = "true" ] && echo -n "--insecure") \
"$ingest_url"/v2/event 2>/dev/null)
elif command -v wget > /dev/null; then
api_output=$(wget \
--header="Content-Type: application/json" \
--header="X-Sf-Token: $access_token" \
--post-data='[]' \
$([ "$insecure" = "true" ] && echo -n "--no-check-certificate") \
-O - \
-o /dev/null \
"$ingest_url"/v2/event)
if [ $? -eq 5 ]; then
echo "TLS cert for Splunk ingest could not be verified, does your system have TLS certs installed?" >&2
exit 1
fi
else
echo "Either curl or wget is required to verify the access token" >&2
exit 1
fi
if [ "$api_output" = "\"OK\"" ]; then
true
else
echo "$api_output"
false
fi
}
download_debian_key() {
local key_url="$1"
local key_path="$2"
if ! download_file_to_stdout "$key_url" > $key_path; then
echo "Could not get Debian GPG signing key from $key_url" >&2
exit 1
fi
chmod 644 $key_path
}
install_collector_apt_repo() {
local stage="$1"
local trusted_flag=
if [ "$stage" = "test" ]; then
trusted_flag="[trusted=yes]"
fi
download_debian_key "$debian_gpg_key_url" "/etc/apt/trusted.gpg.d/splunk.gpg"
echo "deb $trusted_flag $deb_repo_base $stage main" > /etc/apt/sources.list.d/splunk-otel-collector.list
}
install_td_agent_apt_repo() {
local td_agent_version="$1"
local td_agent_major_version="$( echo $td_agent_version | cut -d '.' -f1 )"
if ! download_file_to_stdout "$td_agent_gpg_key_url" | apt-key add -; then
echo "Could not download Debian GPG key from $td_agent_gpg_key_url" >&2
exit 1
fi
echo "deb ${td_agent_repo_base}/${td_agent_major_version}/${distro}/${distro_codename} $distro_codename contrib" > /etc/apt/sources.list.d/td_agent.list
}
install_apt_package() {
local package_name="$1"
local version="$2"
if [ "$version" = "latest" ]; then
version=""
elif [ -n "$version" ]; then
version="=${version}"
fi
apt-get -y install ${package_name}${version}
}
install_collector_yum_repo() {
local stage="$1"
local repo_path="${2:-/etc/yum.repos.d}"
local gpgcheck="1"
if [ "$stage" = "test" ]; then
gpgcheck="0"
fi
cat <<EOH > ${repo_path}/splunk-otel-collector.repo
[splunk-otel-collector]
name=Splunk OpenTelemetry Collector Repository
baseurl=$( repo_for_stage $rpm_repo_base $stage )/\$basearch
gpgcheck=$gpgcheck
repo_gpgcheck=$gpgcheck
gpgkey=$yum_gpg_key_url
enabled=1
EOH
}
install_td_agent_yum_repo() {
local td_agent_version="$1"
local repo_path="${2:-/etc/yum.repos.d}"
local td_agent_major_version="$( echo $td_agent_version | cut -d '.' -f1 )"
local releasever="$( echo "$distro_version" | cut -d '.' -f1 )"
if [ "$distro" = "amzn" ]; then
distro="amazon"
else
distro="redhat"
fi
cat <<EOH > ${repo_path}/td_agent.repo
[td_agent]
name=TreasureData Repository
baseurl=${td_agent_repo_base}/${td_agent_major_version}/${distro}/${releasever}/\$basearch
gpgcheck=1
gpgkey=$td_agent_gpg_key_url
enabled=1
EOH
}
install_yum_package() {
local package_name="$1"
local version="${2:-}"
if [ "$version" = "latest" ]; then
version=""
elif [ -n "$version" ]; then
version="-${version}"
fi
if command -v yum >/dev/null 2>&1; then
yum install -y ${package_name}${version}
elif command -v dnf >/dev/null 2>&1; then
dnf install -y ${package_name}${version}
else
zypper install -y ${package_name}${version}
fi
}
ensure_not_installed() {
local with_fluentd="$1"
local with_instrumentation="$2"
local agents="otelcol"
if [ "$with_fluentd" = "true" ]; then
agents="$agents td-agent"
fi
for agent in $agents; do
if command -v $agent >/dev/null 2>&1; then
echo "An agent binary already exists at $( command -v $agent ) which implies that the agent has already been installed." >&2
echo "Please uninstall the agent and re-run this script." >&2
exit 1
fi
done
if [ "$with_instrumentation" = "true" ] && [ -f "$instrumentation_so_path" ]; then
echo "$instrumentation_so_path already exists which implies that the instrumentation library has already been installed." >&2
echo "Please uninstall the instrumentation library and re-run this script" >&2
exit 1
fi
}
configure_env_file() {
local key="$1"
local value="$2"
local env_file="$3"
echo "${key}=${value}" >> "$env_file"
}
create_user_group() {
local user="$1"
local group="$2"
getent group $group >/dev/null 2>&1 || \
groupadd --system $group
getent passwd $user >/dev/null 2>&1 || \
useradd --system --no-user-group --home-dir /etc/otel/collector --no-create-home --shell $(command -v nologin) --groups $group $user
}
configure_service_owner() {
local service_user="$1"
local service_group="$2"
local tmpfile_path="/etc/tmpfiles.d/splunk-otel-collector.conf"
local override_path="/etc/systemd/system/splunk-otel-collector.service.d/service-owner.conf"
systemctl stop splunk-otel-collector
mkdir -p $(dirname $tmpfile_path)
cat <<EOH > $tmpfile_path
D /run/splunk-otel-collector 0755 ${service_user} ${service_group} - -
EOH
systemd-tmpfiles --create --remove $tmpfile_path
mkdir -p $(dirname $override_path)
cat <<EOH > $override_path
[Service]
User=${service_user}
Group=${service_group}
EOH
chown root:root $override_path
chmod 644 $override_path
systemctl daemon-reload
}
fluent_plugin_installed() {
local name="$1"
td-agent-gem list "$name" --exact | grep -q "$name"
}
install_fluent_plugin() {
local name="$1"
local version="${2:-}"
if [ -n "$version" ]; then
td-agent-gem install "$name" --version "$version"
else
td-agent-gem install "$name"
fi
}
configure_fluentd() {
local override_src_path="$fluent_config_dir/splunk-otel-collector.conf"
local override_dest_path="/etc/systemd/system/td-agent.service.d/splunk-otel-collector.conf"
if [ -f "$override_src_path" ]; then
systemctl stop td-agent
mkdir -p $(dirname $override_dest_path)
cp -f $override_src_path $override_dest_path
chown root:root $override_dest_path
chmod 644 $override_dest_path
systemctl daemon-reload
# ensure the td-agent user has access to the config dir
chown -R td-agent:td-agent "$fluent_config_dir"
# configure permissions/capabilities
if [ -f /opt/td-agent/bin/fluent-cap-ctl ]; then
if ! fluent_plugin_installed "capng_c"; then
install_fluent_plugin "capng_c" "$fluent_capng_c_version"
fi
/opt/td-agent/bin/fluent-cap-ctl --add "dac_override,dac_read_search" -f /opt/td-agent/bin/ruby
else
if getent group adm >/dev/null 2>&1; then
usermod -a -G adm td-agent
fi
if getent group systemd-journal 2>&1; then
usermod -a -G systemd-journal td-agent
fi
fi
if ! fluent_plugin_installed "fluent-plugin-systemd"; then
install_fluent_plugin "fluent-plugin-systemd" "$fluent_plugin_systemd_version"
fi
fi
}
update_instrumentation_config() {
local deployment_environment="$1"
if [ -f "$instrumentation_config_path" ]; then
if grep -q -E "^resource_attributes=.*deployment\.environment=${deployment_environment}(,|$)" "$instrumentation_config_path"; then
echo "The 'deployment.environment=${deployment_environment}' resource attribute already exists in ${instrumentation_config_path}"
return 0
fi
ts="$(date '+%Y%m%d-%H%M%S')"
echo "Backing up $instrumentation_config_path as ${instrumentation_config_path}.bak.${ts}"
cp "$instrumentation_config_path" "${instrumentation_config_path}.bak.${ts}"
echo "Adding 'deployment.environment=${deployment_environment}' resource attribute to $instrumentation_config_path"
if grep -q '^resource_attributes=' "$instrumentation_config_path"; then
# traverse through existing resource attributes to add/update deployment.environment
deployment_environment_found="false"
attributes=""
for i in $(grep '^resource_attributes=' "$instrumentation_config_path" | sed 's|^resource_attributes=||' | sed 's|,| |g'); do
key="$(echo "$i" | cut -d= -f1)"
value="$(echo "$i" | cut -d= -f2)"
if [ "$key" = "deployment.environment" ]; then
deployment_environment_found="true"
value="$deployment_environment"
fi
attributes="${attributes},${key}=${value}"
done
if [ "$deployment_environment_found" != "true" ]; then
attributes="${attributes},deployment.environment=${deployment_environment}"
fi
sed -i "s|^resource_attributes=.*|resource_attributes=${attributes#,}|" "$instrumentation_config_path"
else
# "resource_attributes=" line not found, simply append the line to the config file
echo "resource_attributes=deployment.environment=${deployment_environment}" >> "$instrumentation_config_path"
fi
else
echo "$instrumentation_config_path not found!" >&2
exit 1
fi
}
install() {
local stage="$1"
local collector_version="$2"
local td_agent_version="$3"
local skip_collector_repo="$4"
local skip_fluentd_repo="$5"
local instrumentation_version="$6"
case "$distro" in
ubuntu|debian)
if [ -z "$distro_codename" ]; then
echo "The distribution codename could not be determined" >&2
exit 1
fi
apt-get -y update
apt-get -y install apt-transport-https gnupg
if [ "$skip_collector_repo" = "false" ]; then
install_collector_apt_repo "$stage"
fi
apt-get -y update
install_apt_package "splunk-otel-collector" "$collector_version"
if [ -n "$td_agent_version" ]; then
if [ "$distro_codename" != "stretch" ]; then
td_agent_version="${td_agent_version}-1"
fi
if [ "$skip_fluentd_repo" = "false" ]; then
install_td_agent_apt_repo "$td_agent_version"
fi
apt-get -y update
install_apt_package "td-agent" "$td_agent_version"
apt-get -y install build-essential libcap-ng0 libcap-ng-dev pkg-config
systemctl stop td-agent
fi
if [ -n "$instrumentation_version" ]; then
install_apt_package "splunk-otel-auto-instrumentation" "$instrumentation_version"
fi
;;
amzn|centos|ol|rhel)
if [ -z "$distro_version" ]; then
echo "The distribution version could not be determined" >&2
exit 1
fi
install_yum_package "libcap"
if [ "$skip_collector_repo" = "false" ]; then
install_collector_yum_repo "$stage"
fi
install_yum_package "splunk-otel-collector" "$collector_version"
if [ -n "$td_agent_version" ]; then
if [ "$skip_fluentd_repo" = "false" ]; then
install_td_agent_yum_repo "$td_agent_version"
fi
install_yum_package "td-agent" "$td_agent_version"
if command -v yum >/dev/null 2>&1; then
yum group install -y 'Development Tools'
else
dnf group install -y 'Development Tools'
fi
for pkg in libcap-ng libcap-ng-devel pkgconfig; do
install_yum_package "$pkg" ""
done
systemctl stop td-agent
fi
if [ -n "$instrumentation_version" ]; then
install_yum_package "splunk-otel-auto-instrumentation" "$instrumentation_version"
fi
;;
sles|opensuse*)
if [ "$skip_collector_repo" = "false" ]; then
rpm --import $yum_gpg_key_url
install_collector_yum_repo "$stage" "/etc/zypp/repos.d/"
fi
zypper -n --gpg-auto-import-keys refresh
install_yum_package "libcap-progs"
install_yum_package "splunk-otel-collector" "$collector_version"
if [ -n "$instrumentation_version" ]; then
install_yum_package "splunk-otel-auto-instrumentation" "$instrumentation_version"
fi
;;
*)
echo "Your distro ($distro) is not supported or could not be determined" >&2
exit 1
;;
esac
}
uninstall() {
for agent in otelcol td-agent $instrumentation_so_path; do
if command -v $agent >/dev/null 2>&1; then
pkg="$agent"
if [ "$agent" = "otelcol" ]; then
pkg="splunk-otel-collector"
elif [ "$agent" = "$instrumentation_so_path" ]; then
pkg="splunk-otel-auto-instrumentation"
fi
case "$distro" in
ubuntu|debian)
if dpkg -s $pkg >/dev/null 2>&1; then
if [ "$pkg" != "splunk-otel-auto-instrumentation" ]; then
systemctl stop $pkg || true
fi
apt-get purge -y $pkg 2>&1
echo "Successfully removed the $pkg package"
else
agent_path="$( command -v agent )"
echo "$agent_path exists but the $pkg package is not installed" >&2
echo "$agent_path needs to be manually removed/uninstalled" >&2
exit 1
fi
;;
amzn|centos|ol|rhel|sles|opensuse*)
if rpm -q $pkg >/dev/null 2>&1; then
if [ "$pkg" != "splunk-otel-auto-instrumentation" ]; then
systemctl stop $pkg || true
fi
if command -v yum >/dev/null 2>&1; then
yum remove -y $pkg 2>&1
elif command -v dnf >/dev/null 2>&1; then
dnf remove -y $pkg 2>&1
else
zypper remove -y $pkg
fi
echo "Successfully removed the $pkg package"
else
agent_path="$( command -v agent )"
echo "$agent_path exists but the $pkg package is not installed" >&2
echo "$agent_path needs to be manually removed/uninstalled" >&2
exit 1
fi
;;
*)
echo "Your distro ($distro) is not supported or could not be determined" >&2
exit 1
;;
esac
fi
done
}
usage() {
cat <<EOH >&2
Usage: $0 [options] [access_token]
Installs the Splunk OpenTelemetry Collector for Linux from the package repos.
If access_token is not provided, it will be prompted for on stdin.
Options:
--api-url <url> Set the api endpoint URL explicitly instead of the endpoint inferred from the specified realm
(default: https://api.REALM.signalfx.com)
--ballast <ballast size> Set the ballast size explicitly instead of the value calculated from the --memory option
This should be set to 1/3 to 1/2 of configured memory
--beta Use the beta package repo instead of the primary
--collector-config <path> Set the path to an existing custom config file for the collector service instead of the default
config file provided by the collector package based on the '--mode <agent|gateway>' option.
*Note*: If the specified config file requires custom environment variables, the variables and
values can be manually added to $collector_env_path after installation.
Restart the collector service with the 'sudo systemctl restart splunk-otel-collector' command
for the changes to take effect.
--collector-version <version> The splunk-otel-collector package version to install (default: "$default_collector_version")
--hec-token <token> Set the HEC token if different than the specified Splunk access_token
--hec-url <url> Set the HEC endpoint URL explicitly instead of the endpoint inferred from the specified realm
(default: https://ingest.REALM.signalfx.com/v1/log)
--ingest-url <url> Set the ingest endpoint URL explicitly instead of the endpoint inferred from the specified realm
(default: https://ingest.REALM.signalfx.com)
--memory <memory size> Total memory in MIB to allocate to the collector; automatically calculates the ballast size
(default: "$default_memory_size")
--mode <agent|gateway> Configure the collector service to run in agent or gateway mode (default: "agent")
--realm <us0|us1|eu0|...> The Splunk realm to use (default: "$default_realm")
The ingest, api, trace, and HEC endpoint URLs will automatically be inferred by this value
--service-group <group> Set the group for the splunk-otel-collector service (default: "$default_service_group")
The group will be created if it does not exist
--service-user <user> Set the user for the splunk-otel-collector service (default: "$default_service_user")
The user will be created if it does not exist
--skip-collector-repo By default, a apt/yum/zypper repo definition file will be created to download the
collector deb/rpm package from $repo_base. Specify this option to skip this step
and use a pre-configured repo on the target system that provides the
'splunk-otel-collector' deb/rpm package.
--skip-fluentd-repo By default, a apt/yum repo definition file will be created to download the fluentd
deb/rpm package from $td_agent_repo_base. Specify this option to skip this step
and use a pre-configured repo on the target system that provides the
'td-agent' deb/rpm package.
--test Use the test package repo instead of the primary
--trace-url <url> Set the trace endpoint URL explicitly instead of the endpoint inferred from the specified realm
(default: https://ingest.REALM.signalfx.com/v2/trace)
--uninstall Removes the Splunk OpenTelemetry Collector for Linux
--with[out]-fluentd Whether to install and configure fluentd to forward log events to the collector
(default: --with-fluentd)
--with[out]-instrumentation Whether to install and configure the splunk-otel-auto-instrumentation package
(default: --without-instrumentation)
--deployment-environment <value> Set the 'deployment.environment' resource attribute to the specified value.
Only applicable if the '--with-instrumentation' option is also specified.
(default: empty)
--instrumentation-version The splunk-otel-auto-instrumentation package version to install (default: $default_instrumentation_version)
-- Use -- if access_token starts with -
EOH
exit 0
}
distro_is_supported() {
case "$distro" in
ubuntu)
case "$distro_codename" in
bionic|focal|xenial|jammy)
return 0
;;
esac
;;
debian)
case "$distro_codename" in
bullseye|buster|stretch)
return 0
;;
esac
;;
amzn)
case "$distro_version" in
2)
return 0
;;
esac
;;
sles|opensuse*)
case "$distro_version" in
12*|15*|42*)
return 0
;;
esac
;;
centos|ol|rhel)
case "$distro_version" in
7*|8*)
return 0
;;
esac
;;
esac
return 1
}
parse_args_and_install() {
local access_token=
local api_url=
local ballast=
local collector_version="$default_collector_version"
local hec_token=
local hec_url=
local ingest_url=
local insecure=
local memory="$default_memory_size"
local realm="$default_realm"
local service_group="$default_service_group"
local stage="$default_stage"
local service_user="$default_service_user"
local td_agent_version="$default_td_agent_version"
local trace_url=
local uninstall="false"
local mode="agent"
local with_fluentd="true"
local collector_config_path=
local skip_collector_repo="false"
local skip_fluentd_repo="false"
local with_instrumentation="false"
local instrumentation_version="$default_instrumentation_version"
local deployment_environment="$default_deployment_environment"
while [ -n "${1-}" ]; do
case $1 in
--api-url)
api_url="$2"
shift 1
;;
--ballast)
ballast="$2"
shift 1
;;
--beta)
stage="beta"
;;
--collector-config)
collector_config_path="$2"
shift 1
;;
--collector-version)
collector_version="$2"
shift 1
;;
-h|--help)
usage
exit 0
;;
--hec-token)
hec_token="$2"
shift 1
;;
--hec-url)
hec_url="$2"
shift 1
;;
--ingest-url)
ingest_url="$2"
shift 1
;;
--insecure)
insecure="true"
;;
--memory)
memory="$2"
shift 1
;;
--mode)
case $2 in
agent|gateway)
mode="$2"
;;
*)
echo "Unsupported mode '$2'" >&2
exit 1
;;
esac
shift 1
;;
--realm)
realm="$2"
shift 1
;;
--service-group)
service_group="$2"
shift 1
;;
--service-user)
service_user="$2"
shift 1
;;
--skip-collector-repo)
skip_collector_repo="true"
;;
--skip-fluentd-repo)
skip_fluentd_repo="true"
;;
--test)
stage="test"
;;
--trace-url)
trace_url="$2"
shift 1
;;
--uninstall)
uninstall="true"
;;
--with-fluentd)
with_fluentd="true"
;;
--without-fluentd)
with_fluentd="false"
;;
--with-instrumentation)
with_instrumentation="true"
;;
--without-instrumentation)
with_instrumentation="false"
;;
--instrumentation-version)
instrumentation_version="$2"
shift 1
;;
--deployment-environment)
deployment_environment="$2"
shift 1
;;
--)
access_token="$2"
shift 1
;;
-*)
echo "Unknown option $1" >&2
usage
exit 1
;;
*)
if [ -z "$access_token" ]; then
access_token=$1
else
echo "Unknown argument $1" >&2
usage
exit 1
fi
;;
esac
shift 1
done
if [ "$uninstall" = true ]; then
uninstall
exit 0
fi
case "$distro" in
debian|ubuntu)
if [ -z "$distro_codename" ]; then
echo "Your Linux distribution codename could not be determined from /etc/os-release." >&2
exit 1
fi
;;
*)
if [ -z "$distro" ]; then
echo "Your Linux distribution could not be determined from /etc/os-release." >&2
exit 1
fi
if [ -z "$distro_version" ]; then
echo "Your Linux distribution version could not be determined from /etc/os-release." >&2
exit 1
fi
;;
esac
if ! distro_is_supported; then
echo "Your Linux distribution/version is not supported." >&2
exit 1
fi
if ! command -v systemctl >/dev/null 2>&1; then
echo "The systemctl command is required but was not found." >&2
exit 1
fi
case "$distro" in
sles|opensuse*)
with_fluentd="false"
;;
esac
ensure_not_installed "$with_fluentd" "$with_instrumentation"
if [ -z "$access_token" ]; then
access_token=$(request_access_token)
fi
if [ -z "$api_url" ]; then
api_url="https://api.${realm}.signalfx.com"
fi
if [ -z "$ingest_url" ]; then
ingest_url="https://ingest.${realm}.signalfx.com"
fi
if [ -z "$hec_token" ]; then
hec_token="$access_token"
fi
if [ -z "$hec_url" ]; then
hec_url="${ingest_url}/v1/log"
fi
if [ "$with_fluentd" != "true" ]; then
td_agent_version=""
fi
if [ "$with_instrumentation" != "true" ]; then
instrumentation_version=""
deployment_environment=""
fi
if [ -z "$trace_url" ]; then
trace_url="${ingest_url}/v2/trace"
fi
echo "Splunk OpenTelemetry Collector Version: ${collector_version}"
if [ -n "$ballast" ]; then
echo "Ballast Size in MIB: $ballast"
fi
echo "Memory Size in MIB: $memory"
echo "Realm: $realm"
echo "Ingest Endpoint: $ingest_url"
echo "API Endpoint: $api_url"
echo "Trace Endpoint: $trace_url"
echo "HEC Endpoint: $hec_url"
if [ "$with_fluentd" = "true" ]; then
echo "TD Agent (Fluentd) Version: $td_agent_version"
fi
if [ "$with_instrumentation" = "true" ]; then
echo "Splunk OpenTelemetry Auto Instrumentation Version: $instrumentation_version"
if [ -n "$deployment_environment" ]; then
echo " Resource Attribute: deployment.environment=${deployment_environment}"
fi
fi
if [ "${VERIFY_ACCESS_TOKEN:-true}" = "true" ] && ! verify_access_token "$access_token" "$ingest_url" "$insecure"; then
echo "Your access token could not be verified. This may be due to a network connectivity issue." >&2
exit 1
fi
install "$stage" "$collector_version" "$td_agent_version" "$skip_collector_repo" "$skip_fluentd_repo" "$instrumentation_version"
if [ "$with_instrumentation" = "true" ] && [ -n "$deployment_environment" ]; then
update_instrumentation_config "$deployment_environment"
fi
create_user_group "$service_user" "$service_group"
configure_service_owner "$service_user" "$service_group"
if [ -z "$collector_config_path" ]; then
# custom config not provided; use the config provided by the collector package based on the --mode option
if [ "$mode" = "agent" ]; then
if [ -f "$agent_config_path" ]; then
# use the agent config if the installed package includes it
collector_config_path="$agent_config_path"
elif [ -f "$old_config_path" ]; then
# use the old config if the installed package does not include the new agent config
collector_config_path="$old_config_path"
fi
else
if [ -f "$gateway_config_path" ]; then
# use the gateway config if the installed package includes it
collector_config_path="$gateway_config_path"
elif [ -f "$agent_config_path" ]; then
# use the agent config if the installed package includes it
collector_config_path="$agent_config_path"
elif [ -f "$old_config_path" ]; then
# use the old config if the installed package does not include the new agent or gateway config
collector_config_path="$old_config_path"
fi
fi
fi
if [ -z "$collector_config_path" ]; then
echo "ERROR: The installed splunk-otel-collector package does not include a supported config file!" >&2
exit 1
elif [ ! -f "$collector_config_path" ]; then
echo "ERROR: Config file $collector_config_path not found!" >&2
exit 1
fi
if [ ! -f "${collector_env_path}.example" ]; then
collector_env_path=$collector_env_old_path
fi
mkdir -p "$(dirname $collector_env_path)"
# remove existing env file and recreate with current values
if [ -f "$collector_env_path" ]; then
rm -f "$collector_env_path"
fi
configure_env_file "SPLUNK_CONFIG" "$collector_config_path" "$collector_env_path"
configure_env_file "SPLUNK_ACCESS_TOKEN" "$access_token" "$collector_env_path"
configure_env_file "SPLUNK_REALM" "$realm" "$collector_env_path"
configure_env_file "SPLUNK_API_URL" "$api_url" "$collector_env_path"
configure_env_file "SPLUNK_INGEST_URL" "$ingest_url" "$collector_env_path"
configure_env_file "SPLUNK_TRACE_URL" "$trace_url" "$collector_env_path"
configure_env_file "SPLUNK_HEC_URL" "$hec_url" "$collector_env_path"
configure_env_file "SPLUNK_HEC_TOKEN" "$hec_token" "$collector_env_path"
configure_env_file "SPLUNK_MEMORY_TOTAL_MIB" "$memory" "$collector_env_path"
if [ -n "$ballast" ]; then
configure_env_file "SPLUNK_BALLAST_SIZE_MIB" "$ballast" "$collector_env_path"
fi