Is it possible to change Actuator health api response structure to custom response

Viewed 371

I have my healthIndicators written for different databases which extend the AbstractHealthIndicator from spring.

But the end consumer expects the response in a different format in which the common keys and data expected are different.

Actual :

{
    "status": "DOWN",
    "details": {
        "B": {
            "status": "UP",
            "details": {
                "reachable": true
            }
        },
        "A": {
            "status": "DOWN",
            "details": {
                "reachable": false
            }
        }
    }
}

Expected :

{
    "result": true,
    "data": {
        "modules": [
            {
              "name": "A",
              "status": "OK"
            },
            {
                "name": "B",
                "status": "DOWN"
            },
        ]
    }
}

Is it possible to write a converter, which can do this ?

1 Answers

I don't think you can change the format of the /health endpoint without changing the internal actuator's code.

However its possible to create your own endpoint that will maintain the reference to the Health endpoint (its a bean after all, and therefore can be injected), so that its @GetOperation would call the original "health" endpoint, obtain the results and convert them to your custom format.

The original Health Endpoint is implemented in this class

Related