Skip to content

Commit

Permalink
Merge pull request #9 from 10gen/issue2
Browse files Browse the repository at this point in the history
enhancement: should collect at least getMongo output
hasaketa authored Aug 10, 2024
2 parents bf7de0d + e140a56 commit 62cc273
Showing 1 changed file with 81 additions and 132 deletions.
213 changes: 81 additions & 132 deletions main.go
Original file line number Diff line number Diff line change
@@ -78,90 +78,103 @@ func main() {
outputdir := dcroutdir.DCROutputDir{}
outputdir.OutputPrefix = checkEmptyDirectory("./outputs/" + cred.Clustername + "/")

dcrlog.Info(fmt.Sprintf("DCR outputs directory: %s", outputdir.OutputPrefix))
dcrlog.Info(
fmt.Sprintf(
"Seed Host: %s, Seed Port: %s", cred.Seedmongodhost, cred.Seedmongodport,
),
)

dcrlog.Info(
fmt.Sprintf(
"DCR outputs directory: %s", outputdir.OutputPrefix,
),
)

dcrlog.Info(
fmt.Sprintf(
"remote creds: %v, %v", remoteCred.Username, remoteCred.Available,
),
)

dcrlog.Info("Probing cluster topology")

clustertopology := topologyfinder.TopologyFinder{}
clustertopology.MongoshCapture.S = &cred
err = clustertopology.GetAllNodes()
if err != nil {
dcrlog.Error(fmt.Sprintf("Error in Topology finding: %s", err.Error()))
log.Fatal("Error in Topology finding:", err)
}

if remoteCred.Available {
for _, host := range clustertopology.Allnodes.Nodes {

dcrlog.Info("remote creds provided will handle both remote and local node")
dcrlog.Info(fmt.Sprintf("host: %s, port: %d", host.Hostname, host.Port))

dcrlog.Info("Probing cluster topology")
cred.Currentmongodhost = host.Hostname
cred.Currentmongodport = strconv.Itoa(host.Port)
cred.SetMongoURI()

clustertopology := topologyfinder.TopologyFinder{}
clustertopology.MongoshCapture.S = &cred
err = clustertopology.GetAllNodes()
outputdir.Hostname = cred.Currentmongodhost
outputdir.Port = cred.Currentmongodport
err = outputdir.CreateDCROutputDir()
if err != nil {
dcrlog.Error(fmt.Sprintf("Error in Topology finding: %s", err.Error()))
log.Fatal("Error in Topology finding:", err)
dcrlog.Error("Error creating output Directory for storing DCR outputs")
log.Fatal("Error creating output Directory for storing DCR outputs")
}

for _, host := range clustertopology.Allnodes.Nodes {

dcrlog.Info(fmt.Sprintf("host: %s, port: %d", host.Hostname, host.Port))
c := mongosh.CaptureGetMongoData{}
c.S = &cred
c.Outputdir = &outputdir

cred.Currentmongodhost = host.Hostname
cred.Currentmongodport = strconv.Itoa(host.Port)
cred.SetMongoURI()
dcrlog.Info("Running getMongoData/mongoWellnessChecker")
err := c.RunMongoShellWithEval()
if err != nil {
dcrlog.Error(fmt.Sprintf("Error Running getMongoData %v", err))
log.Fatal("Error Running getMongoData ", err)
}

outputdir.Hostname = cred.Currentmongodhost
outputdir.Port = cred.Currentmongodport
err = outputdir.CreateDCROutputDir()
if err != nil {
dcrlog.Error("Error creating output Directory for storing DCR outputs")
log.Fatal("Error creating output Directory for storing DCR outputs")
}
isLocalHost := false
var errtest error

hostname := host.Hostname
isLocalHost, errtest = isHostnameALocalHost(hostname)
if errtest != nil {
dcrlog.Error(
fmt.Sprintf(
"Error determining if Hostname is a LocalHost or not : %v",
errtest,
),
)
log.Fatal("Error determining if Hostname is a LocalHost or not :", errtest)
}

c := mongosh.CaptureGetMongoData{}
c.S = &cred
c.Outputdir = &outputdir
if isLocalHost {
dcrlog.Info(
fmt.Sprintf("%s is a local hostname. Performing Local Copying.", hostname),
)

dcrlog.Info("Running getMongoData/mongoWellnessChecker")
err := c.RunMongoShellWithEval()
dcrlog.Info("Running FTDC Archiving")
ftdcarchive := ftdcarchiver.FTDCarchive{}
ftdcarchive.Mongo.S = &cred
ftdcarchive.Outputdir = &outputdir
err = ftdcarchive.Start()
if err != nil {
dcrlog.Error(fmt.Sprintf("Error Running getMongoData %v", err))
log.Fatal("Error Running getMongoData ", err)
dcrlog.Error(fmt.Sprintf("Error in FTDCArchive: %v", err))
log.Fatal("Error in FTDCArchive: ", err)
}

isLocalHost := false
var errtest error

hostname := host.Hostname
isLocalHost, errtest = isHostnameALocalHost(hostname)
if errtest != nil {
dcrlog.Error(
fmt.Sprintf(
"Error determining if Hostname is a LocalHost or not : %v",
errtest,
),
)
log.Fatal("Error determining if Hostname is a LocalHost or not :", errtest)
dcrlog.Info("Running mongo log Archiving")
logarchive := mongologarchiver.MongoDLogarchive{}
logarchive.Mongo.S = &cred
logarchive.Outputdir = &outputdir
err = logarchive.Start()
if err != nil {
dcrlog.Error(fmt.Sprintf("Error in LogArchive: %v", err))
log.Fatal("Error in LogArchive:", err)
}

if isLocalHost {
dcrlog.Info(
fmt.Sprintf("%s is a local hostname. Performing Local Copying.", hostname),
)

dcrlog.Info("Running FTDC Archiving")
ftdcarchive := ftdcarchiver.FTDCarchive{}
ftdcarchive.Mongo.S = &cred
ftdcarchive.Outputdir = &outputdir
err = ftdcarchive.Start()
if err != nil {
dcrlog.Error(fmt.Sprintf("Error in FTDCArchive: %v", err))
log.Fatal("Error in FTDCArchive: ", err)
}

dcrlog.Info("Running mongo log Archiving")
logarchive := mongologarchiver.MongoDLogarchive{}
logarchive.Mongo.S = &cred
logarchive.Outputdir = &outputdir
err = logarchive.Start()
if err != nil {
dcrlog.Error(fmt.Sprintf("Error in LogArchive: %v", err))
log.Fatal("Error in LogArchive:", err)
}

} else {
} else {
if remoteCred.Available == true {
dcrlog.Info(fmt.Sprintf("%s is not a local hostname. Proceeding with remote Copier.", hostname))

remotecopyJob := fscopy.FSCopyJob{}
@@ -219,70 +232,6 @@ func main() {
dcrlog.Error(fmt.Sprintf("Error in Remote Log Archive: %v", err))
log.Fatal("Error in Remote Log Archive: ", err)
}

}

}

} else {

dcrlog.Info("Remote cred not provided looking for nodes running locally")

dcrlog.Info("Probing cluster topology")

clustertopology := topologyfinder.TopologyFinder{}
clustertopology.MongoshCapture.S = &cred
err = clustertopology.GetAllNodes()
if err != nil {
dcrlog.Error(fmt.Sprintf("Error in Topology finding: %v", err))
log.Fatal("Error in Topology finding:", err)
}

for _, host := range clustertopology.Allnodes.Nodes {

dcrlog.Info(fmt.Sprintf("host: %s, port: %d", host.Hostname, host.Port))

cred.Currentmongodhost = host.Hostname
cred.Currentmongodport = strconv.Itoa(host.Port)
cred.SetMongoURI()

outputdir.Hostname = cred.Currentmongodhost
outputdir.Port = cred.Currentmongodport
err = outputdir.CreateDCROutputDir()
if err != nil {
dcrlog.Error("Error creating output Directory for storing DCR outputs")
log.Fatal("Error creating output Directory for storing DCR outputs")
}

c := mongosh.CaptureGetMongoData{}
c.S = &cred
c.Outputdir = &outputdir

dcrlog.Info("Running getMongoData/mongoWellnessChecker")
err := c.RunMongoShellWithEval()
if err != nil {
dcrlog.Error(fmt.Sprintf("Error Running getMongoData %v", err))
log.Fatal("Error Running getMongoData ", err)
}

dcrlog.Info("Running FTDCArchiving")
ftdcarchive := ftdcarchiver.FTDCarchive{}
ftdcarchive.Mongo.S = &cred
ftdcarchive.Outputdir = &outputdir
err = ftdcarchive.Start()
if err != nil {
dcrlog.Error(fmt.Sprintf("Error in FTDC Archive: %v", err))
log.Fatal("Error in FTDCArchive:", err)
}

dcrlog.Info("Running mongo log archiving")
logarchive := mongologarchiver.MongoDLogarchive{}
logarchive.Mongo.S = &cred
logarchive.Outputdir = &outputdir
err = logarchive.Start()
if err != nil {
dcrlog.Error(fmt.Sprintf("Error in LogArchive: %v", err))
log.Fatal("Error in LogArchive:", err)
}

}

0 comments on commit 62cc273

Please sign in to comment.