Prepares everything for combining JVB and JICOFO parsing.

main
Yasen Pramatarov 2024-05-27 18:51:48 +03:00
parent 221782a255
commit 3b36033be6
3 changed files with 135 additions and 63 deletions

View File

@ -1,4 +1,5 @@
# jilo.conf - configuration variables for JItso Log Observer # jilo.conf - configuration variables for JItso Log Observer
LOGFILE="./jvb.log" JVB_LOGFILE="./jvb.log"
ROTATED_LOGFILE="./jvb.log.1" JICOFO_LOGFILE="./jicofo.log"
DB="./jilo.db" DB="./jilo.db"

Binary file not shown.

View File

@ -2,9 +2,11 @@
### Default configuration ### Default configuration
# default log files # default log files and processes
DEFAULT_LOGFILE="./jvb.log" DEFAULT_JVB_LOGFILE="/var/log/jitsi/jvb.log"
DEFAULT_ROTATED_LOGFILE="./jvb.log.1" DEFAULT_JVB_PROCESS="videobridge"
DEFAULT_JICOFO_LOGFILE="/var/log/jitsi/jicofo.log"
DEFAULT_JICOFO_PROCESS="jicofo"
# Default SQLite database file # Default SQLite database file
DEFAULT_DB="./jilo.db" DEFAULT_DB="./jilo.db"
@ -17,15 +19,17 @@ if [[ -f "$CONFIG_FILE" ]]; then
fi fi
# use default values if not overriden by config file # use default values if not overriden by config file
LOGFILE=${LOGFILE:-$DEFAULT_LOGFILE} JVB_LOGFILE=${JVB_LOGFILE:-$DEFAULT_JVB_LOGFILE}
ROTATED_LOGFILE=${ROTATED_LOGFILE:-$DEFAULT_ROTATED_LOGFILE} JVB_PROCESS=${JVB_PROCESS:-$DEFAULT_JVB_PROCESS}
JICOFO_LOGFILE=${JICOFO_LOGFILE:-$DEFAULT_JICOFO_LOGFILE}
JICOFO_PROCESS=${JICOFO_PROCESS:-$DEFAULT_JICOFO_PROCESS}
DB=${DB:-$DEFAULT_DB} DB=${DB:-$DEFAULT_DB}
### ###
# SQLite queries # SQLite queries
db_get_state="SELECT filename, filetime, filesize, position, inode FROM state WHERE jitsi_component = 'JVB';" db_get_state_template="SELECT filename, filetime, filesize, position, inode FROM state WHERE jitsi_component = '%s';"
db_set_state_template="UPDATE state SET time=datetime('now'), filename='%s', filetime='%s', filesize='%s', position='%s', inode='%s' WHERE jitsi_component = 'JVB';" db_set_state_template="UPDATE state SET time=datetime('now'), filename='%s', filetime='%s', filesize='%s', position='%s', inode='%s' WHERE jitsi_component = '%s';"
db_insert_template="INSERT INTO conferences (conference_name, conference_id, start, end) VALUES ('%s', '%s', '%s', '%s');" db_insert_template="INSERT INTO conferences (conference_name, conference_id, start, end) VALUES ('%s', '%s', '%s', '%s');"
db_drop=" db_drop="
DROP TABLE IF EXISTS conferences; DROP TABLE IF EXISTS conferences;
@ -47,7 +51,9 @@ CREATE TABLE state (
position INTEGER CHECK(typeof(position)='integer'), position INTEGER CHECK(typeof(position)='integer'),
inode INTEGER inode INTEGER
);" );"
db_init="INSERT OR REPLACE INTO state (id, jitsi_component, time, filename, filetime, filesize, position, inode) VALUES (1, 'JVB', '1970-01-01 00:00:00.000', '', 0, 0, 0, 0);" db_init="
INSERT OR REPLACE INTO state (id, jitsi_component, time, filename, filetime, filesize, position, inode) VALUES (1, 'JVB', '1970-01-01 00:00:00.000', '', 0, 0, 0, 0);
INSERT OR REPLACE INTO state (id, jitsi_component, time, filename, filetime, filesize, position, inode) VALUES (1, 'JICOFO', '1970-01-01 00:00:00.000', '', 0, 0, 0, 0);"
db_flush=" db_flush="
DELETE FROM conferences; DELETE FROM conferences;
DELETE FROM state;" DELETE FROM state;"
@ -80,6 +86,7 @@ check_requirements
# Get the last processed state from the database # Get the last processed state from the database
get_state() { get_state() {
db_get_state=$(printf "$db_get_state_template" "$1")
sqlite3 "$DB" "$db_get_state" sqlite3 "$DB" "$db_get_state"
} }
@ -90,7 +97,8 @@ set_state() {
local filesize=$3 local filesize=$3
local position=${4:-0} local position=${4:-0}
local inode=$5 local inode=$5
db_set_state=$(printf "$db_set_state_template" "$filename" "$filetime" "$filesize" "$position" "$inode") local jitsi_component=$6
db_set_state=$(printf "$db_set_state_template" "$filename" "$filetime" "$filesize" "$position" "$inode" "$jitsi_component")
sqlite3 "$DB" "$db_set_state" sqlite3 "$DB" "$db_set_state"
} }
@ -155,6 +163,12 @@ jvb_log_parse() {
### ###
### FIXME - this is not currently used
# check if and which process is running
is_process_running() {
pgrep -f "$1" >/dev/null 2>&1
}
# commandline options # commandline options
while getopts ":dfcpv" opt; do while getopts ":dfcpv" opt; do
@ -215,10 +229,35 @@ case "$cmd" in
exit 1 exit 1
fi fi
# Check if log files exist
jvb_found=false
jicofo_found=false
if [[ -f "$JVB_LOGFILE" ]]; then
jvb_found=true
jitsi_components+=('JVB')
fi
if [[ -f "$JICOFO_LOGFILE" ]]; then
jicofo_found=true
jitsi_components+=('JICOFO')
fi
# if no logs present, exit
if [[ "$jvb_found" == false && "$jicofo_found" == false ]]; then
echo "Neither \"$JVB_PROCESS\" ($JVB_LOGFILE) nor \"$JICOFO_PROCESS\" ($JICOFO_LOGFILE) log files are found."
exit 1
else
# otherwise loop through the found components
for jitsi_component in "${jitsi_components[@]}"; do
# Retrieve last log file and position inside it # Retrieve last log file and position inside it
IFS='|' read -r last_file last_filetime last_size last_pos last_inode <<< $(get_state) IFS='|' read -r last_file last_filetime last_size last_pos last_inode <<< $(get_state)
# Initialize logfile vars # Initialize logfile vars
LOGFILE=$(eval "echo \$${jitsi_component}_LOGFILE")
ROTATED_LOGFILE="$LOGFILE.1"
current_inode=$(stat -c '%i' "$LOGFILE") current_inode=$(stat -c '%i' "$LOGFILE")
current_filetime=$(stat -c '%Y' "$LOGFILE") current_filetime=$(stat -c '%Y' "$LOGFILE")
current_size=$(stat -c '%s' "$LOGFILE") current_size=$(stat -c '%s' "$LOGFILE")
@ -249,15 +288,43 @@ case "$cmd" in
else else
echo "No new lines in the log." echo "No new lines in the log."
fi fi
done
fi
exit 0 exit 0
;; ;;
--parse) --parse)
# Check if log files exist
jvb_found=false
jicofo_found=false
if [[ -f "$JVB_LOGFILE" ]]; then
jvb_found=true
jitsi_components+=('JVB')
fi
if [[ -f "$JICOFO_LOGFILE" ]]; then
jicofo_found=true
jitsi_components+=('JICOFO')
fi
# if no logs present, exit
if [[ "$jvb_found" == false && "$jicofo_found" == false ]]; then
echo "Neither \"$JVB_PROCESS\" ($JVB_LOGFILE) nor \"$JICOFO_PROCESS\" ($JICOFO_LOGFILE) log files are found."
exit 1
else
# otherwise loop through the found components
for jitsi_component in "${jitsi_components[@]}"; do
# Retrieve last log file and position inside it # Retrieve last log file and position inside it
IFS='|' read -r last_file last_filetime last_size last_pos last_inode <<< $(get_state) IFS='|' read -r last_file last_filetime last_size last_pos last_inode <<< $(get_state "$jitsi_component")
# Initialize logfile vars # Initialize logfile vars
LOGFILE=$(eval "echo \$${jitsi_component}_LOGFILE")
ROTATED_LOGFILE="$LOGFILE.1"
last_pos=${last_pos:-0} last_pos=${last_pos:-0}
current_inode=$(stat -c '%i' "$LOGFILE") current_inode=$(stat -c '%i' "$LOGFILE")
current_filetime=$(stat -c '%Y' "$LOGFILE") current_filetime=$(stat -c '%Y' "$LOGFILE")
@ -271,7 +338,7 @@ case "$cmd" in
last_file="$ROTATED_LOGFILE" last_file="$ROTATED_LOGFILE"
last_inode=$(stat -c '%i' "$ROTATED_LOGFILE") last_inode=$(stat -c '%i' "$ROTATED_LOGFILE")
last_filetime=$(stat -c '%Y' "$ROTATED_LOGFILE") last_filetime=$(stat -c '%Y' "$ROTATED_LOGFILE")
set_state "$last_file" "$last_filetime" "$last_size" "$last_pos" "$last_inode" set_state "$last_file" "$last_filetime" "$last_size" "$last_pos" "$last_inode" "$jitsi_component"
fi fi
# parse the current log file # parse the current log file
@ -283,7 +350,11 @@ case "$cmd" in
fi fi
# update the state in db # update the state in db
set_state "$LOGFILE" "$current_filetime" "$current_size" "$new_last_pos" "$current_inode" set_state "$LOGFILE" "$current_filetime" "$current_size" "$new_last_pos" "$current_inode" "$jitsi_component"
done
fi
echo "Data import finished." echo "Data import finished."
exit 0 exit 0