2022-02-03 00:31:47 +00:00
|
|
|
package detector
|
|
|
|
|
|
|
|
import (
|
|
|
|
"regexp"
|
2022-02-05 01:22:53 +00:00
|
|
|
"strings"
|
2022-02-03 00:31:47 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Flags is list of strings describing problems found among the processes
|
|
|
|
type Flags []string
|
|
|
|
|
2022-02-05 01:22:53 +00:00
|
|
|
func (f *Flags) String() string {
|
|
|
|
return strings.Join(*f, ",")
|
|
|
|
}
|
|
|
|
|
2022-02-03 00:31:47 +00:00
|
|
|
// 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
|
|
|
|
}
|