added gotify alerts on image updates
This commit is contained in:
10
podman/files/check_image_updates.service.jinja
Normal file
10
podman/files/check_image_updates.service.jinja
Normal file
@@ -0,0 +1,10 @@
|
||||
[Unit]
|
||||
Description=Check for image updates on configured podman containers
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
User={{ pillar.podman.user }}
|
||||
ExecStart={{ salt['user.info'](pillar.podman.user).home }}/bin/check_image_updates.sh
|
||||
|
||||
[Install]
|
||||
WantedBy=default.target
|
35
podman/files/check_image_updates.sh.jinja
Normal file
35
podman/files/check_image_updates.sh.jinja
Normal file
@@ -0,0 +1,35 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
URL="{{ pillar['podman']['gotify']['url'] }}"
|
||||
TOKEN="{{ pillar['podman']['gotify']['token'] }}"
|
||||
TITLE="Updates on $HOSTNAME"
|
||||
PRIORITY="{{ pillar['podman']['gotify']['priority'] }}"
|
||||
|
||||
{% raw -%}
|
||||
function check_update(){
|
||||
IFS=',' read -r -a container_info <<< "$(podman container inspect $1 --format '{{ .Name }},{{ .ImageName }},{{ .Image }}')"
|
||||
|
||||
podman pull "${container_info[1]}"
|
||||
if [[ "$(podman image inspect "${container_info[1]}" --format "{{.Id}}")" != "${container_info[2]}" ]];then
|
||||
containers[${#containers[@]}]="${container_info[0]}"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
IFS=$'\n'
|
||||
for line in $(podman container ls -q); do
|
||||
check_update "$line"
|
||||
done
|
||||
if [[ "${#containers[@]}" == "0" ]]; then
|
||||
exit
|
||||
fi
|
||||
|
||||
MESSAGE=$(cat << EOM
|
||||
Following ${#containers[@]} container(s) has updates:
|
||||
${containers[*]}
|
||||
EOM
|
||||
)
|
||||
|
||||
curl "$URL/message?token=$TOKEN" -F "title=$TITLE" -F "priority=$PRIORITY" -F "message=$MESSAGE"
|
||||
echo " "
|
||||
{% endraw -%}
|
9
podman/files/check_image_updates.timer.jinja
Normal file
9
podman/files/check_image_updates.timer.jinja
Normal file
@@ -0,0 +1,9 @@
|
||||
[Unit]
|
||||
Description=Restic backup timer
|
||||
|
||||
[Timer]
|
||||
OnCalendar=Sun, 12:00
|
||||
Unit=check_image_updates.service
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
Reference in New Issue
Block a user