Hello,
When i want to create below watcher definition, i get compile error. Is there any idea why i get compile error and how can i fix it ?
{
"trigger": {
"schedule": {
"interval": "10m"
}
},
"input": {
"search": {
"request": {
"search_type": "query_then_fetch",
"indices": [
"mfp.application-log*"
],
"rest_total_hits_as_int": true,
"body": {
"size": 0,
"query": {
"bool": {
"must": [
{
"term": {
"service.keyword": {
"value": "RL1C971D"
}
}
},
{
"term": {
"level.keyword": {
"value": "ERROR"
}
}
},
{
"range": {
"timestamp": {
"gt": "now-60m"
}
}
}
],
"boost": 1
}
},
"aggs": {}
}
}
}
},
"condition": {
"script": {
"source": "def previousState = ctx.metadata.previous_state ?: 'normal'; def currentTotal = ctx.payload.hits.total; if (currentTotal >= 10 && previousState == 'normal'){ctx.metadata.previous_state = 'critical'; return 'critical';} else if (currentTotal < 10 && previousState == 'critical') { ctx.metadata.previous_state = 'normal'; return 'normal'; } else { return 'none';}"
}
},
"actions": {
"my_webhook": {
"condition":{
"script":{
"source": "ctx.payload.result == 'critical'"
}
},
"webhook": {
"scheme": "http",
"host": "x",
"port": 3,
"method": "post",
"path": "demo.com",
"params": {},
"headers": {
"Content-Type": "application/x-www-form-urlencoded"
},
"body": "<BSMConnectorEvent><alertname>demoAlarm</alertname><domain>demo</domain><severity>Major</severity><relatedCI>demo</relatedCI><alertdetails> mail ile bilgi verilmelidir. Match count: {{ctx.payload.hits.total}}</alertdetails></BSMConnectorEvent>"
}
},
"my_webhook2":{
"condition":{
"script":{
"source": "ctx.payload.result == 'normal'"
}
},
"webhook": {
"scheme": "http",
"host": "demo.com",
"port": 3,
"method": "post",
"path": "x",
"params": {},
"headers": {
"Content-Type": "application/x-www-form-urlencoded"
},
"body": "<BSMConnectorEvent><alertname>demo Alarm</alertname><domain>OC</domain><severity>Clear</severity><relatedCI>Kullandırım Değerlendirme İşlemleri Erişilebilirlik KPI</relatedCI><alertdetails>bilgi verilmelidir. Match count: {{ctx.payload.hits.total}}</alertdetails></BSMConnectorEvent>"
}
}
}
}
Thanks