add monitoring scripts
This commit is contained in:
parent
c51e72686e
commit
8c603d6ebd
5 changed files with 87 additions and 0 deletions
29
appinfo.yml
29
appinfo.yml
|
|
@ -6,6 +6,16 @@ templatefiles:
|
|||
- src: backupmanager.j2
|
||||
dest: ~/backupmanager
|
||||
mode: "0755"
|
||||
- src: monitor@.service.j2
|
||||
dest: ~/.config/systemd/user/monitor@.service
|
||||
- src: monitor.socket.j2
|
||||
dest: ~/.config/systemd/user/monitor.socket
|
||||
- src: monitor.sh.j2
|
||||
dest: ~/monitor.sh
|
||||
mode: "0755"
|
||||
- src: monitor-test.sh.j2
|
||||
dest: ~/monitor-test.sh
|
||||
mode: "0755"
|
||||
backuptype: none
|
||||
configdefinition:
|
||||
"$id": "backup manager config"
|
||||
|
|
@ -72,3 +82,22 @@ configdefinition:
|
|||
description: Repositories where the latest backup is older then timeout days will give a warning that there are no recent backups
|
||||
required:
|
||||
- repos
|
||||
exports:
|
||||
monitoring:
|
||||
checks:
|
||||
- name: main
|
||||
message: Backup manager activated
|
||||
interval: 3600
|
||||
type: string
|
||||
okvalue: active
|
||||
- name: lastrun
|
||||
message: Errors last run
|
||||
interval: 3600
|
||||
type: string
|
||||
okvalue: ""
|
||||
- name: lastrunrecent
|
||||
message: Backup manager did not run recently
|
||||
interval: 3600
|
||||
type: string
|
||||
okvalue: "OK"
|
||||
|
||||
|
|
|
|||
16
monitor-test.sh.j2
Normal file
16
monitor-test.sh.j2
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Usage: ./execute_command_client.sh <command>
|
||||
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "Usage: $0 <command>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
command="$1"
|
||||
|
||||
# Connect to socket and send command
|
||||
output=$(nc -U {{ statedir }}/{{ name }}.monitoring <<< "$command")
|
||||
|
||||
# Print output
|
||||
echo "$output"
|
||||
18
monitor.sh.j2
Normal file
18
monitor.sh.j2
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#!/bin/bash
|
||||
read -r command
|
||||
case $command in
|
||||
main)
|
||||
systemctl is-active --user backup-manager.timer
|
||||
;;
|
||||
lastrun)
|
||||
cat {{ homedir }}/.backupmanager.errors
|
||||
;;
|
||||
lastrunrecent)
|
||||
[ -f {{ homedir }}/.backupmanager.errors ] && [ $(find {{ homedir }}/.backupmanager.errors -mtime -2) ] && echo "OK" || echo "outdated"
|
||||
;;
|
||||
*)
|
||||
echo "Parameter unknown"
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
9
monitor.socket.j2
Normal file
9
monitor.socket.j2
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
[Unit]
|
||||
Description=Execute Command Socket
|
||||
|
||||
[Socket]
|
||||
ListenStream={{ statedir }}/{{ name }}.monitoring
|
||||
Accept=yes
|
||||
|
||||
[Install]
|
||||
WantedBy=sockets.target
|
||||
15
monitor@.service.j2
Normal file
15
monitor@.service.j2
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
[Unit]
|
||||
Description=Execute Command Service
|
||||
After=network.target
|
||||
Requires=monitor.socket
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart={{ homedir }}/monitor.sh
|
||||
StandardInput=socket
|
||||
StandardOutput=socket
|
||||
TimeoutStopSec=5
|
||||
RuntimeMaxSec=10
|
||||
|
||||
[Install]
|
||||
WantedBy=sockets.target
|
||||
Loading…
Add table
Add a link
Reference in a new issue