Implemented systemctl error checker

This commit is contained in:
Kevin Veen-Birkenbach 2023-04-15 14:31:18 +02:00
parent cf66f07c4e
commit d456905577
10 changed files with 58 additions and 1 deletions

View File

@ -0,0 +1,2 @@
# journalctl-health-check
Checks journalctl for error messages

View File

@ -0,0 +1,10 @@
#!/bin/sh
echo "Checking journalctl for error messages..."
journalctl_errors="$(journalctl --since '1 day ago' --no-pager | grep -i 'error')"
if [ ! -z "$journalctl_errors" ]
then
echo "Some errors where found: $journalctl_errors"
exit 1
fi
echo "All docker containers are healthy."
exit 0

View File

@ -0,0 +1,8 @@
[Unit]
Description=starts journalctl-health-check.service
[Timer]
OnCalendar=00:00
[Install]
WantedBy=timers.target

View File

@ -0,0 +1,6 @@
- name: "restart journalctl-health-check.timer"
systemd:
name: journalctl-health-check.timer
state: restarted
enabled: yes
daemon_reload: yes

View File

@ -0,0 +1,2 @@
dependencies:
- native-systemd-email

View File

@ -0,0 +1,19 @@
- name: "create {{journalctl_health_check_folder}}"
file:
path: "{{journalctl_health_check_folder}}"
state: directory
mode: 0755
- name: create journalctl-health-check.sh
copy:
src: journalctl-health-check.sh
dest: "{{journalctl_health_check_folder}}journalctl-health-check.sh"
- name: create journalctl-health-check.service
template: src=journalctl-health-check.service.j2 dest=/etc/systemd/system/journalctl-health-check.service
- name: create journalctl-health-check.timer
copy:
src: journalctl-health-check.timer
dest: "/etc/systemd/system/journalctl-health-check.timer"
notify: restart journalctl-health-check.timer

View File

@ -0,0 +1,7 @@
[Unit]
Description=checking journalctl health
OnFailure=systemd-email@%n.service
[Service]
Type=oneshot
ExecStart=/bin/bash {{journalctl_health_check_folder}}journalctl-health-check.sh

View File

@ -0,0 +1 @@
journalctl_health_check_folder: "/home/administrator/scripts/journalctl-health-check/"

View File

@ -3,5 +3,5 @@
# live monitoring # live monitoring
```bash ```bash
watch -n 0.5 'journalctl -n 20 --no-pager' 'journalctl -f'
``` ```

View File

@ -0,0 +1,2 @@
dependencies:
- native-journalctl-health-check