Compare commits

..

No commits in common. "9a0634cfa7f0a7072925b61c4eb4ad43e2b71ae0" and "4fc2223d442726e1c342a42b09c49491caf80252" have entirely different histories.

1 changed files with 30 additions and 163 deletions

193
jilo-cli
View File

@ -40,111 +40,18 @@ MYSQL_DB=${MYSQL_DB:-$DEFAULT_MYSQL_DB}
###
# DB queries
db_conferences_all_template="SELECT * FROM conferences;"
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_id_template="SELECT * FROM conferences WHERE conference_id='%s';"
db_conferences_name_template="SELECT * FROM conferences WHERE conference_name='%s';"
db_stats_conferences_time_template="SELECT * FROM conferences WHERE start >= '%s' AND end <= '%s';"
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,
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'
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'
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'
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
pe.time;
"
#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';"
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';"
help="Usage:
@ -324,83 +231,43 @@ done
case "$cmd" in
--conference)
# the argument to "--conference" can be either ID or name
if [[ -n "$conference_arg" ]]; then
db_conferences_id=$(printf "$db_conferences_id_template" "$conference_arg")
conferences_id=$(db_query "$db_conferences_id")
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 "$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
# 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 "$conferences_name" ]]; then
db_conference=$(printf "$db_conference_by_name_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
# output
echo -e "$output" | column -t -s $'\t'
# nothing found for neither conference ID or name
else
echo "No match found for \"$conference_arg\""
fi
db_stats_conferences_id=$(printf "$db_stats_conferences_id_template" "$conference_arg")
db_query "$db_stats_conferences_id"
db_stats_conferences_name=$(printf "$db_stats_conferences_name_template" "$conference_arg")
db_query "$db_stats_conferences_name"
exit 0
else
# if no argument is given, we show all the conferences
db_conferences_all=$(printf "$db_conferences_all_template")
db_query "$db_conferences_all"
db_stats_conferences_all=$(printf "$db_stats_conferences_all_template")
db_query "$db_stats_conferences_all"
exit 0
fi
;;
--participant)
if [[ -n "$participant_arg" ]]; then
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"
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"
exit 0
else
db_participants_all=$(printf "$db_participants_all_template" )
db_query "$db_participants_all"
db_stats_participants_all=$(printf "$db_stats_participants_all_template" )
db_query "$db_stats_participants_all"
exit 0
fi
;;
--time)
if [[ "$time_range_specified" == true ]]; then
db_conferences_time=$(printf "$db_conferences_time_template" "$from_time" "$until_time")
db_query "$db_conferences_time"
db_stats_conferences_time=$(printf "$db_stats_conferences_time_template" "$from_time" "$until_time")
db_query "$db_stats_conferences_time"
exit 0
fi
;;