File tree Expand file tree Collapse file tree 3 files changed +34
-22
lines changed Expand file tree Collapse file tree 3 files changed +34
-22
lines changed Original file line number Diff line number Diff line change 1+ package main
2+
3+ // Sets the bit at pos in the integer n
4+ // Author: Kevin Burke
5+ func setBit (n int , pos uint ) int {
6+ n |= (1 << pos )
7+ return n
8+ }
9+
10+ // Clears the bit at pos in n
11+ // Author: Kevin Burke
12+ func clearBit (n int , pos uint ) int {
13+ mask := ^ (1 << pos )
14+ n &= mask
15+ return n
16+ }
17+
18+ // check if number has bit
19+ // Author: Kevin Burke
20+ func hasBit (n int , pos uint ) bool {
21+ val := n & (1 << pos )
22+ return (val > 0 )
23+ }
Original file line number Diff line number Diff line change @@ -69,13 +69,15 @@ func parseConfiguration() {
6969 panic (fmt .Sprintf ("Unable to parse configuration file %s: %v" , opts .Configuration , err .Error ()))
7070 }
7171
72- if configuration . Syslog . Path != "" {
73- configuration .Syslog .Filter .facility = 255
72+ // set internal defaults
73+ configuration .Syslog .Filter .facility = 9223372036854775807
7474
75+ // init syslog configuration
76+ if configuration .Syslog .Path != "" {
7577 // Facility filter
7678 for _ , facility := range strings .Split (configuration .Syslog .Filter .Facility , "," ) {
7779 if facilityId , ok := SyslogFacilityMap [facility ]; ok {
78- configuration .Syslog .Filter .facility -= facilityId
80+ configuration .Syslog .Filter .facility = clearBit ( configuration . Syslog . Filter . facility , uint ( facilityId ))
7981 }
8082 }
8183 }
Original file line number Diff line number Diff line change @@ -37,23 +37,6 @@ var SyslogFacilityMap = map[string]int {
3737 "console" : 14 ,
3838}
3939
40- var SyslogFacilityLookup = map [int ]string {
41- 0 : "kern" ,
42- 1 : "user" ,
43- 2 : "mail" ,
44- 3 : "daemon" ,
45- 4 : "auth" ,
46- 5 : "syslog" ,
47- 6 : "lpr" ,
48- 7 : "news" ,
49- 8 : "uucp" ,
50- 9 : "cron" ,
51- 10 : "authpriv" ,
52- 11 : "ftp" ,
53- 12 : "ntp" ,
54- 13 : "security" ,
55- 14 : "console" ,
56- }
5740
5841func handleSyslog () {
5942 LoggerStdout .Verbose (fmt .Sprintf (" -> starting syslog daemon (%s)" , configuration .Syslog .Path ))
@@ -75,13 +58,17 @@ func handleSyslog() {
7558
7659 go func (channel syslog.LogPartsChannel ) {
7760 for logParts := range channel {
61+ facilityId := uint (logParts ["facility" ].(int ))
62+
7863 // facility filter
79- if configuration .Syslog .Filter .facility & logParts [ "facility" ].( int ) == 0 {
64+ if hasBit ( configuration .Syslog .Filter .facility , facilityId ) == false {
8065 continue
8166 }
8267
68+ //fmt.Println(logParts)
69+
8370 // build message
84- message := logParts ["content" ]
71+ message := fmt . Sprintf ( "%s %s" , logParts ["hostname" ], logParts [ " content" ])
8572
8673 // custom template
8774 if configuration .Syslog .Output .Template != "" {
You can’t perform that action at this time.
0 commit comments