Skip to content

Commit

Permalink
add slice support on matching
Browse files Browse the repository at this point in the history
  • Loading branch information
dmachard committed Dec 17, 2023
1 parent aebecc8 commit a68487c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 18 deletions.
20 changes: 9 additions & 11 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,25 +124,19 @@ pipelines:
listen-port: 6000
routes: [ apple-txt ]

- name: godnsconnector-next
dnstap:
remote-address: 192.168.1.210
remote-port: 6000
- name: godnsconnector-next
dnstap:
remote-address: 192.168.1.210
remote-port: 6000
- name: apple-txt
dnsmessage:
matching:
include:
dns.qtype: "TXT"
dns.qname: "^*.apple.com$"
dns.qname:
- "^*.apple.com$"
- "^*.google.com$"
policy: "drop-unmatched"
transforms:
atags:
tags: [ "TXT:apple" ]
routes: [ outputfile,godnsconnector-next ]
tags: [ "TXT:apple", "TXT:google" ]
routes: [ outputfile, console ]

- name: outputfile
logfile:
Expand All @@ -151,6 +145,10 @@ pipelines:
max-files: 10
mode: flat-json

- name: console
stdout:
mode: text

################################################
# list of supported collectors
################################################
Expand Down
12 changes: 11 additions & 1 deletion dnsutils/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -866,16 +866,26 @@ func (dm *DNSMessage) Matching(matching map[string]interface{}, operator string)
reflectedValue := reflect.ValueOf(value)
switch operator {
case MatchingModeInclude:
// regex support for string
// string
if reflectedValue.Kind() == reflect.String {

Check failure on line 870 in dnsutils/message.go

View workflow job for this annotation

GitHub Actions / linter

ifElseChain: rewrite if-else to switch statement (gocritic)
pattern := regexp.MustCompile(reflectedValue.Interface().(string))
if !pattern.MatchString(fieldValue.Interface().(string)) {
isMatch = false
break
}

// list
} else if reflectedValue.Kind() == reflect.Slice {
subMatch := false
for i := 0; i < reflectedValue.Len(); i++ {
pattern := regexp.MustCompile(reflectedValue.Index(i).Interface().(string))
subMatch = subMatch || pattern.MatchString(fieldValue.Interface().(string))
}
isMatch = subMatch

// other types
} else if value != fieldValue.Interface() {
fmt.Println(reflectedValue.Kind())
isMatch = false
break
}
Expand Down
12 changes: 6 additions & 6 deletions pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ func InitPipelines(mapLoggers map[string]dnsutils.Worker, mapCollectors map[stri
// check if the name of each stanza is uniq
for _, stanza := range config.Pipelines {
if err := StanzaNameIsUniq(stanza.Name, config); err != nil {
panic(fmt.Sprintf("[main] - pipeline stanza with name=%s is duplicated", stanza.Name))
panic(fmt.Sprintf("[pipeline] - stanza with name=%s is duplicated", stanza.Name))
}
}

// check if all routes exists before continue
for _, stanza := range config.Pipelines {
for _, route := range stanza.Routes {
if err := IsRouteExist(route, config); err != nil {
panic(fmt.Sprintf("[main] - pipeline stanza=%s route=%s doest not exist", stanza.Name, route))
panic(fmt.Sprintf("[pipeline] - stanza=%s route=%s doest not exist", stanza.Name, route))
}
}
}
Expand Down Expand Up @@ -186,16 +186,16 @@ func InitPipelines(mapLoggers map[string]dnsutils.Worker, mapCollectors map[stri
// search in collectors
if _, ok := mapCollectors[route]; ok {
mapCollectors[stanza.Name].AddRoute(mapCollectors[route])
logger.Info("[main] - pipeline routing stanza=%s to=%s", stanza.Name, route)
logger.Info("[pipeline] - routing stanza=%s to=%s", stanza.Name, route)
} else if _, ok := mapLoggers[route]; ok {
mapCollectors[stanza.Name].AddRoute(mapLoggers[route])
logger.Info("[main] - pipeline routing stanza=%s to=%s", stanza.Name, route)
logger.Info("[pipeline] - routing stanza=%s to=%s", stanza.Name, route)
} else {
panic(fmt.Sprintf("[main] - pipeline routing error with stanza=%s to=%s doest not exist", stanza.Name, route))
panic(fmt.Sprintf("[pipeline] - routing error with stanza=%s to=%s doest not exist", stanza.Name, route))
}
}
} else {
logger.Info("main - stanza=%v doest not exist", stanza.Name)
logger.Info("[pipeline] - stanza=%v doest not exist", stanza.Name)
}
}
}
Expand Down

0 comments on commit a68487c

Please sign in to comment.