Skip to content

Commit 97094d5

Browse files
committed
make inventory output mode a constant
1 parent 38f707b commit 97094d5

4 files changed

Lines changed: 20 additions & 7 deletions

File tree

pkg/snclient/check_drivesize.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ func (l *CheckDrivesize) Check(ctx context.Context, snc *Agent, check *CheckData
230230
continue
231231
}
232232
// skip file mount in inventory mode, like ex.: from docker /etc/hostname
233-
if check.output == "inventory_json" && utils.IsFile(drive["drive_or_id"]) == nil {
233+
if check.output == OutputInventory && utils.IsFile(drive["drive_or_id"]) == nil {
234234
continue
235235
}
236236

pkg/snclient/check_memory.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ func (l *CheckMemory) Check(ctx context.Context, _ *Agent, check *CheckData, _ [
117117
if err != nil {
118118
return nil, fmt.Errorf("fetching swap failed: %s", err.Error())
119119
}
120-
// osx changes swap total on demand, so always return something
121-
if swap.Total > 0 || check.hasArgsSupplied["type"] || runtime.GOOS == "darwin" {
120+
// osx changes swap total on demand, so always return something in inventory mode
121+
if swap.Total > 0 || check.hasArgsSupplied["type"] || (runtime.GOOS == "darwin" && check.output == OutputInventory) {
122122
l.addMemType(check, "swap", swap.Used, swap.Free, swap.Total)
123123
}
124124
case "committed":

pkg/snclient/checkdata.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ const (
3131
NoCallInventory // does not call this check and puts single entry into inventory
3232
)
3333

34+
// OutputMode sets available output modes
35+
type OutputMode uint8
36+
37+
const (
38+
OutputDefault OutputMode = iota
39+
OutputInventory // only reports available inventory
40+
)
41+
3442
type CommaStringList []string
3543

3644
type CheckArgument struct {
@@ -123,7 +131,7 @@ type CheckData struct {
123131
perfConfig []PerfConfig
124132
perfSyntax string
125133
hasInventory InventoryMode
126-
output string
134+
output OutputMode
127135
implemented Implemented
128136
attributes []CheckAttribute
129137
listSorted []string // sort result list by this keys
@@ -159,7 +167,7 @@ func (cd *CheckData) Finalize() (*CheckResult, error) {
159167
cd.result = &CheckResult{}
160168
}
161169
cd.result.Raw = cd
162-
if cd.output == "inventory_json" {
170+
if cd.output == OutputInventory {
163171
return cd.result, nil
164172
}
165173

@@ -764,7 +772,12 @@ func (cd *CheckData) processArgs(sanitized []Argument, defaultWarning, defaultCr
764772
case "perf-syntax":
765773
cd.perfSyntax = argValue
766774
case "output":
767-
cd.output = argValue
775+
switch argValue {
776+
case "inventory_json":
777+
cd.output = OutputInventory
778+
default:
779+
return nil, false, fmt.Errorf("unknown output mode: %s (valid values are: inventory_json)", argValue)
780+
}
768781
default:
769782
parsed, err2 := cd.parseAnyArg(argExpr, keyword, argValue)
770783
switch {

pkg/snclient/inventory.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ func (snc *Agent) buildInventory(ctx context.Context, modules []string) *Invento
127127
if len(modules) > 0 && (!slices.Contains(modules, name)) {
128128
continue
129129
}
130-
meta.output = "inventory_json"
130+
meta.output = OutputInventory
131131
meta.filter = ConditionList{{isNone: true}}
132132
data, err := handler.Check(ctx, snc, meta, []Argument{})
133133
if err != nil && (data == nil || data.Raw == nil) {

0 commit comments

Comments
 (0)