Skip to content

Commit

Permalink
Merge pull request #6 from slacker87/master
Browse files Browse the repository at this point in the history
Getting updates from slacker87's fork
  • Loading branch information
rouben authored Jun 21, 2017
2 parents 3651b0a + 537a72b commit f7bca21
Show file tree
Hide file tree
Showing 11 changed files with 218 additions and 47 deletions.
4 changes: 2 additions & 2 deletions etc/zfswatcher.conf
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,8 @@ devstatecssclassmap = OFFLINE:text-warning REMOVED:text-error \
; used space bar display. The pseudo severity "none" can be used to specify
; the class when none of the usage levels specified in "usedspace" has
; been reached.
usedstatecssclassmap = none:bar-info info:bar-info notice:bar-warning \
err:bar-warning crit:bar-danger
usedstatecssclassmap = none:progress-bar-info info:progress-bar-info notice:progress-bar-warning \
err:progress-bar-warning crit:progress-bar-danger

;
; alternate root directory - formatted as /zfs
Expand Down
49 changes: 46 additions & 3 deletions webpagehandlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ package main

import (
"fmt"
"regexp"
auth "github.com/abbot/go-http-auth"
"github.com/damicon/zfswatcher/notifier"
"html/template"
"net/http"
"sync"
"time"
"sort"
"strings"
)

var templates *template.Template
Expand Down Expand Up @@ -145,7 +148,8 @@ type enclosureWeb struct {
Chassis45drives45l bool
Chassis45drives45 bool
Chassis45drives60 bool
Pools []*chassisStatusWeb
Drives1 []*devChassisStatusWeb
Drives2 []*devChassisStatusWeb
}

