add failure webhook

This commit is contained in:
Jake Walker 2025-08-12 18:27:12 +01:00
parent 4c9e3b1830
commit af2c7fb6c9
No known key found for this signature in database
4 changed files with 20 additions and 0 deletions

View file

@ -26,6 +26,8 @@ restic_ssh_private_key_path: "/root/.ssh/backup"
restic_systemd_timer_on_calender: "*-*-* 03:00:00" restic_systemd_timer_on_calender: "*-*-* 03:00:00"
restic_systemd_timer_randomized_delay_sec: 0 restic_systemd_timer_randomized_delay_sec: 0
restic_failure_webhook_url: null
restic_arch_map: restic_arch_map:
i386: '386' i386: '386'
x86_64: 'amd64' x86_64: 'amd64'

View file

@ -41,6 +41,14 @@
restic_folders_combined: "{{ restic_default_folders + restic_folders }}" restic_folders_combined: "{{ restic_default_folders + restic_folders }}"
notify: Reload systemd notify: Reload systemd
- name: Add systemd service for restic failure
when: restic_failure_webhook_url is not none
ansible.builtin.template:
src: restic-failure.service.j2
dest: /etc/systemd/system/restic-failure.service
mode: "0644"
notify: Reload systemd
- name: Add systemd timer for restic - name: Add systemd timer for restic
ansible.builtin.template: ansible.builtin.template:
src: restic-backup.timer.j2 src: restic-backup.timer.j2

View file

@ -1,5 +1,8 @@
[Unit] [Unit]
Description=Restic backup Description=Restic backup
{% if restic_failure_webhook_url is not none %}
OnFailure=restic-failure.service
{% endif %}
[Service] [Service]
Type=oneshot Type=oneshot

View file

@ -0,0 +1,7 @@
[Unit]
Description=Restic backup failure
[Service]
Type=oneshot
User={{ restic_user }}
ExecStartPre=/bin/sh -c 'curl -X POST -H "Content-Type: application/json" -d "{\"text\": \"Restic backup service failed on {{ inventory_hostname }}!\"}" {{ restic_failure_webhook_url }}'