mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-05-18 14:51:50 +02:00
add apprise alert
This commit is contained in:
@@ -24,20 +24,50 @@ mkdir -p "$ingest_dir"
|
|||||||
chown -R pi:pi "$ingest_dir"
|
chown -R pi:pi "$ingest_dir"
|
||||||
chmod -R 755 "$ingest_dir"
|
chmod -R 755 "$ingest_dir"
|
||||||
|
|
||||||
|
function apprisemessage() {
|
||||||
|
# Set failed check so it only runs once
|
||||||
|
touch "$HOME"/BirdNET-Pi/failed_servicescheck
|
||||||
|
NOTIFICATION=""
|
||||||
|
STOPPEDSERVICE="<br><b>Stopped services:</b> "
|
||||||
|
services=(birdnet_analysis
|
||||||
|
chart_viewer
|
||||||
|
spectrogram_viewer
|
||||||
|
icecast2
|
||||||
|
birdnet_recording
|
||||||
|
birdnet_log
|
||||||
|
birdnet_stats)
|
||||||
|
for i in "${services[@]}"; do
|
||||||
|
if [[ "$(sudo systemctl is-active "${i}".service)" == "inactive" ]]; then
|
||||||
|
STOPPEDSERVICE+="${i}; "
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
NOTIFICATION+="$STOPPEDSERVICE"
|
||||||
|
NOTIFICATION+="<br><b>Additional informations</b>: "
|
||||||
|
NOTIFICATION+="<br><b>Since:</b> ${LASTCHECK:-unknown}"
|
||||||
|
NOTIFICATION+="<br><b>System:</b> ${SITE_NAME:-$(hostname)}"
|
||||||
|
NOTIFICATION+="<br>Available disk space: $(df -h "$(readlink -f "$HOME/BirdSongs")" | awk 'NR==2 {print $4}')"
|
||||||
|
if [ -n "$BIRDNETPI_URL" ]; then
|
||||||
|
NOTIFICATION+="<br> <a href=\"$BIRDNETPI_URL\">Access your BirdNET-Pi</a>"
|
||||||
|
fi
|
||||||
|
TITLE="BirdNET-Analyzer stopped"
|
||||||
|
$HOME/BirdNET-Pi/birdnet/bin/apprise -vv -t "$TITLE" -b "${NOTIFICATION}" --input-format=html --config="$HOME/BirdNET-Pi/apprise.txt"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
sleep 61
|
sleep 61
|
||||||
|
|
||||||
# Restart analysis if clogged
|
# Restart analysis if clogged
|
||||||
############################
|
############################
|
||||||
|
|
||||||
if (( counter <= 0 )); then
|
if ((counter <= 0)); then
|
||||||
latest="$(cat "$ingest_dir"/analyzing_now.txt)"
|
latest="$(cat "$ingest_dir"/analyzing_now.txt)"
|
||||||
if [[ "$latest" == "$analyzing_now" ]]; then
|
if [[ "$latest" == "$analyzing_now" ]]; then
|
||||||
echo "$(date) WARNING no change in analyzing_now for 10 iterations, restarting services"
|
echo "$(date) WARNING no change in analyzing_now for 10 iterations, restarting services"
|
||||||
/."$HOME"/BirdNET-Pi/scripts/restart_services.sh
|
/."$HOME"/BirdNET-Pi/scripts/restart_services.sh
|
||||||
fi
|
fi
|
||||||
counter=10
|
counter=10
|
||||||
analyzing_now=$(cat "$ingest_dir"/analyzing_now.txt)
|
analyzing_now=$(cat "$ingest_dir"/analyzing_now.txt)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Pause recorder to catch-up
|
# Pause recorder to catch-up
|
||||||
@@ -48,10 +78,11 @@ while true; do
|
|||||||
|
|
||||||
bashio::log.green "$(date) INFO ${wavs} wav files waiting in $ingest_dir, $srv state is $state"
|
bashio::log.green "$(date) INFO ${wavs} wav files waiting in $ingest_dir, $srv state is $state"
|
||||||
|
|
||||||
if (( wavs > 100 )) && [[ "$state" == "active" ]]; then
|
if ((wavs > 100)) && [[ "$state" == "active" ]]; then
|
||||||
sudo systemctl stop "$srv"
|
sudo systemctl stop "$srv"
|
||||||
bashio::log.red "$(date) WARNING stopped $srv service"
|
bashio::log.red "$(date) WARNING stopped $srv service"
|
||||||
elif (( wavs <= 100 )) && [[ "$state" != "active" ]]; then
|
if [ -s "$HOME/BirdNET-Pi/apprise.txt" ]; then apprisealert(); fi
|
||||||
|
elif ((wavs <= 100)) && [[ "$state" != "active" ]]; then
|
||||||
sudo systemctl start $srv
|
sudo systemctl start $srv
|
||||||
bashio::log.yellow "$(date) INFO started $srv service"
|
bashio::log.yellow "$(date) INFO started $srv service"
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user