Skip to content

Commit 4a38ea9

Browse files
committed
fix checking host
1 parent 4cc242f commit 4a38ea9

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

internal/datasource/config/nginx_config_parser.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,13 @@ func (ncp *NginxConfigParser) findValidSysLogServers(sysLogServers []string) []s
257257
for i := range sysLogServers {
258258
matches := re.FindStringSubmatch(sysLogServers[i])
259259
if len(matches) > 1 {
260-
if strings.HasPrefix(matches[1], "localhost") || strings.HasPrefix(matches[1], "127.0.0.1") {
260+
host, _, err := net.SplitHostPort(matches[1])
261+
if err != nil {
262+
continue
263+
}
264+
265+
ip := net.ParseIP(host)
266+
if ip.IsLoopback() || strings.EqualFold(host, "localhost") {
261267
servers = append(servers, matches[1])
262268
}
263269
}

internal/datasource/config/nginx_config_parser_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,8 +688,9 @@ func TestNginxConfigParser_findValidSysLogServers(t *testing.T) {
688688
"app_protect_security_log", "/etc/app_protect/conf/log_default1.json", "syslog:server=my.domain.com:1517",
689689
"app_protect_security_log", "/etc/app_protect/conf/log_default2.json", "syslog:server=127.0.0.1:1515",
690690
"app_protect_security_log", "/etc/app_protect/conf/log_default3.json", "syslog:server=localhost:1516",
691+
"app_protect_security_log\", \"/etc/app_protect/conf/log_default3.json\", \"syslog:server=127.255.255.255:1517",
691692
}
692-
expected := []string{"127.0.0.1:1515", "localhost:1516"}
693+
expected := []string{"127.0.0.1:1515", "localhost:1516", "127.255.255.255:1517"}
693694
ncp := NewNginxConfigParser(types.AgentConfig())
694695
result := ncp.findValidSysLogServers(servers)
695696

0 commit comments

Comments
 (0)