Skip to content

Commit

Permalink
feat(inputs.win_services): Make service selection case-insensitive (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
srebhan authored Feb 6, 2024
1 parent 4c2ba74 commit 3591546
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions plugins/inputs/win_services/win_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"errors"
"fmt"
"io/fs"
"strings"
"syscall"

"golang.org/x/sys/windows"
Expand Down Expand Up @@ -120,11 +121,22 @@ func (*WinServices) SampleConfig() string {
}

func (m *WinServices) Init() error {
var err error
m.servicesFilter, err = filter.NewIncludeExcludeFilter(m.ServiceNames, m.ServiceNamesExcluded)
// For case insensitive comparision (see issue #8796) we need to transform the services
// to lowercase
servicesInclude := make([]string, 0, len(m.ServiceNames))
for _, s := range m.ServiceNames {
servicesInclude = append(servicesInclude, strings.ToLower(s))
}
servicesExclude := make([]string, 0, len(m.ServiceNamesExcluded))
for _, s := range m.ServiceNamesExcluded {
servicesExclude = append(servicesExclude, strings.ToLower(s))
}

f, err := filter.NewIncludeExcludeFilter(servicesInclude, servicesExclude)
if err != nil {
return err
}
m.servicesFilter = f

return nil
}
Expand Down Expand Up @@ -178,9 +190,11 @@ func (m *WinServices) listServices(scmgr WinServiceManager) ([]string, error) {
}

var services []string
for _, n := range names {
for _, name := range names {
// Compare case-insensitive. Use lowercase as we already converted the filter to use it.
n := strings.ToLower(name)
if m.servicesFilter.Match(n) {
services = append(services, n)
services = append(services, name)
}
}

Expand Down

0 comments on commit 3591546

Please sign in to comment.