Fixes for PT-55 & PT-56

This commit is contained in:
Carlos Salguero
2017-01-20 18:02:32 -03:00
parent 98fa733c0c
commit b2406d8da4
5 changed files with 55 additions and 6 deletions

1
.gitignore vendored
View File

@@ -8,3 +8,4 @@ release
snapshot
.DS_Store
build
bin/pt-mongodb-*

View File

@@ -29,6 +29,7 @@ type Parsed struct {
Net Net `bson:"net"`
ProcessManagement ProcessManagement `bson:"processManagement"`
Replication Replication `bson:"replication"`
Security Security `bson:"security"`
}
// Security is a struct to hold security related configs

View File

@@ -289,6 +289,7 @@ func GetHostinfo(session pmgo.SessionManager) (*hostInfo, error) {
}
nodeType, _ := getNodeType(session)
procCount, _ := countMongodProcesses()
i := &hostInfo{
Hostname: hi.System.Hostname,
@@ -296,9 +297,10 @@ func GetHostinfo(session pmgo.SessionManager) (*hostInfo, error) {
HostSystemCPUArch: hi.System.CpuArch,
DBPath: "", // Sets default. It will be overriden later if necessary
ProcessName: ss.Process,
Version: ss.Version,
NodeType: nodeType,
ProcessName: ss.Process,
ProcProcessCount: procCount,
Version: ss.Version,
NodeType: nodeType,
ProcPath: pi.Path,
ProcUserName: pi.UserName,
@@ -315,6 +317,24 @@ func GetHostinfo(session pmgo.SessionManager) (*hostInfo, error) {
return i, nil
}
func countMongodProcesses() (int, error) {
pids, err := process.Pids()
if err != nil {
return 0, err
}
count := 0
for _, pid := range pids {
p, err := process.NewProcess(pid)
if err != nil {
continue
}
if name, _ := p.Name(); name == "mongod" || name == "mongos" {
count++
}
}
return count, nil
}
func getHostnames(dialer pmgo.Dialer, di *mgo.DialInfo) ([]string, error) {
hostnames := []string{di.Addrs[0]}
session, err := dialer.DialWithInfo(di)
@@ -474,7 +494,8 @@ func GetSecuritySettings(session pmgo.SessionManager, ver string) (*security, er
return nil, errors.Wrap(err, "cannot get command line options")
}
if cmdOpts.Security.Authorization != "" || cmdOpts.Security.KeyFile != "" {
if cmdOpts.Security.Authorization != "" || cmdOpts.Security.KeyFile != "" ||
cmdOpts.Parsed.Security.Authorization != "" || cmdOpts.Parsed.Security.KeyFile != "" {
s.Auth = "enabled"
}

View File

@@ -117,6 +117,23 @@ func TestSecurityOpts(t *testing.T) {
Authorization: "",
},
},
// 5
proto.CommandLineOptions{
Parsed: proto.Parsed{
Net: proto.Net{
SSL: proto.SSL{
Mode: "",
},
},
Security: proto.Security{
KeyFile: "/home/plavi/psmdb/percona-server-mongodb-3.4.0-1.0-beta-6320ac4/data/keyfile",
},
},
Security: proto.Security{
KeyFile: "",
Authorization: "",
},
},
}
expect := []*security{
@@ -159,6 +176,16 @@ func TestSecurityOpts(t *testing.T) {
Port: 0,
WarningMsgs: nil,
},
// 5
&security{
Users: 1,
Roles: 2,
Auth: "enabled",
SSL: "disabled",
BindIP: "",
Port: 0,
WarningMsgs: nil,
},
}
ctrl := gomock.NewController(t)
@@ -188,7 +215,7 @@ func TestSecurityOpts(t *testing.T) {
t.Errorf("cannot get sec settings: %v", err)
}
if !reflect.DeepEqual(got, expect[i]) {
t.Errorf("got: %#v\nwant: %#v\n", got, expect[i])
t.Errorf("Test # %d,\ngot: %#v\nwant: %#v\n", i+1, got, expect[i])
}
}
}

View File

@@ -6,7 +6,6 @@ const HostInfo = `# This host
# Report On {{.ThisHostID}} ########################################
User | {{.ProcUserName}}
PID Owner | {{.ProcessName}}
Time | {{.ProcCreateTime}}
Hostname | {{.Hostname}}
Version | {{.Version}}
Built On | {{.HostOsType}} {{.HostSystemCPUArch}}