-
Notifications
You must be signed in to change notification settings - Fork 0
/
jilo-cli
executable file
·1095 lines (980 loc) · 36.4 KB
/
jilo-cli
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
###
# JItsi Log Observer - command line interface
#
# Bash script for Jitsi Meet components (Videobridge, Jicofo, etc.) logs parsing
# Command line interface (jilo-cli)
###
VERSION="0.1.1"
RELEASE_DATE="2024-06-18"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" #"
### Configuration file (overrides default configs)
CONFIG_FILE="$SCRIPT_DIR/jilo.conf"
### Default configuration
# Default database type (sqlite, mysql|mariadb)
DEFAULT_DB_TYPE="sqlite"
# Default SQLite database file
DEFAULT_DB="$SCRIPT_DIR/jilo.db"
# Default MySQL/MariaDB configuration
DEFAULT_MYSQL_HOST="localhost"
DEFAULT_MYSQL_USER="jilo"
DEFAULT_MYSQL_PASS="jilopass"
DEFAULT_MYSQL_DB="jilo_db"
DEFAULT_NORMAL_TEXT="\033[0m"
DEFAULT_IMPORTANT_TEXT="\033[1m"
# Load configurations from the config file if it exists
if [[ -f "$CONFIG_FILE" ]]; then
source "$CONFIG_FILE"
fi
# use default values if not overriden by config file
DB=${DB:-$DEFAULT_DB}
DB_TYPE=${DB_TYPE:-$DEFAULT_DB_TYPE}
MYSQL_HOST=${MYSQL_HOST:-$DEFAULT_MYSQL_HOST}
MYSQL_USER=${MYSQL_USER:-$DEFAULT_MYSQL_USER}
MYSQL_PASS=${MYSQL_PASS:-$DEFAULT_MYSQL_PASS}
MYSQL_DB=${MYSQL_DB:-$DEFAULT_MYSQL_DB}
NORMAL_TEXT=${NORMAL_TEXT:-$DEFAULT_NORMAL_TEXT}
IMPORTANT_TEXT=${IMPORTANT_TEXT:-$DEFAULT_IMPORTANT_TEXT}
### DB queries
## conference related
db_conferences_all_formatted_template="
SELECT DISTINCT
c.jitsi_component,
(SELECT ce.time
FROM conference_events ce
WHERE
ce.conference_id = c.conference_id
AND
ce.conference_event = 'conference created')
AS start,
(SELECT ce.time
FROM conference_events ce
WHERE
ce.conference_id = c.conference_id
AND
ce.conference_event = 'conference expired')
AS end,
c.conference_id,
c.conference_name,
(SELECT COUNT(pe.participant_id)
FROM participant_events pe
WHERE
pe.event_type = 'participant joining'
AND
pe.event_param = c.conference_id)
AS participants,
name_counts.name_count,
c.conference_host
FROM
conferences c
JOIN (
SELECT
conference_name,
COUNT(*) AS name_count
FROM
conferences
GROUP BY
conference_name
) AS name_counts ON c.conference_name = name_counts.conference_name
JOIN
conference_events ce ON c.conference_id = ce.conference_id
WHERE (ce.time >= '%s 00:00:00' AND ce.time <= '%s 23:59:59')
ORDER BY
c.id;"
db_conference_by_id_template="
SELECT
pe.time,
c.conference_id,
c.conference_name,
c.conference_host,
pe.loglevel,
pe.event_type,
p.endpoint_id AS participant_id,
pe.event_param
FROM
conferences c
LEFT JOIN
conference_events ce ON c.conference_id = ce.conference_id
LEFT JOIN
participants p ON c.conference_id = p.conference_id
LEFT JOIN
participant_events pe ON p.endpoint_id = pe.participant_id
WHERE
c.conference_id = '%s'
AND (pe.time >= '%s 00:00:00' AND pe.time <= '%s 23:59:59')
UNION
SELECT
ce.time AS event_time,
c.conference_id,
c.conference_name,
c.conference_host,
ce.loglevel,
ce.conference_event AS event_type,
NULL AS participant_id,
ce.conference_param AS event_param
FROM
conferences c
LEFT JOIN
conference_events ce ON c.conference_id = ce.conference_id
WHERE
c.conference_id = '%s'
AND (event_time >= '%s 00:00:00' AND event_time <= '%s 23:59:59')
ORDER BY
pe.time;"
db_conference_by_name_template="
SELECT
pe.time,
c.conference_id,
c.conference_name,
c.conference_host,
pe.loglevel,
pe.event_type,
p.endpoint_id AS participant_id,
pe.event_param
FROM
conferences c
LEFT JOIN
conference_events ce ON c.conference_id = ce.conference_id
LEFT JOIN
participants p ON c.conference_id = p.conference_id
LEFT JOIN
participant_events pe ON p.endpoint_id = pe.participant_id
WHERE
c.conference_name = '%s'
AND (pe.time >= '%s 00:00:00' AND pe.time <= '%s 23:59:59')
UNION
SELECT
ce.time AS event_time,
c.conference_id,
c.conference_name,
c.conference_host,
ce.loglevel,
ce.conference_event AS event_type,
NULL AS participant_id,
ce.conference_param AS event_param
FROM
conferences c
LEFT JOIN
conference_events ce ON c.conference_id = ce.conference_id
WHERE
c.conference_name = '%s'
AND (event_time >= '%s 00:00:00' AND event_time <= '%s 23:59:59')
ORDER BY
pe.time;"
## participant related
db_participants_all_template="
SELECT DISTINCT
p.jitsi_component, p.endpoint_id, p.conference_id
FROM
participants p
JOIN
participant_events pe ON p.endpoint_id = pe.participant_id
WHERE
pe.time >= '%s 00:00:00' AND pe.time <= '%s 23:59:59'
ORDER BY p.id;"
db_conference_by_participant_id_template="
SELECT
pe.time,
c.conference_id,
c.conference_name,
c.conference_host,
pe.loglevel,
pe.event_type,
p.endpoint_id AS participant_id,
pe.event_param
FROM
conferences c
LEFT JOIN
conference_events ce ON c.conference_id = ce.conference_id
LEFT JOIN
participants p ON c.conference_id = p.conference_id
LEFT JOIN
participant_events pe ON p.endpoint_id = pe.participant_id
WHERE
p.endpoint_id = '%s'
AND (pe.time >= '%s 00:00:00' AND pe.time <= '%s 23:59:59')
UNION
SELECT
ce.time AS event_time,
c.conference_id,
c.conference_name,
c.conference_host,
ce.loglevel,
ce.conference_event AS event_type,
NULL AS participant_id,
ce.conference_param AS event_param
FROM
conferences c
LEFT JOIN
conference_events ce ON c.conference_id = ce.conference_id
WHERE
participant_id = '%s'
AND (event_time >= '%s 00:00:00' AND event_time <= '%s 23:59:59')
ORDER BY
pe.time;"
db_participant_by_conference_id_template="
SELECT
pe.time,
c.conference_id,
c.conference_name,
c.conference_host,
pe.loglevel,
pe.event_type,
p.endpoint_id AS participant_id,
pe.event_param
FROM
conferences c
LEFT JOIN
conference_events ce ON c.conference_id = ce.conference_id
LEFT JOIN
participants p ON c.conference_id = p.conference_id
LEFT JOIN
participant_events pe ON p.endpoint_id = pe.participant_id
WHERE
c.conference_id = '%s'
AND (pe.time >= '%s 00:00:00' AND pe.time <= '%s 23:59:59')
UNION
SELECT
ce.time AS event_time,
c.conference_id,
c.conference_name,
c.conference_host,
ce.loglevel,
ce.conference_event AS event_type,
NULL AS participant_id,
ce.conference_param AS event_param
FROM
conferences c
LEFT JOIN
conference_events ce ON c.conference_id = ce.conference_id
WHERE
ce.conference_id = '%s'
AND (event_time >= '%s 00:00:00' AND event_time <= '%s 23:59:59')
ORDER BY
pe.time;"
db_participant_by_conference_name_template="
SELECT
pe.time,
c.conference_id,
c.conference_name,
c.conference_host,
pe.loglevel,
pe.event_type,
p.endpoint_id AS participant_id,
pe.event_param
FROM
conferences c
LEFT JOIN
conference_events ce ON c.conference_id = ce.conference_id
LEFT JOIN
participants p ON c.conference_id = p.conference_id
LEFT JOIN
participant_events pe ON p.endpoint_id = pe.participant_id
WHERE
c.conference_name LIKE '%%%s%%'
AND (pe.time >= '%s 00:00:00' AND pe.time <= '%s 23:59:59')
UNION
SELECT
ce.time AS event_time,
c.conference_id,
c.conference_name,
c.conference_host,
ce.loglevel,
ce.conference_event AS event_type,
NULL AS participant_id,
ce.conference_param AS event_param
FROM
conferences c
LEFT JOIN
conference_events ce ON c.conference_id = ce.conference_id
WHERE c.conference_name LIKE '%%%s%%'
AND (event_time >= '%s 00:00:00' AND event_time <= '%s 23:59:59')
ORDER BY
pe.time;"
db_participant_by_stats_id_template="
SELECT
pe.time,
c.conference_id,
c.conference_name,
c.conference_host,
pe.loglevel,
pe.event_type,
p.endpoint_id AS participant_id,
pe.event_param
FROM
conferences c
LEFT JOIN
conference_events ce ON c.conference_id = ce.conference_id
LEFT JOIN
participants p ON c.conference_id = p.conference_id
LEFT JOIN
participant_events pe ON p.endpoint_id = pe.participant_id
WHERE
pe.event_type = 'stats_id' AND pe.event_param LIKE '%%%s%%'
AND (pe.time >= '%s 00:00:00' AND pe.time <= '%s 23:59:59')
UNION
SELECT
ce.time AS event_time,
c.conference_id,
c.conference_name,
c.conference_host,
ce.loglevel,
ce.conference_event AS event_type,
NULL AS participant_id,
ce.conference_param AS event_param
FROM
conferences c
LEFT JOIN
conference_events ce ON c.conference_id = ce.conference_id
WHERE
event_type = 'stats_id' AND event_param LIKE '%%%s%%'
AND (event_time >= '%s 00:00:00' AND event_time <= '%s 23:59:59')
ORDER BY
pe.time;"
db_participant_by_ip_template="
SELECT
pe.time,
c.conference_id,
c.conference_name,
c.conference_host,
pe.loglevel,
pe.event_type,
p.endpoint_id AS participant_id,
pe.event_param
FROM
conferences c
LEFT JOIN
conference_events ce ON c.conference_id = ce.conference_id
LEFT JOIN
participants p ON c.conference_id = p.conference_id
LEFT JOIN
participant_events pe ON p.endpoint_id = pe.participant_id
WHERE
pe.event_type = 'pair selected' AND pe.event_param = '%s'
AND (pe.time >= '%s 00:00:00' AND pe.time <= '%s 23:59:59')
UNION
SELECT
ce.time AS event_time,
c.conference_id,
c.conference_name,
c.conference_host,
ce.loglevel,
ce.conference_event AS event_type,
NULL AS participant_id,
ce.conference_param AS event_param
FROM
conferences c
LEFT JOIN
conference_events ce ON c.conference_id = ce.conference_id
WHERE
event_type = 'pair selected' AND event_param = '%s'
AND (event_time >= '%s 00:00:00' AND event_time <= '%s 23:59:59')
ORDER BY
pe.time;"
## jitsi component related
# we use "jitsi_component = %s" (without quotes)
# to re-use the query for all components ("jitsi_component = jitsi_component")
# for specific component the single quotes are added upon loading the template
db_jitsi_components_template="
SELECT jitsi_component, loglevel, time, component_id, event_type, event_param
FROM
jitsi_components
WHERE
jitsi_component = %s
AND
component_id = %s
AND
(time >= '%s 00:00:00' AND time <= '%s 23:59:59')
ORDER BY
time;"
## time period related
db_events_by_period_template="
SELECT
pe.time,
c.conference_id,
c.conference_name,
c.conference_host,
pe.loglevel,
pe.event_type,
p.endpoint_id AS participant_id,
pe.event_param
FROM
conferences c
LEFT JOIN
conference_events ce ON c.conference_id = ce.conference_id
LEFT JOIN
participants p ON c.conference_id = p.conference_id
LEFT JOIN
participant_events pe ON p.endpoint_id = pe.participant_id
WHERE
pe.time >= '%s 00:00:00' AND pe.time <= '%s 23:59:59'
UNION
SELECT
ce.time AS event_time,
c.conference_id,
c.conference_name,
c.conference_host,
ce.loglevel,
ce.conference_event AS event_type,
NULL AS participant_id,
ce.conference_param AS event_param
FROM
conferences c
LEFT JOIN
conference_events ce ON c.conference_id = ce.conference_id
WHERE
event_time >= '%s 00:00:00' AND event_time <= '%s 23:59:59'
ORDER BY
pe.time;"
help="Usage:
$0 [OPTION]
Options:
--conference|-c [conference ID or name] - show specific conference(s), all of empty
--participant|-p [participant endpoint ID, conference ID, conference name, participant IP, or participant stats ID] - show specific participant(s), all if empty
--jitsi-component|-j [jvb|jicofo] - show service level events
--time|-t - show stats for a time interval; can be use separately ot together with -c, -p, or -j
--verbose|-v - show more details, when available
--silent|-s - show less details, more suitable for scripting
--help|-h - show this help message
--version|-V - show version"
version="JILO Jitsi Logs Observer command line client
jilo-cli_${VERSION}_${RELEASE_DATE}
version $VERSION
released on $RELEASE_DATE"
time_formats="Expected formats:
- exact times
YYYY-MM-DD, YYYY-MM, YYYY
- exact periods
YYYY-MM-DD:YYYY-MM-DD, YYYY-MM:YYYY-MM, YYYY:YYYY
- from begining to given time
:YYYY-MM-DD, :YYYY-MM, :YYYY
- from given time until end
YYYY-MM-DD:, YYYY-MM:, YYYY:"
###
# First we check for requirements
check_requirements() {
# required programs, anything non-bash - edit as needed
# deb packages - sqlite3, util-linux (column)
local required_programs=("sqlite3" "column")
local requirements_missing=''
for program in "${required_programs[@]}"; do
if ! command -v "$program" &> /dev/null; then
requirements_missing+="$program, "
fi
done
if [[ "$requirements_missing" != '' ]]; then
requirements_missing=${requirements_missing::-2}
echo "Error: $requirements_missing - not found. Please install to proceed."
exit 1
fi
}
check_requirements
###
# DB functions for Sqlite3 and for MySQL/MariaDB
# execute a query and return the result
db_query() {
local query=$1
if [[ "$DB_TYPE" == "sqlite" ]]; then
sqlite3 "$DB" "$query"
elif [[ "$DB_TYPE" == "mysql" || "$DB_TYPE" == "mariadb" ]]; then
mysql -h "$MYSQL_HOST" -u "$MYSQL_USER" -p "$MYSQL_PASS" -D "$MYSQL_DB" -se "$query"
else
echo "Error: unknown database type $DB_TYPE."
exit 1
fi
}
### input parameters parsing
# time parameters
parse_time_range() {
local time_range="$1"
## exact times
# exact date given (YYYY-MM-DD)
if [[ "$time_range" =~ ^([0-9]{4})-([0-9]{2})-([0-9]{2})$ ]]; then
from_time="${BASH_REMATCH[0]}"
until_time="${BASH_REMATCH[0]}"
# exact month given (YYYY-MM)
elif [[ "$time_range" =~ ^([0-9]{4})-([0-9]{2})$ ]]; then
from_time="${BASH_REMATCH[0]}-01"
until_time="${BASH_REMATCH[0]}-31"
# exact year given (YYYY)
elif [[ "$time_range" =~ ^([0-9]{4})$ ]]; then
from_time="${BASH_REMATCH[0]}-01-01"
until_time="${BASH_REMATCH[0]}-12-31"
## exact periods
# from date to date
elif [[ "$time_range" =~ ^([0-9]{4})-([0-9]{2})-([0-9]{2}):([0-9]{4})-([0-9]{2})-([0-9]{2})$ ]]; then
from_time="${BASH_REMATCH[1]}-${BASH_REMATCH[2]}-${BASH_REMATCH[3]}"
until_time="${BASH_REMATCH[4]}-${BASH_REMATCH[5]}-${BASH_REMATCH[6]}"
# from month to month
elif [[ "$time_range" =~ ^([0-9]{4})-([0-9]{2}):([0-9]{4})-([0-9]{2})$ ]]; then
from_time="${BASH_REMATCH[1]}-${BASH_REMATCH[2]}-01"
until_time="${BASH_REMATCH[3]}-${BASH_REMATCH[4]}-31"
# from year to year
elif [[ "$time_range" =~ ^([0-9]{4}):([0-9]{4})$ ]]; then
from_time="${BASH_REMATCH[1]}-01-01"
until_time="${BASH_REMATCH[2]}-12-31"
## only end time given
# from begining until date (:YYYY-MM-DD)
elif [[ "$time_range" =~ ^:([0-9]{4})-([0-9]{2})-([0-9]{2})$ ]]; then
from_time="0000-01-01"
until_time="${BASH_REMATCH[1]}-${BASH_REMATCH[2]}-${BASH_REMATCH[3]}"
# from begining until month (:YYYY-MM)
elif [[ "$time_range" =~ ^:([0-9]{4})-([0-9]{2})$ ]]; then
from_time="0000-01-01"
until_time="${BASH_REMATCH[1]}-${BASH_REMATCH[2]}-31"
# from begining until year (:YYYY)
elif [[ "$time_range" =~ ^:([0-9]{4})$ ]]; then
from_time="0000-01-01"
until_time="${BASH_REMATCH[0]}-12-31"
## only start time given
# from date until end (YYYY-MM-DD:)
elif [[ "$time_range" =~ ^([0-9]{4})-([0-9]{2})-([0-9]{2}):$ ]]; then
from_time="${BASH_REMATCH[1]}-${BASH_REMATCH[2]}-${BASH_REMATCH[3]}"
until_time="9999-12-31"
# from month until end (YYYY-MM:)
elif [[ "$time_range" =~ ^([0-9]{4})-([0-9]{2}):$ ]]; then
from_time="${BASH_REMATCH[1]}-${BASH_REMATCH[2]}-01"
until_time="9999-12-31"
# from year until end (YYYY:)
elif [[ "$time_range" =~ ^([0-9]{4}):$ ]]; then
from_time="${BASH_REMATCH[1]}-01-01"
until_time="9999-12-31"
else
echo -e "Invalid time range. $time_formats" >&2
exit 1
fi
time_range_specified=true
}
# we have two timestamps in format YYYY-MM-DD HH:MM:SS.sss
# calculate and return the durtion in format HH:MM:SS
calculate_duration() {
start=$(date -d "$1" +"%s")
end=$(date -d "$2" +"%s")
duration_seconds=$((end - start))
hours=$((duration_seconds / 3600))
duration_seconds_remain=$((duration_seconds % 3600))
minutes=$((duration_seconds_remain / 60))
seconds=$((duration_seconds_remain % 60))
# add leading zeroes
duration=$(printf "%02d:%02d:%02d" $hours $minutes $seconds)
}
### commandline options
conference_arg=""
conference_option=false
participant_arg=""
participant_option=false
component_arg=""
component_option=false
from_time="0000-00-00"
until_time="9999-12-31"
time_option=false
time_range_specified=false
# display help if no arguments
if [[ $# -eq 0 ]]; then
echo -e "$help"
exit 0
fi
# then check all the options
while [[ $# -gt 0 ]]; do
case "$1" in
-c | --conference )
conference_option=true
if [[ -n "$2" && "$2" != -* ]]; then
conference_arg="$2"
shift 2
else
shift
fi
;;
-p | --participant)
participant_option=true
if [[ -n "$2" && "$2" != -* ]]; then
participant_arg="$2"
shift 2
else
shift
fi
;;
-j | --jitsi-component)
component_option=true
if [[ -n "$2" && "$2" != -* ]]; then
component_arg="$2"
shift 2
if [[ -n "$1" && "$1" != -* ]]; then
component_id="$1"
shift
fi
else
shift
fi
;;
-t | --time)
time_option=true
if [[ -n "$2" && "$2" != -* ]]; then
parse_time_range "$2"
shift 2
else
echo "Option -t needs a time range argument. $time_formats" >&2
exit 1
fi
;;
-v | --verbose)
verbose=true
shift
;;
-s | --silent)
silent=true
shift
;;
-h | --help)
echo -e "$help"
exit 0
;;
-V | --version)
echo -e "$version"
exit 0
;;
*)
echo "Invalid option: $1" >&2
echo -e "$help"
exit 1
;;
esac
done
if [[ "$conference_option" == true ]]; then
# the argument to "--conference" can be either ID or name
if [[ -n "$conference_arg" ]]; then
# check for conferences match within a time period (or all if not period given)
db_conferences_id=$(printf "$db_conference_by_id_template" "$conference_arg" "$from_time" "$until_time" "$conference_arg" "$from_time" "$until_time")
mapfile -t conferences_id < <(db_query "$db_conferences_id")
db_conferences_name=$(printf "$db_conference_by_name_template" "$conference_arg" "$from_time" "$until_time" "$conference_arg" "$from_time" "$until_time")
mapfile -t conferences_name < <(db_query "$db_conferences_name")
# we check if the argument to "--conference" is a conference ID
# conference ID is unique, so we show that conference
if [[ "${#conferences_id[@]}" -gt 0 ]]; then
output=""
# prepare the header
if [[ "$silent" != true ]]; then
header="\nConferences with ID matching \"$IMPORTANT_TEXT$conference_arg$NORMAL_TEXT\""
if [[ "$time_range_specified" == true ]]; then
header+=" for the time period \"$from_time - $until_time\""
fi
header+="\n"
echo -e "$header"
output="time\tconference ID\tconference name\tconference host\tloglevel\tparticipant ID\tevent\tparameter\n"
fi
# prepare the formatted rows
for row in "${conferences_id[@]}"; do
IFS='|' read -r time conference_id conference_name conference_host loglevel event_type participant_id event_param <<< "$row"
output+="$time\t$IMPORTANT_TEXT$conference_id$NORMAL_TEXT\t$conference_name\t$conference_host\t$loglevel\t$participant_id\t$event_type\t$event_param\n"
done
# output
echo -e "$output" | column -t -s $'\t'
# then we check if the argument to "--conference" is a conference name
# if so, we show all matching conferences (conference names are not unique)
elif [[ "${#conferences_name[@]}" -gt 0 ]]; then
output=""
# prepare the header
if [[ "$silent" != true ]]; then
header="\nConferences with names matching \"$IMPORTANT_TEXT$conference_arg$NORMAL_TEXT\""
if [[ "$time_range_specified" == true ]]; then
header+=" for the time period \"$from_time - $until_time\""
fi
header+="\n"
echo -e "$header"
output="time\tconf ID\tconf name\tconf host\tloglevel\tparticipant ID\tevent\tparameter\n"
fi
# prepare the formatted rows
for row in "${conferences_name[@]}"; do
IFS='|' read -r time conference_id conference_name conference_host loglevel event_type participant_id event_param <<< "$row"
output+="$time\t$conference_id\t$IMPORTANT_TEXT$conference_name$NORMAL_TEXT\t$conference_host\t$loglevel\t$participant_id\t$event_type\t$event_param\n"
done
# output
echo -e "$output" | column -t -s $'\t'
# nothing found for neither conference ID or name
else
if [[ "$silent" != true ]]; then
echo "No match found for \"$conference_arg\""
if [[ "$time_range_specified" == true ]]; then
echo "and time period $from_time - $until_time"
fi
fi
fi
exit 0
else
# if no argument is given, we show all the conferences
db_conferences_all=$(printf "$db_conferences_all_formatted_template" "$from_time" "$until_time")
mapfile -t conference_array < <(db_query "$db_conferences_all")
# we only format the outrput if there are conferences to show
if [[ "${#conference_array[@]}" -gt 0 ]]; then
output=""
# prepare the header
if [[ "$silent" != true ]]; then
header="\nAll conferences"
if [[ "$time_range_specified" == true ]]; then
header+=" for the time period \"$IMPORTANT_TEXT$from_time - $until_time$NORMAL_TEXT\""
fi
header+="\n"
echo -e "$header"
output="component\tduration\tconference ID\tconference name\tparticipants\tname count\tconference host\n"
fi
# prepare the formatted rows
for row in "${conference_array[@]}"; do
IFS='|' read -r jitsi_component start end conference_id conference_name participants name_count conference_host <<< "$row"
calculate_duration "$start" "$end"
output+="$jitsi_component\t$duration\t$conference_id\t$conference_name\t$participants\t$name_count\t$conference_host\n"
done
# output
echo -e "$output" | column -t -s $'\t'
else
if [[ "$silent" != true ]]; then
echo -n "No conferences found"
if [[ "$time_range_specified" == true ]]; then
echo -n " for the time period \"$from_time - $until_time\""
fi
echo "."
fi
fi
exit 0
fi
elif [[ "$participant_option" == true ]]; then
# the argument to "--participant" can be endpointID, conferenceID, conference name, startsID, IP address
# check for participants match within a time period (or all if period not given)
# we check for all ot them and show the matches
## FIXME - we don't catch the case with no results found at all, no message is displayed if no results ## FIXME
if [[ -n "$participant_arg" ]]; then
db_participants_endpoint=$(printf "$db_conference_by_participant_id_template" "$participant_arg" "$from_time" "$until_time" "$participant_arg" "$from_time" "$until_time")
mapfile -t participants_endpoint < <(db_query "$db_participants_endpoint")
db_participants_conference=$(printf "$db_participant_by_conference_id_template" "$participant_arg" "$from_time" "$until_time" "$participant_arg" "$from_time" "$until_time")
mapfile -t participants_conference < <(db_query "$db_participants_conference")
db_participants_conference_name=$(printf "$db_participant_by_conference_name_template" "$participant_arg" "$from_time" "$until_time" "$participant_arg" "$from_time" "$until_time")
mapfile -t participants_conference_name < <(db_query "$db_participants_conference_name")
db_participants_statsid=$(printf "$db_participant_by_stats_id_template" "$participant_arg" "$from_time" "$until_time" "$participant_arg" "$from_time" "$until_time")
mapfile -t participants_statsid < <(db_query "$db_participants_statsid")
db_participants_ip=$(printf "$db_participant_by_ip_template" "$participant_arg" "$from_time" "$until_time" "$participant_arg" "$from_time" "$until_time")
mapfile -t participants_ip < <(db_query "$db_participants_ip")
# match for participant endpoint_id
if [[ "${#participants_endpoint[@]}" -gt 0 ]]; then
output=""
# prepare the header
if [[ "$silent" != true ]]; then
header="\nParticipants with ID matching \"$IMPORTANT_TEXT$participant_arg$NORMAL_TEXT\""
if [[ "$time_range_specified" == true ]]; then
header+=" for the time period \"$from_time - $until_time\""
fi
header+="\n"
echo -e "$header"
output="time\tconference ID\tconference name\tconference host\tloglevel\tparticipant ID\tevent\tparameter\n"
fi
# prepare the formatted rows
for row in "${participants_endpoint[@]}"; do
IFS='|' read -r time conference_id conference_name conference_host loglevel event_type participant_id event_param <<< "$row"
output+="$time\t$conference_id\t$conference_name\t$conference_host\t$loglevel\t$IMPORTANT_TEXT$participant_id$NORMAL_TEXT\t$event_type\t$event_param\n"
done
# output
echo -e "$output" | column -t -s $'\t'
fi
# match for conference_id the participant was in
if [[ "${#participants_conference[@]}" -gt 0 ]]; then
output=""
# prepare the header
if [[ "$silent" != true ]]; then
header="\nParticipants in conferences with ID matching \"$IMPORTANT_TEXT$participant_arg$NORMAL_TEXT\""
if [[ "$time_range_specified" == true ]]; then
header+=" for the time period \"$from_time - $until_time\""
fi
header+="\n"
echo -e "$header"
output+="time\tconference ID\tconference name\tconference host\tloglevel\tparticipant ID\tevent\tparameter\n"
fi
# prepare the formatted rows
for row in "${participants_conference[@]}"; do
IFS='|' read -r time conference_id conference_name conference_host loglevel event_type participant_id event_param <<< "$row"
output+="$time\t$IMPORTANT_TEXT$conference_id$NORMAL_TEXT\t$conference_name\t$conference_host\t$loglevel\t$participant_id\t$event_type\t$event_param\n"
done
# output
echo -e "$output" | column -t -s $'\t'
fi
# match for conference_name the participant was in
if [[ "${#participants_conference_name[@]}" -gt 0 ]]; then
output=""
# prepare the header
if [[ "$silent" != true ]]; then
header="\nParticipants in conferences with name that include the string \"$IMPORTANT_TEXT$participant_arg$NORMAL_TEXT\""
if [[ "$time_range_specified" == true ]]; then
header+=" for the time period \"$from_time - $until_time\""
fi
header+="\n"
echo -e "$header"
output+="time\tconference ID\tconference name\tconference host\tloglevel\tparticipant ID\tevent\tparameter\n"
fi
# prepare the formatted rows
for row in "${participants_conference_name[@]}"; do
IFS='|' read -r time conference_id conference_name conference_host loglevel event_type participant_id event_param <<< "$row"
output+="$time\t$conference_id\t$IMPORTANT_TEXT$conference_name$NORMAL_TEXT\t$conference_host\t$loglevel\t$participant_id\t$event_type\t$event_param\n"
done
# output
echo -e "$output" | column -t -s $'\t'
fi
# match for participant stats_id
if [[ "${#participants_statsid[@]}" -gt 0 ]]; then
output=""
# prepare the header
if [[ "$silent" != true ]]; then
header="\nParticipants with stats ID that include the string \"$IMPORTANT_TEXT$participant_arg$NORMAL_TEXT\""
if [[ "$time_range_specified" == true ]]; then
header+=" for the time period \"$from_time - $until_time\""
fi
header+="\n"
echo -e "$header"
output+="time\tconference ID\tconference name\tconference host\tloglevel\tparticipant ID\tevent\tparameter\n"
fi
# prepare the formatted rows
for row in "${participants_statsid[@]}"; do
IFS='|' read -r time conference_id conference_name conference_host loglevel event_type participant_id event_param <<< "$row"
output+="$time\t$conference_id\t$conference_name\t$conference_host\t$loglevel\t$participant_id\t$event_type\t$IMPORTANT_TEXT$event_param$NORMAL_TEXT\n"
done
# output
echo -e "$output" | column -t -s $'\t'
fi
# match for participant IP
if [[ "${#participants_ip[@]}" -gt 0 ]]; then
output=""
# prepare the header
if [[ "$silent" != true ]]; then
header="\nParticipants with IP address matching \"$IMPORTANT_TEXT$participant_arg$NORMAL_TEXT\""
if [[ "$time_range_specified" == true ]]; then
header+=" for the time period \"$from_time - $until_time\""
fi
header+="\n"
echo -e "$header"
output+="time\tconference ID\tconference name\tconference host\tloglevel\tparticipant ID\tevent\tparameter\n"
fi
# prepare the formatted rows
for row in "${participants_ip[@]}"; do
IFS='|' read -r time conference_id conference_name conference_host loglevel event_type participant_id event_param <<< "$row"
output+="$time\t$conference_id\t$conference_name\t$conference_host\t$loglevel\t$participant_id\t$event_type\t$IMPORTANT_TEXT$event_param$NORMAL_TEXT\n"
done
# output
echo -e "$output" | column -t -s $'\t'
fi
exit 0
else
# if no argument is given, we show all the participants
db_participants_all=$(printf "$db_participants_all_template" "$from_time" "$until_time")
mapfile -t participant_array < <(db_query "$db_participants_all")
# we only format the outrput if there are conferences to show
if [[ "${#participant_array[@]}" -gt 0 ]]; then
output=""
# prepare the header
if [[ "$silent" != true ]]; then
header="\nAll participants"
if [[ "$time_range_specified" == true ]]; then
header+=" for the time period \"$IMPORTANT_TEXT$from_time - $until_time$NORMAL_TEXT\""
fi
header+="\n"
echo -e "$header"
output+="component\tparticipant ID\tconference ID\n"
fi
# prepare the formatted rows
for row in "${participant_array[@]}"; do
IFS='|' read -r jitsi_component endpoint_id conference_id <<< "$row"
output+="$jitsi_component\t$endpoint_id\t$conference_id\n"
done
# output
echo -e "$output" | column -t -s $'\t'
else
if [[ "$silent" != true ]]; then
echo -n "No participants found"
if [[ "$time_range_specified" == true ]]; then
echo -n " for the time period \"$from_time - $until_time\""
fi
echo "."
fi
fi
exit 0