Watcher HTTP Input request

Is there a way to sort this on a field for example end_time so that when I check this value ctx.payload.snapshots.0.state it will be the last snapshot that ran?

  "trigger": {
    "schedule": {
      "interval": "1h"
    }
  },
  "input": {
    "http": {
      "request": {
        "scheme": "http",
        "host": "localhost",
        "port": 9200,
        "method": "get",
        "path": "/_snapshot/s3_repository/_all",
        "headers": {}
      }
    }
  },
   "condition": {
    "script": {
      "source": "if (ctx.payload.snapshots.0.state == 'FAILED')  { return true; } return false;",
      "lang": "painless",
      "params": {
        "threshold": 0
      }
    }
  },
  "actions": {
    "pagerduty": {
      
      "webhook": {
        "scheme": "https",
        "host": "events.pagerduty.com",
        "port": 443,
        "method": "post",
        "path": "/v2/enqueue",
        "params": {},
        "headers": {
          "Content-type": "application/json"
        },
        "body": "{\"payload\":{\"summary\": \"The {{ctx.payload.snapshots.0.snapshot}} \",\"source\": \"elasticsearch\",\"severity\": \"critical\"}, \"routing_key\":  \"${routkey}\", \"event_action\": \"trigger\", \"client\": \"${POD}\",\"dedup_key\":\"TRACKSCH001\"}"
      }
    }
  }
}```

or a way to get the last value of the array somehow without a sort?

can you try /_snapshot/s3_repository/_current?

--Alex

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