# Setting up victorops action in watcher.unable to pass only the error message to the victorops json

**URL:** <https://discuss.elastic.co/t/setting-up-victorops-action-in-watcher-unable-to-pass-only-the-error-message-to-the-victorops-json/211946>\
**Category:** Elasticsearch\
**Created:** [December 16, 2019, 7:00am UTC](https://discuss.elastic.co/t/setting-up-victorops-action-in-watcher-unable-to-pass-only-the-error-message-to-the-victorops-json/211946 "2019-12-16T07:00:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vibin\_sagar\_jain](https://avatars.discourse-cdn.com/v4/letter/v/65b543/32.png) [@vibin\_sagar\_jain](https://discuss.elastic.co/u/vibin_sagar_jain)\
**Post date:** [December 16, 2019, 7:00am UTC](https://discuss.elastic.co/t/setting-up-victorops-action-in-watcher-unable-to-pass-only-the-error-message-to-the-victorops-json/211946/1 "2019-12-16T07:00:59Z")

</div>

I am looking to send only the error message generated during an watcher check to victorops. But the victorops Json is not accepting multiple entities . Looking for a way to pass only the error message as ctx.payload. I tried using transform and it failed needed help on creating the right output to victorops.

---

<div class="post-metadata">

**Author:** ![vibin\_sagar\_jain](https://avatars.discourse-cdn.com/v4/letter/v/65b543/32.png) [@vibin\_sagar\_jain](https://discuss.elastic.co/u/vibin_sagar_jain)\
**Post date:** [December 16, 2019, 7:05am UTC](https://discuss.elastic.co/t/setting-up-victorops-action-in-watcher-unable-to-pass-only-the-error-message-to-the-victorops-json/211946/2 "2019-12-16T07:05:55Z")

</div>

adding the watcher details:-

"trigger": {  
"schedule": {  
"interval": "10m"  
}  
},  
"input": {  
"search": {  
"request": {  
"search\_type": "query\_then\_fetch",  
"indices": [  
"apm-test\*”  
],  
"rest\_total\_hits\_as\_int": true,  
"body": {  
"size": 0,  
"query": {  
"bool": {  
"filter": [  
{  
"term": {  
"service.name": "{{ctx.metadata.serviceName}}"  
}  
},  
{  
"term": {  
"processor.event": "error"  
}  
},  
{  
"range": {  
"@timestamp": {  
"gte": "now-{{ctx.metadata.timeRangeValue}}{{ctx.metadata.timeRangeUnit}}"  
}  
}  
}  
]  
}  
},  
"aggs": {  
"error\_groups": {  
"terms": {  
"min\_doc\_count": "{{ctx.metadata.threshold}}",  
"field": "error.grouping\_key",  
"size": 10,  
"order": {  
"\_count": "desc"  
}  
},  
"aggs": {  
"sample": {  
"top\_hits": {  
"\_source": [  
"error.log.message",  
"error.exception.message",  
"error.exception.handled",  
"error.culprit",  
"error.grouping\_key",  
"@timestamp"  
],  
"sort": [  
{  
"@timestamp": "desc"  
}  
],  
"size": 1  
}  
}  
}  
}  
}  
}  
}  
}  
},  
"condition": {  
"script": {  
"source": "return ctx.payload.aggregations.error\_groups.buckets.length \> 0",  
"lang": "painless"  
}  
},  
"actions": {  
"log\_error": {  
"logging": {  
"level": "info",  
"text": "Your service "{{ctx.metadata.serviceName}}" has error groups which exceeds {{ctx.metadata.threshold}} occurrences within "{{ctx.metadata.timeRangeValue}}{{ctx.metadata.timeRangeUnit}}"  
  
{{#ctx.payload.aggregations.error\_groups.buckets}}  
**{{sample.hits.hits.0.\_source.error.log.message}}{{^sample.hits.hits.0.\_source.error.log.message}}{{sample.hits.hits.0.\_source.error.exception.0.message}}{{/sample.hits.hits.0.\_source.error.log.message}}**  
{{sample.hits.hits.0.\_source.error.culprit}}{{^sample.hits.hits.0.\_source.error.culprit}}N/A{{/sample.hits.hits.0.\_source.error.culprit}}  
{{doc\_count}} occurrences  
{{/ctx.payload.aggregations.error\_groups.buckets}}"  
}  
},  
"victorops": {  
"webhook": {  
"scheme": "https",  
"host": "[alert.victorops.com](http://alert.victorops.com)",  
"port": 443,  
"method": "post",  
"path": "/integrations/generic/somecode/alert/$key/$routingkey“,  
"params": {},  
"headers": {  
"Content-type": "application/json"  
},  
"body": " **json** ::{"text":"message\_type": "CRITICAL","monitoring\_tool": "Elastic Watcher","entity\_id": "prod","entity\_display\_name": "apm","state\_message": " apm has generated alerts","elastic\_watcher\_payload": {{#toJson}}ctx.payload{{/toJson}} }"  
}  
}  
},  
"metadata": {  
"emails": ,  
"timeRangeValue": 10,  
"threshold": 1,  
"trigger": "This value must be changed in trigger section",  
"serviceName": "apm",  
"timeRangeUnit": "m"  
}  
}

---

<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:** [January 13, 2020, 7:15am UTC](https://discuss.elastic.co/t/setting-up-victorops-action-in-watcher-unable-to-pass-only-the-error-message-to-the-victorops-json/211946/3 "2020-01-13T07:15:52Z")

</div>

Closed on January 13, 2020, 7:15am UTC

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