Watcher Alert for Failed Snapshots How to loop the ctx.payload returned

In the below example I query for the snapshots to see if there is a failed status on any of them. In this one I'm pulling the first record and the number of shards that failed in the snapshot. How would I edit this so that I could loop the array and display this for every record vs just the first one? I tried to do some searches for looping through a return to send to the log, or eventually a email alert, but couldn't find anything. Any help would be appreciated.

    "trigger": {
      "schedule": {
        "interval": "60s"
    }
  },
   "input": {
      "http": {
         "request": {
            "scheme": "http",
            "host": "localhost",
            "port": 9200,
            "method": "get",
            "path": "/_snapshot/s3_repository/_all",
            "params": {},
            "headers": {}
         }
      }
   },
  "condition": {
      "always": {}
  },
    "actions": {
        "logging": {
           "logging": {
            "text": "Shards failed in first returned record {{ctx.payload.snapshots.0.shards.failed}} "
          }
       }
    }
}

Here is an example of what it returns on the simulation, I removed the list of indices would make it too long(I get about 12 of those right now that I'm trying to loop through to log the results:

{
            "snapshot": "2018-02-23t03:15",
            "uuid": "nIOUXhIsQLSKONnFSFCNBQ",
            "version_id": 6020299,
            "version": "6.2.2",
            "indices": [
              .. indices were removed here ..
            ],
            "include_global_state": true,
            "state": "SUCCESS",
            "start_time": "2018-02-23T03:15:04.460Z",
            "start_time_in_millis": 1519355704460,
            "end_time": "2018-02-23T05:34:55.313Z",
            "end_time_in_millis": 1519364095313,
            "duration_in_millis": 8390853,
            "failures": [],
            "shards": {
              "total": 909,
              "failed": 0,
              "successful": 909
            }
          },

Ok I figured this out thanks to another example I dug up in the forums, so thanks to those in the forums. I changed from going after the failed shards to snapshot state. Posting this so other new guys like myself have an example of the loop.

	"actions": {
			"logging": {
				"logging": {
					"level": "info",
					"text": "Snapshot state:  {{#ctx.payload.snapshots}}{{state}}{{/ctx.payload.snapshots}} "
				}
			}
		}

Is there anywhere that lists a bunch of watcher alert example? I now have a question on how to do the compare off of that loop, but will post it in another topic since it is a different question.

CC @spinscale

Hey,

you best source of examples is probably the examples repo at https://github.com/elastic/examples/tree/master/Alerting

--Alex

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