# Webhook output formatting

**URL:** <https://discuss.elastic.co/t/webhook-output-formatting/201365>\
**Category:** Kibana\
**Created:** [September 27, 2019, 9:13am UTC](https://discuss.elastic.co/t/webhook-output-formatting/201365 "2019-09-27T09:13:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![kurdit](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kurdit/32/54994_2.png) [@kurdit](https://discuss.elastic.co/u/kurdit)\
**Post date:** [September 27, 2019, 9:13am UTC](https://discuss.elastic.co/t/webhook-output-formatting/201365/1 "2019-09-27T09:13:48Z")

</div>

Good afternoon!

There is a 'transform' from watcher:

```
"transform": {
      "script": {
        "source": "DateFormat dateFormat = new SimpleDateFormat (\" yyyy-MM-dd HH: mm: ss z \ "); dateFormat.setTimeZone (TimeZone.getTimeZone (\" Europe / Moscow \ ")); Date date = new Date (); ctx.execution_time = dateFormat.format (date); return ['human_date': ctx.execution_time, 'aggregations': ctx.payload.aggregations] ",
        "lang": "painless"
     }
   }

```

Via WebHook, the following output is sent to telegrams:

> \*\*\*\* Watcher \*\*\*\*  
> Date / Time: 2019-09-29 10:24:55 MSK  
> Watcher name: test\_watcher  
> Host: [www.domain.com](http://www.domain.com)  
> Request Time (ms): 60. **000999450683594**

In the Request Time field, the time in milliseconds is displayed with a large number of decimal places. How can I reduce the number of characters to zero? So that there is nothing after the decimal point

---

<div class="post-metadata">

**Author:** ![cjcenizal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cjcenizal/32/11216_2.png) [@cjcenizal](https://discuss.elastic.co/u/cjcenizal)\
**Post date:** [September 27, 2019, 11:46pm UTC](https://discuss.elastic.co/t/webhook-output-formatting/201365/2 "2019-09-27T23:46:42Z")

</div>

Hi, could you explain or show me how the return value of your script results in the output you're showing me? Based on the script alone, it looks like the only date-related return value is the `human_date` variable, which would be formatted as `yyyy-MM-dd HH: mm: ss z`. How does that end up in a numeric milliseconds value?

Thanks,  
CJ

---

<div class="post-metadata">

**Author:** ![kurdit](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kurdit/32/54994_2.png) [@kurdit](https://discuss.elastic.co/u/kurdit)\
**Post date:** [September 28, 2019, 8:21am UTC](https://discuss.elastic.co/t/webhook-output-formatting/201365/3 "2019-09-28T08:21:31Z")

</div>

Hi, I can show you my Watcher

```
{
  "trigger": {
    "schedule": {
      "interval": "3m"
    }
  },
  "input": {
    "search": {
      "request": {
        "search_type": "query_then_fetch",
        "indices": ["weblog-*"],
        "rest_total_hits_as_int": true,
        "body": {
          "size": 0,
          "query": {
            "bool": {
              "must": [
                {
                  "range": {
                    "@timestamp": {
                      "gte": "now-1m",
                      "lte": "now"
                    }
                  }
                }
              ],
              "must_not": [
                {
                  "query_string": {
                    "analyze_wildcard": true,
                    "fields": [
                      "http_host.keyword"
                    ],
                    "query": "dev.domain.com"
                  }
                }
              ]
            }
          },
          "aggregations": {
            "host": {
              "terms": {
                "field": "http_host.keyword",
                "order": {
                  "max_req_time": "desc"
                }
              },
              "aggregations": {
                "max_req_time": {
                  "max": {
                    "field": "request_time"
                  }
                },
                "max_agg_pipe": {
                  "bucket_selector": {
                    "buckets_path": {
                      "max_req_time": "max_req_time"
                    },
                    "script": {
                      "lang": "expression",
                      "source": "max_req_time > 16"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "condition": {
    "compare": {
      "ctx.payload.hits.total": {
        "gt": 50
      }
    }
  },
  "actions": {
    "telegram": {
      "webhook": {
        "scheme": "http",
        "host": "api.telegram.com",
        "port": 81,
        "method": "post",
        "path": "/bot123456789:XXXXXXXX/sendMessage",
        "params": {},
        "headers": {
          "Content-Type": "application/x-www-form-urlencoded"
        },
        "body": "chat_id=-123456789&text= ****Watcher**** %0A\nDate/Time: {{ctx.payload.human_date}}%0A\nWatcher name: {{ctx.metadata.name}}%0A\nHost: {{#ctx.payload.aggregations.host.buckets}}\n{{key}}\n%0ARequest Time (ms): {{max_req_time.value}}%0A\n{{/ctx.payload.aggregations.host.buckets}}\n"
      }
    }
  },
  "transform": {
    "script": {
      "source": "DateFormat dateFormat = new SimpleDateFormat(\"yyyy-MM-dd HH:mm:ss z\");dateFormat.setTimeZone(TimeZone.getTimeZone(\"Europe/Moscow\")); Date date = new Date(); ctx.execution_time = dateFormat.format(date); return ['human_date': ctx.execution_time, 'aggregations': ctx.payload.aggregations]",
      "lang": "painless"
    }
  }
}

```

P.S. values are taken from the elastic (and the elastic takes from the logs)

---

<div class="post-metadata">

**Author:** ![cjcenizal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cjcenizal/32/11216_2.png) [@cjcenizal](https://discuss.elastic.co/u/cjcenizal)\
**Post date:** [September 30, 2019, 5:16pm UTC](https://discuss.elastic.co/t/webhook-output-formatting/201365/4 "2019-09-30T17:16:58Z")

</div>

Thanks Aleksandr, I see you also posted this question in [Форматирование вывода через Webhook](https://discuss.elastic.co/t/webhook/201359/13), where Igor was able to answer your question. In the future, if you post the same question in multiple forums could you please link back and forth between the posts? This will help us avoid wasting time by answering the same question twice. Thanks!

CJ

---

<div class="post-metadata">

**Author:** ![kurdit](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kurdit/32/54994_2.png) [@kurdit](https://discuss.elastic.co/u/kurdit)\
**Post date:** [October 1, 2019, 7:30am UTC](https://discuss.elastic.co/t/webhook-output-formatting/201365/5 "2019-10-01T07:30:41Z")

</div>

I apologize for this, from now on I will do so. Thanks you!

---

<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:** [October 29, 2019, 7:30am UTC](https://discuss.elastic.co/t/webhook-output-formatting/201365/6 "2019-10-29T07:30:45Z")

</div>

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