From: Morten Moesgaard Date: Thu, 18 May 2017 08:12:22 +0000 (+0200) Subject: new files added X-Git-Url: https://git.jkkn.net/?a=commitdiff_plain;h=HEAD;p=dai-monitor.git new files added --- diff --git a/monitor-dai.sh b/monitor-dai.sh index 6f55296..e538dda 100755 --- a/monitor-dai.sh +++ b/monitor-dai.sh @@ -28,7 +28,7 @@ BASIC_CURL_PARAMS="--connect-timeout 15 --location -Ss" SCRIPT_NAME=$(basename "$0") - +LISTNAME=$4 DATE_BSD="date -r " DATE_LINUX="date -d @" @@ -122,13 +122,23 @@ function monitorStream() { local doRecord=0 doStopRecord=0 local syncMode=-1 # (-1=get first, x=saw last at, 0=synched) In syncmode we try to request every second until we see a change to get a more precise time sync local stream_time="" # unknown - + local list=$4 echo >&2 "INFO: Started monitoring using: $stream" - + +RIND='{"indexname": "dai", "message": {"state": "info","values": "Started monitoring using:' +RIND+=$stream +RIND+='","name":"' +RIND+=$LISTNAME +RIND+='"} }' +echo $RIND | nc -u a.elastic.g.backend.tv2net.dk 2000 while true; do starttime=$(date +%s) warn_not_a_playlist=1 + zabbix_sender -z zbxprx02.web.tv2net.dk -s "zbxprx02.web.tv2net.dk" -k loggerIn["$4.log"] -o 0 + + zabbix_sender -z zbxprx02.web.tv2net.dk -s "zbxprx02.web.tv2net.dk" -k logger["$4.log"] -o 0 + # Set time to real time first request if [ -z "$stream_time" ]; then syncMode=-1 @@ -136,10 +146,24 @@ function monitorStream() { stream_time=$(($starttime - $streamDelay)) pretty_time=$($DATE${stream_time%.*} +"%Y-%m-%d %H:%M:%S") echo >&2 "NOTICE: Using time-offset of -${streamDelay}s. Stream time is $pretty_time, real time is $($DATE${starttime} +"%Y-%m-%d %H:%M:%S")" + RIND='{"indexname": "dai", "message": {"state": "notice","values": "' + RIND+="Using time-offset of -${streamDelay}s. Stream time is $pretty_time, real time is $($DATE${starttime} +"%Y-%m-%d %H:%M:%S")" + RIND+='","name":"' + RIND+=$LISTNAME + RIND+='"} }' +echo $RIND | nc -u a.elastic.g.backend.tv2net.dk 2000 + else stream_time="$starttime" pretty_time=$($DATE${stream_time%.*} +"%Y-%m-%d %H:%M:%S") echo >&2 "NOTICE: Setting stream time to real time: $pretty_time" +RIND='{"indexname": "dai", "message": {"state": "notice","values": "' +RIND+="NOTICE: Setting stream time to real time: $pretty_time" +RIND+='","name":"' +RIND+=$LISTNAME +RIND+='"} }' +echo $RIND | nc -u a.elastic.g.backend.tv2net.dk 2000 + fi fi @@ -177,7 +201,14 @@ function monitorStream() { pretty_time=$($DATE${stream_time%.*} +"%Y-%m-%d %H:%M:%S") if [[ $curSeq -ne $nextSeq ]]; then echo >&2 "$pretty_time: WARN: Lost segments ($curSeq > $nextSeq)." - stream_time="" + RIND='{"indexname": "dai", "message": {"state": "notice","values": "' +RIND+="$pretty_time: WARN: Lost segments ($curSeq > $nextSeq)." +RIND+='","name":"' +RIND+=$LISTNAME +RIND+='"} }' +echo $RIND | nc -u a.elastic.g.backend.tv2net.dk 2000 + + stream_time="" syncMode=-1 curSeq=-1 doRecord=0 @@ -205,7 +236,14 @@ function monitorStream() { pretty_time=$($DATE${stream_time%.*} +"%Y-%m-%d %H:%M:%S") syncMode=0 echo >&2 "$pretty_time: INFO: Time was adjusted by -$syncOffset seconds." - elif [ "$syncOffset" -eq 0 ]; then +RIND='{"indexname": "dai", "message": {"state": "info","values": "' +RIND+="$pretty_time: INFO: Time was adjusted by -$syncOffset seconds." +RIND+='","name":"' +RIND+=$LISTNAME +RIND+='"} }' +echo $RIND | nc -u a.elastic.g.backend.tv2net.dk 2000 + + elif [ "$syncOffset" -eq 0 ]; then syncMode=0 else # Resync @@ -226,7 +264,14 @@ function monitorStream() { if [ "$tag" == "EXT-X-TARGETDURATION" ]; then if [ "$value" != "$target_duration" ]; then echo >&2 "$pretty_time: INFO: Changing target duration to: $value" - target_duration="$value" + RIND='{"indexname": "dai", "message": {"state": "info","values": "' + RIND+="$pretty_time: INFO: Changing target duration to: $value" + RIND+='","name":"' + RIND+=$LISTNAME + RIND+='"} }' + echo $RIND | nc -u a.elastic.g.backend.tv2net.dk 2000 + + target_duration="$value" fi elif [ "$tag" == "EXTINF" ]; then nextSegmentLength=$value @@ -241,9 +286,24 @@ function monitorStream() { if [ "$tag" == "EXT-X-CUE-OUT" ]; then # Begin ad block echo >&2 "$pretty_time: INFO: Seeing CUE-OUT (Ad block start) of duration: $value" - if [ "$mode" == "ADBLOCK" ]; then + RIND='{"indexname": "dai", "message": {"state": "info","values": "' + RIND+="$pretty_time: INFO: Seeing CUE-OUT (Ad block start) of duration: $value" + RIND+='","name":"' + RIND+=$LISTNAME + RIND+='"} }' + echo $RIND | nc -u a.elastic.g.backend.tv2net.dk 2000 + zabbix_sender -z zbxprx02.web.tv2net.dk -s "zbxprx02.web.tv2net.dk" -k logger["$4.log"] -o 2 + + if [ "$mode" == "ADBLOCK" ]; then echo >&2 "$pretty_time: ERROR: Already in ad block - extra cue-out after $curLength" - else + RIND='{"indexname": "dai", "message": {"state": "error","values": "' + RIND+="$pretty_time: ERROR: Already in ad block - extra cue-out after $curLength" + RIND+='","name":"' + RIND+=$LISTNAME + RIND+='"} }' + echo $RIND | nc -u a.elastic.g.backend.tv2net.dk 2000 + zabbix_sender -z zbxprx02.web.tv2net.dk -s "zbxprx02.web.tv2net.dk" -k logger["$4.log"] -o 1 + else #echo >&2 "$pretty_time: INFO: Ad-block started after $curLength seconds" mode="ADBLOCK" expectedAdLength=$value @@ -251,7 +311,14 @@ function monitorStream() { if [ "$RECORD_AD_BLOCKS" -gt 0 ]; then if [ -z "$lastUsedSegment" ]; then echo >&2 "$pretty_time: INFO: Skipping recording since we did not see start of it." - else + RIND='{"indexname": "dai", "message": {"state": "info","values": "' + RIND+="$pretty_time: INFO: Skipping recording since we did not see start of it." + RIND+= '","name":"' + RIND+=$LISTNAME + RIND+='"} }' + echo $RIND | nc -u a.elastic.g.backend.tv2net.dk 2000 + + else RECORD_AD_BLOCKS=$(($RECORD_AD_BLOCKS - 1)) echo >&2 "$pretty_time: INFO: Recording this adblock ($RECORD_AD_BLOCKS left)." saveStreamBit "$stream" "$lastUsedSegment" "$lastUsedStreamTime" "$recordFolder" & @@ -263,10 +330,25 @@ function monitorStream() { elif [ "$tag" == "EXT-X-CUE-IN" ]; then # End ad block echo >&2 "$pretty_time: INFO: Seeing CUE-IN (Ad block end) after duration: $curLength" - if [ "$mode" == "ADBLOCK" ]; then + RIND='{"indexname": "dai", "message": {"state": "info","values": "' + RIND+="$pretty_time: INFO: Seeing CUE-IN (Ad block end) after duration: $curLength" + RIND+='","name":"' + RIND+=$LISTNAME + RIND+='"} }' + echo $RIND | nc -u a.elastic.g.backend.tv2net.dk 2000 + zabbix_sender -z zbxprx02.web.tv2net.dk -s "zbxprx02.web.tv2net.dk" -k loggerIn["$4.log"] -o 2 + if [ "$mode" == "ADBLOCK" ]; then if [ "$expectedAdLength" != "$curLength" ]; then echo >&2 "$pretty_time: WARN: Block was not the length expected ($curLength <> $expectedAdLength)" - fi + RIND='{"indexname": "dai", "message": {"state": "warn","values": "' + RIND+="$pretty_time: WARN: Block was not the length expected ($curLength <> $expectedAdLength)" + RIND+='","name":"' + RIND+=$LISTNAME + RIND+='"} }' + echo $RIND | nc -u a.elastic.g.backend.tv2net.dk 2000 + + + fi if [ "$doRecord" == "1" ]; then echo >&2 "$pretty_time: INFO: Stopping recording." doStopRecord=1 @@ -274,7 +356,14 @@ function monitorStream() { curLength=0 elif [ "$mode" == "LIVE" ]; then echo >&2 "$pretty_time: ERROR: Extra CUE-IN outside Ad-block after $curLength" - fi + RIND='{"indexname": "dai", "message": {"state": "error","values": "' + RIND+="$pretty_time: ERROR: Extra CUE-IN outside Ad-block after $curLength" + RIND+='","name":"' + RIND+=$LISTNAME + RIND+='"} }' + echo $RIND | nc -u a.elastic.g.backend.tv2net.dk 2000 + zabbix_sender -z zbxprx02.web.tv2net.dk -s "zbxprx02.web.tv2net.dk" -k loggerIn["$4.log"] -o 1 + fi mode="LIVE" fi fi @@ -284,6 +373,13 @@ function monitorStream() { if [ $warn_not_a_playlist -eq 1 ]; then echo >&2 "$pretty_time: ERROR: Not a valid playlist ($stream)" + RIND='{"indexname": "dai", "message": {"state": "error","values": "' + RIND+="$pretty_time: ERROR: Not a valid playlist ($stream)" + RIND+='","name":"' + RIND+=$LISTNAME + RIND+='"} }' + echo $RIND | nc -u a.elastic.g.backend.tv2net.dk 2000 + failed=$(($failed + 1)) else failed=0 @@ -318,7 +414,14 @@ function monitorStream() { if [ "$failed" -ge 2 ]; then if [ "$failed" -ne 10 ]; then echo >&2 "$pretty_time: ERROR: Stream failed twice.. resetting..." - fi + RIND='{"indexname": "dai", "message": {"state": "error","values": "' + RIND+="$pretty_time: ERROR: Stream failed twice.. resetting..." + RIND+='","name":"' + RIND+=$LISTNAME + RIND+='"} }' + echo $RIND | nc -u a.elastic.g.backend.tv2net.dk 2000 + + fi return fi done @@ -381,7 +484,7 @@ while true; do echo >&2 "INFO: (will retry in 10 seconds)" sleep 10 else - monitorStream "$streamurl" "$2" "$3" + monitorStream "$streamurl" "$2" "$3" "$4" fi done diff --git a/start-monitors.sh b/start-monitors.sh index 9cfef9c..58ec8bf 100755 --- a/start-monitors.sh +++ b/start-monitors.sh @@ -89,7 +89,7 @@ fi declare ${stream} echo "Starting monitor for $NAME ..." export STREAM_URL="$URL" - ./monitor-dai.sh --use-env "$recordings_dir/$NAME/" "$DELAY" >"$playlist_dir/$NAME.m3u8" 2>"$log_dir/$NAME.log" & + ./monitor-dai.sh --use-env "$recordings_dir/$NAME/" "$DELAY" "$NAME" > "$playlist_dir/$NAME.m3u8" 2> "$log_dir/$NAME.log" & myjobs+=($!) done