Notify slack action -- help with list_path

Hello,
Could someone help with what needs to be entered into "list_path" ? I'm trying to create a dynamic attachment for Slack based on the cluster health status. "list_path" is required but isn't fully explained in the documentation.

PUT _xpack/watcher/watch/cluster_health_watch
{
"trigger" : {
"schedule" : { "interval" : "30s" }
},
"input" : {
"http" : {
"request" : {
"host" : "localhost",
"port" : 9200,
"path" : "/_cluster/health",
"auth": {
"basic": {
"username": "",
"password": ""
}
}
}
}
},
"actions" : {
"notify-slack" : {
"transform" : {
"script" : {
"inline" : "return ['name': ctx.payload.cluster_name, 'color': ctx.payload.status == 'green' ? 'good' : 'danger'];",
"lang" : "painless"
}
},
"slack" : {
"message" : {
"from" : "",
"to" : [ "" ],
"dynamic_attachments" : {
"list_path" : "?????",
"attachment_template" : {
"title" : "Status:",
"text" : "{{name}}",
"color" : "{{color}}"
}
},
"text" : "Cluster health"
}
}
}
}
}

Hey,

the list_pathpoints to an element in the payload, that is a list - for each element in that list a dynamic attachment is created. For example for the buckets of an aggregation.

Hope that helps!

--Alex

Thanks Alex. I'm new to ES, so still not entirely sure. WRT my example, is this possible. Am i on the right line?

define items list:

"inline" : "def items = ['name': ctx.payload.cluster_name, 'color': ctx.payload.status == 'green' ? 'good' : 'danger']; return items;",

reference list in list_path:

  	"dynamic_attachments" : {
  	   "list_path" : "items",
  	   "attachment_template" : {
  			"title" : "Status:",
  			"text" : "{{name}}",
  			"color" : "{{color}}"
  		}
  	 },

Hey,

the context is not yet, what you want to have. You need a field called ctx.items that contains a list of similar events, like this

ctx.items = [ [name: 'foo', color: 'red'], [ name: 'bar', color: 'green' ], [ name: 'baz', color: 'yellow' ] ]

hope this helps..

--Alex

Hey Alex,
Where should ctx.items be placed? In a condition, action or something else?

This is what I have:

 >  "condition" : {
>     "script" : {
> 	  "inline" : "if (ctx.payload.status != 'green') return true;"
>     }
>   },
>    "actions" : {
> 	  "notify-slack" : {
> 	    "transform" : {
>         "script" : {
>           "inline" : "['items' : ['name': 'test', 'color': ctx.payload.status == 'yellow' ? 'yellow' : 'danger']]",
>           "lang" : "painless"
>         }
>       },
> "slack" : {
> 		  "message" : {
> 			"from" : "watcher",
> 			"to" : [ "#test" ], 
> 			"dynamic_attachments" : {
> 			   "list_path" : "ctx.payload.items",
> 			   "attachment_template" : {
> 					"title" : "Status:",
> 					"text" : "{{name}}",
> 					"color" : "{{color}}"
> 				}
> 			 },
> 			"text" : "*Cluster health*" 
> 		  }
> 		}
> 	  }
>    }
> }

getting the following error:

"reason": "IllegalArgumentException[dynamic attachment could not be resolved. expected context [ctx.payload.items] to be a list, but found [{color=123, name=test}] instead]",

Hey,

it should be placed in a transform, likely inside of that slack action. You need to prepare your data to be in a certain format.

--Alex

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