scripts/alert/docker_alarm.sh

18 lines
577 B
Bash

#!/bin/bash
> /tmp/docker_alarm.log
docker ps -a --format "table {{.Names}}\t{{.Status}}" > /opt/logs/docker_status.log
while read line; do
echo $line | grep -v 'v2raya' | grep -q 'Exited'
if [[ $? -eq 0 ]]; then
name=`echo $line | awk '{print $1}'`
echo "Docker Alarm - $name: Container $name has been off line, please check ASAP." >> /tmp/docker_alarm.log
fi
done < /opt/logs/docker_status.log
if [[ -s /tmp/docker_alarm.log ]]; then
alarm=`cat /tmp/docker_alarm.log`
python3 /opt/scripts/alert/sendmail.py "Docker Alarms" "$alarm"
fi