go.mondoo.com/cnquery@v0.0.0-20231005093811-59568235f6ea/providers/os/resources/services/aixlssrc.go (about) 1 // Copyright (c) Mondoo, Inc. 2 // SPDX-License-Identifier: BUSL-1.1 3 4 package services 5 6 import ( 7 "bufio" 8 "go.mondoo.com/cnquery/providers/os/connection/shared" 9 "io" 10 "regexp" 11 ) 12 13 type AixServiceManager struct { 14 conn shared.Connection 15 } 16 17 func (s *AixServiceManager) Name() string { 18 return "System Resource Controller" 19 } 20 21 func (s *AixServiceManager) List() ([]*Service, error) { 22 cmd, err := s.conn.RunCommand("lssrc -a") 23 if err != nil { 24 return nil, err 25 } 26 27 entries := parseLssrc(cmd.Stdout) 28 services := make([]*Service, len(entries)) 29 for i, entry := range entries { 30 services[i] = &Service{ 31 Name: entry.Subsystem, 32 Enabled: entry.Status == "active", 33 Installed: true, 34 Running: entry.Status == "active", 35 Type: "aix", 36 } 37 } 38 return services, nil 39 } 40 41 type lssrcEntry struct { 42 Subsystem string 43 Group string 44 PID string 45 Status string 46 } 47 48 var lssrcRegex = regexp.MustCompile(`^\s([\w.-]+)(\s+[\w]+\s+){0,1}([\d]+){0,1}\s+([\w]+)$`) 49 50 func parseLssrc(input io.Reader) []lssrcEntry { 51 entries := []lssrcEntry{} 52 scanner := bufio.NewScanner(input) 53 for scanner.Scan() { 54 line := scanner.Text() 55 m := lssrcRegex.FindStringSubmatch(line) 56 if len(m) == 5 { 57 entries = append(entries, lssrcEntry{ 58 Subsystem: m[1], 59 Group: m[2], 60 PID: m[3], 61 Status: m[4], 62 }) 63 } 64 } 65 return entries 66 }