syslog filter could take several filters
This commit is contained in:
parent
04ada45f44
commit
69594c2fe4
4 changed files with 48 additions and 23 deletions
|
|
@ -14,7 +14,7 @@ func declareFlags(o *Config) {
|
|||
flag.StringVar(&o.ARPTablePath, "arp-table-path", "/proc/net/arp", "Path to ARP table file")
|
||||
flag.BoolVar(&o.SyslogEnabled, "syslog-enabled", false, "Enable syslog tailing for iwd messages")
|
||||
flag.StringVar(&o.SyslogPath, "syslog-path", "/var/log/messages", "Path to syslog file")
|
||||
flag.StringVar(&o.SyslogFilter, "syslog-filter", "daemon.info iwd:", "Filter string for syslog lines")
|
||||
flag.Var(&StringArray{&o.SyslogFilter}, "daemon.info iwd:", "Filter string for syslog lines")
|
||||
flag.StringVar(&o.SyslogSource, "syslog-source", "iwd", "Source name for syslog entries in logs")
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,16 +9,16 @@ import (
|
|||
)
|
||||
|
||||
type Config struct {
|
||||
Bind string
|
||||
WifiInterface string
|
||||
WifiBackend string
|
||||
UseARPDiscovery bool
|
||||
DHCPLeasesPath string
|
||||
ARPTablePath string
|
||||
SyslogEnabled bool
|
||||
SyslogPath string
|
||||
SyslogFilter string
|
||||
SyslogSource string
|
||||
Bind string
|
||||
WifiInterface string
|
||||
WifiBackend string
|
||||
UseARPDiscovery bool
|
||||
DHCPLeasesPath string
|
||||
ARPTablePath string
|
||||
SyslogEnabled bool
|
||||
SyslogPath string
|
||||
SyslogFilter []string
|
||||
SyslogSource string
|
||||
}
|
||||
|
||||
// ConsolidateConfig fills an Options struct by reading configuration from
|
||||
|
|
@ -35,7 +35,7 @@ func ConsolidateConfig() (opts *Config, err error) {
|
|||
ARPTablePath: "/proc/net/arp",
|
||||
SyslogEnabled: false,
|
||||
SyslogPath: "/var/log/messages",
|
||||
SyslogFilter: "daemon.info iwd:",
|
||||
SyslogFilter: []string{"daemon.info wpa_supplicant:", "daemon.info iwd:", "daemon.info hostapd:"},
|
||||
SyslogSource: "iwd",
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,27 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
// StringArray is a custom type for handling multiple string values in flags.
|
||||
type StringArray struct {
|
||||
Array *[]string
|
||||
}
|
||||
|
||||
// String returns a string representation of the StringArray.
|
||||
func (i *StringArray) String() string {
|
||||
return fmt.Sprintf("%v", i.Array)
|
||||
}
|
||||
|
||||
// Set appends a new string value to the StringArray.
|
||||
func (i *StringArray) Set(value string) error {
|
||||
*i.Array = append(*i.Array, value)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type URL struct {
|
||||
URL *url.URL
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,9 +14,9 @@ import (
|
|||
|
||||
// SyslogTailer tails a syslog file and filters messages to the logging system.
|
||||
type SyslogTailer struct {
|
||||
path string
|
||||
filter string
|
||||
source string
|
||||
path string
|
||||
filters []string
|
||||
source string
|
||||
|
||||
file *os.File
|
||||
done chan struct{}
|
||||
|
|
@ -29,12 +29,12 @@ type SyslogTailer struct {
|
|||
// path: Path to the syslog file (e.g., "/var/log/messages")
|
||||
// filter: Filter string to match in lines (e.g., "daemon.info iwd:")
|
||||
// source: Source name for logging (e.g., "iwd")
|
||||
func NewSyslogTailer(path, filter, source string) *SyslogTailer {
|
||||
func NewSyslogTailer(path string, filters []string, source string) *SyslogTailer {
|
||||
return &SyslogTailer{
|
||||
path: path,
|
||||
filter: filter,
|
||||
source: source,
|
||||
done: make(chan struct{}),
|
||||
path: path,
|
||||
filters: filters,
|
||||
source: source,
|
||||
done: make(chan struct{}),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -185,15 +185,22 @@ func (t *SyslogTailer) readLines(file *os.File) error {
|
|||
|
||||
line := scanner.Text()
|
||||
|
||||
// Check if the line contains the filter string
|
||||
if !strings.Contains(line, t.filter) {
|
||||
// Check if the line contains any of the filter strings
|
||||
var matchedFilter string
|
||||
for _, filter := range t.filters {
|
||||
if strings.Contains(line, filter) {
|
||||
matchedFilter = filter
|
||||
break
|
||||
}
|
||||
}
|
||||
if matchedFilter == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
// Parse the syslog line to extract the message
|
||||
// We look for "iwd:" (or whatever comes after the filter)
|
||||
// The filter is "daemon.info iwd:" so we want to extract text after "iwd:"
|
||||
daemonPrefix := extractDaemonPrefix(t.filter)
|
||||
daemonPrefix := extractDaemonPrefix(matchedFilter)
|
||||
message, ok := ParseSyslogLine(line, daemonPrefix)
|
||||
if !ok {
|
||||
// Couldn't parse the line, skip it
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue