38 lines
764 B
Go
38 lines
764 B
Go
|
package detector
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"regexp"
|
||
|
)
|
||
|
|
||
|
// Flags is list of strings describing problems found among the processes
|
||
|
type Flags []string
|
||
|
|
||
|
// 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
|
||
|
}
|
||
|
fmt.Println(process, pattern, flag)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
for flag, _ := range tmpFlags {
|
||
|
flags = append(flags, flag)
|
||
|
}
|
||
|
|
||
|
return flags, nil
|
||
|
}
|