Implement reporting service.

This commit is contained in:
Andreas B. Mundt 2023-11-13 15:41:49 +01:00
parent 47844f3019
commit 7fed0e879b
5 changed files with 78 additions and 6 deletions

View file

@ -1,9 +1,9 @@
[Unit]
Description=Run pwroff script every 30 min after 90 min uptime
Description=Run pwroff script every 15 min after 90 min uptime
[Timer]
OnBootSec=90min
OnUnitActiveSec=30min
OnUnitActiveSec=15min
[Install]
WantedBy=timers.target

View file

@ -0,0 +1,51 @@
#!/usr/bin/bash
#
# Send stdout of some commands to monitoring server.
# Collect the reports with 'nc -u -k -l 1234' on 'sendto'.
# Use /bin/nc.openbsd, /bin/nc.traditional seems not to work.
#
set -eu
sendto="collector.steinbeis.schule 1234"
cmds=(
'uname -a'
'uptime'
'apt list --upgradeable -o Apt::Cmd::Disable-Script-Warning=true'
'systemctl --failed'
'w'
'ls -ld /home/ansible/.ansible/tmp/'
'ip addr show'
)
r="$HOSTNAME: ------- $(date) -------
$(for c in "${cmds[@]}" ; do echo "$c"; $c | sed 's/^/ /' ; done | sed "s/^/$HOSTNAME: /")
## -------------------------------------------------"
echo "$r" | nc -w 1 -u $sendto
## below is the corresponding collector part:
# #!/usr/bin/bash
# #
# # collect messages from reporter and drop it into log files
# #
#
# set -eu
#
# port=1234
#
# logdir="/var/log/collector"
# [[ -d "$logdir" ]] || mkdir "$logdir"
#
# nc -k -l -u -p "$port" | while read line ; do
# sndr="${line%%:*}"
# msg="${line#*: }"
# if [[ "$sndr" =~ [a-z0-9]+ ]] ; then
# if [[ "$msg" =~ ^-------\ .+\ -------$ ]] ; then
# echo "$msg" > "$logdir/$sndr"
# else
# echo "$msg" >> "$logdir/$sndr"
# fi
# fi
# done

View file

@ -0,0 +1,6 @@
[Unit]
Description=Run reporting script
[Service]
Type=simple
ExecStart=/usr/local/sbin/reporter

View file

@ -0,0 +1,9 @@
[Unit]
Description=Run reporter script every 15 min
[Timer]
OnBootSec=5min
OnUnitActiveSec=15min
[Install]
WantedBy=timers.target