Logging Web Interface
**Work in progress**
This commit is contained in:
parent
fa90dac953
commit
ea02452abc
31
Log/DeviceDatabase/ReadCustom.go
Normal file
31
Log/DeviceDatabase/ReadCustom.go
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
package DeviceDatabase
|
||||||
|
|
||||||
|
import (
|
||||||
|
"gopkg.in/mgo.v2/bson"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ReadCustom(timeRange, logLevel, logCategory, logImpact, logSeverity, logMessageName, logSender, logPage string) (events []LogDBEntry) {
|
||||||
|
|
||||||
|
//
|
||||||
|
// TODO => Is currently stub
|
||||||
|
//
|
||||||
|
|
||||||
|
query := logDBCollection.Find(bson.D{}).Sort(`-TimeUTC`).Limit(26)
|
||||||
|
count := 26
|
||||||
|
|
||||||
|
if n, err := query.Count(); err == nil {
|
||||||
|
count = n
|
||||||
|
}
|
||||||
|
|
||||||
|
iter := query.Iter()
|
||||||
|
entry := LogDBEntry{}
|
||||||
|
pos := 0
|
||||||
|
events = make([]LogDBEntry, count)
|
||||||
|
|
||||||
|
for iter.Next(&entry) {
|
||||||
|
events[pos] = entry
|
||||||
|
pos++
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/SommerEngineering/Ocean/MimeTypes"
|
"github.com/SommerEngineering/Ocean/MimeTypes"
|
||||||
"github.com/SommerEngineering/Ocean/Shutdown"
|
"github.com/SommerEngineering/Ocean/Shutdown"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func HandlerWebLog(response http.ResponseWriter, request *http.Request) {
|
func HandlerWebLog(response http.ResponseWriter, request *http.Request) {
|
||||||
@ -34,7 +35,49 @@ func HandlerWebLog(response http.ResponseWriter, request *http.Request) {
|
|||||||
} else {
|
} else {
|
||||||
|
|
||||||
// Custom view
|
// Custom view
|
||||||
data.Events = readCustom(request.FormValue(`timeRange`), request.FormValue(`Level`), request.FormValue(`Category`), request.FormValue(`Impact`), request.FormValue(`Severity`), request.FormValue(`MSGName`), request.FormValue(`Sender`), request.FormValue(`CurrentPage`))
|
currentLevel := request.FormValue(`Level`)
|
||||||
|
currentTimeRange := request.FormValue(`timeRange`)
|
||||||
|
currentCategory := request.FormValue(`Category`)
|
||||||
|
currentImpact := request.FormValue(`Impact`)
|
||||||
|
currentSeverity := request.FormValue(`Severity`)
|
||||||
|
currentMessageName := request.FormValue(`MSGName`)
|
||||||
|
currentSender := request.FormValue(`Sender`)
|
||||||
|
currentPage := request.FormValue(`CurrentPage`)
|
||||||
|
currentLiveView := request.FormValue(`LiveView`)
|
||||||
|
|
||||||
|
data.Events = readCustom(currentTimeRange, currentLevel, currentCategory, currentImpact, currentSeverity, currentMessageName, currentSender, currentPage)
|
||||||
|
|
||||||
|
if strings.ToLower(currentLiveView) == `true` {
|
||||||
|
data.SetLiveView = true
|
||||||
|
}
|
||||||
|
|
||||||
|
if currentLevel != `` {
|
||||||
|
data.CurrentLevel = currentLevel
|
||||||
|
} else {
|
||||||
|
data.CurrentLevel = `*`
|
||||||
|
}
|
||||||
|
|
||||||
|
if currentTimeRange != `` {
|
||||||
|
data.CurrentTimeRange = currentTimeRange
|
||||||
|
} else {
|
||||||
|
data.CurrentTimeRange = `*`
|
||||||
|
}
|
||||||
|
|
||||||
|
if currentCategory != `` {
|
||||||
|
data.CurrentCategory = currentCategory
|
||||||
|
} else {
|
||||||
|
data.CurrentCategory = `*`
|
||||||
|
}
|
||||||
|
|
||||||
|
if currentImpact != `` {
|
||||||
|
data.CurrentImpact = currentImpact
|
||||||
|
} else {
|
||||||
|
data.CurrentImpact = `*`
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// TODO
|
||||||
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
MimeTypes.Write2HTTP(response, MimeTypes.TypeWebHTML)
|
MimeTypes.Write2HTTP(response, MimeTypes.TypeWebHTML)
|
||||||
|
@ -1,13 +1,30 @@
|
|||||||
package Web
|
package Web
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/SommerEngineering/Ocean/Log/DeviceDatabase"
|
||||||
"github.com/SommerEngineering/Ocean/Log/Web/Scheme"
|
"github.com/SommerEngineering/Ocean/Log/Web/Scheme"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func readCustom(timeRange, logLevel, logCategory, logImpact, logSeverity, logMessageName, logSender, logPage string) (events []Scheme.LogEvent) {
|
func readCustom(timeRange, logLevel, logCategory, logImpact, logSeverity, logMessageName, logSender, logPage string) (events []Scheme.LogEvent) {
|
||||||
// data.Events = make([]Scheme.LogEvent, 3)
|
|
||||||
// data.Events[0].AB = Scheme.A
|
eventsFromDB := DeviceDatabase.ReadCustom(timeRange, logLevel, logCategory, logImpact, logSeverity, logMessageName, logSender, logPage)
|
||||||
// data.Events[0].LogLevel = Scheme.LogINFO
|
count := len(eventsFromDB)
|
||||||
// data.Events[0].LogLine = `hello world`
|
events = make([]Scheme.LogEvent, count)
|
||||||
|
|
||||||
|
for n := 0; n < count; n++ {
|
||||||
|
eventFromDB := eventsFromDB[n]
|
||||||
|
events[n] = Scheme.LogEvent{}
|
||||||
|
events[n].LogLine = eventFromDB.Format()
|
||||||
|
events[n].LogLevel = fmt.Sprintf("log%s", strings.ToLower(eventFromDB.Level[2:]))
|
||||||
|
|
||||||
|
if n%2 == 0 {
|
||||||
|
events[n].AB = Scheme.B
|
||||||
|
} else {
|
||||||
|
events[n].AB = Scheme.A
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,19 @@
|
|||||||
package Scheme
|
package Scheme
|
||||||
|
|
||||||
type Viewer struct {
|
type Viewer struct {
|
||||||
Title string
|
Title string
|
||||||
SetLiveView bool
|
SetLiveView bool
|
||||||
MessageNames []string
|
CurrentLevel string
|
||||||
Sender []string
|
CurrentTimeRange string
|
||||||
Events []LogEvent
|
CurrentCategory string
|
||||||
|
CurrentImpact string
|
||||||
|
CurrentSeverity string
|
||||||
|
CurrentMessageName string
|
||||||
|
CurrentSender string
|
||||||
|
CurrentPage string
|
||||||
|
MessageNames []string
|
||||||
|
Sender []string
|
||||||
|
Events []LogEvent
|
||||||
}
|
}
|
||||||
|
|
||||||
// <li class="logline loga logwarn">
|
// <li class="logline loga logwarn">
|
||||||
|
@ -10,7 +10,7 @@ var Viewer string = `
|
|||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<title>{{.Title}}</title>
|
<title>{{.Title}}</title>
|
||||||
{{if .SetLiveView}}
|
{{if .SetLiveView}}
|
||||||
<meta http-equiv="refresh" content="30; URL=/log">
|
<meta http-equiv="refresh" content="30; URL=/log?LiveView={{.SetLiveView}}">
|
||||||
{{end}}
|
{{end}}
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<meta name="generator" content="Webflow">
|
<meta name="generator" content="Webflow">
|
||||||
@ -27,7 +27,14 @@ var Viewer string = `
|
|||||||
<div class="w-row">
|
<div class="w-row">
|
||||||
<div class="w-col w-col-6">
|
<div class="w-col w-col-6">
|
||||||
<h2 class="headercontrol">Options</h2>
|
<h2 class="headercontrol">Options</h2>
|
||||||
<div class="options"><a class="button optionbuttons" href="#">Enable live view</a>
|
<div class="options">
|
||||||
|
<a class="button optionbuttons" href="#">
|
||||||
|
{{if .SetLiveView}}
|
||||||
|
Disable live view
|
||||||
|
{{else}}
|
||||||
|
Enable live view
|
||||||
|
{{end}}
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="w-col w-col-6">
|
<div class="w-col w-col-6">
|
||||||
|
Loading…
Reference in New Issue
Block a user