node-api/detector/main.go
Adam Štrauch fdcdca237f
All checks were successful
continuous-integration/drone/push Build is passing
Upgade of docker client, ...
Docker client upgrade,
Miner detection
Flags for apps
2022-02-05 02:22:53 +01:00

41 lines
795 B
Go

package detector
import (
"regexp"
"strings"
)
// Flags is list of strings describing problems found among the processes
type Flags []string
func (f *Flags) String() string {
return strings.Join(*f, ",")
}
// Check goes over patterns and tries to flag given list of processes with flags.
func Check(processes []string) (Flags, error) {
flags := Flags{}
tmpFlags := make(map[string]bool)
for _, process := range processes {
for flag, patternSet := range patterns {
for _, pattern := range patternSet {
matched, err := regexp.MatchString(".*"+pattern+".*", process)
if err != nil {
return flags, err
}
if matched {
tmpFlags[flag] = true
break
}
}
}
}
for flag, _ := range tmpFlags {
flags = append(flags, flag)
}
return flags, nil
}