mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-02 02:34:19 +00:00
Fixes for PT-55 & PT-56
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -8,3 +8,4 @@ release
|
||||
snapshot
|
||||
.DS_Store
|
||||
build
|
||||
bin/pt-mongodb-*
|
||||
|
@@ -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
|
||||
|
@@ -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"
|
||||
}
|
||||
|
||||
|
@@ -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])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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}}
|
||||
|
Reference in New Issue
Block a user