@@ -52,14 +52,14 @@ func isDirectoryExist(OutputPrefix string) bool {
5252 return ! os .IsNotExist (err )
5353}
5454
55- func isMongoNodeAlive (hostname string , port int ) bool {
55+ func isMongoNodeAlive (hostname string , port int ) ( bool , error ) {
5656 // Attempt to connect to the MongoDB host on the specified port
5757 conn , err := net .DialTimeout ("tcp" , net .JoinHostPort (hostname , strconv .Itoa (port )), 5 * time .Second )
5858 if err != nil {
59- return false
59+ return false , err
6060 }
6161 conn .Close ()
62- return true
62+ return true , err
6363}
6464
6565func main () {
@@ -145,7 +145,7 @@ func main() {
145145
146146 for _ , host := range clustertopology .Allnodes .Nodes {
147147
148- dcrlog .Info (fmt .Sprintf ("host: %s, port: %d" , host .Hostname , host .Port ))
148+ dcrlog .Info (fmt .Sprintf ("Collecting logs for MongoDB node - host: %s, port: %d" , host .Hostname , host .Port ))
149149 fmt .Printf ("\n Collecting logs for MongoDB node %s:%d\n " , host .Hostname , host .Port )
150150 // determine if the data collection should abort due to not enough free space
151151 // we keep approx 1GB as limit
@@ -173,8 +173,10 @@ func main() {
173173 log .Fatal ("Error creating output Directory for storing DCR outputs" )
174174 }
175175
176- isAliveBefore := isMongoNodeAlive (host .Hostname , host .Port )
177- dcrlog .Info (fmt .Sprintf ("host: %s, port: %d is alive: %t" , host .Hostname , host .Port , isAliveBefore ))
176+ isAliveBefore , err := isMongoNodeAlive (host .Hostname , host .Port )
177+ if err != nil {
178+ dcrlog .Error (fmt .Sprintf ("Error checking if host: %s, port: %d is alive: \n %v" , host .Hostname , host .Port , err ))
179+ }
178180
179181 c := mongosh.CaptureGetMongoData {}
180182 c .S = & cred
@@ -186,11 +188,10 @@ func main() {
186188 dcrlog .Error (fmt .Sprintf ("Error Running getMongoData %v" , err ))
187189 }
188190
189- // fmt.Println("\nPaused the code for testing purpose, press enter to continue...") //use this if you want to crash a node intentionally for testing purposes
190- // bufio.NewReader(os.Stdin).ReadBytes('\n')
191+ isAliveAfter , err := isMongoNodeAlive (host .Hostname , host .Port )
191192
192- if ! isMongoNodeAlive ( host . Hostname , host . Port ) && isAliveBefore {
193- dcrlog .Error (fmt .Sprintf ("MongoDB node %s:%d became unreachable after collecting getMongoData." , host .Hostname , host .Port ))
193+ if ! isAliveAfter && isAliveBefore {
194+ dcrlog .Error (fmt .Sprintf ("MongoDB node %s:%d became unreachable after collecting getMongoData.\n %v " , host .Hostname , host .Port , err ))
194195
195196 fmt .Printf ("\n " )
196197 fmt .Println ("######################################################################" )
0 commit comments