forked from Cyclenerd/static_status
-
Notifications
You must be signed in to change notification settings - Fork 0
/
status.sh
executable file
·1133 lines (1037 loc) · 36.6 KB
/
status.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
#!/usr/bin/env bash
# status.sh
# Author: Nils Knieling and Contributors- https://github.com/Cyclenerd/static_status
# Simple Bash script to generate a status page.
ME=$(basename "$0")
BASE_PATH=$(dirname "$0")
MY_TIMESTAMP=$(date -u "+%s")
MY_LASTRUN_TIME="0"
BE_LOUD="no"
BE_QUIET="no"
################################################################################
# Usage
################################################################################
function usage {
returnCode="$1"
echo -e "Usage: $ME [OPTION]:
OPTION is one of the following:
\\t silent no output from faulty connections to stout (default: $BE_QUIET)
\\t loud output from successful and faulty connections to stout (default: $BE_LOUD)
\\t debug displays all variables
\\t help displays help (this message)"
exit "$returnCode"
}
case "$1" in
"")
# called without arguments
;;
"silent")
BE_QUIET="yes"
;;
"loud")
BE_LOUD="yes"
;;
"debug")
ONLY_OUTPUT_DEBUG_VARIABLES="yes"
;;
"h" | "help" | "-h" | "-help" | "-?" | *)
usage 0
;;
esac
################################################################################
#### Configuration Section
################################################################################
# Tip: You can also outsource configuration to an extra configuration file.
# Just create a file named 'config' at the location of this script.
# You can find an example here:
# https://github.com/Cyclenerd/static_status/blob/master/config-example
# You can also pass a configuration file with the variable MY_STATUS_CONFIG.
# if a config file has been specified with MY_STATUS_CONFIG=myfile use this one, otherwise default to config
if [[ -z "$MY_STATUS_CONFIG" ]]; then
MY_STATUS_CONFIG="$BASE_PATH/config"
fi
if [ -e "$MY_STATUS_CONFIG" ]; then
if [[ "$BE_LOUD" = "yes" ]] || [[ "$BE_QUIET" = "no" ]]; then
echo "using config from file: $MY_STATUS_CONFIG"
fi
# ignore SC1090
# shellcheck source=/dev/null
source "$MY_STATUS_CONFIG"
fi
# Tip: You can tweak curl parameters via .curlrc config file.
# The default curl config file is checked for in the following places in this order:
# 1. "$CURL_HOME/.curlrc"
# 2. "$HOME/.curlrc"
#
# ~~~ Example .curlrc file ~~~
# # this is a comment
# # change the useragent string
# -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:97.0) Gecko/20100101 Firefox/97.0"
# # ok if certification validation fails
# --insecure
# ~~~ End of example file ~~~
# Title for the status page
MY_STATUS_TITLE=${MY_STATUS_TITLE:-"Status Page"}
# Link for the homepage button
MY_HOMEPAGE_URL=${MY_HOMEPAGE_URL:-"https://github.com/Cyclenerd/static_status"}
# Text for the homepage button
MY_HOMEPAGE_TITLE=${MY_HOMEPAGE_TITLE:-"Homepage"}
# Auto refresh interval in seconds 0 is no refresh
MY_AUTOREFRESH=${MY_AUTOREFRESH:-"0"}
# Shortcut to place the configuration file in a folder.
# Save it without / at the end.
MY_STATUS_CONFIG_DIR=${MY_STATUS_CONFIG_DIR:-"$HOME/status"}
# List with the configuration. What do we want to monitor?
MY_HOSTNAME_FILE=${MY_HOSTNAME_FILE:-"$MY_STATUS_CONFIG_DIR/status_hostname_list.txt"}
# Where should the HTML status page be stored?
MY_STATUS_HTML=${MY_STATUS_HTML:-"$HOME/status_index.html"}
# Where should the SVG status icon be stored?
MY_STATUS_ICON=${MY_STATUS_ICON:-"$HOME/status.svg"}
# Icon colors
MY_STATUS_ICON_COLOR_SUCCESS=${MY_STATUS_ICON_COLOR_SUCCESS:-"lime"}
MY_STATUS_ICON_COLOR_WARNING=${MY_STATUS_ICON_COLOR_WARNING:-"orange"}
MY_STATUS_ICON_COLOR_DANGER=${MY_STATUS_ICON_COLOR_DANGER:-"red"}
# Where should the JSON status page be stored? Set to "" to disable JSON output
MY_STATUS_JSON=${MY_STATUS_JSON:-"$HOME/status.json"}
# Text file in which you can place a status message.
# If the file exists and has a content, all errors on the status page are overwritten.
MY_MAINTENANCE_TEXT_FILE=${MY_MAINTENANCE_TEXT_FILE:-"$MY_STATUS_CONFIG_DIR/status_maintenance_text.txt"}
# Duration we wait for response (nc, curl and traceroute).
MY_TIMEOUT=${MY_TIMEOUT:-"2"}
# Duration we wait for response (only ping).
MY_PING_TIMEOUT=${MY_PING_TIMEOUT:-"4"}
MY_PING_COUNT=${MY_PING_COUNT:-"2"}
# Duration we wait for response (only script)
MY_SCRIPT_TIMEOUT=${MY_SCRIPT_TIMEOUT:-20}
# Route to host
MY_TRACEROUTE_HOST=${MY_TRACEROUTE_HOST:-"1.1.1.1"} # Cloudflare DNS
# Sets the number of probe packets per hop
MY_TRACEROUTE_NQUERIES=${MY_TRACEROUTE_NQUERIES:-"1"}
# Location for the status files. Please do not edit created files.
MY_HOSTNAME_STATUS_OK=${MY_HOSTNAME_STATUS_OK:-"$MY_STATUS_CONFIG_DIR/status_hostname_ok.txt"}
MY_HOSTNAME_STATUS_DOWN=${MY_HOSTNAME_STATUS_DOWN:-"$MY_STATUS_CONFIG_DIR/status_hostname_down.txt"}
MY_HOSTNAME_STATUS_LASTRUN=${MY_HOSTNAME_STATUS_LASTRUN:-"$MY_STATUS_CONFIG_DIR/status_hostname_last.txt"}
MY_HOSTNAME_STATUS_DEGRADE=${MY_HOSTNAME_STATUS_DEGRADE:-"$MY_STATUS_CONFIG_DIR/status_hostname_degrade.txt"}
MY_HOSTNAME_STATUS_LASTRUN_DEGRADE=${MY_HOSTNAME_STATUS_LASTRUN_DEGRADE:-"$MY_STATUS_CONFIG_DIR/status_hostname_last_degrade.txt"}
MY_HOSTNAME_STATUS_HISTORY=${MY_HOSTNAME_STATUS_HISTORY:-"$MY_STATUS_CONFIG_DIR/status_hostname_history.txt"}
MY_HOSTNAME_STATUS_HISTORY_TEMP_SORT=${MY_HOSTNAME_STATUS_HISTORY_TEMP_SORT:-"/tmp/status_hostname_history_sort.txt"}
# Minimum downtime in seconds to display in past incidents
MY_MIN_DOWN_TIME=${MY_MIN_DOWN_TIME:-"60"}
# CSS Stylesheet for the status page
MY_STATUS_STYLESHEET=${MY_STATUS_STYLESHEET:-"https://cdnjs.cloudflare.com/ajax/libs/bootstrap/4.6.2/css/bootstrap.min.css"}
# FontAwesome for the status page
MY_STATUS_FONTAWESOME=${MY_STATUS_FONTAWESOME:-"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css"}
# A footer
MY_STATUS_FOOTER=${MY_STATUS_FOOTER:-'Powered by <a href="https://github.com/Cyclenerd/static_status">static_status</a>'}
# Lock file to prevent duplicate execution.
# If this file exists, status.sh script is terminated.
# If something has gone wrong and the file has not been deleted automatically, you can delete it.
MY_STATUS_LOCKFILE=${MY_STATUS_LOCKFILE:-"/tmp/STATUS_SH_IS_RUNNING.lock"}
# Date format for the web page.
# UTC (`-u`) is the default.
# Example: 2021-12-23 12:34:55 UTC
MY_DATE_TIME=${MY_DATE_TIME:-$(date -u "+%Y-%m-%d %H:%M:%S %Z")}
# Can be changed. Example with system time:
# MY_DATE_TIME=$(date "+%Y-%m-%d %H:%M:%S")
# Avoid semicolons.
# More details can be found in `man date`.
################################################################################
#### END Configuration Section
################################################################################
################################################################################
# Helper
################################################################################
# debug_variables() print all script global variables to ease debugging
debug_variables() {
echo "USER: $USER"
echo "SHELL: $SHELL"
echo "BASH_VERSION: $BASH_VERSION"
echo
echo "MY_COMMANDS:"
for MY_COMMAND in "${MY_COMMANDS[@]}"; do
echo " $MY_COMMAND"
done
echo
echo "MY_TIMEOUT: $MY_TIMEOUT"
echo "MY_STATUS_CONFIG: $MY_STATUS_CONFIG"
echo "MY_STATUS_CONFIG_DIR: $MY_STATUS_CONFIG_DIR"
echo "MY_HOSTNAME_FILE: $MY_HOSTNAME_FILE"
echo "MY_HOSTNAME_STATUS_OK: $MY_HOSTNAME_STATUS_OK"
echo "MY_HOSTNAME_STATUS_DOWN: $MY_HOSTNAME_STATUS_DOWN"
echo "MY_HOSTNAME_STATUS_LASTRUN: $MY_HOSTNAME_STATUS_LASTRUN"
echo "MY_HOSTNAME_STATUS_DEGRADE: $MY_HOSTNAME_STATUS_DEGRADE"
echo "MY_HOSTNAME_STATUS_LASTRUN_DEGRADE: $MY_HOSTNAME_STATUS_LASTRUN_DEGRADE"
echo "MY_HOSTNAME_STATUS_HISTORY: $MY_HOSTNAME_STATUS_HISTORY"
echo
echo "MY_STATUS_HTML: $MY_STATUS_HTML"
echo "MY_STATUS_ICON: $MY_STATUS_ICON"
echo "MY_STATUS_JSON: $MY_STATUS_JSON"
echo "MY_MAINTENANCE_TEXT_FILE: $MY_MAINTENANCE_TEXT_FILE"
echo "MY_HOMEPAGE_URL: $MY_HOMEPAGE_URL"
echo "MY_HOMEPAGE_TITLE: $MY_HOMEPAGE_TITLE"
echo "MY_STATUS_TITLE: $MY_STATUS_TITLE"
echo "MY_STATUS_STYLESHEET: $MY_STATUS_STYLESHEET"
echo "MY_STATUS_FOOTER: $MY_STATUS_FOOTER"
echo
echo "MY_STATUS_LOCKFILE: $MY_STATUS_LOCKFILE"
echo
echo "MY_TIMEOUT: $MY_TIMEOUT"
echo "MY_PING_TIMEOUT: $MY_PING_TIMEOUT"
echo "MY_PING_COUNT: $MY_PING_COUNT"
echo "MY_SCRIPT_TIMEOUT: $MY_SCRIPT_TIMEOUT"
echo "MY_TRACEROUTE_HOST: $MY_TRACEROUTE_HOST"
echo "MY_TRACEROUTE_NQUERIES: $MY_TRACEROUTE_NQUERIES"
echo
echo "MY_TIMESTAMP: $MY_TIMESTAMP"
echo "MY_DATE_TIME: $MY_DATE_TIME"
echo "MY_LASTRUN_TIME: $MY_LASTRUN_TIME"
}
# command_exists() tells if a given command exists.
function command_exists() {
command -v "$1" >/dev/null 2>&1
}
# check_bash() check if current shell is bash
function check_bash() {
if [[ "$0" == *"bash" ]]; then
exit_with_failure "Your current shell is $0"
fi
}
# check_command() check if command exists and exit if not exists
function check_command() {
if ! command_exists "$1"; then
exit_with_failure "Command '$1' not found"
fi
}
# check_config() check if the configuration file is readable
function check_config() {
if [ ! -r "$1" ]; then
exit_with_failure "Can not read required configuration file '$1'"
fi
}
# check_file() check if the file exists if not create the file
function check_file() {
if [ ! -f "$1" ]; then
if ! echo > "$1"; then
exit_with_failure "Can not create file '$1'"
fi
fi
if [ ! -w "$1" ]; then
exit_with_failure "Can not write file '$1'"
fi
}
# exit_with_failure() outputs a message before exiting the script.
function exit_with_failure() {
echo
echo "FAILURE: $1"
echo
debug_variables
echo
del_lock
exit 1
}
# echo_warning() outputs a warning message.
function echo_warning() {
echo
echo "WARNING: $1, will attempt to continue..."
echo
}
# echo_do_not_edit() outputs a "do not edit" message to write to a file
function echo_do_not_edit() {
echo "#"
echo "# !!! Do not edit this file !!!"
echo "#"
echo "# To reset everything, delete the files:"
echo "# $MY_HOSTNAME_STATUS_OK"
echo "# $MY_HOSTNAME_STATUS_DOWN"
echo "# $MY_HOSTNAME_STATUS_LASTRUN"
echo "# $MY_HOSTNAME_STATUS_DEGRADE"
echo "# $MY_HOSTNAME_STATUS_LASTRUN_DEGRADE"
echo "# $MY_HOSTNAME_STATUS_HISTORY"
echo "#"
}
# set_lock() sets lock file
function set_lock() {
if ! echo "$MY_DATE_TIME" > "$MY_STATUS_LOCKFILE"; then
exit_with_failure "Can not create lock file '$MY_STATUS_LOCKFILE'"
fi
}
# del_lock() deletes lock file
function del_lock() {
rm "$MY_STATUS_LOCKFILE" &> /dev/null
}
# check_lock() checks lock file and exit if the file exists
function check_lock() {
if [ -f "$MY_STATUS_LOCKFILE" ]; then
exit_with_failure "$ME is already running. Please wait... In case of problems simply delete the file: '$MY_STATUS_LOCKFILE'"
fi
}
# port_to_name() outputs name of well-known ports
# https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers#Well-known_ports
function port_to_name() {
case "$1" in
32[0-9][0-9])
MY_PORT_NAME="SAP Dispatcher"
;;
33[0-9][0-9])
MY_PORT_NAME="SAP Gateway"
;;
80[0-9][0-9])
MY_PORT_NAME="SAP ICM HTTP"
;;
443[0-9][0-9])
MY_PORT_NAME="SAP ICM HTTPS"
;;
36[0-9][0-9])
MY_PORT_NAME="SAP Message Server"
;;
5[0-9][0-9]00)
MY_PORT_NAME="SAP J2EE HTTP"
;;
5[0-9][0-9]01)
MY_PORT_NAME="SAP J2EE HTTPS"
;;
5[0-9][0-9]04)
MY_PORT_NAME="SAP P4"
;;
5[0-9][0-9]08)
MY_PORT_NAME="SAP Telnet"
;;
*)
MY_SERVICE_NAME=$(awk '$2 ~ /^'"$1"'\// {print $1; exit}' "/etc/services" 2> /dev/null)
if [ -n "$MY_SERVICE_NAME" ]; then
MY_PORT_NAME=$(echo "$MY_SERVICE_NAME" | awk '{print toupper($0)}')
else
MY_PORT_NAME="Port $1"
fi
;;
esac
printf "%s" "$MY_PORT_NAME"
}
# get_lastrun_time()
function get_lastrun_time() {
while IFS=';' read -r MY_LASTRUN_COMMAND MY_LASTRUN_TIMESTAMP || [[ -n "$MY_LASTRUN_COMMAND" ]]; do
if [[ "$MY_LASTRUN_COMMAND" = "timestamp" ]]; then
if [ "$MY_LASTRUN_TIMESTAMP" -ge "0" ]; then
MY_LASTRUN_TIME="$((MY_TIMESTAMP-MY_LASTRUN_TIMESTAMP))"
else
MY_LASTRUN_TIME="0"
fi
fi
done <"$MY_HOSTNAME_STATUS_LASTRUN"
}
# check_downtime() check whether a failure has already been documented
# and determine the duration
function check_downtime() {
MY_COMMAND="$1"
MY_HOSTNAME="$2"
MY_PORT="$3"
MY_DOWN_TIME="0"
while IFS=';' read -r MY_DOWN_COMMAND MY_DOWN_HOSTNAME MY_DOWN_PORT MY_DOWN_TIME || [[ -n "$MY_DOWN_COMMAND" ]]; do
if [[ "$MY_DOWN_COMMAND" = "ping" ]] ||
[[ "$MY_DOWN_COMMAND" = "ping6" ]] ||
[[ "$MY_DOWN_COMMAND" = "nc" ]] ||
[[ "$MY_DOWN_COMMAND" = "grep" ]] ||
[[ "$MY_DOWN_COMMAND" = "traceroute" ]] ||
[[ "$MY_DOWN_COMMAND" = "curl" ]] ||
[[ "$MY_DOWN_COMMAND" = "http-status" ]] ||
[[ "$MY_DOWN_COMMAND" = "script" ]]; then
if [[ "$MY_DOWN_HOSTNAME" = "$MY_HOSTNAME" ]]; then
if [[ "$MY_DOWN_PORT" = "$MY_PORT" ]]; then
MY_DOWN_TIME="$((MY_DOWN_TIME+MY_LASTRUN_TIME))"
break # Skip entire rest of loop.
fi
fi
fi
done <"$MY_HOSTNAME_STATUS_LASTRUN" # MY_HOSTNAME_STATUS_DOWN is copied to MY_HOSTNAME_STATUS_LASTRUN
}
# check_degradetime() check whether a degradation has already been documented
# and determine the duration
function check_degradetime() {
MY_COMMAND="$1"
MY_HOSTNAME="$2"
MY_DEGRADE_TIME="0"
while IFS=';' read -r MY_DEGRADE_COMMAND MY_DEGRADE_HOSTNAME MY_DEGRADE_TIME || [[ -n "$MY_DEGRADE_COMMAND" ]]; do
if [[ "$MY_DEGRADE_COMMAND" = "script" ]]; then
if [[ "$MY_DEGRADE_HOSTNAME" = "$MY_HOSTNAME" ]]; then
MY_DEGRADE_TIME="$((MY_DEGRADE_TIME+MY_LASTRUN_TIME))"
break # Skip entire rest of loop.
fi
fi
done <"$MY_HOSTNAME_STATUS_LASTRUN_DEGRADE" # MY_HOSTNAME_STATUS_DEGRADE is copied to MY_HOSTNAME_STATUS_LASTRUN_DEGRADE
}
# save_downtime()
function save_downtime() {
MY_COMMAND="$1"
MY_HOSTNAME="$2"
MY_PORT="$3"
MY_DOWN_TIME="$4"
printf "\\n%s;%s;%s;%s" "$MY_COMMAND" "$MY_HOSTNAME" "$MY_PORT" "$MY_DOWN_TIME" >> "$MY_HOSTNAME_STATUS_DOWN"
if [[ "$BE_LOUD" = "yes" ]] || [[ "$BE_QUIET" = "no" ]]; then
printf "\\n%-5s %-4s %s" "DOWN:" "$MY_COMMAND" "$MY_HOSTNAME"
if [[ $MY_COMMAND == "nc" ]]; then
printf " %s" "$(port_to_name "$MY_PORT")"
fi
if [[ $MY_COMMAND == "grep" ]]; then
printf " %s" "$MY_PORT"
fi
if [[ $MY_COMMAND == "http-status" ]]; then
printf " %s" "$MY_PORT"
fi
fi
}
# save_degradetime()
function save_degradetime() {
MY_COMMAND="$1"
MY_HOSTNAME="$2"
MY_DEGRADE_TIME="$3"
printf "\\n%s;%s;%s" "$MY_COMMAND" "$MY_HOSTNAME" "$MY_DEGRADE_TIME" >> "$MY_HOSTNAME_STATUS_DEGRADE"
if [[ "$BE_LOUD" = "yes" ]] || [[ "$BE_QUIET" = "no" ]]; then
printf "\\n%-5s %-4s %s" "DEGRADED:" "$MY_COMMAND" "$MY_HOSTNAME"
fi
}
# save_availability()
function save_availability() {
MY_COMMAND="$1"
MY_HOSTNAME="$2"
MY_PORT="$3"
printf "\\n%s;%s;%s" "$MY_COMMAND" "$MY_HOSTNAME" "$MY_PORT" >> "$MY_HOSTNAME_STATUS_OK"
if [[ "$BE_LOUD" = "yes" ]]; then
printf "\\n%-5s %-4s %s" "UP:" "$MY_COMMAND" "$MY_HOSTNAME"
if [[ $MY_COMMAND == "nc" ]]; then
printf " %s" "$(port_to_name "$MY_PORT")"
fi
if [[ $MY_COMMAND == "grep" ]]; then
printf " %s" "$MY_PORT"
fi
if [[ $MY_COMMAND == "http-status" ]]; then
printf " %s" "$MY_PORT"
fi
fi
}
# save_history()
function save_history() {
MY_COMMAND="$1"
MY_HOSTNAME="$2"
MY_PORT="$3"
MY_DOWN_TIME="$4"
MY_DATE_TIME="$5"
if cp "$MY_HOSTNAME_STATUS_HISTORY" "$MY_HOSTNAME_STATUS_HISTORY_TEMP_SORT" &> /dev/null; then
printf "\\n%s;%s;%s;%s;%s" "$MY_COMMAND" "$MY_HOSTNAME" "$MY_PORT" "$MY_DOWN_TIME" "$MY_DATE_TIME" > "$MY_HOSTNAME_STATUS_HISTORY"
cat "$MY_HOSTNAME_STATUS_HISTORY_TEMP_SORT" >> "$MY_HOSTNAME_STATUS_HISTORY"
rm "$MY_HOSTNAME_STATUS_HISTORY_TEMP_SORT" &> /dev/null
else
exit_with_failure "Can not copy file '$MY_HOSTNAME_STATUS_HISTORY' to '$MY_HOSTNAME_STATUS_HISTORY_TEMP_SORT'"
fi
if [[ "$BE_LOUD" = "yes" ]]; then
printf "\\n%-5s %-4s %s %s sec" "HIST:" "$MY_COMMAND" "$MY_HOSTNAME" "$MY_DOWN_TIME"
if [[ $MY_COMMAND == "nc" ]]; then
printf " %s" "$(port_to_name "$MY_PORT")"
fi
if [[ $MY_COMMAND == "grep" ]]; then
printf " %s" "$MY_PORT"
fi
if [[ $MY_COMMAND == "http-status" ]]; then
printf " %s" "$MY_PORT"
fi
fi
}
################################################################################
# HTML
################################################################################
function page_header() {
# check for autorefresh
if [ "$MY_AUTOREFRESH" -gt 0 ]
then
MY_AUTOREFRESH_TEXT="<meta http-equiv=\"refresh\" content=\"$MY_AUTOREFRESH\">"
else
MY_AUTOREFRESH_TEXT=""
fi
cat > "$MY_STATUS_HTML" << EOF
<!DOCTYPE HTML>
<html lang="en" translate="no">
<head>
<meta charset="utf-8">
<title>$MY_STATUS_TITLE</title>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="robots" content="noindex, nofollow">
$MY_AUTOREFRESH_TEXT
<link rel="stylesheet" href="$MY_STATUS_STYLESHEET">
<link rel="stylesheet" href="$MY_STATUS_FONTAWESOME">
<link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🚦</text></svg>">
</head>
<body>
<div class="container">
<div class="pb-2 mt-5 mb-2 border-bottom">
<h1>
$MY_STATUS_TITLE
<span class="float-right d-none d-sm-block">
<a href="$MY_HOMEPAGE_URL" class="btn btn-primary" role="button">
<i class="fas fa-home"></i>
$MY_HOMEPAGE_TITLE
</a>
</span>
</h1>
</div>
<div class="d-sm-none d-md-none d-lg-none d-xl-none my-3">
<a href="$MY_HOMEPAGE_URL" class="btn btn-primary" role="button">
<i class="fas fa-home"></i>
$MY_HOMEPAGE_TITLE
</a>
</div>
EOF
}
function page_footer() {
cat >> "$MY_STATUS_HTML" << EOF
<hr class="mt-4">
<footer>
<p>$MY_STATUS_FOOTER</p>
<p class="text-muted">$MY_DATE_TIME</p>
</footer>
</div>
<!-- Powered by https://github.com/Cyclenerd/static_status -->
</body>
</html>
EOF
}
function page_alert_success() {
cat >> "$MY_STATUS_HTML" << EOF
<div class="alert alert-success my-3" role="alert">
<i class="fas fa-thumbs-up"></i>
All systems are operational
</div>
EOF
}
function page_alert_warning() {
cat >> "$MY_STATUS_HTML" << EOF
<div class="alert alert-warning my-3" role="alert">
<i class="fas fa-exclamation-triangle"></i>
Some systems are experiencing problems
</div>
EOF
}
function page_alert_danger() {
cat >> "$MY_STATUS_HTML" << EOF
<div class="alert alert-danger my-3" role="alert">
<i class="fas fa-fire"></i>
Major Outage
</div>
EOF
}
function page_alert_maintenance() {
cat >> "$MY_STATUS_HTML" << EOF
<div class="card my-3">
<div class="card-header">
<i class="fas fa-wrench"></i>
Maintenance
</div>
<div class="card-body">
EOF
if [ -r "$MY_MAINTENANCE_TEXT_FILE" ]; then
cat "$MY_MAINTENANCE_TEXT_FILE" >> "$MY_STATUS_HTML"
else
echo ":-(" >> "$MY_STATUS_HTML"
echo_warning "Can not read file '$MY_MAINTENANCE_TEXT_FILE'"
fi
cat >> "$MY_STATUS_HTML" << EOF
</div>
</div>
EOF
}
function item_ok() {
echo '<li class="list-group-item d-flex justify-content-between align-items-center">'
if [[ -n "${MY_DISPLAY_TEXT}" ]]; then
echo "${MY_DISPLAY_TEXT}"
else
if [[ "$MY_OK_COMMAND" = "ping" ]]; then
echo "ping $MY_OK_HOSTNAME"
elif [[ "$MY_OK_COMMAND" = "ping6" ]]; then
echo "ping6 $MY_OK_HOSTNAME"
elif [[ "$MY_OK_COMMAND" = "nc" ]]; then
echo "$(port_to_name "$MY_OK_PORT") on $MY_OK_HOSTNAME"
elif [[ "$MY_OK_COMMAND" = "curl" ]]; then
echo "Site $MY_OK_HOSTNAME"
elif [[ "$MY_OK_COMMAND" = "http-status" ]]; then
echo "HTTP status $MY_OK_PORT of $MY_OK_HOSTNAME"
elif [[ "$MY_OK_COMMAND" = "grep" ]]; then
echo "Grep for \"$MY_OK_PORT\" on $MY_OK_HOSTNAME"
elif [[ "$MY_OK_COMMAND" = "traceroute" ]]; then
echo "Route path contains $MY_OK_HOSTNAME"
elif [[ "$MY_OK_COMMAND" = "script" ]]; then
echo "Script $MY_OK_HOSTNAME"
fi
fi
cat <<EOF
<span class="badge badge-pill badge-success"><i class="fas fa-check"></i></span>
</li>
EOF
}
function item_down() {
echo '<li class="list-group-item d-flex justify-content-between align-items-center">'
if [[ -n "${MY_DISPLAY_TEXT}" ]]; then
echo "${MY_DISPLAY_TEXT}"
else
if [[ "$MY_DOWN_COMMAND" = "ping" ]]; then
echo "ping $MY_DOWN_HOSTNAME"
elif [[ "$MY_DOWN_COMMAND" = "ping6" ]]; then
echo "ping6 $MY_DOWN_HOSTNAME"
elif [[ "$MY_DOWN_COMMAND" = "nc" ]]; then
echo "$(port_to_name "$MY_DOWN_PORT") on $MY_DOWN_HOSTNAME"
elif [[ "$MY_DOWN_COMMAND" = "curl" ]]; then
echo "Site $MY_DOWN_HOSTNAME"
elif [[ "$MY_DOWN_COMMAND" = "http-status" ]]; then
echo "HTTP status $MY_DOWN_PORT of $MY_DOWN_HOSTNAME"
elif [[ "$MY_DOWN_COMMAND" = "grep" ]]; then
echo "Grep for \"$MY_DOWN_PORT\" on $MY_DOWN_HOSTNAME"
elif [[ "$MY_DOWN_COMMAND" = "traceroute" ]]; then
echo "Route path contains $MY_DOWN_HOSTNAME"
elif [[ "$MY_DOWN_COMMAND" = "script" ]]; then
echo "Script $MY_DOWN_HOSTNAME"
fi
fi
printf '<span class="badge badge-pill badge-danger"><i class="fas fa-times"></i> '
if [[ "$MY_DOWN_TIME" -gt "1" ]]; then
printf "%.0f min</span>" "$((MY_DOWN_TIME/60))"
else
echo "</span>"
fi
echo "</li>"
}
function item_degrade() {
echo '<li class="list-group-item d-flex justify-content-between align-items-center">'
if [[ -n "${MY_DISPLAY_TEXT}" ]]; then
echo "${MY_DISPLAY_TEXT}"
else
echo "Script $MY_DEGRADE_HOSTNAME"
fi
printf '<span class="badge badge-pill badge-warning badge"><i class="fas fa-times"></i> '
if [[ "$MY_DEGRADE_TIME" -gt "1" ]]; then
printf "%.0f min</span>" "$((MY_DEGRADE_TIME/60))"
else
echo "</span>"
fi
echo "</li>"
}
function item_history() {
echo '<li class="list-group-item d-flex justify-content-between align-items-center">'
echo '<span>'
if [[ -n "${MY_DISPLAY_TEXT}" ]]; then
echo "${MY_DISPLAY_TEXT}"
else
if [[ "$MY_HISTORY_COMMAND" = "ping" ]]; then
echo "ping $MY_HISTORY_HOSTNAME"
elif [[ "$MY_HISTORY_COMMAND" = "ping6" ]]; then
echo "ping6 $MY_HISTORY_HOSTNAME"
elif [[ "$MY_HISTORY_COMMAND" = "nc" ]]; then
echo "$(port_to_name "$MY_HISTORY_PORT") on $MY_HISTORY_HOSTNAME"
elif [[ "$MY_HISTORY_COMMAND" = "curl" ]]; then
echo "Site $MY_HISTORY_HOSTNAME"
elif [[ "$MY_HISTORY_COMMAND" = "http-status" ]]; then
echo "HTTP status $MY_HISTORY_PORT of $MY_HISTORY_HOSTNAME"
elif [[ "$MY_HISTORY_COMMAND" = "grep" ]]; then
echo "Grep for \"$MY_HISTORY_PORT\" on $MY_HISTORY_HOSTNAME"
elif [[ "$MY_HISTORY_COMMAND" = "traceroute" ]]; then
echo "Route path contains $MY_HISTORY_HOSTNAME"
elif [[ "$MY_HISTORY_COMMAND" = "script" ]]; then
echo "Script $MY_HISTORY_HOSTNAME"
fi
fi
echo '<small class="text-muted">'
echo "$MY_HISTORY_DATE_TIME"
echo '</small>'
echo '</span>'
printf '<span class="badge badge-pill badge-dark"><i class="fas fa-times"></i> '
if [[ "$MY_HISTORY_DOWN_TIME" -gt "1" ]]; then
printf "%.0f min</span>" "$((MY_HISTORY_DOWN_TIME/60))"
else
echo "</span>"
fi
echo "</li>"
}
################################################################################
# MAIN
################################################################################
check_bash
# Commands we need
MY_COMMANDS=(
ping
ping6
nc
curl
grep
sed
)
# Add traceroute optional if MY_TRACEROUTE_HOST is set
if [[ -n "$MY_TRACEROUTE_HOST" ]]; then
MY_COMMANDS+=("traceroute")
fi
if [[ -n "$ONLY_OUTPUT_DEBUG_VARIABLES" ]]; then
debug_variables
exit
fi
for MY_COMMAND in "${MY_COMMANDS[@]}"; do
check_command "$MY_COMMAND"
done
check_lock
set_lock
check_config "$MY_HOSTNAME_FILE"
check_file "$MY_HOSTNAME_STATUS_DOWN"
check_file "$MY_HOSTNAME_STATUS_LASTRUN"
check_file "$MY_HOSTNAME_STATUS_DEGRADE"
check_file "$MY_HOSTNAME_STATUS_LASTRUN_DEGRADE"
check_file "$MY_HOSTNAME_STATUS_HISTORY"
check_file "$MY_HOSTNAME_STATUS_HISTORY_TEMP_SORT"
check_file "$MY_STATUS_HTML"
# Optional checks
if [ -n "$MY_STATUS_ICON" ]; then
check_file "$MY_STATUS_ICON" # status.svg
fi
if [ -n "$MY_STATUS_JSON" ]; then
check_file "$MY_STATUS_JSON" # status.json
fi
if cp "$MY_HOSTNAME_STATUS_DOWN" "$MY_HOSTNAME_STATUS_LASTRUN" && cp "$MY_HOSTNAME_STATUS_DEGRADE" "$MY_HOSTNAME_STATUS_LASTRUN_DEGRADE"; then
get_lastrun_time
else
exit_with_failure "Can not copy file '$MY_HOSTNAME_STATUS_DOWN' to '$MY_HOSTNAME_STATUS_LASTRUN' or '$MY_HOSTNAME_STATUS_DEGRADE' to '$MY_HOSTNAME_STATUS_LASTRUN_DEGRADE'"
fi
{
echo "# $MY_DATE_TIME"
echo_do_not_edit
} > "$MY_HOSTNAME_STATUS_OK"
{
echo "# $MY_DATE_TIME"
echo_do_not_edit
echo "timestamp;$MY_TIMESTAMP"
} > "$MY_HOSTNAME_STATUS_DEGRADE"
{
echo "# $MY_DATE_TIME"
echo_do_not_edit
echo "timestamp;$MY_TIMESTAMP"
} > "$MY_HOSTNAME_STATUS_DOWN"
#
# Check and save status
#
MY_HOSTNAME_COUNT=0
while IFS=';' read -r MY_COMMAND MY_HOSTNAME_STRING MY_PORT || [[ -n "$MY_COMMAND" ]]; do
MY_HOSTNAME="${MY_HOSTNAME_STRING%%|*}" # remove alternative display textS
if [[ "$MY_COMMAND" = "ping" ]]; then
(( MY_HOSTNAME_COUNT++ ))
# Detect ping Version
ping &> /dev/null
# macOS: 64 = ping -n -t TIMEOUT
# GNU: 2 = ping -n -w TIMEOUT (-t TTL)
# OpenBSD: 1 = ping -n -w TIMEOUT (-t TTL)
if [ $? -gt 2 ] || [[ "$OSTYPE" == "freebsd"* ]]; then
# BSD ping
MY_PING_COMMAND='ping -n -t'
else
# GNU or OpenBSD ping
MY_PING_COMMAND='ping -n -w'
fi
if $MY_PING_COMMAND "$MY_PING_TIMEOUT" -c "$MY_PING_COUNT" "$MY_HOSTNAME" &> /dev/null; then
check_downtime "$MY_COMMAND" "$MY_HOSTNAME_STRING" ""
# Check status change
if [[ "$MY_DOWN_TIME" -gt "0" ]]; then
save_history "$MY_COMMAND" "$MY_HOSTNAME_STRING" "" "$MY_DOWN_TIME" "$MY_DATE_TIME"
fi
save_availability "$MY_COMMAND" "$MY_HOSTNAME_STRING" ""
else
check_downtime "$MY_COMMAND" "$MY_HOSTNAME_STRING" ""
save_downtime "$MY_COMMAND" "$MY_HOSTNAME_STRING" "" "$MY_DOWN_TIME"
fi
elif [[ "$MY_COMMAND" = "ping6" ]]; then
(( MY_HOSTNAME_COUNT++ ))
# Detect ping6 Version
ping6 &> /dev/null
# macOS: 64 = ping6 -n -t TIMEOUT
# GNU: 2 = ping6 -n -w TIMEOUT (-t TTL)
# OpenBSD: 1 = ping6 -n -w TIMEOUT (-t TTL)
if [ $? -gt 2 ] || [[ "$OSTYPE" == "freebsd"* ]]; then
# BSD ping6
MY_PING6_COMMAND='ping6 -n -t'
else
# GNU or OpenBSD ping6
MY_PING6_COMMAND='ping6 -n -w'
fi
if $MY_PING6_COMMAND "$MY_PING_TIMEOUT" -c "$MY_PING_COUNT" "$MY_HOSTNAME" &> /dev/null; then
check_downtime "$MY_COMMAND" "$MY_HOSTNAME_STRING" ""
# Check status change
if [[ "$MY_DOWN_TIME" -gt "0" ]]; then
save_history "$MY_COMMAND" "$MY_HOSTNAME_STRING" "" "$MY_DOWN_TIME" "$MY_DATE_TIME"
fi
save_availability "$MY_COMMAND" "$MY_HOSTNAME_STRING" ""
else
check_downtime "$MY_COMMAND" "$MY_HOSTNAME_STRING" ""
save_downtime "$MY_COMMAND" "$MY_HOSTNAME_STRING" "" "$MY_DOWN_TIME"
fi
elif [[ "$MY_COMMAND" = "nc" ]]; then
(( MY_HOSTNAME_COUNT++ ))
if nc -z -w "$MY_TIMEOUT" "$MY_HOSTNAME" "$MY_PORT" &> /dev/null; then
check_downtime "$MY_COMMAND" "$MY_HOSTNAME_STRING" "$MY_PORT"
# Check status change
if [[ "$MY_DOWN_TIME" -gt "0" ]]; then
save_history "$MY_COMMAND" "$MY_HOSTNAME_STRING" "$MY_PORT" "$MY_DOWN_TIME" "$MY_DATE_TIME"
fi
save_availability "$MY_COMMAND" "$MY_HOSTNAME_STRING" "$MY_PORT"
else
check_downtime "$MY_COMMAND" "$MY_HOSTNAME_STRING" "$MY_PORT"
save_downtime "$MY_COMMAND" "$MY_HOSTNAME_STRING" "$MY_PORT" "$MY_DOWN_TIME"
fi
elif [[ "$MY_COMMAND" = "curl" ]]; then
(( MY_HOSTNAME_COUNT++ ))
if curl -If --max-time "$MY_TIMEOUT" "$MY_HOSTNAME" &> /dev/null; then
check_downtime "$MY_COMMAND" "$MY_HOSTNAME_STRING" ""
# Check status change
if [[ "$MY_DOWN_TIME" -gt "0" ]]; then
save_history "$MY_COMMAND" "$MY_HOSTNAME_STRING" "" "$MY_DOWN_TIME" "$MY_DATE_TIME"
fi
save_availability "$MY_COMMAND" "$MY_HOSTNAME_STRING" ""
else
check_downtime "$MY_COMMAND" "$MY_HOSTNAME_STRING" ""
save_downtime "$MY_COMMAND" "$MY_HOSTNAME_STRING" "" "$MY_DOWN_TIME"
fi
elif [[ "$MY_COMMAND" = "http-status" ]]; then
(( MY_HOSTNAME_COUNT++))
if [[ $(curl -s -o /dev/null -I --max-time "$MY_TIMEOUT" -w "%{http_code}" "$MY_HOSTNAME" 2>/dev/null) == "$MY_PORT" ]]; then
check_downtime "$MY_COMMAND" "$MY_HOSTNAME_STRING" "$MY_PORT"
# Check status change
if [[ "$MY_DOWN_TIME" -gt "0" ]]; then
save_history "$MY_COMMAND" "$MY_HOSTNAME_STRING" "$MY_PORT" "$MY_DOWN_TIME" "$MY_DATE_TIME"
fi
save_availability "$MY_COMMAND" "$MY_HOSTNAME_STRING" "$MY_PORT"
else
check_downtime "$MY_COMMAND" "$MY_HOSTNAME_STRING" "$MY_PORT"
save_downtime "$MY_COMMAND" "$MY_HOSTNAME_STRING" "$MY_PORT" "$MY_DOWN_TIME"
fi
elif [[ "$MY_COMMAND" = "grep" ]]; then
(( MY_HOSTNAME_COUNT++ ))
if curl --no-buffer -fs --max-time "$MY_TIMEOUT" "$MY_HOSTNAME" | grep -q "$MY_PORT" &> /dev/null; then
check_downtime "$MY_COMMAND" "$MY_HOSTNAME_STRING" "$MY_PORT"
# Check status change
if [[ "$MY_DOWN_TIME" -gt "0" ]]; then
save_history "$MY_COMMAND" "$MY_HOSTNAME_STRING" "$MY_PORT" "$MY_DOWN_TIME" "$MY_DATE_TIME"
fi
save_availability "$MY_COMMAND" "$MY_HOSTNAME_STRING" "$MY_PORT"
else
check_downtime "$MY_COMMAND" "$MY_HOSTNAME_STRING" "$MY_PORT"
save_downtime "$MY_COMMAND" "$MY_HOSTNAME_STRING" "$MY_PORT" "$MY_DOWN_TIME"
fi
elif [[ "$MY_COMMAND" = "traceroute" ]]; then
(( MY_HOSTNAME_COUNT++ ))
MY_PORT=${MY_PORT:=64}
if traceroute -w "$MY_TIMEOUT" -q "$MY_TRACEROUTE_NQUERIES" -m "$MY_PORT" "$MY_TRACEROUTE_HOST" | grep -q "$MY_HOSTNAME" &> /dev/null; then
check_downtime "$MY_COMMAND" "$MY_HOSTNAME_STRING" "$MY_PORT"
# Check status change
if [[ "$MY_DOWN_TIME" -gt "0" ]]; then
save_history "$MY_COMMAND" "$MY_HOSTNAME_STRING" "$MY_PORT" "$MY_DOWN_TIME" "$MY_DATE_TIME"
fi
save_availability "$MY_COMMAND" "$MY_HOSTNAME_STRING" "$MY_PORT"
else
check_downtime "$MY_COMMAND" "$MY_HOSTNAME_STRING" "$MY_PORT"
save_downtime "$MY_COMMAND" "$MY_HOSTNAME_STRING" "$MY_PORT" "$MY_DOWN_TIME"
fi
elif [[ "$MY_COMMAND" = "script" ]]; then
(( MY_HOSTNAME_COUNT++ ))
if [[ -x "$MY_STATUS_CONFIG_DIR/$MY_HOSTNAME" ]]; then
cmd="$MY_STATUS_CONFIG_DIR/$MY_HOSTNAME"
else
cmd="$MY_HOSTNAME"
fi
(timeout --preserve-status "$MY_SCRIPT_TIMEOUT" "$cmd" &> /dev/null)
case "$?" in
"0")
check_downtime "$MY_COMMAND" "$MY_HOSTNAME_STRING" "$MY_PORT"
# Check status change
if [[ "$MY_DOWN_TIME" -gt "0" ]]; then
save_history "$MY_COMMAND" "$MY_HOSTNAME_STRING" "$MY_PORT" "$MY_DOWN_TIME" "$MY_DATE_TIME"
fi
save_availability "$MY_COMMAND" "$MY_HOSTNAME_STRING" "$MY_PORT"
;;
"80")
check_degradetime "$MY_COMMAND" "$MY_HOSTNAME_STRING"
save_degradetime "$MY_COMMAND" "$MY_HOSTNAME_STRING" "$MY_DEGRADE_TIME"
;;
*)
check_downtime "$MY_COMMAND" "$MY_HOSTNAME_STRING" "$MY_PORT"
save_downtime "$MY_COMMAND" "$MY_HOSTNAME_STRING" "$MY_PORT" "$MY_DOWN_TIME"
;;
esac
fi
done <"$MY_HOSTNAME_FILE"
#
# Create status page
#
page_header
MY_ITEMS_JSON=()
# Get outage
MY_OUTAGE_COUNT=0
MY_OUTAGE_ITEMS=()
while IFS=';' read -r MY_DOWN_COMMAND MY_DOWN_HOSTNAME_STRING MY_DOWN_PORT MY_DOWN_TIME || [[ -n "$MY_DOWN_COMMAND" ]]; do
if [[ "$MY_DOWN_COMMAND" = "ping" ]] ||
[[ "$MY_DOWN_COMMAND" = "ping6" ]] ||
[[ "$MY_DOWN_COMMAND" = "nc" ]] ||
[[ "$MY_DOWN_COMMAND" = "curl" ]] ||
[[ "$MY_DOWN_COMMAND" = "http-status" ]] ||
[[ "$MY_DOWN_COMMAND" = "grep" ]] ||
[[ "$MY_DOWN_COMMAND" = "script" ]] ||
[[ "$MY_DOWN_COMMAND" = "traceroute" ]]; then
MY_DOWN_HOSTNAME="${MY_DOWN_HOSTNAME_STRING%%|*}"
MY_DISPLAY_TEXT="${MY_DOWN_HOSTNAME_STRING/${MY_DOWN_HOSTNAME}/}"
MY_DISPLAY_TEXT="${MY_DISPLAY_TEXT:1}"
(( MY_OUTAGE_COUNT++ ))
MY_OUTAGE_ITEMS+=("$(item_down)")
MY_ITEMS_JSON+=("${MY_DISPLAY_TEXT:-${MY_DOWN_HOSTNAME}};$MY_DOWN_COMMAND;Fail;$MY_DOWN_TIME")
fi
done <"$MY_HOSTNAME_STATUS_DOWN"
# Get degrades
MY_DEGRADE_COUNT=0
MY_DEGRADE_ITEMS=()
while IFS=';' read -r MY_DEGRADE_COMMAND MY_DEGRADE_HOSTNAME_STRING MY_DEGRADE_TIME || [[ -n "$MY_DEGRADE_COMMAND" ]]; do
if [[ "$MY_DEGRADE_COMMAND" = "script" ]]; then
MY_DEGRADE_HOSTNAME="${MY_DEGRADE_HOSTNAME_STRING%%|*}"
MY_DISPLAY_TEXT="${MY_DEGRADE_HOSTNAME_STRING/${MY_DEGRADE_HOSTNAME}/}"
MY_DISPLAY_TEXT="${MY_DISPLAY_TEXT:1}"
(( MY_DEGRADE_COUNT++ ))
MY_DEGRADE_ITEMS+=("$(item_degrade)")
MY_ITEMS_JSON+=("${MY_DISPLAY_TEXT:-${MY_DEGRADE_HOSTNAME}};$MY_DEGRADE_COMMAND;Degraded;$MY_DEGRADE_TIME")
fi
done <"$MY_HOSTNAME_STATUS_DEGRADE"
# Get available systems
MY_AVAILABLE_COUNT=0
MY_AVAILABLE_ITEMS=()
while IFS=';' read -r MY_OK_COMMAND MY_OK_HOSTNAME_STRING MY_OK_PORT || [[ -n "$MY_OK_COMMAND" ]]; do
if [[ "$MY_OK_COMMAND" = "ping" ]] ||
[[ "$MY_OK_COMMAND" = "ping6" ]] ||
[[ "$MY_OK_COMMAND" = "nc" ]] ||
[[ "$MY_OK_COMMAND" = "curl" ]] ||
[[ "$MY_OK_COMMAND" = "http-status" ]] ||
[[ "$MY_OK_COMMAND" = "grep" ]] ||
[[ "$MY_OK_COMMAND" = "script" ]] ||
[[ "$MY_OK_COMMAND" = "traceroute" ]]; then
MY_OK_HOSTNAME="${MY_OK_HOSTNAME_STRING%%|*}"
MY_DISPLAY_TEXT="${MY_OK_HOSTNAME_STRING/${MY_OK_HOSTNAME}/}"
MY_DISPLAY_TEXT="${MY_DISPLAY_TEXT:1}"
(( MY_AVAILABLE_COUNT++ ))
MY_AVAILABLE_ITEMS+=("$(item_ok)")