blob: 7f34a372ac390814ef7d99a0cf73ef8bec1c6f6b [file] [log] [blame]
package main
import (
"context"
mirko "code.hackerspace.pl/hscloud/go/mirko"
"code.hackerspace.pl/hscloud/go/statusz"
)
const statuszFragment = `
<style type="text/css">
.table td,th {
background-color: #eee;
padding: 0.2em 0.4em 0.2em 0.4em;
}
.table th {
background-color: #c0c0c0;
}
.table {
background-color: #fff;
border-spacing: 0.2em;
}
</style>
<div>
<b>Current leases:</b> {{ .Leases | len }}<br />
<table class="table">
<tr>
<th>IP Address</th>
<th>MAC Address</th>
<th>Start</th>
<th>End</th>
</tr>
{{range .Leases }}
<tr>
<td>{{ .IP }}</td>
<td>{{ .MAC }}</td>
<td>{{ .Start }}</td>
<td>{{ .End }}</td>
</tr>
{{end}}
</table>
</div>
`
type szLeases struct {
IP string
MAC string
Start string
End string
}
func (s *service) setupStatusz(m *mirko.Mirko) {
statusz.AddStatusPart("Leases", statuszFragment, func(ctx context.Context) interface{} {
c := make(chan []lease)
s.leaseC <- c
leases := <-c
ls := make([]szLeases, len(leases))
for i, l := range leases {
ls[i].IP = l.ip.String()
ls[i].MAC = l.hardware.String()
ls[i].Start = l.from.String()
ls[i].End = l.to.String()
}
return struct {
Leases []szLeases
}{
Leases: ls,
}
})
}