-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
⭐️ IBM AIX support #1940
Merged
Merged
⭐️ IBM AIX support #1940
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright (c) Mondoo, Inc. | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
|
||
package packages | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"go.mondoo.com/cnquery/providers/os/connection/shared" | ||
"io" | ||
"strings" | ||
) | ||
|
||
const ( | ||
AixPkgFormat = "bff" | ||
) | ||
|
||
func parseAixPackages(r io.Reader) ([]Package, error) { | ||
pkgs := []Package{} | ||
|
||
scanner := bufio.NewScanner(r) | ||
i := 0 | ||
for scanner.Scan() { | ||
line := scanner.Text() | ||
i++ | ||
|
||
if i == 1 { | ||
continue | ||
} | ||
|
||
record := strings.Split(line, ":") | ||
|
||
// Fileset, Level, PtfID, State, Type, Description, EFIXLocked | ||
pkgs = append(pkgs, Package{ | ||
Name: record[1], | ||
Version: record[2], | ||
Description: strings.TrimSpace(record[6]), | ||
Format: AixPkgFormat, | ||
}) | ||
|
||
} | ||
return pkgs, nil | ||
} | ||
|
||
type AixPkgManager struct { | ||
conn shared.Connection | ||
} | ||
|
||
func (f *AixPkgManager) Name() string { | ||
return "AIX Package Manager" | ||
} | ||
|
||
func (f *AixPkgManager) Format() string { | ||
return AixPkgFormat | ||
} | ||
|
||
func (f *AixPkgManager) List() ([]Package, error) { | ||
cmd, err := f.conn.RunCommand("lslpp -cl ") | ||
if err != nil { | ||
return nil, fmt.Errorf("could not read freebsd package list") | ||
} | ||
|
||
return parseAixPackages(cmd.Stdout) | ||
} | ||
|
||
func (f *AixPkgManager) Available() (map[string]PackageUpdate, error) { | ||
return map[string]PackageUpdate{}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (c) Mondoo, Inc. | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
|
||
package packages | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestParseAixPackages(t *testing.T) { | ||
f, err := os.Open("testdata/packages_aix.txt") | ||
require.NoError(t, err) | ||
|
||
m, err := parseAixPackages(f) | ||
require.Nil(t, err) | ||
assert.Equal(t, 16, len(m), "detected the right amount of packages") | ||
|
||
var p Package | ||
p = Package{ | ||
Name: "X11.apps.msmit", | ||
Version: "7.3.0.0", | ||
Description: "AIXwindows msmit Application", | ||
Format: "bff", | ||
} | ||
assert.Contains(t, m, p) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#Fileset:Level:PTF Id:State:Type:Description:EFIX Locked | ||
/usr/lib/objrepos:ICU4C.rte:7.3.0.0::COMMITTED:I:International Components for Unicode : | ||
/usr/lib/objrepos:Java8_64.jre:8.0.0.636::COMMITTED:I:Java SDK 64-bit Java Runtime Environment : | ||
/usr/lib/objrepos:Java8_64.sdk:8.0.0.636::COMMITTED:I:Java SDK 64-bit Development Kit : | ||
/usr/lib/objrepos:X11.adt.bitmaps:7.3.0.0::COMMITTED:I:AIXwindows Application Development Toolkit Bitmap Files : | ||
/usr/lib/objrepos:X11.adt.imake:7.3.0.0::COMMITTED:I:AIXwindows Application Development Toolkit imake : | ||
/usr/lib/objrepos:X11.adt.include:7.3.0.0::COMMITTED:I:AIXwindows Application Development Toolkit Include Files : | ||
/usr/lib/objrepos:X11.adt.lib:7.3.0.0::COMMITTED:I:AIXwindows Application Development Toolkit Libraries : | ||
/usr/lib/objrepos:X11.apps.aixterm:7.3.0.0::COMMITTED:I:AIXwindows aixterm Application : | ||
/usr/lib/objrepos:X11.apps.clients:7.3.0.0::COMMITTED:I:AIXwindows Client Applications : | ||
/usr/lib/objrepos:X11.apps.config:7.3.0.0::COMMITTED:I:AIXwindows Configuration Applications : | ||
/usr/lib/objrepos:X11.apps.custom:7.3.0.0::COMMITTED:I:AIXwindows Customizing Tool : | ||
/usr/lib/objrepos:X11.apps.msmit:7.3.0.0::COMMITTED:I:AIXwindows msmit Application : | ||
/usr/lib/objrepos:X11.apps.rte:7.3.0.0::COMMITTED:I:AIXwindows Runtime Configuration Applications : | ||
/usr/lib/objrepos:X11.apps.util:7.3.0.0::COMMITTED:I:AIXwindows Utility Applications : | ||
/usr/lib/objrepos:X11.apps.xdm:7.3.0.0::COMMITTED:I:AIXwindows xdm Application : | ||
/usr/lib/objrepos:X11.apps.xterm:7.3.0.0::COMMITTED:I:AIXwindows xterm Application : |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright (c) Mondoo, Inc. | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
|
||
package services | ||
|
||
import ( | ||
"bufio" | ||
"go.mondoo.com/cnquery/providers/os/connection/shared" | ||
"io" | ||
"regexp" | ||
) | ||
|
||
type AixServiceManager struct { | ||
conn shared.Connection | ||
} | ||
|
||
func (s *AixServiceManager) Name() string { | ||
return "System Resource Controller" | ||
} | ||
|
||
func (s *AixServiceManager) List() ([]*Service, error) { | ||
cmd, err := s.conn.RunCommand("lssrc -a") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
entries := parseLssrc(cmd.Stdout) | ||
services := make([]*Service, len(entries)) | ||
for i, entry := range entries { | ||
services[i] = &Service{ | ||
Name: entry.Subsystem, | ||
Enabled: entry.Status == "active", | ||
Installed: true, | ||
Running: entry.Status == "active", | ||
Type: "aix", | ||
} | ||
} | ||
return services, nil | ||
} | ||
|
||
type lssrcEntry struct { | ||
Subsystem string | ||
Group string | ||
PID string | ||
Status string | ||
} | ||
|
||
var lssrcRegex = regexp.MustCompile(`^\s([\w.-]+)(\s+[\w]+\s+){0,1}([\d]+){0,1}\s+([\w]+)$`) | ||
|
||
func parseLssrc(input io.Reader) []lssrcEntry { | ||
entries := []lssrcEntry{} | ||
scanner := bufio.NewScanner(input) | ||
for scanner.Scan() { | ||
line := scanner.Text() | ||
m := lssrcRegex.FindStringSubmatch(line) | ||
if len(m) == 5 { | ||
entries = append(entries, lssrcEntry{ | ||
Subsystem: m[1], | ||
Group: m[2], | ||
PID: m[3], | ||
Status: m[4], | ||
}) | ||
} | ||
} | ||
return entries | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright (c) Mondoo, Inc. | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
|
||
package services | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestLssrcParse(t *testing.T) { | ||
testOutput := ` | ||
Subsystem Group PID Status | ||
syslogd ras 3932558 active | ||
aso 4653462 active | ||
biod nfs 5046692 active | ||
rpc.lockd nfs 5636560 active | ||
qdaemon spooler 5767630 active | ||
ctrmc rsct 5439966 active | ||
pmperfrec 6881768 active | ||
IBM.HostRM rsct_rm 5898530 active | ||
automountd autofs 7340402 active | ||
lpd spooler inoperative | ||
nimsh nimclient inoperative | ||
nimhttp inoperative | ||
timed tcpip inoperative | ||
` | ||
entries := parseLssrc(strings.NewReader(testOutput)) | ||
assert.Equal(t, 13, len(entries), "detected the right amount of services") | ||
assert.Equal(t, "syslogd", entries[0].Subsystem, "service name detected") | ||
assert.Equal(t, "active", entries[0].Status, "service status detected") | ||
assert.Equal(t, "timed", entries[12].Subsystem, "service name detected") | ||
assert.Equal(t, "inoperative", entries[12].Status, "service status detected") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you going to add RPM packages as well? AIX supports those and it would be very handy to expose those.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @scotthain Great idea! Lets do this as follow-up