-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathobserve_configure_script.sh
executable file
·1238 lines (997 loc) · 36 KB
/
observe_configure_script.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/bash
END_OUTPUT="END_OF_OUTPUT"
cd ~ || exit && echo "$SPACER $END_OUTPUT $SPACER"
config_file_directory="$HOME/observe_config_files"
log ()
{
echo "`date` $1" | sudo tee -a "/tmp/observe-install.log"
}
getConfigurationFiles(){
local branch_replace="$1"
local SPACER
SPACER=$(generateSpacer)
if [ ! -d "$config_file_directory" ]; then
mkdir "$config_file_directory"
log "$SPACER $config_file_directory CREATED $SPACER"
else
rm -f "${config_file_directory:?}"/*
log "$SPACER"
log "$config_file_directory DELETED"
log "$SPACER"
ls "$config_file_directory"
log "$SPACER"
fi
if [ ! -f "$config_file_directory/osquery.conf" ]; then
url="https://raw.githubusercontent.com/observeinc/linux-host-configuration-scripts/${branch_replace}/config_files/osquery.conf"
filename="$config_file_directory/osquery.conf"
log "$SPACER"
log "filename = $filename"
log "$SPACER"
log "url = $url"
curl "$url" > "$filename"
log "$SPACER"
log "$filename created"
log "$SPACER"
fi
if [ ! -f "$config_file_directory/telegraf.conf" ]; then
url="https://raw.githubusercontent.com/observeinc/linux-host-configuration-scripts/${branch_replace}/config_files/telegraf.conf"
filename="$config_file_directory/telegraf.conf"
log "$SPACER"
log "filename = $filename"
log "$SPACER"
log "url = $url"
curl "$url" > "$filename"
log "$SPACER"
log "$filename created"
log "$SPACER"
fi
if [ ! -f "$config_file_directory/td-agent-bit.conf" ]; then
url="https://raw.githubusercontent.com/observeinc/linux-host-configuration-scripts/${branch_replace}/config_files/td-agent-bit.conf"
filename="$config_file_directory/td-agent-bit.conf"
log "$SPACER"
log "filename = $filename"
log "$SPACER"
log "url = $url"
curl "$url" > "$filename"
log "$SPACER"
log "$filename created"
log "$SPACER"
fi
if [ ! -f "$config_file_directory/fluent-bit.conf" ]; then
url="https://raw.githubusercontent.com/observeinc/linux-host-configuration-scripts/${branch_replace}/config_files/fluent-bit.conf"
filename="$config_file_directory/fluent-bit.conf"
log "$SPACER"
log "filename = $filename"
log "$SPACER"
log "url = $url"
curl "$url" > "$filename"
log "$SPACER"
log "$filename created"
log "$SPACER"
fi
if [ ! -f "$config_file_directory/observe-linux-host.conf" ]; then
url="https://raw.githubusercontent.com/observeinc/linux-host-configuration-scripts/${branch_replace}/config_files/observe-linux-host.conf"
filename="$config_file_directory/observe-linux-host.conf"
log "$SPACER"
log "filename = $filename"
log "$SPACER"
log "url = $url"
curl "$url" > "$filename"
log "$SPACER"
log "$filename created"
log "$SPACER"
fi
if [ ! -f "$config_file_directory/observe-jenkins.conf" ]; then
url="https://raw.githubusercontent.com/observeinc/linux-host-configuration-scripts/${branch_replace}/config_files/observe-jenkins.conf"
filename="$config_file_directory/observe-jenkins.conf"
log "$SPACER"
log "filename = $filename"
log "$SPACER"
log "url = $url"
curl "$url" > "$filename"
log "$SPACER"
log "$filename created"
log "$SPACER"
fi
if [ ! -f "$config_file_directory/observe-securityonion.conf" ]; then
url="https://raw.githubusercontent.com/observeinc/linux-host-configuration-scripts/${branch_replace}/config_files/observe-securityonion.conf"
filename="$config_file_directory/observe-securityonion.conf"
log "$SPACER"
log "filename = $filename"
log "$SPACER"
log "url = $url"
curl "$url" > "$filename"
log "$SPACER"
log "$filename created"
log "$SPACER"
fi
if [ ! -f "$config_file_directory/osquery.flags" ]; then
url="https://raw.githubusercontent.com/observeinc/linux-host-configuration-scripts/${branch_replace}/config_files/osquery.flags"
filename="$config_file_directory/osquery.flags"
log "$SPACER"
log "filename = $filename"
log "$SPACER"
log "url = $url"
curl "$url" > "$filename"
log "$SPACER"
log "$filename created"
log "$SPACER"
fi
if [ ! -f "$config_file_directory/observe-installer.conf" ]; then
url="https://raw.githubusercontent.com/observeinc/linux-host-configuration-scripts/${branch_replace}/config_files/observe-installer.conf"
filename="$config_file_directory/observe-installer.conf"
log "$SPACER"
log "filename = $filename"
log "$SPACER"
log "url = $url"
curl "$url" > "$filename"
log "$SPACER"
log "$filename created"
log "$SPACER"
fi
if [ ! -f "$config_file_directory/parsers-observe.conf" ]; then
url="https://raw.githubusercontent.com/observeinc/linux-host-configuration-scripts/${branch_replace}/config_files/parsers-observe.conf"
filename="$config_file_directory/parsers-observe.conf"
log "$SPACER"
log "filename = $filename"
log "$SPACER"
log "url = $url"
curl "$url" > "$filename"
log "$SPACER"
log "$filename created"
log "$SPACER"
fi
}
generateTestKey(){
echo "${OBSERVE_TEST_RUN_KEY}"
}
# identify OS and architecture
if [ -f /etc/os-release ]; then
#shellcheck disable=SC1091
. /etc/os-release
OS=$( echo "${ID}" | tr '[:upper:]' '[:lower:]')
CODENAME=$( echo "${VERSION_CODENAME}" | tr '[:upper:]' '[:lower:]')
elif lsb_release &>/dev/null; then
OS=$(lsb_release -is | tr '[:upper:]' '[:lower:]')
CODENAME=$(lsb_release -cs)
else
OS=$(uname -s)
fi
SYS_ARCH=$(uname -m)
if [[ $SYS_ARCH = "aarch64" ]]; then
ARCH="arm64"
else
ARCH="amd64"
fi
# used for terminal output
generateSpacer(){
echo "###########################################"
}
printHelp(){
log "$SPACER"
log "## HELP CONTENT"
log "$SPACER"
log "### Required inputs"
log "- Required --customer_id OBSERVE_CUSTOMER "
log "- Required --ingest_token OBSERVE_TOKEN "
log "## Optional inputs"
log "- Optional --observe_host_name - Defaults to https://<OBSERVE_CUSTOMER>.collect.observeinc.com/ "
log "- Optional --config_files_clean TRUE or FALSE - Defaults to FALSE"
log " - controls whether to delete created config_files temp directory"
log "- Optional --ec2metadata TRUE or FALSE - Defaults to FALSE"
log " - controls fluentbit config for whether to use default ec2 metrics "
log "- Optional --cloud_metadata TRUE or FALSE - Defaults to FALSE"
log " - controls fluentbit config for whether to poll for VM metadata"
log "- Optional --datacenter defaults to AWS"
log "- Optional --appgroup id supplied sets value in fluentbit config"
log "- Optional --branch_input branch of repository to pull scrips and config files from -Defaults to main"
log "- Optional --validate_endpoint of observe_hostname using customer_id and ingest_token -Defaults to TRUE"
log "- Optional --module to use for installs -Defaults to linux_host which installs osquery, fluentbit or td-agent-bit, and telegraf"
log " - Optional module flag: securityonion adds a config to fluentbit or td-agent-bit. If securityonion is specified without linux_host, only fluent-bit (or td-agent-bit) will be installed."
log " - Optional module flag: jenkins adds a config to fluent-bit or td-agent-bit. If jenkins is specified without linux_host, only fluent-bit or td-agent-bit will be installed."
log "- Optional --observe_jenkins_path used in combination with jenkins module - location of jenkins logs"
log "- Optional --custom_fluentbit_config add an additional configuration file for fluentbit or td-agent-bit"
log "- Optional --osquery_version value for which osquery version to install (defaults to "latest"). Note this needs to be the full version number: i.e. '5.9.1-1.linux'"
log "- Optional --telegraf_version value for which telegraf version to install (defaults to "latest"). Note this needs to be the full version number: i.e. '1.28.2-1'"
log "- Optional --fluentbit_version value for which fluentbit version to install (defaults to "latest"). Note this needs to be the full version number: i.e. '2.1.10'"
log "***************************"
log "### Sample command:"
log "\`\`\` curl https://raw.githubusercontent.com/observeinc/linux-host-configuration-scripts/main/observe_configure_script.sh | bash -s -- --customer_id OBSERVE_CUSTOMER --ingest_token OBSERVE_TOKEN --observe_host_name https://<OBSERVE_CUSTOMER>.collect.observeinc.com/ --config_files_clean TRUE --ec2metadata TRUE --datacenter MY_DATA_CENTER --appgroup MY_APP_GROUP\`\`\`"
log "***************************"
}
requiredInputs(){
log "$SPACER"
log "* Error: Invalid argument.*"
log "$SPACER"
printVariables
printHelp
log "$SPACER"
log "$END_OUTPUT"
log "$SPACER"
exit 1
}
printVariables(){
log "$SPACER"
log "* VARIABLES *"
log "$SPACER"
log "customer_id: $customer_id"
log "observe_host_name: $observe_host_name"
log "config_files_clean: $config_files_clean"
log "ec2metadata: $ec2metadata"
log "cloud_metadata: $cloud_metadata"
log "datacenter: $datacenter"
log "appgroup: $appgroup"
log "testeject: $testeject"
log "validate_endpoint: $validate_endpoint"
log "branch_input: $branch_input"
log "module: $module"
log "observe_jenkins_path: ${observe_jenkins_path}"
log "osquery_version: ${osquery_version}"
log "telegraf_version: ${telegraf_version}"
log "fluentbit_version: ${fluentbit_version}"
log "$SPACER"
}
testEject(){
local bail="$1"
local bailPosition="$2"
if [[ "$bail" == "$bailPosition" ]]; then
log "$SPACER"
log "$SPACER"
log " TEST EJECTION "
log "Position = $bailPosition"
log "$SPACER"
log "$END_OUTPUT"
log "$SPACER"
log "$SPACER"
exit 0;
fi
}
removeConfigDirectory() {
rm -f -R "$config_file_directory"
}
validateObserveHostName () {
local url="$1"
# check for properly formatted url input - assumes - https://<customer-id>.collect.observe[anything]/
# we can modify this rule to be specific as needed
regex='^(https?)://[0-9]+.collect.observe[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*\/'
if [[ $url =~ $regex ]]
then
log "$SPACER"
log "$url IS valid"
log "$SPACER"
else
log "$SPACER"
log "$url IS NOT valid - example valid input - https://123456789012.collect.observeinc.com/"
log "$SPACER"
exit 1
fi
}
includeFiletdAgent(){
# Process modules
IFS=',' read -a CONFS <<< "$module"
for i in "${CONFS[@]}"; do
log "includeFiletdAgent - $i"
sudo cp "$config_file_directory/observe-installer.conf" /etc/td-agent-bit/observe-installer.conf;
sudo cp "$config_file_directory/parsers-observe.conf" /etc/td-agent-bit/parsers-observe.conf;
case ${i} in
linux_host)
sudo cp "$config_file_directory/observe-linux-host.conf" /etc/td-agent-bit/observe-linux-host.conf;
;;
jenkins)
sudo cp "$config_file_directory/observe-jenkins.conf" /etc/td-agent-bit/observe-jenkins.conf;
;;
securityonion)
sudo cp "$config_file_directory/observe-securityonion.conf" /etc/td-agent-bit/observe-securityonion.conf;
;;
*)
log "includeFiletdAgent function failed - i = $i"
log "$SPACER"
log "$END_OUTPUT"
log "$SPACER"
exit 1;
;;
esac
done
#install custom config if exists
if ! [ -z ${custom_fluentbit_config} ]
then
sudo cp ${custom_fluentbit_config} /etc/td-agent-bit/observe-custom-config.conf
fi
}
includeFilefluentAgent(){
# Process modules
IFS=',' read -a CONFS <<< "$module"
for i in "${CONFS[@]}"; do
log "includeFilefluentAgent - $i"
sudo cp "$config_file_directory/observe-installer.conf" /etc/fluent-bit/observe-installer.conf;
sudo cp "$config_file_directory/parsers-observe.conf" /etc/fluent-bit/parsers-observe.conf;
case ${i} in
linux_host)
sudo cp "$config_file_directory/observe-linux-host.conf" /etc/fluent-bit/observe-linux-host.conf;
;;
jenkins)
sudo cp "$config_file_directory/observe-jenkins.conf" /etc/fluent-bit/observe-jenkins.conf;
;;
securityonion)
sudo cp "$config_file_directory/observe-securityonion.conf" /etc/fluent-bit/observe-securityonion.conf;
;;
*)
log "includeFiletdAgent function failed - i = $i"
log "$SPACER"
log "$END_OUTPUT"
log "$SPACER"
exit 1;
;;
esac
done
#install custom config if exists
if ! [ -z ${custom_fluentbit_config}]
then
sudo cp ${custom_fluentbit_config} /etc/fluent-bit/observe-custom-config.conf
fi
}
setInstallFlags(){
# Process modules
log "$SPACER"
log "setInstallFlags - module=$module"
log "$SPACER"
IFS=',' read -a CONFS <<< "$module"
for i in "${CONFS[@]}"; do
log "setInstallFlags - $i"
case ${i} in
linux_host)
log "setInstallFlags linux_host flags"
osqueryinstall="TRUE"
telegrafinstall="TRUE"
fluentbitinstall="TRUE"
;;
securityonion)
fluentbitinstall="TRUE"
;;
jenkins)
fluentbitinstall="TRUE"
;;
*)
log "setInstallFlags function failed - i = $i"
log "$SPACER"
log "$END_OUTPUT"
log "$SPACER"
exit 1;
;;
esac
done
}
validateFluentbitVersion(){
local version="$1"
if [[ $version == "1."* ]] || [[ $version == "0."* ]] ; then
log
log "$SPACER"
log "Unable to install version $version of fluent-bit, due to the service name change in 1.9"
log " see https://docs.fluentbit.io/manual/installation/upgrade-notes#fluent-bit-v1.9.9"
log "$SPACER"
exit 1
fi
}
printMessage(){
local message="$1"
log
log "$SPACER"
log "$message"
log "$SPACER"
log
}
SPACER=$(generateSpacer)
log "$SPACER"
log "Script starting ..."
log "$SPACER"
log "Validate inputs ..."
customer_id=0
ingest_token=0
observe_host_name_base=
config_files_clean="FALSE"
ec2metadata="FALSE"
cloud_metadata="FALSE"
datacenter="AWS"
testeject="NO"
appgroup="UNSET"
branch_input="main"
validate_endpoint="TRUE"
module="linux_host"
osqueryinstall="FALSE"
telegrafinstall="FALSE"
fluentbitinstall="FALSE"
osquery_version="latest"
telegraf_version="latest"
fluentbit_version="latest"
observe_jenkins_path="/var/lib/jenkins/"
if [ "$1" == "--help" ]; then
printHelp
log "$SPACER"
log "$END_OUTPUT"
log "$SPACER"
exit 0
fi
if [ $# -lt 4 ]; then
requiredInputs
fi
# Parse inputs
while [ $# -gt 0 ]; do
echo "required inputs $1 $2 $# "
case "$1" in
--customer_id)
customer_id="$2"
;;
--ingest_token)
ingest_token="$2"
;;
--observe_host_name)
observe_host_name_base="$2"
;;
--config_files_clean)
config_files_clean="$2"
;;
--ec2metadata)
ec2metadata="$2"
;;
--cloud_metadata)
cloud_metadata="$2"
;;
--datacenter)
datacenter="$2"
;;
--appgroup)
appgroup="$2"
;;
--testeject)
testeject="$2"
;;
--branch_input)
branch_input="$2"
;;
--module)
module="$2"
;;
--validate_endpoint)
validate_endpoint="$2"
;;
--observe_jenkins_path)
observe_jenkins_path="$2"
;;
--custom_fluentbit_config)
custom_fluentbit_config="$2"
;;
--osquery_version)
osquery_version="$2"
;;
--telegraf_version)
telegraf_version="$2"
;;
--fluentbit_version)
fluentbit_version="$2"
;;
*)
esac
shift
shift
done
if [ "$customer_id" == 0 ] || [ "$ingest_token" == 0 ]; then
requiredInputs
fi
# Construct the per-customer-id ingest host name.
if [ -z "$observe_host_name_base" ]; then
observe_host_name_base="https://${customer_id}.collect.observeinc.com/"
fi
validateObserveHostName "$observe_host_name_base"
observe_host_name=$(echo "$observe_host_name_base" | sed -e 's|^[^/]*//||' -e 's|/.*$||')
validateFluentbitVersion "$fluentbit_version"
log "$SPACER"
log "customer_id: ${customer_id}"
log "observe_host_name_base: ${observe_host_name_base}"
log "observe_host_name: ${observe_host_name}"
log "config_files_clean: ${config_files_clean}"
log "ec2metadata: ${ec2metadata}"
log "cloud_metadata: ${cloud_metadata}"
log "datacenter: ${datacenter}"
log "appgroup: ${appgroup}"
log "testeject: ${testeject}"
log "validate_endpoint: ${validate_endpoint}"
log "branch_input: ${branch_input}"
log "module: ${module}"
log "observe_jenkins_path: ${observe_jenkins_path}"
log "custom_fluentbit_config: ${custom_fluentbit_config}"
log "osquery_version: ${osquery_version}"
log "telegraf_version: ${telegraf_version}"
log "fluentbit_version: ${fluentbit_version}"
setInstallFlags
printMessage "osqueryinstall = $osqueryinstall"
printMessage "telegrafinstall = $telegrafinstall"
printMessage "fluentbitinstall = $fluentbitinstall"
OBSERVE_ENVIRONMENT="$observe_host_name"
DEFAULT_OBSERVE_HOSTNAME="${HOSTNAME}"
DEFAULT_OBSERVE_DATA_CENTER="$datacenter"
if [ "$validate_endpoint" == TRUE ]; then
log "$SPACER"
log "Validate customer_id / ingest token ..."
log "$SPACER"
log
# Send the HEAD request so we aren't posting data
curl_endpoint=$(curl -I https://"${OBSERVE_ENVIRONMENT}"/ \
-H "Authorization: Bearer ${ingest_token}" \
-H "Content-type: application/json")
# Extract HTTP response code
http_code=$(echo "$curl_endpoint" | grep -i -m 1 -o -E 'HTTP/[0-9.]+ [0-9]+' | awk '{print $2}')
if ((http_code != "200" )); then
log "$SPACER"
log "Endpoint Validation failed with:"
log "$curl_endpoint"
log "$SPACER"
log "$END_OUTPUT"
log "$SPACER"
exit 1
else
log "$SPACER"
log "Successfully validated customer_id and ingest_token"
fi
log "$SPACER"
fi
log "$SPACER"
log "Values for configuration:"
log "$SPACER"
log " Environment: $OBSERVE_ENVIRONMENT"
log
log " Data Center: $DEFAULT_OBSERVE_DATA_CENTER"
log
log " Hostname: $DEFAULT_OBSERVE_HOSTNAME"
log
log " Customer ID: $customer_id"
testEject "${testeject}" "EJECT1"
log "$SPACER"
getConfigurationFiles "$branch_input"
log "$SPACER"
cd "$config_file_directory" || (exit && log "$SPACER CONFIG FILE DIRECTORY PROBLEM - $(pwd) - $config_file_directory - $END_OUTPUT $SPACER")
sed -i "s/REPLACE_WITH_DATACENTER/${DEFAULT_OBSERVE_DATA_CENTER}/g" ./*
sed -i "s/REPLACE_WITH_HOSTNAME/${DEFAULT_OBSERVE_HOSTNAME}/g" ./*
sed -i "s/REPLACE_WITH_CUSTOMER_INGEST_TOKEN/${ingest_token}/g" ./*
sed -i "s/REPLACE_WITH_OBSERVE_ENVIRONMENT/${OBSERVE_ENVIRONMENT}/g" ./*
sed -i "s:REPLACE_WITH_OBSERVE_JENKINS_PATH:${observe_jenkins_path}:g" ./*
if [ "$ec2metadata" == TRUE ]; then
sed -i "s/#REPLACE_WITH_OBSERVE_EC2_OPTION//g" ./*
fi
if [ "$appgroup" != UNSET ]; then
sed -i "s/#REPLACE_WITH_OBSERVE_APP_GROUP_OPTION/Record appgroup ${appgroup}/g" ./*
fi
metadata_buffer_size="8mb"
metadata_interval_secs="300"
sed -i "s/REPLACE_WITH_METADATA_BUFFER_SIZE/${metadata_buffer_size}/g" ./*
sed -i "s/REPLACE_WITH_METADATA_INTERVAL/${metadata_interval_secs}/g" ./*
metadata_command=":"
if [[ "$cloud_metadata" == TRUE ]]; then
# AWS
metadata_commands[0]='TOKEN=`curl --fail -s -X PUT http://169.254.169.254/latest/api/token -H "X-aws-ec2-metadata-token-ttl-seconds: 60"` \&\& curl --fail -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/dynamic/instance-identity/document | tr "\\n" " "'
# GCP
metadata_commands[1]='curl --fail "http://metadata.google.internal/computeMetadata/v1/?recursive=true" -H "Metadata-Flavor: Google"'
# Azure
metadata_commands[2]='curl --fail -s -H Metadata:true --noproxy "*" "http://169.254.169.254/metadata/instance?api-version=2021-02-01"'
for command in "${metadata_commands[@]}"
do
command_parsed=$(echo REPLACE_WITH_METADATA_COMMAND | sed "s#REPLACE_WITH_METADATA_COMMAND#${command}#g")
eval $command_parsed > /dev/null 2>&1
retVal=$?
if [ $retVal -eq 0 ]; then
metadata_command="$command"
break
fi
echo $?
done
fi
log "Using the following command to fetch VM metadata: ${metadata_command}"
sed -i "s#REPLACE_WITH_METADATA_COMMAND#${metadata_command}#g" ./*
if [[ "${metadata_command}" == *"aws-ec2"* ]]; then
log "Cloud is AWS, enabling ec2metadata"
ec2metadata="TRUE"
fi
testEject "${testeject}" "EJECT2"
# https://docs.observeinc.com/en/latest/content/integrations/linux/linux.html
#####################################
# BASELINEINSTALL - START
#####################################
if [[ "$osquery_version" == latest ]] || [[ "$osquery_version" == "" ]]; then
osquery_version="osquery"
else
osquery_version="osquery=${osquery_version}"
fi
if [[ "$telegraf_version" == latest ]] || [[ "$telegraf_version" == "" ]]; then
telegraf_version="telegraf"
else
telegraf_version="telegraf=${telegraf_version}"
fi
if [[ "$fluentbit_version" == latest ]] || [[ "$fluentbit_version" == "" ]]; then
fluentbit_version="fluent-bit"
else
fluentbit_version="fluent-bit=${fluentbit_version}"
fi
case ${OS} in
amzn|amazonlinux)
log "Amazon OS"
export AL_VERSION=$(awk -F= '$1=="VERSION" { print $2 ;}' /etc/os-release | xargs)
#####################################
# osquery
#####################################
if [ "$osqueryinstall" == TRUE ]; then
printMessage "${osquery_version/=/-}"
curl -L https://pkg.osquery.io/rpm/GPG | sudo tee /etc/pki/rpm-gpg/RPM-GPG-KEY-osquery
if [[ $AL_VERSION == "2023" ]]; then
sudo dnf config-manager --add-repo https://pkg.osquery.io/rpm/osquery-s3-rpm.repo
sudo dnf config-manager --enable osquery-s3-rpm-repo
sudo dnf install "${osquery_version/=/-}" -y
else
sudo yum-config-manager --add-repo https://pkg.osquery.io/rpm/osquery-s3-rpm.repo
sudo yum-config-manager --enable osquery-s3-rpm-repo
sudo yum install "${osquery_version/=/-}" -y
fi
sudo service osqueryd start 2>/dev/null || true
sudo systemctl enable osqueryd
# ################
sourcefilename=$config_file_directory/osquery.conf
filename=/etc/osquery/osquery.conf
osquery_conf_filename=/etc/osquery/osquery.conf
if [ -f "$filename" ]
then
sudo mv "$filename" "$filename".OLD
fi
sudo cp "$sourcefilename" "$filename"
sourcefilename=$config_file_directory/osquery.flags
filename=/etc/osquery/osquery.flags
osquery_flags_filename=/etc/osquery/osquery.flags
if [ -f "$filename" ]
then
sudo mv "$filename" "$filename".OLD
fi
sudo cp "$sourcefilename" "$filename"
sudo service osqueryd restart
fi
# #####################################
# # fluent
# #####################################
if [ "$fluentbitinstall" == TRUE ]; then
printMessage "${fluentbit_version}"
if [[ $AL_VERSION == "2023" ]]; then
sudo tee /etc/yum.repos.d/fluent-bit.repo > /dev/null << EOT
[fluent-bit]
name = Fluent Bit
baseurl = https://packages.fluentbit.io/amazonlinux/2023/
gpgcheck=1
gpgkey=https://packages.fluentbit.io/fluentbit.key
enabled=1
EOT
else
sudo tee /etc/yum.repos.d/fluent-bit.repo > /dev/null << EOT
[fluent-bit]
name = Fluent Bit
baseurl = https://packages.fluentbit.io/amazonlinux/2/
gpgcheck=1
gpgkey=https://packages.fluentbit.io/fluentbit.key
enabled=1
EOT
fi
sudo yum install "${fluentbit_version/=/-}" -y
sourcefilename=$config_file_directory/fluent-bit.conf
filename=/etc/fluent-bit/fluent-bit.conf
fluent_bit_filename=/etc/fluent-bit/fluent-bit.conf
if [ -f "$filename" ]; then
sudo mv "$filename" "$filename".OLD
fi
sudo cp "$sourcefilename" "$filename"
includeFilefluentAgent
sudo service fluent-bit restart
sudo systemctl enable fluent-bit
fi
# #####################################
# # telegraf
# #####################################
if [ "$telegrafinstall" == TRUE ]; then
printMessage "${telegraf_version}"
cat <<EOF | sudo tee /etc/yum.repos.d/influxdb.repo
[influxdb]
name = InfluxDB Repository - RHEL 7
baseurl = https://repos.influxdata.com/rhel/7/\$basearch/stable
enabled = 1
gpgcheck = 1
gpgkey = https://repos.influxdata.com/influxdata-archive_compat.key
EOF
# sudo tee /etc/yum.repos.d/influxdb.repo > /dev/null << EOT
# [influxdb]
# name = InfluxDB Repository - RHEL
# baseurl = https://repos.influxdata.com/rhel/7/\$basearch/stable/
# enabled = 1
# gpgcheck = 1
# gpgkey = https://repos.influxdata.com/influxdb.key
# EOT
sudo yum install "${telegraf_version/=/-}" -y
sourcefilename=$config_file_directory/telegraf.conf
filename=/etc/telegraf/telegraf.conf
telegraf_conf_filename=/etc/telegraf/telegraf.conf
if [ -f "$filename" ]
then
sudo mv "$filename" "$filename".OLD
fi
sudo cp "$sourcefilename" "$filename"
sudo systemctl enable telegraf
sudo service telegraf restart
fi
################################################################################################
################################################################################################
;;
################################################################################################
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!#
################################################################################################
# rhel|centos
#####################################
#####################################
rhel|centos)
log "RHEL OS"
#####################################
# osquery
#####################################
if [ "$osqueryinstall" == TRUE ]; then
printMessage "${osquery_version}"
sudo yum install yum-utils -y
curl -L https://pkg.osquery.io/rpm/GPG | sudo tee /etc/pki/rpm-gpg/RPM-GPG-KEY-osquery
sudo yum-config-manager --add-repo https://pkg.osquery.io/rpm/osquery-s3-rpm.repo
sudo yum-config-manager --enable osquery-s3-rpm-repo
sudo yum install "${osquery_version/=/-}" -y
# ################
sourcefilename=$config_file_directory/osquery.conf
filename=/etc/osquery/osquery.conf
osquery_conf_filename=/etc/osquery/osquery.conf
if [ -f "$filename" ]
then
sudo mv "$filename" "$filename".OLD
fi
sudo cp "$sourcefilename" "$filename"
sourcefilename=$config_file_directory/osquery.flags
filename=/etc/osquery/osquery.flags
osquery_flags_filename=/etc/osquery/osquery.flags
if [ -f "$filename" ]
then
sudo mv "$filename" "$filename".OLD
fi
sudo cp "$sourcefilename" "$filename"
sudo service osqueryd restart
sudo systemctl enable osqueryd
fi
# #####################################
# # fluent
# #####################################
if [ "$fluentbitinstall" == TRUE ]; then
printMessage "${fluentbit_version}"
cat << EOF | sudo tee /etc/yum.repos.d/fluent-bit.repo
[fluent-bit]
name = Fluent Bit
baseurl = https://packages.fluentbit.io/centos/$releasever/
gpgcheck=1
gpgkey=https://packages.fluentbit.io/fluentbit.key
repo_gpgcheck=1
enabled=1
EOF
sudo yum install "${fluentbit_version/=/-}" -y
sudo service fluent-bit start
sourcefilename=$config_file_directory/fluent-bit.conf
filename=/etc/fluent-bit/fluent-bit.conf
fluent_bit_filename=/etc/fluent-bit/fluent-bit.conf
if [ -f "$filename" ]
then
sudo mv "$filename" "$filename".OLD
fi
sudo cp "$sourcefilename" "$filename"
includeFilefluentAgent
sudo service fluent-bit restart
sudo systemctl enable fluent-bit
fi
# #####################################
# # telegraf
# #####################################
if [ "$telegrafinstall" == TRUE ]; then
printMessage "${telegraf_version}"
cat <<EOF | sudo tee /etc/yum.repos.d/influxdb.repo
[influxdb]
name = InfluxDB Repository - RHEL \$releasever
baseurl = https://repos.influxdata.com/rhel/\$releasever/\$basearch/stable
enabled = 1
gpgcheck = 1
gpgkey = https://repos.influxdata.com/influxdata-archive_compat.key
EOF
# cat << EOF | sudo tee /etc/yum.repos.d/influxdb.repo
# [influxdb]
# name = InfluxDB Repository - RHEL \$releasever
# baseurl = https://repos.influxdata.com/rhel/\$releasever/\$basearch/stable
# enabled = 1
# gpgcheck = 0
# gpgkey = https://repos.influxdata.com/influxdb.key
# EOF
sudo yum install "${telegraf_version/=/-}" -y
sourcefilename=$config_file_directory/telegraf.conf
filename=/etc/telegraf/telegraf.conf
telegraf_conf_filename=/etc/telegraf/telegraf.conf
if [ -f "$filename" ]