Compare commits

...

2 Commits

1 changed files with 163 additions and 30 deletions

193
jilo-cli
View File

@ -40,18 +40,111 @@ MYSQL_DB=${MYSQL_DB:-$DEFAULT_MYSQL_DB}
### ###
# DB queries # DB queries
db_stats_conferences_all_template="SELECT * FROM conferences;" db_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_stats_conferences_time_template="SELECT * FROM conferences WHERE start >= '%s' AND end <= '%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_participants_all_template="SELECT * FROM participants;" db_participants_id_template="SELECT * FROM participants WHERE endpoint_id='%s';"
db_stats_participants_conference_template="SELECT * FROM participants WHERE conference_id='%s';" #db_participants_
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_conference_events_template="SELECT * FROM conference_events WHERE conference_id='%s';"
db_stats_participants_statsid_template="SELECT * FROM participants WHERE stats_id LIKE '%%%s%%';" db_participant_events_template="SELECT * FROM participant_events WHERE participant_id='%s';"
db_stats_participants_ip_template="SELECT * FROM participants WHERE participant_ip='%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';"
help="Usage: help="Usage:
@ -231,43 +324,83 @@ done
case "$cmd" in case "$cmd" in
--conference) --conference)
# the argument to "--conference" can be either ID or name
if [[ -n "$conference_arg" ]]; then if [[ -n "$conference_arg" ]]; then
db_stats_conferences_id=$(printf "$db_stats_conferences_id_template" "$conference_arg")
db_query "$db_stats_conferences_id" db_conferences_id=$(printf "$db_conferences_id_template" "$conference_arg")
db_stats_conferences_name=$(printf "$db_stats_conferences_name_template" "$conference_arg") conferences_id=$(db_query "$db_conferences_id")
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 "$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
exit 0 exit 0
else else
db_stats_conferences_all=$(printf "$db_stats_conferences_all_template") # if no argument is given, we show all the conferences
db_query "$db_stats_conferences_all" db_conferences_all=$(printf "$db_conferences_all_template")
db_query "$db_conferences_all"
exit 0 exit 0
fi fi
;; ;;
--participant) --participant)
if [[ -n "$participant_arg" ]]; then if [[ -n "$participant_arg" ]]; then
db_stats_participants_conference=$(printf "$db_stats_participants_conference_template" "$participant_arg") db_participants_conference=$(printf "$db_participants_conference_template" "$participant_arg")
db_query "$db_stats_participants_conference" db_query "$db_participants_conference"
db_stats_participants_event=$(printf "$db_stats_participants_event_template" "$participant_arg") db_participants_event=$(printf "$db_participants_event_template" "$participant_arg")
db_query "$db_stats_participants_event" db_query "$db_participants_event"
db_stats_participants_endpoint=$(printf "$db_stats_participants_endpoint_template" "$participant_arg") db_participants_endpoint=$(printf "$db_participants_endpoint_template" "$participant_arg")
db_query "$db_stats_participants_endpoint" db_query "$db_participants_endpoint"
db_stats_participants_statsid=$(printf "$db_stats_participants_statsid_template" "$participant_arg") db_participants_statsid=$(printf "$db_participants_statsid_template" "$participant_arg")
db_query "$db_stats_participants_statsid" db_query "$db_participants_statsid"
db_stats_participants_ip=$(printf "$db_stats_participants_ip_template" "$participant_arg") db_participants_ip=$(printf "$db_participants_ip_template" "$participant_arg")
db_query "$db_stats_participants_ip" db_query "$db_participants_ip"
exit 0 exit 0
else else
db_stats_participants_all=$(printf "$db_stats_participants_all_template" ) db_participants_all=$(printf "$db_participants_all_template" )
db_query "$db_stats_participants_all" db_query "$db_participants_all"
exit 0 exit 0
fi fi
;; ;;
--time) --time)
if [[ "$time_range_specified" == true ]]; then if [[ "$time_range_specified" == true ]]; then
db_stats_conferences_time=$(printf "$db_stats_conferences_time_template" "$from_time" "$until_time") db_conferences_time=$(printf "$db_conferences_time_template" "$from_time" "$until_time")
db_query "$db_stats_conferences_time" db_query "$db_conferences_time"
exit 0 exit 0
fi fi
;; ;;