Stream List Output Formatting in Script (for use in Watcher actions)

alerting

#1

I've been trying to develop a script that can be used for a number different watcher tasks. I came across this this post and it was quite helpful in showing me how to map the output of two aggregations. However, I don't understand painless or Java well enough to get the output of this scipt to print prettier. Can someone point me in the right direction?

Source Thread

{
  "script": {
"source": "return [ 'hosts' : ctx.payload.aggregations.hosts.buckets.stream().map(b -> [b.key: b.values.value]).collect(Collectors.toList()) ]",
"lang": "painless"
  }
}

Existing output (sample):

{0={dev01.foo.bar=0.892}, 1={dev02.foo.bar=0.8310000000000001})

Preferred output (something with line breaks and less array postion designations):

dev01.foo.bar=0.892
dev02.foo.bar=0.8310000000000001

Much appreciation in advance, all.

-Z


#2

Well, I suppose I was making this harder on myself than it needed to be. Using basic Java functions did the trick. I can be pretty dense, at times. I'll leave this here in case anyone needs it. Feel free to make suggestions.

{
  "script": {
    "source": "return [ 'hosts' : ctx.payload.aggregations.hosts.buckets.stream().map(b -> [b.key: b.values.value]).collect(Collectors.toList()).join('\\\\n\\\\n').replace('{','').replace('}','').replace('=',' ')   ]",
    "lang": "painless"
  }
}

(system) #3

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