summaryrefslogtreecommitdiff
path: root/print-status-html
blob: 4babe0871d4ed54c0a7879d8b06d03ba968a4cbc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#!/bin/bash

. /etc/print-status.conf

{

  printf '<html><head><title>Status Of %s</title></head><body>\n' \
    "$(uname -n | cut -d. -f1)"

  if [ -n "${!watch_dirs[@]}" ]; then

    printf '%s\n' \
      '<h1>Partitions</h1>'

    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>"
    }'

  fi

  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
      }
      / is active\.$/ {
        s,.*,<font color="#808000">\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\n' \
    | sed 's@^md@@' \
    | sort -n \
    | while read -r md; do
      if [ -f "/sys/block/md${md}/md/mismatch_cnt" ]; then
        sed '
          s/^/md'"${md}"': /
          s/$/ mismatches/
          /^\S\+: 0 mismatches$/ {
            s,.*,<font color="#008000">\0</font>,
            b
          }
          s,.*,<font color="#800000">\0</font>,
        ' "/sys/block/md${md}/md/mismatch_cnt"
      else
        printf 'md%s\n' "${md}"
      fi
    done
  } \
    | sed '
      s/$/<br>/
    '

  if command -v ssacli >/dev/null 2>&1; then

    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>/
    '

  fi

  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 "${http_dir}/index.html" ]; then

    cat <<EOF
<table>
<tr><th>Name</th><th>Fortschritt</th><th>bisherige Gr&ouml;&szlig;e</th></tr>
EOF

    OUTPUT="${http_dir}/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 "${http_dir}"; then
    sponge "${http_dir}/index.html"
  else
    cat
  fi