Last active
August 3, 2021 10:02
-
-
Save ci7lus/fa8ceccc9fad00957d1feb47fe84c04d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# mirakurun_check.sh | |
# 10秒受信して200かつdropしていればその数を、200以外だったらステータスコードをwebhookするshellscript | |
# MIT License | |
# https://gist.github.com/ci7lus/fa8ceccc9fad00957d1feb47fe84c04d | |
set -eu | |
# https://github.com/xtne6f/tsselect_gcc | |
TSSELECT_PATH=/usr/local/bin/tsselect | |
URL="http://192.168.0.10:40772/api" | |
WEBHOOK_URL=https://discord.com/api/webhooks/xxx | |
TUNER_INDEX=0 | |
CHANNEL=18 | |
TUNERS=`curl -sL $URL/tuners` | |
NAME=`jq -r ".[$TUNER_INDEX].name" <<< """$TUNERS"""` | |
COMMAND=`jq -r ".[$TUNER_INDEX].command" <<< """$TUNERS"""` | |
TYPE=`jq -r ".[$TUNER_INDEX].types[0]" <<< """$TUNERS"""` | |
if [[ $COMMAND =~ [0-9]{2} ]]; then | |
CHANNEL=$BASH_REMATCH | |
fi | |
echo "チャンネル:" $CHANNEL | |
function Received { | |
if [ $RES = "200" ]; then | |
ANAL=`$TSSELECT_PATH /tmp/chk.ts` | |
RE="total sync error: ([0-9]+)" | |
if [[ $ANAL =~ $RE ]]; then | |
DROP=${BASH_REMATCH[1]} | |
echo "DROP COUNT:" $DROP | |
curl -sL -H "Content-Type: application/json" -X POST -d "{\"content\": \"[$NAME] $CHANNEL($TYPE) の受信テストで $DROP Drop しました\"}" $WEBHOOK_URL | |
fi | |
else | |
echo "受信失敗: $RES" | |
curl -sL -H "Content-Type: application/json" -X POST -d "{\"content\": \"[$NAME] $CHANNEL($TYPE) の受信テストが $RES で失敗しました\"}" $WEBHOOK_URL | |
fi | |
} | |
trap Received EXIT | |
RES=`curl -sL --max-time 10 -o /tmp/chk.ts -w '%{http_code}\n' $URL/channels/$TYPE/$CHANNEL/stream` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment