summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2021-06-27 09:10:11 +0200
committerErich Eckner <git@eckner.net>2021-06-27 09:10:11 +0200
commit763e3c7bd3b70f7f59a9a23b259f714ff4d3d811 (patch)
treecfb59e6a59085a17360e0cdf3e74777504713894
downloadprint-status-763e3c7bd3b70f7f59a9a23b259f714ff4d3d811.tar.xz
status quo
-rwxr-xr-xprint-status28
-rwxr-xr-xprint-status-html184
-rw-r--r--print-status-html.service6
-rw-r--r--print-status-html.timer11
-rw-r--r--print-status.service6
-rw-r--r--print-status.timer11
6 files changed, 246 insertions, 0 deletions
diff --git a/print-status b/print-status
new file mode 100755
index 0000000..f28821a
--- /dev/null
+++ b/print-status
@@ -0,0 +1,28 @@
+#!/bin/bash
+
+{
+ find /dev/mapper -mindepth 1 -maxdepth 1 \( -name 'leg*' -o -name 'foot*' \) -printf '%f\n' \
+ | sort -u \
+ | xargs -rn1 cryptsetup status \
+ | grep -v '^\s\+device:'
+ sed -n '
+ /^Personalities/d
+ /^\S/ {
+ N
+ s/^\(\S\+\)\s*:.*\n\s*\([0-9]\)/\1: \2/
+ T
+ p
+ }
+ ' /proc/mdstat \
+ | sort -u
+ find /sys/block/ -mindepth 1 -maxdepth 1 -name 'md*' -printf '%f: ' -exec cat {}/md/mismatch_cnt \; \
+ | sort -u
+ ssacli ctrl slot=1 ld all show \
+ | grep -v '^\s*$'
+} | \
+ if mountpoint -q /srv/http/tmp; then
+ sponge /srv/http/tmp/status
+ date +%s > /srv/http/tmp/status.time
+ else
+ cat
+ fi
diff --git a/print-status-html b/print-status-html
new file mode 100755
index 0000000..d4c30c6
--- /dev/null
+++ b/print-status-html
@@ -0,0 +1,184 @@
+#!/bin/bash
+
+watch_dirs=('/data/raid/harti')
+
+{
+ cat <<EOF
+<html><head><title>Status Of Backup Server</title></head><body>
+<h1>Partitions</h1>
+EOF
+
+ for dir in "${watch_dirs[@]}"; do
+ {
+ du -sxh "${dir}"
+ df -h "${dir}" \
+ | sed '1d'
+ } \
+ | tr '\n' ' '
+ printf '\n'
+ done \
+ | awk '{
+ print $2 ": " $1 "B (partition: " $5 "B of " $4 "B used, " $6 "B free)<br>"
+ }'
+
+ cat <<EOF
+<h1>Crypt Devices</h1>
+EOF
+
+ find /dev/mapper -mindepth 1 -maxdepth 1 \( -name 'leg*' -o -name 'foot*' \) -printf '%f\n' \
+ | sort -u \
+ | xargs -rn1 cryptsetup status \
+ | sed '
+ s/^\s\+//
+ s/\s\+$//
+ \,^/dev/mapper/, !d
+ / is active and is in use\.$/ {
+ s,.*,<font color="#008000">\0</font>,
+ b
+ }
+ s,.*,<font color="#800000">\0</font>,
+ ' \
+ | sed '
+ s/$/<br>/
+ '
+
+ cat <<EOF
+<h1>Software RAIDs</h1>
+EOF
+
+ {
+ sed -n '
+ /^Personalities/d
+ /^\S/ {
+ N
+ s/^\(\S\+\)\s*:.*\n\s*\([0-9]\)/\1: \2/
+ T
+ p
+ }
+ s/^\s\+\(\[[^][]\+]\)\s\+\(\S\+\)\s\+=\s\+\(\S\+\)\s\+\S\+\s\+\(finish=\S\+\)\s.*$/\2 \3 \1 \4/
+ T
+ p
+ ' /proc/mdstat \
+ | sort -u \
+ | while read -r line; do
+ if [ -z "${line%%* finish=*min*}" ]; then
+ duration="${line##* finish=}"
+ duration="${duration%%min*}"
+ time=$(
+ date +'%F %T' -d@$((
+ $(date +%s) + $(echo "60 * ${duration}" | bc -l | sed 's/\..*$//')
+ ))
+ )
+ printf '%s (%s)\n' "${line}" "${time}"
+ else
+ printf '%s\n' "${line}"
+ fi
+ done \
+ | sed '
+ s,.*\[U\+\]$,<font color="#008000">\0</font>,
+ t
+ s,^\(re\(shape\|covery\|sync\) \S\+\) \[\(\S*\)>\(\.*\)\] \(\S\+\s\+\S\+\s\+\S\+\)$,<font color="#808000">\1</font> <tt>[<font color="#008000">\3</font><font color="#808000">\&gt;</font><font color="#800000">\4</font>]</tt> \5,
+ t
+ s,.*,<font color="#800000">\0</font>,
+ '
+
+ find /sys/block/ -mindepth 1 -maxdepth 1 -name 'md*' -printf '%f: ' -exec cat {}/md/mismatch_cnt \; \
+ | sort -u \
+ | sed '
+ s/$/ mismatches/
+ /^\S\+: 0 mismatches$/ {
+ s,.*,<font color="#008000">\0</font>,
+ b
+ }
+ s,.*,<font color="#800000">\0</font>,
+ '
+ } \
+ | sed '
+ s/$/<br>/
+ '
+
+ cat <<EOF
+<h1>Hardware RAIDs</h1>
+EOF
+
+ ssacli ctrl slot=1 ld all show \
+ | sed '
+ s/^\s\+//
+ s/\s\+$//
+ /^$/d
+ /^logicaldrive/ !b
+ / OK)$/ {
+ s,.*,<font color="#008000">\0</font>,
+ b
+ }
+ s,.*,<font color="#800000">\0</font>,
+ ' \
+ | sed '
+ s/$/<br>/
+ '
+
+ cat <<EOF
+<h1>Backups</h1>
+<table>
+<tr><th>Status</th><th>Name</th><th>Letztes erfolgreiches Backup</th></tr>
+EOF
+ last-backups \
+ | sed '
+ /VERALTET\|LEER/ ! s/^/ok/
+ ' \
+ | awk '{
+ print "<tr><td>" $1 "</td><td>" $2 "</td><td>" $3 "</td></tr>"
+ }' \
+ | sed '
+ s/^\(<tr><td>[^<>]*\)_laeuft/\1 (l\&auml;uft)/
+ /^<tr><td>ok\( [^<>]\+\)\?</ {
+ s,<td>\([^<>]\+\)</td>,<td><font color="#008000">\1</font></td>,g
+ b
+ }
+ s,<td>\([^<>]\+\)</td>,<td><font color="#800000">\1</font></td>,g
+ '
+ cat <<EOF
+</table>
+EOF
+
+ if [ -f /srv/http/tmp/index.html ]; then
+
+ cat <<EOF
+<table>
+<tr><th>Name</th><th>Fortschritt</th><th>bisherige Gr&ouml;&szlig;e</th></tr>
+EOF
+
+ OUTPUT=/srv/http/tmp/index.html backup-progress \
+ | tr -d '()' \
+ | awk '{print "<tr><td>" $1 "</td><td>" $2 " " $3 "</td><td>" $4 " " $5 "</td></tr>"}'
+
+ cat <<EOF
+</table>
+EOF
+
+ fi
+
+ cat <<EOF
+<h1>Status</h1>
+EOF
+ printf 'Bericht erstellt am %s um %s Uhr (%s).<br>\n' \
+ "$(
+ date '+%F'
+ )" \
+ "$(
+ date '+%H:%M:%S'
+ )" \
+ "$(
+ date '+%Z'
+ )"
+
+ cat <<EOF
+</body></html>
+EOF
+
+} | \
+ if mountpoint -q /srv/http/tmp; then
+ sponge /srv/http/tmp/index.html
+ else
+ cat
+ fi
diff --git a/print-status-html.service b/print-status-html.service
new file mode 100644
index 0000000..935792a
--- /dev/null
+++ b/print-status-html.service
@@ -0,0 +1,6 @@
+[Unit]
+Description=print status of raid as html
+
+[Service]
+Type=simple
+ExecStart=/root/print-status-html
diff --git a/print-status-html.timer b/print-status-html.timer
new file mode 100644
index 0000000..f91e2fe
--- /dev/null
+++ b/print-status-html.timer
@@ -0,0 +1,11 @@
+[Unit]
+Description=repeatedly print raid status as html
+
+[Timer]
+AccuracySec=1us
+RandomizedDelaySec=10min
+OnUnitInactiveSec=10min
+OnBootSec=2min
+
+[Install]
+WantedBy=timers.target
diff --git a/print-status.service b/print-status.service
new file mode 100644
index 0000000..3730aa7
--- /dev/null
+++ b/print-status.service
@@ -0,0 +1,6 @@
+[Unit]
+Description=print status of raid
+
+[Service]
+Type=simple
+ExecStart=/root/print-status
diff --git a/print-status.timer b/print-status.timer
new file mode 100644
index 0000000..b897dc9
--- /dev/null
+++ b/print-status.timer
@@ -0,0 +1,11 @@
+[Unit]
+Description=repeatedly print raid status
+
+[Timer]
+AccuracySec=1us
+RandomizedDelaySec=30sec
+OnUnitInactiveSec=30sec
+OnBootSec=1min
+
+[Install]
+WantedBy=timers.target