Implement reporting service.
This commit is contained in:
parent
47844f3019
commit
7fed0e879b
5 changed files with 78 additions and 6 deletions
|
@ -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
|
||||
|
|
51
roles/lmn_fvs/files/reporter
Normal file
51
roles/lmn_fvs/files/reporter
Normal 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
|
6
roles/lmn_fvs/files/reporter.service
Normal file
6
roles/lmn_fvs/files/reporter.service
Normal file
|
@ -0,0 +1,6 @@
|
|||
[Unit]
|
||||
Description=Run reporting script
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart=/usr/local/sbin/reporter
|
9
roles/lmn_fvs/files/reporter.timer
Normal file
9
roles/lmn_fvs/files/reporter.timer
Normal file
|
@ -0,0 +1,9 @@
|
|||
[Unit]
|
||||
Description=Run reporter script every 15 min
|
||||
|
||||
[Timer]
|
||||
OnBootSec=5min
|
||||
OnUnitActiveSec=15min
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
Loading…
Add table
Add a link
Reference in a new issue