paolo1  
                
               
                 
              
                  
                    March 8, 2017,  9:35am
                   
                   
              1 
               
             
            
              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 " 
} 
} 
} 
} 
}
 
             
            
               
               
               
            
            
           
          
            
              
                spinscale  
                (Alexander Reelsen)
               
              
                  
                    March 8, 2017,  2:12pm
                   
                   
              2 
               
             
            
              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
             
            
               
               
               
            
            
           
          
            
              
                paolo1  
                
               
              
                  
                    March 8, 2017,  2:40pm
                   
                   
              3 
               
             
            
              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}}"
  		}
  	 },
 
 
             
            
               
               
               
            
            
           
          
            
              
                spinscale  
                (Alexander Reelsen)
               
              
                  
                    March 13, 2017,  7:54pm
                   
                   
              4 
               
             
            
              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
             
            
               
               
               
            
            
           
          
            
              
                paolo1  
                
               
              
                  
                    March 14, 2017,  4:19pm
                   
                   
              5 
               
             
            
              Hey Alex, 
Where should ctx.items be placed? In a condition, action or something else?
             
            
               
               
               
            
            
           
          
            
              
                paolo1  
                
               
              
                  
                    March 14, 2017,  4:43pm
                   
                   
              6 
               
             
            
              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]",
             
            
               
               
               
            
            
           
          
            
              
                spinscale  
                (Alexander Reelsen)
               
              
                  
                    March 16, 2017,  8:02am
                   
                   
              7 
               
             
            
              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
             
            
               
               
               
            
            
           
          
            
              
                system  
                (system)
                  Closed 
               
              
                  
                    April 13, 2017,  8:02am
                   
                   
              8 
               
             
            
              This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.