TEXT   49

Platten

Guest on 24th July 2022 03:43:36 PM

  1. #!/bin/ksh93
  2.  
  3. HOST=$(hostname)
  4.  
  5. typeset -A COLORS
  6. COLORS=( [ONLINE]="#00710f" [DEGRADED]="#ffe100" [FAULTED]="#df0404" \
  7.         [REMOVED]="#02cfbe" [OFFLINE]="#0000c0" [UNAVAIL]="#df0404" )
  8.  
  9. printf 'Content-type: text/html; charset=iso-8859-1
  10.  
  11. <html><head><title>Platten Status %s</title></head><body>
  12. <style type="text/css">
  13. ' "$HOST"
  14.  
  15. for STATE in ${!COLORS[@]} ; do
  16.         printf '.%s { color: %s; }\n' "$STATE" "${COLORS[$STATE]}"
  17. done
  18. print '</style>\n'
  19.  
  20. export LC_TIME=de LC_NUMERIC=de LC_MESSAGES=de
  21.  
  22. printf '<h1>Status der Platten-Pools von %s</h1>\n' "$HOST"
  23. POOLS="$(zpool list -H -o name)"
  24.  
  25. STATUS="ONLINE"
  26. zpool list -H -o health | sort -u | while read HEALTH ; do
  27.         case "$HEALTH" in
  28.                 DEGRADED) [ "$STATUS" == "ONLINE" ] && STATUS=DEGRADED ;;
  29.                 FAULTED|UNAVAIL) STATUS=FAULTED ;;
  30.                 REMOVED|OFFLINE) [ "$STATUS" == "ONLINE" ] && STATUS=OFFLINE ;;
  31.                 # ONLINE ignored
  32.         esac
  33. done
  34. printf '<p class="%s">%s</p>\n' "$STATUS" "$(zpool status -xv)"
  35.  
  36. print '<table><thead><tr><th>Pool</th><th>Größe</th><th>Belegt</th><th>Verfügbar</th><th>Kapazität</th><th>Status</th><th>Version</th></tr></thead>
  37. <tbody>
  38. '
  39. zpool list -H -o name,size,used,available,capacity,health,version | \
  40. while read LINE ; do
  41.         FIELDS=( ${LINE} )
  42.         CLASS="class=\"${FIELDS[5]}\""
  43.         printf "<tr><th>%s</th><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td ${CLASS}>%s</td><td>%s</td></tr>\n" ${LINE}
  44. done
  45. print '</tbody></table>'
  46.  
  47. print '<h2>Erweiterte Pool-Informationen</h2>'
  48. STATUS="$(zpool status)"
  49. printf "<pre>${STATUS//@(ONLINE|DEGRADED|FAULTED|REMOVED|OFFLINE|UNAVAIL)/<span class=\"\1\">\1</span>}</pre>"
  50.  
  51. print '
  52. <p>Zurück zur <a href="status">Status-Seite</a>.</p>
  53. </body></ht

Raw Paste


Login or Register to edit or fork this paste. It's free.