|
@@ -6,19 +6,15 @@ import (
|
|
|
"os"
|
|
|
"time"
|
|
|
|
|
|
+ "git.lattuga.net/boyska/circolog/data"
|
|
|
"git.lattuga.net/boyska/circolog/filtering"
|
|
|
"gopkg.in/mcuadros/go-syslog.v2/format"
|
|
|
)
|
|
|
|
|
|
-// Message is currently an alias for format.Logparts, but this is only temporary; sooner or later, a real struct will be used
|
|
|
-// The advantage of having an explicit Message is to clear out what data we are sending to circolog "readers"
|
|
|
-// This is not necessarily (and not in practice) the same structure that we receive from logging programs
|
|
|
-type Message format.LogParts
|
|
|
-
|
|
|
// Client represent a client connected via websocket. Its most important field is the messages channel, where
|
|
|
// new messages are sent.
|
|
|
type Client struct {
|
|
|
- Messages chan Message // only hub should write/close this
|
|
|
+ Messages chan data.Message // only hub should write/close this
|
|
|
Options ClientOptions
|
|
|
}
|
|
|
|
|
@@ -106,7 +102,7 @@ func (h *Hub) register(cl Client) {
|
|
|
item := buf.Value
|
|
|
if item != nil {
|
|
|
select { // send with short timeout
|
|
|
- case cl.Messages <- item.(Message):
|
|
|
+ case cl.Messages <- item.(data.Message):
|
|
|
break
|
|
|
case <-time.After(500 * time.Millisecond):
|
|
|
close(cl.Messages)
|
|
@@ -123,30 +119,6 @@ func (h *Hub) register(cl Client) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// logEntryToMessage converts messages received from writers to the format we promise to readers
|
|
|
-func logEntryToMessage(orig format.LogParts) Message {
|
|
|
- m := Message{}
|
|
|
- if orig["version"] == 1 { // RFC5424
|
|
|
- m["prog"] = orig["app_name"]
|
|
|
- m["client"] = orig["client"]
|
|
|
- m["host"] = orig["hostname"]
|
|
|
- m["proc_id"] = orig["proc_id"]
|
|
|
- m["msg"] = orig["message"]
|
|
|
- m["facility"] = orig["facility"]
|
|
|
- m["time"] = orig["timestamp"]
|
|
|
- m["sev"] = orig["severity"]
|
|
|
- } else { //RFC3164
|
|
|
- m["prog"] = orig["tag"]
|
|
|
- m["client"] = orig["client"]
|
|
|
- m["host"] = orig["hostname"]
|
|
|
- m["msg"] = orig["content"]
|
|
|
- m["sev"] = orig["severity"]
|
|
|
- m["time"] = orig["timestamp"]
|
|
|
- m["proc_id"] = "-"
|
|
|
- }
|
|
|
- return m
|
|
|
-}
|
|
|
-
|
|
|
// Run is hub main loop; keeps everything going
|
|
|
func (h *Hub) Run() {
|
|
|
active := true
|
|
@@ -162,8 +134,8 @@ func (h *Hub) Run() {
|
|
|
delete(h.clients, cl)
|
|
|
}
|
|
|
case msg := <-h.LogMessages:
|
|
|
- if active == true && filter.Validate(msg) {
|
|
|
- newmsg := logEntryToMessage(msg)
|
|
|
+ newmsg := data.LogEntryToMessage(msg)
|
|
|
+ if active == true && filter.Validate(newmsg) {
|
|
|
h.circbuf.Value = newmsg
|
|
|
h.circbuf = h.circbuf.Next()
|
|
|
for client := range h.clients {
|