This repository was archived by the owner on Mar 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbigdiff.sh
More file actions
1134 lines (1091 loc) · 38.7 KB
/
Copy pathbigdiff.sh
File metadata and controls
1134 lines (1091 loc) · 38.7 KB
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
# Author: Leonardo Souza
# Version: 2.1.0
# Date: 27/08/2020
# Version History
# 1.0.0 - First Version
# 1.1.0 - #1 Wrong error code when there is no SNMP community
# 1.2.0 - Added debug mode options
#2 LTM Total table not showing lines that have changed
#3 GTM objects in the HTML file when the device does not have GTM provision
# 1.2.1 - #4 Object showing as changed, when disable and status are the same
# 2.0.0
# Added bash associative array
# Added GTM Distributed Application
# Added support for objects that has space in the name
# 2.0.1 - Changed Distributed Applications to Distributed Application to match singular used in other objects
# 2.1.0 - Added v16 to the version supported list
## Error Codes ##
# Script exit error codes
e_invalid_script_option=1
e_product_not_supported=2
e_software_version_not_supported=3
e_no_snmp_community=4
e_running_snmpwalk=5
e_no_before_upgrade_file=6
e_no_after_upgrade_file=7
e_unknown_bash_version=8
e_running_tmsh_ucs=9
e_running_qkview=10
e_generate_logs=11
e_multiple_options=12
## Variables ##
# No need to declare variables in Bash, but this is just to keep track
silent=0 # Indicates if script is running in silent mode
product="" # BIG-IP/BIG-IQ/etc..
supported_product=( BIG-IP ) # Produc supported by the script
supported_version=( 11 12 13 14 15 16 ) # List of versions the script supports
software_version="" # Software version used in the device
software_version_major="" # Major software version used in the device
bash_version="" # Bash version used in this device
bash_version_major="" # Major bash version used in this device
script_name="BIGdiff" # Script name
script_author="" # Script author
script_version="" # Script version
script_date="" # Script date
message="" # Variable used for text in the dialog program
provision_gtm=0 # Indicates if GTM is provisioned
snmp_community="" # SNMP community
ltm_oids="" # LTM OIDs for snmpwalk
gtm_oids="" # GTM OIDs for snmpwalk
bug_364556_versions=( 11.0.0 11.1.0 11.2.0 11.2.1 11.3.0 ) # Versions affected by bug 364556 - https://support.f5.com/csp/article/K14618
before_file="" # Before upgrade file with snmpwalk output
before_file_tmp="" # Before upgrade temporary file with snmpwalk output
after_file="" # After upgrade file with snmpwalk output
changes=0 # Number of changes found after upgrade
html_file="" # HTML file generated by the script
html_tables_file="" # Temporary HTML file to save the tables
temp_variable1="" # Temporary variable used in the script
temp_variable2="" # Temporary variable used in the script
temp_variable3="" # Temporary variable used in the script
index="" # Temporary variable used in the script
index2="" # Temporary variable used in the script
option="" # Temporary variable used in the script
fselect_option="" # Variable with the file name from fselect function
exit_status="" # Temporary variable used in the script
ucs_file="" # varibale to save UCS file name
qkview_file="" # varibale to save QKView file name
logs_file="" # varibale to save logs file name
# Multiple arrays to store objects
declare -a before_object_name
declare -a before_object_enabled
declare -a before_object_status
declare -a after_object_name
declare -a after_object_enabled
declare -a after_object_status
# Dialog exit Codes
dialog_cancel=1
dialog_esc=255
dialog_yes=0
dialog_no=1
## General ##
# Diverse functions
# Populate variables with information about the script
script_information_variables()
{
script_author=`egrep "^# Author:" $0`
script_author=${script_author/"# Author: "}
script_version=`egrep "^# Version:" $0`
script_version=${script_version/"# Version: "}
script_date=`egrep "^# Date:" $0`
script_date=${script_date/"# Date: "}
}
# Get bash version
get_bash_version()
{
bash_version=$BASH_VERSION
if [[ $bash_version == "" ]]
then
cli_error "Unknown Bash version" $e_unknown_bash_version
else
bash_version_major=${bash_version%%.*}
fi
}
# Output error to CLI and exit
cli_error()
{
echo "Error: $1."
exit $2
}
# Ouptut error using dialog and exit
menu_error()
{
dialog --backtitle "$script_name - $HOSTNAME - $product $software_version" --title "Error" --msgbox "$1." 0 0
exit $2
}
# If silent mode just exit, otherwise call menu_error
error()
{
if [[ $silent == 1 ]]
then
exit $2
else
menu_error "$1" "$2"
fi
}
# Generate UCS file
generate_ucs()
{
[[ $silent == 0 ]] && infobox "UCS" "Generating UCS..." 0 0
ucs_file="/shared/tmp/${HOSTNAME}-${1}`date "+%Y%m%d%H%M%S"`.ucs"
tmsh save sys ucs $ucs_file &> /dev/null
[[ $? != 0 ]] && error "Failure to generate UCS" $e_running_tmsh_ucs
}
# Generate QKView file
# qkview script adds /var/tmp if the file destination does not starts with that, even when /shared/tmp/ is just a link to /var/tmp/
generate_qkview()
{
[[ $silent == 0 ]] && infobox "QKView" "Generating QKView..." 0 0
qkview_file="${HOSTNAME}-${1}`date "+%Y%m%d%H%M%S"`.qkview"
qkview -f "/var/tmp/"$qkview_file &> /dev/null
[[ $? != 0 ]] && error "Failure to generate QKView" $e_running_qkview
qkview_file="/shared/tmp/$qkview_file"
}
# Generate single file with all logs
generate_logs()
{
[[ $silent == 0 ]] && infobox "Logs" "Collecting full logs..." 0 0
logs_file="/shared/tmp/${HOSTNAME}-${1}`date "+%Y%m%d%H%M%S"`.tar.gz"
tar -czpf $logs_file /var/log/* &> /dev/null
[[ $? > 1 ]] && error "Failure to generate logs file" $e_generate_logs
}
## Checks ##
# Check that this script can run in this system
# Check if the system is a supported F5 product
check_product()
{
if [[ -f "/VERSION" ]]
then
product=`fgrep Product /VERSION`
product=${product/"Product: "}
printf "%s \n" ${supported_product[@]} | grep $product &> /dev/null
[[ $? != 0 ]] && cli_error "Product not supported" $e_product_not_supported
else
cli_error "Product not supported, not a F5 device" $e_product_not_supported
fi
}
# Check if the system is running a version that is supported by this script
check_version()
{
if [[ -f "/VERSION" ]]
then
software_version=`fgrep Version /VERSION`
software_version=${software_version/"Version: "}
software_version_major=${software_version%%.*}
printf "%s \n" ${supported_version[@]} | grep $software_version_major &> /dev/null
[[ $? != 0 ]] && cli_error "Software version not suppported" $e_software_version_not_supported
fi
}
# Check which modules are provisioned in the system
check_provision()
{
# LTM Module
# Most modules use LTM internally, so the script will show LTM even if it is not provisioned
# GTM Module
tmsh list sys provision gtm level &> /dev/null
if [[ $? == 0 ]]
then
tmsh list sys provision gtm level 2> /dev/null | grep "level none" &> /dev/null
[[ $? != 0 ]] && provision_gtm=1
fi
# Link Controller uses GTM Objects
tmsh list sys provision lc level &> /dev/null
if [[ $? == 0 ]]
then
tmsh list sys provision lc level 2> /dev/null | grep "level none" &> /dev/null
[[ $? != 0 ]] && provision_gtm=1
fi
}
## Options ##
# Get script Options
# Provide information about how to run the script
usage()
{
echo "Usage: `basename $0` --option"
echo "If no option is provided, the script will run in menu mode."
echo "If any option is provided, excepting help or error, the script will run in silent mode."
echo "In silent mode, no menu is presented, and script error is indicated by script exit code."
echo "Options:"
echo "before - Run script before change"
echo "after - Run script after change"
echo "before-without - Run script before change without backup"
echo "after-without - Run script after change without backup"
echo "backup - Generate backup files"
echo "ucs - Generate UCS file"
echo "qkview - Generate QKView file"
echo "logs - Generate full logs file"
echo "debug - Debug mode"
echo "help - Print information about how to use the script"
echo "error - Print information about error codes"
echo "info - Script information"
echo "support - List the versions the script supports"
exit 0
}
# Output error code variables in the script code
error_codes()
{
echo "Script exit error codes:"
egrep "^e_" $0
exit 0
}
# Output information about the script
script_information()
{
echo "Author: $script_author"
echo "Version: $script_version"
echo "Date: $script_date"
}
# Output the versions the script supports
version_support()
{
echo "The script should work with any version from 11.0.0."
echo "However, it has only been tested on the following versions:"
printf "%s.x.x " ${supported_version[@]}
echo
echo "If you want to use the script in a later version that has not been tested yet, change the following line on the script:"
egrep "^supported_version" $0
}
# Option before - Run script before change
option_before()
{
silent=1
generate_ucs "before-"
generate_qkview "before-"
generate_logs "before-"
get_snmp_community
before_file=${HOSTNAME}-before-`date "+%Y%m%d%H%M%S"`".txt"
run_snmpwalk $before_file
echo $before_file
echo $ucs_file
echo $qkview_file
echo $logs_file
}
# Option after - Run script after change
option_after()
{
silent=1
generate_ucs "after-"
generate_qkview "after-"
generate_logs "after-"
get_snmp_community
after_file=${HOSTNAME}-after-`date "+%Y%m%d%H%M%S"`".txt"
run_snmpwalk $after_file
get_before_file
generate_results
echo $before_file
echo $after_file
echo $html_file
echo $ucs_file
echo $qkview_file
echo $logs_file
}
# Option before-without - Run script before change without backup
option_before-without()
{
silent=1
get_snmp_community
before_file=${HOSTNAME}-before-`date "+%Y%m%d%H%M%S"`".txt"
run_snmpwalk $before_file
echo $before_file
}
# Option after-without - Run script after change without backup
option_after-without()
{
silent=1
get_snmp_community
after_file=${HOSTNAME}-after-`date "+%Y%m%d%H%M%S"`".txt"
run_snmpwalk $after_file
get_before_file
generate_results
echo $before_file
echo $after_file
echo $html_file
}
# Option backup - Generate backup files
option_backup()
{
silent=1
generate_ucs ""
generate_qkview ""
generate_logs ""
echo $ucs_file
echo $qkview_file
echo $logs_file
}
# Option ucs - Generate UCS file
option_ucs()
{
silent=1
generate_ucs ""
echo $ucs_file
}
# Option qkview - Generate QKView file
option_qkview()
{
silent=1
generate_qkview ""
echo $qkview_file
}
# Option logs - Generate full logs file
option_logs()
{
silent=1
generate_logs ""
echo $logs_file
}
# Option debug - Debug mode
option_debug()
{
silent=1
get_before_file
get_after_file
generate_results
}
# Read the script arguments
get_options()
{
case $1 in
"--before") option_before;;
"--after") option_after;;
"--before-without") option_before-without;;
"--after-without") option_after-without;;
"--backup") option_backup;;
"--ucs") option_ucs;;
"--qkview") option_qkview;;
"--logs") option_logs;;
"--debug") option_debug;;
"--help") usage;;
"--error") error_codes;;
"--info") script_information;;
"--support") version_support;;
*) cli_error "Invalid script option" $e_invalid_script_option;;
esac
}
## Compare Objects ##
# Compare objects
# Get the first SNMP string available in the system
get_snmp_community()
{
snmp_community=`tmsh list sys snmp communities | fgrep "community-name" | head -n1`
[[ $snmp_community == "" ]] && error "There is no SNMP community setup" $e_no_snmp_community
snmp_community=${snmp_community/" community-name"}
}
# Run snmpwalk command to get the objects
run_snmpwalk()
{
> $1
[[ $silent == 0 ]] && menu_file_creating $1
# LTM module
ltm_oids=( ltmVsStatusEnabledState ltmVsStatusAvailState ltmPoolStatusEnabledState ltmPoolStatusAvailState \
ltmPoolMbrStatusEnabledState ltmPoolMbrStatusAvailState ltmNodeAddrStatusEnabledState ltmNodeAddrStatusAvailState )
for oid in ${ltm_oids[@]}
do
# -C I: don't include the given OID, even if no results are returned
# -O q: quick print for easier parsing
# -r RETRIES set the number of retries
# -t TIMEOUT set the request timeout (in seconds)
snmpwalk -CI -Oq -t30 -r0 -c $snmp_community localhost $oid >> $1
[[ $? != 0 ]] && error "Failure to run snmpwalk" $e_running_snmpwalk
done
# bug 364556
printf "%s \n" ${bug_364556_versions[@]} | grep "$software_version" &> /dev/null
if [[ $? == 0 ]]
then
fgrep ".111.109.109.111.110." $1 &> /dev/null
if [[ $? == 0 ]]
then
[[ $silent == 0 ]] && menu_bug_364556
sed -i '/.111.109.109.111.110./d' $1
fi
fi
# GTM Module
if [[ $provision_gtm == 1 ]]
then
gtm_oids=( gtmDcStatusEnabledState gtmDcStatusAvailState gtmServerStatusEnabledState gtmServerStatusAvailState \
gtmWideipStatusEnabledState gtmWideipStatusAvailState gtmPoolStatusEnabledState gtmPoolStatusAvailState \
gtmPoolMbrStatusEnabledState gtmPoolMbrStatusAvailState gtmVsStatusEnabledState gtmVsStatusAvailState \
gtmProberPoolStatusEnabledState gtmProberPoolStatusAvailState gtmProberPoolMbrStatusEnabledState \
gtmProberPoolMbrStatusAvailState gtmLinkStatusEnabledState gtmLinkStatusAvailState gtmAppStatusEnabledState gtmAppStatusAvailState )
for oid in ${gtm_oids[@]}
do
# -C I: don't include the given OID, even if no results are returned
# -O q: quick print for easier parsing
# -r RETRIES set the number of retries
# -t TIMEOUT set the request timeout (in seconds)
snmpwalk -CI -Oq -t30 -r0 -c $snmp_community localhost $oid >> $1
[[ $? != 0 ]] && error "Failure to run snmpwalk" $e_running_snmpwalk
#sed -i 's/F5-BIGIP-GLOBAL-MIB:://' $1
done
fi
[[ $silent == 0 ]] && menu_file_created $1
}
# Get before upgrade file
get_before_file()
{
before_file=`ls | fgrep -- "-before-"`
[[ $before_file == "" ]] && error "Could not find before upgrade file" $e_no_before_upgrade_file
}
# Get after upgrade file
get_after_file()
{
after_file=""
after_file=`ls | fgrep -- "-after-"`
[[ $after_file == "" ]] && error "Could not find after upgrade file" $e_no_after_upgrade_file
}
# Get before upgrade file
get_before_file_menu()
{
before_file_tmp=${HOSTNAME}-before-`date "+%Y%m%d%H%M%S"`".tmp"
before_file=( $(ls | fgrep -- "-before-") )
if [[ ${#before_file[@]} > 0 ]]
then
yesnobox "Files" "Do you want to use the following files as before change files?\n`echo ${before_file[@]}`" 0 0
option=$?
else
option=$dialog_no
fi
if [[ $option == $dialog_no ]]
then
before_file=()
while true
do
fselect
before_file=( ${before_file[@]} $fselect_option )
yesnobox "Files" "Do you want to select another file?" 0 0
if [[ $? == $dialog_no ]]
then
break
fi
done
fi
for index in ${before_file[@]}
do
cat $index >> $before_file_tmp
done
before_file=$before_file_tmp
}
# Load before and after upgrade files to arrays - Bash version 4 or higher
load_files_v4()
{
let temp_variable1=${#before_object_name[@]}-1
for index in `seq 0 $temp_variable1`
do
before_object_enabled_v4[${before_object_name[$index]}]=${before_object_enabled[$index]}
before_object_status_v4[${before_object_name[$index]}]=${before_object_status[$index]}
done
let temp_variable1=${#after_object_name[@]}-1
for index in `seq 0 $temp_variable1`
do
after_object_enabled_v4[${after_object_name[$index]}]=${after_object_enabled[$index]}
after_object_status_v4[${after_object_name[$index]}]=${after_object_status[$index]}
done
}
# Load before and after upgrade files to arrays
load_files()
{
case $1 in
ltmPoolMbrStatusEnabledState)
eval before_object_name=($(grep $1 $3 | cut -d'.' -f2- | xargs -d '\n' printf "'%s' "))
let temp_variable1=${#before_object_name[@]}-1
for index in `seq 0 $temp_variable1`
do
before_object_name[$index]=${before_object_name[$index]% enabled}
before_object_name[$index]=${before_object_name[$index]% disabled}
before_object_name[$index]="`echo -n ${before_object_name[$index]} | cut -d'"' -f2`+`echo -n ${before_object_name[$index]} | cut -d'"' -f4`+`echo -n ${before_object_name[$index]} | cut -d'"' -f5 | tr -d '.' | cut -d' ' -f1`"
done
eval after_object_name=($(grep $1 $4 | cut -d'.' -f2- | xargs -d '\n' printf "'%s' "))
let temp_variable1=${#after_object_name[@]}-1
for index in `seq 0 $temp_variable1`
do
after_object_name[$index]=${after_object_name[$index]% enabled}
after_object_name[$index]=${after_object_name[$index]% disabled}
after_object_name[$index]="`echo -n ${after_object_name[$index]} | cut -d'"' -f2`+`echo -n ${after_object_name[$index]} | cut -d'"' -f4`+`echo -n ${after_object_name[$index]} | cut -d'"' -f5 | tr -d '.' | cut -d' ' -f1`"
done
before_object_enabled=( $(grep $1 $3 | cut -d'"' -f5 | cut -d' ' -f2) )
before_object_status=( $(grep $2 $3 | cut -d'"' -f5 | cut -d' ' -f2) )
after_object_enabled=( $(grep $1 $4 | cut -d'"' -f5 | cut -d' ' -f2) )
after_object_status=( $(grep $2 $4 | cut -d'"' -f5 | cut -d' ' -f2) )
;;
gtmPoolMbrStatusEnabledState)
eval before_object_name=($(grep $1 $3 | cut -d'.' -f2- | xargs -d '\n' printf "'%s' "))
let temp_variable1=${#before_object_name[@]}-1
for index in `seq 0 $temp_variable1`
do
before_object_name[$index]=${before_object_name[$index]% enabled}
before_object_name[$index]=${before_object_name[$index]% disabled}
before_object_name[$index]="`echo -n ${before_object_name[$index]} | cut -d'"' -f2`+`echo -n ${before_object_name[$index]} | cut -d'"' -f4`+`echo -n ${before_object_name[$index]} | cut -d'"' -f6`"
done
eval after_object_name=($(grep $1 $4 | cut -d'.' -f2- | xargs -d '\n' printf "'%s' "))
let temp_variable1=${#after_object_name[@]}-1
for index in `seq 0 $temp_variable1`
do
after_object_name[$index]=${after_object_name[$index]% enabled}
after_object_name[$index]=${after_object_name[$index]% disabled}
after_object_name[$index]="`echo -n ${after_object_name[$index]} | cut -d'"' -f2`+`echo -n ${after_object_name[$index]} | cut -d'"' -f4`+`echo -n ${after_object_name[$index]} | cut -d'"' -f6`"
done
before_object_enabled=( $(grep $1 $3 | cut -d'"' -f7 | tr -d ' ') )
before_object_status=( $(grep $2 $3 | cut -d'"' -f7 | tr -d ' ') )
after_object_enabled=( $(grep $1 $4 | cut -d'"' -f7 | tr -d ' ') )
after_object_status=( $(grep $2 $4 | cut -d'"' -f7 | tr -d ' ') )
;;
gtmVsStatusEnabledState|gtmProberPoolMbrStatusEnabledState)
eval before_object_name=($(grep $1 $3 | cut -d'.' -f2- | xargs -d '\n' printf "'%s' "))
let temp_variable1=${#before_object_name[@]}-1
for index in `seq 0 $temp_variable1`
do
before_object_name[$index]=${before_object_name[$index]% enabled}
before_object_name[$index]=${before_object_name[$index]% disabled}
before_object_name[$index]="`echo -n ${before_object_name[$index]} | cut -d'"' -f2`+`echo -n ${before_object_name[$index]} | cut -d'"' -f4`"
done
eval after_object_name=($(grep $1 $4 | cut -d'.' -f2- | xargs -d '\n' printf "'%s' "))
let temp_variable1=${#after_object_name[@]}-1
for index in `seq 0 $temp_variable1`
do
after_object_name[$index]=${after_object_name[$index]% enabled}
after_object_name[$index]=${after_object_name[$index]% disabled}
after_object_name[$index]="`echo -n ${after_object_name[$index]} | cut -d'"' -f2`+`echo -n ${after_object_name[$index]} | cut -d'"' -f4`"
done
before_object_enabled=( $(grep $1 $3 | cut -d'"' -f5 | tr -d ' ') )
before_object_status=( $(grep $2 $3 | cut -d'"' -f5 | tr -d ' ') )
after_object_enabled=( $(grep $1 $4 | cut -d'"' -f5 | tr -d ' ') )
after_object_status=( $(grep $2 $4 | cut -d'"' -f5 | tr -d ' ') )
;;
*)
eval before_object_name=($(grep $1 $3 | cut -d'"' -f2 | xargs -d '\n' printf '"%s" '))
eval after_object_name=($(grep $1 $4 | cut -d'"' -f2 | xargs -d '\n' printf '"%s" '))
before_object_enabled=( $(grep $1 $3 | cut -d'"' -f3 | tr -d ' ') )
before_object_status=( $(grep $2 $3 | cut -d'"' -f3 | tr -d ' ') )
after_object_enabled=( $(grep $1 $4 | cut -d'"' -f3 | tr -d ' ') )
after_object_status=( $(grep $2 $4 | cut -d'"' -f3 | tr -d ' ') )
;;
esac
if [[ "${before_object_name[0]}" == "" ]] || [[ "${before_object_name[0]}" == "+" ]] || [[ "${before_object_name[0]}" == "++" ]]
then
before_object_name=()
fi
if [[ "${after_object_name[0]}" == "" ]] || [[ "${after_object_name[0]}" == "+" ]] || [[ "${after_object_name[0]}" == "++" ]]
then
after_object_name=()
fi
if [[ $bash_version_major > 3 ]]
then
load_files_v4
fi
}
# Generate object table
generate_object_table_v4()
{
[[ $# == 3 ]] && html_table_object_header "$1" "$2" "$3" >> $html_tables_file
[[ $# == 4 ]] && html_table_object_header "$1" "$2" "$3" "$4" >> $html_tables_file
[[ $# == 5 ]] && html_table_object_header "$1" "$2" "$3" "$4" "$5" >> $html_tables_file
let temp_variable1=${#before_object_name[@]}-1
for index in `seq 0 $temp_variable1`
do
if [[ ${after_object_enabled_v4[${before_object_name[index]}]} != "" ]]
then
if [[ ${before_object_enabled_v4[${before_object_name[index]}]} != ${after_object_enabled_v4[${after_object_name[index]}]} ]] || [[ ${before_object_status_v4[${before_object_name[index]}]} != ${after_object_status_v4[${after_object_name[index]}]} ]]
then
let changes=changes+1
html_table_object_row "red" "${before_object_name[$index]}" ${before_object_enabled_v4[${before_object_name[index]}]} ${after_object_enabled_v4[${after_object_name[index]}]} \
${before_object_status_v4[${before_object_name[index]}]} ${after_object_status_v4[${after_object_name[index]}]} "Changed" >> $html_tables_file
else
html_table_object_row "white" "${before_object_name[$index]}" ${before_object_enabled_v4[${before_object_name[index]}]} ${after_object_enabled_v4[${after_object_name[index]}]} \
${before_object_status_v4[${before_object_name[index]}]} ${after_object_status_v4[${after_object_name[index]}]} "Same" >> $html_tables_file
fi
fi
done
html_table_object_tail >> $html_tables_file
}
# Generate object table
generate_object_table()
{
if [[ $bash_version_major > 3 ]]
then
generate_object_table_v4 "${@}"
return
fi
[[ $# == 3 ]] && html_table_object_header "$1" "$2" "$3" >> $html_tables_file
[[ $# == 4 ]] && html_table_object_header "$1" "$2" "$3" "$4" >> $html_tables_file
[[ $# == 5 ]] && html_table_object_header "$1" "$2" "$3" "$4" "$5" >> $html_tables_file
let temp_variable1=${#before_object_name[@]}-1
let temp_variable2=${#after_object_name[@]}-1
for index in `seq 0 $temp_variable1`
do
# If the same device, most likely the order of the objects will be same for both files
# To avoid a second loop, test if is the same first
if [[ "${before_object_name[$index]}" == "${after_object_name[$index]}" ]]
then
if [[ ${before_object_enabled[$index]} != ${after_object_enabled[$index]} ]] || [[ ${before_object_status[$index]} != ${after_object_status[$index]} ]]
then
let changes=changes+1
html_table_object_row "red" "${before_object_name[$index]}" ${before_object_enabled[$index]} ${after_object_enabled[$index]} \
${before_object_status[$index]} ${after_object_status[$index]} "Changed" >> $html_tables_file
else
html_table_object_row "white" "${before_object_name[$index]}" ${before_object_enabled[$index]} ${after_object_enabled[$index]} \
${before_object_status[$index]} ${after_object_status[$index]} "Same" >> $html_tables_file
fi
else
for index2 in `seq 0 $temp_variable2`
do
if [[ "${before_object_name[$index]}" == "${after_object_name[$index2]}" ]]
then
if [[ ${before_object_enabled[$index]} != ${after_object_enabled[$index2]} ]] || [[ ${before_object_status[$index]} != ${after_object_status[$index2]} ]]
then
let changes=changes+1
html_table_object_row "red" "${before_object_name[$index]}" ${before_object_enabled[$index]} ${after_object_enabled[$index2]} \
${before_object_status[$index]} ${after_object_status[$index2]} "Changed" >> $html_tables_file
else
html_table_object_row "white" "${before_object_name[$index]}" ${before_object_enabled[$index]} ${after_object_enabled[$index2]} \
${before_object_status[$index]} ${after_object_status[$index2]} "Same" >> $html_tables_file
fi
fi
done
fi
done
html_table_object_tail >> $html_tables_file
}
# Generate total table row
generate_total_table_row()
{
if [[ ${#before_object_name[@]} == ${#after_object_name[@]} ]]
then
html_table_total_row "white" "$1" ${#before_object_name[@]} ${#after_object_name[@]} >> $html_file
else
let changes=changes+1
html_table_total_row "red" "$1" ${#before_object_name[@]} ${#after_object_name[@]} >> $html_file
fi
}
# Merge files, total table first and object tables after
merge_files()
{
cat $html_tables_file >> $html_file
rm -f $html_tables_file
rm -f $before_file_tmp
}
# Generate the results to the HTML files
generate_results()
{
html_file=${HOSTNAME}-html-`date "+%Y%m%d%H%M%S"`".html"
html_tables_file=${HOSTNAME}-html-`date "+%Y%m%d%H%M%S"`".tmp"
changes=0
html_head > $html_file
> $html_tables_file
# LTM Module
html_table_total_header "LTM" "ltm" >> $html_file
# LTM Module Virtual
[[ $silent == 0 ]] && infobox "Calculating" "Virtual Server..." 0 0
load_files "ltmVsStatusEnabledState" "ltmVsStatusAvailState" $before_file $after_file
generate_object_table "LTM - Virtual Server" "ltm_virtual_server" "Virtual Server"
generate_total_table_row "Virtual Server"
# LTM Module Pool
[[ $silent == 0 ]] && infobox "Calculating" "LTM Pool..." 0 0
load_files "ltmPoolStatusEnabledState" "ltmPoolStatusAvailState" $before_file $after_file
generate_object_table "LTM - Pool" "ltm_pool" "Pool"
generate_total_table_row "Pool"
# LTM Module Pool Member
[[ $silent == 0 ]] && infobox "Calculating" "LTM Pool Member..." 0 0
load_files "ltmPoolMbrStatusEnabledState" "ltmPoolMbrStatusAvailState" $before_file $after_file
generate_object_table "LTM - Pool Member" "ltm_pool_member" "Pool" "Node" "Port"
generate_total_table_row "Pool Member"
# LTM Module Node
[[ $silent == 0 ]] && infobox "Calculating" "LTM Node..." 0 0
load_files "ltmNodeAddrStatusEnabledState" "ltmNodeAddrStatusAvailState" $before_file $after_file
generate_object_table "LTM - Node" "ltm_node" "Node"
generate_total_table_row "Node"
html_table_total_tail "LTM" >> $html_file
# GTM Module
if [[ $provision_gtm == 1 ]]
then
html_table_total_header "GTM" "gtm" >> $html_file
# GTM Module Data Center
[[ $silent == 0 ]] && infobox "Calculating" "GTM Data Center..." 0 0
load_files "gtmDcStatusEnabledState" "gtmDcStatusAvailState" $before_file $after_file
generate_object_table "GTM - Data Center" "gtm_data_center" "Data Center"
generate_total_table_row "Data Center"
# GTM Module Server
[[ $silent == 0 ]] && infobox "Calculating" "GTM Server..." 0 0
load_files "gtmServerStatusEnabledState" "gtmServerStatusAvailState" $before_file $after_file
generate_object_table "GTM - Server" "gtm_server" "Server"
generate_total_table_row "Server"
# GTM Module Wide IP
[[ $silent == 0 ]] && infobox "Calculating" "GTM Wide IP..." 0 0
load_files "gtmWideipStatusEnabledState" "gtmWideipStatusAvailState" $before_file $after_file
generate_object_table "GTM - Wide IP" "gtm_wideip" "Wide IP"
generate_total_table_row "Wide IP"
# GTM Module Pool
[[ $silent == 0 ]] && infobox "Calculating" "GTM Pool..." 0 0
load_files "gtmPoolStatusEnabledState" "gtmPoolStatusAvailState" $before_file $after_file
generate_object_table "GTM - Pool" "gtm_pool" "Pool"
generate_total_table_row "Pool"
# GTM Module Pool Member
[[ $silent == 0 ]] && infobox "Calculating" "GTM Pool Member..." 0 0
load_files "gtmPoolMbrStatusEnabledState" "gtmPoolMbrStatusAvailState" $before_file $after_file
generate_object_table "GTM - Pool Member" "gtm_pool_member" "Pool" "Server" "Virtual Server"
generate_total_table_row "Pool Member"
# GTM Module Virtual Server
[[ $silent == 0 ]] && infobox "Calculating" "GTM Virtual Server..." 0 0
load_files "gtmVsStatusEnabledState" "gtmVsStatusAvailState" $before_file $after_file
generate_object_table "GTM - Virtual Server" "gtm_virtual_server" "Server" "Virtual Server"
generate_total_table_row "Virtual Server"
# GTM Module Prober Pool
[[ $silent == 0 ]] && infobox "Calculating" "GTM Prober Pool..." 0 0
load_files "gtmProberPoolStatusEnabledState" "gtmProberPoolStatusAvailState" $before_file $after_file
generate_object_table "GTM - Prober Pool" "gtm_prober_pool" "Prober Pool"
generate_total_table_row "Prober Pool"
# GTM Module Prober Pool Member
[[ $silent == 0 ]] && infobox "Calculating" "GTM Prober Pool Member..." 0 0
load_files "gtmProberPoolMbrStatusEnabledState" "gtmProberPoolMbrStatusAvailState" $before_file $after_file
generate_object_table "GTM - Prober Pool Member" "gtm_prober_pool_member" "Prober Pool" "Server"
generate_total_table_row "Prober Pool Member"
# GTM Module Link
[[ $silent == 0 ]] && infobox "Calculating" "GTM Link..." 0 0
load_files "gtmLinkStatusEnabledState" "gtmLinkStatusAvailState" $before_file $after_file
generate_object_table "GTM - Link" "gtm_link" "Link"
generate_total_table_row "Link"
# GTM Module Distributed Application
[[ $silent == 0 ]] && infobox "Calculating" "GTM Distributed Application..." 0 0
load_files "gtmAppStatusEnabledState" "gtmAppStatusAvailState" $before_file $after_file
generate_object_table "GTM - Distributed Application" "gtm_distributed_application" "Distributed Application"
generate_total_table_row "Distributed Application"
html_table_total_tail "GTM" >> $html_file
fi
merge_files
html_tail >> $html_file
if [[ $changes == 0 ]]
then
sed -i 's/0123456789/No changes/' $html_file
else
sed -i 's/0123456789/Changes found/' $html_file
fi
sed -i s\/1234567890\/$changes\/ $html_file
[[ $silent == 0 ]] && menu_file_created $html_file
}
## HTML ##
# Create HTML code
# Code for first part of the HTMl file
html_head()
{
echo "<html>"
echo "<head>"
echo "<title>$script_name</title>"
cat <<'HereDocument'
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.20/css/jquery.dataTables.min.css">
<style type="text/css" class="init">
</style>
<script type="text/javascript" language="javascript" src="https://code.jquery.com/jquery-3.4.1.slim.min.js"></script>
<script type="text/javascript" language="javascript" src="https://cdn.datatables.net/1.10.20/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" class="init">
$(document).ready(function() {
$('#total_ltm').DataTable();
$('#total_gtm').DataTable();
$('#ltm_virtual_server').DataTable();
$('#ltm_pool').DataTable();
$('#ltm_pool_member').DataTable();
$('#ltm_node').DataTable();
$('#gtm_data_center').DataTable();
$('#gtm_server').DataTable();
$('#gtm_wideip').DataTable();
$('#gtm_pool').DataTable();
$('#gtm_pool_member').DataTable();
$('#gtm_virtual_server').DataTable();
$('#gtm_prober_pool').DataTable();
$('#gtm_prober_pool_member').DataTable();
$('#gtm_link').DataTable();
$('#gtm_distributed_application').DataTable();
} );
</script>
HereDocument
echo "</head>"
echo "<body>"
echo "<center>"
echo "<p><font size="10">$script_name</font></p>"
echo "<p><font size="5">`date`</font></p>"
echo "<br>"
echo "<p><font size="5">Status</font></p>"
echo "<p><font size="4">0123456789</font></p>"
echo "<p><font size="5">Number of Changes</font></p>"
echo "<p><font size="4">1234567890</font></p>"
echo "<br>"
}
# Code for last part of the HTMl file
# Includes TableFilter v0.6.21 to provide filtering functionality using Javascript to the tables
# http://koalyptus.github.io/TableFilter/
html_tail()
{
echo "</center>"
echo "</body>"
echo "</html>"
}
# Code for first part of the total table
html_table_total_header()
{
echo "<p><font size="5">${1} Total</font></p>"
echo "<table id="total_${2}" class="compact" border="1">"
echo "<thead>"
echo "<tr>"
echo "<th>Object</th>"
echo "<th>Before Change</th>"
echo "<th>After Change</th>"
echo "</tr>"
echo "</thead>"
echo "<tbody>"
}
# Code for a row of the total table
html_table_total_row()
{
echo "<tr>"
echo "<td bgcolor="$1">$2</td>"
echo "<td bgcolor="$1">$3</td>"
echo "<td bgcolor="$1">$4</td>"
echo "</tr>"
}
# Code for last part of the HTMl file
html_table_total_tail()
{
echo "</tbody>"
echo "</table>"
}
# Code for first part of the object table
html_table_object_header()
{
echo "<p><font size="5">$1</font></p>"
echo "<table id="$2" class="compact" border="1">"
echo "<thead>"
echo "<tr>"
echo "<th>$3</th>"
[[ $# > 3 ]] && echo "<th>$4</th>"
[[ $# > 4 ]] && echo "<th>$5</th>"
echo "<th>Before Change - Enabled</th>"
echo "<th>After Change - Enabled</th>"
echo "<th>Before Change - Status</th>"
echo "<th>After Change - Status</th>"
echo "<th>Result</th>"
echo "</tr>"
echo "</thead>"
echo "<tbody>"
}
# Code for a row of the object table
html_table_object_row()
{
echo "<tr>"
temp_variable1=`grep -o '+' <<< $2 | wc -l`
case $temp_variable1 in
0) echo "<td bgcolor="$1">$2</td>";;
1)
echo "<td bgcolor="$1">`cut -d'+' -f1 <<< $2`</td>"
echo "<td bgcolor="$1">`cut -d'+' -f2 <<< $2`</td>";;
2)
echo "<td bgcolor="$1">`cut -d'+' -f1 <<< $2`</td>"
echo "<td bgcolor="$1">`cut -d'+' -f2 <<< $2`</td>"
echo "<td bgcolor="$1">`cut -d'+' -f3 <<< $2`</td>";;
esac
echo "<td bgcolor="$1">$3</td>"
echo "<td bgcolor="$1">$4</td>"
echo "<td bgcolor="$1">$5</td>"
echo "<td bgcolor="$1">$6</td>"
echo "<td bgcolor="$1">$7</td>"
echo "</tr>"
}
# Code for last part of the object table
html_table_object_tail()
{
echo "</tbody>"
echo "</table>"
}
## Menu ##
# Create dialog menus
# Display a dialog box with a message, with a ok button
msgbox()
{
dialog --backtitle "$script_name - $HOSTNAME - $product $software_version" --title "$1" --msgbox "$2" $3 $4
}
# Display a dialog box with information, without buttons
infobox()
{
dialog --backtitle "$script_name - $HOSTNAME - $product $software_version" --title "$1" --infobox "$2" $3 $4
}
# Display a dialog box with yes or no answer.
yesnobox()
{
exec 3>&1
option=`dialog --backtitle "$script_name - $HOSTNAME - $product $software_version" --title "$1" --yesno "$2" "$3" $4 2>&1 1>&3`
exit_status=$?
exec 3>&-
if [[ $exit_status == $dialog_esc ]]
then
exit 0
else
return $exit_status
fi
}
# Display a dialog box to select a file
fselect()
{
while true
do
exec 3>&1
option=`dialog --cancel-label "Exit" --backtitle "$script_name - $HOSTNAME - $product $software_version" --title "Select a file" --fselect \
"${PWD}/" 0 0 2>&1 1>&3`
exit_status=$?
exec 3>&-
if [[ $exit_status == $dialog_esc ]] || [[ $exit_status == $dialog_cancel ]]
then
exit 0
else
if [[ -f $option ]]
then
fselect_option=$option
return
else
msgbox "Script Information" "The selected file is not valid.\nPress space to select a file." 0 0
fi
fi
done
}
# Display a dialog menu with multiple options
menu_main()
{
while true
do
exec 3>&1
option=`dialog --cancel-label "Exit" --backtitle "$script_name - $HOSTNAME - $product $software_version" --title "Menu" --menu \
"Select one option:" 0 0 10 \
"1" "Run before change" \
"2" "Run after change" \
"3" "Run before change without backup" \
"4" "Run after change without backup" \
"5" "Generate backup files" \
"6" "Generate UCS file" \
"7" "Generate QKView file" \