diff --git a/syslogconf.go b/syslogconf.go new file mode 100644 index 0000000..87345fc --- /dev/null +++ b/syslogconf.go @@ -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 +} diff --git a/syslogmsgparts.go b/syslogmsgparts.go index 64fe22a..537264b 100644 --- a/syslogmsgparts.go +++ b/syslogmsgparts.go @@ -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)) +}