package com.example.voter;

import org.springframework.boot.actuate.info.Info;
import org.springframework.boot.actuate.info.InfoContributor;
import org.springframework.stereotype.Component;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.Map;

@Component
public class HostInfoContributor implements InfoContributor {

    @Override
    public void contribute(Info.Builder builder) {
        InetAddress ip = null;
        Map<String, String> hostMap = new HashMap<>();

        try {
            ip = InetAddress.getLocalHost();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
        hostMap.put("ipAddress", ip.getHostAddress());
        hostMap.put("hostname", ip.getHostName());
        builder.withDetail("hostInfo", hostMap);
    }

}

@@ -21,16 +21,171 @@
 voter;%0A%0A
+import com.mongodb.CommandResult;%0Aimport com.mongodb.MongoClient;%0Aimport org.bson.Document;%0Aimport org.springframework.beans.factory.annotation.Autowired;%0A
 import o
@@ -227,16 +227,16 @@
 o.Info;%0A
-
 import o
@@ -289,16 +289,76 @@
 ibutor;%0A
+import org.springframework.data.mongodb.core.MongoTemplate;%0A
 import o
@@ -466,16 +466,44 @@
 eption;%0A
+import java.util.ArrayList;%0A
 import j
@@ -617,16 +617,73 @@
 utor %7B%0A%0A
+    @Autowired%0A    private MongoTemplate mongoTemplate;%0A%0A
     @Ove
@@ -1105,17 +1105,538 @@
 Detail(%22
-h
+appHostInfo%22, hostMap);%0A%0A        hostMap = new HashMap%3C%3E();%0A        CommandResult commandResult = this.mongoTemplate.executeCommand(%22%7B serverStatus: 1 %7D%22);%0A        hostMap.put(%22hostname%22, commandResult.getString(%22host%22));%0A%0A        MongoClient mongoClient = new MongoClient();%0A        Document buildInfo = mongoClient.getDatabase(%22admin%22).runCommand(new Document(%22currentOp%22, Boolean.TRUE));%0A%0A        hostMap.put(%22currentOp%22, buildInfo.get(%22inprog%22, ArrayList.class).get(0).toString());%0A        builder.withDetail(%22mongoDbH
 ostInfo%22

Add Mongo host info to info endpoint