var (
Expand Down Expand Up @@ -246,7 +250,6 @@ func makeChassisStatusWeb(pool *PoolType) *chassisStatusWeb {
devw := devChassisStatusWeb{
Name: dev.name,
State: dev.state,
StateClass: cfg.Www.Devstatecssclassmap[dev.state],
}
devw.Indent = 1
for d := n; pool.devs[d].parentDev != -1; d = pool.devs[d].parentDev {
Expand Down Expand Up @@ -450,20 +453,60 @@ func enclosureHandler(w http.ResponseWriter, r *auth.AuthenticatedRequest) {
currentState.mutex.RUnlock()

var ws []*chassisStatusWeb
var wsx []*devChassisStatusWeb
var wsz []*devChassisStatusWeb

for n, s := range state {
ws = append(ws, makeChassisStatusWeb(s))
ws[n].N = n
}

regx, _ := regexp.Compile("^1-.*")
regy, _ := regexp.Compile("^2-.*")

for _, v := range ws {
for _, x := range v.Devs {
wsa := &devChassisStatusWeb{
Name: x.Name,
State: x.State,
}
if regx.MatchString(x.Name) {
wsx = append(wsx, wsa)
} else if regy.MatchString(x.Name) {
wsz = append(wsz, wsa)
}
}
}

sort.Slice(wsx, func(i, j int) bool {
switch strings.Compare(wsx[i].Name[:1], wsx[j].Name[:1]) {
case -1:
return true
case 1:
return false
}
return wsx[i].State > wsx[j].State
})

sort.Slice(wsz, func(i, j int) bool {
switch strings.Compare(wsz[i].Name[:1], wsz[j].Name[:1]) {
case -1:
return true
case 1:
return false
}
return wsz[i].State > wsz[j].State
})

ewd := &enclosureWeb{
ChassisEnable: cfg.Chassis.Enable,
Chassis45drives15: cfg.Chassis.Chassis45drives15,
Chassis45drives30: cfg.Chassis.Chassis45drives30,
Chassis45drives45l: cfg.Chassis.Chassis45drives45l,
Chassis45drives45: cfg.Chassis.Chassis45drives45,
Chassis45drives60: cfg.Chassis.Chassis45drives60,
Pools: ws,
Drives1: wsx,
Drives2: wsz,
}

err := templates.ExecuteTemplate(w, "enclosure.html", &webData{Nav: wn, Data: ewd})
Expand Down
1 change: 1 addition & 0 deletions www/resources/bootstrap/css/bootstrap-theme.min.css.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions www/resources/bootstrap/css/bootstrap.min.css.map

Large diffs are not rendered by default.

Binary file added www/resources/circles-and-roundabouts.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
82 changes: 82 additions & 0 deletions www/resources/zfswatcher.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
body {
background: transparent url("circles-and-roundabouts.png") repeat scroll 0% 0%;
}

.table-zfswatcher-dashboard th,
.table-zfswatcher-dashboard td {
vertical-align:middle;
Expand All @@ -7,3 +11,81 @@
margin-bottom: 0px;
min-width: 50px;
}

/* for enclosure drive status classes */
.enclosure45table {
border: 4px solid #3e3a3a;
border-top: 30px solid #3e3a3a;
border-bottom: 30vh solid #3e3a3a;
background-color: #3e3a3a;
border-collapse: separate !important;
border-spacing: 7px;
border-radius: 5px;
-webkit-box-shadow: 1px 1px 2px 2px rgba(0,0,0,0.2);
-moz-box-shadow: 1px 1px 2px 2px rgba(0,0,0,0.2);
box-shadow: 1px 1px 2px 2px rgba(0,0,0,0.2);
}

.enclosuretabletd {
border: 3px solid #3e3a3a;
text-align: center;
padding-top: 5%;
padding-bottom: 5%;
min-width: 4vw;
border-radius: 12px 12px 12px 12px;
-moz-border-radius: 12px 12px 12px 12px;
-webkit-border-radius: 12px 12px 12px 12px;
-webkit-box-shadow: 1px 1px 1px 1px rgba(0,0,0,0.2);
-moz-box-shadow: 1px 1px 1px 1px rgba(0,0,0,0.2);
box-shadow: 1px 1px 1px 1px rgba(0,0,0,0.2);
}

.isONLINE {
background-color: #148614;
color: #d1d1d1;
}

.isOFFLINE {
background-color: : #2d2a2a;
color: #d1d1d1;
}

.isREMOVED {
background-color: : #e69d17;
color: #d1d1d1;
}

.isFAULTED {
background-color: : #e73737;
color: #d1d1d1;
}

.isSPLIT {
background-color: : #e69d17;
color: #d1d1d1;
}

.isUNAVAIL {
background-color: : #2d2a2a;
color: #d1d1d1;
}

.isDEGRADED {
background-color: : #e69d17;
color: #d1d1d1;
}

.isUNKNOWN {
background-color: : #656161;
color: #d1d1d1;
}

.isINUSE {
background-color: : #e69d17;
color: #d1d1d1;
}

.isAVAIL {
background-color: #1c691c;
color: #d1d1d1;
}
4 changes: 2 additions & 2 deletions www/templates/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
<a href="{{ .Root }}/usage/{{ .Name }}">
<div class="progress progress-zfswatcher-dashboard">
{{ if or .UsedPercent .AvailPercent }}
<div class="bar {{ .UsedClass }}" style="width: {{ .UsedPercent }}%"></div>
<div class="bar bar-success" style="width: {{ .AvailPercent }}%"></div>
<div class="progress-bar {{ .UsedClass }}" style="width: {{ .UsedPercent }}%"></div>
<div class="progress-bar progress-bar-success" style="width: {{ .AvailPercent }}%"></div>
{{ end }}
</div>
</a>
Expand Down
118 changes: 81 additions & 37 deletions www/templates/enclosure.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{{ template "header.html" .Nav }}
{{ with .Data }}
{{ if .ChassisEnable }}
<div class="page-header" style="margin: 0px;">
{{ if .Chassis45drives15 }}
<h3 align="center">45Drives AV15</h3>
{{ end }}
Expand All @@ -11,52 +12,95 @@ <h3 align="center">45Drives Q30</h3>
<h3 align="center">45Drives S45 lite</h3>
{{ end }}
{{ if .Chassis45drives45 }}
<h3 align="center">45Drives S45</h3>
{{ if .Pools }}
<table class="table table-zfswatcher-dashboard table-hover">
<thead>
<tr>
<th style="width: 5%"></th>
<th style="width: 5%"></th>
<th style="width: 5%"></th>
<th style="width: 5%"></th>
<th style="width: 5%"></th>
<th style="width: 5%"></th>
<th style="width: 5%"></th>
<th style="width: 5%"></th>
<th style="width: 5%"></th>
<th style="width: 5%"></th>
<th style="width: 5%"></th>
<th style="width: 5%"></th>
<th style="width: 5%"></th>
<th style="width: 5%"></th>
<th style="width: 5%"></th>
</tr>
</thead>
<h1 align="center">45Drives S45 Enclosure
</h1>
<h2 align="center"><small>Front of unit</small></h2>
<table class="enclosure45table" align="center">
<tbody>
{{ range .Pools }}
<tr>
{{ range .Devs }}
<td>{{ .Name }}{{ .State }}</td>
{{ end }}
<td id="drive1-1" class="enclosuretabletd"></td>
<td id="drive1-2" class="enclosuretabletd"></td>
<td id="drive1-3" class="enclosuretabletd"></td>
<td id="drive1-4" class="enclosuretabletd"></td>
<td id="drive1-5" class="enclosuretabletd"></td>
<td id="drive1-6" class="enclosuretabletd"></td>
<td id="drive1-7" class="enclosuretabletd"></td>
<td id="drive1-8" class="enclosuretabletd"></td>
<td id="drive1-9" class="enclosuretabletd"></td>
<td id="drive1-10" class="enclosuretabletd"></td>
<td id="drive1-11" class="enclosuretabletd"></td>
<td id="drive1-12" class="enclosuretabletd"></td>
<td id="drive1-13" class="enclosuretabletd"></td>
<td id="drive1-14" class="enclosuretabletd"></td>
<td id="drive1-15" class="enclosuretabletd"></td>
</tr>
<tr>
<td id="drive2-6" class="enclosuretabletd"></td>
<td id="drive2-5" class="enclosuretabletd"></td>
<td id="drive2-4" class="enclosuretabletd"></td>
<td id="drive2-3" class="enclosuretabletd"></td>
<td id="drive2-2" class="enclosuretabletd"></td>
<td id="drive2-1" class="enclosuretabletd"></td>
<td id="drive1-24" class="enclosuretabletd"></td>
<td id="drive1-23" class="enclosuretabletd"></td>
<td id="drive1-22" class="enclosuretabletd"></td>
<td id="drive1-21" class="enclosuretabletd"></td>
<td id="drive1-20" class="enclosuretabletd"></td>
<td id="drive1-19" class="enclosuretabletd"></td>
<td id="drive1-18" class="enclosuretabletd"></td>
<td id="drive1-17" class="enclosuretabletd"></td>
<td id="drive1-16" class="enclosuretabletd"></td>
</tr>
<tr>
<td id="drive2-7" class="enclosuretabletd"></td>
<td id="drive2-8" class="enclosuretabletd"></td>
<td id="drive2-9" class="enclosuretabletd"></td>
<td id="drive2-10" class="enclosuretabletd"></td>
<td id="drive2-11" class="enclosuretabletd"></td>
<td id="drive2-12" class="enclosuretabletd"></td>
<td id="drive2-13" class="enclosuretabletd"></td>
<td id="drive2-14" class="enclosuretabletd"></td>
<td id="drive2-15" class="enclosuretabletd"></td>
<td id="drive2-16" class="enclosuretabletd"></td>
<td id="drive2-17" class="enclosuretabletd"></td>
<td id="drive2-18" class="enclosuretabletd"></td>
<td id="drive2-19" class="enclosuretabletd"></td>
<td id="drive2-20" class="enclosuretabletd"></td>
<td id="drive2-21" class="enclosuretabletd"></td>
</tr>
{{ end }}
</tbody>
</table>
{{ else }}
<div class="alert alert-info">
There are no pools.
</div>
{{ end }}
{{ else }}
<div class="alert alert-error">
Enclosure detection has not been enabled in config
</div>
{{ end }}

<script type="text/javascript">
var drive1 = [
{{range .Drives1}}
{{.}},
{{end}}
];
var drive2 = [
{{range .Drives2}}
{{.}},
{{end}}
];
for (i = 0; i < 24; i++) {
$("#drive1-"+[i+1]).append("<span class=is"+drive1[i].State+"><kbd>"+drive1[i].Name+"</kbd></span>");
$("#drive1-"+[i+1]).addClass("is"+drive1[i].State);
};
for (i = 0; i < 21; i++) {
$("#drive2-"+[i+1]).append("<span class=is"+drive2[i].State+"><kbd>"+drive2[i].Name+"</kbd></span>");
$("#drive2-"+[i+1]).addClass("is"+drive2[i].State);
};
</script>
{{ end }}
{{ if .Chassis45drives60 }}
<h3 align="center">45Drives XL60</h3>
{{ end }}
</div>
{{ else }}
<div class="alert alert-error">
Enclosure detection has not been enabled in config
</div>
{{ end }}

{{ end }}
{{ template "footer.html" .Nav }}
1 change: 0 additions & 1 deletion www/templates/footer.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
</div> <!-- /row-fluid -->
</div> <!-- /container -->

<script src="{{ .Root }}/resources/bootstrap/js/jquery.min.js"></script>
<script src="{{ .Root }}/resources/bootstrap/js/bootstrap.min.js"></script>

</body>
Expand Down
1 change: 1 addition & 0 deletions www/templates/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
</style>
<link href="{{ .Root }}/resources/zfswatcher.css" rel="stylesheet">
<link href="{{ .Root }}/resources/favicon.ico" rel="shortcut icon">
<script src="{{ .Root }}/resources/bootstrap/js/jquery.min.js"></script>
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
Expand Down
4 changes: 2 additions & 2 deletions www/templates/status-pool.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@
{{ if .Locate }}
<input type="hidden" name="dev" value="{{ .Name }}">
<input type="hidden" name="state" value="off">
<button type="submit" class="btn btn-mini btn-warning">
<button type="submit" class="btn btn-sm btn-warning">
</button>
{{ else }}
<input type="hidden" name="dev" value="{{ .Name }}">
<input type="hidden" name="state" value="on">
<button type="submit" class="btn btn-mini">
<button type="submit" class="btn btn-sm">
</button>
{{ end }}
Expand Down

0 comments on commit f7bca21

Please sign in to comment.