-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
syslogd.go
74 lines (69 loc) · 1.52 KB
/
syslogd.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package logger
/*
syslogをログに記録する
*/
import (
"encoding/json"
"log"
"time"
"github.com/twsnmp/twsnmpfc/datastore"
"github.com/twsnmp/twsnmpfc/report"
syslog "gopkg.in/mcuadros/go-syslog.v2"
)
func syslogd(stopCh chan bool) {
syslogCh := make(syslog.LogPartsChannel, 2000)
server := syslog.NewServer()
server.SetFormat(syslog.Automatic)
server.SetHandler(syslog.NewChannelHandler(syslogCh))
_ = server.ListenUDP("0.0.0.0:514")
_ = server.ListenTCP("0.0.0.0:514")
_ = server.Boot()
log.Printf("start syslogd")
for {
select {
case <-stopCh:
{
log.Printf("stop syslogd")
_ = server.Kill()
return
}
case sl := <-syslogCh:
{
if datastore.MapConf.AutoCharCode {
if c, ok := sl["content"].(string); ok {
sl["content"] = CheckCharCode(c)
}
}
s, err := json.Marshal(sl)
if err == nil {
tag, ok := sl["tag"].(string)
if !ok {
tag, ok = sl["app_name"].(string)
}
if ok {
switch tag {
case "twpcap":
report.ReportTWPCAP(sl)
case "twwinlog":
report.ReportTwWinLog(sl)
case "twBlueScan":
report.ReportTWBuleScan(sl)
case "twWifiScan":
report.ReportTWWifiScan(sl)
case "twSdrPower":
report.ReportTWSdrPower(sl)
}
}
logCh <- &datastore.LogEnt{
Time: time.Now().UnixNano(),
Type: "syslog",
Log: string(s),
}
report.UpdateSensor(sl["hostname"].(string), "syslog", 1)
} else {
log.Printf("syslogd err=%v", err)
}
}
}
}
}