1
0
Fork 0
forked from boyska/circolog

Compare commits

...

9 commits

6 changed files with 109 additions and 6 deletions

3
.gitmodules vendored Normal file
View file

@ -0,0 +1,3 @@
[submodule "vendor/gopkg.in/mcuadros/go-syslog.v2"]
path = vendor/gopkg.in/mcuadros/go-syslog.v2
url = https://github.com/boyska/go-syslog

View file

@ -57,11 +57,14 @@ func main() {
addr := flag.String("addr", "localhost:9080", "http service address")
querySocket := flag.String("socket", "", "Path to a unix domain socket for the HTTP server")
backlogLimit := flag.Int("n", -1, "Limit the backlog length, defaults to no limit (-1)")
var format formatter.Format
format = formatter.FormatSyslog
flag.Var(&format, "fmt", "Output format [syslog|json]")
var filter filtering.ExprValue
flag.Var(&filter, "where", "sql-like query to filter logs")
// TODO: change to color-mode=auto/no/always
hasColor := BoolAuto_AUTO
flag.Var(&hasColor, "color", "dis/enable colors")
flag.Var(&hasColor, "color", "dis/enable colors; yes/no/auto")
flag.Parse()
if hasColor == BoolAuto_NO || (!isatty.IsTerminal(os.Stdout.Fd()) && hasColor != BoolAuto_YES) {
@ -120,11 +123,13 @@ func main() {
if !filter.Validate(parsed) {
continue
}
if err := formatter.WriteFormatted(os.Stdout, formatter.FormatSyslog, parsed); err != nil {
if err := formatter.WriteFormatted(os.Stdout, format, parsed); err != nil {
log.Println("error printing", err)
}
if format == formatter.FormatSyslog { // oops
fmt.Println()
}
}
}()
for {

58
data/data_test.go Normal file
View file

@ -0,0 +1,58 @@
package data
import (
"testing"
"time"
"gopkg.in/mcuadros/go-syslog.v2/format"
)
var timeNow = time.Now()
var returnValues = map[string]interface{}{
"prog": "test_app",
"client": "test_client",
"host": "my_machine",
"msg": "test message",
"sev": 3,
"time": timeNow,
}
var msgRFC5424 = format.LogParts{
"version": 1,
"app_name": returnValues["prog"],
"client": returnValues["client"],
"hostname": returnValues["host"],
"proc_id": "spam_process",
"message": returnValues["msg"],
"facility": "hell",
"timestamp": returnValues["time"],
"severity": returnValues["sev"],
}
var msgRFC3164 = format.LogParts{
"tag": returnValues["prog"],
"client": returnValues["client"],
"hostname": returnValues["host"],
"content": returnValues["msg"],
"severity": returnValues["sev"],
"timestamp": returnValues["time"],
"proc_id": "spam_process",
}
var testMessages = []format.LogParts{
msgRFC5424,
msgRFC3164,
}
func TestLogEntryToMessage(t *testing.T) {
for _, msg := range testMessages {
parsedMsg := LogEntryToMessage(msg)
for key, value := range returnValues {
if data, ok := parsedMsg[key]; !ok || data != value {
t.Errorf("Missing/wrong key: %s\nmsg: %s\nparsed msg: %s\n", key, value, data)
}
}
}
}

View file

@ -27,6 +27,41 @@ endless, we tried to document some common setups.
#### Use Case: circologd receiving messages from syslog-ng
Put this in `/etc/syslog-ng/conf.d/circolog.conf`
```
destination d_circolog {
unix-dgram("/run/circolog/syslog.sock"
flags(syslog-protocol)
);
};
log { source(s_src); destination(d_circolog); };
```
This doesn't tell syslog-ng not to log to disk.
Change `/etc/syslog-ng.conf` according to your need.
#### Use Case: circologd receiving messages from rsyslog
rsyslogd can easily be configured to send every message to circolog:
```
$ModLoad omuxsock
$OMUxSockSocket /tmp/circolog.sock
*.* :omuxsock:
```
If you want to force messages of level `debug` and `info` not to be logged to disk, you can put this snippet
at the **top** of the rules
```
$ModLoad omuxsock
$OMUxSockSocket /tmp/circolog.sock
*.* :omuxsock:
*.=debug;*.=info stop
```
#### Use Case: circologd receiving messages from journald
[TODO: il codice va ancora scritto: bisogna bindare /run/systemd/journal/syslog

View file

@ -3,11 +3,12 @@ package circolog
import (
"testing"
"git.lattuga.net/boyska/circolog/data"
"gopkg.in/mcuadros/go-syslog.v2/format"
)
func msg(s string) format.LogParts {
return format.LogParts{"text": s}
return format.LogParts{"content": s}
}
func hubCount(h Hub) int {
@ -19,10 +20,10 @@ var DefaultClient ClientOptions = ClientOptions{Nofollow: true, BacklogLength: -
func hubToArrayOpt(h Hub, opt ClientOptions) []string {
r := make([]string, 0)
cl := Client{Options: opt}
cl.Messages = make(chan format.LogParts)
cl.Messages = make(chan data.Message)
h.Register <- cl
for m := range cl.Messages {
r = append(r, m["text"].(string))
r = append(r, m["msg"].(string))
}
return r
}

1
vendor/gopkg.in/mcuadros/go-syslog.v2 generated vendored Submodule

@ -0,0 +1 @@
Subproject commit a127d826d6c27489d377b3c080bd256d8f8093a6