summaryrefslogtreecommitdiff
path: root/print-status-html
blob: 2092700e5a92b4d0fa773be350f389c3af2cd8b2 (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
207
208
209
210
211
212
213
214
215
216
#!/bin/bash

. /etc/print-status.conf

{

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

  if [ "${#watch_dirs[@]}" -gt 0 ]; 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

  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>/
      1i <h1>Crypt Devices</h1>
    '

  if [ -f /proc/mdstat ]; then

    cat <<EOF
<h1>Software RAIDs</h1>
EOF

    {
      sed -n '
        /^Personalities/d
        /^\S/ {
          N
          s/^\(\S\+\)\s*:\s*\(\S\+\)\s.*\n\s*\([0-9]\)/\1: \2 \3/
          T
          p
        }
        s/^\s\+\(\[[^][]\+]\)\s\+\(\S\+\)\s\+=\s\+\(\S\+\)\s\+\S\+\s\+\(finish=\S\+\)\s.*$/\2 \3 \1 \4/
        T
        p
      ' /proc/mdstat \
      | sed '
        s/^md\([0-9]\+\):/\1 \0/
      ' \
      | sort -k1n,1 \
      | sed '
        s/^\([0-9]\+\) md\1:/md\1:/
      ' \
      | 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,^\(.* \)active \(.*\[U\+\]\)$,<font color="#008000">\1\2</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,^\(.* \)active \(.*\)$,<font color="#008000">\1\2</font>,
        t
        s,^.*$,<font color="#800000">\0</font>,
      '

      find /sys/block/ \
        -mindepth 1 \
        -maxdepth 1 \
        -name 'md*' \
        -exec sh -c 'test -f "{}/md/mismatch_cnt"' \; \
        -printf '%f: ' \
        -exec cat '{}/md/mismatch_cnt' \; \
      | sed 's@^md\([0-9]\+\): @\1 \0@' \
      | sort -k1n,1 \
      | sed 's@^\S\+ @@' \
      | sed '
        s@^\S\+: 0$@<font color="#008000">\0</font>@
        t
        s@^.*$@<font color="#800000">\0</font>@
      '
    } \
      | sed '
        s/$/<br>/
      '

  fi

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

    cat <<EOF
<h1>Hardware RAIDs</h1>
EOF

    ssacli controller all show \
    | awk '$1 == "Smart" && $2 == "Array" {print $6}' \
    | xargs -rI __ ssacli ctrl slot=__ 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>Network</h1>
<img src="/vnstat.png">
<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