I would like to send messages from the Alerting Plugin to another application that will read the results returned by the Alert.
The Action’s message reads as follows:
"{\"Name\": \"{{ctx.monitor.name}}\",
\"Message\": \"Sample Alert.\",
\"TriggerName\": \"{{ctx.trigger.name}}\",
\"Severity\": {{ctx.trigger.severity}},
\"PeriodStart\": \"{{ctx.periodStart}}\",
\"PeriodEnd\": \"{{ctx.periodEnd}}\",
\"TimeToLive\":180,
\"results\":
{{{ctx.results.0}}} }"
I can parse everything properly except for the results, which come back as “almost-JSON”:
{"Name": "Alert",
"Message": "Sample Alert.",
"TriggerName": "Testing",
"Severity": 1,
"PeriodStart": "2020-02-24T21:13:23.992Z",
"PeriodEnd": "2020-02-24T21:14:23.992Z",
"TimeToLive":180,
\"results\":
{_shards={total=30, failed=0, successful=30, skipped=0}, hits={hits=[], total=3, max_score=0.0}, took=16, timed_out=false, aggregations={aggregation={doc_count_error_upper_bound=0, sum_other_doc_count=0, buckets=[{doc_count=3, key=1.1.1.1}]}}} }"
Elasticsearch brings results back as JSON when I query it directly. I can also see results as JSON when I run the Monitor from Kibana.
Is there any way to have ctx.results come back as JSON? Or is there an easy way to turn it back into JSON if there isn’t? I have been searching around to see if there’s some Mustache thing I’m missing.
Thank you very much.