Fixes jilo-cli conferences search to work with new SQL.
parent
4d4d14dbf0
commit
9a0634cfa7
199
jilo-cli
199
jilo-cli
|
@ -40,26 +40,26 @@ MYSQL_DB=${MYSQL_DB:-$DEFAULT_MYSQL_DB}
|
|||
###
|
||||
|
||||
# DB queries
|
||||
db_stats_conferences_all_template="SELECT * FROM conferences;"
|
||||
db_stats_conferences_name_template="SELECT * FROM conferences WHERE conference_name='%s';"
|
||||
db_stats_conferences_id_template="SELECT * FROM conferences WHERE conference_id='%s';"
|
||||
db_conferences_all_template="SELECT * FROM conferences;"
|
||||
|
||||
db_stats_conference_events_template="SELECT * FROM conference_events WHERE conference_id='%s';"
|
||||
db_stats_participant_events_template="SELECT * FROM participant_events WHERE event_param='%s';"
|
||||
db_conferences_id_template="SELECT * FROM conferences WHERE conference_id='%s';"
|
||||
db_conferences_name_template="SELECT * FROM conferences WHERE conference_name='%s';"
|
||||
|
||||
db_stats_conference_by_id_template="
|
||||
SELECT DISTINCT
|
||||
db_participants_id_template="SELECT * FROM participants WHERE endpoint_id='%s';"
|
||||
#db_participants_
|
||||
|
||||
db_conference_events_template="SELECT * FROM conference_events WHERE conference_id='%s';"
|
||||
db_participant_events_template="SELECT * FROM participant_events WHERE participant_id='%s';"
|
||||
|
||||
db_conference_by_id_template="
|
||||
SELECT
|
||||
pe.time,
|
||||
c.conference_id,
|
||||
c.conference_name,
|
||||
c.conference_host,
|
||||
COALESCE(ce.time, pe.time) AS event_time,
|
||||
ce.loglevel AS conference_loglevel,
|
||||
ce.conference_event,
|
||||
ce.conference_param,
|
||||
p.endpoint_id,
|
||||
pe.time AS participant_time,
|
||||
pe.loglevel AS participant_loglevel,
|
||||
pe.loglevel,
|
||||
pe.event_type,
|
||||
p.endpoint_id AS participant_id,
|
||||
pe.event_param
|
||||
FROM
|
||||
conferences c
|
||||
|
@ -71,22 +71,38 @@ LEFT JOIN
|
|||
participant_events pe ON p.endpoint_id = pe.participant_id
|
||||
WHERE
|
||||
c.conference_id = '%s'
|
||||
ORDER BY
|
||||
event_time;"
|
||||
|
||||
db_stats_conference_by_name_template="
|
||||
SELECT DISTINCT
|
||||
UNION
|
||||
|
||||
SELECT
|
||||
ce.time AS event_time,
|
||||
c.conference_id,
|
||||
c.conference_name,
|
||||
c.conference_host,
|
||||
COALESCE(ce.time, pe.time) AS event_time,
|
||||
ce.loglevel AS conference_loglevel,
|
||||
ce.conference_event,
|
||||
ce.conference_param,
|
||||
p.endpoint_id,
|
||||
pe.time AS participant_time,
|
||||
pe.loglevel AS participant_loglevel,
|
||||
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'
|
||||
|
||||
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
|
||||
|
@ -98,17 +114,37 @@ LEFT JOIN
|
|||
participant_events pe ON p.endpoint_id = pe.participant_id
|
||||
WHERE
|
||||
c.conference_name = '%s'
|
||||
|
||||
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'
|
||||
|
||||
ORDER BY
|
||||
event_time;"
|
||||
pe.time;
|
||||
"
|
||||
|
||||
db_stats_conferences_time_template="SELECT * FROM conferences WHERE start >= '%s' AND end <= '%s';"
|
||||
|
||||
db_stats_participants_all_template="SELECT * FROM participants;"
|
||||
db_stats_participants_conference_template="SELECT * FROM participants WHERE conference_id='%s';"
|
||||
db_stats_participants_event_template="SELECT * FROM participants WHERE event_type LIKE '%%%s%%';"
|
||||
db_stats_participants_endpoint_template="SELECT * FROM participants WHERE endpoint_id='%s';"
|
||||
db_stats_participants_statsid_template="SELECT * FROM participants WHERE stats_id LIKE '%%%s%%';"
|
||||
db_stats_participants_ip_template="SELECT * FROM participants WHERE participant_ip='%s';"
|
||||
#db_conferences_time_template="SELECT * FROM conferences WHERE start >= '%s' AND end <= '%s';"
|
||||
#
|
||||
#db_participants_all_template="SELECT * FROM participants;"
|
||||
#db_participants_conference_template="SELECT * FROM participants WHERE conference_id='%s';"
|
||||
#db_participants_event_template="SELECT * FROM participants WHERE event_type LIKE '%%%s%%';"
|
||||
#db_participants_endpoint_template="SELECT * FROM participants WHERE endpoint_id='%s';"
|
||||
#db_participants_statsid_template="SELECT * FROM participants WHERE stats_id LIKE '%%%s%%';"
|
||||
#db_participants_ip_template="SELECT * FROM participants WHERE participant_ip='%s';"
|
||||
|
||||
|
||||
help="Usage:
|
||||
|
@ -291,53 +327,42 @@ case "$cmd" in
|
|||
# the argument to "--conference" can be either ID or name
|
||||
if [[ -n "$conference_arg" ]]; then
|
||||
|
||||
db_stats_conferences_id=$(printf "$db_stats_conferences_id_template" "$conference_arg")
|
||||
stats_conferences_id=$(db_query "$db_stats_conferences_id")
|
||||
db_conferences_id=$(printf "$db_conferences_id_template" "$conference_arg")
|
||||
conferences_id=$(db_query "$db_conferences_id")
|
||||
|
||||
db_stats_conferences_name=$(printf "$db_stats_conferences_name_template" "$conference_arg")
|
||||
stats_conferences_name=$(db_query "$db_stats_conferences_name")
|
||||
db_conferences_name=$(printf "$db_conferences_name_template" "$conference_arg")
|
||||
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 [[ -n "$stats_conferences_id" ]]; then
|
||||
db_stats_conference=$(printf "$db_stats_conference_by_id_template" "$conference_arg")
|
||||
mapfile -t stats_conference_array < <(db_query "$db_stats_conference")
|
||||
|
||||
current_conference=""
|
||||
for row in "${stats_conference_array[@]}"; do
|
||||
IFS='|' read -r conference_id conference_name conference_host conference_time loglevel conference_event conference_param endpoint_id participant_time loglevel event_type event_param <<< "$row"
|
||||
|
||||
if [[ -z "$current_conference" ]]; then
|
||||
current_conference="$conference_name"
|
||||
echo "$conference_time | $conference_id | $conference_name | $conference_host | $loglevel | Conference created"
|
||||
fi
|
||||
|
||||
if [[ -n "$conference_event" ]]; then
|
||||
echo "$participant_time | $conference_id | $conference_name | $conference_host | $loglevel | $endpoint_id | $event_type | $event_param"
|
||||
fi
|
||||
if [[ -n "$conferences_id" ]]; then
|
||||
db_conference=$(printf "$db_conference_by_id_template" "$conference_arg" "$conference_arg")
|
||||
mapfile -t conference_array < <(db_query "$db_conference")
|
||||
# prepare the header
|
||||
output="time\tconf ID\tconf name\tconf host\tloglevel\tparticipant ID\tevent\tparameter\n"
|
||||
# prepare the formatted rows
|
||||
for row in "${conference_array[@]}"; 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$event_param\n"
|
||||
done
|
||||
echo "$conference_time | $conference_id | $conference_name | $conference_host | $loglevel | Conference Ended"
|
||||
# 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 [[ -n "$stats_conferences_name" ]]; then
|
||||
db_stats_conference=$(printf "$db_stats_conference_by_name_template" "$conference_arg")
|
||||
mapfile -t stats_conference_array < <(db_query "$db_stats_conference")
|
||||
elif [[ -n "$conferences_name" ]]; then
|
||||
db_conference=$(printf "$db_conference_by_name_template" "$conference_arg" "$conference_arg")
|
||||
mapfile -t conference_array < <(db_query "$db_conference")
|
||||
|
||||
current_conference=""
|
||||
for row in "${stats_conference_array[@]}"; do
|
||||
IFS='|' read -r conference_id conference_name conference_host conference_time loglevel conference_event conference_param endpoint_id participant_time loglevel event_type event_param <<< "$row"
|
||||
|
||||
if [[ -z "$current_conference" ]]; then
|
||||
current_conference="$conference_name"
|
||||
echo "$conference_time | $conference_id | $conference_name | $conference_host | $loglevel | Conference created"
|
||||
fi
|
||||
|
||||
if [[ -n "$conference_event" ]]; then
|
||||
echo "$participant_time | $conference_id | $conference_name | $conference_host | $loglevel | $endpoint_id | $event_type | $event_param"
|
||||
fi
|
||||
# prepare the header
|
||||
output="time\tconf ID\tconf name\tconf host\tloglevel\tparticipant ID\tevent\tparameter\n"
|
||||
# prepare the formatted rows
|
||||
for row in "${conference_array[@]}"; 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$event_param\n"
|
||||
done
|
||||
echo "$conference_time | $conference_id | $conference_name | $conference_host | $loglevel | Conference Ended"
|
||||
# output
|
||||
echo -e "$output" | column -t -s $'\t'
|
||||
|
||||
# nothing found for neither conference ID or name
|
||||
else
|
||||
|
@ -346,36 +371,36 @@ case "$cmd" in
|
|||
exit 0
|
||||
else
|
||||
# if no argument is given, we show all the conferences
|
||||
db_stats_conferences_all=$(printf "$db_stats_conferences_all_template")
|
||||
db_query "$db_stats_conferences_all"
|
||||
db_conferences_all=$(printf "$db_conferences_all_template")
|
||||
db_query "$db_conferences_all"
|
||||
exit 0
|
||||
fi
|
||||
;;
|
||||
|
||||
--participant)
|
||||
if [[ -n "$participant_arg" ]]; then
|
||||
db_stats_participants_conference=$(printf "$db_stats_participants_conference_template" "$participant_arg")
|
||||
db_query "$db_stats_participants_conference"
|
||||
db_stats_participants_event=$(printf "$db_stats_participants_event_template" "$participant_arg")
|
||||
db_query "$db_stats_participants_event"
|
||||
db_stats_participants_endpoint=$(printf "$db_stats_participants_endpoint_template" "$participant_arg")
|
||||
db_query "$db_stats_participants_endpoint"
|
||||
db_stats_participants_statsid=$(printf "$db_stats_participants_statsid_template" "$participant_arg")
|
||||
db_query "$db_stats_participants_statsid"
|
||||
db_stats_participants_ip=$(printf "$db_stats_participants_ip_template" "$participant_arg")
|
||||
db_query "$db_stats_participants_ip"
|
||||
db_participants_conference=$(printf "$db_participants_conference_template" "$participant_arg")
|
||||
db_query "$db_participants_conference"
|
||||
db_participants_event=$(printf "$db_participants_event_template" "$participant_arg")
|
||||
db_query "$db_participants_event"
|
||||
db_participants_endpoint=$(printf "$db_participants_endpoint_template" "$participant_arg")
|
||||
db_query "$db_participants_endpoint"
|
||||
db_participants_statsid=$(printf "$db_participants_statsid_template" "$participant_arg")
|
||||
db_query "$db_participants_statsid"
|
||||
db_participants_ip=$(printf "$db_participants_ip_template" "$participant_arg")
|
||||
db_query "$db_participants_ip"
|
||||
exit 0
|
||||
else
|
||||
db_stats_participants_all=$(printf "$db_stats_participants_all_template" )
|
||||
db_query "$db_stats_participants_all"
|
||||
db_participants_all=$(printf "$db_participants_all_template" )
|
||||
db_query "$db_participants_all"
|
||||
exit 0
|
||||
fi
|
||||
;;
|
||||
|
||||
--time)
|
||||
if [[ "$time_range_specified" == true ]]; then
|
||||
db_stats_conferences_time=$(printf "$db_stats_conferences_time_template" "$from_time" "$until_time")
|
||||
db_query "$db_stats_conferences_time"
|
||||
db_conferences_time=$(printf "$db_conferences_time_template" "$from_time" "$until_time")
|
||||
db_query "$db_conferences_time"
|
||||
exit 0
|
||||
fi
|
||||
;;
|
||||
|
|
Loading…
Reference in New Issue