# Custom heartbeat shipper

**URL:** <https://discuss.elastic.co/t/custom-heartbeat-shipper/176165>\
**Category:** Synthetics\
**Created:** [April 10, 2019, 8:17am UTC](https://discuss.elastic.co/t/custom-heartbeat-shipper/176165 "2019-04-10T08:17:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![suikast42](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/suikast42/32/29865_2.png) [@suikast42](https://discuss.elastic.co/u/suikast42)\
**Post date:** [April 10, 2019, 8:17am UTC](https://discuss.elastic.co/t/custom-heartbeat-shipper/176165/1 "2019-04-10T08:17:32Z")

</div>

I want track the health state of an application that exposes it's health over mocriprofile heatlhcheck api. So I have multible states in one healthcheck.

I can't find in heartbeat a monitor that can handle this. So I end up with a custom solution.

I look at the exported fields of heartbeat and try to create a hearbeat entry with that json fields

```
           jsonMap.put("@timestamp", zonedDateTime.toString());
            jsonMap.put("@metadata.beat", "heartbeat");
            jsonMap.put("@metadata.type", "doc");
            jsonMap.put("@metadata.version", "6.7.0");
            jsonMap.put("event.dataset", "uptime");

            jsonMap.put("beat.name", "heartbeat");
            jsonMap.put("beat.hostname", "heartbeat");
            jsonMap.put("beat.version", "6.7.0");

            jsonMap.put("host.name", "heartbeat");
            jsonMap.put("tcp.port", 9090);

            jsonMap.put("monitor.id", check.getName());
            jsonMap.put("monitor.status", check.getState().name().toLowerCase());
            jsonMap.put("monitor.name", "http");
            jsonMap.put("monitor.type", "http");
            jsonMap.put("monitor.scheme", "http");
            jsonMap.put("monitor.ip", "172.17.8.101");
            jsonMap.put("http.url", "http://172.17.8.1:9990/health");

            jsonMap.put("tcp.rtt.connect.us",50);
            jsonMap.put("http.rtt.response_header.us",50);
            jsonMap.put("http.rtt.validate.us",50);
            jsonMap.put("http.rtt.content.us",50);
            jsonMap.put("http.rtt.write_request.us",50);
            jsonMap.put("http.rtt.total.us",5000);
            if (check.getState() == Entry.State.UP) {
                jsonMap.put("http.response.status_code", 200);
            } else {
                if (check.getData() != null) {
                    jsonMap.put("error.type", "validate");
                    jsonMap.put("error.message", check.getData().getErrorMessage());
                }
                jsonMap.put("http.response.status_code", _outcome.getStatusCode().value());
            }

```

With that approach I can see my entries in monitor status but have the follwing problems:

1. Status is invalid
2. Type and IP not shown

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/5/7/5748a2452e0671d18ff837aa7a6cc2610cf8e115.png)

---

<div class="post-metadata">

**Author:** ![suikast42](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/suikast42/32/29865_2.png) [@suikast42](https://discuss.elastic.co/u/suikast42)\
**Post date:** [April 10, 2019, 12:03pm UTC](https://discuss.elastic.co/t/custom-heartbeat-shipper/176165/2 "2019-04-10T12:03:25Z")

</div>

So I find the solution myself. My mistake was to use the jsonmap in wrong way.

It works like a charm if I use `XContentBuilder builder = XContentFactory.jsonBuilder();`

---

<div class="post-metadata">

**Author:** ![dov0211](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dov0211/32/36505_2.png) [@dov0211](https://discuss.elastic.co/u/dov0211)\
**Post date:** [April 10, 2019, 12:04pm UTC](https://discuss.elastic.co/t/custom-heartbeat-shipper/176165/3 "2019-04-10T12:04:07Z")

</div>

Thank you for updating us with the solution

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 4, 2019, 12:04pm UTC](https://discuss.elastic.co/t/custom-heartbeat-shipper/176165/4 "2019-05-04T12:04:11Z")

</div>

This topic was automatically closed 24 days after the last reply. New replies are no longer allowed.
