Skip to content

Commit ce53a3d

Browse files
committed
metrics: rename 'SmbStatusShare' to 'SmbStatusTreeCon'
Align with 'smbstatus' (json output) terminology. Signed-off-by: Shachar Sharon <[email protected]>
1 parent 60e3c02 commit ce53a3d

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

internal/metrics/smbstatus.go

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ type SmbStatusSigning struct {
3131
Degree string `json:"degree"`
3232
}
3333

34-
// SmbStatusShare represents a single entry from the output of 'smbstatus -S'
35-
type SmbStatusShare struct {
34+
// SmbStatusTreeCon represents a 'tcon' output field
35+
type SmbStatusTreeCon struct {
3636
Service string `json:"service"`
3737
ServerID SmbStatusServerID `json:"server_id"`
38+
TConID string `json:"tcon_id"`
39+
SessionID string `json:"session_id"`
3840
Machine string `json:"machine"`
3941
ConnectedAt string `json:"connected_at"`
4042
Encryption SmbStatusEncryption `json:"encryption"`
@@ -81,7 +83,7 @@ type SmbStatusJSON struct {
8183
Version string `json:"version"`
8284
SmbConf string `json:"smb_conf"`
8385
Sessions map[string]SmbStatusSession `json:"sessions"`
84-
TCons map[string]SmbStatusShare `json:"tcons"`
86+
TCons map[string]SmbStatusTreeCon `json:"tcons"`
8587
LockedFiles map[string]SmbStatusLockedFile `json:"locked_files"`
8688
}
8789

@@ -148,7 +150,7 @@ func RunSmbStatusVersion() (string, error) {
148150
}
149151

150152
// RunSmbStatusShares executes 'smbstatus -S' on host container
151-
func RunSmbStatusShares() ([]SmbStatusShare, error) {
153+
func RunSmbStatusShares() ([]SmbStatusTreeCon, error) {
152154
// Case 1: using new json output
153155
dat, err := executeSmbStatusCommand("-S --json")
154156
if err == nil {
@@ -159,19 +161,19 @@ func RunSmbStatusShares() ([]SmbStatusShare, error) {
159161
if err == nil {
160162
return parseSmbStatusShares(dat)
161163
}
162-
return []SmbStatusShare{}, err
164+
return []SmbStatusTreeCon{}, err
163165
}
164166

165-
func parseSmbStatusSharesAsJSON(dat string) ([]SmbStatusShare, error) {
166-
shares := []SmbStatusShare{}
167+
func parseSmbStatusSharesAsJSON(dat string) ([]SmbStatusTreeCon, error) {
168+
tcons := []SmbStatusTreeCon{}
167169
res, err := parseSmbStatusJSON(dat)
168170
if err != nil {
169-
return shares, err
171+
return tcons, err
170172
}
171173
for _, share := range res.TCons {
172-
shares = append(shares, share)
174+
tcons = append(tcons, share)
173175
}
174-
return shares, nil
176+
return tcons, nil
175177
}
176178

177179
// RunSmbStatusLocks executes 'smbstatus -L' on host container
@@ -215,16 +217,16 @@ func RunSmbStatusProcs() ([]SmbStatusProc, error) {
215217

216218
// SmbStatusSharesByMachine converts the output of RunSmbStatusShares into map
217219
// indexed by machine's host
218-
func SmbStatusSharesByMachine() (map[string][]SmbStatusShare, error) {
220+
func SmbStatusSharesByMachine() (map[string][]SmbStatusTreeCon, error) {
219221
shares, err := RunSmbStatusShares()
220222
if err != nil {
221-
return map[string][]SmbStatusShare{}, err
223+
return map[string][]SmbStatusTreeCon{}, err
222224
}
223225
return makeSmbSharesMap(shares), nil
224226
}
225227

226-
func makeSmbSharesMap(shares []SmbStatusShare) map[string][]SmbStatusShare {
227-
ret := map[string][]SmbStatusShare{}
228+
func makeSmbSharesMap(shares []SmbStatusTreeCon) map[string][]SmbStatusTreeCon {
229+
ret := map[string][]SmbStatusTreeCon{}
228230
for _, share := range shares {
229231
ret[share.Machine] = append(ret[share.Machine], share)
230232
}
@@ -251,8 +253,8 @@ func executeCommand(command string, arg ...string) (string, error) {
251253

252254
// parseSmbStatusShares parses to output of 'smbstatus -S' into internal
253255
// representation.
254-
func parseSmbStatusShares(data string) ([]SmbStatusShare, error) {
255-
shares := []SmbStatusShare{}
256+
func parseSmbStatusShares(data string) ([]SmbStatusTreeCon, error) {
257+
shares := []SmbStatusTreeCon{}
256258
serviceIndex := 0
257259
pidIndex := 0
258260
machineIndex := 0
@@ -287,7 +289,7 @@ func parseSmbStatusShares(data string) ([]SmbStatusShare, error) {
287289
continue
288290
}
289291
// Parse data into internal repr
290-
share := SmbStatusShare{}
292+
share := SmbStatusTreeCon{}
291293
share.Service = parseSubstr(ln, serviceIndex)
292294
share.ServerID.PID = parseSubstr(ln, pidIndex)
293295
share.Machine = parseSubstr(ln, machineIndex)

0 commit comments

Comments
 (0)