1
0
Fork 0
mirror of https://github.com/alice-lg/birdwatcher.git synced 2025-03-09 00:00:05 +01:00

Added action for what to do with the values so far for the current

item. If it's "store" we just store it and wait for more to find
complete data in more regexps. If it's "send" we close this data item
and add it to the list to be returned to the web server.
This commit is contained in:
Michael Cardell Widerkrantz 2016-10-23 17:38:03 +02:00
parent 2335670d97
commit 1da50a7178
3 changed files with 42 additions and 4 deletions

View file

@ -22,6 +22,7 @@ type Match struct {
Expr string // The regular expression as a string.
Fields []string // The named fields for grouped expressions.
Next string // The next regular expression in the flow.
Action string // What to do with the stored fields: "store" or "send".
}
// Compiled regular expression and it's corresponding match data.

View file

@ -20,10 +20,12 @@ matches:
- connection
expr: '^(\w+)\s+BGP\s+(\w+)\s+(\w+)\s+([0-9\-]+)\s+(\w+)\s*$'
next: "protdescription"
action: store
# Description: Pipe for AS10310 - Yahoo! - VLAN Interface 236
protdescription:
fields:
- desc
expr: " Description: (.*)"
next: ""
next: "getprotocol" # back again for more similar lines
action: send # Done here, send it back.

View file

@ -26,7 +26,21 @@ func readLines(path string) ([]string, error) {
// pattern looks for pattern matching regular expression re in the
// lines buffer. Returns the name of our next regular expression to
// look for.
func pattern(re RE, lines []string) (next string) {
func pattern(first string, lines []string) (maplist []map[string]string) {
var re RE
var fieldmap map[string]string
fmt.Printf("In pattern\n")
re, ok := conf.Res[first]
if !ok {
slog.Debug("Couldn't find first state.")
return
}
// Store away all the fields in a map.
fieldmap = make(map[string]string)
for _, line := range lines {
if debug > 1 {
slog.Debug("Looking at: " + line)
@ -39,8 +53,29 @@ func pattern(re RE, lines []string) (next string) {
line := fmt.Sprintf("Found match for a message of type '%v'", re.Match)
slog.Debug(line)
}
for key, name := range re.Match.Fields {
if debug > 0 {
slog.Debug("Got " + re.Match.Fields[key])
}
fieldmap[name] = fields[key+1]
}
fmt.Printf("%#v\n", fieldmap)
if re.Match.Action == "send" {
// Finished for this item. Create a new field map and add this to the list.
maplist = append(maplist, fieldmap)
fieldmap = make(map[string]string)
}
// Go to the next state, if it exists. If it
// doesn't we're finished here.
re, ok = conf.Res[re.Match.Next]
if !ok {
break
}
}
}
return re.Match.Next
return maplist
}