Skip to content

Commit

Permalink
Initiate syslogconf development
Browse files Browse the repository at this point in the history
  • Loading branch information
g41797 committed Oct 28, 2023
1 parent 8a8a1d1 commit ffb6dfd
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 0 deletions.
83 changes: 83 additions & 0 deletions syslogconf.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package syslogsidecar

import "strconv"

var fis = map[int]string{
0: "kern",
1: "user",
2: "mail",
3: "daemon",
4: "auth",
5: "syslog",
6: "lpr",
7: "news",
8: "uucp",
9: "cron",
10: "authpriv",
11: "ftp",
16: "local0",
17: "local1",
18: "local2",
19: "local3",
20: "local4",
21: "local5",
22: "local6",
23: "local7",
}

var sis = map[int]string{
0: "emerg",
1: "alert",
2: "crit",
3: "err",
4: "warning",
5: "notice",
6: "info",
7: "debug",
}

func facsev(priority string) (facility, severiry string) {
if len(priority) == 0 {
return "", ""
}

prval, _ := strconv.Atoi(priority)

facility, _ = fis[prval/8]
severiry, _ = sis[prval%8]

return
}

var fsi = swap(fis)
var ssi = swap(sis)

func swap(in map[int]string) map[string]int {
result := make(map[string]int)

for key, val := range fis {
result[val] = key
}

return result
}

func isFacility(fac string) bool {
if len(fac) == 0 {
return false
}

_, ok := fsi[fac]

return ok
}

func isSeverity(sev string) bool {
if len(sev) == 0 {
return false
}

_, ok := ssi[sev]

return ok
}
18 changes: 18 additions & 0 deletions syslogmsgparts.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,21 @@ func toMsg(logParts format.LogParts) sputnik.Msg {
return msg

}

func (mp *syslogmsgparts) priority() (string, error) {
mp.rewind()

count, _ := mp.runeAt(0)

if int(count) <= badMessageParts {
return "", fmt.Errorf("non rfc message")
}

rfclen, _ := mp.runeAt(1)

mp.skip(int(count + rfclen + 1))

prlen, _ := mp.runeAt(2)

return mp.part(int(prlen))
}

0 comments on commit ffb6dfd

Please sign in to comment.